1 // Author: Benjamin Hess 29/01/2010
3 /*************************************************************************
4 * Copyright (C) 2009-2010, Alexandru Bercuci, Benjamin Hess. *
5 * All rights reserved. *
6 *************************************************************************/
8 //////////////////////////////////////////////////////////////////////////
10 // AliEveListAnalyser //
12 // An AliEveListAnalyser is, in principal, a TEveElementList with some //
13 // sophisticated features. You can add macros to this list, which then //
14 // can be applied to the list of analysis objects (these objects can be //
15 // added to the list in the same way as for the TEveElementList, but //
16 // also "by clicking" (cf. AliEveListAnaLyserEditor)). //
17 // In general, please use AddMacro(...) for this purpose. //
18 // Macros that are no longer needed can be removed from the list via //
19 // RemoveSelectedMacros(...). This function takes an iterator of the //
20 // list of macros that are to be removed. //
21 // An entry looks like: //
22 // The data for each macro consists of path, name, type and the command //
23 // that will be used to apply the macro. This stuff is stored in a map //
24 // which takes the macro name for the key and the above mentioned data //
25 // in a TGeneralMacroData-object for the value. //
26 // You can get the macro type via GetMacroType(...). //
27 // To find the type of objects the macro will deal with (corresponds to //
28 // "YourObjectType" in the examples below) please use //
29 // GetMacroObjectType(...). //
30 // With ApplySOSelectionMacros(...) or ApplyProcessMacros(...) //
31 // respectively you can apply the macros to the track list via //
32 // iterators (same style like for RemoveSelectedMacros(...)(cf. above)).//
33 // Selection macros (de-)select macros according to a selection rule //
34 // by setting the rnr-state of the tracks. //
35 // If multiple selection macros are applied, a track is selected, if //
36 // all selection macros select the track. //
37 // Process macros create data or histograms, which will be stored in //
38 // a temporary file. The editor of this class will access this file //
39 // and draw all the stuff within it's DrawHistos() function. The file //
40 // will be deleted by the destructor. //
42 // Currently, the following macro types are supported: //
43 // Selection macros: //
44 // Bool_t YourMacro(const YourObjectType*); //
45 // Bool_t YourMacro(const YourObjectType*, const YourObjectType2*); //
48 // void YourMacro(const YourObjectType*, Double_t*&, Int_t&); //
49 // void YourMacro(const YourObjectType*, const YourObjectType2*, //
50 // Double_t*&, Int_t&); //
51 // TH1* YourMacro(const YourObjectType*); //
52 // TH1* YourMacro(const YourObjectType*, const YourObjectType2*); //
54 // The macros which take 2 tracks are applied to all track pairs //
55 // (whereby BOTH tracks of the pair have to be selected by the single //
56 // track selection macros and have to be unequal, otherwise they will //
57 // be skipped) that have been selected by ALL correlated tracks //
58 // selection macros. The selection macros with 2 tracks do NOT affect //
59 // process macros that process only a single track! //
60 //////////////////////////////////////////////////////////////////////////
62 #ifndef AliEveListAnalyser_H
63 #define AliEveListAnalyser_H
66 #include <TEveElement.h>
67 #include <EveDet/AliEveTRDData.h>
69 #define SIGNATURE_ERROR -1
70 #define NOT_EXIST_ERROR -2
72 #define UNKNOWN_OBJECT_TYPE_ERROR -4
76 #define MAX_MACRO_NAME_LENGTH 100
77 #define MAX_MACRO_PATH_LENGTH 300
78 #define MAX_APPLY_COMMAND_LENGTH 120
80 #define UNSETBIT(n,i) ((n) &= ~BIT(i))
83 class AliEveListAnalyserEditor;
84 class AliTRDReconstructor;
96 class TTreeSRedirector;
98 class AliEveListAnalyser: public TEveElementList
100 friend class AliEveListAnalyserEditor;
106 // Maximum length (number of characters) for a macro name:
107 fkMaxMacroNameLength = MAX_MACRO_NAME_LENGTH,
108 // Maximum length (number of characters) for a macro path:
109 fkMaxMacroPathLength = MAX_MACRO_PATH_LENGTH,
110 // Maximum length (number of characters) for a macro pathname:
111 fkMaxMacroPathNameLength = MAX_MACRO_NAME_LENGTH + MAX_MACRO_PATH_LENGTH,
112 // Maximum length (number of characters) for "apply macro" commands in addition to the length of the name, path...
113 fkMaxApplyCommandLength = MAX_APPLY_COMMAND_LENGTH
117 enum AliEveListAnalyserMacroType
120 kSingleObjectSelect = 1,
121 kSingleObjectAnalyse = 2,
122 kSingleObjectHisto = 3,
123 kCorrelObjectSelect = 4,
124 kCorrelObjectAnalyse = 5,
125 kCorrelObjectHisto = 6
129 AliEveListAnalyser(const Text_t* n = "AliEveListAnalyser", const Text_t* t = "", Bool_t doColor = kFALSE);
130 virtual ~AliEveListAnalyser();
132 Int_t AddMacro(const Char_t* path, const Char_t* name, Bool_t forceReload = kFALSE);
133 Bool_t AddMacroFast(const Char_t* path, const Char_t* name, AliEveListAnalyserMacroType type, TClass* objectType, TClass* objectType2);
134 Int_t AddPrimSelectedObject(TEveElement* el);
135 //void AddPrimSelectedObjects();
136 void AddSecSelectedSingleObjectToList(Int_t pointId);
137 virtual void AddStandardContent();
138 Bool_t ApplyProcessMacros(const TList* selIterator, const TList* procIterator);
139 void ApplySOSelectionMacros(const TList* iterator);
140 Bool_t GetConnected() // Returns whether "adding objects by clicking" is enabled or not.
141 { return fConnected; };
142 TClass* GetMacroObjectType(const Char_t* name, Int_t argNum = 1) const;
144 // Returns the type of the macro of the corresponding entry (i.e. "macro.C (Path: path)").
145 // If you have only the name and the path, you can simply use MakeMacroEntry.
146 // If "UseList" is kTRUE, the type will be looked up in the internal list (very fast). But if this list
147 // does not exist, you have to use kFALSE for this parameter. Then the type will be determined by the
148 // prototype! NOTE: It is assumed that the macro has been compiled! If not, the return value is not
149 // predictable, but normally will be kUnknown.
150 // "objectType" gives the class/"type of object" of the pointer(s), the macro accepts as a parametre.
151 // Note: AddMacro(Fast) will update the internal list and RemoveProcess(/Selection)Macros respectively.
152 AliEveListAnalyserMacroType GetMacroType(const Char_t* name, const Char_t* objectType = "TObject",
153 const Char_t* objectType2 = "TObject", Bool_t UseList = kTRUE) const;
155 //void RemovePrimSelectedObjects();
156 void RemoveSelectedMacros(const TList* iterator);
157 void ResetObjectList();
158 Bool_t StartAddingObjects();
159 Bool_t StopAddingObjects();
162 Bool_t fConnected; // Connection to the TEvePointSet signal
164 TList* fDataFromMacroList; // List of macros that currently have data for histograms
166 AliEveListAnalyserEditor* fEditor; // Pointer to the editor of this list
168 TMap* fMacroList; // Stores the names, paths, types and commands of all macros added to this list
170 TTreeSRedirector *fDataTree; // Tree containing data for histograms
172 Int_t fHistoDataSelected; // Stores the selection for the data of the histograms
173 Int_t fMacroListSelected; // Stores the selection of the macro list
175 Char_t fSelectedTab; // Holds the index of the selected tab
177 Char_t GetSelectedTab() const // Gets the selected tab
178 { return fSelectedTab; }
180 Bool_t HistoDataIsSelected(Int_t index) const // Is entry in list selected?
181 { return TESTBIT(fHistoDataSelected, index); }
183 Bool_t MacroListIsSelected(Int_t index) const // Is entry in list selected?
184 { return TESTBIT(fMacroListSelected, index); }
186 void SetHistoDataSelection(Int_t index, Bool_t set) // Set selection of entry in list
187 { if (set) SETBIT(fHistoDataSelected, index); else UNSETBIT(fHistoDataSelected, index); }
189 void SetMacroListSelection(Int_t index, Bool_t set) // Set selection of entry in list
190 { if (set) SETBIT(fMacroListSelected, index); else UNSETBIT(fMacroListSelected, index); }
192 void SetSelectedTab(Int_t index) // Sets the selected tab
193 { fSelectedTab = (Char_t)index; }
196 AliEveListAnalyser(const AliEveListAnalyser&); // Not implemented
197 AliEveListAnalyser& operator=(const AliEveListAnalyser&); // Not implemented
199 ClassDef(AliEveListAnalyser, 0); // Class containing a list of analyse objects
202 //////////////////////////////////////////////////////////////////////////
204 // TGeneralMacroData //
206 // Stores macro data which will be used by AliEveListAnalyser. //
208 //////////////////////////////////////////////////////////////////////////
210 class TGeneralMacroData: public TObject
213 TGeneralMacroData(const Char_t* name, const Char_t* path, // Constructor
214 AliEveListAnalyser::AliEveListAnalyserMacroType type = AliEveListAnalyser::kUnknown,
215 TClass* objectType = TObject::Class(), TClass* objectType2 = TObject::Class()):
220 fType(AliEveListAnalyser::kUnknown)
223 // The command is automatically set via type.
226 SetObjectType(objectType);
227 SetObjectType2(objectType2);
231 // Register the commands for each type here
232 // Note: The framework will cast all data objects to "TObject*"
233 // -> We need to cast to the correct type for the macro!
236 case AliEveListAnalyser::kSingleObjectSelect:
237 case AliEveListAnalyser::kSingleObjectHisto:
238 SetCmd(Form("%s((%s*)automaticObject_1);", name, fObjectType->GetName()));
241 case AliEveListAnalyser::kSingleObjectAnalyse:
242 SetCmd(Form("%s((%s*)automaticObject_1, results, n);", name, fObjectType->GetName()));
245 case AliEveListAnalyser::kCorrelObjectSelect:
246 case AliEveListAnalyser::kCorrelObjectHisto:
247 SetCmd(Form("%s((%s*)automaticObject_1, (%s*)automaticObject_2);", name, fObjectType->GetName(), fObjectType2->GetName()));
250 case AliEveListAnalyser::kCorrelObjectAnalyse:
251 SetCmd(Form("%s((%s*)automaticObject_1, (%s*)automaticObject_2, results, n);", name, fObjectType->GetName(), fObjectType2->GetName()));
260 const Char_t* GetCmd() const // Returns the command that will be used to call this macro
262 const Char_t* GetName() const // Returns the macro name (without ".C")
264 TClass* GetObjectType() const // Returns the object type of the macro parameter (1st pointer)
265 { return fObjectType; }
266 TClass* GetObjectType2() const // Returns the object type of the macro parameter (2nd pointer)
267 { return fObjectType2; }
268 const Char_t* GetPath() const // Returns the path of the macro
270 AliEveListAnalyser::AliEveListAnalyserMacroType GetType() const // Returns the type of the macro
272 Bool_t IsProcessMacro() const // Returns whether the macro is a process type macro or not
276 case AliEveListAnalyser::kSingleObjectAnalyse:
277 case AliEveListAnalyser::kSingleObjectHisto:
278 case AliEveListAnalyser::kCorrelObjectAnalyse:
279 case AliEveListAnalyser::kCorrelObjectHisto:
289 Bool_t IsSelected() const // Returns whether the macro is selected or not
290 { return fIsSelected; }
291 Bool_t IsSelectionMacro() const // Returns whether the macro is a selection type macro or not
295 case AliEveListAnalyser::kSingleObjectSelect:
296 case AliEveListAnalyser::kCorrelObjectSelect:
306 void SetCmd(const char* newCmd) // Sets the command that will be used to call this macro
308 memset(fCmd, '\0', sizeof(Char_t) * MAX_APPLY_COMMAND_LENGTH);
309 snprintf(fCmd, MAX_APPLY_COMMAND_LENGTH, "%s", newCmd);
311 void SetName(const char* newName) // Sets the macro name (please use without ".C")
313 memset(fName, '\0', sizeof(Char_t) * MAX_MACRO_NAME_LENGTH);
314 snprintf(fName, MAX_MACRO_NAME_LENGTH, "%s", newName);
316 void SetObjectType(TClass* newObjectType) // Sets the object type of the macro parameter (1st pointer)
318 fObjectType = newObjectType;
320 void SetObjectType2(TClass* newObjectType2) // Sets the object type of the macro parameter (2nd pointer)
322 fObjectType2 = newObjectType2;
324 void SetPath(const char* newPath) // Sets the path of the macro
326 memset(fPath, '\0', sizeof(Char_t) * MAX_MACRO_PATH_LENGTH);
327 snprintf(fPath, MAX_MACRO_PATH_LENGTH, "%s", newPath);
329 void SetSelected(Bool_t selection) // Sets whether the macro is selected or not
331 fIsSelected = selection;
333 void SetType(AliEveListAnalyser::AliEveListAnalyserMacroType newType) // Sets the type of the macro
339 TGeneralMacroData(const TGeneralMacroData&); // Not implemented
340 TGeneralMacroData& operator=(const TGeneralMacroData&); // Not implemented
342 Char_t fCmd[MAX_APPLY_COMMAND_LENGTH]; // Command that will be used to call this macro
343 Char_t fName[MAX_MACRO_NAME_LENGTH]; // Macro name (without ".C"!)
344 TClass* fObjectType; // Type of object of the macro parameter (1st pointer)
345 TClass* fObjectType2; // Type of object of the macro parameter (2nd pointer)
346 Char_t fPath[MAX_MACRO_PATH_LENGTH]; // Path of the macro
347 Bool_t fIsSelected; // Is macro selected (e.g. in the editor's list)?
348 AliEveListAnalyser::AliEveListAnalyserMacroType fType; // Type of the macro