]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG1/TRD/AliTRDpwg1Helper.cxx
fix steering of (all) individual TRD tasks by AddTrainPerformanceTRD.C
[u/mrichter/AliRoot.git] / PWG1 / TRD / AliTRDpwg1Helper.cxx
1 #include <Rtypes.h>
2 #include <TError.h>
3 #include <TObjArray.h>
4 #include <TObjString.h>
5 #include <TRandom.h>
6 #include <TString.h>
7 #include <TSystem.h>
8
9 #include <cstring>
10 #include <fstream>
11
12 #include "AliTRDpwg1Helper.h"
13
14 Char_t const* AliTRDpwg1Helper::fgkTRDtaskClassName[AliTRDpwg1Helper::kNTRDTASKS] = {
15   "AliTRDcheckESD"
16   ,"AliTRDinfoGen"
17   ,"AliTRDcheckDET"
18   ,"AliTRDefficiency"
19   ,"AliTRDresolution"
20   ,"AliTRDcheckPID"
21   ,"AliTRDv0Monitor"
22   ,"AliTRDcalibration"
23   ,"AliTRDefficiencyMC"
24   ,"AliTRDalignmentTask"
25   ,"AliTRDpidRefMaker"
26   ,"AliTRDclusterResolution"
27   ,"AliTRDmultiplicity"
28 };
29
30 Char_t const* AliTRDpwg1Helper::fgkTRDtaskOpt[AliTRDpwg1Helper::kNTRDTASKS+1] = {
31   "ESD"
32   ,"GEN"
33   ,"DET"
34   ,"EFF"
35   ,"RES"
36   ,"PID"
37   ,"V0"
38   ,"CAL"
39   ,"EFFC"
40   ,"ALGN"
41   ,"PIDR"
42   ,"CLRES"
43   ,"MULT"
44   ,"ALL"
45 };
46
47 //______________________________________________________
48 Int_t AliTRDpwg1Helper::ParseOptions(Char_t *trd){
49   Int_t fSteerTask = 0;
50   TObjArray *tasksArray = TString(trd).Tokenize(" ");
51   for(Int_t isel = 0; isel < tasksArray->GetEntriesFast(); isel++){
52     TString s = (dynamic_cast<TObjString *>(tasksArray->UncheckedAt(isel)))->String();
53     if(s.CompareTo("ALL") == 0){
54       for(Int_t itask = 0; itask < kNTRDQATASKS; itask++) SETBIT(fSteerTask, itask);
55       continue;
56     } else if(s.CompareTo("NOMC") == 0 || s.CompareTo("NOFR") == 0){
57       continue; // taken care by special functions
58     } else { 
59       Bool_t foundOpt = kFALSE;  
60       for(Int_t itask = 0; itask < kNTRDTASKS; itask++){
61         if(s.CompareTo(fgkTRDtaskOpt[itask]) != 0) continue;
62         SETBIT(fSteerTask, itask); 
63         if(itask>1) SETBIT(fSteerTask, kInfoGen);
64         foundOpt = kTRUE;
65         break;
66       }
67       if(!foundOpt) Info("ParseOptions()", Form("TRD task %s not implemented (yet).", s.Data()));
68     }
69   }
70   // extra rules for calibration tasks
71   if(TESTBIT(fSteerTask, kCalibration)) SETBIT(fSteerTask, kCheckDET);
72   if(TESTBIT(fSteerTask, kMultiplicity)) SETBIT(fSteerTask, kEfficiency);
73   if(TESTBIT(fSteerTask, kEfficiencyMC)) SETBIT(fSteerTask, kEfficiency);
74   if(TESTBIT(fSteerTask, kClErrParam)) SETBIT(fSteerTask, kResolution);
75   if(TESTBIT(fSteerTask, kAlignment)) SETBIT(fSteerTask, kResolution);
76   if(TESTBIT(fSteerTask, kPIDRefMaker)) SETBIT(fSteerTask, kCheckPID);
77   if(TESTBIT(fSteerTask, kV0Monitor)) SETBIT(fSteerTask, kCheckPID);
78
79   return fSteerTask;
80
81 }
82
83 //______________________________________________________
84 void AliTRDpwg1Helper::MergeProd(const Char_t *mark, const Char_t *files, const Int_t nBatch = 20)
85 {
86
87
88   // Clear first predefines
89   Char_t MERGE[8]; sprintf(MERGE, "%d.lst", (Int_t)gRandom->Uniform(9999.));
90   Char_t PURGE[8]; sprintf(PURGE, "%d.lst", (Int_t)gRandom->Uniform(9999.));
91   gSystem->Exec("mkdir -p merge; rm -rf merge/*");
92
93   // purge file list
94   std::string filename;
95   std::ifstream file(files);
96   Int_t iline(0);
97   while(getline(file, filename)){
98     if(Int_t(filename.find(mark)) < 0) continue;
99     gSystem->Exec(Form("echo %s >> %s", filename.c_str(), PURGE));
100     iline++;
101   }
102   Int_t nBatches(iline/nBatch);
103
104   for(Int_t ibatch(0); ibatch<nBatches; ibatch++){
105     Int_t first(ibatch*nBatch);
106     if(!gSystem->Exec(Form("root.exe -b -q \'$ALICE_ROOT/PWG1/TRD/macros/mergeBatch.C(\"%s\", \"%s\", %d, %d)\'", mark, PURGE, nBatch, first))) continue;
107     gSystem->Exec(Form("mv %d_%s merge/", first, mark));
108     gSystem->Exec(Form("echo %s/merge/%d_%s >> %s", gSystem->ExpandPathName("$PWD"), first, mark, MERGE));
109   }
110   gSystem->Exec(Form("root.exe -b -q \'$ALICE_ROOT/PWG1/TRD/macros/mergeBatch.C(\"%s\", \"%s\", %d, 0, kFALSE, kTRUE)\'", mark, MERGE, nBatches));
111   gSystem->Exec(Form("mv 0_%s %s", mark, mark));
112   
113   gSystem->Exec(Form("rm -rfv %s %s merge", MERGE, PURGE));
114 }
115
116 //______________________________________________________
117 Int_t AliTRDpwg1Helper::GetTaskIndex(const Char_t *name){
118   for(Int_t it(0); it<kNTRDTASKS; it++){
119     if(strcmp(fgkTRDtaskClassName[it], name)==0) return it;
120   }
121   return -1;
122 }
123
124 //______________________________________________________
125 Bool_t AliTRDpwg1Helper::HasReadMCData(Char_t *opt){
126   return !(Bool_t)strstr(opt, "NOMC");
127 }
128
129 //____________________________________________
130 Bool_t AliTRDpwg1Helper::HasReadFriendData(Char_t *opt){
131   return !(Bool_t)strstr(opt, "NOFR");
132 }
133