]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/EveDet/AliEveListAnalyser.h
Bugfix with zero event % alert
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveListAnalyser.h
CommitLineData
00dc25ef 1// Author: Benjamin Hess 06/11/2009
2
3/*************************************************************************
4 * Copyright (C) 2009, Alexandru Bercuci, Benjamin Hess. *
5 * All rights reserved. *
6 *************************************************************************/
7
8#ifndef AliEveListAnalyser_H
9#define AliEveListAnalyser_H
10
11// TODO: DOCUMENTATION
12//////////////////////////////////////////////////////////////////////////
13// //
14// AliEveTRDTAnalyseObjectList //
15// //
16// An AliEveListAnalyser is, in principal, a TEveElementList //
17// with some sophisticated features. You can add macros to this list, //
18// which then can be applied to the list of tracks (these tracks can //
19// be added to the list in the same way as for the TEveElementList). //
20// In general, please use AddMacro(...) for this purpose. //
21// Macros that are no longer needed can be removed from the list via //
22// RemoveSelectedMacros(...).This function takes an iterator of the //
23// list of macros that are to be removed. //
24// be removed. An entry looks like: //
25// The data for each macro consists of path, name, type and the command //
26// that will be used to apply the macro. This stuff is stored in a map //
27// which takes the macro name for the key and the above mentioned data //
28// in a TGeneralMacroData-object for the value. //
29// You can get the macro type via GetMacroType(...). //
30// With ApplySTSelectionMacros(...) 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. //
41// //
42// Currently, the following macro types are supported: //
43// Selection macros: //
6e420565 44// Bool_t YourMacro(const YourObjectType*); //
45// Bool_t YourMacro(const YourObjectType*, const YourObjectType*); //
00dc25ef 46// //
47// Process macros: //
6e420565 48// void YourMacro(const YourObjectType*, Double_t*&, Int_t&); //
49// void YourMacro(const YourObjectType*, const YourObjectType*, //
00dc25ef 50// Double_t*&, Int_t&); //
6e420565 51// TH1* YourMacro(const YourObjectType*); //
52// TH1* YourMacro(const YourObjectType*, const YourObjectType*); //
00dc25ef 53// //
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//////////////////////////////////////////////////////////////////////////
61
62
63#include <TEveElement.h>
6e420565 64#include <TClass.h>
00dc25ef 65#include <EveDet/AliEveTRDData.h>
66
67#define SIGNATURE_ERROR -1
68#define NOT_EXIST_ERROR -2
69#define ERROR -3
70#define UNKNOWN_OBJECT_TYPE_ERROR -4
71#define WARNING 0
72#define SUCCESS 1
73
74#define MAX_MACRO_NAME_LENGTH 100
75#define MAX_MACRO_PATH_LENGTH 300
76#define MAX_APPLY_COMMAND_LENGTH 120
77
78#define UNSETBIT(n,i) ((n) &= ~BIT(i))
79
80//class AliEveTRDTrack;
81class AliEveListAnalyserEditor;
82class AliTRDReconstructor;
83class TClass;
84class TFile;
85class TFunction;
86class TH1;
87class TObjString;
88class TList;
89class TMap;
90class TPair;
91class TString;
92class TTreeSRedirector;
93
94class AliEveListAnalyser: public TEveElementList
95{
96 friend class AliEveListAnalyserEditor;
97
98public:
99
100 enum
101 {
102 // Maximum length (number of characters) for a macro name:
103 fkMaxMacroNameLength = MAX_MACRO_NAME_LENGTH,
104 // Maximum length (number of characters) for a macro path:
105 fkMaxMacroPathLength = MAX_MACRO_PATH_LENGTH,
106 // Maximum length (number of characters) for a macro pathname:
107 fkMaxMacroPathNameLength = MAX_MACRO_NAME_LENGTH + MAX_MACRO_PATH_LENGTH,
108 // Maximum length (number of characters) for "apply macro" commands in addition to the length of the name, path...
109 fkMaxApplyCommandLength = MAX_APPLY_COMMAND_LENGTH
110 };
111
112 // Macro types
113 enum AliEveListAnalyserMacroType
114 {
115 kUnknown = 0,
116 kSingleObjectSelect = 1,
117 kSingleObjectAnalyse = 2,
118 kSingleObjectHisto = 3,
119 kCorrelObjectSelect = 4,
120 kCorrelObjectAnalyse = 5,
121 kCorrelObjectHisto = 6
122 };
123
124
125 AliEveListAnalyser(const Text_t* n = "AliEveListAnalyser", const Text_t* t = "", Bool_t doColor = kFALSE);
126 virtual ~AliEveListAnalyser();
127
128 Int_t AddMacro(const Char_t* path, const Char_t* name, Bool_t forceReload = kFALSE);
129 Bool_t AddMacroFast(const Char_t* path, const Char_t* name, AliEveListAnalyserMacroType type, TClass* objectType);
130 virtual void AddStandardContent();
131 Bool_t ApplyProcessMacros(const TList* selIterator, const TList* procIterator);
132 void ApplySTSelectionMacros(const TList* iterator);
133
134 // Returns the type of the macro of the corresponding entry (i.e. "macro.C (Path: path)").
135 // If you have only the name and the path, you can simply use MakeMacroEntry.
136 // If "UseList" is kTRUE, the type will be looked up in the internal list (very fast). But if this list
137 // does not exist, you have to use kFALSE for this parameter. Then the type will be determined by the
138 // prototype! NOTE: It is assumed that the macro has been compiled! If not, the return value is not
139 // predictable, but normally will be kUnknown.
140 // "objectType" gives the class/"type of object" of the pointer(s), the macro accepts as a parametre.
141 // Note: AddMacro(Fast) will update the internal list and RemoveProcess(/Selection)Macros respectively.
142 AliEveListAnalyserMacroType GetMacroType(const Char_t* name, const Char_t* objectType = "TObject", Bool_t UseList = kTRUE) const;
143
144 // TODO Documentation
145 TClass* GetMacroObjectType(const Char_t* name) const;
146 void RemoveSelectedMacros(const TList* iterator);
147
148protected:
149 AliEveListAnalyserEditor* fEditor; // Pointer to the editor of this list
150
151 TList* fDataFromMacroList; // List of macros that currently have data for histograms
152
153 TMap* fMacroList; // Stores the names, paths, types and commands of all macros added to this list
154
155 TTreeSRedirector *fDataTree; // Tree containing data for histograms
156
157 Int_t fHistoDataSelected; // Stores the selection for the data of the histograms
158 Int_t fMacroListSelected; // Stores the selection of the macro list
159
160 Char_t fSelectedTab; // Holds the index of the selected tab
00dc25ef 161
162 Char_t GetSelectedTab() const // Gets the selected tab
163 { return fSelectedTab; }
164
00dc25ef 165 Bool_t HistoDataIsSelected(Int_t index) const // Is entry in list selected?
166 { return TESTBIT(fHistoDataSelected, index); }
167
168 Bool_t MacroListIsSelected(Int_t index) const // Is entry in list selected?
169 { return TESTBIT(fMacroListSelected, index); }
170
171 void SetHistoDataSelection(Int_t index, Bool_t set) // Set selection of entry in list
172 { if (set) SETBIT(fHistoDataSelected, index); else UNSETBIT(fHistoDataSelected, index); }
173
174 void SetMacroListSelection(Int_t index, Bool_t set) // Set selection of entry in list
175 { if (set) SETBIT(fMacroListSelected, index); else UNSETBIT(fMacroListSelected, index); }
176
177 void SetSelectedTab(Int_t index) // Sets the selected tab
178 { fSelectedTab = (Char_t)index; }
179
00dc25ef 180private:
181 AliEveListAnalyser(const AliEveListAnalyser&); // Not implemented
182 AliEveListAnalyser& operator=(const AliEveListAnalyser&); // Not implemented
183
184 ClassDef(AliEveListAnalyser, 0); // Class containing a list of analyse objects
185};
186
187//////////////////////////////////////////////////////////////////////////
188// //
189// TGeneralMacroData //
190// //
191// Stores macro data which will be used by AliEveListAnalyser. //
192// //
193//////////////////////////////////////////////////////////////////////////
194
195class TGeneralMacroData: public TObject
196{
197public:
198 TGeneralMacroData(const Char_t* name, const Char_t* path, // Constructor
199 AliEveListAnalyser::AliEveListAnalyserMacroType type = AliEveListAnalyser::kUnknown,
200 TClass* objectType = TObject::Class()):
201 TObject(),
202 fObjectType(0x0),
203 fIsSelected(kFALSE),
204 fType(AliEveListAnalyser::kUnknown)
205
206 {
207 // The command is automatically set via type.
208
209 SetName(name);
210 SetObjectType(objectType);
211 SetPath(path);
212 SetType(type);
213
214 // Register the commands for each type here
6e420565 215 // Note: The framework will cast all data objects to "TObject*"
216 // -> We need to cast to the correct type for the macro!
00dc25ef 217 switch (type)
218 {
219 case AliEveListAnalyser::kSingleObjectSelect:
220 case AliEveListAnalyser::kSingleObjectHisto:
6e420565 221 SetCmd(Form("%s((%s*)automaticObject_1);", name, fObjectType->GetName()));
00dc25ef 222 break;
223
224 case AliEveListAnalyser::kSingleObjectAnalyse:
6e420565 225 SetCmd(Form("%s((%s*)automaticObject_1, results, n);", name, fObjectType->GetName()));
00dc25ef 226 break;
227
228 case AliEveListAnalyser::kCorrelObjectSelect:
229 case AliEveListAnalyser::kCorrelObjectHisto:
6e420565 230 SetCmd(Form("%s((%s*)automaticObject_1, (%s*)automaticObject_2);", name, fObjectType->GetName(), fObjectType->GetName()));
00dc25ef 231 break;
232
233 case AliEveListAnalyser::kCorrelObjectAnalyse:
6e420565 234 SetCmd(Form("%s((%s*)automaticObject_1, (%s*)automaticObject_2, results, n);", name, fObjectType->GetName(), fObjectType->GetName()));
00dc25ef 235 break;
236
237 default:
238 SetCmd("");
239 break;
240 }
241 }
242
243 const Char_t* GetCmd() const // Returns the command that will be used to call this macro
244 { return fCmd; }
245 const Char_t* GetName() const // Returns the macro name (without ".C")
246 { return fName; }
247 TClass* GetObjectType() const // Returns the object type of the macro parameter
248 { return fObjectType; }
249 const Char_t* GetPath() const // Returns the path of the macro
250 { return fPath; }
251 AliEveListAnalyser::AliEveListAnalyserMacroType GetType() const // Returns the type of the macro
252 { return fType; }
253 Bool_t IsProcessMacro() const // Returns whether the macro is a process type macro or not
254 {
255 switch (fType)
256 {
257 case AliEveListAnalyser::kSingleObjectAnalyse:
258 case AliEveListAnalyser::kSingleObjectHisto:
259 case AliEveListAnalyser::kCorrelObjectAnalyse:
260 case AliEveListAnalyser::kCorrelObjectHisto:
261 return kTRUE;
262 break;
263 default:
264 break;
265 }
266
267 return kFALSE;
268 }
269
270 Bool_t IsSelected() const // Returns whether the macro is selected or not
271 { return fIsSelected; }
272 Bool_t IsSelectionMacro() const // Returns whether the macro is a selection type macro or not
273 {
274 switch (fType)
275 {
276 case AliEveListAnalyser::kSingleObjectSelect:
277 case AliEveListAnalyser::kCorrelObjectSelect:
278 return kTRUE;
279 break;
280 default:
281 break;
282 }
283
284 return kFALSE;
285 }
286
287 void SetCmd(const char* newCmd) // Sets the command that will be used to call this macro
288 {
289 memset(fCmd, '\0', sizeof(Char_t) * MAX_APPLY_COMMAND_LENGTH);
290 sprintf(fCmd, "%s", newCmd);
291 }
292 void SetName(const char* newName) // Sets the macro name (please use without ".C")
293 {
294 memset(fName, '\0', sizeof(Char_t) * MAX_MACRO_NAME_LENGTH);
295 sprintf(fName, "%s", newName);
296 }
297 void SetObjectType(TClass* newObjectType) // Sets the object type of the macro parameter
298 {
299 fObjectType = newObjectType;
300 }
301 void SetPath(const char* newPath) // Sets the path of the macro
302 {
303 memset(fPath, '\0', sizeof(Char_t) * MAX_MACRO_PATH_LENGTH);
304 sprintf(fPath, "%s", newPath);
305 }
306 void SetSelected(Bool_t selection) // Sets whether the macro is selected or not
307 {
308 fIsSelected = selection;
309 }
310 void SetType(AliEveListAnalyser::AliEveListAnalyserMacroType newType) // Sets the type of the macro
311 {
312 fType = newType;
313 }
314
315private:
316 TGeneralMacroData(const TGeneralMacroData&); // Not implemented
317 TGeneralMacroData& operator=(const TGeneralMacroData&); // Not implemented
318
319 Char_t fCmd[MAX_APPLY_COMMAND_LENGTH]; // Command that will be used to call this macro
320 Char_t fName[MAX_MACRO_NAME_LENGTH]; // Macro name (without ".C"!)
321 TClass* fObjectType; // Type of object of the macro parameter
322 Char_t fPath[MAX_MACRO_PATH_LENGTH]; // Path of the macro
323 Bool_t fIsSelected; // Is macro selected (e.g. in the editor's list)?
324 AliEveListAnalyser::AliEveListAnalyserMacroType fType; // Type of the macro
325};
326
327#endif