3 #ifndef ALIHLTSPACEPOINTCONTAINER_H
4 #define ALIHLTSPACEPOINTCONTAINER_H
5 //* This file is property of and copyright by the ALICE HLT Project *
6 //* ALICE Experiment at CERN, All rights reserved. *
7 //* See cxx source for full Copyright notice *
9 /// @file AliHLTSpacePointContainer.h
10 /// @author Matthias Richter
12 /// @brief Base helper class for handling of HLT space point data blocks
18 #include "AliHLTLogging.h"
19 #include "AliHLTDataTypes.h"
20 #include "AliHLTStdIncludes.h"
22 class AliHLTDataDeflater;
28 * @class AliHLTSpacePointContainer
29 * Base class of helper classes for space point data blocks.
30 * The class implements a couple of interface methods to be commonly used
31 * for space point data blocks.
33 * @ingroup alihlt_base
35 class AliHLTSpacePointContainer : public TObject, public AliHLTLogging
38 /// standard constructor
39 AliHLTSpacePointContainer();
41 AliHLTSpacePointContainer(const AliHLTSpacePointContainer&);
42 /// assignment operator
43 AliHLTSpacePointContainer& operator=(const AliHLTSpacePointContainer&);
46 ~AliHLTSpacePointContainer();
48 //////////////////////////////////////////////////////////////////////////
50 // helper classes for access of space points within a grid
52 struct AliHLTSpacePointCell {
58 class AliHLTSpacePointGrid {
60 AliHLTSpacePointGrid(float maxX, float stepX,
61 float maxY, float stepY,
62 float maxZ, float stepZ,
63 int initialDataSize=-1);
64 virtual ~AliHLTSpacePointGrid();
66 // for now array of spacepoint ids
67 typedef AliHLTUInt32_t ValueType;
69 int GetDimensionX() const {return fDimX;}
70 int GetDimensionY() const {return fDimY;}
71 int GetDimensionZ() const {return fDimZ;}
72 int GetXIndex(float x) const {
73 if (x>fMaxX) return fDimX-1;
75 return (int)floor(x/fStepX);
77 int GetYIndex(float y) const {
78 if (y>fMaxY) return fDimY-1;
80 return (int)floor(y/fStepY);
82 int GetZIndex(float z) const {
83 if (z>fMaxZ) return fDimZ-1;
85 return (int)floor(z/fStepZ);
87 float GetLowerBoundX(int cell) const {
88 if (fDimX==0 || fDimY==0 ||fDimZ==0) return 0.;
89 int index=cell/(fDimY*fDimZ);
92 float GetLowerBoundY(int cell) const {
93 if (fDimX==0 || fDimY==0 ||fDimZ==0) return 0.;
94 int index=cell%(fDimY*fDimZ); index/=fDimZ;
97 float GetLowerBoundZ(int cell) const {
98 if (fDimX==0 || fDimY==0 ||fDimZ==0) return 0.;
99 int index=cell%(fDimY*fDimZ); index%=fDimZ;
102 int GetCellIndex(float x, float y, float z) const {
103 return GetXIndex(x)*fDimY*fDimZ + (y<0?0:GetYIndex(y))*fDimZ + (z<0?0:GetZIndex(z));
105 int GetNumberOfSpacePoints(int index, int endIndex) const {
106 if (!fCells) return 0;
108 for (int cell=index; cell<endIndex && cell<fCellDimension && count<fCount; cell++) if (fCells[cell].fCount>0) count+=fCells[cell].fCount;
112 // increment counter of the cell where the spacepoint is
113 int CountSpacePoint(float x, float y, float z);
115 // add spacepoint, all spacepoints must have been counted before
116 int AddSpacePoint(ValueType t, float x, float y, float z);
118 void Clear(const char* option="");
119 void Print(const char* option="");
125 iterator(const ValueType* pData)
127 iterator(const iterator& i)
129 iterator& operator=(const iterator& i)
130 { fData=i.fData; return *this;}
131 ~iterator() {fData=NULL;}
133 bool operator==(const iterator& i) const {return (fData!=NULL) && (fData==i.fData);}
134 bool operator!=(const iterator& i) const {return (fData!=NULL) && (fData!=i.fData);}
136 iterator& operator++() {fData++; return *this;}
137 iterator& operator--() {fData--; return *this;}
139 iterator operator++(int) {iterator i(*this); fData++; return i;}
140 iterator operator--(int) {iterator i(*this); fData--; return i;}
142 iterator& operator+=(int step) {fData+=step; return *this;}
144 const ValueType& Data() const {return *fData;}
148 const ValueType* fData; //! data
151 // prepare iterator and end marker
152 iterator& begin(float x=-1., float y=-1., float z=-1.) {
153 fIterator.~iterator();
154 fIteratorEnd.~iterator();
160 new (&fIterator) iterator(fData);
161 fIteratorEnd=fIterator;
162 fIteratorEnd+=fCount;
167 // only search for the start index if specific x selected
168 int cell=GetCellIndex(x, y, z);
169 if (cell<0 || !fCells || cell>=fCellDimension) return fIterator;
170 // get the index of the cell
171 startIndex=fCells[cell].fStartIndex;
172 if (startIndex<0 || !fData || startIndex>=fDataDimension) return fIterator;
174 // get the range end position
176 if (x<0) endCell=fCellDimension;
177 else if (y<0) endCell=GetCellIndex(x+fStepX, -1., -1.); // all entries for fixed x
178 else if (z<0) endCell=GetCellIndex(x, y+fStepY, -1.); // all entries for fixed x and y
180 // cell index returned is never outside the array
181 // so this is a special case where we get to the bounds of the array
182 endCell=fCellDimension;
185 new (&fIterator) iterator(fData+startIndex);
186 fIteratorEnd=fIterator;
187 fIteratorEnd+=GetNumberOfSpacePoints(cell, endCell);
191 // get loop end marker
198 // standard constructor prohibited
199 AliHLTSpacePointGrid();
200 // copy constructor prohibited
201 AliHLTSpacePointGrid(const AliHLTSpacePointGrid&);
202 // assignment operator prohibited
203 AliHLTSpacePointGrid& operator=(const AliHLTSpacePointGrid&);
218 AliHLTSpacePointCell* fCells; //! cell array
219 int fCellDimension; //! size of cell array
220 ValueType* fData; //! spacepoint data
221 int fDataDimension; //! size of spacepoint data
224 iterator fIterator; //! iterator
225 iterator fIteratorEnd; //! end marker iterator
227 static const int fgkDefaultDataSize; //! the default data size
229 ClassDef(AliHLTSpacePointGrid, 0)
232 //////////////////////////////////////////////////////////////////////////
234 // interface functions
237 /// add input block to the collection
238 virtual int AddInputBlock(const AliHLTComponentBlockData* pDesc)=0;
239 virtual int PopulateAccessGrid(AliHLTSpacePointGrid* /*pGrid*/, AliHLTUInt32_t /*mask*/) const {return -ENOSYS;}
240 virtual const AliHLTSpacePointGrid* GetAccessGrid(AliHLTUInt32_t /*mask*/) const {return NULL;}
242 virtual int GetNumberOfSpacePoints() const;
243 virtual bool Check(AliHLTUInt32_t clusterID) const;
244 virtual int GetClusterIDs(vector<AliHLTUInt32_t>& tgt) const = 0;
245 virtual const vector<AliHLTUInt32_t>* GetClusterIDs(AliHLTUInt32_t /*mask*/) {return NULL;}
246 virtual float GetX(AliHLTUInt32_t clusterID) const = 0;
247 virtual float GetXWidth(AliHLTUInt32_t clusterID) const = 0;
248 virtual float GetY(AliHLTUInt32_t clusterID) const = 0;
249 virtual float GetYWidth(AliHLTUInt32_t clusterID) const = 0;
250 virtual float GetZ(AliHLTUInt32_t clusterID) const = 0;
251 virtual float GetZWidth(AliHLTUInt32_t clusterID) const = 0;
252 virtual float GetCharge(AliHLTUInt32_t clusterID) const = 0;
253 virtual float GetMaxSignal(AliHLTUInt32_t /*clusterID*/) const {return 0.0;}
254 virtual float GetPhi(AliHLTUInt32_t /*clusterID*/) const {return 0.0;}
256 /// create a collection of clusters for a space point mask
257 virtual AliHLTSpacePointContainer* SelectByMask(AliHLTUInt32_t mask, bool bAlloc=false) const;
259 /// create a collection of clusters for a specific track
260 virtual AliHLTSpacePointContainer* SelectByTrack(int trackId, bool bAlloc=false) const;
262 /// create a collection of clusters for a specific MC track
263 virtual AliHLTSpacePointContainer* SelectByMC(int mcId, bool bAlloc=false) const;
265 /// create a collection of all used clusters
266 virtual AliHLTSpacePointContainer* UsedClusters(bool bAlloc=false) const;
268 /// create a collection of all unused clusters
269 virtual AliHLTSpacePointContainer* UnusedClusters(bool bAlloc=false) const;
271 int MarkUsed(AliHLTUInt32_t clusterID) {return MarkUsed(&clusterID, sizeof(clusterID));}
272 virtual int MarkUsed(const AliHLTUInt32_t* clusterIDs, int arraySize);
274 int SetTrackID(int trackID, AliHLTUInt32_t clusterID) {
275 return SetTrackID(trackID, &clusterID, sizeof(clusterID));
277 virtual int SetTrackID(int trackID, const AliHLTUInt32_t* clusterIDs, int arraySize);
279 virtual int GetTrackID(AliHLTUInt32_t /*clusterID*/) const {return -1;}
281 int SetMCID(int mcID, AliHLTUInt32_t clusterID) {
282 return SetMCID(mcID, &clusterID, sizeof(clusterID));
284 virtual int SetMCID(int clusterID, const AliHLTUInt32_t* clusterIDs, int arraySize);
286 /// write blocks to HLT component output
287 virtual int Write(AliHLTUInt8_t* outputPtr, AliHLTUInt32_t size,
288 vector<AliHLTComponentBlockData>& outputBlocks,
289 AliHLTDataDeflater* /*pDeflater*/,
290 const char* option="") const {
291 return Write(outputPtr, size, outputBlocks, option);
294 /// write blocks to HLT component output: old function definition for backward compatibility
295 virtual int Write(AliHLTUInt8_t* /*outputPtr*/, AliHLTUInt32_t /*size*/,
296 vector<AliHLTComponentBlockData>& /*outputBlocks*/,
297 const char* /*option*/="") const {return 0;}
299 /// add input block from file to collection
300 int AddInputBlock(const char* filename, AliHLTComponentDataType dt, unsigned specification);
302 /// add input block from list of blank separated files to collection
303 int AddInputBlocks(const char* filenames, AliHLTComponentDataType dt);
305 /// alloc memory for a space point data block
306 AliHLTUInt8_t* Alloc(int size);
308 /// inherited from TObject: clear the object and reset pointer references
309 virtual void Clear(Option_t * /*option*/ ="");
311 /// inherited from TObject
312 virtual void Print(Option_t *option="") const;
314 virtual void Print(ostream& out, Option_t *option="") const;
316 void Draw(Option_t *option);
318 TH1* DrawProjection(const char* plane) const {
319 vector<AliHLTUInt32_t> selection; // empty list -> no selection
320 return DrawProjection(plane, selection);
323 TH1* DrawProjection(const char* plane, AliHLTUInt32_t specification) const {
324 vector<AliHLTUInt32_t> selection; selection.push_back(specification);
325 return DrawProjection(plane, selection);
328 TH1* DrawProjection(const char* plane, const vector<AliHLTUInt32_t>& selection) const;
330 TTree* FillTree(const char* name, const char* title="");
335 vector<TArrayC*> fBuffers; //! buffers of loaded files
337 ClassDef(AliHLTSpacePointContainer, 0)
340 ostream& operator<<(ostream &out, const AliHLTSpacePointContainer& c);