StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
storetofTDIGOnTray.C
1 // macro to upload tofr5 INL tables to database
2 //
3 // based on
4 // http://www.star.bnl.gov/STAR/comp/db/StoreDbTable.cc.html
5 //
6 // Jing Liu, 02/18/2005
7 // FG 01/13/2012 -- Updated to allow for arbitray number of TDIGs per tray
8 
9 
10 #include <iostream>
11 #include <fstream>
12 #include <string>
13 #include <iomanip>
14 using namespace std;
15 
16 
17 void storetofTDIGOnTray() {
18  const Bool_t Debug = kFALSE;
19  const Int_t NBOARD = 8;
20 //-- year8
21  // const Int_t NTRAY = 5;
22 //-- year9
23  // const Int_t NTRAY = 94;
24  // const Int_t NVPDTRAY = 2;
25  // const Int_t NMAX = 120;
26 //-- year10/year11
27  const Int_t NTRAY = 120;
28  const Int_t NVPDTRAY = 2;
29  const Int_t NMAX = 300; //123;
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 ZStoreTime = "2007-11-01 00:00:03";
48  // TString ZStoreTime = "2008-11-01 00:00:00";
49  // TString ZStoreTime = "2009-11-01 00:00:00";
50  // TString ZStoreTime = "2010-12-20 00:00:01";
51  // TString ZStoreTime = "2011-04-20 00:00:00";
52  // TString ZStoreTime = "2011-12-20 00:00:00";
53  TString ZStoreTime = "2012-12-20 00:00:00";
54 
55 //-- add table to the container with descriptor given by Database
56  StDbTable* tofTDIGOnTray = configNode->addDbTable("tofTDIGOnTray");
57 
58 //-- fill structures & store times
59  tofTDIGOnTray_st *tdig = new tofTDIGOnTray_st[NMAX+NVPDTRAY];
60 
61 //-- year8
62  // Short_t trayId[NTRAY+NVPDTRAY] = {76, 77, 78, 79, 80, 121, 122};
63  // Short_t tdigId[NTRAY+NVPDTRAY][NBOARD] = {
64  // 36, 26, 27, 29, 25, 23, 22, 21,
65  // 30, 31, 33, 35, 28, 32, 34, 37,
66  // 74, 63, 49, 72, 64, 53, 59, 52,
67  // 70, 51, 75, 65, 66, 50, 71, 68,
68  // 46, 62, 72, 69, 61, 58, 42, 43,
69  // 89, 91, 0, 0, 84, 82, 0, 0,
70  // 85, 79, 0, 0, 80, 83, 0, 0
71  // };
72 // ------------------------------
73 //-- year10
74  // Short_t trayId[NMAX] = { 68, 58, 63, 6,106, 67, 61, 50, 57, 60,
75  // 47, 46, 87,133, 64, 72, 62, 42, 14, 11,
76  // 28, 7, 25, 33, 19, 17, 37, 21, 30, 35,
77  // 8, 20, 31, 27, 12, 9, 10, 29, 34, 13,
78  // 16, 77, 89, 36, 39, 23, 32, 15, 24, 18,
79  // 59, 66, 70, 38, 41, 45, 52, 54, 53, 55,
80  // 84,105, 94, 91, 95, 48, 44, 22, 26, 49,
81  // 5, 2, 75, 40,117, 4,121, 99,120,122,
82  // 111,116,118,119,109,101,100,107, 98, 56,
83  // 88,115,102,108,112,110,113,114,123, 90,
84  // 93, 65, 51, 73, 76, 83, 69, 80, 82, 74,
85  // 97, 79, 43, 86, 85,132,104, 92, 96,103};
86  // // B-132; C-133 renamed
87 // ------------------------------
88 //-- year11
89  // ifstream infile("data/run11/INL/tdigs_01122011.txt");
90 // VPD boards until April 2011
91  // Short_t tdigId_Vpd[NVPDTRAY][NBOARD] = { 89, 91, 1102, 0, 885, 82, 0, 0,
92  // 85, 79, 1101, 0, 80, 83, 0, 0};
93  //
94  // Short_t trayId[NMAX] = { 68, 58, 63, 6,106, 67, 61, 50, 57, 71,
95  // 47, 46, 87,133, 64, 72, 62, 42, 14, 11,
96  // 28, 7, 25, 33, 19, 17, 37, 21, 30, 35,
97  // 8, 20, 31, 27, 12, 9, 10, 29, 34, 13,
98  // 16, 77, 89, 36, 39, 23, 32, 15, 24, 18,
99  // 59, 66, 70, 38, 41, 45, 52, 54, 53, 55,
100  // 84,105, 94, 91, 95, 48, 44, 22, 26, 49,
101  // 5, 2, 75, 40,117, 4,121, 99,120,122,
102  // 111,116,118,119,109,101,100,107, 98, 56,
103  // 88,115,102,108,112,110,113,114,123, 90,
104  // 93, 65, 51, 73, 76, 83, 69, 80, 82, 74,
105  // 97, 79, 43, 86, 85,132,104, 92, 96,103};
106  // // B-132; C-133 renamed
107 // ------------------------------
108 //-- year12
109 // changed trays at W8, W23, E93
110 // ifstream infile("data/run12/INL/tdigs_120106.txt");
111 // Short_t trayId[NTRAY] = { 68, 58, 63, 6,106, 67, 61, 81, 57, 71,
112 // 47, 46, 87,133, 64, 72, 62, 42, 14, 11,
113 // 28, 7, 3, 33, 19, 17, 37, 21, 30, 35,
114 // 8, 20, 31, 27, 12, 9, 10, 29, 34, 13,
115 // 16, 77, 89, 36, 39, 23, 32, 15, 24, 18,
116 // 59, 66, 70, 38, 41, 45, 52, 54, 53, 55,
117 // 84,105, 94, 91, 95, 48, 44, 22, 26, 49,
118 // 5, 2, 75, 40,117, 4,121, 99,120,122,
119 // 111,116,118,119,109,101,100,107, 98, 56,
120 // 88,115, 78,108,112,110,113,114,123, 90,
121 // 93, 65, 51, 73, 76, 83, 69, 60, 82, 74,
122 // 97, 79, 43, 86, 85,132,104, 92, 96,103};
123 // // B-132; C-133 renamed
124 // ------------------------------
125 //-- year13
126 // changed trays at W8, W23, W38, E93, E95, E109
127 // see http://www.star.bnl.gov/HyperNews-star/protected/get/startof/2675.html
128  ifstream infile("data/run13/INL/tdigs_20130115.txt");
129  Short_t trayId[NTRAY] = { 68, 58, 63, 6,106, 67, 61, 50, 57, 71,
130  47, 46, 87,133, 64, 72, 62, 42, 14, 11,
131  28, 7, 25, 33, 19, 17, 37, 21, 30, 35,
132  8, 20, 31, 27, 12, 9, 10, 3, 34, 13,
133  16, 77, 89, 36, 39, 23, 32, 15, 24, 18,
134  59, 66, 70, 38, 41, 45, 52, 54, 53, 55,
135  84,105, 94, 91, 95, 48, 44, 22, 26, 49,
136  5, 2, 75, 40,117, 4,121, 99,120,122,
137  111,116,118,119,109,101,100,107, 98, 56,
138  88,115,102,108, 81,110,113,114,123, 90,
139  93, 65, 51, 73, 76, 83, 69, 80, 82, 74,
140  97, 79, 43, 86, 85,132,104, 92, 96,103};
141  // B-132; C-133 renamed
142 // ------------------------------
143  Short_t tdigId[NTRAY][NBOARD];
144 
145 //-- run 11 AuAu@18GeV, run 12, run 13
146  Short_t tdigId_Vpd[NVPDTRAY][NBOARD] = { 89, 91, 495, 0, 885, 82, 0, 0,
147  85, 79, 1101, 0, 80, 83, 0, 0};
148 
149  Short_t tId[NMAX], boardId[NMAX][NBOARD]; // two additional trays
150  int i(0),j(0); // clear counters
151  int trayNum, oldTrayNum, iboard, boardNum;
152 
153  cout << "Reading UT-Austin database info ... " << endl;
154  if (infile) {
155  // read first entry
156  infile >> trayNum >> iboard >> boardNum;
157  tId[i] = (Short_t)trayNum;
158  boardId[i][iboard-1] = (Short_t)boardNum;
159  oldTrayNum = trayNum;
160  // increment general counter (total# of TDIGs, only for debugging) and dump data
161  if (Debug) cout << j++ << " " << i << " " << trayNum << " "<< iboard << " " << boardNum << endl;
162 
163  // loop in the remaining entries
164  while ( infile >> trayNum >> iboard >> boardNum ) {
165  // increment i only when trayNum incrememts ...
166  if (trayNum != oldTrayNum) {
167  tId[++i] = (Short_t)trayNum;
168  oldTrayNum = trayNum;
169  }
170  // increment general counter (total# of TDIGs, only for debugging) and dump data
171  if (Debug) cout << j++ << " " << i << " " << trayNum << " "<< iboard << " " << boardNum << endl;
172 
173  boardId[i][iboard-1] = (Short_t)boardNum;
174  }
175  }
176  infile.close();
177  cout << "... done reading database info" << endl;
178 
179  for(int i=0;i<NTRAY;i++) {
180  for(int j=0;j<NBOARD;j++) { tdigId[i][j] = 0; }
181 
182  Short_t thisTray = trayId[i];
183  int index = -1;
184  for(int j=0;j<NMAX;j++) {
185  if(thisTray==tId[j]) {
186  index = j;
187  break;
188  }
189  }
190  if (Debug) cout << "pos = " << i+1 << " tray = " << thisTray << " index = " << index << " : ";
191  if(index<0||index>=NMAX) { cout<< "ERROR: unexpected index "<< index << endl; continue;}
192  for(int j=0;j<NBOARD;j++) {
193  tdigId[i][j] = boardId[index][j];
194  if (Debug) cout << tdigId[i][j] << " ";
195  }
196  if (Debug) cout << endl;
197  }
198 
199 /*
200  {
201  89, 91, 0, 0, 84, 82, 0, 0,
202  85, 79, 0, 0, 80, 83, 0, 0
203  };
204 */
205 //-- include the VPD TDIG mapping
206  for(int i=0;i<NTRAY+NVPDTRAY;i++) {
207  tdig[i].trayId = i+1;
208  for(int j=0;j<NBOARD;j++) {
209  if(i<NTRAY) {
210  tdig[i].tdigId[j] = tdigId[i][j];
211  } else {
212  tdig[i].tdigId[j] = tdigId_Vpd[i-NTRAY][j];
213  }
214  }
215  }
216 
217 //-- create output file for test/verification purposes
218  ofstream outData("testTDIGMap.dat");
219  for(int i=0;i<NTRAY+NVPDTRAY;i++) {
220  for(int j=0;j<NBOARD;j++) {
221  outData << setw(5) << tdig[i].tdigId[j];
222  }
223  outData << endl;
224  }
225  outData.close();
226 
227 //-- store data in table
228  tofTDIGOnTray->SetTable((char*)tdig, NTRAY+NVPDTRAY);
229 //- set store time
230  dbManager->setStoreTime(ZStoreTime.Data());
231 //- store table in dBase
232  cout<<"Preparing to upload ... "<<endl;
233  dbManager->storeDbTable(tofTDIGOnTray);
234  cout << "... done" << endl;
235 }
236 
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