]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/global/AliHLTGlobalHistoComponent.h
Add method as parameter output
[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() {}
e7f3baeb 86 ~AliHLTGlobalHistoVariables() {Reset();}
a4c1f5dd 87
88 /// init the arrays
e7f3baeb 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 }
a4c1f5dd 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
e7f3baeb 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
a4c1f5dd 130 /// fill variable at key
e7f3baeb 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
a4c1f5dd 138 /// get array at key
e7f3baeb 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
a4c1f5dd 146 /// get the key of an array
e7f3baeb 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 }
a4c1f5dd 154
155 /// reset and cleanup arrays
e7f3baeb 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 }
a4c1f5dd 162
163 /// reset the fill counts
e7f3baeb 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();}
a4c1f5dd 171
172 private:
b09a4c9e 173 AliHLTGlobalHistoVariables(const AliHLTGlobalHistoVariables& src);
174 AliHLTGlobalHistoVariables& operator=(const AliHLTGlobalHistoVariables& src);
175
e7f3baeb 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 };
a4c1f5dd 192
193 /// capacity of all arrays
194 int fCapacity; //!
195 /// pointers of arrays
e7f3baeb 196 vector<T*> fArrays; //!
a4c1f5dd 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
b77cb0b8 207 int FillTree(TTree* pTree, const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData );
a4c1f5dd 208 /// dtOrigin for PushBack.
209 AliHLTComponentDataType GetOriginDataType() const;
b77cb0b8 210 /// clean up variables
a4c1f5dd 211 int ResetVariables();
b77cb0b8 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
a4c1f5dd 217private:
218 /// copy constructor prohibited
219 AliHLTGlobalHistoComponent(const AliHLTGlobalHistoComponent&);
220 /// assignment operator prohibited
221 AliHLTGlobalHistoComponent& operator=(const AliHLTGlobalHistoComponent&);
7a37a034 222
a4c1f5dd 223 /// the event number, tree filling variable
224 int fEvent; //!
225 /// track count, tree filling variable
226 int fNofTracks; //!
1b89b93a 227 /// V0 count, tree filling variable
a0cfb01c 228 int fNofV0s; //!
1b89b93a 229 /// contributors count, tree filling variable
230 int fNofContributors; //!
a0cfb01c 231 /// x coordinate of vertex
54da0d34 232 float fVertexX; //!
233 /// y coordinate of vertex
234 float fVertexY; //!
235 /// z coordinate of vertex
236 float fVertexZ; //!
1b89b93a 237 /// vertex status, found or not
238 bool fVertexStatus; //!
b77cb0b8 239 /// maximum track multiplicity
a0cfb01c 240 int fMaxTrackCount; //!
241 /// maximum number of V0 entries
242 int fMaxV0Count; //!
243 /// activate event properties branch
244 bool fFillV0; //!
54da0d34 245
a4c1f5dd 246 /// filling arrays for track parameters
e7f3baeb 247 AliHLTGlobalHistoVariables<float> fTrackVariables; //!
a0cfb01c 248 /// filling array for the track status
e7f3baeb 249 AliHLTGlobalHistoVariables<int> fTrackVariablesInt; //!
7a37a034 250 /// filling arrays for V0 parameters
a0cfb01c 251 AliHLTGlobalHistoVariables<float> fV0Variables; //!
252
a4c1f5dd 253 ClassDef(AliHLTGlobalHistoComponent, 0) // HLT Global Histogram component
254};
255#endif