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