#include "AliESDEvent.h"
#include "TTree.h"
#include "TString.h"
-#include "TObjString.h"
-#include "TObjArray.h"
#include <cassert>
/** ROOT macro for the implementation of ROOT specific class methods */
, fVertexY(-99)
, fVertexZ(-99)
, fTrackVariables()
+ , fTrackVariablesInt()
{
// see header file for class documentation
// or
{
// see header file for class documentation
fTrackVariables.Reset();
+ fTrackVariablesInt.Reset();
}
void AliHLTGlobalHistoComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
if (!pTree) return NULL;
const char* trackVariableNames = {
+ // Note the black at the end of each name!
"Track_pt "
"Track_phi "
"Track_eta "
"Track_dEdx "
};
+ const char* trackIntVariableNames = {
+ // Note the black at the end of each name!
+ "Track_status "
+ };
+
int maxTrackCount=20000; // FIXME: make configurable
if ((iResult=fTrackVariables.Init(maxTrackCount, trackVariableNames))<0) {
- HLTError("failed to initialize internal structure for track properties");
+ HLTError("failed to initialize internal structure for track properties (float)");
+ }
+ if ((iResult=fTrackVariablesInt.Init(maxTrackCount, trackIntVariableNames))<0) {
+ HLTError("failed to initialize internal structure for track properties (int)");
}
if (iResult>=0) {
pTree->Branch("vertexX", &fVertexX, "vertexX/F");
pTree->Branch("vertexY", &fVertexY, "vertexY/F");
pTree->Branch("vertexZ", &fVertexZ, "vertexZ/F");
-
- for (int i=0; i<fTrackVariables.Variables(); i++) {
+
+ int i=0;
+ // FIXME: this is a bit ugly since type 'f' and 'i' are specified
+ // explicitely. Would be better to use a function like
+ // AliHLTGlobalHistoVariables::GetType but could not get this working
+ for (i=0; i<fTrackVariables.Variables(); i++) {
TString specifier=fTrackVariables.GetKey(i);
float* pArray=fTrackVariables.GetArray(specifier);
specifier+="[trackcount]/f";
pTree->Branch(fTrackVariables.GetKey(i), pArray, specifier.Data());
}
+ for (i=0; i<fTrackVariablesInt.Variables(); i++) {
+ TString specifier=fTrackVariablesInt.GetKey(i);
+ int* pArray=fTrackVariablesInt.GetArray(specifier);
+ specifier+="[trackcount]/i";
+ pTree->Branch(fTrackVariablesInt.GetKey(i), pArray, specifier.Data());
+ }
} else {
delete pTree;
pTree=NULL;
fTrackVariables.Fill("Track_DCAr" , DCAr );
fTrackVariables.Fill("Track_DCAz" , DCAz );
fTrackVariables.Fill("Track_dEdx" , esdTrack->GetTPCsignal() );
+
+ fTrackVariablesInt.Fill("Track_status" , esdTrack->GetStatus() );
}
HLTInfo("added parameters for %d tracks", fNofTracks);
/// reset all filling variables
fNofTracks=0;
fTrackVariables.ResetCount();
+ fTrackVariablesInt.ResetCount();
return 0;
}
// // get specifications of the output data
// return 0;
// }
-
-AliHLTGlobalHistoComponent::AliHLTGlobalHistoVariables::AliHLTGlobalHistoVariables()
- : fCapacity(0)
- , fArrays()
- , fCount()
- , fKeys()
-{
- /// default constructor
-}
-
-AliHLTGlobalHistoComponent::AliHLTGlobalHistoVariables::~AliHLTGlobalHistoVariables()
-{
- /// destructor
- Reset();
-}
-
-int AliHLTGlobalHistoComponent::AliHLTGlobalHistoVariables::Init(int capacity, const char* names)
-{
- /// init the arrays
- int iResult=0;
- TString initializer(names);
- TObjArray* pTokens=initializer.Tokenize(" ");
- fCapacity=capacity;
- if (pTokens) {
- int entries=pTokens->GetEntriesFast();
- fArrays.resize(entries);
- fCount.resize(entries);
- for (int i=0; i<entries; i++) {
- fKeys[pTokens->At(i)->GetName()]=i;
- fArrays[i]=new float[fCapacity];
- }
- delete pTokens;
- }
- assert(fArrays.size()==fCount.size());
- assert(fArrays.size()==fKeys.size());
- if (fArrays.size()!=fCount.size() ||
- fArrays.size()!=fKeys.size()) {
- return -EFAULT;
- }
-
- ResetCount();
- return iResult;
-}
-
-int AliHLTGlobalHistoComponent::AliHLTGlobalHistoVariables::Reset()
-{
- /// reset the arrays
- for (vector<float*>::iterator element=fArrays.begin();
- element!=fArrays.end();
- element++) {
- delete *element;
- }
- fArrays.clear();
- fCount.clear();
- fKeys.clear();
-
- return 0;
-}
-
-int AliHLTGlobalHistoComponent::AliHLTGlobalHistoVariables::ResetCount()
-{
- /// reset the fill counts
- for (vector<int>::iterator element=fCount.begin();
- element!=fCount.end();
- element++) {
- *element=0;
- }
- return 0;
-}
-
-int AliHLTGlobalHistoComponent::AliHLTGlobalHistoVariables::Fill(unsigned index, float value)
-{
- /// fill variable at index
- assert(fArrays.size()==fCount.size());
- if (index>=fArrays.size() || index>=fCount.size()) return -ENOENT;
- if (fCount[index]>=fCapacity) return -ENOSPC;
-
- (fArrays[index])[fCount[index]++]=value;
- return fCount[index];
-}
-
-int AliHLTGlobalHistoComponent::AliHLTGlobalHistoVariables::Fill(const char* key, float value)
-{
- /// fill variable at key
- int index=FindKey(key);
- if (index<0) return -ENOENT;
-
- return Fill(index, value);
-}
-
-float* AliHLTGlobalHistoComponent::AliHLTGlobalHistoVariables::GetArray(const char* key)
-{
- /// get array at key
- int index=FindKey(key);
- if (index<0) return NULL;
- assert((unsigned)index<fArrays.size());
- if ((unsigned)index>=fArrays.size()) return NULL;
-
- return fArrays[index];
-}
-
-int AliHLTGlobalHistoComponent::AliHLTGlobalHistoVariables::FindKey(const char* key) const
-{
- /// fill variable at key
- map<string, int>::const_iterator element=fKeys.find(key);
- if (element==fKeys.end()) return -ENOENT;
- return element->second;
-}
-
-const char* AliHLTGlobalHistoComponent::AliHLTGlobalHistoVariables::GetKey(int index) const
-{
- /// fill variable at key
- for (map<string, int>::const_iterator element=fKeys.begin();
- element!=fKeys.end(); element++) {
- if (element->second==index) return element->first.c_str();
- }
- return NULL;
-}
/// on the AliHLTTTreeProcessor
#include "AliHLTTTreeProcessor.h"
+#include "TObjString.h"
+#include "TObjArray.h"
#include <string>
#include <map>
#include <vector>
/// @class AliHLTGlobalHistoVariables
/// container for the tree branch variables
+ template <typename T>
class AliHLTGlobalHistoVariables {
public:
- AliHLTGlobalHistoVariables();
- AliHLTGlobalHistoVariables(int capacity, const char* names);
- ~AliHLTGlobalHistoVariables();
+ AliHLTGlobalHistoVariables() : fCapacity(0), fArrays(), fCount(), fKeys() {}
+ AliHLTGlobalHistoVariables(const AliHLTGlobalHistoVariables& src) : fCapacity(0), fArrays(), fCount(), fKeys() {}
+ ~AliHLTGlobalHistoVariables() {Reset();}
/// init the arrays
- int Init(int capacity, const char* names);
+ int Init(int capacity, const char* names)
+ {
+ /// init the arrays
+ int iResult=0;
+ TString initializer(names);
+ TObjArray* pTokens=initializer.Tokenize(" ");
+ fCapacity=capacity;
+ if (pTokens) {
+ int entries=pTokens->GetEntriesFast();
+ fArrays.resize(entries);
+ fCount.resize(entries);
+ for (int i=0; i<entries; i++) {
+ fKeys[pTokens->At(i)->GetName()]=i;
+ fArrays[i]=new T[fCapacity];
+ }
+ delete pTokens;
+ }
+ if (fArrays.size()!=fCount.size() ||
+ fArrays.size()!=fKeys.size()) {
+ return -EFAULT;
+ }
+
+ ResetCount();
+ return iResult;
+ }
/// capacity for every key
int Capacity() const {return fCapacity;}
int Variables() const {return fArrays.size();}
/// fill variable at index
- int Fill(unsigned index, float value);
+ int Fill(unsigned index, T value)
+ {
+ if (index>=fArrays.size() || index>=fCount.size()) return -ENOENT;
+ if (fCount[index]>=fCapacity) return -ENOSPC;
+
+ (fArrays[index])[fCount[index]++]=value;
+ return fCount[index];
+ }
+
/// fill variable at key
- int Fill(const char* key, float value);
+ int Fill(const char* key, T value)
+ {
+ int index=FindKey(key);
+ if (index<0) return -ENOENT;
+ return Fill(index, value);
+ }
+
/// get array at key
- float* GetArray(const char* key);
+ T* GetArray(const char* key)
+ {
+ int index=FindKey(key); if (index<0) return NULL;
+ if ((unsigned)index>=fArrays.size()) return NULL;
+ return fArrays[index];
+ }
+
/// get the key of an array
- const char* GetKey(int index) const;
+ const char* GetKey(int index) const
+ {
+ for (map<string, int>::const_iterator element=fKeys.begin(); element!=fKeys.end(); element++) {
+ if (element->second==index) return element->first.c_str();
+ }
+ return NULL;
+ }
/// reset and cleanup arrays
- int Reset();
+ int Reset()
+ {
+ for (unsigned i=0; i<fArrays.size(); i++) {delete fArrays[i];}
+ fArrays.clear(); fCount.clear(); fKeys.clear();
+ return 0;
+ }
/// reset the fill counts
- int ResetCount();
+ int ResetCount()
+ {
+ for (vector<int>::iterator element=fCount.begin(); element!=fCount.end(); element++) *element=0;
+ return 0;
+ }
+
+ char GetType() const {AliHLTGlobalHistoVariablesType type(T&); return type.GetType();}
private:
- int FindKey(const char* key) const;
+ int FindKey(const char* key) const
+ {
+ map<string, int>::const_iterator element=fKeys.find(key);
+ if (element==fKeys.end()) return -ENOENT;
+ return element->second;
+ }
+
+ /// internal helper class to get the type of the template
+ class AliHLTGlobalHistoVariablesType {
+ public:
+ AliHLTGlobalHistoVariablesType(float&) : fType('f') {}
+ AliHLTGlobalHistoVariablesType(int&) : fType('i') {}
+ char GetType() const {return fType;}
+ private:
+ char fType; //!
+ };
/// capacity of all arrays
int fCapacity; //!
/// pointers of arrays
- vector<float*> fArrays; //!
+ vector<T*> fArrays; //!
/// fill count for arrays
vector<int> fCount; //!
/// map of keys
float fVertexZ; //!
/// filling arrays for track parameters
- AliHLTGlobalHistoComponent::AliHLTGlobalHistoVariables fTrackVariables; //!
+ AliHLTGlobalHistoVariables<float> fTrackVariables; //!
+ AliHLTGlobalHistoVariables<int> fTrackVariablesInt; //!
ClassDef(AliHLTGlobalHistoComponent, 0) // HLT Global Histogram component
};