2 //**************************************************************************
3 //* This file is property of and copyright by the *
4 //* ALICE Experiment at CERN, All rights reserved. *
6 //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
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 //**************************************************************************
17 /// @file AliHLTTPCDataCompressionDecoder.cxx
18 /// @author Matthias Richter
20 /// @brief Generic decoder class for compressed TPC data, works on a container
21 /// class implementation which fills the actual target data struct
23 #include "AliHLTTPCDataCompressionDecoder.h"
24 #include "AliHLTTPCDataCompressionDescriptor.h"
25 #include "AliHLTDataInflaterSimple.h"
26 #include "AliHLTDataInflaterHuffman.h"
30 ClassImp(AliHLTTPCDataCompressionDecoder)
32 AliHLTTPCDataCompressionDecoder::AliHLTTPCDataCompressionDecoder()
35 , fUseClusterMerger(kTRUE)
36 , fpDataInflaterPartition(NULL)
37 , fpDataInflaterTrack(NULL)
38 , fpClusterMerger(NULL)
39 , fPartitionClusterIds()
40 , fTrackModelClusterIds()
41 , fCurrentClusterIds(NULL)
47 AliHLTTPCDataCompressionDecoder::~AliHLTTPCDataCompressionDecoder()
50 if (fpDataInflaterPartition) delete fpDataInflaterPartition;
51 fpDataInflaterPartition=NULL;
52 if (fpDataInflaterTrack) delete fpDataInflaterTrack;
53 fpDataInflaterTrack=NULL;
54 if (fpClusterMerger) delete fpClusterMerger;
58 AliHLTDataInflater* AliHLTTPCDataCompressionDecoder::CreateInflater(int deflater, int mode) const
60 // create the inflater for the specified mode
61 vector<AliHLTTPCDefinitions::AliClusterParameterId_t> parameterids;
64 parameterids.push_back(AliHLTTPCDefinitions::kPadRow );
65 parameterids.push_back(AliHLTTPCDefinitions::kPad );
66 parameterids.push_back(AliHLTTPCDefinitions::kTime );
67 parameterids.push_back(AliHLTTPCDefinitions::kSigmaY2);
68 parameterids.push_back(AliHLTTPCDefinitions::kSigmaZ2);
69 parameterids.push_back(AliHLTTPCDefinitions::kCharge );
70 parameterids.push_back(AliHLTTPCDefinitions::kQMax );
73 parameterids.push_back(AliHLTTPCDefinitions::kResidualPad );
74 parameterids.push_back(AliHLTTPCDefinitions::kResidualTime);
75 parameterids.push_back(AliHLTTPCDefinitions::kSigmaY2);
76 parameterids.push_back(AliHLTTPCDefinitions::kSigmaZ2);
77 parameterids.push_back(AliHLTTPCDefinitions::kCharge );
78 parameterids.push_back(AliHLTTPCDefinitions::kQMax );
81 HLTError("invalid mode %d for inflater initialization", mode);
87 std::auto_ptr<AliHLTDataInflaterSimple> inflatersimple(new AliHLTDataInflaterSimple);
88 if (!inflatersimple.get()) return NULL;
89 for (vector<AliHLTTPCDefinitions::AliClusterParameterId_t>::const_iterator id=parameterids.begin();
90 id!=parameterids.end(); id++) {
91 const AliHLTTPCDefinitions::AliClusterParameter& parameter=AliHLTTPCDefinitions::fgkClusterParameterDefinitions[*id];
92 if (inflatersimple->AddParameterDefinition(parameter.fName,
94 parameter.fOptional)<0) {
95 HLTError("error adding parameter definition %s to inflater", parameter.fName);
99 return inflatersimple.release();
104 std::auto_ptr<AliHLTDataInflaterHuffman> inflaterhuffman(new AliHLTDataInflaterHuffman);
105 if (!inflaterhuffman.get()) return NULL;
106 TString cdbPath("HLT/ConfigTPC/TPCDataCompressorHuffmanTables");
107 TObject* pConf=AliHLTMisc::Instance().ExtractObject(AliHLTMisc::Instance().LoadOCDBEntry(cdbPath));
109 HLTError("can not load configuration object %s", cdbPath.Data());
112 if (dynamic_cast<TList*>(pConf)==NULL) {
113 HLTError("huffman table configuration object of inconsistent type");
116 inflaterhuffman->InitDecoders(dynamic_cast<TList*>(pConf));
117 for (vector<AliHLTTPCDefinitions::AliClusterParameterId_t>::const_iterator id=parameterids.begin();
118 id!=parameterids.end(); id++) {
119 const AliHLTTPCDefinitions::AliClusterParameter& parameter=AliHLTTPCDefinitions::fgkClusterParameterDefinitions[*id];
120 if (inflaterhuffman->AddParameterDefinition(parameter.fName,
121 parameter.fBitLength)<0) {
122 HLTError("error adding parameter definition %s to inflater", parameter.fName);
126 return inflaterhuffman.release();
130 HLTError("unknown inflater requested %d", deflater);
135 int AliHLTTPCDataCompressionDecoder::InitPartitionClusterDecoding(AliHLTUInt32_t specification)
137 /// init the decoding of partition cluster block
138 AliHLTUInt8_t slice=AliHLTTPCDefinitions::GetMinSliceNr(specification);
139 AliHLTUInt8_t partition=AliHLTTPCDefinitions::GetMinPatchNr(specification);
140 unsigned index=slice*AliHLTTPCTransform::GetNumberOfPatches()+partition;
141 if (index<fPartitionClusterIds.size())
142 fCurrentClusterIds=&fPartitionClusterIds[index];
144 fCurrentClusterIds=NULL;
148 int AliHLTTPCDataCompressionDecoder::InitTrackModelClusterClusterDecoding()
150 /// init the decoding of track model cluster block
151 if (fTrackModelClusterIds.fIds && fTrackModelClusterIds.fSize>0)
152 fCurrentClusterIds=&fTrackModelClusterIds;
154 fCurrentClusterIds=NULL;
158 int AliHLTTPCDataCompressionDecoder::AddCompressionDescriptor(const AliHLTComponentBlockData* pDesc)
161 if (!pDesc) return -EINVAL;
162 if (pDesc->fDataType!=AliHLTTPCDefinitions::DataCompressionDescriptorDataType()) return -ENODATA;
163 const AliHLTTPCDataCompressionDescriptor* pHeader=reinterpret_cast<const AliHLTTPCDataCompressionDescriptor*>(pDesc->fPtr);
164 if (! pHeader->CheckSize( pDesc->fSize ) ) return -EINVAL;
165 if( pHeader->GetMergedClustersFlag() == 0 ){
166 fUseClusterMerger = kTRUE;
167 } else if( pHeader->GetMergedClustersFlag() == 1 ){
168 fUseClusterMerger = kFALSE;
169 } else return -EINVAL;
173 int AliHLTTPCDataCompressionDecoder::AddClusterMCData(const AliHLTComponentBlockData* pDesc)
175 /// add cluster mc data block
176 if (!pDesc) return -EINVAL;
177 if (pDesc->fDataType==AliHLTTPCDefinitions::AliHLTDataTypeClusterMCInfo()) {
178 AliHLTUInt8_t slice=AliHLTTPCDefinitions::GetMinSliceNr(pDesc->fSpecification);
179 AliHLTUInt8_t partition=AliHLTTPCDefinitions::GetMinPatchNr(pDesc->fSpecification);
180 unsigned index=slice*AliHLTTPCTransform::GetNumberOfPatches()+partition;
181 if (fClusterMCData.size()<=index) {
182 if ((int)fClusterMCData.size()<AliHLTTPCTransform::GetNSlice()*AliHLTTPCTransform::GetNumberOfPatches()) {
183 fClusterMCData.resize(AliHLTTPCTransform::GetNSlice()*AliHLTTPCTransform::GetNumberOfPatches(), NULL);
185 fClusterMCData.resize(index+1, NULL);
188 if (pDesc->fSize<sizeof(AliHLTTPCClusterMCData)) return -EINVAL;
189 const AliHLTTPCClusterMCData* pData=reinterpret_cast<const AliHLTTPCClusterMCData*>(pDesc->fPtr);
190 unsigned nLabels = pData->fCount;
191 if (nLabels*sizeof(AliHLTTPCClusterMCLabel) + sizeof(AliHLTTPCClusterMCData) != pDesc->fSize) {
194 fClusterMCData[index]=pData;
200 int AliHLTTPCDataCompressionDecoder::AddClusterIds(const AliHLTComponentBlockData* pDesc)
202 /// add cluster id block for partition or track model clusters
203 if (!pDesc) return -EINVAL;
204 if (pDesc->fDataType==AliHLTTPCDefinitions::ClusterIdTracksDataType()) {
205 fTrackModelClusterIds.fIds=reinterpret_cast<AliHLTUInt32_t*>(pDesc->fPtr);
206 fTrackModelClusterIds.fSize=pDesc->fSize/sizeof(AliHLTUInt32_t);
209 if (pDesc->fDataType==AliHLTTPCDefinitions::RemainingClusterIdsDataType()) {
210 AliHLTUInt8_t slice=AliHLTTPCDefinitions::GetMinSliceNr(pDesc->fSpecification);
211 AliHLTUInt8_t partition=AliHLTTPCDefinitions::GetMinPatchNr(pDesc->fSpecification);
212 unsigned index=slice*AliHLTTPCTransform::GetNumberOfPatches()+partition;
213 if (fPartitionClusterIds.size()<=index) {
214 if ((int)fPartitionClusterIds.size()<AliHLTTPCTransform::GetNSlice()*AliHLTTPCTransform::GetNumberOfPatches()) {
215 fPartitionClusterIds.resize(AliHLTTPCTransform::GetNSlice()*AliHLTTPCTransform::GetNumberOfPatches());
217 fPartitionClusterIds.resize(index+1);
220 fPartitionClusterIds[index].fIds=reinterpret_cast<AliHLTUInt32_t*>(pDesc->fPtr);
221 fPartitionClusterIds[index].fSize=pDesc->fSize/sizeof(AliHLTUInt32_t);
227 AliHLTUInt32_t AliHLTTPCDataCompressionDecoder::GetClusterId(int clusterNo) const
229 /// get the cluster id from the current cluster id block
230 /// clusters ids correctly link the MC label from the separate MC data block
231 /// to the cluster. The option is enabled by default in the simulation.
232 if (!fCurrentClusterIds ||
233 (int)fCurrentClusterIds->fSize<=clusterNo ||
235 return kAliHLTVoidDataSpec;
236 return fCurrentClusterIds->fIds[clusterNo];
239 const AliHLTTPCClusterMCLabel* AliHLTTPCDataCompressionDecoder::GetMCLabel(AliHLTUInt32_t clusterId) const
241 /// get MC data for a cluster Id
242 /// MC data is sent in a separate data block to keep the raw compressed
243 /// format free from any overhead
244 if (clusterId==kAliHLTVoidDataSpec) return NULL;
246 unsigned slice=AliHLTTPCSpacePointData::GetSlice(clusterId);
247 unsigned partition=AliHLTTPCSpacePointData::GetPatch(clusterId);
248 unsigned number=AliHLTTPCSpacePointData::GetNumber(clusterId);
249 if ((int)slice>=AliHLTTPCTransform::GetNSlice() ||
250 (int)partition>=AliHLTTPCTransform::GetNumberOfPatches()) return NULL;
251 unsigned index=slice*AliHLTTPCTransform::GetNumberOfPatches()+partition;
252 if (fClusterMCData.size()<=index ||
253 fClusterMCData[index]==NULL ||
254 fClusterMCData[index]->fCount<=number) return NULL;
256 return &(fClusterMCData[index]->fLabels[number]);
259 void AliHLTTPCDataCompressionDecoder::Clear(const char* option)
261 /// cleanup, tabula rase for next event
262 if (fpDataInflaterPartition) fpDataInflaterPartition->Clear(option);
263 if (fpDataInflaterTrack) fpDataInflaterTrack->Clear(option);
264 if (fpClusterMerger) fpClusterMerger->Clear();
265 fCurrentClusterIds=NULL;
266 fPartitionClusterIds.clear();
267 fTrackModelClusterIds.Clear();
268 fClusterMCData.clear();
269 fUseClusterMerger = kTRUE;