StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
readtofTOffset.C
1 // macro to read tofr5 MAP table from database
2 //
3 // based on
4 // http://www.star.bnl.gov/STAR/comp/db/StoreDbTable.cc.html
5 //
6 // Xin Dong, 04/14/2010
7 //
8 
9 
10 // #include "StDbLib/StDbManager.hh"
11 // #include "StDbLib/StDbConfigNode.hh"
12 // #include "StDbLib/StDbTable.h"
13 // #include "StDbLib/StDbDefs.hh"
14 
15 #include <iostream>
16 #include <fstream>
17 using namespace std;
18 
19 void readtofTOffset(string ZReadTime = "2029-12-31 23:59:59")
20 {
21  const int mNTray = 120;
22  const Int_t mNTOF = 192;
23  const Int_t mNModule = 32;
24  const Int_t mNCell = 6;
25 
26  //-- load dBase and Table definition libraries
27  gSystem->Load("St_base");
28  gSystem->Load("StChain");
29  gSystem->Load("StUtilities");
30  gSystem->Load("St_Tables.so");
31 
32  gSystem->Load("StDbLib.so");
33  gSystem->Load("libStDb_Tables.so");
34 
35  //-- get the singleton manager
36  StDbManager* dbManager = StDbManager::Instance();
37 
38  //-- connect to the db & get an empty container
39  StDbConfigNode* configNode = dbManager->initConfig("Calibrations_tof");
40 
41  dbManager->setRequestTime(ZReadTime.c_str());
42 
43  StDbTable* tofTOffset = configNode->addDbTable("tofTOffset");
44 
45  dbManager->fetchDbTable(tofTOffset);
46 
47  cout<<tofTOffset->getVersion()<<endl;
48  //cout<<tofTOffset->getTableName()<<endl;
49  cout<<tofTOffset->getBeginDateTime()<<endl;
50  cout<<tofTOffset->getEndDateTime()<<endl;
51 
52 
53 
54  tofTOffset_st* tZero = static_cast<tofTOffset_st*>(tofTOffset->GetTable());
55 
56  if(!tZero) {
57  cout << " ahhhhhh! " << endl;
58  return;
59  }
60 
61  Int_t nRows = tofTOffset->GetNRows();
62  cout << " NRows = " << nRows << endl;
63  if(nRows!=mNTray) {
64  cout << " NRows doesn't match !!! " << endl;
65  }
66 
67  Double_t mTofTZero[120][32][6];
68  for(int i=0;i<120;i++) {
69  for(int j=0;j<32;j++) {
70  for(int k=0;k<6;k++) {
71  mTofTZero[i][j][k] = 0.0;
72  }
73  }
74  }
75 
76  cout<<"Read out from DataBase-------------->"<<endl;
77 
78  ofstream outData;
79  outData.open("TOffset_read.dat");
80  for (Int_t i=0;i<mNTray;i++) {
81  for(int j=0;j<mNModule;j++) {
82  for(int k=0;k<mNCell;k++) {
83  short trayId, moduleId, cellId;
84  trayId = tZero[i].trayId;
85  moduleId = j+1;
86  cellId = k+1;
87  int index = j*mNCell+k;
88  outData << " " << trayId << " " << moduleId << " " << cellId << endl;
89  outData << tZero[i].T0[index] << endl;
90  }
91  }
92  }
93  outData.close();
94 
95  cout<<tofTOffset->getVersion()<<endl;
96  //cout<<tofTOffset->getTableName()<<endl;
97  cout<<tofTOffset->getBeginDateTime()<<endl;
98  cout<<tofTOffset->getEndDateTime()<<endl;
99 
100 
101 
102 }
static StDbManager * Instance()
strdup(..) is not ANSI
Definition: StDbManager.cc:155