]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/global/AliHLTGlobalHistoComponent.h
adding USE_DLOPEN option for HLT
[u/mrichter/AliRoot.git] / HLT / global / AliHLTGlobalHistoComponent.h
1 // -*- Mode: C++ -*-
2 // $Id$
3
4 #ifndef ALIHLTGLOBALHISTOCOMPONENT_H
5 #define ALIHLTGLOBALHISTOCOMPONENT_H
6 //* This file is property of and copyright by the ALICE HLT Project        * 
7 //* ALICE Experiment at CERN, All rights reserved.                         *
8 //* See cxx source for full Copyright notice                               *
9
10 /// @file   AliHLTGlobalHistoComponent.h
11 /// @author Matthias Richter
12 /// @date   2010-09-16
13 /// @brief  A histogramming component for global ESD properties based
14 ///         on the AliHLTTTreeProcessor
15
16 #include "AliHLTTTreeProcessor.h"
17 #include "TObjString.h"
18 #include "TObjArray.h"
19 #include <string>
20 #include <map>
21 #include <vector>
22
23 /**
24  * @class AliHLTGlobalHistoComponent
25  *
26  * <h2>General properties:</h2>
27  *
28  * Component ID: \b GlobalHisto                                         <br>
29  * Library: \b libAliHLTGlobal.so                                       <br>
30  * Input Data Types: ::kAliHLTAnyDataType                               <br>
31  * Output Data Types: none                                              <br>
32  *
33  * <h2>Mandatory arguments:</h2>
34  * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting -->
35  *      
36  * <h2>Optional arguments:</h2>
37  * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting -->
38  *
39  * <h2>Configuration:</h2>
40  * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting -->
41  * Configuration by component arguments.
42  *
43  * <h2>Default CDB entries:</h2>
44  * The component loads no CDB entries.
45  *
46  * <h2>Performance:</h2>
47  * The component does not process any event data.
48  *
49  * <h2>Memory consumption:</h2>
50  * The component does not process any event data.
51  *
52  * <h2>Output size:</h2>
53  * Depending on the mode.
54  *
55  * @ingroup alihlt_global_components
56  */
57 class AliHLTGlobalHistoComponent : public AliHLTTTreeProcessor
58 {
59  public:
60   /// standard constructor
61   AliHLTGlobalHistoComponent();
62   /// destructor
63   virtual ~AliHLTGlobalHistoComponent();
64
65   /// inherited from AliHLTComponent: return id of the component.
66   virtual const char* GetComponentID() {return "GlobalHisto";};
67   /// inherited from AliHLTComponent: input data types
68   virtual void GetInputDataTypes(AliHLTComponentDataTypeList&);
69  
70   
71   /// interface function, see AliHLTComponent for description
72   AliHLTComponentDataType GetOutputDataType();
73   
74   
75   /// inherited from AliHLTComponent: spawn function, create an instance.
76   virtual AliHLTComponent* Spawn() {return new AliHLTGlobalHistoComponent;}
77
78   void FillHistogramDefinitions();
79
80   /// @class AliHLTGlobalHistoVariables
81   /// container for the tree branch variables
82   template <typename T>
83   class AliHLTGlobalHistoVariables {
84   public:
85     AliHLTGlobalHistoVariables()  : fCapacity(0), fArrays(), fCount(), fKeys() {}
86     ~AliHLTGlobalHistoVariables() {Reset();}
87
88     /// init the arrays
89     int Init(int capacity, const char* names)
90     {
91       /// init the arrays
92       int iResult=0;
93       TString initializer(names);
94       TObjArray* pTokens=initializer.Tokenize(" ");
95       fCapacity=capacity;
96       if (pTokens) {
97         int entries=pTokens->GetEntriesFast();
98         fArrays.resize(entries);
99         fCount.resize(entries);
100         for (int i=0; i<entries; i++) {
101           fKeys[pTokens->At(i)->GetName()]=i;
102           fArrays[i]=new T[fCapacity];
103         }
104         delete pTokens;
105       }
106       if (fArrays.size()!=fCount.size() ||
107           fArrays.size()!=fKeys.size()) {
108         return -EFAULT;
109       }
110
111       ResetCount();
112       return iResult;
113     }
114
115     /// capacity for every key
116     int Capacity() const {return fCapacity;}
117     /// number of variables
118     int Variables() const {return fArrays.size();}
119
120     /// fill variable at index
121     int Fill(unsigned index, T value)
122     {
123       if (index>=fArrays.size() || index>=fCount.size()) return -ENOENT;
124       if (fCount[index]>=fCapacity) return -ENOSPC;
125
126       (fArrays[index])[fCount[index]++]=value;
127       return fCount[index];
128     }
129
130     /// fill variable at key
131     int Fill(const char* key, T value)
132     {
133       int index=FindKey(key);
134       if (index<0) return -ENOENT;
135       return Fill(index, value);
136     }
137
138     /// get array at key
139     T* GetArray(const char* key)
140     {
141       int index=FindKey(key); if (index<0) return NULL;
142       if ((unsigned)index>=fArrays.size()) return NULL;
143       return fArrays[index];
144     }
145
146     /// get the key of an array
147     const char* GetKey(int index) const
148     {
149       for (map<string, int>::const_iterator element=fKeys.begin(); element!=fKeys.end(); element++) {
150         if (element->second==index) return element->first.c_str();
151       }
152       return NULL;
153     }
154
155     /// reset and cleanup arrays
156     int Reset()
157     {
158       for (unsigned i=0; i<fArrays.size(); i++) {delete fArrays[i];}
159       fArrays.clear(); fCount.clear(); fKeys.clear();
160       return 0;
161     }
162
163     /// reset the fill counts
164     int ResetCount()
165     {
166       for (vector<int>::iterator element=fCount.begin(); element!=fCount.end(); element++) *element=0;
167       return 0;
168     }
169
170     char GetType() const {AliHLTGlobalHistoVariablesType type(T&); return type.GetType();}
171
172   private:
173     AliHLTGlobalHistoVariables(const AliHLTGlobalHistoVariables& src);
174     AliHLTGlobalHistoVariables& operator=(const AliHLTGlobalHistoVariables& src);
175
176     int FindKey(const char* key) const
177     {
178       map<string, int>::const_iterator element=fKeys.find(key);
179       if (element==fKeys.end()) return -ENOENT;
180       return element->second;
181     }
182
183     /// internal helper class to get the type of the template
184     class AliHLTGlobalHistoVariablesType {
185     public:
186       AliHLTGlobalHistoVariablesType(float&) : fType('f') {}
187       AliHLTGlobalHistoVariablesType(int&)   : fType('i') {}
188       char GetType() const {return fType;}
189     private:
190       char fType; //!
191     };
192
193     /// capacity of all arrays
194     int fCapacity; //!
195     /// pointers of arrays
196     vector<T*> fArrays; //!
197     /// fill count for arrays
198     vector<int> fCount; //!
199     /// map of keys
200     map<string,int> fKeys; //!
201   };
202
203  protected:
204   /// inherited from AliHLTTTreeProcessor: create the tree instance and all branches
205   TTree* CreateTree(int argc, const char** argv);
206   /// inherited from AliHLTTTreeProcessor: process input blocks and fill tree
207   int FillTree(TTree* pTree, const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData );
208   /// dtOrigin for PushBack.
209   AliHLTComponentDataType GetOriginDataType() const;
210   /// clean up variables
211   int ResetVariables();
212   /// inherited from AliHLTComponent, scan argument
213   int ScanConfigurationArgument(int argc, const char** argv);
214   /// function for online reconfiguration
215   int Reconfigure(const char* cdbEntry, const char* chainId);
216
217 private:
218   /// copy constructor prohibited
219   AliHLTGlobalHistoComponent(const AliHLTGlobalHistoComponent&);
220   /// assignment operator prohibited
221   AliHLTGlobalHistoComponent& operator=(const AliHLTGlobalHistoComponent&);
222     
223   /// the event number, tree filling variable
224   int fEvent; //!
225   /// track count, tree filling variable
226   int fNofTracks; //!
227   /// V0 count, tree filling variable
228   int fNofV0s; //!
229   /// contributors count, tree filling variable
230   int fNofContributors; //!
231   /// x coordinate of vertex
232   float fVertexX; //!
233   /// y coordinate of vertex
234   float fVertexY; //!
235   /// z coordinate of vertex
236   float fVertexZ; //!
237   /// vertex status, found or not
238   bool fVertexStatus; //!
239   /// maximum track multiplicity
240   int fMaxTrackCount; //!
241   /// maximum number of V0 entries
242   int fMaxV0Count; //!
243   /// activate event properties branch
244   bool fFillV0; //!
245  
246   /// filling arrays for track parameters
247   AliHLTGlobalHistoVariables<float> fTrackVariables; //!
248   /// filling array for the track status
249   AliHLTGlobalHistoVariables<int> fTrackVariablesInt; //!
250   /// filling arrays for V0 parameters
251   AliHLTGlobalHistoVariables<float> fV0Variables; //!
252    
253   ClassDef(AliHLTGlobalHistoComponent, 0) // HLT Global Histogram component
254 };
255 #endif