]>
Commit | Line | Data |
---|---|---|
caaf90d2 | 1 | // Uncomment to display debugging infos |
2 | //#define ALIEVETRDTRACKLIST_DEBUG | |
3 | ||
2ef0687e | 4 | #include "AliEveTRDTrackList.h" |
5 | ||
caaf90d2 | 6 | #include <AliTRDtrackV1.h> |
7 | #include <TFile.h> | |
8 | #include <TFunction.h> | |
9 | #include <TList.h> | |
10 | #include <TObjString.h> | |
11 | #include <TROOT.h> | |
12 | #include <TSystem.h> | |
13 | #include <TTree.h> | |
14 | #include <TTreeStream.h> | |
15 | #include <EveDet/AliEveTRDData.h> | |
16 | ||
2ef0687e | 17 | ClassImp(AliEveTRDTrackList) |
18 | ||
19 | /////////////////////////////////////////////////////////// | |
20 | ///////////// AliEveTRDTrackList //////////////////////// | |
21 | /////////////////////////////////////////////////////////// | |
22 | AliEveTRDTrackList::AliEveTRDTrackList(const Text_t* n, const Text_t* t, Bool_t doColor): | |
23 | TEveElementList(n, t, doColor), | |
caaf90d2 | 24 | fMacroList(0), |
25 | fMacroSelList(0), | |
26 | fDataFromMacroList(0), | |
4f6473f6 | 27 | fDataTree(0), |
28 | fHistoDataSelected(0), | |
29 | fMacroListSelected(0), | |
30 | fMacroSelListSelected(0), | |
31 | fSelectedTab(1) // Standard tab: "Apply macros" (index 1) | |
2ef0687e | 32 | { |
caaf90d2 | 33 | // Only accept childs of type AliEveTRDTrack |
2ef0687e | 34 | SetChildClass(AliEveTRDTrack::Class()); |
35 | ||
caaf90d2 | 36 | fMacroList = new TList(); |
37 | fMacroSelList = new TList(); | |
38 | fDataFromMacroList = new TList(); | |
39 | ||
4f6473f6 | 40 | //fDataTree = new TTreeSRedirector("TRD.TrackListMacroData.root"); |
caaf90d2 | 41 | |
42 | AddStandardMacros(); | |
43 | } | |
44 | ||
8e27fca1 | 45 | //______________________________________________________ |
caaf90d2 | 46 | AliEveTRDTrackList::~AliEveTRDTrackList() |
47 | { | |
48 | if (fMacroList != 0) | |
49 | { | |
50 | fMacroList->Clear(); | |
51 | delete fMacroList; | |
52 | fMacroList = 0; | |
53 | } | |
54 | if (fMacroSelList != 0) | |
55 | { | |
56 | fMacroSelList->Clear(); | |
57 | delete fMacroSelList; | |
58 | fMacroSelList = 0; | |
59 | } | |
60 | if (fDataFromMacroList != 0) | |
61 | { | |
62 | fDataFromMacroList->Clear(); | |
63 | delete fDataFromMacroList; | |
64 | fDataFromMacroList = 0; | |
65 | } | |
66 | if (fDataTree != 0) | |
67 | { | |
68 | delete fDataTree; | |
69 | fDataTree = 0; | |
70 | } | |
71 | } | |
72 | ||
8e27fca1 | 73 | //______________________________________________________ |
caaf90d2 | 74 | Int_t AliEveTRDTrackList::AddMacro(const Char_t* path, const Char_t* nameC) |
75 | { | |
76 | // First check the type of the macro: | |
77 | // If it has the signature of a selection macro: | |
78 | // Bool_t MacroName(AliTRDtrackV1*) | |
79 | // it is assumed to be a selection macro. | |
80 | // If it has the signature of a process macro: | |
81 | // void MacroName(AliTRDtrackV1*, Double_t*&, Int_t&) | |
82 | // it is assumed to be a process macro. | |
83 | // In all other cases: Macro is rejected | |
84 | Bool_t isSelectionMacro = kFALSE; | |
85 | Bool_t hasCorrectSignature = kFALSE; | |
86 | ||
87 | ||
88 | Char_t* entryName = MakeMacroEntry(path, nameC); | |
89 | ||
4f6473f6 | 90 | Char_t pathname[fkMaxMacroPathNameLength]; |
91 | memset(pathname, '\0', sizeof(Char_t) * fkMaxMacroPathNameLength); | |
caaf90d2 | 92 | |
93 | // Expand the path and create the pathname | |
94 | Char_t* systemPath = gSystem->ExpandPathName(path); | |
95 | sprintf(pathname, "%s/%s", systemPath, nameC); | |
96 | delete systemPath; | |
97 | systemPath = 0; | |
98 | ||
99 | // Delete ".C" from filename | |
4f6473f6 | 100 | Char_t name[fkMaxMacroNameLength]; |
101 | memset(name, '\0', sizeof(Char_t) * fkMaxMacroNameLength); | |
102 | ||
103 | for (UInt_t ind = 0; ind < fkMaxMacroNameLength && ind < strlen(nameC) - 2; ind++) name[ind] = nameC[ind]; | |
caaf90d2 | 104 | |
105 | // Check, if files exists | |
106 | FILE* fp = 0; | |
107 | ||
108 | fp = fopen(pathname, "rb"); | |
109 | if (fp != 0) | |
110 | { | |
111 | fclose(fp); | |
112 | fp = 0; | |
113 | } | |
114 | else | |
115 | { | |
caaf90d2 | 116 | if (entryName != 0) delete entryName; |
117 | entryName = 0; | |
118 | ||
119 | return NOT_EXIST_ERROR; | |
120 | } | |
121 | ||
122 | // Clean up root, load the desired macro and then check the type of the macro | |
123 | //gROOT->Reset("a"); | |
124 | gROOT->Reset(); | |
4f6473f6 | 125 | gROOT->ProcessLineSync(Form(".L %s+", pathname)); |
caaf90d2 | 126 | |
127 | // Selection macro? | |
4f6473f6 | 128 | TFunction* f = gROOT->GetGlobalFunctionWithPrototype(name, "const AliTRDtrackV1*", kTRUE); |
8e27fca1 | 129 | if (f != 0x0) |
130 | { | |
131 | if (!strcmp(f->GetReturnTypeName(), "Bool_t")) | |
132 | { | |
c04e790a | 133 | // Some additional check (is the parameter EXACTLY of the desired type?) |
4f6473f6 | 134 | if (strstr(f->GetMangledName(), "oPconstsPAliTRDtrackV1mUsP") != 0x0) |
8e27fca1 | 135 | { |
c04e790a | 136 | hasCorrectSignature = kTRUE; |
137 | isSelectionMacro = kTRUE; | |
138 | } | |
caaf90d2 | 139 | } |
8e27fca1 | 140 | } |
141 | // Process macro? | |
142 | else | |
143 | { | |
4f6473f6 | 144 | f = gROOT->GetGlobalFunctionWithPrototype(name, "const AliTRDtrackV1*, Double_t*&, Int_t&", kTRUE); |
8e27fca1 | 145 | if (f != 0x0) |
146 | { | |
147 | if (!strcmp(f->GetReturnTypeName(), "void")) | |
148 | { | |
c04e790a | 149 | // Some additional check (are the parameters EXACTLY of the desired type?) |
4f6473f6 | 150 | if (strstr(f->GetMangledName(), "oPconstsPAliTRDtrackV1mUsP") != 0x0 && |
151 | strstr(f->GetMangledName(), "cODouble_tmUaNsP") != 0x0 && | |
152 | strstr(f->GetMangledName(), "cOInt_taNsP") != 0x0) | |
8e27fca1 | 153 | { |
c04e790a | 154 | hasCorrectSignature = kTRUE; |
155 | isSelectionMacro = kFALSE; | |
156 | } | |
caaf90d2 | 157 | } |
158 | } | |
159 | } | |
160 | ||
4f6473f6 | 161 | //// Clean up again / unload this function |
162 | //gROOT->ProcessLineSync(Form(".U %s", pathname)); | |
caaf90d2 | 163 | //gROOT->Reset("a"); |
4f6473f6 | 164 | // Clean up again |
caaf90d2 | 165 | gROOT->Reset(); |
4f6473f6 | 166 | |
caaf90d2 | 167 | // Has not the correct signature! |
168 | if (!hasCorrectSignature) | |
169 | { | |
170 | if (entryName != 0) delete entryName; | |
171 | entryName = 0; | |
172 | return SIGNATURE_ERROR; | |
173 | } | |
174 | ||
175 | Int_t returnValue = WARNING; | |
176 | ||
177 | // Only add macro, if it is not already in the list | |
178 | if (!isSelectionMacro && fMacroList->FindObject(entryName) == 0) | |
179 | { | |
180 | fMacroList->Add(new TObjString(entryName)); | |
181 | fMacroList->Sort(); | |
182 | ||
183 | returnValue = SUCCESS; | |
184 | } | |
185 | else if (isSelectionMacro && fMacroSelList->FindObject(entryName) == 0) | |
186 | { | |
187 | fMacroSelList->Add(new TObjString(entryName)); | |
188 | fMacroSelList->Sort(); | |
189 | ||
190 | returnValue = SUCCESS; | |
191 | } | |
192 | else returnValue = WARNING; | |
193 | ||
194 | if (entryName != 0) delete entryName; | |
195 | entryName = 0; | |
196 | ||
197 | return returnValue; | |
198 | } | |
4f6473f6 | 199 | /* |
8e27fca1 | 200 | //______________________________________________________ |
caaf90d2 | 201 | void AliEveTRDTrackList::AddMacroFast(const Char_t* path, const Char_t* name, Bool_t toSelectionList) |
202 | { | |
203 | Char_t* entry = MakeMacroEntry(path, name); | |
8e27fca1 | 204 | if (entry != 0) |
205 | { | |
caaf90d2 | 206 | if (toSelectionList) fMacroSelList->Add(new TObjString(entry)); |
207 | else fMacroList->Add(new TObjString(entry)); | |
208 | ||
209 | delete entry; | |
210 | entry = 0; | |
211 | ||
212 | #ifdef ALIEVETRDTRACKLIST_DEBUG | |
213 | // Successfull add will only be displayed in debug mode | |
214 | printf("#AliEveTRDTrackList: Standard macros: Added macro %s/%s to %s list\n", path, name, | |
215 | (toSelectionList ? "selection" : "process")); | |
216 | #endif | |
8e27fca1 | 217 | } |
218 | else | |
219 | { | |
caaf90d2 | 220 | // Error will always be displayed |
221 | printf("#AliEveTRDTrackList: Standard macros: ERROR: Could not add macro %s/%s to %s list\n", path, name, | |
222 | (toSelectionList ? "selection" : "process")); | |
223 | } | |
224 | } | |
4f6473f6 | 225 | */ |
8e27fca1 | 226 | //______________________________________________________ |
caaf90d2 | 227 | void AliEveTRDTrackList::AddStandardMacros() |
228 | { | |
229 | // Add your standard macros here, e.g.: | |
230 | // To add a macro without any checks (very fast, but unsafe): | |
231 | // AddMacroFast("$(ALICE_ROOT)/myFolder", "myMacroName.C", isSelMacro); | |
232 | // To add a macro with checks (slower, but safe): | |
233 | // AddMacro("$(ALICE_ROOT)/myFolder", "myMacroName.C"); | |
234 | // -> If the file does not exist, nothing happens. So if you want to handle this, | |
235 | // use the return value of AddMacro (NOT_EXIST_ERROR is returned, if file does not exist) | |
236 | AddMacro("$(ALICE_ROOT)/TRD/qaRec/macros", "clusterSelection.C"); | |
237 | AddMacro("$(ALICE_ROOT)/TRD/qaRec/macros", "chargeDistr.C"); | |
4f6473f6 | 238 | AddMacro("$(ALICE_ROOT)/TRD/qaRec/macros", "nclusters.C"); |
239 | AddMacro("$(ALICE_ROOT)/TRD/qaRec/macros", "clusterResiduals.C"); | |
caaf90d2 | 240 | } |
241 | ||
8e27fca1 | 242 | //______________________________________________________ |
caaf90d2 | 243 | void AliEveTRDTrackList::ApplyProcessMacros(TList* iterator) |
244 | { | |
8e27fca1 | 245 | if (iterator->GetEntries() <= 0) return; |
246 | ||
4f6473f6 | 247 | Char_t name[fkMaxMacroNameLength]; |
8e27fca1 | 248 | Char_t** cmds = new Char_t*[iterator->GetEntries()]; |
caaf90d2 | 249 | |
250 | AliEveTRDTrack* track = 0; | |
251 | AliTRDtrackV1 *trackv1 = 0; | |
252 | ||
253 | // Clear root | |
254 | gROOT->Reset(); | |
255 | ||
256 | // Clear old data and re-allocate | |
257 | if (fDataFromMacroList != 0) delete fDataFromMacroList; | |
258 | fDataFromMacroList = new TList(); | |
259 | ||
4f6473f6 | 260 | fHistoDataSelected = 0; |
261 | ||
caaf90d2 | 262 | if (fDataTree == 0) fDataTree = new TTreeSRedirector("TRD.TrackListMacroData.root"); |
8e27fca1 | 263 | |
264 | // Collect the commands for each macro and add them to "data-from-list" | |
265 | for (Int_t i = 0; i < iterator->GetEntries(); i++) | |
266 | { | |
4f6473f6 | 267 | memset(name, '\0', sizeof(Char_t) * fkMaxMacroNameLength); |
268 | ||
269 | cmds[i] = new Char_t[(fkMaxMacroPathNameLength + fkMaxApplyCommandLength)]; | |
270 | memset(cmds[i], '\0', sizeof(Char_t) * (fkMaxMacroNameLength + fkMaxApplyCommandLength)); | |
8e27fca1 | 271 | |
272 | #ifdef ALIEVETRDTRACKLIST_DEBUG | |
273 | printf("AliEveTRDTrackList: Applying process macro: %s\n", iterator->At(i)->GetTitle()); | |
274 | #endif | |
275 | ||
4f6473f6 | 276 | // Extract the name |
277 | sscanf(iterator->At(i)->GetTitle(), "%s (Path: %*s)", name); | |
8e27fca1 | 278 | |
4f6473f6 | 279 | // Delete ".C" at the end |
280 | // -> Note: Physical address pointer, do NOT delete. / Changes "name" as well! | |
281 | Char_t* dotC = (Char_t*)strrchr(name, '.'); | |
282 | if (dotC != 0) | |
283 | { | |
284 | *dotC = '\0'; | |
285 | dotC++; | |
286 | *dotC = '\0'; | |
287 | } | |
288 | ||
8e27fca1 | 289 | // Add to "data-from-list" |
290 | fDataFromMacroList->Add(new TObjString(name)); | |
291 | ||
4f6473f6 | 292 | // Create the command |
293 | sprintf(cmds[i], "%s(automaticTrackV1, results, n);", name); | |
8e27fca1 | 294 | } |
caaf90d2 | 295 | |
8e27fca1 | 296 | // Walk through the list of tracks |
297 | for (TEveElement::List_i iter = this->BeginChildren(); iter != this->EndChildren(); ++iter) | |
caaf90d2 | 298 | { |
299 | track = dynamic_cast<AliEveTRDTrack*>(*iter); | |
300 | ||
301 | if (!track) continue; | |
4f6473f6 | 302 | |
caaf90d2 | 303 | // Skip tracks that have not been selected |
304 | if (!track->GetRnrState()) continue; | |
305 | ||
306 | trackv1 = (AliTRDtrackV1*)track->GetUserData(); | |
307 | ||
308 | track->ExportToCINT((Text_t*)"automaticTrack"); | |
309 | // Cast to AliTRDtrackV1 | |
310 | gROOT->ProcessLineSync("AliTRDtrackV1* automaticTrackV1 = (AliTRDtrackV1*)automaticTrack->GetUserData();"); | |
311 | ||
312 | // Collect data for each macro | |
313 | for (Int_t i = 0; i < iterator->GetEntries(); i++) | |
314 | { | |
caaf90d2 | 315 | // Create data pointers in CINT, execute the macro and get the data |
316 | gROOT->ProcessLineSync("Double_t* results = 0;"); | |
317 | gROOT->ProcessLineSync("Int_t n = 0;"); | |
8e27fca1 | 318 | gROOT->ProcessLineSync(cmds[i]); |
caaf90d2 | 319 | Double_t* results = (Double_t*)gROOT->ProcessLineSync("results;"); |
320 | Int_t nResults = (Int_t)gROOT->ProcessLineSync("n;"); | |
321 | ||
322 | if (results == 0) | |
323 | { | |
8e27fca1 | 324 | Error("Apply macros", Form("Error reading data from macro \"%s\"", iterator->At(i)->GetTitle())); |
caaf90d2 | 325 | continue; |
326 | } | |
327 | for (Int_t resInd = 0; resInd < nResults; resInd++) | |
328 | { | |
329 | (*fDataTree) << Form("TrackData%d", i) << Form("Macro%d=", i) << results[resInd] << (Char_t*)"\n"; | |
330 | } | |
331 | ||
332 | delete results; | |
333 | results = 0; | |
334 | } | |
335 | } | |
caaf90d2 | 336 | |
337 | delete fDataTree; | |
338 | fDataTree = 0; | |
339 | ||
8e27fca1 | 340 | if (cmds != 0) delete [] cmds; |
341 | ||
caaf90d2 | 342 | // Clear root |
343 | gROOT->Reset(); | |
344 | ||
4f6473f6 | 345 | // If there is data, select the first data set |
346 | if (iterator->GetEntries() > 0) SETBIT(fHistoDataSelected, 0); | |
347 | ||
caaf90d2 | 348 | // Now the data is stored in "TRD.TrackListMacroData.root" |
349 | // The editor will access this file to display the data | |
350 | } | |
351 | ||
8e27fca1 | 352 | //______________________________________________________ |
caaf90d2 | 353 | void AliEveTRDTrackList::ApplySelectionMacros(TList* iterator) |
354 | { | |
4f6473f6 | 355 | Char_t name[fkMaxMacroNameLength]; |
356 | Char_t cmd[(fkMaxMacroNameLength + fkMaxApplyCommandLength)]; | |
caaf90d2 | 357 | |
358 | AliEveTRDTrack* track = 0; | |
359 | AliTRDtrackV1 *trackv1 = 0; | |
360 | Bool_t selectedByMacro = kFALSE; | |
361 | ||
362 | // Clear root | |
363 | gROOT->Reset(); | |
364 | ||
4f6473f6 | 365 | // Select all tracks at first. A track is then deselect, if at least one selection macro |
366 | // returns kFALSE for this track | |
367 | // Enable all tracks (Note: EnableListElements(..) will call "ElementChanged", which will cause unforseen behaviour!) | |
368 | for (TEveElement::List_i iter = this->BeginChildren(); iter != this->EndChildren(); ++iter) | |
369 | { | |
370 | ((TEveElement*)(*iter))->SetRnrState(kTRUE); | |
371 | } | |
372 | SetRnrState(kTRUE); | |
373 | ||
caaf90d2 | 374 | for (Int_t i = 0; i < iterator->GetEntries(); i++) |
375 | { | |
4f6473f6 | 376 | |
377 | memset(name, '\0', sizeof(Char_t) * fkMaxMacroNameLength); | |
378 | memset(cmd, '\0', sizeof(Char_t) * (fkMaxMacroNameLength + fkMaxApplyCommandLength)); | |
caaf90d2 | 379 | |
380 | #ifdef ALIEVETRDTRACKLIST_DEBUG | |
381 | printf("AliEveTRDTrackList: Applying selection macro: %s\n", iterator->At(i)->GetTitle()); | |
382 | #endif | |
caaf90d2 | 383 | |
4f6473f6 | 384 | // Extract the name |
385 | sscanf(iterator->At(i)->GetTitle(), "%s (Path: %*s)", name); | |
386 | // Delete ".C" at the end | |
387 | // -> Note: Physical address pointer, do NOT delete. / Changes "name" as well! | |
388 | Char_t* dotC = (Char_t*)strrchr(name, '.'); | |
389 | if (dotC != 0) | |
390 | { | |
391 | *dotC = '\0'; | |
392 | dotC++; | |
393 | *dotC = '\0'; | |
394 | } | |
395 | ||
396 | // Create the command | |
397 | sprintf(cmd, "%s(automaticTrackV1);", name); | |
caaf90d2 | 398 | |
399 | // Walk through the list of tracks | |
400 | for (TEveElement::List_i iter = this->BeginChildren(); iter != this->EndChildren(); ++iter) | |
401 | { | |
402 | track = dynamic_cast<AliEveTRDTrack*>(*iter); | |
403 | ||
404 | if (!track) continue; | |
405 | ||
406 | trackv1 = (AliTRDtrackV1*)track->GetUserData(); | |
407 | ||
408 | track->ExportToCINT((Text_t*)"automaticTrack"); | |
409 | // Cast to AliTRDtrackV1 | |
410 | gROOT->ProcessLineSync("AliTRDtrackV1* automaticTrackV1 = (AliTRDtrackV1*)automaticTrack->GetUserData();"); | |
411 | selectedByMacro = (Bool_t)gROOT->ProcessLineSync(cmd); | |
4f6473f6 | 412 | track->SetRnrState(selectedByMacro && track->GetRnrState()); |
caaf90d2 | 413 | } |
414 | } | |
415 | ||
416 | // Clear root | |
417 | gROOT->Reset(); | |
418 | } | |
419 | ||
8e27fca1 | 420 | //______________________________________________________ |
caaf90d2 | 421 | Char_t* AliEveTRDTrackList::MakeMacroEntry(const Char_t* path, const Char_t* name) |
422 | { | |
4f6473f6 | 423 | Char_t* entry = new Char_t[(fkMaxMacroPathNameLength + 30)]; |
424 | memset(entry, '\0', sizeof(Char_t) * (fkMaxMacroPathNameLength + 30)); | |
caaf90d2 | 425 | |
426 | Char_t* systemPath = gSystem->ExpandPathName(path); | |
427 | sprintf(entry, "%s (Path: %s)", name, systemPath); | |
428 | delete systemPath; | |
429 | systemPath = 0; | |
430 | ||
431 | return entry; | |
432 | } | |
433 | ||
8e27fca1 | 434 | //______________________________________________________ |
caaf90d2 | 435 | void AliEveTRDTrackList::RemoveProcessMacros(TList* iterator) |
436 | { | |
437 | for (Int_t i = 0; i < iterator->GetEntries(); i++) | |
438 | { | |
439 | fMacroList->Remove(fMacroList->FindObject(iterator->At(i)->GetTitle())); | |
440 | } | |
441 | } | |
442 | ||
8e27fca1 | 443 | //______________________________________________________ |
caaf90d2 | 444 | void AliEveTRDTrackList::RemoveSelectionMacros(TList* iterator) |
445 | { | |
446 | for (Int_t i = 0; i < iterator->GetEntries(); i++) | |
447 | { | |
448 | fMacroSelList->Remove(fMacroSelList->FindObject(iterator->At(i)->GetTitle())); | |
449 | } | |
2ef0687e | 450 | } |
4f6473f6 | 451 |