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

Annotation of /DarthVader/src/DarthVader.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations) (download)
Tue Jun 27 13:57:43 2006 UTC (18 years, 5 months ago) by mocchiut
Branch: MAIN
Changes since 1.2: +3 -1 lines
Workaround in CaloCore and ToFCore programs + new ToF default calibration file to process flight data

1 mocchiut 1.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 mocchiut 1.3 filename += outDir;
438     filename += "/";
439 mocchiut 1.1 filename += strun.str();
440     filename += ".Level2.root";
441     };
442 mocchiut 1.3 // filename = outDir + "/" + filename;
443 mocchiut 1.1 processFile = new TFile(filename.Data(),"UPDATE");
444     if ( !processFile->IsOpen() ) throw -15;
445     //
446     // Run the core program, put any output error in the "error" variable
447     //
448     if ( RUN ) {
449     printf(" Calling RunInfo... ");
450     RUNSGN = RunInfoCore(run,processFile,dbc,runargc,runargv);
451     printf("done\n");
452     };
453     if ( TRK ) {
454     printf(" Calling TrackerLevel2... ");
455     TRKSGN = TrkCore(run,processFile,dbc,trkargc,trkargv);
456     printf("done\n");
457     };
458     if ( TOF ) {
459     printf(" Calling ToFLevel2... ");
460     TOFSGN = ToFCore(run,processFile,dbc,tofargc,tofargv);
461     printf("done\n");
462     };
463     if ( CAL ) {
464     printf(" Calling CalorimeterLevel2... ");
465     CALSGN = CaloCore(run,processFile,dbc,calargc,calargv);
466     printf("done\n");
467     };
468     if ( TRG ) {
469     printf(" Calling TriggerLevel2... ");
470     TRGSGN = TrigCore(run,processFile,dbc,trgargc,trgargv);
471     printf("done\n");
472     };
473     if ( AC ) {
474     printf(" Calling AnticounterLevel2... ");
475     ACSGN = AcCore(run,processFile,dbc,acargc,acargv);
476     printf("done\n");
477     };
478     if ( S4 ) {
479     printf(" Calling S4Level2 ... ");
480     S4SGN = S4Core(run,processFile,dbc,s4argc,s4argv);
481     printf("done\n");
482     };
483     if ( ND ) {
484     printf(" Calling NDLevel2... ");
485     NDSGN = NDCore(run,processFile,dbc,ndargc,ndargv);
486     printf("done\n");
487     };
488     if ( ORB ) {
489     printf(" Calling OrbitalInfo... ");
490     ORBSGN = OrbitalInfoCore(run,processFile,dbc,orbargc,orbargv);
491     printf("done\n");
492     };
493     //
494     } catch(Int_t signal) {
495     error = signal;
496     switch(signal){
497     case 51: message += " GLTABLES - TO_TIME < time when querying tables"; break;
498     case -1: message += " Missing/wrong run ID input parameter"; break;
499     case -2: message += " DB connection failure"; break;
500     case -3: message += " Error in input parameters (check format)"; break;
501     case -4: message += " Request reprocessing of all runs (idRun = 0) but processFile is missing"; break;
502     case -6: message += " No LEVEL0 file "; break;
503     case -7: message += " No Physics tree in LEVEL0 file"; break;
504     case -8: message += " No Header branch in LEVEL0 Physics tree"; break;
505     case -9: message += " No Registry branch in LEVEL0 Physics tree"; break;
506     case -11: message += " LEVEL0 Physics tree is empty"; break;
507 mocchiut 1.2 case -12: message += " Too few entries in the registry tree"; break;
508 mocchiut 1.1 case -13: message += " Cannot create processFolder directory"; break;
509     case -14: message += " Error querying the DB"; break;
510     case -15: message += " Cannot open file for writing"; break;
511     //
512     case -50: message += " GLTABLES - No entries matching GL_RUN query"; break;
513     case -51: message += " GLTABLES - No entries matching GL_ROOT query"; break;
514     case -52: message += " GLTABLES - No entries matching GL_PARAM query"; break;
515     case -53: message += " GLTABLES - No entries matching GL_TRK_CALIB query"; break;
516     case -54: message += " GLTABLES - No entries matching GL_CALO_CALIB query"; break;
517     case -55: message += " GLTABLES - No entries matching GL_CALO_CALIB query"; break;
518     //
519     case -100: message += " CALORIMETERLEVEL2 - No Level2 input file"; break;
520     case -101: message += " CALORIMETERLEVEL2 - Cannot open Level2 file"; break;
521     case -102: message += " CALORIMETERLEVEL2 - No Tracker TTree in Level2 file"; break;
522     case -103: message += " CALORIMETERLEVEL2 - No Calorimeter TBranch in Level0 file"; break;
523     case -104: message += " CALORIMETERLEVEL2 - No Trigger TTree in Level0 file"; break;
524     case -105: message += " CALORIMETERLEVEL2 - No Calorimeter ADC2MIP conversion file"; break;
525     case -106: message += " CALORIMETERLEVEL2 - No Calorimeter alignement file"; break;
526     case -107: message += " CALORIMETERLEVEL2 - Cannot find Level0 file needed for the calibration"; break;
527     case -108: message += " CALORIMETERLEVEL2 - Cannot open Level0 file needed for the calibration"; break;
528     case -109: message += " CALORIMETERLEVEL2 - No CalibCalPed TTree in Level0 file needed for the calibration"; break;
529     case -110: message += " CALORIMETERLEVEL2 - No calibrations in Level0 file needed for the calibration"; break;
530     case -111: message += " CALORIMETERLEVEL2 - Corrupted calibration"; break;
531     case -112: message += " CALORIMETERLEVEL2 - No physics event related to registry entry in Level0 file"; break;
532     case -113: message += " CALORIMETERLEVEL2 - No tracker event related to registry entry in Level2 file"; break;
533     //
534     case -200: message += " TRACKERLEVEL2 - LEVEL1 framework unknown (HBOOK/ROOT)"; break;
535     case -201: message += " TRACKERLEVEL2 - LEVEL2 framework unknown (HBOOK/ROOT)"; break;
536     case -202: message += " TRACKERLEVEL2 - Neither LEVEL1 nor LEVEL2 output requested"; break;
537     case -203: message += " TRACKERLEVEL2 - No Tracker branch in LEVEL0 Physics tree"; break;
538     case -204: message += " TRACKERLEVEL2 - No reprocessing implemented for LEVEL1 output"; break;
539     case -205: message += " TRACKERLEVEL2 - Error accessing RunInfo "; break;
540     case -210: message += " TRACKERLEVEL2 - Error opening/reading trk mask GL_PARAM parameters "; break;
541     case -211: message += " TRACKERLEVEL2 - Error opening/reading trk alignment GL_PARAM parameters"; break;
542     case -212: message += " TRACKERLEVEL2 - Error opening/reading trk mip GL_PARAM parameters"; break;
543     case -213: message += " TRACKERLEVEL2 - Error opening/reading trk charge GL_PARAM parameters"; break;
544     case -214: message += " TRACKERLEVEL2 - Error opening/reading trk pfa GL_PARAM parameters"; break;
545     case -215: message += " TRACKERLEVEL2 - Error opening/reading field GL_PARAM parameters"; break;
546     case -216: message += " TRACKERLEVEL2 - Error opening/reading default calibration GL_PARAM parameters"; break;
547     case -298: message += " TRACKERLEVEL2 - Reprocessing not implemented in standalone mode"; break;
548     case -299: message += " TRACKERLEVEL2 - Not yet implemented"; break;
549     //
550     case -300: message += " TOFLEVEL2 - No Trigger branch in Level0 tree"; break;
551     case -301: message += " TOFLEVEL2 - Cannot open file for writing"; break;
552     case -302: message += " TOFLEVEL2 - No tracker tree in Level2 file"; break;
553     case -303: message += " TOFLEVEL2 - No Tof branch in Level0 file"; break;
554     case -313: message += " TOFLEVEL2 - No more tracker events in Level2 file"; break;
555     //
556     case -401: message += " TRIGGERLEVEL2 - Cannot open file for writing"; break;
557     case -402: message += " TRIGGERLEVEL2 - No Trigger branch in Level0 tree"; break;
558     //
559     case -500: message += " S4LEVEL2 - No level2 file"; break;
560     case -501: message += " S4LEVEL2 - Cannot open file for writing"; break;
561     case -502: message += " S4LEVEL2 - No result from GL_S4_CALIB"; break;
562     case -503: message += " S4LEVEL2 - No S4 branch in Level0 tree"; break;
563     //
564     case -600: message += " NDLEVEL2 - No level2 file"; break;
565     case -601: message += " NDLEVEL2 - Cannot open file for writing"; break;
566     case -603: message += " NDLEVEL2 - No S4Level2 branch in Level0 tree"; break;
567     //
568     case -701: message += " NDLEVEL2 - Cannot open file for writing"; break;
569     case -704: message += " NDLEVEL2 - No Anticounter branch in Level0 tree"; break;
570     //
571     case -800: message += " RUNINFO - No such run in the RunInfo list"; break;
572     case -801: message += " RUNINFO - No RunInfo tree in Level2 file"; break;
573     case -802: message += " RUNINFO - Cannot open file for writing"; break;
574     case -803: message += " RUNINFO - Updating but no RunInfo tree in Level2 file"; break;
575     case -804: message += " RUNINFO - Unknown detector"; break;
576 mocchiut 1.2 case -805: message += " RUNINFO - Reprocessing data but no RunInfo tree in Level2 file"; break;
577 mocchiut 1.1 //
578     default: message += "Unidentified error or warning"; break;
579     };
580     printf("\n");
581     if ( signal < 0 ) cout << " ERROR ("<< signal << ") "<< message <<endl;
582     }
583     // switch(RUNSGN){
584     // };
585     switch(CALSGN){
586     case 100: printf("\n WARNING CALORIMETER - Data with no associated calibration\n"); break;
587     case 101: printf("\n WARNING CALORIMETER - No tracks or good events in this run\n"); break;
588     };
589     //
590     // Close the DB connection
591     //
592     if ( dbc ){
593     if ( debug ) printf("\nClose the connection to the database... \n");
594     dbc->Close();
595     if ( debug ) printf("...connection terminated!\n\n");
596     };
597     if ( processFile ){
598     processFile->cd();
599     processFile->Close();
600     };
601     //
602     if ( error != 0 ) printf("\n\n WARNING: exiting with signal %i \n\n",error);
603     printf("\n");
604     //
605     // Close redirection if the case.
606     //
607     if ( !beverbose ) close(nul);
608     //
609     //
610     exit(error);
611     }

  ViewVC Help
Powered by ViewVC 1.1.23