/[PAMELA software]/c3po/src/C3PO.cpp
ViewVC logotype

Contents of /c3po/src/C3PO.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (download) (vendor branch)
Fri Jul 21 11:32:02 2006 UTC (18 years, 4 months ago) by pam-fi
Branch: C3PO, MAIN
CVS Tags: v1r00, v1r01, HEAD
Changes since 1.1: +0 -0 lines
C3PO the Flight Data Converter

1 //
2 // C3PO.cpp -- standalone program to convert Level2 data.
3 // by David Fedele
4 //
5 // v1r00
6 //
7 // C/C++ headers
8 //
9 #include <iostream>
10 //
11 // ROOT headers
12 //
13 #include <TString.h>
14 #include <TFile.h>
15 #include <TTree.h>
16 #include <TSystem.h>
17 //
18 // header of Level2 classes
19 //
20 #include <TrkLevel2.h>
21 #include <ToFLevel2.h>
22 #include <AcLevel2.h>
23 #include <CaloLevel2.h>
24 #include <NDLevel2.h>
25 #include <S4Level2.h>
26 #include <TrigLevel2.h>
27 #include <OrbitalInfo.h>
28 #include <GLTables.h>
29 #include <RunInfo.h>
30
31 //
32 // Detector's package headers
33 //
34 //
35 using namespace std;
36 //
37 // Usage subroutine
38 //
39 void usage(){
40 printf("\nUsage:\n");
41 printf("\n C3PO filename.root [OPTIONS]\n\n");
42 printf("\t -h | --help: print this help and exit \n");
43 printf("\t filename: file.root to be converted with complete path [give at least this parameter]\n");
44 printf("\nOPTIONS:\n");
45 printf("\t --version: print informations about compilation and exit\n");
46 printf("\t -v | --verbose: be verbose [default: print nothing on STDOUT]\n");
47 printf("\t -outDir: path to the output directory [default = ./] \n");
48 printf("\t -outFile: name of the output file with the '.rz' extension [default = filename.rz] \n");
49 printf("\t +all: call all detectors software [default]\n");
50 printf("\t -all: call nothing\n");
51 printf("\t +detector: process detector; detector can be: TOF,TRK,CAL,TRG,ORB,S4,ND,AC,RUN\n");
52 printf("\t -detector: do not process detector (as above)\n");
53 printf("\nExamples: \n");
54 printf("\tStandard call: C3PO 42.Level2.root \n");
55 printf("\tProcess only Calorimeter and Tracker: C3PO 42.Level2.root -all +CAL +TRK -outFile miofile.rz -outDir ~/tmp -v\n");
56 };
57
58 //
59 // Fortran functions and ntuples
60 //
61 extern "C" {
62
63 void openlev2_();
64 void closelev2_();
65
66 //
67 // Tracker
68 extern struct cTrkLevel2 tracker_;
69 void booktrackerntupla_();
70 void filltrackerntupla_();
71 void closetrackerntupla_();
72
73 //
74 // Calorimeter
75 extern struct cCaloLevel2 calo_;
76 void bookcalontupla_();
77 void fillcalontupla_();
78 void closecalontupla_();
79
80 //
81 // ToF
82 extern struct cToFLevel2 tof_;
83 void booktofntupla_();
84 void filltofntupla_();
85 void closetofntupla_();
86
87 //
88 // Trigger
89 extern struct cTrigLevel2 trigger_;
90 void booktriggerntupla_();
91 void filltriggerntupla_();
92 void closetriggerntupla_();
93
94 //
95 // Anticounter
96 extern struct cAcLevel2 antic_;
97 void bookanticntupla_();
98 void fillanticntupla_();
99 void closeanticntupla_();
100
101 //
102 // S4
103 extern struct cS4Level2 s4_;
104 void books4ntupla_();
105 void fills4ntupla_();
106 void closes4ntupla_();
107
108 //
109 // NeutronD
110 extern struct cNDLevel2 nd_;
111 void bookndntupla_();
112 void fillndntupla_();
113 void closendntupla_();
114
115 //
116 //OrbitalInfo
117 extern struct cOrbitalInfo orbinfo_;
118 void bookorbitalinfontupla_();
119 void fillorbitalinfontupla_();
120 void closeorbitalinfontupla_();
121
122 //
123 //RunInfo
124 extern struct cGLRun glrun_;
125 extern struct cSoftInfo softinfo_;
126 void bookruninfontupla_();
127 void fillruninfontupla_();
128 void closeruninfontupla_();
129
130 };
131
132
133 //
134 // Here the main
135 //
136 int main(int argc, char *argv[]){
137 //
138 // Variables booking
139 //
140 TString FILE,OUTDIR="./",OUTFILE="default";
141 TString message;
142 int nul = 0;
143 // Int_t error = 0;
144 // Bool_t debug = false;
145 Bool_t beverbose = false;
146 Bool_t CAL = true;
147 Bool_t TRK = true;
148 Bool_t TRG = true;
149 Bool_t TOF = true;
150 Bool_t S4 = true;
151 Bool_t ND = true;
152 Bool_t AC = true;
153 Bool_t ORB = true;
154 Bool_t RUN = true;
155 //
156 // Checking input parameters
157 //
158
159 if(argc>1){
160 if ( !strcmp(argv[1],"--version") ){
161 printf("Sorry, at the moment no infos available!");
162 // info();
163 exit(0);
164 };
165 if(!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help") || argc>11){
166 usage();
167 exit(0);
168 }
169 if ( (!strcmp(argv[1],"-v") || !strcmp(argv[1],"--verbose"))&& argc == 2 ){
170 printf("Sorry, at the moment no infos available!");
171 // info();
172 exit(0);
173 }
174 else {
175
176 FILE = argv[1];
177 for(int i=2; i<argc;i++){
178
179 if ( !strcmp(argv[i],"-v") || !strcmp(argv[i],"--verbose") )
180 beverbose = true;
181
182 if (!strcmp(argv[i], "-outDir")){
183 if (++i >= argc || !strncmp(argv[i],"-",1) || !strncmp(argv[i],"+",1)){
184 printf( "\n-outDir needs arguments. \n");
185 usage();
186 exit(0);
187 }
188 else{
189 OUTDIR = argv[i];
190 continue;
191 }
192 }
193
194 if (!strcmp(argv[i], "-outFile")){
195 if (++i >= argc || !strncmp(argv[i],"-",1) || !strncmp(argv[i],"+",1)){
196 printf( "\n-outFile needs arguments. \n");
197 usage();
198 exit(0);
199 }
200 else{
201 OUTFILE = argv[i];
202 continue;
203 }
204 }
205
206 //
207 if ( !strcmp(argv[i],"+all") ) {
208 CAL = true;
209 ORB = true;
210 TRK = true;
211 TRG = true;
212 TOF = true;
213 S4 = true;
214 ND = true;
215 AC = true;
216 RUN = true;
217 };
218 if ( !strcmp(argv[i],"+CAL") ) {
219 CAL = true;
220 };
221 if ( !strcmp(argv[i],"+TRK") ) {
222 TRK = true;
223 };
224 if ( !strcmp(argv[i],"+TOF") ) {
225 TOF = true;
226 };
227 if ( !strcmp(argv[i],"+TRG") ) {
228 TRG = true;
229 };
230 if ( !strcmp(argv[i],"+S4") ) {
231 S4 = true;
232 };
233 if ( !strcmp(argv[i],"+ND") ) {
234 ND = true;
235 };
236 if ( !strcmp(argv[i],"+AC") ) {
237 AC = true;
238 };
239 if ( !strcmp(argv[i],"+RUN") ) {
240 RUN = true;
241 };
242 if ( !strcmp(argv[i],"+ORB") ) {
243 ORB = true;
244 };
245 //
246 //
247 if ( !strcmp(argv[i],"-all") ) {
248 CAL = false;
249 ORB = false;
250 TRK = false;
251 TRG = false;
252 TOF = false;
253 S4 = false;
254 ND = false;
255 AC = false;
256 RUN = false;
257 };
258 if ( !strcmp(argv[i],"-CAL") ) {
259 CAL = false;
260 };
261 if ( !strcmp(argv[i],"-TRK") ) {
262 TRK = false;
263 };
264 if ( !strcmp(argv[i],"-TOF") ) {
265 TOF = false;
266 };
267 if ( !strcmp(argv[i],"-TRG") ) {
268 TRG = false;
269 };
270 if ( !strcmp(argv[i],"-S4") ) {
271 S4 = false;
272 };
273 if ( !strcmp(argv[i],"-ND") ) {
274 ND = false;
275 };
276 if ( !strcmp(argv[i],"-AC") ) {
277 AC = false;
278 };
279 if ( !strcmp(argv[i],"-RUN") ) {
280 RUN = false;
281 };
282 if ( !strcmp(argv[i],"-ORB") ) {
283 ORB = false;
284 };
285 //
286
287 if (strcmp(argv[i],"-v") && strcmp(argv[i],"--verbose") && strcmp(argv[i],"-outDir") && strcmp(argv[i],"-outFile") && strcmp(argv[i], "-all") && strcmp(argv[i], "+all") && strcmp(argv[i], "-TOF") && strcmp(argv[i], "-TRK") && strcmp(argv[i], "-CAL") && strcmp(argv[i], "-TRG") && strcmp(argv[i], "-ORB") && strcmp(argv[i], "-S4") && strcmp(argv[i], "-ND") && strcmp(argv[i], "-AC") && strcmp(argv[i], "-RUN") && strcmp(argv[i], "+TOF") && strcmp(argv[i], "+TRK") && strcmp(argv[i], "+CAL") && strcmp(argv[i], "+TRG") && strcmp(argv[i], "+ORB") && strcmp(argv[i], "+S4") && strcmp(argv[i], "+ND") && strcmp(argv[i], "+AC") && strcmp(argv[i], "+RUN")){
288 printf( "\n------>Warning: WRONG OPTIONS!\n");
289 usage();
290 exit(0);
291 }
292 }
293 }
294 }
295
296 else if(argc==1){
297 printf("\n\tYou have to insert at least the file to analyze \n");
298 usage();
299 exit(0);
300 }
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 printf("\n Welcome to C3PO! \n\n");
313
314 //
315 // Open root File
316 //
317 TFile *Lev2file = new TFile(FILE);
318 if ( !Lev2file ){
319 printf("No Level2 data file, exiting...\n");
320 exit(0);
321 }
322
323 //
324 // Open rz File
325 //
326 TString rzfile;
327 if(OUTFILE=="default"){
328 Int_t posi=FILE.Last('/');
329 Int_t posf=FILE.Last('.');
330 rzfile=FILE(posi+1,posf-(posi+1));
331 rzfile+=".rz";
332 }
333 else rzfile=OUTFILE;
334 if(OUTDIR.Last('/')+1<OUTDIR.Length()) OUTDIR+="/";
335 if(OUTDIR.Length()+rzfile.Length()>=80) {
336 printf("%s%s\n\t\t ERROR: The name of the rz file is bigger then 80 characters ^\n\n",OUTDIR.Data(),rzfile.Data());
337 exit(0);
338 }
339 else {
340 path_.FillWith(OUTDIR+rzfile);
341 openlev2_();
342 }
343
344 //
345 // Run the Converter program for the detectors
346 //
347 if ( RUN ) {
348 printf(" Calling RunInfoConverter... ");
349 GL_RUN *glr=0;
350 SoftInfo *si=0;
351 TTree *runtree = (TTree*)Lev2file->Get("Run");
352 if(!runtree) printf("No Run Tree, exiting...\n");
353 else{
354 runtree->SetBranchAddress("RunInfo",&glr);
355 runtree->SetBranchAddress("SoftInfo",&si);
356 Int_t runevent=runtree->GetEntries();
357 if(runevent!=0){
358 glrun_.InitcGLRun();
359 bookruninfontupla_();
360
361 for(Int_t ev=0;ev<runevent;ev++){
362 runtree->GetEntry(ev);
363 glr->GetLevel2Struct(&glrun_);
364 si->GetLevel2Struct(&softinfo_);
365 fillruninfontupla_();
366 }
367
368 closeruninfontupla_();
369 printf("done\n");
370 }
371 else printf("The RunInfo Tree is empty, exiting...\n");
372 }
373 };
374
375
376 if ( TRK ) {
377 printf(" Calling TrackerLevel2Converter... ");
378 TrkLevel2 *trk=0;
379 TTree *trktree = (TTree*)Lev2file->Get("Tracker");
380 if(!trktree) printf("No Tracker Tree, exiting...\n");
381 else{
382 trktree->SetBranchAddress("TrkLevel2",&trk);
383 Int_t trkevent=trktree->GetEntries();
384 if(trkevent!=0){
385 tracker_.InitcTrkLevel2();
386 booktrackerntupla_();
387
388 for(Int_t ev=0;ev<trkevent;ev++){
389 trktree->GetEntry(ev);
390 trk->GetLevel2Struct(&tracker_);
391 filltrackerntupla_();
392 }
393
394 closetrackerntupla_();
395 printf("done\n");
396 }
397 else printf("The Tracker Tree is empty, exiting...\n");
398 }
399 };
400
401
402 if ( TOF ) {
403 printf(" Calling ToFLevel2Converter... ");
404 ToFLevel2 *tof=0;
405 TTree *toftree = (TTree*)Lev2file->Get("ToF");
406 if(!toftree) printf("No ToF Tree, exiting...\n");
407 else{
408 toftree->SetBranchAddress("ToFLevel2",&tof);
409 Int_t tofevent=toftree->GetEntries();
410 if(tofevent!=0){
411 tof_.InitcToFLevel2();
412 booktofntupla_();
413
414 for(Int_t ev=0;ev<tofevent;ev++){
415 toftree->GetEntry(ev);
416 tof->GetLevel2Struct(&tof_);
417 filltofntupla_();
418 }
419
420 closetofntupla_();
421 printf("done\n");
422 }
423 else printf("The ToF Tree is empty, exiting...\n");
424 }
425 };
426
427
428 if ( CAL ) {
429 printf(" Calling CalorimeterLevel2Converter... ");
430 CaloLevel2 *calo=0;
431 TTree *calotree = (TTree*)Lev2file->Get("Calorimeter");
432 if(!calotree) printf("No Calorimeter Tree, exiting...\n");
433 else{
434 calotree->SetBranchAddress("CaloLevel2",&calo);
435 Int_t caloevent=calotree->GetEntries();
436 if(caloevent!=0){
437 calo_.InitcCaloLevel2();
438 bookcalontupla_();
439
440 for(Int_t ev=0;ev<caloevent;ev++){
441 calotree->GetEntry(ev);
442 calo->GetLevel2Struct(&calo_);
443 fillcalontupla_();
444 }
445
446 closecalontupla_();
447 printf("done\n");
448 }
449 else printf("The Calorimeter Tree is empty, exiting...\n");
450 }
451 };
452
453
454 if ( TRG ) {
455 printf(" Calling TriggerLevel2Converter... ");
456 TrigLevel2 *trig=0;
457 TTree *trigtree = (TTree*)Lev2file->Get("Trigger");
458 if(!trigtree) printf("No Trigger Tree, exiting...\n");
459 else{
460 trigtree->SetBranchAddress("TrigLevel2",&trig);
461 Int_t trigevent=trigtree->GetEntries();
462 if(trigevent!=0){
463 trigger_.InitcTrigLevel2();
464 booktriggerntupla_();
465
466 for(Int_t ev=0;ev<trigevent;ev++){
467 trigtree->GetEntry(ev);
468 trig->GetLevel2Struct(&trigger_);
469 filltriggerntupla_();
470 }
471
472 closetriggerntupla_();
473 printf("done\n");
474 }
475 else printf("The Trigger Tree is empty, exiting...\n");
476 }
477 };
478
479
480 if ( AC ) {
481 printf(" Calling AnticounterLevel2Converter... ");
482 AcLevel2 *ac=0;
483 TTree *actree = (TTree*)Lev2file->Get("Anticounter");
484 if(!actree) printf("No Anticounter Tree, exiting...\n");
485 else{
486 actree->SetBranchAddress("AcLevel2",&ac);
487 Int_t acevent=actree->GetEntries();
488 if(acevent!=0){
489 antic_.InitcAcLevel2();
490 bookanticntupla_();
491
492 for(Int_t ev=0;ev<acevent;ev++){
493 actree->GetEntry(ev);
494 ac->GetLevel2Struct(&antic_);
495 fillanticntupla_();
496 }
497
498 closeanticntupla_();
499 printf("done\n");
500 }
501 else printf("The Anticounter Tree is empty, exiting...\n");
502 }
503 };
504
505
506 if ( S4 ) {
507 printf(" Calling S4Level2Converter... ");
508 S4Level2 *s4=0;
509 TTree *s4tree = (TTree*)Lev2file->Get("S4");
510 if(!s4tree) printf("No S4 Tree, exiting...\n");
511 else{
512 s4tree->SetBranchAddress("S4Level2",&s4);
513 Int_t s4event=s4tree->GetEntries();
514 if(s4event!=0){
515 s4_.InitcS4Level2();
516 books4ntupla_();
517
518 for(Int_t ev=0;ev<s4event;ev++){
519 s4tree->GetEntry(ev);
520 s4->GetLevel2Struct(&s4_);
521 fills4ntupla_();
522 }
523
524 closes4ntupla_();
525 printf("done\n");
526 }
527 else printf("The S4 Tree is empty, exiting...\n");
528 }
529 };
530
531
532 if ( ND ) {
533 printf(" Calling NDLevel2Converter... ");
534 NDLevel2 *nd=0;
535 TTree *ndtree = (TTree*)Lev2file->Get("NeutronD");
536 if(!ndtree) printf("No NeutronD Tree, exiting...\n");
537 else{
538 ndtree->SetBranchAddress("NDLevel2",&nd);
539 Int_t ndevent=ndtree->GetEntries();
540 if(ndevent!=0){
541 nd_.InitcNDLevel2();
542 bookndntupla_();
543
544 for(Int_t ev=0;ev<ndevent;ev++){
545 ndtree->GetEntry(ev);
546 nd->GetLevel2Struct(&nd_);
547 fillndntupla_();
548 }
549
550 closendntupla_();
551 printf("done\n");
552 }
553 else printf("The NeutronD Tree is empty, exiting...\n");
554 }
555 };
556
557
558 if ( ORB ) {
559 printf(" Calling OrbitalInfoConverter... ");
560 OrbitalInfo *oi=0;
561 TTree *oitree = (TTree*)Lev2file->Get("OrbitalInfo");
562 if(!oitree) printf("No OrbitalInfo Tree, exiting...\n");
563 else{
564 oitree->SetBranchAddress("OrbitalInfo",&oi);
565 Int_t oievent=oitree->GetEntries();
566 if(oievent!=0){
567 orbinfo_.InitcOrbitalInfo();
568 bookorbitalinfontupla_();
569
570 for(Int_t ev=0;ev<oievent;ev++){
571 oitree->GetEntry(ev);
572 oi->GetLevel2Struct(&orbinfo_);
573 fillorbitalinfontupla_();
574 }
575
576 closeorbitalinfontupla_();
577 printf("done\n\n");
578 }
579 else printf("The OrbitalInfo Tree is empty, exiting...\n");
580 }
581 };
582
583 //
584 // Close root file
585 //
586 Lev2file->Close();
587
588 //
589 // Close rz file
590 //
591
592 closelev2_();
593
594 //
595 // Close redirection if the case.
596 //
597 if ( !beverbose ) close(nul);
598 //
599 //
600 exit(0);
601 }

  ViewVC Help
Powered by ViewVC 1.1.23