]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/AliHLTTPCHWCFData.h
Updated responsibles for HLT FXS
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCHWCFData.h
CommitLineData
3aa4d287 1// $Id$
2#ifndef ALIHLTTPCHWCFDATA_H
3#define ALIHLTTPCHWCFDATA_H
4//* This file is property of and copyright by the ALICE HLT Project *
5//* ALICE Experiment at CERN, All rights reserved. *
6//* See cxx source for full Copyright notice *
7
8/// @file AliHLTTPCHWCFData.h
9/// @author Matthias Richter
10/// @date 2011-08-04
11/// @brief Decoder methods for the HWCF format
12///
13
14#include "AliHLTTPCRootTypes.h"
15#include "AliHLTDataTypes.h"
16#include "AliHLTLogging.h"
17
18class TArrayC;
19
20/**
21 * @class AliHLTTPCHWCFData
22 * The class provides decoding functionality for the output format of the
23 * TPC HW ClusterFinder
24 *
25 * Two formats have been defined in the past and can be detected:
26 * version 0: 5 32bit words 20 Byte
27 * <pre>
28 * word 0: header (big endian 32bit unsigned)
29 * bit 31-30: 0x11 indicates cluster
30 * bit 29-24: row number in partition
31 * bit 23-0: Qtot, fixed point number with 6 bits after the point
32 * word 1: pad (float)
33 * word 2: time (float)
34 * word 3: pad variance (float)
35 * word 4: time variance (float)
36 * </pre>
37 *
38 * version 1: 6 32bit words 24 Byte
39 * <pre>
40 * word 0: header (big endian 32bit unsigned)
41 * bit 31-30: 0x11 indicates cluster
42 * bit 29-24: row number in partition
43 * bit 23-0: Qmax, fixed point number with 6 bits after the point
44 * word 1: total charge 32bit big endian, fixed point number with 12 bits after the point
45 * word 2: pad (float)
46 * word 3: time (float)
47 * word 4: pad variance (float)
48 * word 5: time variance (float)
49 * </pre>
50 */
51class AliHLTTPCHWCFData : public AliHLTLogging {
52 public:
53 AliHLTTPCHWCFData(int forceVersion=-1);
54 virtual ~AliHLTTPCHWCFData();
55
56 int Init(const AliHLTUInt8_t* pBuffer, int bufferSize);
57 int Reset();
58
59 Int_t GetNumberOfClusters() const;
60
61 Int_t GetPadRow(int i) const;
62 Float_t GetPad(int i) const;
63 Float_t GetTime(int i) const;
64 Float_t GetSigmaY2(int i) const;
65 Float_t GetSigmaZ2(int i) const;
66 Int_t GetCharge(int i) const;
67 Int_t GetQMax(int i) const;
68
69 int CheckVersion();
70 bool CheckAssumption(int format, const AliHLTUInt8_t* pData, int size) const;
71 bool CheckBounds(int i) const;
72 int GetElementSize(int format) const;
73
74 // pointer to RCU trailer
75 const AliHLTUInt8_t* GetRCUTrailer() const
76 {
77 if (fRCUTrailerSize<=0 || fpBuffer==NULL || fBufferSize<fRCUTrailerSize) return NULL;
78 return fpBuffer+fRCUTrailerSize;
79 }
80
81 // size of RCU trailer
82 int GetRCUTrailerSize() const { return fRCUTrailerSize; }
83
84 // print info
85 void Print(const char* option);
86
87 // open a file and init
88 int Open(const char* filename);
89
90 enum {
91 kHWCFDataV0 = 0,
92 kHWCFDataV1 = 1,
93 };
94
95 struct AliHLTTPCHWClusterV0 {
96 AliHLTUInt32_t fHeader;
97 Float_t fPad;
98 Float_t fTime;
99 Float_t fSigmaY2;
100 Float_t fSigmaZ2;
101
102 Int_t GetPadRow() const;
103 Float_t GetPad() const {return fPad;}
104 Float_t GetTime() const {return fTime;}
105 Float_t GetSigmaY2() const {return fSigmaY2;}
106 Float_t GetSigmaZ2() const {return fSigmaZ2;}
107 Int_t GetCharge() const;
108 Int_t GetQMax() const {return -1;}
109 };
110
111 struct AliHLTTPCHWClusterV1 {
112 AliHLTUInt32_t fHeader;
113 AliHLTUInt32_t fCharge;
114 Float_t fPad;
115 Float_t fTime;
116 Float_t fSigmaY2;
117 Float_t fSigmaZ2;
118
119 Int_t GetPadRow() const;
120 Float_t GetPad() const {return fPad;}
121 Float_t GetTime() const {return fTime;}
122 Float_t GetSigmaY2() const {return fSigmaY2;}
123 Float_t GetSigmaZ2() const {return fSigmaZ2;}
124 Int_t GetCharge() const;
125 Int_t GetQMax() const;
126 };
127
128 template<typename T>
129 class AliHLTTPCHWClusterDecoder {
130 public:
131 AliHLTTPCHWClusterDecoder(const T* pClusterArray, int entries);
132 ~AliHLTTPCHWClusterDecoder();
133
134 // i'th element, no bounds check for performance reasons
135 const T& operator[](unsigned i) {
136 return fpClusterArray[i];
137 }
138
139 Int_t GetPadRow(int i) const {return fpClusterArray[i]->GetPadRow();}
140 Float_t GetPad(int i) const {return fpClusterArray[i]->GetPad();}
141 Float_t GetTime(int i) const {return fpClusterArray[i]->GetTime();}
142 Float_t GetSigmaY2(int i) const {return fpClusterArray[i]->GetSigmaY2();}
143 Float_t GetSigmaZ2(int i) const {return fpClusterArray[i]->GetSigmaZ2();}
144 Int_t GetCharge(int i) const {return fpClusterArray[i]->GetCharge();}
145 Int_t GetQMax(int i) const {return fpClusterArray[i]->GetQMax();}
146
147 private:
148 const T* fpClusterArray; //! array of clusters
149 int fEntries; //! number of entries
150 };
151
536e7d6d 152 class iterator {
153 public:
154 iterator()
155 : fData(NULL), fVersion(-1), fElementSize(0) {}
156 iterator(const AliHLTUInt8_t* pData, int version, int elementSize)
157 : fData(pData), fVersion(version), fElementSize(elementSize) {}
158 iterator(const iterator& i)
159 : fData(i.fData), fVersion(i.fVersion), fElementSize(i.fElementSize) {}
160 iterator& operator=(const iterator& i)
161 { fData=i.fData; fVersion=i.fVersion; fElementSize=i.fElementSize; return *this;}
162 ~iterator() {}
163
164 bool operator==(const iterator& i) const {return (fData!=NULL) && (fData==i.fData);}
165 bool operator!=(const iterator& i) const {return (fData!=NULL) && (fData!=i.fData);}
166 // prefix operators
167 iterator& operator++() {fData+=fElementSize; return *this;}
168 iterator& operator--() {fData-=fElementSize; return *this;}
169 // postfix operators
170 iterator operator++(int) {iterator i(*this); fData+=fElementSize; return i;}
171 iterator operator--(int) {iterator i(*this); fData-=fElementSize; return i;}
172
173 iterator& operator+=(int step) {fData+=step*fElementSize; return *this;}
174
175 Int_t GetPadRow() const {
176 switch (fVersion) {
177 case 0: return reinterpret_cast<const AliHLTTPCHWClusterV0*>(fData)->GetPadRow();
178 case 1: return reinterpret_cast<const AliHLTTPCHWClusterV1*>(fData)->GetPadRow();
179 } return -1;
180 }
181 Float_t GetPad() const {
182 switch (fVersion) {
183 case 0: return reinterpret_cast<const AliHLTTPCHWClusterV0*>(fData)->GetPad();
184 case 1: return reinterpret_cast<const AliHLTTPCHWClusterV1*>(fData)->GetPad();
185 } return -10000.;
186 }
187 Float_t GetTime() const {
188 switch (fVersion) {
189 case 0: return reinterpret_cast<const AliHLTTPCHWClusterV0*>(fData)->GetTime();
190 case 1: return reinterpret_cast<const AliHLTTPCHWClusterV1*>(fData)->GetTime();
191 } return -10000.;
192 }
193 Float_t GetSigmaY2() const {
194 switch (fVersion) {
195 case 0: return reinterpret_cast<const AliHLTTPCHWClusterV0*>(fData)->GetSigmaY2();
196 case 1: return reinterpret_cast<const AliHLTTPCHWClusterV1*>(fData)->GetSigmaY2();
197 } return -10000.;
198 }
199 Float_t GetSigmaZ2() const {
200 switch (fVersion) {
201 case 0: return reinterpret_cast<const AliHLTTPCHWClusterV0*>(fData)->GetSigmaZ2();
202 case 1: return reinterpret_cast<const AliHLTTPCHWClusterV1*>(fData)->GetSigmaZ2();
203 } return -10000.;
204 }
205 Int_t GetCharge() const {
206 switch (fVersion) {
207 case 0: return reinterpret_cast<const AliHLTTPCHWClusterV0*>(fData)->GetCharge();
208 case 1: return reinterpret_cast<const AliHLTTPCHWClusterV1*>(fData)->GetCharge();
209 } return -1;
210 }
211 Int_t GetQMax() const {
212 switch (fVersion) {
213 case 0: return reinterpret_cast<const AliHLTTPCHWClusterV0*>(fData)->GetQMax();
214 case 1: return reinterpret_cast<const AliHLTTPCHWClusterV1*>(fData)->GetQMax();
215 } return -1;
216 }
217
218 protected:
219 private:
220 const AliHLTUInt8_t* fData; //! data
221 int fVersion; //! format version
222 int fElementSize; //! element size
223 };
224
225 // prepare iterator and end marker
226 iterator& begin() {
227 fIterator.~iterator();
228 new (&fIterator) iterator(fpBuffer, fVersion, GetElementSize(fVersion));
229 fIteratorEnd=fIterator;
230 fIteratorEnd+=GetNumberOfClusters();
231 return fIterator;
232 }
233
234 // get loop end marker
235 iterator& end() {
236 return fIteratorEnd;
237 }
238
3aa4d287 239 static const unsigned fgkAliHLTTPCHWClusterSize;
240 protected:
241
242 private:
243 AliHLTTPCHWCFData(const AliHLTTPCHWCFData&);
244 AliHLTTPCHWCFData& operator=(const AliHLTTPCHWCFData&);
245
246 // get pointer to i'th element
247 const AliHLTUInt8_t* Get(int i) const
248 {
249 if (!fpBuffer) return NULL;
250 int elementsize=GetElementSize(fVersion);
251 if (elementsize<0) return NULL;
252 return fpBuffer+(i*elementsize);
253 }
254
255
256 const AliHLTUInt8_t* fpBuffer; //! pointer to data buffer
257 int fBufferSize; //! size of data buffer
258
259 int fVersion; //! format version
260 int fForcedVersion; //! forced format version
261 int fRCUTrailerSize; //! size of the RCU trailer in Byte
262
263 TArrayC* fpFileBuffer; //! internal buffer for file content
264
536e7d6d 265 iterator fIterator; //! iterator
266 iterator fIteratorEnd; //! end iterator
267
3aa4d287 268 ClassDef(AliHLTTPCHWCFData, 0)
269};
270#endif