StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
readvpdTotCorr.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 readvpdTotCorr(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* vpdTotCorr = configNode->addDbTable("vpdTotCorr");
45 
46  dbManager->fetchDbTable(vpdTotCorr);
47 
48  cout<<vpdTotCorr->getVersion()<<endl;
49  //cout<<vpdTotCorr->getTableName()<<endl;
50  cout<<vpdTotCorr->getBeginDateTime()<<endl;
51  cout<<vpdTotCorr->getEndDateTime()<<endl;
52 
53 
54  vpdTotCorr_st* totcorr = static_cast<vpdTotCorr_st*>(vpdTotCorr->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 = vpdTotCorr->GetNRows();
64  cout << " NRows = " << nRows << endl;
65  if(nRows!=2*mNVPD) {
66  cout << " NRows doesn't match !!! " << endl;
67  }
68 
69  ofstream outData;
70  outData.open("vpdTotCorr_read.dat");
71  for(int i=0;i<2*mNVPD;i++) {
72  outData << setw(6) << totcorr[i].tubeId << endl;
73  cout << totcorr[i].tubeId << " " << totcorr[i].corralgo << endl;
74  for(int j=0;j<128;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<128;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