using now the specification provided by the base class
[u/mrichter/AliRoot.git] / HLT / global / AliHLTGlobalHistoComponent.h
CommitLineData
a4c1f5dd 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"
e7f3baeb 17#include "TObjString.h"
18#include "TObjArray.h"
a4c1f5dd 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_util_components
56 */
57class 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&);
af747e4b 69
70
71 /// interface function, see AliHLTComponent for description
72 AliHLTComponentDataType GetOutputDataType();
73
74
a4c1f5dd 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
e7f3baeb 82 template <typename T>
a4c1f5dd 83 class AliHLTGlobalHistoVariables {
84 public:
e7f3baeb 85 AliHLTGlobalHistoVariables() : fCapacity(0), fArrays(), fCount(), fKeys() {}
86 AliHLTGlobalHistoVariables(const AliHLTGlobalHistoVariables& src) : fCapacity(0), fArrays(), fCount(), fKeys() {}
87 ~AliHLTGlobalHistoVariables() {Reset();}
a4c1f5dd 88
89 /// init the arrays
e7f3baeb 90 int Init(int capacity, const char* names)
91 {
92 /// init the arrays
93 int iResult=0;
94 TString initializer(names);
95 TObjArray* pTokens=initializer.Tokenize(" ");
96 fCapacity=capacity;
97 if (pTokens) {
98 int entries=pTokens->GetEntriesFast();
99 fArrays.resize(entries);
100 fCount.resize(entries);
101 for (int i=0; i<entries; i++) {
102 fKeys[pTokens->At(i)->GetName()]=i;
103 fArrays[i]=new T[fCapacity];
104 }
105 delete pTokens;
106 }
107 if (fArrays.size()!=fCount.size() ||
108 fArrays.size()!=fKeys.size()) {
109 return -EFAULT;
110 }
111
112 ResetCount();
113 return iResult;
114 }
a4c1f5dd 115
116 /// capacity for every key
117 int Capacity() const {return fCapacity;}
118 /// number of variables
119 int Variables() const {return fArrays.size();}
120
121 /// fill variable at index
e7f3baeb 122 int Fill(unsigned index, T value)
123 {
124 if (index>=fArrays.size() || index>=fCount.size()) return -ENOENT;
125 if (fCount[index]>=fCapacity) return -ENOSPC;
126
127 (fArrays[index])[fCount[index]++]=value;
128 return fCount[index];
129 }
130
a4c1f5dd 131 /// fill variable at key
e7f3baeb 132 int Fill(const char* key, T value)
133 {
134 int index=FindKey(key);
135 if (index<0) return -ENOENT;
136 return Fill(index, value);
137 }
138
a4c1f5dd 139 /// get array at key
e7f3baeb 140 T* GetArray(const char* key)
141 {
142 int index=FindKey(key); if (index<0) return NULL;
143 if ((unsigned)index>=fArrays.size()) return NULL;
144 return fArrays[index];
145 }
146
a4c1f5dd 147 /// get the key of an array
e7f3baeb 148 const char* GetKey(int index) const
149 {
150 for (map<string, int>::const_iterator element=fKeys.begin(); element!=fKeys.end(); element++) {
151 if (element->second==index) return element->first.c_str();
152 }
153 return NULL;
154 }
a4c1f5dd 155
156 /// reset and cleanup arrays
e7f3baeb 157 int Reset()
158 {
159 for (unsigned i=0; i<fArrays.size(); i++) {delete fArrays[i];}
160 fArrays.clear(); fCount.clear(); fKeys.clear();
161 return 0;
162 }
a4c1f5dd 163
164 /// reset the fill counts
e7f3baeb 165 int ResetCount()
166 {
167 for (vector<int>::iterator element=fCount.begin(); element!=fCount.end(); element++) *element=0;
168 return 0;
169 }
170
171 char GetType() const {AliHLTGlobalHistoVariablesType type(T&); return type.GetType();}
a4c1f5dd 172
173 private:
e7f3baeb 174 int FindKey(const char* key) const
175 {
176 map<string, int>::const_iterator element=fKeys.find(key);
177 if (element==fKeys.end()) return -ENOENT;
178 return element->second;
179 }
180
181 /// internal helper class to get the type of the template
182 class AliHLTGlobalHistoVariablesType {
183 public:
184 AliHLTGlobalHistoVariablesType(float&) : fType('f') {}
185 AliHLTGlobalHistoVariablesType(int&) : fType('i') {}
186 char GetType() const {return fType;}
187 private:
188 char fType; //!
189 };
a4c1f5dd 190
191 /// capacity of all arrays
192 int fCapacity; //!
193 /// pointers of arrays
e7f3baeb 194 vector<T*> fArrays; //!
a4c1f5dd 195 /// fill count for arrays
196 vector<int> fCount; //!
197 /// map of keys
198 map<string,int> fKeys; //!
199 };
200
201 protected:
202 /// inherited from AliHLTTTreeProcessor: create the tree instance and all branches
203 TTree* CreateTree(int argc, const char** argv);
204 /// inherited from AliHLTTTreeProcessor: process input blocks and fill tree
205 int FillTree(TTree* pTree, const AliHLTComponentEventData& evtData,
206 AliHLTComponentTriggerData& trigData );
207 /// dtOrigin for PushBack.
208 AliHLTComponentDataType GetOriginDataType() const;
a4c1f5dd 209
210 int ResetVariables();
54da0d34 211
a4c1f5dd 212private:
213 /// copy constructor prohibited
214 AliHLTGlobalHistoComponent(const AliHLTGlobalHistoComponent&);
215 /// assignment operator prohibited
216 AliHLTGlobalHistoComponent& operator=(const AliHLTGlobalHistoComponent&);
7a37a034 217
a4c1f5dd 218 /// the event number, tree filling variable
219 int fEvent; //!
220 /// track count, tree filling variable
221 int fNofTracks; //!
1b89b93a 222 /// V0 count, tree filling variable
223 int fNofV0s; //!
1c1af02a 224 /// UPC pair count (=1), tree filling variable
225 int fNofUPCpairs; //!
1b89b93a 226 /// contributors count, tree filling variable
227 int fNofContributors; //!
228 /// x coordinate of vertex
54da0d34 229 float fVertexX; //!
230 /// y coordinate of vertex
231 float fVertexY; //!
232 /// z coordinate of vertex
233 float fVertexZ; //!
1b89b93a 234 /// vertex status, found or not
235 bool fVertexStatus; //!
54da0d34 236
a4c1f5dd 237 /// filling arrays for track parameters
e7f3baeb 238 AliHLTGlobalHistoVariables<float> fTrackVariables; //!
239 AliHLTGlobalHistoVariables<int> fTrackVariablesInt; //!
7a37a034 240
241 /// filling arrays for V0 parameters
242 AliHLTGlobalHistoVariables<float> fV0Variables; //!
1c1af02a 243
244 /// filling arrays for UPC parameters
245 AliHLTGlobalHistoVariables<float> fUPCVariables; //!
54da0d34 246
7a37a034 247
248 Double_t fGammaCuts[8]; // cuts for gammas
249 Double_t fKsCuts[8]; // cuts for Ks
250 Double_t fLambdaCuts[8]; // cuts for Lambdas
251 Double_t fAPCuts[8]; // cuts for Armenteros-Podolanski plot
252
253 Int_t fNEvents; // n of processed events
254 Int_t fNGammas; // n found total
255 Int_t fNKShorts; // n found total
256 Int_t fNLambdas; // n found total
257 Int_t fNPi0s; // n found total
258
a4c1f5dd 259 ClassDef(AliHLTGlobalHistoComponent, 0) // HLT Global Histogram component
260};
261#endif