]>
Commit | Line | Data |
---|---|---|
61f6b45e | 1 | //////////////////////////////////////////////////////////////////////////// |
2 | // // | |
3 | // Helper class for PWG1 TRD train // | |
4 | // // | |
5 | // Authors: // | |
6 | // Markus Fasel <M.Fasel@gsi.de> // | |
7 | // // | |
8 | //////////////////////////////////////////////////////////////////////////// | |
9 | ||
3ceb45ae | 10 | #include "TError.h" |
7f1490fc | 11 | #include <Rtypes.h> |
5468a262 | 12 | #include <TMath.h> |
7f1490fc | 13 | #include <TObjArray.h> |
14 | #include <TObjString.h> | |
5468a262 | 15 | #include <TFileMerger.h> |
7f1490fc | 16 | #include <TRandom.h> |
17 | #include <TString.h> | |
18 | #include <TSystem.h> | |
19 | ||
5468a262 | 20 | #include <string> |
7f1490fc | 21 | #include <cstring> |
22 | #include <fstream> | |
23 | ||
24 | #include "AliTRDpwg1Helper.h" | |
25 | ||
99535225 | 26 | const Char_t * AliTRDpwg1Helper::fgkTRDtaskClassName[AliTRDpwg1Helper::kNTRDTASKS] = { |
7f1490fc | 27 | "AliTRDcheckESD" |
28 | ,"AliTRDinfoGen" | |
29 | ,"AliTRDcheckDET" | |
30 | ,"AliTRDefficiency" | |
31 | ,"AliTRDresolution" | |
32 | ,"AliTRDcheckPID" | |
33 | ,"AliTRDv0Monitor" | |
3ceb45ae | 34 | ,"AliTRDcheckTRK" |
7f1490fc | 35 | ,"AliTRDcalibration" |
36 | ,"AliTRDefficiencyMC" | |
37 | ,"AliTRDalignmentTask" | |
38 | ,"AliTRDpidRefMaker" | |
39 | ,"AliTRDclusterResolution" | |
40 | ,"AliTRDmultiplicity" | |
41 | }; | |
42 | ||
99535225 | 43 | const Char_t * AliTRDpwg1Helper::fgkTRDtaskOpt[AliTRDpwg1Helper::kNTRDTASKS+1] = { |
7f1490fc | 44 | "ESD" |
45 | ,"GEN" | |
46 | ,"DET" | |
47 | ,"EFF" | |
48 | ,"RES" | |
49 | ,"PID" | |
50 | ,"V0" | |
3ceb45ae | 51 | ,"TRK" |
7f1490fc | 52 | ,"CAL" |
53 | ,"EFFC" | |
54 | ,"ALGN" | |
55 | ,"PIDR" | |
56 | ,"CLRES" | |
57 | ,"MULT" | |
58 | ,"ALL" | |
59 | }; | |
60 | ||
b94f89e4 | 61 | //______________________________________________________ |
62 | Bool_t AliTRDpwg1Helper::DoTask(Int_t idx, Int_t map) | |
63 | { | |
64 | return TESTBIT(map, idx); | |
65 | } | |
66 | ||
7f1490fc | 67 | //______________________________________________________ |
61f6b45e | 68 | Int_t AliTRDpwg1Helper::ParseOptions(Char_t *trd) |
69 | { | |
70 | // Parse space separated options. | |
71 | // Possible options are: | |
72 | // "ALL" : [default] all performance (no calibration) tasks | |
73 | // ------- Performance tasks ---------- | |
74 | // "ESD" : Basic TRD Detector checks on ESD only (no TRD tracks analysed) | |
75 | // "DET" : Basic TRD Detector checks | |
76 | // "RES" : TRD tracking Resolution | |
77 | // "EFF" : TRD Tracking Efficiency | |
78 | // "PID" : TRD PID - pion efficiency | |
79 | // "V0" : monitor V0 performance for use in TRD PID calibration | |
80 | // ------- Calibration tasks ---------- | |
3ceb45ae | 81 | // "TRK" : multidimensional tracking performance resolution |
61f6b45e | 82 | // "EFFC" : TRD Tracking Efficiency Combined (barrel + stand alone) - only in case of simulations |
83 | // "MULT" : TRD single track selection | |
84 | // "CLRES": clusters Resolution | |
85 | // "CAL" : TRD calibration | |
86 | // "ALGN" : TRD alignment | |
87 | // "PIDR" : TRD PID - reference data | |
88 | // ------- SPECIAL OPTIONS ----------- | |
89 | // "NOFR" : Data set does not have AliESDfriends.root | |
90 | // "NOMC" : Data set does not have Monte Carlo Informations (default have MC), | |
91 | ||
8ee59659 | 92 | Int_t fSteerTask = 0; |
7f1490fc | 93 | TObjArray *tasksArray = TString(trd).Tokenize(" "); |
94 | for(Int_t isel = 0; isel < tasksArray->GetEntriesFast(); isel++){ | |
95 | TString s = (dynamic_cast<TObjString *>(tasksArray->UncheckedAt(isel)))->String(); | |
96 | if(s.CompareTo("ALL") == 0){ | |
97 | for(Int_t itask = 0; itask < kNTRDQATASKS; itask++) SETBIT(fSteerTask, itask); | |
98 | continue; | |
99 | } else if(s.CompareTo("NOMC") == 0 || s.CompareTo("NOFR") == 0){ | |
100 | continue; // taken care by special functions | |
101 | } else { | |
102 | Bool_t foundOpt = kFALSE; | |
103 | for(Int_t itask = 0; itask < kNTRDTASKS; itask++){ | |
104 | if(s.CompareTo(fgkTRDtaskOpt[itask]) != 0) continue; | |
105 | SETBIT(fSteerTask, itask); | |
106 | if(itask>1) SETBIT(fSteerTask, kInfoGen); | |
107 | foundOpt = kTRUE; | |
108 | break; | |
109 | } | |
3ceb45ae | 110 | if(!foundOpt) Warning("AliTRDpwg1Helper::ParseOptions()", Form("TRD task %s not implemented (yet).", s.Data())); |
7f1490fc | 111 | } |
112 | } | |
113 | // extra rules for calibration tasks | |
3ed01fbe | 114 | // if(TESTBIT(fSteerTask, kCheckTRK)) SETBIT(fSteerTask, kResolution); |
7f1490fc | 115 | if(TESTBIT(fSteerTask, kCalibration)) SETBIT(fSteerTask, kCheckDET); |
116 | if(TESTBIT(fSteerTask, kMultiplicity)) SETBIT(fSteerTask, kEfficiency); | |
117 | if(TESTBIT(fSteerTask, kEfficiencyMC)) SETBIT(fSteerTask, kEfficiency); | |
118 | if(TESTBIT(fSteerTask, kClErrParam)) SETBIT(fSteerTask, kResolution); | |
119 | if(TESTBIT(fSteerTask, kAlignment)) SETBIT(fSteerTask, kResolution); | |
120 | if(TESTBIT(fSteerTask, kPIDRefMaker)) SETBIT(fSteerTask, kCheckPID); | |
121 | if(TESTBIT(fSteerTask, kV0Monitor)) SETBIT(fSteerTask, kCheckPID); | |
122 | ||
123 | return fSteerTask; | |
124 | ||
125 | } | |
126 | ||
127 | //______________________________________________________ | |
5468a262 | 128 | void AliTRDpwg1Helper::MergeProd(const Char_t *mark, const Char_t *files, const Int_t nBatch, Int_t level) |
7f1490fc | 129 | { |
5468a262 | 130 | // Recursively merge files named "mark" from list in "files" in groups of "nBatch" files. |
131 | // parameter "level" is used to index recurent calls of this function. | |
7f1490fc | 132 | |
7fe4e88b | 133 | Char_t lMERGE[8]; snprintf(lMERGE, 8, "%04d.lst", (Int_t)gRandom->Uniform(9999.)); |
134 | Char_t lPURGE[8]; snprintf(lPURGE, 8, "%04d.lst", (Int_t)gRandom->Uniform(9999.)); | |
7f1490fc | 135 | |
136 | // purge file list | |
137 | std::string filename; | |
138 | std::ifstream file(files); | |
139 | Int_t iline(0); | |
140 | while(getline(file, filename)){ | |
141 | if(Int_t(filename.find(mark)) < 0) continue; | |
61f6b45e | 142 | gSystem->Exec(Form("echo %s >> %s", filename.c_str(), lPURGE)); |
7f1490fc | 143 | iline++; |
144 | } | |
74427277 | 145 | Int_t nBatches=Int_t(TMath::Ceil(Double_t(iline)/nBatch)); |
5468a262 | 146 | Info("MergeProd()", Form("Merge %d files in %d batches.", iline, nBatches)); |
7f1490fc | 147 | |
5468a262 | 148 | Int_t first(0); |
7f1490fc | 149 | for(Int_t ibatch(0); ibatch<nBatches; ibatch++){ |
5468a262 | 150 | first = ibatch*nBatch; |
151 | if(!gSystem->Exec(Form("aliroot -b -q \'$ALICE_ROOT/PWG1/TRD/macros/mergeBatch.C(\"%s\", \"%s\", %d, %d)\'", mark, lPURGE, nBatch, first))) continue; | |
152 | gSystem->Exec(Form("mv %d_%s merge/%d_%d_%s", first, mark, level, first, mark)); | |
153 | gSystem->Exec(Form("echo %s/merge/%d_%d_%s >> %s", gSystem->ExpandPathName("$PWD"), level, first, mark, lMERGE)); | |
7f1490fc | 154 | } |
5468a262 | 155 | |
156 | if(nBatches==1){ | |
3ceb45ae | 157 | Info("AliTRDpwg1Helper::MergeProd()", "Rename 1 merged file."); |
5468a262 | 158 | gSystem->Exec(Form("mv merge/%d_%d_%s %s", level, first, mark, mark)); |
159 | } else if(nBatches<=nBatch){ | |
3ceb45ae | 160 | Info("AliTRDpwg1Helper::MergeProd()", Form("Merge %d files in 1 batch.", nBatches)); |
5468a262 | 161 | if(!gSystem->Exec(Form("aliroot -b -q \'$ALICE_ROOT/PWG1/TRD/macros/mergeBatch.C(\"%s\", \"%s\", %d, 0, kFALSE)\'", mark, lMERGE, nBatches))) return; |
162 | gSystem->Exec(Form("mv 0_%s %s", mark, mark)); | |
c5342457 | 163 | } else { |
164 | level++; | |
3ceb45ae | 165 | Info("AliTRDpwg1Helper::MergeProd()", Form("Merge level %d.", level)); |
c5342457 | 166 | MergeProd(mark, lMERGE, nBatch, level); |
167 | } | |
5468a262 | 168 | gSystem->Exec(Form("rm -fv %s %s", lMERGE, lPURGE)); |
169 | } | |
170 | ||
171 | ||
172 | //______________________________________________________ | |
173 | const Char_t* AliTRDpwg1Helper::MergeBatch(const Char_t *mark, const Char_t *files, const Int_t nfiles, const Int_t first, Bool_t kSVN, Bool_t kCLEAR) | |
174 | { | |
175 | // Merge files specified in the file list "files" by the token "mark". | |
176 | // The script will merge "nfiles" files starting from the "first" file. | |
177 | // If the file "svnInfo.log" is found together with the files to be merged it is copied locally | |
178 | // if option "kSVN". The input files are removed from disk if option "kCLEAR". | |
179 | // | |
180 | // On return the name of the merged file is return or NULL in case of failure. | |
181 | // | |
182 | TObjArray arr(nfiles); arr.SetOwner(kTRUE); | |
5468a262 | 183 | TFileMerger fFM(kTRUE); |
184 | fFM.OutputFile(Form("%s/%d_%s", gSystem->ExpandPathName("$PWD"), first, mark)); | |
185 | Int_t iline(0), nbatch(0); | |
186 | std::string filename; | |
187 | std::ifstream file(files); | |
188 | while(getline(file, filename)){ | |
189 | if(Int_t(filename.find(mark)) < 0) continue; | |
62028b10 | 190 | if(iline<first){ |
191 | iline++; | |
192 | continue; | |
193 | } | |
5468a262 | 194 | if(kSVN){ // download SVN info for trending |
302e5f17 | 195 | if(gSystem->Exec(Form("if [ ! -f svnInfo.log ]; then cp -v %s/svnInfo.log %s; fi", Dirname(filename.c_str()), gSystem->ExpandPathName("$PWD"))) == 0) kSVN=kFALSE; |
5468a262 | 196 | } |
3ceb45ae | 197 | Info("AliTRDpwg1Helper::MergeBatch()", filename.c_str()); |
62028b10 | 198 | if(!fFM.AddFile(filename.c_str())) return NULL; |
5468a262 | 199 | arr.Add(new TObjString(filename.c_str())); |
200 | nbatch++; | |
201 | if(nbatch==nfiles) break; | |
202 | } | |
203 | if(!nbatch){ | |
3ceb45ae | 204 | Warning("AliTRDpwg1Helper::MergeBatch()", "NOTHING TO MERGE"); return NULL; |
5468a262 | 205 | } else { |
3ceb45ae | 206 | Info("AliTRDpwg1Helper::MergeBatch()", "MERGING FILES[%d] START[%d] %s ... ", nbatch, first, ((nbatch<nfiles)?"INCOMPLETE":"")); |
5468a262 | 207 | } |
208 | if(!fFM.Merge()) return NULL; | |
209 | ||
210 | if(kCLEAR){ | |
211 | for(Int_t ifile(0); ifile<arr.GetEntries(); ifile++){ | |
212 | gSystem->Exec(Form("rm -fv %s", ((TObjString*)arr.At(ifile))->GetString().Data())); | |
213 | } | |
214 | } | |
215 | return fFM.GetOutputFileName(); | |
216 | } | |
217 | ||
218 | //______________________________________________________ | |
219 | const Char_t* AliTRDpwg1Helper::Basename(const char* filepath) | |
220 | { | |
221 | // Implementation of shell "basename" builtin | |
222 | TString s(filepath); | |
223 | Int_t idx(s.Last('/')+1); | |
224 | s=s(idx, idx+100); | |
225 | return s; | |
226 | } | |
227 | ||
228 | //______________________________________________________ | |
229 | const Char_t* AliTRDpwg1Helper::Dirname(const char* filepath) | |
230 | { | |
231 | // Implementation of shell "dirname" builtin | |
232 | TString s(filepath); | |
233 | Int_t idx(s.Last('/')); | |
234 | s=s(0, idx); | |
235 | return s; | |
7f1490fc | 236 | } |
237 | ||
8ee59659 | 238 | //______________________________________________________ |
61f6b45e | 239 | Int_t AliTRDpwg1Helper::GetTaskIndex(const Char_t *name) |
240 | { | |
241 | // Give index in TRD train of task class "name" | |
8ee59659 | 242 | for(Int_t it(0); it<kNTRDTASKS; it++){ |
243 | if(strcmp(fgkTRDtaskClassName[it], name)==0) return it; | |
244 | } | |
245 | return -1; | |
246 | } | |
247 | ||
7f1490fc | 248 | //______________________________________________________ |
61f6b45e | 249 | Bool_t AliTRDpwg1Helper::HasReadMCData(Char_t *opt) |
250 | { | |
251 | // Use MC data option | |
7f1490fc | 252 | return !(Bool_t)strstr(opt, "NOMC"); |
253 | } | |
254 | ||
255 | //____________________________________________ | |
61f6b45e | 256 | Bool_t AliTRDpwg1Helper::HasReadFriendData(Char_t *opt) |
257 | { | |
258 | // Use friends data option | |
7f1490fc | 259 | return !(Bool_t)strstr(opt, "NOFR"); |
260 | } | |
261 |