1 |
// |
2 |
#include <iostream> |
3 |
#include <sstream> |
4 |
#include <errno.h> |
5 |
// |
6 |
#include <TSystem.h> |
7 |
// |
8 |
#include <GLTables.h> |
9 |
#include <PamelaDBOperations.h> |
10 |
#include <YodaProfilerVerl2.h> |
11 |
// |
12 |
using namespace std; |
13 |
// |
14 |
// Usage subroutine |
15 |
// |
16 |
void usage(){ |
17 |
printf("\nUsage:\n"); |
18 |
printf("\n YodaProfiler [options] -rawFile raw_filename -yodaFile yoda_filename \n"); |
19 |
printf("\n -rawFile full path to the raw file\n"); |
20 |
printf( " -yodaFile full path to the YODA file OR ID of the file to be processed\n"); |
21 |
printf("\n Options are:\n\n"); |
22 |
printf(" --version print informations about compilation and exit\n"); |
23 |
printf(" -h | --help print this help and exit \n"); |
24 |
printf(" -v | --verbose be verbose [default]\n"); |
25 |
printf(" -s | --silent print nothing on STDOUT\n"); |
26 |
printf(" -g | --debug be very verbose [default: no]\n"); |
27 |
printf(" -p | --pedantic be strict in checks, exit with error if any problem is found [default: no]\n"); |
28 |
printf(" -boot number CPU boot number [default = taken from VarDump]\n"); |
29 |
printf(" -autoboot if no VarDump found try to determine the BOOT number\n"); |
30 |
printf(" looking at timesync [default]\n"); |
31 |
printf(" -no-autoboot disable previous check\n"); |
32 |
printf(" -tsync number timesync (s) [default = taken from data]\n"); |
33 |
printf(" -obt0 number obt at timesync (ms) [default = taken from data]\n"); |
34 |
printf(" -dworbit number number is the downlink orbit number (to be used with non-standard names)\n"); |
35 |
printf(" -static use static path inside the DB instead of symbolic names\n"); |
36 |
// printf(" -gpamela shortcut to \"-clean 0 -obt0 1 -tsync 1 -no-autoboot -boot 1 -dworbit 1 -static\"\n"); |
37 |
printf(" -gpamela shortcut to \"-clean 0 -obt0 1 -no-autoboot -dworbit 1 -static\"\n"); |
38 |
printf(" -clean number number in seconds after which the fragment table\n"); |
39 |
printf(" can be cleaned and runs validated [default = -1 do not clean],\n"); |
40 |
printf(" if 0 force cleaning immediatly, if negative do not clean\n"); |
41 |
printf(" -remove file remove file and all related runs and calibrations from DB\n"); |
42 |
printf(" file must be the YODA filename (full path is not needed)\n"); |
43 |
printf(" 'same' can be used if in conjuction with -yodaFile\n"); |
44 |
printf(" -validate file validates runs between the two closest calibration to file \n"); |
45 |
printf(" not belonging to file itself. File must be the YODA filename\n"); |
46 |
printf(" 'same' can be used if in conjuction with -yodaFile\n"); |
47 |
printf(" -cleanfrag file clean run fragments for file only\n"); |
48 |
printf(" File must be the YODA filename\n"); |
49 |
printf(" 'same' can be used if in conjuction with -yodaFile\n"); |
50 |
printf(" -runpieces when cleaning fragments check if run are divided in more pieces [default: false in standard case, true for chewbacca files]\n"); |
51 |
printf(" -nofrag do not leave runs in the fragment table and look for fragments\n"); |
52 |
printf(" in the GL_RUN table.\n"); |
53 |
printf(" -f | -force to be used to reprocess a file or to process a file\n"); |
54 |
printf(" when already validated the surroundings, it is equivalent to:\n"); |
55 |
printf(" -remove same -validate same -cleanfrag same -nofrag\n"); |
56 |
printf(" -check performs some test on the GL_RUN table to check its consistency\n"); |
57 |
printf(" -checkfrom idrun performs some test on the GL_RUN table to check its consistency starting from run number idrun\n"); |
58 |
printf(" -checkto idrun performs some test on the GL_RUN table to check its consistency arriving till run number idrun\n"); |
59 |
printf(" -host name of the DB host [default = $PAM_DBHOST or mysql://localhost/pamelaprod]\n"); |
60 |
printf(" -user username for the DB connection [default = $PAM_DBUSER or \"anonymous\"] \n"); |
61 |
printf(" -psw password for the DB connection [default = $PAM_DBPSW or \"\"]\n"); |
62 |
printf(" -tle <file> ascii file containing TLE obtained from celestrak.org or space-track.org [default = no]\n"); |
63 |
printf("\n The order of input files and options does not matter. \n"); |
64 |
printf("\n Example: \n"); |
65 |
printf(" YodaProfiler -yodaFile /path/to/raw/files/000_000_00000_cln2.root -rawFile /path/to/filesfromyoda/000_000_00000_cln2.pam -v \n\n"); |
66 |
}; |
67 |
// |
68 |
int main(int numinp, char *inps[]){ |
69 |
// |
70 |
// Variables booking |
71 |
// |
72 |
Int_t signal = 0; |
73 |
Int_t nul = 0; |
74 |
UInt_t boot = 0; |
75 |
UInt_t tsync = 0; |
76 |
UInt_t obt0 = 0; |
77 |
UInt_t dwinput = 0; |
78 |
UInt_t chfrom = 0; |
79 |
UInt_t chto = 0; |
80 |
Long64_t olderthan = -1LL; |
81 |
Bool_t runpieces = false; |
82 |
// |
83 |
// |
84 |
TString filerawname = ""; |
85 |
TString filerootname = ""; |
86 |
// |
87 |
TString host = "mysql://localhost/pamelaprod"; |
88 |
TString user = "anonymous"; |
89 |
TString password = ""; |
90 |
// |
91 |
TString tlefilename = ""; |
92 |
// |
93 |
const char *pamdbhost = gSystem->Getenv("PAM_DBHOST"); |
94 |
const char *pamdbuser = gSystem->Getenv("PAM_DBUSER"); |
95 |
const char *pamdbpsw = gSystem->Getenv("PAM_DBPSW"); |
96 |
if ( !pamdbhost ) pamdbhost = ""; |
97 |
if ( !pamdbuser ) pamdbuser = ""; |
98 |
if ( !pamdbpsw ) pamdbpsw = ""; |
99 |
if ( strcmp(pamdbhost,"") ) host = pamdbhost; |
100 |
if ( strcmp(pamdbuser,"") ) user = pamdbuser; |
101 |
if ( strcmp(pamdbpsw,"") ) password = pamdbpsw; |
102 |
// |
103 |
// |
104 |
Bool_t chewbacca = false; |
105 |
Bool_t staticp = false; |
106 |
Bool_t beverbose = true; |
107 |
Bool_t debug = false; |
108 |
Bool_t autoboot = true; |
109 |
Bool_t gpamela = false; |
110 |
// |
111 |
Bool_t remove = false; |
112 |
TString remfile = ""; |
113 |
// |
114 |
Bool_t forceclean = false; |
115 |
TString fcleanfile = ""; |
116 |
// |
117 |
Bool_t validate = false; |
118 |
TString validfile = ""; |
119 |
// |
120 |
Bool_t nofrag = false; |
121 |
// |
122 |
Bool_t force = false; |
123 |
// |
124 |
Bool_t check = false; |
125 |
// |
126 |
Bool_t pedantic = false; |
127 |
// |
128 |
Int_t i = 0; |
129 |
// |
130 |
if ( numinp > 1 ){ |
131 |
while ( i < numinp ){ |
132 |
if ( !strcmp(inps[i],"--version") ){ |
133 |
YodaProfilerInfo(true); |
134 |
exit(0); |
135 |
}; |
136 |
if ( !strcmp(inps[i],"-h") || !strcmp(inps[i],"--help") ){ |
137 |
|
138 |
usage(); |
139 |
exit(0); |
140 |
}; |
141 |
if ( !strcmp(inps[i],"-rawFile") ) { |
142 |
if ( numinp-1 < i+1 ){ |
143 |
usage(); |
144 |
exit(1); |
145 |
}; |
146 |
filerawname = (TString)inps[i+1]; |
147 |
}; |
148 |
if ( !strcmp(inps[i],"-yodaFile") ) { |
149 |
if ( numinp-1 < i+1 ){ |
150 |
usage(); |
151 |
exit(1); |
152 |
}; |
153 |
filerootname = (TString)inps[i+1]; |
154 |
if ( filerootname.IsDigit() ){ |
155 |
chewbacca = true; |
156 |
runpieces = true; |
157 |
}; |
158 |
}; |
159 |
if ( !strcmp(inps[i],"-remove") ) { |
160 |
if ( numinp-1 < i+1 ){ |
161 |
usage(); |
162 |
exit(1); |
163 |
}; |
164 |
remfile = (TString)inps[i+1]; |
165 |
remove = true; |
166 |
}; |
167 |
if ( !strcmp(inps[i],"-cleanfrag") ) { |
168 |
if ( numinp-1 < i+1 ){ |
169 |
usage(); |
170 |
exit(1); |
171 |
}; |
172 |
fcleanfile = (TString)inps[i+1]; |
173 |
forceclean = true; |
174 |
}; |
175 |
if ( !strcmp(inps[i],"-validate") ) { |
176 |
if ( numinp-1 < i+1 ){ |
177 |
usage(); |
178 |
exit(1); |
179 |
}; |
180 |
validfile = (TString)inps[i+1]; |
181 |
validate = true; |
182 |
}; |
183 |
if ( !strcmp(inps[i],"-gpamela") ) { |
184 |
gpamela = true; |
185 |
}; |
186 |
if ( !strcmp(inps[i],"-runpieces") ) { |
187 |
runpieces = true; |
188 |
}; |
189 |
if ( !strcmp(inps[i],"-static") ) { |
190 |
staticp = true; |
191 |
}; |
192 |
if ( !strcmp(inps[i],"-autoboot") ) { |
193 |
autoboot = true; |
194 |
}; |
195 |
if ( !strcmp(inps[i],"-no-autoboot") ) { |
196 |
autoboot = false; |
197 |
}; |
198 |
if ( !strcmp(inps[i],"-boot") ) { |
199 |
if ( numinp-1 < i+1 ){ |
200 |
usage(); |
201 |
exit(1); |
202 |
}; |
203 |
boot = atoi(inps[i+1]); |
204 |
}; |
205 |
if ( !strcmp(inps[i],"-checkfrom") ) { |
206 |
if ( numinp-1 < i+1 ){ |
207 |
usage(); |
208 |
exit(1); |
209 |
}; |
210 |
chfrom = atoi(inps[i+1]); |
211 |
check = true; |
212 |
}; |
213 |
if ( !strcmp(inps[i],"-checkto") ) { |
214 |
if ( numinp-1 < i+1 ){ |
215 |
usage(); |
216 |
exit(1); |
217 |
}; |
218 |
chto = atoi(inps[i+1]); |
219 |
check = true; |
220 |
}; |
221 |
if ( !strcmp(inps[i],"-tsync") ) { |
222 |
if ( numinp-1 < i+1 ){ |
223 |
usage(); |
224 |
exit(1); |
225 |
}; |
226 |
tsync = (UInt_t)atoll(inps[i+1]); |
227 |
}; |
228 |
if ( !strcmp(inps[i],"-obt0") ) { |
229 |
if ( numinp-1 < i+1 ){ |
230 |
usage(); |
231 |
exit(1); |
232 |
}; |
233 |
obt0 = (UInt_t)atoll(inps[i+1]); |
234 |
}; |
235 |
if ( !strcmp(inps[i],"-dworbit") ) { |
236 |
if ( numinp-1 < i+1 ){ |
237 |
usage(); |
238 |
exit(1); |
239 |
}; |
240 |
dwinput = (UInt_t)atoll(inps[i+1]); |
241 |
}; |
242 |
if ( !strcmp(inps[i],"-clean") ) { |
243 |
if ( numinp-1 < i+1 ){ |
244 |
usage(); |
245 |
exit(1); |
246 |
}; |
247 |
olderthan = (Long64_t)atoll(inps[i+1]); |
248 |
}; |
249 |
if ( !strcmp(inps[i],"-host") ) { |
250 |
if ( numinp-1 < i+1 ){ |
251 |
usage(); |
252 |
exit(1); |
253 |
}; |
254 |
host = (TString)inps[i+1]; |
255 |
}; |
256 |
if ( !strcmp(inps[i],"-user") ) { |
257 |
if ( numinp-1 < i+1 ){ |
258 |
usage(); |
259 |
exit(1); |
260 |
}; |
261 |
user = (TString)inps[i+1]; |
262 |
}; |
263 |
if ( !strcmp(inps[i],"-psw") ) { |
264 |
if ( numinp-1 < i+1 ){ |
265 |
usage(); |
266 |
exit(1); |
267 |
}; |
268 |
password = (TString)inps[i+1]; |
269 |
}; |
270 |
if ( !strcmp(inps[i],"-tle") ) { |
271 |
if ( numinp-1 < i+1 ){ |
272 |
usage(); |
273 |
exit(1); |
274 |
}; |
275 |
tlefilename = (TString)inps[i+1]; |
276 |
}; |
277 |
// |
278 |
if ( !strcmp(inps[i],"-v") || !strcmp(inps[i],"--verbose") ) beverbose = true; |
279 |
// |
280 |
if ( !strcmp(inps[i],"-s") || !strcmp(inps[i],"--silent") ) beverbose = false; |
281 |
// |
282 |
if ( !strcmp(inps[i],"-g") || !strcmp(inps[i],"--debug") ) debug = true; |
283 |
// |
284 |
if ( !strcmp(inps[i],"-f") || !strcmp(inps[i],"-force") ) force = true; |
285 |
// |
286 |
if ( !strcmp(inps[i],"-p") || !strcmp(inps[i],"--pedantic") ) pedantic = true; |
287 |
// |
288 |
if ( !strcmp(inps[i],"-nofrag") ) nofrag = true; |
289 |
// |
290 |
if ( !strcmp(inps[i],"-check") ) check = true; |
291 |
// |
292 |
i++; |
293 |
}; |
294 |
} else { |
295 |
// |
296 |
// no input parameters exit with error, we need at least the run id. |
297 |
// |
298 |
cout << "\n ERROR: NO INPUT PARAMETERS \n"; |
299 |
usage(); |
300 |
exit(1); |
301 |
}; |
302 |
|
303 |
// |
304 |
// If not in verbose mode redirect to /dev/null the stdout and stderr |
305 |
// |
306 |
if ( !beverbose ){ |
307 |
nul = open("/dev/null", O_CREAT | O_RDWR,S_IREAD | S_IWRITE); |
308 |
dup2(nul,1); |
309 |
dup2(nul,2); |
310 |
}; |
311 |
// |
312 |
if ( !strcmp(filerootname.Data(),"") ){ |
313 |
if ( (validate && !strcmp(validfile.Data(),"same")) || |
314 |
(remove && !strcmp(remfile.Data(),"same")) || |
315 |
(forceclean && !strcmp(fcleanfile.Data(),"same")) || force ){ |
316 |
printf("\n ERROR IN INPUT PARAMETERS \n"); |
317 |
usage(); |
318 |
exit(1); |
319 |
}; |
320 |
} else { |
321 |
if ( validate && !strcmp(validfile.Data(),"same") ) validfile = (TString)gSystem->BaseName(filerootname.Data()); |
322 |
if ( remove && !strcmp(remfile.Data(),"same") ) remfile = (TString)gSystem->BaseName(filerootname.Data()); |
323 |
if ( forceclean && !strcmp(fcleanfile.Data(),"same") ) fcleanfile = (TString)gSystem->BaseName(filerootname.Data()); |
324 |
}; |
325 |
// |
326 |
if ( force ){ |
327 |
nofrag = true; |
328 |
forceclean = true; |
329 |
remove = true; |
330 |
validate = true; |
331 |
fcleanfile = (TString)gSystem->BaseName(filerootname.Data()); |
332 |
remfile = fcleanfile; |
333 |
validfile = fcleanfile; |
334 |
}; |
335 |
// |
336 |
if ( chewbacca ){ |
337 |
// |
338 |
// temporary settings |
339 |
// |
340 |
// pedantic = true; |
341 |
// debug = true; |
342 |
// end temporary settings |
343 |
if ( debug ) printf("\n\n WOW! using the new software features \n\n"); |
344 |
}; |
345 |
// |
346 |
const char *paml0 = gSystem->Getenv("PAM_L0"); |
347 |
const char *paml2 = gSystem->Getenv("PAM_L2"); |
348 |
const char *pamraw = gSystem->Getenv("PAM_RAW"); |
349 |
if ( !paml0 || !paml2 || !pamraw ){ |
350 |
printf(" WARNING: to use symbolic paths in DB you must set up PAM_L0, PAM_L2 and PAM_RAW env var!\n Using static paths\n"); |
351 |
staticp = true; |
352 |
}; |
353 |
// |
354 |
// |
355 |
GL_TABLES *glt = new GL_TABLES(host,user,password); |
356 |
// |
357 |
if ( gpamela ){ |
358 |
// // -clean 0 -obt0 1 -tsync 1 -boot 1 -dworbit 1 |
359 |
// -clean 0 -obt0 1 -dworbit 1 |
360 |
if ( olderthan < 0LL ) olderthan = 0LL; |
361 |
if ( !obt0 ) obt0 = 1; |
362 |
// if ( !tsync ) tsync = 1; |
363 |
// if ( !boot ) boot = 1; |
364 |
if ( !dwinput ) dwinput = 1; |
365 |
staticp = true; |
366 |
autoboot = false; |
367 |
}; |
368 |
// |
369 |
if ( filerawname == "" && filerootname != "" ){ |
370 |
filerawname = "/not_given/"+(TString)gSystem->BaseName(filerootname.Data()); |
371 |
filerawname = filerawname.ReplaceAll(".root",5,".pam",4); |
372 |
// printf("filerawname %s \n",filerawname.Data()); |
373 |
}; |
374 |
// |
375 |
// Start: |
376 |
TString message; |
377 |
char *version = YodaProfilerInfo(false); |
378 |
PamelaDBOperations *pamDB = 0; |
379 |
UInt_t sizeofwar = 12; |
380 |
UInt_t WAR[12]; |
381 |
memset(WAR, 0, sizeofwar*sizeof(UInt_t)); |
382 |
// |
383 |
printf("\n Welcome to the PAMELA YodaProfiler, version %s \n\n",version); |
384 |
try{ |
385 |
// |
386 |
//------------------------------------------------------------------------------------------- |
387 |
// Create pamDB object and open SQL connection |
388 |
//------------------------------------------------------------------------------------------- |
389 |
if ( beverbose ) printf(" 1 => Initialize and open SQL connection \n"); |
390 |
pamDB = new PamelaDBOperations(host,user,password,filerawname,filerootname,boot,tsync,obt0,debug,tlefilename,dwinput,staticp,gpamela); |
391 |
pamDB->CheckConnection(); |
392 |
pamDB->LockTables(); |
393 |
pamDB->OpenL0File(filerootname); |
394 |
//------------------------------------------------------------------------------------------- |
395 |
// |
396 |
// |
397 |
pamDB->SetNoFrag(nofrag); |
398 |
pamDB->SetAutoBoot(autoboot); |
399 |
pamDB->SetPedantic(pedantic); |
400 |
// |
401 |
if ( remove ){ |
402 |
//------------------------------------------------------------------------------------------- |
403 |
// Remove a file and, on cascade, all that follows from the DB |
404 |
//------------------------------------------------------------------------------------------- |
405 |
if ( beverbose ) printf(" X => Remove file %s from DB \n",((TString)gSystem->BaseName(remfile)).Data()); |
406 |
WAR[11] = pamDB->removeFile((TString)gSystem->BaseName(remfile.Data())); |
407 |
//------------------------------------------------------------------------------------------- |
408 |
}; |
409 |
// |
410 |
if( pamDB->InsertRaw() ){ |
411 |
//------------------------------------------------------------------------------------------- |
412 |
//Insert a Raw file in GL_RAW |
413 |
//------------------------------------------------------------------------------------------- |
414 |
if ( beverbose ) printf(" 2 => Insert a RAW file in GL_RAW \n"); |
415 |
WAR[0] = pamDB->insertPamelaRawFile(); |
416 |
//------------------------------------------------------------------------------------------- |
417 |
}; |
418 |
// |
419 |
if( pamDB->InsertRoot() ){ |
420 |
// |
421 |
if( !pamDB->InsertRaw() && !chewbacca ) printf("=> RAW file not inserted --- the DB might not ( yet ) be filled correctly \n"); |
422 |
pamDB->CheckFile(); |
423 |
// |
424 |
// Set upper and lower limits (taken out from insertPamelaGL_TIMESYNC()) |
425 |
// |
426 |
WAR[1] = pamDB->SetUpperLimits(); |
427 |
//------------------------------------------------------------------------------------------- |
428 |
//Insert an entry in GL_TIMESYNC |
429 |
//------------------------------------------------------------------------------------------- |
430 |
if ( beverbose ) printf(" 3 => Insert an entry in GL_TIMESYNC \n"); |
431 |
WAR[1] += pamDB->insertPamelaGL_TIMESYNC(); |
432 |
//------------------------------------------------------------------------------------------- |
433 |
// |
434 |
//------------------------------------------------------------------------------------------- |
435 |
//Update a single GL_RAW record with its BOOT_NUMBER |
436 |
//------------------------------------------------------------------------------------------- |
437 |
if ( beverbose ) printf(" 4 => Update a single GL_RAW record with its BOOT_NUMBER \n"); |
438 |
WAR[3] = pamDB->assignBOOT_NUMBER(); |
439 |
if ( WAR[3] && WAR[3] != 1 && WAR[3] != 8 ) throw -9; |
440 |
//------------------------------------------------------------------------------------------- |
441 |
// |
442 |
//------------------------------------------------------------------------------------------- |
443 |
//Insert unpack ROOT file in GL_ROOT |
444 |
//------------------------------------------------------------------------------------------- |
445 |
if ( beverbose ) printf(" 5 => Insert unpacked ROOT file in GL_ROOT \n"); |
446 |
WAR[2] = pamDB->insertPamelaRootFile(); |
447 |
//------------------------------------------------------------------------------------------- |
448 |
// |
449 |
//------------------------------------------------------------------------------------------- |
450 |
//Insert in GL_RUN runs information records relative to a single unpack |
451 |
//------------------------------------------------------------------------------------------- |
452 |
if ( beverbose ) printf(" 6 => Scan physics and store runs in the GL_RUN table\n"); |
453 |
WAR[4] = pamDB->insertPamelaRUN(); |
454 |
//------------------------------------------------------------------------------------------- |
455 |
|
456 |
//------------------------------------------------------------------------------------------- |
457 |
//Insert in GL_CALO_CALIB calibration information records relative to a single unpack |
458 |
//------------------------------------------------------------------------------------------- |
459 |
if ( beverbose ) printf(" 7 => Insert calorimeter calibrations in the GL_CALO_CALIB table\n"); |
460 |
WAR[5] = pamDB->insertCALO_CALIB(); |
461 |
//------------------------------------------------------------------------------------------- |
462 |
|
463 |
if ( !gpamela ){ |
464 |
//--------------------------------------------------------------------------------------------------------------------- |
465 |
//Insert in GL_CALOPULSE_CALIB calibration PULSE information records relative to a single unpack (only for real data!) |
466 |
//--------------------------------------------------------------------------------------------------------------------- |
467 |
if ( beverbose ) printf(" 7b => Insert calorimeter pulse calibrations in the GL_CALOPULSE_CALIB table\n"); |
468 |
WAR[5] += pamDB->insertCALOPULSE_CALIB(); |
469 |
//------------------------------------------------------------------------------------------- |
470 |
}; |
471 |
|
472 |
//------------------------------------------------------------------------------------------- |
473 |
//Insert in GL_TRK_CALIB calibration information records relative to a single unpack |
474 |
//------------------------------------------------------------------------------------------- |
475 |
if ( beverbose ) printf(" 8 => Insert tracker calibrations in the GL_TRK_CALIB table\n"); |
476 |
WAR[6] = pamDB->insertTRK_CALIB(); |
477 |
//------------------------------------------------------------------------------------------- |
478 |
|
479 |
//------------------------------------------------------------------------------------------- |
480 |
//Insert in GL_S4_CALIB calibration information records relative to a single unpack |
481 |
//------------------------------------------------------------------------------------------- |
482 |
if ( beverbose ) printf(" 9 => Insert S4 calibrations in the GL_S4_CALIB table\n"); |
483 |
WAR[7] = pamDB->insertS4_CALIB(); |
484 |
//------------------------------------------------------------------------------------------- |
485 |
}; |
486 |
// |
487 |
if ( forceclean ){ |
488 |
//------------------------------------------------------------------------------------------- |
489 |
//Clean the GL_RUN_FRAGMENTS for the given file |
490 |
//------------------------------------------------------------------------------------------- |
491 |
if ( beverbose ) printf(" 10 => Clean the GL_RUN_FRAGMENTS table for file %s \n",fcleanfile.Data()); |
492 |
WAR[8] = pamDB->CleanGL_RUN_FRAGMENTS((TString)gSystem->BaseName(fcleanfile.Data()),runpieces); |
493 |
}; |
494 |
// |
495 |
// |
496 |
if ( validate ){ |
497 |
//------------------------------------------------------------------------------------------- |
498 |
//Validate runs |
499 |
//------------------------------------------------------------------------------------------- |
500 |
if ( beverbose ) printf(" 11 => Validate runs table for file %s \n",validfile.Data()); |
501 |
WAR[9] = pamDB->ValidateRuns((TString)gSystem->BaseName(validfile.Data())); |
502 |
//------------------------------------------------------------------------------------------- |
503 |
}; |
504 |
// |
505 |
pamDB->CheckValidate(olderthan); |
506 |
// |
507 |
if( pamDB->Validate() ){ |
508 |
//------------------------------------------------------------------------------------------- |
509 |
//Clean the GL_RUN_FRAGMENTS |
510 |
//------------------------------------------------------------------------------------------- |
511 |
if ( beverbose ) printf(" 10 => Clean the GL_RUN_FRAGMENTS table (earlier than %s) \n",pamDB->GetCleanTime() ); |
512 |
WAR[8] = pamDB->CleanGL_RUN_FRAGMENTS(runpieces); |
513 |
//------------------------------------------------------------------------------------------- |
514 |
//------------------------------------------------------------------------------------------- |
515 |
//Validate runs |
516 |
//------------------------------------------------------------------------------------------- |
517 |
if ( beverbose ) printf(" 11 => Validate runs (earlier than %s)\n",pamDB->GetCleanTime()); |
518 |
WAR[9] = pamDB->ValidateRuns(); |
519 |
//------------------------------------------------------------------------------------------- |
520 |
}; |
521 |
|
522 |
if(! tlefilename.IsNull() ) { |
523 |
//---------------------------------------------- |
524 |
//Populate GL_TLE table using the file provided |
525 |
//---------------------------------------------- |
526 |
if ( beverbose ) printf(" 12 => Insert TLE elements in the GL_TLE table from file %s \n",tlefilename.Data()); |
527 |
WAR[10] = pamDB->populateTLE(); |
528 |
} |
529 |
|
530 |
if ( check ){ |
531 |
//---------------------------------------------- |
532 |
//Check GL_RUN table consistency |
533 |
//---------------------------------------------- |
534 |
if ( beverbose ) printf(" 13 => Check GL_RUN table consistency\n"); |
535 |
UInt_t ch = pamDB->Check(chfrom,chto); |
536 |
if ( !ch ){ |
537 |
printf(" GL_RUN table seems ok!\n"); |
538 |
} else { |
539 |
printf(" Problems found in the GL_RUN table!\n"); |
540 |
}; |
541 |
}; |
542 |
|
543 |
} catch (Int_t exc) { |
544 |
signal = exc; |
545 |
switch(exc){ |
546 |
case -1: message += " DB connection failure"; break; |
547 |
case -2: message += " Connection failure"; break; |
548 |
case -3: message += " Cannot determine the timesync, use the -tsync and -obt0 options to override"; break; |
549 |
case -4: message += " Error querying DB"; break; |
550 |
case -5: message += " Inconsistent OBT/pkt_num"; break; |
551 |
case -6: message += " The file is not in the database"; break; |
552 |
case -7: message += " Cannot open TLE file"; break; |
553 |
case -8: message += " Event file is empty"; break; |
554 |
case -9: message += " No VarDump no BOOT number, use the -boot option to override"; break; |
555 |
case -10: message += " No results from DB"; break; |
556 |
case -11: message += " Raw file not found"; break; |
557 |
case -12: message += " Cannot open Level0 file"; break; |
558 |
case -13: message += " No consistent OBT/PKT_NUM information"; break; |
559 |
case -14: message += " Not supported yet: run with no events, no runtrailer, no runheader"; break; |
560 |
case -15: message += " Not supported yet: run with no runheader at the beginning/end of file not recognized as run fragment"; break; |
561 |
case -16: message += " No Physics tree in Level0 file"; break; |
562 |
case -17: message += " No RunHeader tree in Level0 file"; break; |
563 |
case -18: message += " No RunTrailer tree in Level0 file"; break; |
564 |
case -19: message += " No Mcmd tree in Level0 file"; break; |
565 |
case -20: message += " No VarDump tree in Level0 file"; break; |
566 |
case -21: message += " No CalibCalPed tree in Level0 file"; break; |
567 |
case -22: message += " No CalibTrk1 tree in Level0 file"; break; |
568 |
case -23: message += " No CalibTrk2 tree in Level0 file"; break; |
569 |
case -24: message += " No CalibS4 tree in Level0 file"; break; |
570 |
case -25: message += " Cannot find the run just inserted"; break; |
571 |
case -26: message += " Raw file not found looking for VarDump"; break; |
572 |
case -27: message += " Cannot determine downlink orbit, wrong filename format?"; break; |
573 |
case -28: message += " Cannot assign a RUN ID unique number!"; break; |
574 |
case -29: message += " No VarDump and impossible to find a consistent BOOT number, use the -boot option to override"; break; |
575 |
case -30: message += " Old database selected, no GL_CALOPULSE_CALIB table in the DB!"; break; |
576 |
case -31: message += " No CalibCalPulse1 tree in Level0 file"; break; |
577 |
case -32: message += " No CalibCalPulse2 tree in Level0 file"; break; |
578 |
case -66: message += " PEDANTIC: REPETITION"; break; |
579 |
case -67: message += " PEDANTIC: TIMESYNC ALREADY INSERTED"; break; |
580 |
case -68: message += " PEDANTIC: NO TIMESYNC IN THE FILE"; break; |
581 |
case -69: message += " PEDANTIC: RUN FRAGMENT ALREADY INSERTED"; break; |
582 |
case -70: message += " PEDANTIC: RUN ALREADY INSERTED"; break; |
583 |
case -71: message += " PEDANTIC: OVERLAPPING RUNS (FIRST)"; break; |
584 |
case -72: message += " PEDANTIC: OVERLAPPING RUNS (LAST)"; break; |
585 |
case -73: message += " PEDANTIC: CALO CALIB ALREADY INSERTED"; break; |
586 |
case -74: message += " PEDANTIC: CALO CALIB REPEATED"; break; |
587 |
case -75: message += " PEDANTIC: CALOPULSE1 CALIB ALREADY INSERTED"; break; |
588 |
case -76: message += " PEDANTIC: CALOPULSE1 CALIB REPEATED"; break; |
589 |
case -77: message += " PEDANTIC: CALOPULSE2 CALIB ALREADY INSERTED"; break; |
590 |
case -78: message += " PEDANTIC: CALOPULSE2 CALIB REPEATED"; break; |
591 |
case -79: message += " PEDANTIC: TRK1 CALIB REPEATED"; break; |
592 |
case -80: message += " PEDANTIC: TRK CALIB ALREADY INSERTED"; break; |
593 |
case -81: message += " PEDANTIC: S4 CALIB ALREADY INSERTED"; break; |
594 |
case -82: message += " PEDANTIC: S4 CALIB REPEATED"; break; |
595 |
case -83: message += " PEDANTIC: CLEANING ERROR, RUN ALREADY INSERTED IN THE GL_RUN TABLE"; break; |
596 |
case -84: message += " CHEWBACCA: problems querying the ROOT_TABLE_MERGING table"; break; |
597 |
case -85: message += " CHEWBACCA: problems querying the ROOT_TABLE table"; break; |
598 |
case -86: message += " PEDANTIC: RUN ALREADY INSERTED IN THE GL_RUN TABLE"; break; |
599 |
case -87: message += " PEDANTIC: THE RUN SHOULD HAVE ALREADY BEEN TREATED BY HANDLERUN()!"; break; |
600 |
case -88: message += " PEDANTIC: INCONSISTENT PKT/OBT SEQUENCE"; break; |
601 |
case -89: message += " PEDANTIC: CANNOT FIND PKT/OBT SEQUENCE IN THE POINTED FILE"; break; |
602 |
case -90: message += " No PhysEndRun tree in the file"; break; |
603 |
case -91: message += " PEDANTIC: Repetition of PhysEndRun data"; break; |
604 |
default: message += " Unidentified error"; break; |
605 |
}; |
606 |
printf("\n"); |
607 |
printf(" ERROR (%i) %s \n",exc,message.Data()); |
608 |
printf("\n"); |
609 |
} |
610 |
// |
611 |
// warnings handlers |
612 |
// |
613 |
Bool_t printwarning = false; |
614 |
message=""; |
615 |
for (UInt_t j=0; j<sizeofwar; j++){ |
616 |
if ( WAR[j] ){ |
617 |
printwarning = true; |
618 |
// |
619 |
if ( j == 0 ){ // insertPamelaRaw warnings |
620 |
for (UInt_t bit=0; bit<32; bit++){ |
621 |
if ( WAR[j] & (1 << bit) ){ |
622 |
if ( bit == 0 ) message += "=> RAW file already inserted\n"; |
623 |
else message += "=> Unidentified insertPamelaRaw warning\n"; |
624 |
}; |
625 |
}; |
626 |
}; |
627 |
// |
628 |
if ( j == 1 ){ // insertTimeSync warnings |
629 |
for (UInt_t bit=0; bit<32; bit++){ |
630 |
if ( WAR[j] & (1 << bit) ){ |
631 |
if ( bit == 0 ) message += "=> TIMESYNC already inserted\n"; |
632 |
else if ( bit == 1 ) message += "=> No mcmd timesync in the file\n"; |
633 |
else if ( bit == 2 ) message += "=> No runheaders in the file\n"; |
634 |
else if ( bit == 3 ) message += "=> No runtrailers in the file\n"; |
635 |
else if ( bit == 4 ) message += "=> No mcmd inclination in the file\n"; |
636 |
else if ( bit == 5 ) message += "=> Inconsistent PKT/OBT sequence\n"; |
637 |
else if ( bit == 6 ) message += "=> No physics events in the file\n"; |
638 |
else if ( bit == 7 ) message += "=> Less than 2 physics events in the file\n"; |
639 |
else message += "=> Unidentified insertTimeSync warning\n"; |
640 |
}; |
641 |
}; |
642 |
}; |
643 |
// |
644 |
if ( j == 2 ){ // insertPamelaRoot warnings |
645 |
for (UInt_t bit=0; bit<32; bit++){ |
646 |
if ( WAR[j] & (1 << bit) ){ |
647 |
if ( bit == 0 ) message += "=> ROOT file already inserted\n"; |
648 |
else message += "=> Unidentified insertPamelaRoot warning\n"; |
649 |
}; |
650 |
}; |
651 |
}; |
652 |
// |
653 |
if ( j == 3 ){ // assignBOOTnumber warnings |
654 |
for (UInt_t bit=0; bit<32; bit++){ |
655 |
if ( WAR[j] & (1 << bit) ){ |
656 |
if ( bit == 0 ) message += "=> BOOT number already inserted\n";// |
657 |
else if ( bit == 1 ) message += "=> VarDump event tree is empty, use the -boot option to override\n";// |
658 |
else if ( bit == 2 ) message += "=> No BOOT number in VarDump(!), use the -boot option to override\n";// |
659 |
else if ( bit == 3 ) message += "=> No VarDump! autoboot option used\n";// |
660 |
else if ( bit == 4 ) message += "=> The file is not in the database looking for VarDump, use the -boot option to override\n";// |
661 |
else message += "=> Unidentified assignBOOTnumber warning\n"; |
662 |
}; |
663 |
}; |
664 |
}; |
665 |
// |
666 |
if ( j == 4 ){ // insertPamelaRUN |
667 |
for (UInt_t bit=0; bit<32; bit++){ |
668 |
if ( WAR[j] & (1 << bit) ){ |
669 |
if ( bit == 0 ) message += "=> Inconsistent PKT/OBT sequence\n"; |
670 |
else if ( bit == 1 ) message += "=> No physics events in the file\n"; |
671 |
else if ( bit == 2 ) message += "=> Less than 2 physics events in the file\n"; |
672 |
else if ( bit == 3 ) message += "=> Not supported yet: run with no events, no runtrailer, no runheader\n"; |
673 |
else if ( bit == 4 ) message += "=> File with no events, no runtrailers, no runheaders\n"; |
674 |
else message += "=> Unidentified insertPamelaRun warning\n"; |
675 |
}; |
676 |
}; |
677 |
}; |
678 |
// |
679 |
if ( j == 5 ){ // insertCALO_CALIB |
680 |
for (UInt_t bit=0; bit<32; bit++){ |
681 |
if ( WAR[j] & (1 << bit) ){ |
682 |
if ( bit == 0 ) message += "=> No calorimeter calibrations in the file\n"; |
683 |
else message += "=> Unidentified insertCaloCalib warning\n"; |
684 |
}; |
685 |
}; |
686 |
}; |
687 |
// |
688 |
// |
689 |
if ( j == 6 ){ // insertTRACKER_CALIB |
690 |
for (UInt_t bit=0; bit<32; bit++){ |
691 |
if ( WAR[j] & (1 << bit) ){ |
692 |
if ( bit == 0 ) message += "=> No tracker calibrations in the file\n"; |
693 |
else message += "=> Unidentified insertTrkCalib warning\n"; |
694 |
}; |
695 |
}; |
696 |
}; |
697 |
// |
698 |
// |
699 |
if ( j == 7 ){ // insertS4_CALIB |
700 |
for (UInt_t bit=0; bit<32; bit++){ |
701 |
if ( WAR[j] & (1 << bit) ){ |
702 |
if ( bit == 0 ) message += "=> No s4 calibrations in the file\n"; |
703 |
else message += "=> Unidentified insertS4calib warning\n"; |
704 |
}; |
705 |
}; |
706 |
}; |
707 |
// |
708 |
// |
709 |
if ( j == 8 ){ // CleanGL_RUN_FRAGMENTS |
710 |
for (UInt_t bit=0; bit<32; bit++){ |
711 |
if ( WAR[j] & (1 << bit) ){ |
712 |
if ( bit == 0 ) message += "=> Skip the GL_RUN_FRAGMENTS table cleaning\n"; |
713 |
if ( bit == 1 ) message += "=> Problems retrieving ROOT ID from DB\n"; |
714 |
else message += "=> Unidentified CleanGL_RUN_FRAGMENTS warning\n"; |
715 |
}; |
716 |
}; |
717 |
}; |
718 |
// |
719 |
if ( j == 9 ){ // ValidateRuns |
720 |
for (UInt_t bit=0; bit<32; bit++){ |
721 |
if ( WAR[j] & (1 << bit) ){ |
722 |
if ( bit == 0 ) message += "=> Skip the run validation \n"; |
723 |
if ( bit == 1 ) message += "=> Problems retrieving ROOT ID from DB\n"; |
724 |
else message += "=> Unidentified ValidateRuns warning\n"; |
725 |
}; |
726 |
}; |
727 |
}; |
728 |
// |
729 |
if ( j == 10 ){ // populateTLE |
730 |
for (UInt_t bit=0; bit<32; bit++){ |
731 |
if ( WAR[j] & (1 << bit) ){ |
732 |
if ( bit == 0 ) message += "=> TLE insertion failed\n"; |
733 |
if ( bit == 1 ) message += "=> No new TLE available\n"; |
734 |
else message += "=> Unidentified populateTle warning\n"; |
735 |
}; |
736 |
}; |
737 |
}; |
738 |
// |
739 |
if ( j == 11 ){ // removeFile |
740 |
for (UInt_t bit=0; bit<32; bit++){ |
741 |
if ( WAR[j] & (1 << bit) ){ |
742 |
if ( bit == 0 ) message += "=> No file to delete from DB \n"; |
743 |
else message += "=> Unidentified populateTle warning\n"; |
744 |
}; |
745 |
}; |
746 |
}; |
747 |
}; |
748 |
}; |
749 |
// |
750 |
if ( printwarning ){ |
751 |
printf("\n"); |
752 |
printf(" WARNING(s):\n%s\n",message.Data()); |
753 |
printf("\n"); |
754 |
if ( !signal ) signal = 1; |
755 |
}; |
756 |
// |
757 |
//--------------------------------------------------------------------------------------- |
758 |
// Close and exit |
759 |
//--------------------------------------------------------------------------------------- |
760 |
if ( beverbose ) printf(" 13 => Free objects and close SQL connection \n"); |
761 |
pamDB->UnLockTables(); |
762 |
pamDB->Close(); |
763 |
// |
764 |
if ( debug ) printf(" Total number of queries through GLTABLES: %u \n",glt->GetNqueries()); |
765 |
delete glt; |
766 |
// |
767 |
printf("\n"); |
768 |
printf(" Finished, exiting...\n"); |
769 |
printf("\n"); |
770 |
// |
771 |
// Close redirection if the case. |
772 |
// |
773 |
if ( !beverbose ) close(nul); |
774 |
// |
775 |
exit(signal); |
776 |
// |
777 |
} |