Line data Source code
1 : // $Id$
2 : //**************************************************************************
3 : //* This file is property of and copyright by the *
4 : //* ALICE Experiment at CERN, All rights reserved. *
5 : //* *
6 : //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 : //* *
8 : //* Permission to use, copy, modify and distribute this software and its *
9 : //* documentation strictly for non-commercial purposes is hereby granted *
10 : //* without fee, provided that the above copyright notice appears in all *
11 : //* copies and that both the copyright notice and this permission notice *
12 : //* appear in the supporting documentation. The authors make no claims *
13 : //* about the suitability of this software for any purpose. It is *
14 : //* provided "as is" without express or implied warranty. *
15 : //**************************************************************************
16 :
17 : /// @file AliHLTTPCDataCompressionDecoder.cxx
18 : /// @author Matthias Richter
19 : /// @date 2011-10-04
20 : /// @brief Generic decoder class for compressed TPC data, works on a container
21 : /// class implementation which fills the actual target data struct
22 :
23 : #include "AliHLTTPCDataCompressionDecoder.h"
24 : #include "AliHLTTPCDataCompressionDescriptor.h"
25 : #include "AliHLTTPCRawClustersDescriptor.h"
26 : #include "AliHLTDataInflaterSimple.h"
27 : #include "AliHLTDataInflaterHuffman.h"
28 : #include "TList.h"
29 : #include <memory>
30 :
31 6 : ClassImp(AliHLTTPCDataCompressionDecoder)
32 :
33 0 : AliHLTTPCDataCompressionDecoder::AliHLTTPCDataCompressionDecoder()
34 0 : : fPadShift(0.)
35 0 : , fVerbosity(0)
36 0 : , fUseClusterMerger(kTRUE)
37 0 : , fExtractGlobalPadrow(kTRUE)
38 0 : , fpDataInflaterPartition(NULL)
39 0 : , fpDataInflaterTrack(NULL)
40 0 : , fpClusterMerger(NULL)
41 0 : , fPartitionClusterIds()
42 0 : , fPartitionClusterFlags()
43 0 : , fTrackModelClusterIds()
44 0 : , fCurrentClusterIds(NULL)
45 0 : , fCurrentClusterFlags(NULL)
46 0 : , fDecodeFlagsTmpFlag(0)
47 0 : , fDecodeFlagsTmpPos(0)
48 0 : , fDecodeFlagsTmpEntries(0)
49 0 : , fClusterMCData()
50 0 : {
51 : /// constructor
52 0 : }
53 :
54 : AliHLTTPCDataCompressionDecoder::~AliHLTTPCDataCompressionDecoder()
55 0 : {
56 : ///destructor
57 0 : if (fpDataInflaterPartition) delete fpDataInflaterPartition;
58 0 : fpDataInflaterPartition=NULL;
59 0 : if (fpDataInflaterTrack) delete fpDataInflaterTrack;
60 0 : fpDataInflaterTrack=NULL;
61 0 : if (fpClusterMerger) delete fpClusterMerger;
62 0 : fpClusterMerger=NULL;
63 0 : }
64 :
65 : AliHLTDataInflater* AliHLTTPCDataCompressionDecoder::CreateInflater(int deflater, int mode) const
66 : {
67 : // create the inflater for the specified mode
68 0 : vector<AliHLTTPCDefinitions::AliClusterParameterId_t> parameterids;
69 0 : switch (mode) {
70 : case 1:
71 0 : parameterids.push_back(AliHLTTPCDefinitions::kPadRow );
72 0 : parameterids.push_back(AliHLTTPCDefinitions::kPad );
73 0 : parameterids.push_back(AliHLTTPCDefinitions::kTime );
74 0 : parameterids.push_back(AliHLTTPCDefinitions::kSigmaY2);
75 0 : parameterids.push_back(AliHLTTPCDefinitions::kSigmaZ2);
76 0 : parameterids.push_back(AliHLTTPCDefinitions::kCharge );
77 0 : parameterids.push_back(AliHLTTPCDefinitions::kQMax );
78 : break;
79 : case 2:
80 0 : parameterids.push_back(AliHLTTPCDefinitions::kResidualPad );
81 0 : parameterids.push_back(AliHLTTPCDefinitions::kResidualTime);
82 0 : parameterids.push_back(AliHLTTPCDefinitions::kSigmaY2);
83 0 : parameterids.push_back(AliHLTTPCDefinitions::kSigmaZ2);
84 0 : parameterids.push_back(AliHLTTPCDefinitions::kCharge );
85 0 : parameterids.push_back(AliHLTTPCDefinitions::kQMax );
86 : break;
87 : default:
88 0 : HLTError("invalid mode %d for inflater initialization", mode);
89 : }
90 :
91 0 : switch (deflater) {
92 : case 1:
93 : {
94 0 : std::auto_ptr<AliHLTDataInflaterSimple> inflatersimple(new AliHLTDataInflaterSimple);
95 0 : if (!inflatersimple.get()) return NULL;
96 0 : for (vector<AliHLTTPCDefinitions::AliClusterParameterId_t>::const_iterator id=parameterids.begin();
97 0 : id!=parameterids.end(); id++) {
98 0 : const AliHLTTPCDefinitions::AliClusterParameter& parameter=AliHLTTPCDefinitions::fgkClusterParameterDefinitions[*id];
99 0 : if (inflatersimple->AddParameterDefinition(parameter.fName,
100 0 : parameter.fBitLength,
101 0 : parameter.fOptional)<0) {
102 0 : HLTError("error adding parameter definition %s to inflater", parameter.fName);
103 0 : return NULL;
104 : }
105 0 : }
106 0 : return inflatersimple.release();
107 0 : }
108 : break;
109 : case 2:
110 : {
111 0 : std::auto_ptr<AliHLTDataInflaterHuffman> inflaterhuffman(new AliHLTDataInflaterHuffman);
112 0 : if (!inflaterhuffman.get()) return NULL;
113 0 : TString cdbPath("HLT/ConfigTPC/TPCDataCompressorHuffmanTables");
114 0 : TObject* pConf=AliHLTMisc::Instance().ExtractObject(AliHLTMisc::Instance().LoadOCDBEntry(cdbPath));
115 0 : if (!pConf) {
116 0 : HLTError("can not load configuration object %s", cdbPath.Data());
117 0 : return NULL;
118 : }
119 0 : if (dynamic_cast<TList*>(pConf)==NULL) {
120 0 : HLTError("huffman table configuration object of inconsistent type");
121 0 : return NULL;
122 : }
123 0 : inflaterhuffman->InitDecoders(dynamic_cast<TList*>(pConf));
124 0 : for (vector<AliHLTTPCDefinitions::AliClusterParameterId_t>::const_iterator id=parameterids.begin();
125 0 : id!=parameterids.end(); id++) {
126 0 : const AliHLTTPCDefinitions::AliClusterParameter& parameter=AliHLTTPCDefinitions::fgkClusterParameterDefinitions[*id];
127 0 : if (inflaterhuffman->AddParameterDefinition(parameter.fName,
128 0 : parameter.fBitLength)<0) {
129 0 : HLTError("error adding parameter definition %s to inflater", parameter.fName);
130 0 : return NULL;
131 : }
132 0 : }
133 0 : return inflaterhuffman.release();
134 0 : }
135 : break;
136 : default:
137 0 : HLTError("unknown inflater requested %d", deflater);
138 : }
139 0 : return NULL;
140 0 : }
141 :
142 : int AliHLTTPCDataCompressionDecoder::InitPartitionClusterDecoding(AliHLTUInt32_t specification)
143 : {
144 : /// init the decoding of partition cluster block
145 0 : AliHLTUInt8_t slice=AliHLTTPCDefinitions::GetMinSliceNr(specification);
146 0 : AliHLTUInt8_t partition=AliHLTTPCDefinitions::GetMinPatchNr(specification);
147 0 : unsigned index=slice*AliHLTTPCGeometry::GetNumberOfPatches()+partition;
148 0 : if (index<fPartitionClusterIds.size())
149 0 : fCurrentClusterIds=&fPartitionClusterIds[index];
150 : else
151 0 : fCurrentClusterIds=NULL;
152 :
153 0 : if (index<fPartitionClusterFlags.size())
154 0 : fCurrentClusterFlags=fPartitionClusterFlags[index];
155 : else
156 0 : fCurrentClusterFlags=NULL;
157 :
158 0 : fDecodeFlagsTmpFlag=0;
159 0 : fDecodeFlagsTmpPos=0;
160 0 : fDecodeFlagsTmpEntries=0;
161 :
162 0 : return 0;
163 : }
164 :
165 : int AliHLTTPCDataCompressionDecoder::InitTrackModelClusterClusterDecoding()
166 : {
167 : /// init the decoding of track model cluster block
168 0 : if (fTrackModelClusterIds.fIds && fTrackModelClusterIds.fSize>0)
169 0 : fCurrentClusterIds=&fTrackModelClusterIds;
170 : else
171 0 : fCurrentClusterIds=NULL;
172 :
173 0 : fCurrentClusterFlags=NULL;
174 0 : fDecodeFlagsTmpFlag=0;
175 0 : fDecodeFlagsTmpPos=0;
176 0 : fDecodeFlagsTmpEntries=0;
177 0 : return 0;
178 : }
179 :
180 : int AliHLTTPCDataCompressionDecoder::AddCompressionDescriptor(const AliHLTComponentBlockData* pDesc)
181 : {
182 : /// read descriptor
183 0 : if (!pDesc) return -EINVAL;
184 0 : if (pDesc->fDataType!=AliHLTTPCDefinitions::DataCompressionDescriptorDataType()) return -ENODATA;
185 0 : const AliHLTTPCDataCompressionDescriptor* pHeader=reinterpret_cast<const AliHLTTPCDataCompressionDescriptor*>(pDesc->fPtr);
186 0 : if (! pHeader->CheckSize( pDesc->fSize ) ) return -EINVAL;
187 0 : if( pHeader->GetMergedClustersFlag() == 0 ){
188 0 : fUseClusterMerger = kTRUE;
189 0 : } else if( pHeader->GetMergedClustersFlag() == 1 ){
190 0 : fUseClusterMerger = kFALSE;
191 0 : } else return -EINVAL;
192 0 : return 0;
193 0 : }
194 :
195 : int AliHLTTPCDataCompressionDecoder::AddRawClustersDescriptor(const AliHLTComponentBlockData* pDesc)
196 : {
197 : /// read descriptor
198 0 : if (!pDesc) return -EINVAL;
199 0 : if (pDesc->fDataType!=AliHLTTPCDefinitions::RawClustersDescriptorDataType()) return -ENODATA;
200 0 : const AliHLTTPCRawClustersDescriptor* pHeader=reinterpret_cast<const AliHLTTPCRawClustersDescriptor*>(pDesc->fPtr);
201 0 : if (! pHeader->CheckSize( pDesc->fSize ) ) return -EINVAL;
202 0 : if( pHeader->GetMergedClustersFlag() == 0 ){
203 0 : fUseClusterMerger = kTRUE;
204 0 : } else if( pHeader->GetMergedClustersFlag() == 1 ){
205 0 : fUseClusterMerger = kFALSE;
206 0 : } else return -EINVAL;
207 0 : return 0;
208 0 : }
209 :
210 : int AliHLTTPCDataCompressionDecoder::AddClusterMCData(const AliHLTComponentBlockData* pDesc)
211 : {
212 : /// add cluster mc data block
213 0 : if (!pDesc) return -EINVAL;
214 0 : if (pDesc->fDataType==AliHLTTPCDefinitions::AliHLTDataTypeClusterMCInfo()) {
215 0 : AliHLTUInt8_t slice=AliHLTTPCDefinitions::GetMinSliceNr(pDesc->fSpecification);
216 0 : AliHLTUInt8_t partition=AliHLTTPCDefinitions::GetMinPatchNr(pDesc->fSpecification);
217 0 : unsigned index=slice*AliHLTTPCGeometry::GetNumberOfPatches()+partition;
218 0 : if (fClusterMCData.size()<=index) {
219 0 : if ((int)fClusterMCData.size()<AliHLTTPCGeometry::GetNSlice()*AliHLTTPCGeometry::GetNumberOfPatches()) {
220 0 : fClusterMCData.resize(AliHLTTPCGeometry::GetNSlice()*AliHLTTPCGeometry::GetNumberOfPatches(), NULL);
221 0 : } else {
222 0 : fClusterMCData.resize(index+1, NULL);
223 : }
224 : }
225 0 : if (pDesc->fSize<sizeof(AliHLTTPCClusterMCData)) return -EINVAL;
226 0 : const AliHLTTPCClusterMCData* pData=reinterpret_cast<const AliHLTTPCClusterMCData*>(pDesc->fPtr);
227 0 : unsigned nLabels = pData->fCount;
228 0 : if (nLabels*sizeof(AliHLTTPCClusterMCLabel) + sizeof(AliHLTTPCClusterMCData) != pDesc->fSize) {
229 0 : return -EINVAL;
230 : }
231 0 : fClusterMCData[index]=pData;
232 0 : return 0;
233 : }
234 0 : return -ENODATA;
235 0 : }
236 :
237 : int AliHLTTPCDataCompressionDecoder::AddClusterIds(const AliHLTComponentBlockData* pDesc)
238 : {
239 : /// add cluster id block for partition or track model clusters
240 0 : if (!pDesc) return -EINVAL;
241 0 : if (pDesc->fDataType==AliHLTTPCDefinitions::ClusterIdTracksDataType()) {
242 0 : fTrackModelClusterIds.fIds=reinterpret_cast<AliHLTUInt32_t*>(pDesc->fPtr);
243 0 : fTrackModelClusterIds.fSize=pDesc->fSize/sizeof(AliHLTUInt32_t);
244 0 : return 0;
245 : }
246 0 : if (pDesc->fDataType==AliHLTTPCDefinitions::RemainingClusterIdsDataType()) {
247 0 : AliHLTUInt8_t slice=AliHLTTPCDefinitions::GetMinSliceNr(pDesc->fSpecification);
248 0 : AliHLTUInt8_t partition=AliHLTTPCDefinitions::GetMinPatchNr(pDesc->fSpecification);
249 0 : unsigned index=slice*AliHLTTPCGeometry::GetNumberOfPatches()+partition;
250 0 : if (fPartitionClusterIds.size()<=index) {
251 0 : if ((int)fPartitionClusterIds.size()<AliHLTTPCGeometry::GetNSlice()*AliHLTTPCGeometry::GetNumberOfPatches()) {
252 0 : fPartitionClusterIds.resize(AliHLTTPCGeometry::GetNSlice()*AliHLTTPCGeometry::GetNumberOfPatches());
253 0 : } else {
254 0 : fPartitionClusterIds.resize(index+1);
255 : }
256 : }
257 0 : fPartitionClusterIds[index].fIds=reinterpret_cast<AliHLTUInt32_t*>(pDesc->fPtr);
258 0 : fPartitionClusterIds[index].fSize=pDesc->fSize/sizeof(AliHLTUInt32_t);
259 : return 0;
260 : }
261 0 : return -ENODATA;
262 0 : }
263 :
264 : int AliHLTTPCDataCompressionDecoder::AddClusterFlags(const AliHLTComponentBlockData* pDesc)
265 : {
266 : /// add cluster flag block for partition or track model clusters
267 0 : if (!pDesc) return -EINVAL;
268 0 : if (pDesc->fDataType==AliHLTTPCDefinitions::ClustersFlagsDataType()) {
269 0 : AliHLTUInt8_t slice=AliHLTTPCDefinitions::GetMinSliceNr(pDesc->fSpecification);
270 0 : AliHLTUInt8_t partition=AliHLTTPCDefinitions::GetMinPatchNr(pDesc->fSpecification);
271 0 : unsigned index=slice*AliHLTTPCGeometry::GetNumberOfPatches()+partition;
272 0 : if (fPartitionClusterFlags.size()<=index) {
273 0 : if ((int)fPartitionClusterFlags.size()<AliHLTTPCGeometry::GetNSlice()*AliHLTTPCGeometry::GetNumberOfPatches()) {
274 0 : fPartitionClusterFlags.resize(AliHLTTPCGeometry::GetNSlice()*AliHLTTPCGeometry::GetNumberOfPatches());
275 0 : } else {
276 0 : fPartitionClusterFlags.resize(index+1);
277 : }
278 : }
279 0 : fPartitionClusterFlags[index]=reinterpret_cast<AliHLTTPCClusterFlagsData*>(pDesc->fPtr);
280 : return 0;
281 : }
282 0 : return -ENODATA;
283 0 : }
284 :
285 : AliHLTUInt32_t AliHLTTPCDataCompressionDecoder::GetClusterId(int clusterNo) const
286 : {
287 : /// get the cluster id from the current cluster id block
288 : /// clusters ids correctly link the MC label from the separate MC data block
289 : /// to the cluster. The option is enabled by default in the simulation.
290 0 : if (!fCurrentClusterIds ||
291 0 : (int)fCurrentClusterIds->fSize<=clusterNo ||
292 0 : clusterNo<0)
293 0 : return kAliHLTVoidDataSpec;
294 0 : return fCurrentClusterIds->fIds[clusterNo];
295 0 : }
296 :
297 : unsigned short AliHLTTPCDataCompressionDecoder::GetNextClusterFlag()
298 : {
299 0 : if (!fCurrentClusterFlags) return(0); //No data block with flags present
300 0 : if (fCurrentClusterFlags->fVersion == 0) return(0); //Shipping of cluster flags was disabled during reconstruction
301 0 : if (fCurrentClusterFlags->fVersion >= 2)
302 : {
303 0 : HLTError("Invalid version for compression of cluster flags. Version in the Data: %d, maximum version supported by this AliRoot Version: %d", fCurrentClusterFlags->fVersion, 2);
304 0 : return(0);
305 : }
306 0 : if (fCurrentClusterFlags->fVersion == 1)
307 : {
308 0 : if (fDecodeFlagsTmpPos == 0) fDecodeFlagsTmpFlag = ((unsigned int*) fCurrentClusterFlags->fData)[fDecodeFlagsTmpEntries++];
309 0 : unsigned short retVal = (fDecodeFlagsTmpFlag >> fDecodeFlagsTmpPos) & ((1 << fCurrentClusterFlags->fNumberOfFlags) - 1);
310 0 : fDecodeFlagsTmpPos += fCurrentClusterFlags->fNumberOfFlags;
311 0 : if (fDecodeFlagsTmpPos >= sizeof(fDecodeFlagsTmpFlag) * 8)
312 : {
313 0 : fDecodeFlagsTmpPos -= sizeof(fDecodeFlagsTmpFlag) * 8;
314 0 : if (fDecodeFlagsTmpPos)
315 : {
316 0 : fDecodeFlagsTmpFlag = ((unsigned int*) fCurrentClusterFlags->fData)[fDecodeFlagsTmpEntries++];
317 0 : retVal |= (fDecodeFlagsTmpFlag << (fCurrentClusterFlags->fNumberOfFlags - fDecodeFlagsTmpPos))& ((1 << fCurrentClusterFlags->fNumberOfFlags) - 1);
318 0 : }
319 : }
320 : return(retVal);
321 : }
322 0 : HLTFatal("Internal Error"); //We should never reach this code
323 0 : return(0);
324 0 : }
325 :
326 : const AliHLTTPCClusterMCLabel* AliHLTTPCDataCompressionDecoder::GetMCLabel(AliHLTUInt32_t clusterId) const
327 : {
328 : /// get MC data for a cluster Id
329 : /// MC data is sent in a separate data block to keep the raw compressed
330 : /// format free from any overhead
331 0 : if (clusterId==kAliHLTVoidDataSpec) return NULL;
332 :
333 0 : unsigned slice=AliHLTTPCSpacePointData::GetSlice(clusterId);
334 0 : unsigned partition=AliHLTTPCSpacePointData::GetPatch(clusterId);
335 0 : unsigned number=AliHLTTPCSpacePointData::GetNumber(clusterId);
336 0 : if ((int)slice>=AliHLTTPCGeometry::GetNSlice() ||
337 0 : (int)partition>=AliHLTTPCGeometry::GetNumberOfPatches()) return NULL;
338 0 : unsigned index=slice*AliHLTTPCGeometry::GetNumberOfPatches()+partition;
339 0 : if (fClusterMCData.size()<=index ||
340 0 : fClusterMCData[index]==NULL ||
341 0 : fClusterMCData[index]->fCount<=number) return NULL;
342 :
343 0 : return &(fClusterMCData[index]->fLabels[number]);
344 0 : }
345 :
346 : void AliHLTTPCDataCompressionDecoder::Clear(const char* option)
347 : {
348 : /// cleanup, tabula rase for next event
349 0 : if (fpDataInflaterPartition) fpDataInflaterPartition->Clear(option);
350 0 : if (fpDataInflaterTrack) fpDataInflaterTrack->Clear(option);
351 0 : if (fpClusterMerger) fpClusterMerger->Clear();
352 0 : fCurrentClusterIds=NULL;
353 0 : fCurrentClusterFlags=NULL;
354 0 : fDecodeFlagsTmpFlag=0;
355 0 : fDecodeFlagsTmpPos=0;
356 0 : fDecodeFlagsTmpEntries=0;
357 0 : fPartitionClusterIds.clear();
358 0 : fPartitionClusterFlags.clear();
359 0 : fTrackModelClusterIds.Clear();
360 0 : fClusterMCData.clear();
361 0 : fUseClusterMerger = kTRUE;
362 0 : }
|