new macro for processing calibration tasks
[u/mrichter/AliRoot.git] / TRD / qaRec / macros / AliTRDperformanceTrain.h
1 #ifndef ALITRDPERFORMANCETRAIN_H
2 #define ALITRDPERFORMANCETRAIN_H
3
4 #define BIT(n)      (1 << (n))
5 #define SETBIT(n,i) ((n) |= BIT(i))
6 #define TSTBIT(n,i) ((Bool_t)(((n) & BIT(i)) != 0))
7 #define CLRBIT(n,i) ((n) &= ~BIT(i))
8
9 #define NTRDQATASKS 6
10 #define NTRDCALIBTASKS 7
11 const Int_t NTRDTASKS = NTRDQATASKS+NTRDCALIBTASKS;
12
13 enum AliTRDrecoTasks{
14    kCheckESD      = 0
15   ,kInfoGen       = 1
16   ,kCheckDET      = 2
17   ,kEfficiency    = 3
18   ,kResolution    = 4
19   ,kCheckPID      = 5
20   ,kCalibration   = 6
21   ,kEfficiencyMC  = 7
22   ,kAlignment     = 8
23   ,kPIDRefMakerLQ = 9
24   ,kPIDRefMakerNN =10
25   ,kClErrParam    =11
26   ,kMultiplicity  =12
27 };
28
29 const Char_t* fgkTRDtaskClassName[NTRDTASKS] = {
30   "AliTRDcheckESD"
31   ,"AliTRDinfoGen"
32   ,"AliTRDcheckDET"
33   ,"AliTRDefficiency"
34   ,"AliTRDresolution"
35   ,"AliTRDcheckPID"
36   ,"AliTRDcalibration"
37   ,"AliTRDefficiencyMC"
38   ,"AliTRDalignmentTask"
39   ,"AliTRDpidRefMakerLQ"
40   ,"AliTRDpidRefMakerNN"
41   ,"AliTRDclusterResolution"
42   ,"AliTRDmultiplicity"
43 };
44
45 const Char_t *fgkTRDtaskOpt[NTRDTASKS+1] = {
46   ""
47   ,"GEN"
48   ,"DET"
49   ,"EFF"
50   ,"RES"
51   ,"PID"
52   ,"CAL"
53   ,"EFFC"
54   ,"ALGN"
55   ,"LQR"
56   ,"NNR"
57   ,"CLRES"
58   ,"MULT"
59   ,"ALL"
60 };
61
62 #if ! defined (__CINT__) || defined (__MAKECINT__)
63 #include "TFileMerger.h"
64 #include "TSystem.h"
65 #include "TString.h"
66 #include "TObjString.h"
67 #include "TObjArray.h"
68 #include "TError.h"
69 #endif
70
71 #include <cstring>
72
73 //____________________________________________
74 Bool_t HasReadMCData(Char_t *opt){
75   return !(Bool_t)strstr(opt, "NOMC");
76 }
77
78 //____________________________________________
79 Bool_t HasReadFriendData(Char_t *opt){
80   return !(Bool_t)strstr(opt, "NOFR");
81 }
82
83 //____________________________________________
84 Int_t ParseOptions(Char_t *trd)
85 {
86   Int_t fSteerTask = 1;
87   TObjArray *tasksArray = TString(trd).Tokenize(" ");
88   for(Int_t isel = 0; isel < tasksArray->GetEntriesFast(); isel++){
89     TString s = (dynamic_cast<TObjString *>(tasksArray->UncheckedAt(isel)))->String();
90     if(s.CompareTo("ALL") == 0){
91       for(Int_t itask = 0; itask < NTRDQATASKS; itask++) SETBIT(fSteerTask, itask);
92       continue;
93     } else { 
94       Bool_t foundOpt = kFALSE;  
95       for(Int_t itask = 2; itask < NTRDTASKS; itask++){
96         if(s.CompareTo(fgkTRDtaskOpt[itask]) != 0) continue;
97         SETBIT(fSteerTask, itask); SETBIT(fSteerTask, kInfoGen);
98         foundOpt = kTRUE;
99         break;
100       }
101       if(!foundOpt) Info("run.C", Form("TRD task %s not implemented (yet).", s.Data()));
102     }
103   }
104   // extra rules for calibration tasks
105 //   if(TSTBIT(fSteerTask, kCalibration)) SETBIT(fSteerTask, kCheckDET);
106 //   if(TSTBIT(fSteerTask, kMultiplicity)) SETBIT(fSteerTask, kEfficiency);
107 //   if(TSTBIT(fSteerTask, kEfficiencyMC)) SETBIT(fSteerTask, kEfficiency);
108 //   if(TSTBIT(fSteerTask, kClErrParam)) SETBIT(fSteerTask, kResolution);
109 //   if(TSTBIT(fSteerTask, kAlignment)) SETBIT(fSteerTask, kResolution);
110 //   if(TSTBIT(fSteerTask, kPIDRefMaker)) SETBIT(fSteerTask, kCheckPID);
111
112   return fSteerTask;
113 }
114
115 //______________________________________________________
116 void mergeProd(const Char_t *mark, const Char_t *files)
117 {
118   const Int_t kBatch = 20;
119
120   TFileMerger *fFM = new TFileMerger(1);
121   fFM->OutputFile(Form("%s/0_%s",  gSystem->ExpandPathName("$PWD"), mark));
122
123   Int_t jbatch = 0, nbatch = 0;
124   string filename;
125   ifstream file(files);
126   while(getline(file, filename)){
127     if(Int_t(filename.find(mark)) < 0) continue;
128     fFM->AddFile(filename.c_str()); nbatch++;
129     if(nbatch==kBatch){
130       //printf("MERGE BATCH %d [%d]\n", jbatch, nbatch);
131       fFM->Merge(); jbatch++;
132       new(fFM) TFileMerger(kTRUE);
133       fFM->OutputFile(Form("%s/%d_%s",  gSystem->ExpandPathName("$PWD"), jbatch, mark));
134       nbatch=0;
135     }
136   }
137   if(nbatch){
138     //printf("MERGE BATCH %d[%d]\n", jbatch, nbatch);
139     fFM->Merge();
140     jbatch++;
141   }
142   if(!jbatch){
143     delete fFM;
144     return;
145   }
146
147   new(fFM) TFileMerger(kTRUE);
148   fFM->OutputFile(Form("%s/%s",  gSystem->ExpandPathName("$PWD"), mark));
149   for(Int_t ib=jbatch; ib--;){
150     fFM->AddFile(Form("%s/%d_%s",  gSystem->ExpandPathName("$PWD"), ib, mark));
151     gSystem->Exec(Form("rm -f %s/%d_%s", gSystem->ExpandPathName("$PWD"), ib, mark));
152   }
153   fFM->Merge();
154   delete fFM;
155 }
156
157 #endif
158