1 |
// |
2 |
#include <iostream> |
3 |
#include <sstream> |
4 |
#include <errno.h> |
5 |
// |
6 |
#include <TSystem.h> |
7 |
// |
8 |
#include <PamelaDBOperations.h> |
9 |
#include <YodaProfilerVerl2.h> |
10 |
// |
11 |
using namespace std; |
12 |
// |
13 |
// Usage subroutine |
14 |
// |
15 |
void usage(){ |
16 |
printf("\nUsage:\n"); |
17 |
printf("\n YodaProfiler [options] -rawFile raw_filename -yodaFile yoda_filename \n"); |
18 |
printf("\n -rawFile full path to the raw file\n"); |
19 |
printf("\n -yodaFile full path to the YODA file\n"); |
20 |
printf("\n Options can be: \n"); |
21 |
printf("\n --version print informations about compilation and exit\n"); |
22 |
printf("\n -h | --help print this help and exit \n"); |
23 |
printf("\n -v | --verbose be verbose [default]\n"); |
24 |
printf("\n -s | --silent print nothing on STDOUT\n"); |
25 |
printf("\n -g | --debug be very verbose [default: no]\n"); |
26 |
printf("\n -boot number CPU boot number [default = taken from VarDump]\n"); |
27 |
printf("\n -tsync number timesync (s) [default = taken from data]\n"); |
28 |
printf("\n -obt0 number obt at timesync (ms) [default = taken from data]\n"); |
29 |
printf("\n -clean number number in seconds after which the fragment table\n"); |
30 |
printf("\n can be cleaned and runs validated [default = -1 do not clean],\n"); |
31 |
printf("\n if 0 force cleaning immediatly, if negative do not clean\n"); |
32 |
printf("\n -host name for the host [default = $PAM_DBHOST or mysql://localhost/pamelaprod]\n"); |
33 |
printf("\n -user username for the DB [default = $PAM_DBUSER or \"anonymous\"] \n"); |
34 |
printf("\n -psw password for the DB [default = $PAM_DBPSW or \"\"]\n"); |
35 |
printf("\n The order of input files and options does not matter. \n"); |
36 |
printf("\nExample: \n"); |
37 |
printf("\n YodaProfiler -yodaFile /path/to/raw/files/000_000_00000_cln2.pam -rawFile /path/to/filesfromyoda/000_000_00000_cln2.root -v \n\n"); |
38 |
}; |
39 |
// |
40 |
int main(int numinp, char *inps[]){ |
41 |
// |
42 |
// Variables booking |
43 |
// |
44 |
Int_t signal = 0; |
45 |
Int_t nul = 0; |
46 |
UInt_t boot = 0; |
47 |
UInt_t tsync = 0; |
48 |
UInt_t obt0 = 0; |
49 |
// Long64_t olderthan = 864000LL; |
50 |
Long64_t olderthan = -1LL; |
51 |
|
52 |
// |
53 |
// |
54 |
TString filerawname = ""; |
55 |
TString filerootname = ""; |
56 |
// |
57 |
TString host = "mysql://localhost/pamelaprod"; |
58 |
TString user = "anonymous"; |
59 |
TString password = ""; |
60 |
// |
61 |
const char *pamdbhost = gSystem->Getenv("PAM_DBHOST"); |
62 |
const char *pamdbuser = gSystem->Getenv("PAM_DBUSER"); |
63 |
const char *pamdbpsw = gSystem->Getenv("PAM_DBPSW"); |
64 |
if ( !pamdbhost ) pamdbhost = ""; |
65 |
if ( !pamdbuser ) pamdbuser = ""; |
66 |
if ( !pamdbpsw ) pamdbpsw = ""; |
67 |
if ( strcmp(pamdbhost,"") ) host = pamdbhost; |
68 |
if ( strcmp(pamdbuser,"") ) user = pamdbuser; |
69 |
if ( strcmp(pamdbpsw,"") ) password = pamdbpsw; |
70 |
// |
71 |
// |
72 |
Bool_t beverbose = true; |
73 |
Bool_t debug = false; |
74 |
Int_t i = 0; |
75 |
// |
76 |
if ( numinp > 1 ){ |
77 |
while ( i < numinp ){ |
78 |
if ( !strcmp(inps[i],"--version") ){ |
79 |
YodaProfilerInfo(true); |
80 |
exit(0); |
81 |
}; |
82 |
if ( !strcmp(inps[i],"-h") || !strcmp(inps[i],"--help") ){ |
83 |
|
84 |
usage(); |
85 |
exit(0); |
86 |
}; |
87 |
if ( !strcmp(inps[i],"-rawFile") ) { |
88 |
if ( numinp-1 < i+1 ){ |
89 |
usage(); |
90 |
exit(1); |
91 |
}; |
92 |
filerawname = (TString)inps[i+1]; |
93 |
}; |
94 |
if ( !strcmp(inps[i],"-yodaFile") ) { |
95 |
if ( numinp-1 < i+1 ){ |
96 |
usage(); |
97 |
exit(1); |
98 |
}; |
99 |
filerootname = (TString)inps[i+1]; |
100 |
}; |
101 |
if ( !strcmp(inps[i],"-boot") ) { |
102 |
if ( numinp-1 < i+1 ){ |
103 |
usage(); |
104 |
exit(1); |
105 |
}; |
106 |
boot = atoi(inps[i+1]); |
107 |
}; |
108 |
if ( !strcmp(inps[i],"-tsync") ) { |
109 |
if ( numinp-1 < i+1 ){ |
110 |
usage(); |
111 |
exit(1); |
112 |
}; |
113 |
tsync = (UInt_t)atoll(inps[i+1]); |
114 |
}; |
115 |
if ( !strcmp(inps[i],"-obt0") ) { |
116 |
if ( numinp-1 < i+1 ){ |
117 |
usage(); |
118 |
exit(1); |
119 |
}; |
120 |
obt0 = (UInt_t)atoll(inps[i+1]); |
121 |
}; |
122 |
if ( !strcmp(inps[i],"-clean") ) { |
123 |
if ( numinp-1 < i+1 ){ |
124 |
usage(); |
125 |
exit(1); |
126 |
}; |
127 |
olderthan = (Long64_t)atoll(inps[i+1]); |
128 |
}; |
129 |
if ( !strcmp(inps[i],"-host") ) { |
130 |
if ( numinp-1 < i+1 ){ |
131 |
usage(); |
132 |
exit(1); |
133 |
}; |
134 |
host = (TString)inps[i+1]; |
135 |
}; |
136 |
if ( !strcmp(inps[i],"-user") ) { |
137 |
if ( numinp-1 < i+1 ){ |
138 |
usage(); |
139 |
exit(1); |
140 |
}; |
141 |
user = (TString)inps[i+1]; |
142 |
}; |
143 |
if ( !strcmp(inps[i],"-psw") ) { |
144 |
if ( numinp-1 < i+1 ){ |
145 |
usage(); |
146 |
exit(1); |
147 |
}; |
148 |
password = (TString)inps[i+1]; |
149 |
}; |
150 |
// |
151 |
if ( !strcmp(inps[i],"-v") || !strcmp(inps[i],"--verbose") ) beverbose = true; |
152 |
// |
153 |
if ( !strcmp(inps[i],"-s") || !strcmp(inps[i],"--silent") ) beverbose = false; |
154 |
// |
155 |
if ( !strcmp(inps[i],"-g") || !strcmp(inps[i],"--debug") ) debug = true; |
156 |
// |
157 |
i++; |
158 |
}; |
159 |
} else { |
160 |
// |
161 |
// no input parameters exit with error, we need at least the run id. |
162 |
// |
163 |
cout << "\n ERROR: NO INPUT PARAMETERS \n"; |
164 |
usage(); |
165 |
exit(1); |
166 |
}; |
167 |
|
168 |
// |
169 |
// If not in verbose mode redirect to /dev/null the stdout and stderr |
170 |
// |
171 |
if ( !beverbose ){ |
172 |
nul = open("/dev/null", O_CREAT | O_RDWR,S_IREAD | S_IWRITE); |
173 |
dup2(nul,1); |
174 |
dup2(nul,2); |
175 |
}; |
176 |
// |
177 |
// Start: |
178 |
// |
179 |
TString message; |
180 |
char *version = YodaProfilerInfo(false); |
181 |
PamelaDBOperations *pamDB = 0; |
182 |
UInt_t sizeofwar = 10; |
183 |
UInt_t WAR[10]; |
184 |
memset(WAR, 0, 10*sizeof(UInt_t)); |
185 |
// |
186 |
printf("\n Welcome to the PAMELA YodaProfiler, version %s \n\n",version); |
187 |
try{ |
188 |
// |
189 |
//------------------------------------------------------------------------------------------- |
190 |
// Create pamDB object and open SQL connection |
191 |
//------------------------------------------------------------------------------------------- |
192 |
if ( beverbose ) printf(" 1 => Initialize and open SQL connection \n"); |
193 |
pamDB = new PamelaDBOperations(host,user,password,filerawname,filerootname,boot,tsync,obt0,debug); |
194 |
pamDB->CheckConnection(); |
195 |
//------------------------------------------------------------------------------------------- |
196 |
// |
197 |
|
198 |
if(pamDB->InsertRaw()){ |
199 |
//------------------------------------------------------------------------------------------- |
200 |
//Insert a Raw file in GL_RAW |
201 |
//------------------------------------------------------------------------------------------- |
202 |
if ( beverbose ) printf(" 2 => Insert a RAW file in GL_RAW \n"); |
203 |
WAR[0] = pamDB->insertPamelaRawFile(); |
204 |
//------------------------------------------------------------------------------------------- |
205 |
}; |
206 |
|
207 |
if(pamDB->InsertRoot()){ |
208 |
|
209 |
if(!pamDB->InsertRaw())printf("=> RAW file not inserted --- the DB might not ( yet ) be filled correctly \n"); |
210 |
pamDB->CheckFile(); |
211 |
//------------------------------------------------------------------------------------------- |
212 |
//Update a single GL_RAW record with its BOOT_NUMBER |
213 |
//------------------------------------------------------------------------------------------- |
214 |
if ( beverbose ) printf(" 3 => Update a single GL_RAW record with its BOOT_NUMBER \n"); |
215 |
WAR[3] = pamDB->assignBOOT_NUMBER(); |
216 |
// if ( WAR[3] ) pamDB->SetNOBOOT(true); |
217 |
if ( WAR[3] && WAR[3] != 1 ) throw -9; |
218 |
//------------------------------------------------------------------------------------------- |
219 |
// |
220 |
//------------------------------------------------------------------------------------------- |
221 |
//Insert an entry in GL_TIMESYNC |
222 |
//------------------------------------------------------------------------------------------- |
223 |
if ( beverbose ) printf(" 4 => Insert an entry in GL_TIMESYNC \n"); |
224 |
WAR[1] = pamDB->insertPamelaGL_TIMESYNC(); |
225 |
//------------------------------------------------------------------------------------------- |
226 |
// |
227 |
//------------------------------------------------------------------------------------------- |
228 |
//Insert unpack ROOT file in GL_ROOT |
229 |
//------------------------------------------------------------------------------------------- |
230 |
if ( beverbose ) printf(" 5 => Insert unpack ROOT file in GL_ROOT \n"); |
231 |
WAR[2] = pamDB->insertPamelaRootFile(); |
232 |
//------------------------------------------------------------------------------------------- |
233 |
// |
234 |
//------------------------------------------------------------------------------------------- |
235 |
//Insert in GL_RUN runs information records relative to a single unpack |
236 |
//------------------------------------------------------------------------------------------- |
237 |
if ( beverbose ) printf(" 6 => Scan physics and store runs in the GL_RUN table\n"); |
238 |
WAR[4] = pamDB->insertPamelaRUN(); |
239 |
//------------------------------------------------------------------------------------------- |
240 |
|
241 |
//------------------------------------------------------------------------------------------- |
242 |
//Insert in GL_CALO_CALIB calibration information records relative to a single unpack |
243 |
//------------------------------------------------------------------------------------------- |
244 |
if ( beverbose ) printf(" 7 => Insert calorimeter calibrations in the GL_CALO_CALIB table\n"); |
245 |
WAR[5] = pamDB->insertCALO_CALIB(); |
246 |
//------------------------------------------------------------------------------------------- |
247 |
|
248 |
//------------------------------------------------------------------------------------------- |
249 |
//Insert in GL_TRK_CALIB calibration information records relative to a single unpack |
250 |
//------------------------------------------------------------------------------------------- |
251 |
if ( beverbose ) printf(" 8 => Insert tracker calibrations in the GL_TRK_CALIB table\n"); |
252 |
WAR[6] = pamDB->insertTRK_CALIB(); |
253 |
//------------------------------------------------------------------------------------------- |
254 |
|
255 |
//------------------------------------------------------------------------------------------- |
256 |
//Insert in GL_S4_CALIB calibration information records relative to a single unpack |
257 |
//------------------------------------------------------------------------------------------- |
258 |
if ( beverbose ) printf(" 9 => Insert S4 calibrations in the GL_S4_CALIB table\n"); |
259 |
WAR[7] = pamDB->insertS4_CALIB(); |
260 |
//------------------------------------------------------------------------------------------- |
261 |
}; |
262 |
// |
263 |
pamDB->CheckValidate(olderthan); |
264 |
// |
265 |
if(pamDB->Validate()){ |
266 |
//------------------------------------------------------------------------------------------- |
267 |
//Clean the GL_RUN_FRAGMENTS |
268 |
//------------------------------------------------------------------------------------------- |
269 |
if ( beverbose ) printf(" 10 => Clean the GL_RUN_FRAGMENTS table (earlier than %s) \n",pamDB->GetCleanTime() ); |
270 |
WAR[8] = pamDB->CleanGL_RUN_FRAGMENTS(); |
271 |
//------------------------------------------------------------------------------------------- |
272 |
|
273 |
//------------------------------------------------------------------------------------------- |
274 |
//Validate runs |
275 |
//------------------------------------------------------------------------------------------- |
276 |
if ( beverbose ) printf(" 11 => Validate runs (earlier than %s)\n",pamDB->GetCleanTime()); |
277 |
WAR[9] = pamDB->ValidateRuns(); |
278 |
//------------------------------------------------------------------------------------------- |
279 |
}; |
280 |
|
281 |
} catch (Int_t exc) { |
282 |
signal = exc; |
283 |
switch(exc){ |
284 |
case -1: message += " DB connection failure"; break; |
285 |
case -2: message += " Connection failure"; break; |
286 |
case -3: message += " Cannot determine the timesync, use the -tsync and -obt0 options to override"; break; |
287 |
case -4: message += " Error querying DB"; break; |
288 |
case -5: message += " Inconsistent OBT/pkt_num"; break; |
289 |
case -6: message += " The file is not in the database"; break; |
290 |
case -8: message += " Event file is empty"; break; |
291 |
case -9: message += " No VarDump no BOOT number, use the -boot option to override"; break; |
292 |
case -10: message += " No results from DB"; break; |
293 |
case -11: message += " Raw file not found"; break; |
294 |
case -12: message += " Cannot open Level0 file"; break; |
295 |
case -13: message += " No consistent OBT/PKT_NUM information"; break; |
296 |
case -14: message += " Not supported yet: run with no events, no runtrailer, no runheader"; break; |
297 |
case -15: message += " Not supported yet: run with no runheader at the beginning/end of file not recognized as run fragment"; break; |
298 |
case -16: message += " No Physics tree in Level0 file"; break; |
299 |
case -17: message += " No RunHeader tree in Level0 file"; break; |
300 |
case -18: message += " No RunTrailer tree in Level0 file"; break; |
301 |
case -19: message += " No Mcmd tree in Level0 file"; break; |
302 |
case -20: message += " No VarDump tree in Level0 file"; break; |
303 |
case -21: message += " No CalibCalPed tree in Level0 file"; break; |
304 |
case -22: message += " No CalibTrk1 tree in Level0 file"; break; |
305 |
case -23: message += " No CalibTrk2 tree in Level0 file"; break; |
306 |
case -24: message += " No CalibS4 tree in Level0 file"; break; |
307 |
case -25: message += " Cannot find the run just inserted"; break; |
308 |
case -26: message += " Raw file not found looking for VarDump"; break; |
309 |
default: message += " Unidentified error"; break; |
310 |
}; |
311 |
printf("\n"); |
312 |
printf(" ERROR (%i) %s \n",exc,message.Data()); |
313 |
printf("\n"); |
314 |
} |
315 |
// |
316 |
// warnings handlers |
317 |
// |
318 |
Bool_t printwarning = false; |
319 |
message=""; |
320 |
for (UInt_t j=0; j<sizeofwar; j++){ |
321 |
if ( WAR[j] ){ |
322 |
printwarning = true; |
323 |
// |
324 |
if ( j == 0 ){ // insertPamelaRaw warnings |
325 |
for (UInt_t bit=0; bit<32; bit++){ |
326 |
if ( WAR[j] & (1 << bit) ){ |
327 |
if ( bit == 0 ) message += "=> RAW file already inserted\n"; |
328 |
else message += "=> Unidentified insertPamelaRaw warning\n"; |
329 |
}; |
330 |
}; |
331 |
}; |
332 |
// |
333 |
if ( j == 1 ){ // insertTimeSync warnings |
334 |
for (UInt_t bit=0; bit<32; bit++){ |
335 |
if ( WAR[j] & (1 << bit) ){ |
336 |
if ( bit == 0 ) message += "=> TIMESYNC already inserted\n"; |
337 |
else if ( bit == 1 ) message += "=> No mcmd timesync in the file\n"; |
338 |
else if ( bit == 2 ) message += "=> No runheaders in the file\n"; |
339 |
else if ( bit == 3 ) message += "=> No runtrailers in the file\n"; |
340 |
else if ( bit == 4 ) message += "=> No mcmd inclination in the file\n"; |
341 |
else message += "=> Unidentified insertTimeSync warning\n"; |
342 |
}; |
343 |
}; |
344 |
}; |
345 |
// |
346 |
if ( j == 2 ){ // insertPamelaRoot warnings |
347 |
for (UInt_t bit=0; bit<32; bit++){ |
348 |
if ( WAR[j] & (1 << bit) ){ |
349 |
if ( bit == 0 ) message += "=> ROOT file already inserted\n"; |
350 |
else message += "=> Unidentified insertPamelaRoot warning\n"; |
351 |
}; |
352 |
}; |
353 |
}; |
354 |
// |
355 |
if ( j == 3 ){ // assignBOOTnumber warnings |
356 |
for (UInt_t bit=0; bit<32; bit++){ |
357 |
if ( WAR[j] & (1 << bit) ){ |
358 |
if ( bit == 0 ) message += "=> BOOT number already inserted\n";// |
359 |
else if ( bit == 1 ) message += "=> VarDump event tree is empty, use the -boot option to override\n";// |
360 |
else if ( bit == 2 ) message += "=> No BOOT number in VarDump(!), use the -boot option to override\n";// |
361 |
else if ( bit == 4 ) message += "=> The file is not in the database looking for VarDump, use the -boot option to override\n";// |
362 |
else message += "=> Unidentified assignBOOTnumber warning\n"; |
363 |
}; |
364 |
}; |
365 |
}; |
366 |
// |
367 |
if ( j == 4 ){ // insertPamelaRUN |
368 |
for (UInt_t bit=0; bit<32; bit++){ |
369 |
if ( WAR[j] & (1 << bit) ){ |
370 |
if ( bit == 0 ) message += "=> Inconsistent PKT/OBT sequence\n"; |
371 |
else if ( bit == 1 ) message += "=> No physics events in the file\n"; |
372 |
else if ( bit == 2 ) message += "=> Less than 2 physics events in the file\n"; |
373 |
else message += "=> Unidentified insertPamelaRun warning\n"; |
374 |
}; |
375 |
}; |
376 |
}; |
377 |
// |
378 |
if ( j == 5 ){ // insertCALO_CALIB |
379 |
for (UInt_t bit=0; bit<32; bit++){ |
380 |
if ( WAR[j] & (1 << bit) ){ |
381 |
if ( bit == 0 ) message += "=> No calorimeter calibrations in the file\n"; |
382 |
else message += "=> Unidentified insertCaloCalib warning\n"; |
383 |
}; |
384 |
}; |
385 |
}; |
386 |
// |
387 |
// |
388 |
if ( j == 6 ){ // insertTRACKER_CALIB |
389 |
for (UInt_t bit=0; bit<32; bit++){ |
390 |
if ( WAR[j] & (1 << bit) ){ |
391 |
if ( bit == 0 ) message += "=> No tracker calibrations in the file\n"; |
392 |
else message += "=> Unidentified insertTrkCalib warning\n"; |
393 |
}; |
394 |
}; |
395 |
}; |
396 |
// |
397 |
// |
398 |
if ( j == 7 ){ // insertS4_CALIB |
399 |
for (UInt_t bit=0; bit<32; bit++){ |
400 |
if ( WAR[j] & (1 << bit) ){ |
401 |
if ( bit == 0 ) message += "=> No s4 calibrations in the file\n"; |
402 |
else message += "=> Unidentified insertS4calib warning\n"; |
403 |
}; |
404 |
}; |
405 |
}; |
406 |
// |
407 |
// |
408 |
if ( j == 8 ){ // CleanGL_RUN_FRAGMENTS |
409 |
for (UInt_t bit=0; bit<32; bit++){ |
410 |
if ( WAR[j] & (1 << bit) ){ |
411 |
if ( bit == 0 ) message += "=> Skip the GL_RUN_FRAGMENTS table cleaning\n"; |
412 |
else message += "=> Unidentified CleanGL_RUN_FRAGMENTS warning\n"; |
413 |
}; |
414 |
}; |
415 |
}; |
416 |
// |
417 |
if ( j == 9 ){ // ValidateRuns |
418 |
for (UInt_t bit=0; bit<32; bit++){ |
419 |
if ( WAR[j] & (1 << bit) ){ |
420 |
if ( bit == 0 ) message += "=> Skip the run validation \n"; |
421 |
else message += "=> Unidentified ValidateRuns warning\n"; |
422 |
}; |
423 |
}; |
424 |
}; |
425 |
}; |
426 |
}; |
427 |
// |
428 |
if ( printwarning ){ |
429 |
printf("\n"); |
430 |
printf(" WARNING(s):\n%s\n",message.Data()); |
431 |
printf("\n"); |
432 |
if ( !signal ) signal = 1; |
433 |
}; |
434 |
// |
435 |
//--------------------------------------------------------------------------------------- |
436 |
// Close and exit |
437 |
//--------------------------------------------------------------------------------------- |
438 |
if ( beverbose ) printf(" 12 => Free objects and close SQL connection \n"); |
439 |
pamDB->Close(); |
440 |
// |
441 |
printf("\n"); |
442 |
printf(" Finished, exiting...\n"); |
443 |
printf("\n"); |
444 |
// |
445 |
// Close redirection if the case. |
446 |
// |
447 |
if ( !beverbose ) close(nul); |
448 |
// |
449 |
exit(signal); |
450 |
// |
451 |
} |