/[PAMELA software]/DarthVader/src/DarthVader.cpp
ViewVC logotype

Contents of /DarthVader/src/DarthVader.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (download) (vendor branch)
Fri May 19 13:15:25 2006 UTC (18 years, 6 months ago) by mocchiut
Branch: DarthVader
CVS Tags: v0r01, start
Changes since 1.1: +0 -0 lines
Imported sources

1 //
2 // C/C++ headers
3 //
4 #include <iostream>
5 #include <sstream>
6 //
7 // ROOT headers
8 //
9 #include <TString.h>
10 #include <TSQLServer.h>
11 #include <TFile.h>
12 #include <TSystem.h>
13 //
14 // Detector's package headers
15 //
16 #include <RunInfoCore.h>
17 #include <TrkCore.h>
18 #include <TrigCore.h>
19 #include <ToFCore.h>
20 #include <CaloCore.h>
21 #include <AcCore.h>
22 #include <S4Core.h>
23 #include <NDCore.h>
24 #include <OrbitalInfoCore.h>
25 //
26 using namespace std;
27 //
28 //
29 //
30 #include <DarthVaderVerl2.h>
31 //
32 // Usage subroutine
33 //
34 void usage(){
35 printf("\nUsage:\n");
36 printf("\n DarthVader [-v | --verbose] [-h | --help] [--version] -idRun ID_RUN [-processFile filename]\n");
37 printf("\n [-host host] [-user username] [-psw password] [+-all] [+-detector [detector options] ]\n");
38 printf("\n --version print informations about compilation and exit\n");
39 printf("\n -h | --help print this help and exit \n");
40 printf("\n -v | --verbose be verbose [default: print nothing on STDOUT]\n");
41 printf("\n -idRun ID_RUN: ID number of the run to be processed \n");
42 printf("\n -processFile output filename [default ID_RUN.Level2.root]\n");
43 printf("\n -processFolder folder for output data but the processFile [default \"calorimeterFolder\"]\n");
44 printf("\n -host name for the host [default = mysql://localhost/pamelaprod]\n");
45 printf("\n -user username for the DB [default = anonymous] \n");
46 printf("\n -psw password for the DB [default = \"\"]\n");
47 printf("\n +all call all detectors software [default]\n");
48 printf("\n -all call nothing\n");
49 printf("\n +detector process detector; detector can be: TOF,TRK,CAL,TRG,ORB,S4,ND,AC,RUN\n");
50 printf("\n -detector do not process detector (as above)\n");
51 printf("\nExamples: \n");
52 printf("\nStandard call: DarthVader -idRun 1085 \n");
53 printf("\nProcess only RunInfo and Tracker (be verbose for tracker): DarthVader -idRun 1085 -all +RUN +TRK [ --verbose ] \n");
54 printf("\nProcess all and be verbose for calorimeter: DarthVader -idRun 1085 +CAL [ --verbose ] \n\n");
55 };
56 //
57 // Here the main
58 //
59 int main(int numinp, char *inps[]){
60 //
61 // Variables booking
62 //
63 TString message;
64 int nul = 0;
65 Int_t error = 0;
66 //
67 Int_t CALSGN = 0;
68 Int_t TRKSGN = 0;
69 Int_t TRGSGN = 0;
70 Int_t TOFSGN = 0;
71 Int_t RUNSGN = 0;
72 Int_t ORBSGN = 0;
73 Int_t ACSGN = 0;
74 Int_t S4SGN = 0;
75 Int_t NDSGN = 0;
76 //
77 Bool_t debug = false;
78 Bool_t beverbose = false;
79 Bool_t givenid = false;
80 Bool_t CAL = true;
81 Bool_t TRK = true;
82 Bool_t TRG = true;
83 Bool_t TOF = true;
84 Bool_t S4 = true;
85 Bool_t ND = true;
86 Bool_t AC = true;
87 Bool_t ORB = true;
88 Bool_t RUN = true;
89 //
90 Int_t calargc = 0;
91 char *calargv[50];
92 Int_t trkargc = 0;
93 char *trkargv[50];
94 Int_t tofargc = 0;
95 char *tofargv[50];
96 Int_t trgargc = 0;
97 char *trgargv[50];
98 Int_t orbargc = 0;
99 char *orbargv[50];
100 Int_t runargc = 0;
101 char *runargv[50];
102 Int_t acargc = 0;
103 char *acargv[50];
104 Int_t s4argc = 0;
105 char *s4argv[50];
106 Int_t ndargc = 0;
107 char *ndargv[50];
108 //
109 //
110 //
111 ULong64_t run = 0;
112 //
113 TString filename;
114 TString outDir = gSystem->WorkingDirectory();
115 //
116 TSQLServer *dbc = 0;
117 TString host = "mysql://localhost/pamelaprod";
118 TString user = "anonymous";
119 TString psw = "";
120 //
121 TFile *processFile = 0;
122 //
123 // Checking input parameters
124 //
125 Int_t i = 0;
126 try {
127 if ( numinp > 1 ){
128 while ( i < numinp ){
129 if ( !strcmp(inps[i],"--version") ){
130 DarthVaderInfo(true);
131 exit(0);
132 };
133 if ( !strcmp(inps[i],"-h") || !strcmp(inps[i],"--help") ){
134 usage();
135 exit(0);
136 };
137 if ( !strcmp(inps[i],"-idRun") ) {
138 if ( numinp-1 < i+1 ) {
139 usage();
140 throw -3;
141 };
142 givenid = true;
143 char *pEnd;
144 run = strtoull(inps[i+1],&pEnd,0);
145 };
146 if ( !strcmp(inps[i],"-processFile") ) {
147 if ( numinp-1 < i+1 ){
148 usage();
149 throw -3;
150 };
151 filename = (TString)inps[i+1];
152 };
153 if ( !strcmp(inps[i],"-outDir") ) {
154 if ( numinp-1 < i+1 ){
155 usage();
156 throw -3;
157 };
158 outDir = (TString)inps[i+1];
159 };
160 if ( !strcmp(inps[i],"-host") ) {
161 if ( numinp-1 < i+1 ){
162 usage();
163 throw -3;
164 };
165 host = (TString)inps[i+1];
166 };
167 if ( !strcmp(inps[i],"-user") ) {
168 if ( numinp-1 < i+1 ){
169 usage();
170 throw -3;
171 };
172 user = (TString)inps[i+1];
173 };
174 if ( !strcmp(inps[i],"-psw") ) {
175 if ( numinp-1 < i+1 ){
176 usage();
177 throw -3;
178 };
179 psw = (TString)inps[i+1];
180 };
181 if ( !strcmp(inps[i],"-v") || !strcmp(inps[i],"--verbose") ) beverbose = true;
182 //
183 if ( !strcmp(inps[i],"-g") || !strcmp(inps[i],"--debug") ) debug = true;
184 //
185 if ( !strcmp(inps[i],"-CAL") ) {
186 CAL = false;
187 };
188 if ( !strcmp(inps[i],"-TRK") ) {
189 TRK = false;
190 };
191 if ( !strcmp(inps[i],"-TOF") ) {
192 TOF = false;
193 };
194 if ( !strcmp(inps[i],"-TRG") ) {
195 TRG = false;
196 };
197 if ( !strcmp(inps[i],"-S4") ) {
198 S4 = false;
199 };
200 if ( !strcmp(inps[i],"-ND") ) {
201 ND = false;
202 };
203 if ( !strcmp(inps[i],"-AC") ) {
204 AC = false;
205 };
206 if ( !strcmp(inps[i],"-RUN") ) {
207 RUN = false;
208 };
209 if ( !strcmp(inps[i],"-ORB") ) {
210 ORB = false;
211 };
212 //
213 if ( !strcmp(inps[i],"-all") ) {
214 CAL = false;
215 ORB = false;
216 TRK = false;
217 TRG = false;
218 TOF = false;
219 S4 = false;
220 ND = false;
221 AC = false;
222 RUN = false;
223 };
224 //
225 if ( !strcmp(inps[i],"+all") ) {
226 CAL = true;
227 ORB = true;
228 TRK = true;
229 TRG = true;
230 TOF = true;
231 S4 = true;
232 ND = true;
233 AC = true;
234 RUN = true;
235 };
236 //
237 if ( !strcmp(inps[i],"+CAL") ) {
238 CAL = true;
239 if ( numinp >= i+2 && !strcmp(inps[i+1],"[") ){
240 if ( numinp < i+2 ){
241 usage();
242 throw -3;
243 };
244 i += 2;
245 calargc = 0;
246 while ( strcmp(inps[i],"]") ){
247 calargv[calargc] = inps[i];
248 calargc++;
249 i++;
250 if ( i > numinp-1 ){
251 usage();
252 throw -3;
253 };
254 };
255 };
256 };
257 if ( !strcmp(inps[i],"+TRK") ) {
258 TRK = true;
259 if ( numinp >= i+2 && !strcmp(inps[i+1],"[") ){
260 if ( numinp-1 < i+2 ){
261 usage();
262 throw -3;
263 };
264 i += 2;
265 trkargc = 0;
266 while ( strcmp(inps[i],"]") ){
267 trkargv[trkargc] = inps[i];
268 trkargc++;
269 i++;
270 if ( i > numinp-1 ){
271 usage();
272 throw -3;
273 };
274 };
275 };
276 };
277 if ( !strcmp(inps[i],"+TOF") ) {
278 TOF = true;
279 if ( numinp >= i+2 && !strcmp(inps[i+1],"[") ){
280 i += 2;
281 tofargc = 0;
282 while ( strcmp(inps[i],"]") ){
283 tofargv[tofargc] = inps[i];
284 tofargc++;
285 i++;
286 if ( i > numinp-1 ){
287 usage();
288 throw -3;
289 };
290 };
291 };
292 };
293 if ( !strcmp(inps[i],"+TRG") ) {
294 TRG = true;
295 if ( numinp >= i+2 && !strcmp(inps[i+1],"[") ){
296 i += 2;
297 trgargc = 0;
298 while ( strcmp(inps[i],"]") ){
299 trgargv[trgargc] = inps[i];
300 trgargc++;
301 i++;
302 if ( i > numinp-1 ){
303 usage();
304 throw -3;
305 };
306 };
307 };
308 };
309 if ( !strcmp(inps[i],"+ORB") ) {
310 ORB = true;
311 if ( numinp >= i+2 && !strcmp(inps[i+1],"[") ){
312 i += 2;
313 orbargc = 0;
314 while ( strcmp(inps[i],"]") ){
315 orbargv[orbargc] = inps[i];
316 orbargc++;
317 i++;
318 if ( i > numinp-1 ){
319 usage();
320 throw -3;
321 };
322 };
323 };
324 };
325 if ( !strcmp(inps[i],"+RUN") ) {
326 RUN = true;
327 if ( numinp >= i+2 && !strcmp(inps[i+1],"[") ){
328 i += 2;
329 runargc = 0;
330 while ( strcmp(inps[i],"]") ){
331 runargv[runargc] = inps[i];
332 runargc++;
333 i++;
334 if ( i > numinp-1 ){
335 usage();
336 throw -3;
337 };
338 };
339 };
340 };
341 if ( !strcmp(inps[i],"+AC") ) {
342 AC = true;
343 if ( numinp >= i+2 && !strcmp(inps[i+1],"[") ){
344 i += 2;
345 acargc = 0;
346 while ( strcmp(inps[i],"]") ){
347 acargv[acargc] = inps[i];
348 acargc++;
349 i++;
350 if ( i > numinp-1 ){
351 usage();
352 throw -3;
353 };
354 };
355 };
356 };
357 if ( !strcmp(inps[i],"+S4") ) {
358 S4 = true;
359 if ( numinp >= i+2 && !strcmp(inps[i+1],"[") ){
360 i += 2;
361 s4argc = 0;
362 while ( strcmp(inps[i],"]") ){
363 s4argv[s4argc] = inps[i];
364 s4argc++;
365 i++;
366 if ( i > numinp-1 ){
367 usage();
368 throw -3;
369 };
370 };
371 };
372 };
373 if ( !strcmp(inps[i],"+ND") ) {
374 ND = true;
375 if ( numinp >= i+2 && !strcmp(inps[i+1],"[") ){
376 i += 2;
377 ndargc = 0;
378 while ( strcmp(inps[i],"]") ){
379 ndargv[ndargc] = inps[i];
380 ndargc++;
381 i++;
382 if ( i > numinp-1 ){
383 usage();
384 throw -3;
385 };
386 };
387 };
388 };
389 //
390 i++;
391 };
392 //
393 } else {
394 //
395 // no input parameters exit with error, we need at least the run id.
396 //
397 throw -1;
398 };
399 //
400 // If not in verbose mode redirect to /dev/null the stdout and stderr
401 //
402 if ( !beverbose ){
403 nul = open("/dev/null", O_CREAT | O_RDWR,S_IREAD | S_IWRITE);
404 dup2(nul,1);
405 dup2(nul,2);
406 };
407 //
408 // Check that an input run number has been given
409 //
410 if ( !givenid ) throw -1;
411 //
412 char *version = DarthVaderInfo(false);
413 //
414 // Start:
415 //
416 printf("\n Welcome to the PAMELA LEVEL2 flight software, version %s \n\n",version);
417 //
418 // Connect to the DB
419 //
420 if ( debug ) printf("\nConnecting to database... \n");
421 //
422 dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
423 if( !dbc ) throw -2;
424 //
425 bool connect = dbc->IsConnected();
426 //
427 if( !connect ) throw -2;
428 //
429 if ( debug ) printf("...connected! \n\n");
430 //
431 // Create LEVEL2 filename and open it in update mode
432 //
433 if ( filename.IsNull() ){
434 stringstream strun;
435 strun.str("");
436 strun << run;
437 filename += strun.str();
438 filename += ".Level2.root";
439 };
440 filename = outDir + "/" + filename;
441 processFile = new TFile(filename.Data(),"UPDATE");
442 if ( !processFile->IsOpen() ) throw -15;
443 //
444 // Run the core program, put any output error in the "error" variable
445 //
446 if ( RUN ) {
447 printf(" Calling RunInfo... ");
448 RUNSGN = RunInfoCore(run,processFile,dbc,runargc,runargv);
449 printf("done\n");
450 };
451 if ( TRK ) {
452 printf(" Calling TrackerLevel2... ");
453 TRKSGN = TrkCore(run,processFile,dbc,trkargc,trkargv);
454 printf("done\n");
455 };
456 if ( TOF ) {
457 printf(" Calling ToFLevel2... ");
458 TOFSGN = ToFCore(run,processFile,dbc,tofargc,tofargv);
459 printf("done\n");
460 };
461 if ( CAL ) {
462 printf(" Calling CalorimeterLevel2... ");
463 CALSGN = CaloCore(run,processFile,dbc,calargc,calargv);
464 printf("done\n");
465 };
466 if ( TRG ) {
467 printf(" Calling TriggerLevel2... ");
468 TRGSGN = TrigCore(run,processFile,dbc,trgargc,trgargv);
469 printf("done\n");
470 };
471 if ( AC ) {
472 printf(" Calling AnticounterLevel2... ");
473 ACSGN = AcCore(run,processFile,dbc,acargc,acargv);
474 printf("done\n");
475 };
476 if ( S4 ) {
477 printf(" Calling S4Level2 ... ");
478 S4SGN = S4Core(run,processFile,dbc,s4argc,s4argv);
479 printf("done\n");
480 };
481 if ( ND ) {
482 printf(" Calling NDLevel2... ");
483 NDSGN = NDCore(run,processFile,dbc,ndargc,ndargv);
484 printf("done\n");
485 };
486 if ( ORB ) {
487 printf(" Calling OrbitalInfo... ");
488 ORBSGN = OrbitalInfoCore(run,processFile,dbc,orbargc,orbargv);
489 printf("done\n");
490 };
491 //
492 } catch(Int_t signal) {
493 error = signal;
494 switch(signal){
495 case 51: message += " GLTABLES - TO_TIME < time when querying tables"; break;
496 case -1: message += " Missing/wrong run ID input parameter"; break;
497 case -2: message += " DB connection failure"; break;
498 case -3: message += " Error in input parameters (check format)"; break;
499 case -4: message += " Request reprocessing of all runs (idRun = 0) but processFile is missing"; break;
500 case -6: message += " No LEVEL0 file "; break;
501 case -7: message += " No Physics tree in LEVEL0 file"; break;
502 case -8: message += " No Header branch in LEVEL0 Physics tree"; break;
503 case -9: message += " No Registry branch in LEVEL0 Physics tree"; break;
504 case -11: message += " LEVEL0 Physics tree is empty"; break;
505 case -12: message += " LEVEL2 output directory does not exists"; break;
506 case -13: message += " Cannot create processFolder directory"; break;
507 case -14: message += " Error querying the DB"; break;
508 case -15: message += " Cannot open file for writing"; break;
509 //
510 case -50: message += " GLTABLES - No entries matching GL_RUN query"; break;
511 case -51: message += " GLTABLES - No entries matching GL_ROOT query"; break;
512 case -52: message += " GLTABLES - No entries matching GL_PARAM query"; break;
513 case -53: message += " GLTABLES - No entries matching GL_TRK_CALIB query"; break;
514 case -54: message += " GLTABLES - No entries matching GL_CALO_CALIB query"; break;
515 case -55: message += " GLTABLES - No entries matching GL_CALO_CALIB query"; break;
516 //
517 case -100: message += " CALORIMETERLEVEL2 - No Level2 input file"; break;
518 case -101: message += " CALORIMETERLEVEL2 - Cannot open Level2 file"; break;
519 case -102: message += " CALORIMETERLEVEL2 - No Tracker TTree in Level2 file"; break;
520 case -103: message += " CALORIMETERLEVEL2 - No Calorimeter TBranch in Level0 file"; break;
521 case -104: message += " CALORIMETERLEVEL2 - No Trigger TTree in Level0 file"; break;
522 case -105: message += " CALORIMETERLEVEL2 - No Calorimeter ADC2MIP conversion file"; break;
523 case -106: message += " CALORIMETERLEVEL2 - No Calorimeter alignement file"; break;
524 case -107: message += " CALORIMETERLEVEL2 - Cannot find Level0 file needed for the calibration"; break;
525 case -108: message += " CALORIMETERLEVEL2 - Cannot open Level0 file needed for the calibration"; break;
526 case -109: message += " CALORIMETERLEVEL2 - No CalibCalPed TTree in Level0 file needed for the calibration"; break;
527 case -110: message += " CALORIMETERLEVEL2 - No calibrations in Level0 file needed for the calibration"; break;
528 case -111: message += " CALORIMETERLEVEL2 - Corrupted calibration"; break;
529 case -112: message += " CALORIMETERLEVEL2 - No physics event related to registry entry in Level0 file"; break;
530 case -113: message += " CALORIMETERLEVEL2 - No tracker event related to registry entry in Level2 file"; break;
531 //
532 case -200: message += " TRACKERLEVEL2 - LEVEL1 framework unknown (HBOOK/ROOT)"; break;
533 case -201: message += " TRACKERLEVEL2 - LEVEL2 framework unknown (HBOOK/ROOT)"; break;
534 case -202: message += " TRACKERLEVEL2 - Neither LEVEL1 nor LEVEL2 output requested"; break;
535 case -203: message += " TRACKERLEVEL2 - No Tracker branch in LEVEL0 Physics tree"; break;
536 case -204: message += " TRACKERLEVEL2 - No reprocessing implemented for LEVEL1 output"; break;
537 case -205: message += " TRACKERLEVEL2 - Error accessing RunInfo "; break;
538 case -210: message += " TRACKERLEVEL2 - Error opening/reading trk mask GL_PARAM parameters "; break;
539 case -211: message += " TRACKERLEVEL2 - Error opening/reading trk alignment GL_PARAM parameters"; break;
540 case -212: message += " TRACKERLEVEL2 - Error opening/reading trk mip GL_PARAM parameters"; break;
541 case -213: message += " TRACKERLEVEL2 - Error opening/reading trk charge GL_PARAM parameters"; break;
542 case -214: message += " TRACKERLEVEL2 - Error opening/reading trk pfa GL_PARAM parameters"; break;
543 case -215: message += " TRACKERLEVEL2 - Error opening/reading field GL_PARAM parameters"; break;
544 case -216: message += " TRACKERLEVEL2 - Error opening/reading default calibration GL_PARAM parameters"; break;
545 case -298: message += " TRACKERLEVEL2 - Reprocessing not implemented in standalone mode"; break;
546 case -299: message += " TRACKERLEVEL2 - Not yet implemented"; break;
547 //
548 case -300: message += " TOFLEVEL2 - No Trigger branch in Level0 tree"; break;
549 case -301: message += " TOFLEVEL2 - Cannot open file for writing"; break;
550 case -302: message += " TOFLEVEL2 - No tracker tree in Level2 file"; break;
551 case -303: message += " TOFLEVEL2 - No Tof branch in Level0 file"; break;
552 case -313: message += " TOFLEVEL2 - No more tracker events in Level2 file"; break;
553 //
554 case -401: message += " TRIGGERLEVEL2 - Cannot open file for writing"; break;
555 case -402: message += " TRIGGERLEVEL2 - No Trigger branch in Level0 tree"; break;
556 //
557 case -500: message += " S4LEVEL2 - No level2 file"; break;
558 case -501: message += " S4LEVEL2 - Cannot open file for writing"; break;
559 case -502: message += " S4LEVEL2 - No result from GL_S4_CALIB"; break;
560 case -503: message += " S4LEVEL2 - No S4 branch in Level0 tree"; break;
561 //
562 case -600: message += " NDLEVEL2 - No level2 file"; break;
563 case -601: message += " NDLEVEL2 - Cannot open file for writing"; break;
564 case -603: message += " NDLEVEL2 - No S4Level2 branch in Level0 tree"; break;
565 //
566 case -701: message += " NDLEVEL2 - Cannot open file for writing"; break;
567 case -704: message += " NDLEVEL2 - No Anticounter branch in Level0 tree"; break;
568 //
569 case -800: message += " RUNINFO - No such run in the RunInfo list"; break;
570 case -801: message += " RUNINFO - No RunInfo tree in Level2 file"; break;
571 case -802: message += " RUNINFO - Cannot open file for writing"; break;
572 case -803: message += " RUNINFO - Updating but no RunInfo tree in Level2 file"; break;
573 case -804: message += " RUNINFO - Unknown detector"; break;
574 //
575 default: message += "Unidentified error or warning"; break;
576 };
577 printf("\n");
578 if ( signal < 0 ) cout << " ERROR ("<< signal << ") "<< message <<endl;
579 }
580 // switch(RUNSGN){
581 // };
582 switch(CALSGN){
583 case 100: printf("\n WARNING CALORIMETER - Data with no associated calibration\n"); break;
584 case 101: printf("\n WARNING CALORIMETER - No tracks or good events in this run\n"); break;
585 };
586 //
587 // Close the DB connection
588 //
589 if ( dbc ){
590 if ( debug ) printf("\nClose the connection to the database... \n");
591 dbc->Close();
592 if ( debug ) printf("...connection terminated!\n\n");
593 };
594 if ( processFile ){
595 processFile->cd();
596 processFile->Close();
597 };
598 //
599 if ( error != 0 ) printf("\n\n WARNING: exiting with signal %i \n\n",error);
600 printf("\n");
601 //
602 // Close redirection if the case.
603 //
604 if ( !beverbose ) close(nul);
605 //
606 //
607 exit(error);
608 }

  ViewVC Help
Powered by ViewVC 1.1.23