StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
readtofTotbCorr.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 readtofTotbCorr(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* tofTotbCorr = configNode->addDbTable("tofTotbCorr");
45 
46  dbManager->fetchDbTable(tofTotbCorr);
47 
48  cout<<tofTotbCorr->getVersion()<<endl;
49  //cout<<tofTotbCorr->getTableName()<<endl;
50  cout<<tofTotbCorr->getBeginDateTime()<<endl;
51  cout<<tofTotbCorr->getEndDateTime()<<endl;
52 
53 
54  tofTotbCorr_st* totcorr = static_cast<tofTotbCorr_st*>(tofTotbCorr->GetTable());
55 
56  if(!totcorr) {
57  cout << " ahhhhhh! " << endl;
58  return;
59  }
60 
61  cout<<"Read out from DataBase-------------->"<<endl;
62 
63  Int_t nRows = tofTotbCorr->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("totCorr_read.dat");
71  //for(int i=0;i<mNTray*mNTDIG;i++) {
72  for(int i=0;i<nRows;i++) {
73  outData << setw(6) << totcorr[i].trayId << setw(6) << totcorr[i].moduleId << setw(6) << totcorr[i].cellId << setw(6) << totcorr[i].tdcId << endl;
74  for(int j=0;j<60;j++) {
75  if(totcorr[i].tot[j]>1.e-4)
76  outData << setw(15) << totcorr[i].tot[j];
77  }
78  outData << endl;
79  for(int j=0;j<60;j++) {
80  if(totcorr[i].tot[j]>1.e-4)
81  outData << setw(15) << totcorr[i].corr[j];
82  }
83  outData << endl;
84  }
85  outData.close();
86 
87 }
static StDbManager * Instance()
strdup(..) is not ANSI
Definition: StDbManager.cc:155