StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
storetofTOffset.C
1 // $Id: storetofTOffset.C,v 1.2 2014/11/24 22:18:54 geurts Exp $
2 // macro to upload tofTOffset tables to database
3 //
4 // based on http://www.star.bnl.gov/STAR/comp/db/StoreDbTable.cc.html
5 //
6 // Xin Dong, 06/04/2008
7 // ---
8 // $Log: storetofTOffset.C,v $
9 // Revision 1.2 2014/11/24 22:18:54 geurts
10 // Add striciter protection against non-existing files (bail out), and reduce excessive std output
11 //
12 // Revision 1.1 2010/12/14 19:27:28 geurts
13 // *** empty log message ***
14 //
15 // ---
16 
17 
18 #include <iostream>
19 #include <fstream>
20 #include <string>
21 using namespace std;
22 
23 void storetofTOffset(const Bool_t mTest = 1)
24 {
25 
26  const Int_t mNTray = 120;
27  const Int_t mNTOF = 192;
28  const Int_t mNModule = 32;
29  const Int_t mNCell = 6;
30 
31  //-- load dBase and Table definition libraries
32  gSystem->Load("St_base");
33  gSystem->Load("StChain");
34  gSystem->Load("StUtilities");
35  gSystem->Load("St_Tables.so");
36 
37  gSystem->Load("StDbLib.so");
38  gSystem->Load("libStDb_Tables.so");
39 
40  //-- get the singleton manager
41  StDbManager* dbManager = StDbManager::Instance();
42 
43  //-- connect to the db & get an empty container
44  StDbConfigNode* configNode = dbManager->initConfig("Calibrations_tof");
45 
46  //----------------------------------------
47 // TString StoreTime = "2008-02-01 00:00:03";
48 // TString StoreTime = "2008-03-04 16:00:01";
49 // TString StoreTime = "2009-03-15 00:00:00";
50 // TString StoreTime = "2009-11-01 00:00:00"; // 200 GeV preliminary
51 // TString StoreTime = "2010-03-18 18:00:00"; // 62 GeV preliminary
52 // TString StoreTime = "2010-04-08 15:00:00"; // 39 GeV preliminary
53  ifstream inTime;
54  inTime.open("input/timestamp");
55  string time;
56  if (inTime.is_open()) {
57  getline(inTime, time);
58  inTime.close();
59  } else {
60  cout << " Unable to open the TimeStamp file! EXIT! " << endl;
61  return;
62  }
63  TString StoreTime = time;
64  cout << " Store Time " << StoreTime.Data() << endl;
65 
66  //-- add table to the container with descriptor given by Database
67  StDbTable* tofTOffset = configNode->addDbTable("tofTOffset");
68 
69  //-- fill structures & store times
70  tofTOffset_st *tZero = new tofTOffset_st[mNTray];
71 
72  // read in tzero file by file.
73 
74  ifstream inData;
75  inData.open("input/t0_4DB.dat");
76  if (!inData.is_open()){
77  cerr <<" unable to open input/t0_4DB.dat; bailing out ..." << endl;
78  exit(-1);
79  }
80 
81  for (Int_t i=0;i<mNTray;i++) {
82  for (Int_t j=0;j<mNModule;j++) {
83  for (Int_t k=0;k<mNCell;k++) {
84  short trayId, moduleId, cellId;
85  inData>>trayId>>moduleId>>cellId;
86 
87  double t0;
88  inData >> t0;
89  tZero[i].trayId = (Short_t)trayId;
90  tZero[i].T0[j*mNCell+k] = (Float_t)t0;
91  }
92  }
93  }
94  inData.close();
95 
96  // test
97  ofstream outData;
98  outData.open("TOffset_test.dat");
99  for(int i=0;i<mNTray;i++) {
100  for(int j=0;j<mNModule;j++) {
101  for(int k=0;k<mNCell;k++) {
102  short trayId, moduleId, cellId;
103  trayId = tZero[i].trayId;
104  moduleId = j+1;
105  cellId = k+1;
106  int index = j*mNCell+k;
107  outData << " " << trayId << " " << moduleId << " " << cellId << endl;
108  outData << tZero[i].T0[index] << endl;
109  }
110  }
111  }
112  outData.close();
113 
114  if(!mTest) {
115  cout<<" prepare to upload data to DB"<<endl;
116  //- store data in table
117  tofTOffset->SetTable((char*)tZero, mNTray);
118  //- set store time
119  dbManager->setStoreTime(StoreTime.Data());
120  //- store table in dBase
121  cout<<" here "<<endl;
122  dbManager->storeDbTable(tofTOffset);
123  cout<<"uploaded"<<endl;
124  // return 0;
125  }
126 }
virtual void SetTable(char *data, int nrows, int *idList=0)
calloc&#39;d version of data for StRoot
Definition: StDbTable.cc:550
static StDbManager * Instance()
strdup(..) is not ANSI
Definition: StDbManager.cc:155