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 *
9 /// @file AliHLTTPCHWCFData.h
10 /// @author Matthias Richter
12 /// @brief Decoder methods for the HWCF format
15 #include "AliHLTTPCRootTypes.h"
16 #include "AliHLTDataTypes.h"
17 #include "AliHLTLogging.h"
18 #include "AliHLTErrorGuard.h"
23 * @class AliHLTTPCHWCFData
24 * The class provides decoding functionality for the output format of the
25 * TPC HW ClusterFinder
27 * Two formats have been defined in the past and can be detected:
28 * version 0: 5 32bit words 20 Byte
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
35 * word 2: time (float)
36 * word 3: pad variance (float)
37 * word 4: time variance (float)
40 * version 1: 6 32bit words 24 Byte
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
48 * word 3: time (float)
49 * word 4: pad variance (float)
50 * word 5: time variance (float)
53 class AliHLTTPCHWCFData : public AliHLTLogging {
55 AliHLTTPCHWCFData(int forceVersion=-1);
56 virtual ~AliHLTTPCHWCFData();
58 int Init(const AliHLTUInt8_t* pBuffer, int bufferSize);
61 Int_t GetNumberOfClusters() const;
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;
72 bool CheckAssumption(int format, const AliHLTUInt8_t* pData, int size) const;
74 // check if index is within bounds
75 bool CheckBounds(int i) const {
77 ALIHLTERRORGUARD(1, "");
80 int elementsize=GetElementSize(fVersion);
81 if (elementsize<0) return false;
82 return ((i+1)*elementsize+fRCUTrailerSize<=fBufferSize);
85 // get the size of one element
86 int GetElementSize(int version) const {
88 case 0: return sizeof(AliHLTTPCHWClusterV0);
89 case 1: return sizeof(AliHLTTPCHWClusterV1);
91 ALIHLTERRORGUARD(1, "invalid format version %d", fVersion);
96 // pointer to RCU trailer
97 const AliHLTUInt8_t* GetRCUTrailer() const
99 if (fRCUTrailerSize<=0 || fpBuffer==NULL || fBufferSize<fRCUTrailerSize) return NULL;
100 return fpBuffer+(fBufferSize-fRCUTrailerSize);
103 // size of RCU trailer
104 int GetRCUTrailerSize() const { return fRCUTrailerSize; }
107 void Print(const char* option);
109 // open a file and init
110 int Open(const char* filename);
117 struct AliHLTTPCHWClusterV0 {
118 AliHLTUInt32_t fHeader;
124 Int_t GetPadRow() const;
125 Float_t GetPad() const {return fPad+0.5;}
126 Float_t GetTime() const {return fTime;}
127 Float_t GetSigmaY2() const {
128 Float_t sy2 = fSigmaY2 - fPad*fPad;
129 return (sy2>0) ?sy2 :0.;
131 Float_t GetSigmaZ2() const {
132 Float_t sz2 = fSigmaZ2 - fTime*fTime;
133 return (sz2>0) ?sz2 :0.;
135 Int_t GetCharge() const;
136 Int_t GetQMax() const {return -1;}
139 struct AliHLTTPCHWClusterV1 {
140 AliHLTUInt32_t fHeader;
141 AliHLTUInt32_t fCharge;
147 Int_t GetPadRow() const;
148 Float_t GetPad() const {return fPad+0.5;}
149 Float_t GetTime() const {return fTime;}
150 Float_t GetSigmaY2() const {
151 Float_t sy2 = fSigmaY2 - fPad*fPad;
152 return (sy2>0) ?sy2 :0.;
154 Float_t GetSigmaZ2() const {
155 Float_t sz2 = fSigmaZ2 - fTime*fTime;
156 return (sz2>0) ?sz2 :0.;
158 Int_t GetCharge() const;
159 Int_t GetQMax() const;
163 class AliHLTTPCHWClusterDecoder {
165 AliHLTTPCHWClusterDecoder(const T* pClusterArray, int entries);
166 ~AliHLTTPCHWClusterDecoder();
168 // i'th element, no bounds check for performance reasons
169 const T& operator[](unsigned i) {
170 return fpClusterArray[i];
173 Int_t GetPadRow(int i) const {return fpClusterArray[i]->GetPadRow();}
174 Float_t GetPad(int i) const {return fpClusterArray[i]->GetPad();}
175 Float_t GetTime(int i) const {return fpClusterArray[i]->GetTime();}
176 Float_t GetSigmaY2(int i) const {return fpClusterArray[i]->GetSigmaY2();}
177 Float_t GetSigmaZ2(int i) const {return fpClusterArray[i]->GetSigmaZ2();}
178 Int_t GetCharge(int i) const {return fpClusterArray[i]->GetCharge();}
179 Int_t GetQMax(int i) const {return fpClusterArray[i]->GetQMax();}
182 const T* fpClusterArray; //! array of clusters
183 int fEntries; //! number of entries
189 : fData(NULL), fVersion(-1), fElementSize(0) {}
190 iterator(const AliHLTUInt8_t* pData, int version, int elementSize)
191 : fData(pData), fVersion(version), fElementSize(elementSize) {}
192 iterator(const iterator& i)
193 : fData(i.fData), fVersion(i.fVersion), fElementSize(i.fElementSize) {}
194 iterator& operator=(const iterator& i)
195 { fData=i.fData; fVersion=i.fVersion; fElementSize=i.fElementSize; return *this;}
196 ~iterator() {fData=NULL;}
198 bool operator==(const iterator& i) const {return (fData!=NULL) && (fData==i.fData);}
199 bool operator!=(const iterator& i) const {return (fData!=NULL) && (fData!=i.fData);}
201 iterator& operator++() {fData+=fElementSize; return *this;}
202 iterator& operator--() {fData-=fElementSize; return *this;}
204 iterator operator++(int) {iterator i(*this); fData+=fElementSize; return i;}
205 iterator operator--(int) {iterator i(*this); fData-=fElementSize; return i;}
207 iterator& operator+=(int step) {fData+=step*fElementSize; return *this;}
209 Int_t GetPadRow() const {
211 case 0: return reinterpret_cast<const AliHLTTPCHWClusterV0*>(fData)->GetPadRow();
212 case 1: return reinterpret_cast<const AliHLTTPCHWClusterV1*>(fData)->GetPadRow();
215 Float_t GetPad() const {
217 case 0: return reinterpret_cast<const AliHLTTPCHWClusterV0*>(fData)->GetPad();
218 case 1: return reinterpret_cast<const AliHLTTPCHWClusterV1*>(fData)->GetPad();
221 Float_t GetTime() const {
223 case 0: return reinterpret_cast<const AliHLTTPCHWClusterV0*>(fData)->GetTime();
224 case 1: return reinterpret_cast<const AliHLTTPCHWClusterV1*>(fData)->GetTime();
227 Float_t GetSigmaY2() const {
229 case 0: return reinterpret_cast<const AliHLTTPCHWClusterV0*>(fData)->GetSigmaY2();
230 case 1: return reinterpret_cast<const AliHLTTPCHWClusterV1*>(fData)->GetSigmaY2();
233 Float_t GetSigmaZ2() const {
235 case 0: return reinterpret_cast<const AliHLTTPCHWClusterV0*>(fData)->GetSigmaZ2();
236 case 1: return reinterpret_cast<const AliHLTTPCHWClusterV1*>(fData)->GetSigmaZ2();
239 Int_t GetCharge() const {
241 case 0: return reinterpret_cast<const AliHLTTPCHWClusterV0*>(fData)->GetCharge();
242 case 1: return reinterpret_cast<const AliHLTTPCHWClusterV1*>(fData)->GetCharge();
245 Int_t GetQMax() const {
247 case 0: return reinterpret_cast<const AliHLTTPCHWClusterV0*>(fData)->GetQMax();
248 case 1: return reinterpret_cast<const AliHLTTPCHWClusterV1*>(fData)->GetQMax();
254 const AliHLTUInt8_t* fData; //! data
255 int fVersion; //! format version
256 int fElementSize; //! element size
259 // prepare iterator and end marker
261 fIterator.~iterator();
262 new (&fIterator) iterator(fpBuffer, fVersion, GetElementSize(fVersion));
263 fIteratorEnd=fIterator;
264 fIteratorEnd+=GetNumberOfClusters();
268 // get loop end marker
273 // find one single element
274 iterator& find(int i) {
275 fIterator.~iterator();
276 fIteratorEnd.~iterator();
277 if (i>=GetNumberOfClusters()) return fIterator;
278 new (&fIterator) iterator(fpBuffer, fVersion, GetElementSize(fVersion));
280 fIteratorEnd=fIterator;
285 static const unsigned fgkAliHLTTPCHWClusterSize;
289 AliHLTTPCHWCFData(const AliHLTTPCHWCFData&);
290 AliHLTTPCHWCFData& operator=(const AliHLTTPCHWCFData&);
292 // get pointer to i'th element
293 const AliHLTUInt8_t* Get(int i) const
295 if (!fpBuffer) return NULL;
296 int elementsize=GetElementSize(fVersion);
297 if (elementsize<0) return NULL;
298 return fpBuffer+(i*elementsize);
302 const AliHLTUInt8_t* fpBuffer; //! pointer to data buffer
303 int fBufferSize; //! size of data buffer
305 int fVersion; //! format version
306 int fForcedVersion; //! forced format version
307 int fRCUTrailerSize; //! size of the RCU trailer in Byte
309 TArrayC* fpFileBuffer; //! internal buffer for file content
311 iterator fIterator; //! iterator
312 iterator fIteratorEnd; //! end iterator
314 ClassDef(AliHLTTPCHWCFData, 0)