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