StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
readtofSimResParams.C
1 // macro to read tofSimResTables from database
2 //
3 // Frank Geurts Nov. 24, 2020
4 
5 #include <iostream>
6 #include <fstream>
7 #include <string>
8 #include "iomanip.h"
9 using namespace std;
10 
11 void readtofSimResParams(string ZReadTime = "2029-12-31 23:59:59")
12 {
13  const int mNTray = 120;
14  const int mNCellsPerTray = 192;
15  const int mNVPD = 19;
16  //double params[mNTray][mNCellsPerTray];
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  gSystem->Load("StDbLib.so");
24  gSystem->Load("libStDb_Tables.so");
25 
26  //-- get the singleton manager
27  StDbManager* dbManager = StDbManager::Instance();
28 
29  //-- connect to the db & get an empty container
30  StDbConfigNode* configNode = dbManager->initConfig("Calibrations_tof");
31  dbManager->setRequestTime(ZReadTime.c_str());
32 
33 // --- BTOF
34  StDbTable* tofSimResParams = configNode->addDbTable("tofSimResParams");
35  dbManager->fetchDbTable(tofSimResParams);
36 
37  cout<<"--- BTOF table ---"<< endl;
38  cout<<"version : " << tofSimResParams->getVersion()<<endl;
39  cout<<"begin data/time :" << tofSimResParams->getBeginDateTime()<<endl;
40  cout<<"end data/time :" << tofSimResParams->getEndDateTime()<<endl;
41 
42  tofSimResParams_st* tofTable = static_cast<tofSimResParams_st*>(tofSimResParams->GetTable());
43  if(!tofTable) {
44  cout << " No BTOF table? arrghhhhhh! " << endl;
45  return;
46  }
47 
48 // --- VPD
49  StDbTable* vpdSimParams = configNode->addDbTable("vpdSimParams");
50  dbManager->fetchDbTable(vpdSimParams);
51 
52  cout<<"--- VPD table ---"<< endl;
53  cout<<"version : " << vpdSimParams->getVersion()<<endl;
54  cout<<"begin data/time :" << vpdSimParams->getBeginDateTime()<<endl;
55  cout<<"end data/time :" << vpdSimParams->getEndDateTime()<<endl;
56 
57  vpdSimParams_st* vpdTable = static_cast<vpdSimParams_st*>(vpdSimParams->GetTable());
58  if(!vpdTable) {
59  cout << " No VPD table? arrghhhhhh! " << endl;
60  return;
61  }
62 
63 
64  //--- store BTOF data in text file
65  cout <<"--- Read from BTOF table ---"<<endl;
66  Int_t nRows = tofSimResParams->GetNRows();
67  cout << " NRows = " << nRows << endl;
68 
69  ofstream outData;
70  outData.open("tofSimResParams.dat");
71 
72  for ( int row = 0; row < nRows; row++){
73  //cout << "row " << setw(6) << row << ": ";
74  for ( int i = 0; i < mNTray; i++ ){ // nTrays
75  //cout << ".";
76  for ( int j = 0; j < mNCellsPerTray; j++ ){
77  size_t index = i * mNTray + j;
78  //params[i][j] = tofTable[0].resolution[index];
79  outData << setw(6) << i << setw(6) << j << setw(6) << tofTable[0].resolution[index] << endl;
80  }
81  }
82  //cout << endl;
83  }
84  outData.close();
85 
86 
87 // --- Store VPD data in text file
88  cout <<"--- Read from VPD table ---"<<endl;
89  nRows = vpdSimParams->GetNRows();
90  cout << " NRows = " << nRows << endl;
91 
92  outData.open("vpdSimParams.dat");
93 
94  for ( int row = 0; row < nRows; row++){
95  //cout << "row " << setw(6) << row << ": ";
96  for ( int i = 0; i < 2*mNVPD; i++ ){ // nTubes
97  //params.tubeId = table->tubeID[i];
98  //params.singleTubeRes = table->tubeRes[i];
99  //params.tubeStatusFlag = table->tubeStatusFlag[i];
100  //params.tubeTriggerFlag = table->tubeTriggerFlag[i];
101  //mSimParams[table->tubeID[i]] = params;
102  outData << setw(6) << i << setw(6) << vpdTable->tubeRes[i] << endl;
103 
104  }
105  //cout << endl;
106  }
107  outData.close();
108 
109 }
static StDbManager * Instance()
strdup(..) is not ANSI
Definition: StDbManager.cc:155