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