StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
readtofGeomAlign.C
1 // macro to read tof Geom Align data
2 //
3 
4 
5 // #include "StDbLib/StDbManager.hh"
6 // #include "StDbLib/StDbConfigNode.hh"
7 // #include "StDbLib/StDbTable.h"
8 // #include "StDbLib/StDbDefs.hh"
9 
10 #include <iostream>
11 #include <fstream>
12 #include <string>
13 #include <iomanip>
14 using namespace std;
15 
16 void readtofGeomAlign(string ZReadTime = "2029-12-31 23:59:59")
17 {
18  //-- load dBase and Table definition libraries
19  gSystem->Load("St_base");
20  gSystem->Load("StChain");
21  gSystem->Load("StUtilities");
22  gSystem->Load("St_Tables.so");
23 
24  gSystem->Load("StDbLib.so");
25  gSystem->Load("libStDb_Tables.so");
26 
27  const Int_t NTRAY = 94;
28  const Int_t NVPDTRAY = 2;
29  const Int_t NMAX = 120;
30 
31  //-- get the singleton manager
32  StDbManager* dbManager = StDbManager::Instance();
33 
34  //-- connect to the db & get an empty container
35  StDbConfigNode* configNode = dbManager->initConfig("Calibrations_tof");
36  //string ZReadTime = time;
37  dbManager->setRequestTime(ZReadTime.c_str());
38 
39  StDbTable* tofGeomAlign = configNode->addDbTable("tofGeomAlign");
40  dbManager->fetchDbTable(tofGeomAlign);
41 
42  cout<< "--- Table properties: ---" << endl;
43  cout<<tofGeomAlign->getVersion()<<endl;
44  cout<<tofGeomAlign->getBeginDateTime()<<endl;
45  cout<<tofGeomAlign->getEndDateTime()<<endl;
46  cout<< "------------------------" << endl;
47 
48  tofGeomAlign_st *tofAlign = static_cast<tofGeomAlign_st*>(tofGeomAlign->GetTable());
49  if (!tofAlign){
50  cout << "ERROR: no such table" << endl;
51  return;
52  }
53 
54  cout << "Reading out from database ..." << endl;
55  Int_t nRows = tofGeomAlign->GetNRows();
56  cout << "Number of rows: " << nRows << endl;
57  if (nRows != NMAX) {
58  cout << " WARNING: number of rows does not match " << NMAX << endl;
59  }
60 
61  ofstream outData;
62  outData.open("geomAlign_readback.dat");
63 
64  for(int i=0;i<nRows;i++) {
65  int tray = i+1;
66  cout << " trayId=" << tray
67  << " phi0=" << tofAlign[i].phi0
68  << " z0=" << tofAlign[i].z0
69  << " x0=" << tofAlign[i].x0
70  << " a0=" << tofAlign[i].angle0 << endl;
71  outData << setw(6) << tray
72  << setw(15) << tofAlign[i].phi0
73  << setw(15) << tofAlign[i].z0
74  << setw(15) << tofAlign[i].x0
75  << setw(15) << tofAlign[i].angle0
76  << endl;
77  }
78 
79  outData.close();
80  cout << "done." << endl;
81 
82 }
static StDbManager * Instance()
strdup(..) is not ANSI
Definition: StDbManager.cc:155