1 // Uncomment to display debugging infos
2 //#define ALIEVETRDTRACKLIST_DEBUG
4 #include "AliEveTRDTrackList.h"
6 #include <AliTRDtrackV1.h>
10 #include <TObjString.h>
14 #include <TTreeStream.h>
15 #include <EveDet/AliEveTRDData.h>
17 ClassImp(AliEveTRDTrackList)
19 ///////////////////////////////////////////////////////////
20 ///////////// AliEveTRDTrackList ////////////////////////
21 ///////////////////////////////////////////////////////////
22 AliEveTRDTrackList::AliEveTRDTrackList(const Text_t* n, const Text_t* t, Bool_t doColor):
23 TEveElementList(n, t, doColor),
26 fDataFromMacroList(0),
29 // Only accept childs of type AliEveTRDTrack
30 SetChildClass(AliEveTRDTrack::Class());
32 fMacroList = new TList();
33 fMacroSelList = new TList();
34 fDataFromMacroList = new TList();
36 fDataTree = new TTreeSRedirector("TRD.TrackListMacroData.root");
41 //______________________________________________________
42 AliEveTRDTrackList::~AliEveTRDTrackList()
50 if (fMacroSelList != 0)
52 fMacroSelList->Clear();
56 if (fDataFromMacroList != 0)
58 fDataFromMacroList->Clear();
59 delete fDataFromMacroList;
60 fDataFromMacroList = 0;
69 //______________________________________________________
70 Int_t AliEveTRDTrackList::AddMacro(const Char_t* path, const Char_t* nameC)
72 // First check the type of the macro:
73 // If it has the signature of a selection macro:
74 // Bool_t MacroName(AliTRDtrackV1*)
75 // it is assumed to be a selection macro.
76 // If it has the signature of a process macro:
77 // void MacroName(AliTRDtrackV1*, Double_t*&, Int_t&)
78 // it is assumed to be a process macro.
79 // In all other cases: Macro is rejected
80 Bool_t isSelectionMacro = kFALSE;
81 Bool_t hasCorrectSignature = kFALSE;
84 Char_t* entryName = MakeMacroEntry(path, nameC);
86 Char_t* pathname = new Char_t[300];
87 memset(pathname, '\0', sizeof(Char_t) * 300);
89 // Expand the path and create the pathname
90 Char_t* systemPath = gSystem->ExpandPathName(path);
91 sprintf(pathname, "%s/%s", systemPath, nameC);
95 // Delete ".C" from filename
96 Char_t* name = new Char_t[strlen(nameC)];
97 memset(name, '\0', sizeof(Char_t) * strlen(nameC));
98 strncpy(name, nameC, strlen(nameC) - 2);
100 // Check, if files exists
103 fp = fopen(pathname, "rb");
111 if (name != 0) delete name;
113 if (pathname != 0) delete pathname;
115 if (entryName != 0) delete entryName;
118 return NOT_EXIST_ERROR;
121 // Clean up root, load the desired macro and then check the type of the macro
124 gROOT->ProcessLineSync(Form(".L %s", pathname));
127 TFunction* f = gROOT->GetGlobalFunctionWithPrototype(name, "AliTRDtrackV1*", kTRUE);
130 if (!strcmp(f->GetReturnTypeName(), "Bool_t"))
132 // Some additional check (is the parameter EXACTLY of the desired type?)
133 if (strstr(f->GetMangledName(), "AliTRDtrackV1mUsP") != 0x0)
135 hasCorrectSignature = kTRUE;
136 isSelectionMacro = kTRUE;
143 f = gROOT->GetGlobalFunctionWithPrototype(name, "AliTRDtrackV1*, Double_t*&, Int_t&", kTRUE);
146 if (!strcmp(f->GetReturnTypeName(), "void"))
148 // Some additional check (are the parameters EXACTLY of the desired type?)
149 if (strstr(f->GetMangledName(), "AliTRDtrackV1mUsP") != 0x0 &&
150 strstr(f->GetMangledName(), "Double_tmUaNsP") != 0x0 &&
151 strstr(f->GetMangledName(), "Int_taNsP") != 0x0)
153 hasCorrectSignature = kTRUE;
154 isSelectionMacro = kFALSE;
160 // Clean up again / unload this function
161 gROOT->ProcessLineSync(Form(".U %s", pathname));
164 if (name != 0) delete name;
166 if (pathname != 0) delete pathname;
169 // Has not the correct signature!
170 if (!hasCorrectSignature)
172 if (entryName != 0) delete entryName;
174 return SIGNATURE_ERROR;
177 Int_t returnValue = WARNING;
179 // Only add macro, if it is not already in the list
180 if (!isSelectionMacro && fMacroList->FindObject(entryName) == 0)
182 fMacroList->Add(new TObjString(entryName));
185 returnValue = SUCCESS;
187 else if (isSelectionMacro && fMacroSelList->FindObject(entryName) == 0)
189 fMacroSelList->Add(new TObjString(entryName));
190 fMacroSelList->Sort();
192 returnValue = SUCCESS;
194 else returnValue = WARNING;
196 if (entryName != 0) delete entryName;
202 //______________________________________________________
203 void AliEveTRDTrackList::AddMacroFast(const Char_t* path, const Char_t* name, Bool_t toSelectionList)
205 Char_t* entry = MakeMacroEntry(path, name);
208 if (toSelectionList) fMacroSelList->Add(new TObjString(entry));
209 else fMacroList->Add(new TObjString(entry));
214 #ifdef ALIEVETRDTRACKLIST_DEBUG
215 // Successfull add will only be displayed in debug mode
216 printf("#AliEveTRDTrackList: Standard macros: Added macro %s/%s to %s list\n", path, name,
217 (toSelectionList ? "selection" : "process"));
222 // Error will always be displayed
223 printf("#AliEveTRDTrackList: Standard macros: ERROR: Could not add macro %s/%s to %s list\n", path, name,
224 (toSelectionList ? "selection" : "process"));
228 //______________________________________________________
229 void AliEveTRDTrackList::AddStandardMacros()
231 // Add your standard macros here, e.g.:
232 // To add a macro without any checks (very fast, but unsafe):
233 // AddMacroFast("$(ALICE_ROOT)/myFolder", "myMacroName.C", isSelMacro);
234 // To add a macro with checks (slower, but safe):
235 // AddMacro("$(ALICE_ROOT)/myFolder", "myMacroName.C");
236 // -> If the file does not exist, nothing happens. So if you want to handle this,
237 // use the return value of AddMacro (NOT_EXIST_ERROR is returned, if file does not exist)
238 AddMacro("$(ALICE_ROOT)/TRD/qaRec/macros", "clusterSelection.C");
239 AddMacro("$(ALICE_ROOT)/TRD/qaRec/macros", "chargeDistr.C");
242 //______________________________________________________
243 void AliEveTRDTrackList::ApplyProcessMacros(TList* iterator)
245 if (iterator->GetEntries() <= 0) return;
249 Char_t pathname[400];
250 Char_t** cmds = new Char_t*[iterator->GetEntries()];
252 AliEveTRDTrack* track = 0;
253 AliTRDtrackV1 *trackv1 = 0;
258 // Clear old data and re-allocate
259 if (fDataFromMacroList != 0) delete fDataFromMacroList;
260 fDataFromMacroList = new TList();
262 if (fDataTree == 0) fDataTree = new TTreeSRedirector("TRD.TrackListMacroData.root");
264 // Collect the commands for each macro and add them to "data-from-list"
265 for (Int_t i = 0; i < iterator->GetEntries(); i++)
267 memset(name, '\0', sizeof(Char_t) * 100);
268 memset(path, '\0', sizeof(Char_t) * 300);
269 memset(pathname, '\0', sizeof(Char_t) * 400);
271 cmds[i] = new Char_t[430];
272 memset(cmds[i], '\0', sizeof(Char_t) * 430);
274 #ifdef ALIEVETRDTRACKLIST_DEBUG
275 printf("AliEveTRDTrackList: Applying process macro: %s\n", iterator->At(i)->GetTitle());
278 // Extract path and name -> Make pathname
279 sscanf(iterator->At(i)->GetTitle(), "%s (Path: %s)", name, path);
281 // Add to "data-from-list"
282 fDataFromMacroList->Add(new TObjString(name));
284 // Delete ")" at the end of path
285 path[strlen(path)] = '\0';
286 path[strlen(path) - 1] = '\0';
287 sprintf(pathname, "%s/%s", path, name);
288 sprintf(cmds[i], ".x %s(automaticTrackV1, results, n);", pathname);
291 // Walk through the list of tracks
292 for (TEveElement::List_i iter = this->BeginChildren(); iter != this->EndChildren(); ++iter)
294 track = dynamic_cast<AliEveTRDTrack*>(*iter);
296 if (!track) continue;
298 // Skip tracks that have not been selected
299 if (!track->GetRnrState()) continue;
301 trackv1 = (AliTRDtrackV1*)track->GetUserData();
303 track->ExportToCINT((Text_t*)"automaticTrack");
304 // Cast to AliTRDtrackV1
305 gROOT->ProcessLineSync("AliTRDtrackV1* automaticTrackV1 = (AliTRDtrackV1*)automaticTrack->GetUserData();");
307 // Collect data for each macro
308 for (Int_t i = 0; i < iterator->GetEntries(); i++)
310 // Create data pointers in CINT, execute the macro and get the data
311 gROOT->ProcessLineSync("Double_t* results = 0;");
312 gROOT->ProcessLineSync("Int_t n = 0;");
313 gROOT->ProcessLineSync(cmds[i]);
314 Double_t* results = (Double_t*)gROOT->ProcessLineSync("results;");
315 Int_t nResults = (Int_t)gROOT->ProcessLineSync("n;");
319 Error("Apply macros", Form("Error reading data from macro \"%s\"", iterator->At(i)->GetTitle()));
322 for (Int_t resInd = 0; resInd < nResults; resInd++)
324 (*fDataTree) << Form("TrackData%d", i) << Form("Macro%d=", i) << results[resInd] << (Char_t*)"\n";
335 if (cmds != 0) delete [] cmds;
340 // Now the data is stored in "TRD.TrackListMacroData.root"
341 // The editor will access this file to display the data
344 //______________________________________________________
345 void AliEveTRDTrackList::ApplySelectionMacros(TList* iterator)
347 if (iterator->GetEntries() <= 0) return;
351 Char_t pathname[400];
354 AliEveTRDTrack* track = 0;
355 AliTRDtrackV1 *trackv1 = 0;
356 Bool_t selectedByMacro = kFALSE;
361 for (Int_t i = 0; i < iterator->GetEntries(); i++)
363 memset(name, '\0', sizeof(Char_t) * 100);
364 memset(path, '\0', sizeof(Char_t) * 300);
365 memset(pathname, '\0', sizeof(Char_t) * 400);
366 memset(cmd, '\0', sizeof(Char_t) * 430);
368 #ifdef ALIEVETRDTRACKLIST_DEBUG
369 printf("AliEveTRDTrackList: Applying selection macro: %s\n", iterator->At(i)->GetTitle());
372 // Extract path and name -> Make pathname
373 sscanf(iterator->At(i)->GetTitle(), "%s (Path: %s)", name, path);
374 // Delete ")" at the end of path.
375 path[strlen(path)] = '\0';
376 path[strlen(path) - 1] = '\0';
378 sprintf(pathname, "%s/%s", path, name);
379 sprintf(cmd, ".x %s(automaticTrackV1);", pathname);
381 // Walk through the list of tracks
382 for (TEveElement::List_i iter = this->BeginChildren(); iter != this->EndChildren(); ++iter)
384 track = dynamic_cast<AliEveTRDTrack*>(*iter);
386 if (!track) continue;
388 trackv1 = (AliTRDtrackV1*)track->GetUserData();
390 track->ExportToCINT((Text_t*)"automaticTrack");
391 // Cast to AliTRDtrackV1
392 gROOT->ProcessLineSync("AliTRDtrackV1* automaticTrackV1 = (AliTRDtrackV1*)automaticTrack->GetUserData();");
393 selectedByMacro = (Bool_t)gROOT->ProcessLineSync(cmd);
394 track->SetRnrState(selectedByMacro);
402 //______________________________________________________
403 Char_t* AliEveTRDTrackList::MakeMacroEntry(const Char_t* path, const Char_t* name)
405 Char_t* entry = new Char_t[400];
406 memset(entry, '\0', sizeof(Char_t) * 400);
408 Char_t* systemPath = gSystem->ExpandPathName(path);
409 sprintf(entry, "%s (Path: %s)", name, systemPath);
416 //______________________________________________________
417 void AliEveTRDTrackList::RemoveProcessMacros(TList* iterator)
419 for (Int_t i = 0; i < iterator->GetEntries(); i++)
421 fMacroList->Remove(fMacroList->FindObject(iterator->At(i)->GetTitle()));
425 //______________________________________________________
426 void AliEveTRDTrackList::RemoveSelectionMacros(TList* iterator)
428 for (Int_t i = 0; i < iterator->GetEntries(); i++)
430 fMacroSelList->Remove(fMacroSelList->FindObject(iterator->At(i)->GetTitle()));