StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
readtofZbCorr.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 #include <string>
18 #include "iomanip.h"
19 using namespace std;
20 
21 void readtofZbCorr(string ZReadTime = "2029-12-31 23:59:59")
22 {
23  const int mNTray = 120;
24  const int mNTDIG = 8;
25  const int mNVPD = 19;
26 
27  //-- load dBase and Table definition libraries
28  gSystem->Load("St_base");
29  gSystem->Load("StChain");
30  gSystem->Load("StUtilities");
31  gSystem->Load("St_Tables.so");
32 
33  gSystem->Load("StDbLib.so");
34  gSystem->Load("libStDb_Tables.so");
35 
36  //-- get the singleton manager
37  StDbManager* dbManager = StDbManager::Instance();
38 
39  //-- connect to the db & get an empty container
40  StDbConfigNode* configNode = dbManager->initConfig("Calibrations_tof");
41 
42  dbManager->setRequestTime(ZReadTime.c_str());
43 
44  StDbTable* tofZbCorr = configNode->addDbTable("tofZbCorr");
45 
46  dbManager->fetchDbTable(tofZbCorr);
47 
48  cout<<tofZbCorr->getVersion()<<endl;
49  //cout<<tofZbCorr->getTableName()<<endl;
50  cout<<tofZbCorr->getBeginDateTime()<<endl;
51  cout<<tofZbCorr->getEndDateTime()<<endl;
52 
53 
54  tofZbCorr_st* zcorr = static_cast<tofZbCorr_st*>(tofZbCorr->GetTable());
55 
56  if(!zcorr) {
57  cout << " ahhhhhh! " << endl;
58  return;
59  }
60 
61  cout<<"Read out from DataBase-------------->"<<endl;
62 
63  Int_t nRows = tofZbCorr->GetNRows();
64  cout << " NRows = " << nRows << endl;
65  // if(nRows!=mNTray*mNTDIG) {
66  // cout << " nRows doesn't match !!! " << endl;
67  // }
68 
69  ofstream outData;
70  outData.open("zCorr_read.dat");
71  // for(int i=0;i<mNTray*mNTDIG;i++) {
72  for(int i=0;i<nRows;i++) {
73  outData << setw(6) << zcorr[i].trayId << setw(6) << zcorr[i].moduleId << setw(6) << zcorr[i].cellId << endl;
74  for(int j=0;j<60;j++) {
75  if(fabs(zcorr[i].z[j])<1.e-4 && fabs(zcorr[i].corr[j])<1.e-4) continue;
76  outData << setw(15) << zcorr[i].z[j];
77  }
78  outData << endl;
79  for(int j=0;j<60;j++) {
80  if(fabs(zcorr[i].z[j])<1.e-4 && fabs(zcorr[i].corr[j])<1.e-4) continue;
81  outData << setw(15) << zcorr[i].corr[j];
82  }
83  outData << endl;
84  }
85  outData.close();
86 
87 }
static StDbManager * Instance()
strdup(..) is not ANSI
Definition: StDbManager.cc:155