]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCHWCFSpacePointContainer.h
adding protection for invalid array index
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCHWCFSpacePointContainer.h
1 //-*- Mode: C++ -*-
2 // $Id$
3 #ifndef ALIHLTTPCHWCFSPACEPOINTCONTAINER_H
4 #define ALIHLTTPCHWCFSPACEPOINTCONTAINER_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                               *
8
9 /// @file   AliHLTTPCHWCFSpacePointContainer.h
10 /// @author Matthias Richter
11 /// @date   2011-08-08
12 /// @brief  Helper class for handling of HLT TPC cluster data blocks from the
13 ///         HW ClusterFinder
14 /// @note   Class is a duplicate of AliHLTTPCHWCFSpacePointContainer and should
15 ///         be merged with it in a generic way
16
17 #include "AliHLTSpacePointContainer.h"
18 #include "AliHLTTPCHWCFData.h"
19 #include <map>
20 #include <vector>
21 using namespace std;
22
23 /**
24  * @class AliHLTTPCHWCFSpacePointContainer
25  * Handler class for HLT TPC hardware ClusterFinder space point data blocks.
26  *
27  * @ingroup alihlt_tpc
28  */
29 class AliHLTTPCHWCFSpacePointContainer : public AliHLTSpacePointContainer
30 {
31  public:
32   /// standard constructor
33   AliHLTTPCHWCFSpacePointContainer(int mode=0);
34   /// copy constructor
35   AliHLTTPCHWCFSpacePointContainer(const AliHLTTPCHWCFSpacePointContainer& c);
36   /// assignment operator
37   AliHLTTPCHWCFSpacePointContainer& operator=(const AliHLTTPCHWCFSpacePointContainer& c);
38   /// destructor
39   ~AliHLTTPCHWCFSpacePointContainer();
40
41   enum {
42     kModeSingle = 0x1,
43     kModeCreateMap = 0x2
44   };
45
46   virtual bool Check(AliHLTUInt32_t clusterID) const;
47   virtual int GetClusterIDs(vector<AliHLTUInt32_t>& tgt) const;
48   virtual const vector<AliHLTUInt32_t>* GetClusterIDs(AliHLTUInt32_t mask);
49   virtual float GetX(AliHLTUInt32_t clusterID) const;
50   virtual float GetXWidth(AliHLTUInt32_t clusterID) const;
51   virtual float GetY(AliHLTUInt32_t clusterID) const;
52   virtual float GetYWidth(AliHLTUInt32_t clusterID) const;
53   virtual float GetZ(AliHLTUInt32_t clusterID) const;
54   virtual float GetZWidth(AliHLTUInt32_t clusterID) const;
55   virtual float GetCharge(AliHLTUInt32_t clusterID) const;
56   virtual float GetQMax(AliHLTUInt32_t clusterID) const;
57   virtual float GetPhi(AliHLTUInt32_t clusterID) const;
58
59   /// add input block to the collection
60   virtual int AddInputBlock(const AliHLTComponentBlockData* pDesc);
61
62   virtual int PopulateAccessGrid(AliHLTSpacePointPropertyGrid* pGrid, AliHLTUInt32_t mask) const;
63   int PopulateAccessGrid(AliHLTSpacePointPropertyGrid* pGrid, AliHLTTPCHWCFData* pDecoder, int slice, int partition) const;
64   virtual const AliHLTSpacePointPropertyGrid* GetSpacePointPropertyGrid(AliHLTUInt32_t mask) const;
65   virtual int SetSpacePointPropertyGrid(AliHLTUInt32_t mask, AliHLTSpacePointPropertyGrid*);
66
67   /// clear the object and reset pointer references
68   virtual void Clear(Option_t * option ="");
69
70   /// print information
71   virtual void Print(ostream& out, Option_t *option="") const;
72
73   /// create a collection of clusters for a space point mask
74   virtual AliHLTSpacePointContainer* SelectByMask(AliHLTUInt32_t mask, bool bAlloc=false) const;
75
76   /// create a collection of clusters for a specific track
77   virtual AliHLTSpacePointContainer* SelectByTrack(int trackId, bool bAlloc=false) const;
78
79   /// create a collection of clusters for a specific MC track
80   virtual AliHLTSpacePointContainer* SelectByMC(int mcId, bool bAlloc=false) const;
81
82   /// create a collection of all used clusters
83   virtual AliHLTSpacePointContainer* UsedClusters(bool bAlloc=false) const;
84
85   /// create a collection of all unused clusters
86   virtual AliHLTSpacePointContainer* UnusedClusters(bool bAlloc=false) const;
87
88   virtual int MarkUsed(const AliHLTUInt32_t* clusterIDs, int arraySize);
89   virtual int SetTrackID(int trackID, const AliHLTUInt32_t* clusterIDs, int arraySize);
90   virtual int GetTrackID(AliHLTUInt32_t clusterID) const;
91   virtual int SetMCID(int clusterID, const AliHLTUInt32_t* clusterIDs, int arraySize);
92
93   virtual int Write(AliHLTUInt8_t* outputPtr, AliHLTUInt32_t size,
94                     vector<AliHLTComponentBlockData>& outputBlocks,
95                     AliHLTDataDeflater* pDeflater,
96                     const char* option="") const;
97   virtual int Write(AliHLTUInt8_t* outputPtr, AliHLTUInt32_t size, AliHLTUInt32_t offset,
98                     vector<AliHLTComponentBlockData>& outputBlocks,
99                     AliHLTDataDeflater* pDeflater,
100                     const char* option="") const;
101
102   int WriteSorted(AliHLTUInt8_t* outputPtr, AliHLTUInt32_t size, AliHLTUInt32_t offset,
103                   vector<AliHLTComponentBlockData>& outputBlocks,
104                   AliHLTDataDeflater* pDeflater,
105                   const char* option="") const;
106
107   int WriteSorted(AliHLTUInt8_t* outputPtr, AliHLTUInt32_t size, AliHLTUInt32_t offset,
108                   AliHLTTPCHWCFData* pDecoder, AliHLTSpacePointPropertyGrid* pGrid,
109                   AliHLTUInt32_t mask,
110                   vector<AliHLTComponentBlockData>&  outputBlocks,
111                   AliHLTDataDeflater* pDeflater,
112                   const char* option) const;
113
114   /// allocate index grid, one single point to define the dimensions
115   static AliHLTSpacePointPropertyGrid* AllocateIndexGrid();
116
117   class AliHLTTPCHWCFSpacePointProperties {
118   public:
119     AliHLTTPCHWCFSpacePointProperties();
120     AliHLTTPCHWCFSpacePointProperties(const AliHLTTPCHWCFData* pDecoder, int index);
121     AliHLTTPCHWCFSpacePointProperties(const AliHLTTPCHWCFSpacePointProperties& src);
122     AliHLTTPCHWCFSpacePointProperties& operator=(const AliHLTTPCHWCFSpacePointProperties& src);
123
124     ~AliHLTTPCHWCFSpacePointProperties() {}
125
126     const AliHLTTPCHWCFData* Decoder() const {return fDecoder;}
127     int GetSpacepointIndex() const {return fIndex;}
128     bool IsUsed() const {return fUsed;}
129     void MarkUsed(bool used=true) {fUsed=used;}
130     int GetTrackId() const {return fTrackId;}
131     void SetTrackId(int trackId) {fTrackId=trackId;}
132     int GetMCId() const {return fMCId;}
133     void SetMCId(int mcId) {fMCId=mcId;}
134
135     void Print(ostream& out, Option_t *option="") const;
136
137   private:
138     const AliHLTTPCHWCFData* fDecoder; //! decoder for data block
139     int fIndex; //! index within the decoder block
140     bool fUsed; //! transient
141     int fTrackId; //! track id from reconstruction
142     int fMCId; //! MC id
143   };
144
145   class AliHLTTPCHWCFSpacePointBlock {
146   public:
147     AliHLTTPCHWCFSpacePointBlock(AliHLTUInt32_t id=0, AliHLTTPCHWCFData* pDecoder=NULL, AliHLTSpacePointPropertyGrid* pGrid=NULL)
148       : fDecoder(pDecoder), fGrid(pGrid), fId(id) {}
149     AliHLTTPCHWCFSpacePointBlock(const AliHLTTPCHWCFSpacePointBlock& s) 
150       : fDecoder(s.fDecoder), fGrid(s.fGrid), fId(s.fId) {}
151     AliHLTTPCHWCFSpacePointBlock& operator=(const AliHLTTPCHWCFSpacePointBlock& s) 
152     { fDecoder=s.fDecoder; fGrid=s.fGrid; fId=s.fId; return *this;}
153     ~AliHLTTPCHWCFSpacePointBlock() {}
154
155     int GetNofSpacepoints() const {return fDecoder?fDecoder->GetNumberOfClusters():0;}
156     AliHLTUInt32_t GetId() const {return fId;}
157     void SetId(AliHLTUInt32_t id) {fId=id;}
158     AliHLTTPCHWCFData* GetDecoder() const {return fDecoder;} 
159     void SetDecoder(AliHLTTPCHWCFData* pDecoder) {fDecoder=pDecoder;}
160     AliHLTSpacePointPropertyGrid* GetGrid() const {return fGrid;}
161     void SetGrid(AliHLTSpacePointPropertyGrid* pGrid) {fGrid=pGrid;}
162
163   protected:
164   private:
165     AliHLTTPCHWCFData* fDecoder; //!
166     AliHLTSpacePointPropertyGrid* fGrid; //!
167     AliHLTUInt32_t fId; //!
168   };
169
170  protected:
171
172  private:
173   /// map of clusters
174   std::map<AliHLTUInt32_t, AliHLTTPCHWCFSpacePointProperties> fClusters; //!
175
176   /// map of cluster id collection for different masks
177   std::map<AliHLTUInt32_t, vector<AliHLTUInt32_t>*> fSelections; //!
178
179   /// array of decoders
180   std::map<AliHLTUInt32_t, AliHLTTPCHWCFSpacePointBlock> fBlocks; //!
181
182   /// the one instance for mode single (=1)
183   AliHLTTPCHWCFSpacePointBlock fSingleBlock;
184
185   /// mode
186   int fMode; //!
187
188   /// vector of cluster ids for writing
189   vector<AliHLTUInt32_t>* fWrittenClusterIds; //!
190
191   ClassDef(AliHLTTPCHWCFSpacePointContainer, 0)
192 };
193
194 ostream& operator<<(ostream &out, const AliHLTTPCHWCFSpacePointContainer::AliHLTTPCHWCFSpacePointProperties& p);
195
196 #endif