From: richterm Date: Tue, 4 Oct 2011 10:16:06 +0000 (+0000) Subject: moving decoding of compressed TPC data to generic class X-Git-Url: http://git.uio.no/git/?a=commitdiff_plain;h=f899e06036b532ae9b0c3e089c0e1fc9fe2aa7aa;p=u%2Fmrichter%2FAliRoot.git moving decoding of compressed TPC data to generic class --- diff --git a/HLT/CMakelibAliHLTTPC.pkg b/HLT/CMakelibAliHLTTPC.pkg index bcb3c501b11..83fc0186863 100644 --- a/HLT/CMakelibAliHLTTPC.pkg +++ b/HLT/CMakelibAliHLTTPC.pkg @@ -125,6 +125,7 @@ set ( CLASS_HDRS comp/AliHLTTPCCompModelInflaterComponent.h comp/AliHLTTPCDataCompressionComponent.h comp/AliHLTTPCDataCompressionMonitorComponent.h + comp/AliHLTTPCDataCompressionDecoder.h AliHLTTPCClusterHistoComponent.h AliHLTTPCTrackHistoComponent.h AliHLTTPCTrackDumpComponent.h diff --git a/HLT/TPCLib/comp/AliHLTTPCDataCompressionDecoder.cxx b/HLT/TPCLib/comp/AliHLTTPCDataCompressionDecoder.cxx new file mode 100644 index 00000000000..7bd80107630 --- /dev/null +++ b/HLT/TPCLib/comp/AliHLTTPCDataCompressionDecoder.cxx @@ -0,0 +1,117 @@ +// $Id$ +//************************************************************************** +//* This file is property of and copyright by the ALICE HLT Project * +//* ALICE Experiment at CERN, All rights reserved. * +//* * +//* Primary Authors: Matthias Richter * +//* for The ALICE HLT Project. * +//* * +//* Permission to use, copy, modify and distribute this software and its * +//* documentation strictly for non-commercial purposes is hereby granted * +//* without fee, provided that the above copyright notice appears in all * +//* copies and that both the copyright notice and this permission notice * +//* appear in the supporting documentation. The authors make no claims * +//* about the suitability of this software for any purpose. It is * +//* provided "as is" without express or implied warranty. * +//************************************************************************** + +/// @file AliHLTTPCDataCompressionDecoder.cxx +/// @author Matthias Richter +/// @date 2011-10-04 +/// @brief Generic decoder class for compressed TPC data, works on a container +/// class implementation which fills the actual target data struct + +#include "AliHLTTPCDataCompressionDecoder.h" +#include "AliHLTDataInflaterSimple.h" +#include "AliHLTDataInflaterHuffman.h" +#include "TList.h" +#include + +ClassImp(AliHLTTPCDataCompressionDecoder) + +AliHLTTPCDataCompressionDecoder::AliHLTTPCDataCompressionDecoder() +{ + /// constructor +} + +AliHLTTPCDataCompressionDecoder::~AliHLTTPCDataCompressionDecoder() +{ + ///destructor +} + +AliHLTDataInflater* AliHLTTPCDataCompressionDecoder::CreateInflater(int deflater, int mode) const +{ + // create the inflater for the specified mode + vector parameterids; + switch (mode) { + case 1: + parameterids.push_back(AliHLTTPCDefinitions::kPadRow ); + parameterids.push_back(AliHLTTPCDefinitions::kPad ); + parameterids.push_back(AliHLTTPCDefinitions::kTime ); + parameterids.push_back(AliHLTTPCDefinitions::kSigmaY2); + parameterids.push_back(AliHLTTPCDefinitions::kSigmaZ2); + parameterids.push_back(AliHLTTPCDefinitions::kCharge ); + parameterids.push_back(AliHLTTPCDefinitions::kQMax ); + break; + case 2: + parameterids.push_back(AliHLTTPCDefinitions::kResidualPad ); + parameterids.push_back(AliHLTTPCDefinitions::kResidualTime); + parameterids.push_back(AliHLTTPCDefinitions::kSigmaY2); + parameterids.push_back(AliHLTTPCDefinitions::kSigmaZ2); + parameterids.push_back(AliHLTTPCDefinitions::kCharge ); + parameterids.push_back(AliHLTTPCDefinitions::kQMax ); + break; + default: + HLTError("invalid mode %d for inflater initialization", mode); + } + + switch (deflater) { + case 1: + { + std::auto_ptr inflatersimple(new AliHLTDataInflaterSimple); + if (!inflatersimple.get()) return NULL; + for (vector::const_iterator id=parameterids.begin(); + id!=parameterids.end(); id++) { + const AliHLTTPCDefinitions::AliClusterParameter& parameter=AliHLTTPCDefinitions::fgkClusterParameterDefinitions[*id]; + if (inflatersimple->AddParameterDefinition(parameter.fName, + parameter.fBitLength, + parameter.fOptional)<0) { + HLTError("error adding parameter definition %s to inflater", parameter.fName); + return NULL; + } + } + return inflatersimple.release(); + } + break; + case 2: + { + std::auto_ptr inflaterhuffman(new AliHLTDataInflaterHuffman); + if (!inflaterhuffman.get()) return NULL; + TString cdbPath("HLT/ConfigTPC/TPCDataCompressorHuffmanTables"); + TObject* pConf=AliHLTMisc::Instance().ExtractObject(AliHLTMisc::Instance().LoadOCDBEntry(cdbPath)); + if (!pConf) { + HLTError("can not load configuration object %s", cdbPath.Data()); + return NULL; + } + if (dynamic_cast(pConf)==NULL) { + HLTError("huffman table configuration object of inconsistent type"); + return NULL; + } + inflaterhuffman->InitDecoders(dynamic_cast(pConf)); + for (vector::const_iterator id=parameterids.begin(); + id!=parameterids.end(); id++) { + const AliHLTTPCDefinitions::AliClusterParameter& parameter=AliHLTTPCDefinitions::fgkClusterParameterDefinitions[*id]; + if (inflaterhuffman->AddParameterDefinition(parameter.fName, + parameter.fBitLength)<0) { + HLTError("error adding parameter definition %s to inflater", parameter.fName); + return NULL; + } + } + return inflaterhuffman.release(); + } + break; + default: + HLTError("unknown inflater requested %d", deflater); + } + return NULL; +} diff --git a/HLT/TPCLib/comp/AliHLTTPCDataCompressionDecoder.h b/HLT/TPCLib/comp/AliHLTTPCDataCompressionDecoder.h new file mode 100644 index 00000000000..f54cf462243 --- /dev/null +++ b/HLT/TPCLib/comp/AliHLTTPCDataCompressionDecoder.h @@ -0,0 +1,356 @@ +//-*- Mode: C++ -*- +// $Id$ +#ifndef ALIHLTTPCDATACOMPRESSIONDECODER_H +#define ALIHLTTPCDATACOMPRESSIONDECODER_H +//* This file is property of and copyright by the ALICE HLT Project * +//* ALICE Experiment at CERN, All rights reserved. * +//* See cxx source for full Copyright notice * + +/// @file AliHLTTPCDataCompressionDecoder.h +/// @author Matthias Richter +/// @date 2011-10-04 +/// @brief Generic decoder class for compressed TPC data, works on a container +/// class implementation which fills the actual target data struct + +#include "AliHLTLogging.h" +#include "AliHLTMisc.h" +#include "AliHLTTPCDataCompressionComponent.h" +#include "AliHLTTPCDefinitions.h" +#include "AliHLTTPCClusterDataFormat.h" +#include "AliHLTTPCRawCluster.h" +#include "AliHLTTPCTransform.h" +#include "AliHLTTPCTrackGeometry.h" +#include "AliHLTDataInflater.h" + +/** + * @class AliHLTTPCDataCompressionDecoder + * Generic decoder class for compressed TPC data, works on a container + * class implementation which fills the actual target data struct + */ +class AliHLTTPCDataCompressionDecoder : public AliHLTLogging { + public: + AliHLTTPCDataCompressionDecoder(); + ~AliHLTTPCDataCompressionDecoder(); + + template + int ReadRemainingClustersCompressed(T& c, const AliHLTUInt8_t* pData, int dataSize, AliHLTUInt32_t specification); + + template + int ReadRemainingClustersCompressed(T& c, AliHLTDataInflater* pInflater, int nofClusters, AliHLTUInt32_t specification); + + template + int ReadTrackModelClustersCompressed(T& c, const AliHLTUInt8_t* pData, int dataSize, AliHLTUInt32_t specification); + + template + int ReadTrackClustersCompressed(T& c, AliHLTDataInflater* pInflater, AliHLTTPCTrackGeometry* pTrackPoints); + + AliHLTDataInflater* CreateInflater(int deflater, int mode) const; + + protected: + private: + ClassDef(AliHLTTPCDataCompressionDecoder, 0) +}; + +template +int AliHLTTPCDataCompressionDecoder::ReadRemainingClustersCompressed(T& c, const AliHLTUInt8_t* pData, int dataSize, AliHLTUInt32_t specification) +{ + // read cluster data from AliHLTTPCClusterData + int iResult=0; + if (!pData || dataSize<4) return -EINVAL; + + const AliHLTUInt8_t* pBuffer=pData; + AliHLTUInt32_t size=dataSize; + const AliHLTTPCRawClusterData* clusterData = reinterpret_cast(pBuffer); + Int_t nCount = (Int_t) clusterData->fCount; + + AliHLTDataInflater* inflater=CreateInflater(clusterData->fVersion, 1); + if (!inflater) return -ENODEV; + + if ((iResult=inflater->InitBitDataInput(reinterpret_cast(clusterData->fClusters), + size-sizeof(AliHLTTPCRawClusterData)))<0) { + return iResult; + } + + iResult=ReadRemainingClustersCompressed(c, inflater, nCount, specification); + + return iResult; +} + +template +int AliHLTTPCDataCompressionDecoder::ReadRemainingClustersCompressed(T& c, AliHLTDataInflater* pInflater, int nofClusters, AliHLTUInt32_t specification) +{ + // read cluster data + + int iResult=0; + if (!pInflater) return -EINVAL; + + AliHLTUInt8_t slice = AliHLTTPCDefinitions::GetMinSliceNr(specification); + AliHLTUInt8_t partition = AliHLTTPCDefinitions::GetMinPatchNr(specification); + // the compressed format stores the difference of the local row number in + // the partition to the row of the last cluster + // add the first row in the partition to get global row number + // offline uses row number in physical sector, inner sector consists of + // partitions 0 and 1, outer sector of partition 2-5 + int rowOffset=AliHLTTPCTransform::GetFirstRow(partition);//-(partition<2?0:AliHLTTPCTransform::GetFirstRow(2)); + + int parameterId=0; + int outClusterCnt=0; + AliHLTUInt64_t value=0; + AliHLTUInt32_t length=0; + AliHLTUInt32_t lastPadRow=0; + while (outClusterCntNextValue(value, length)) { + const AliHLTTPCDefinitions::AliClusterParameter& parameter + =AliHLTTPCDefinitions::fgkClusterParameterDefinitions[parameterId]; + + if (parameter.fBitLength!=(int)length) { + HLTError("decode error: expecting length %d for parameter %s, but got %d", + parameter.fBitLength, parameter.fName, length); + break; + } + + switch (parameterId) { + case AliHLTTPCDefinitions::kPadRow: + {c.SetPadRow(value+lastPadRow+rowOffset); lastPadRow+=value;break;} + case AliHLTTPCDefinitions::kPad: + {float pad=value; pad/=parameter.fScale; c.SetPad(pad); break;} + case AliHLTTPCDefinitions::kTime: + {float time=value; time/=parameter.fScale; c.SetTime(time); break;} + case AliHLTTPCDefinitions::kSigmaY2: + {float sigmaY2=value; sigmaY2/=parameter.fScale; c.SetSigmaY2(sigmaY2); break;} + case AliHLTTPCDefinitions::kSigmaZ2: + {float sigmaZ2=value; sigmaZ2/=parameter.fScale; c.SetSigmaZ2(sigmaZ2); break;} + case AliHLTTPCDefinitions::kCharge: + {c.SetCharge(value); break;} + case AliHLTTPCDefinitions::kQMax: + {c.SetQMax(value); break;} + } + if (parameterId>=AliHLTTPCDefinitions::kLast) { + // switch to next cluster + c.Next(slice, partition); + outClusterCnt++; + parameterId=-1; + } + parameterId++; + } + pInflater->Pad8Bits(); + AliHLTUInt8_t bit=0; + if (pInflater->InputBit(bit)) { + HLTWarning("format error of compressed clusters, there is more data than expected"); + } + pInflater->CloseBitDataInput(); + if (iResult>=0 && nofClusters!=outClusterCnt) { + // is this a Fatal? + HLTError("error reading compressed cluster format of block 0x%08x: expected %d, read only %d cluster(s)", specification, nofClusters, outClusterCnt); + return -EPROTO; + } + return iResult; +} + +template +int AliHLTTPCDataCompressionDecoder::ReadTrackModelClustersCompressed(T& c, const AliHLTUInt8_t* pData, int dataSize, AliHLTUInt32_t /*specification*/) +{ + // read cluster data from the track model data block + int iResult=0; + int dataOffset=sizeof(AliHLTTPCDataCompressionComponent::AliHLTTPCTrackModelBlock); + if (!pData || dataSize(pData); + if (trackModelBlock->fVersion!=1) { + HLTError("unknown version %d", trackModelBlock->fVersion); + return -EINVAL; + } + std::auto_ptr pInflater(CreateInflater(trackModelBlock->fDeflaterMode, 2)); + if (!pInflater.get()) { + HLTError("failed to create the data inflater for mode %d", trackModelBlock->fDeflaterMode); + } + int nofTracks=trackModelBlock->fTrackCount; + dataOffset+=trackModelBlock->fGlobalParameterCnt*sizeof(trackModelBlock->fGlobalParameters); + if (dataSizefGlobalParameterCnt); + return -ENOSPC; + } + float bz=0.0; + float driftTimeFactorA=0.; + float driftTimeOffsetA=0.; + float driftTimeFactorC=0.; + float driftTimeOffsetC=0.; + + AliHLTUInt32_t parameterIndex=0; + switch (trackModelBlock->fGlobalParameterCnt) { + case 5: + bz =trackModelBlock->fGlobalParameters[parameterIndex++]; + driftTimeFactorA=trackModelBlock->fGlobalParameters[parameterIndex++]; + driftTimeOffsetA=trackModelBlock->fGlobalParameters[parameterIndex++]; + driftTimeFactorC=trackModelBlock->fGlobalParameters[parameterIndex++]; + driftTimeOffsetC=trackModelBlock->fGlobalParameters[parameterIndex++]; + break; + default: + HLTError("unknown version of global parameters %d", trackModelBlock->fGlobalParameterCnt); + return -ENODATA; + } + + if (parameterIndex!=trackModelBlock->fGlobalParameterCnt) { + HLTError("internal error, size of parameter array has changed without providing all values"); + return -EFAULT; + } + + for (int trackno=0; tracknoInitBitDataInput(pData+dataOffset, clusterBlockSize))<0) { + return iResult; + } + if ((iResult=ReadTrackClustersCompressed(c, pInflater.get(), &trackpoints))<0) { + HLTError("reading of associated clusters failed for track %d", trackno); + return iResult; + } + pInflater->Pad8Bits(); + AliHLTUInt8_t bit=0; + if (pInflater->InputBit(bit)) { + HLTWarning("format error of compressed clusters, there is more data than expected"); + } + pInflater->CloseBitDataInput(); + dataOffset+=clusterBlockSize; + } + + return iResult; +} + +template +int AliHLTTPCDataCompressionDecoder::ReadTrackClustersCompressed(T& c, AliHLTDataInflater* pInflater, AliHLTTPCTrackGeometry* pTrackPoints) +{ + // read cluster data + + int iResult=0; + if (!pInflater || !pTrackPoints) return -EINVAL; + + const vector& rawTrackPoints=pTrackPoints->GetRawPoints(); + vector::const_iterator currentTrackPoint=rawTrackPoints.begin(); + + bool bReadSuccess=true; + AliHLTUInt32_t clusterCountBitLength=AliHLTTPCDefinitions::fgkClusterParameterDefinitions[AliHLTTPCDefinitions::kClusterCount].fBitLength; + //unsigned long dataPosition=pInflater->GetCurrentByteInputPosition(); + for (unsigned row=0; row<159 && bReadSuccess; row++) { + AliHLTUInt8_t haveClusters=0; + // 1 bit for clusters on that padrow + bReadSuccess=bReadSuccess && pInflater->InputBit(haveClusters); + if (!haveClusters) continue; + bool bEscape=false; + do { + if (currentTrackPoint==rawTrackPoints.end()) { + if (bEscape || rawTrackPoints.begin()==rawTrackPoints.end()) break; + currentTrackPoint=rawTrackPoints.begin(); + bEscape=true; + } + if (AliHLTTPCTransform::GetFirstRow(AliHLTTPCSpacePointData::GetPatch(currentTrackPoint->GetId())) + + AliHLTTPCSpacePointData::GetNumber(currentTrackPoint->GetId()) == row) { + break; + } + currentTrackPoint++; + } while (!bEscape); + if (currentTrackPoint==rawTrackPoints.end()) { + HLTError("decoding error, can not find track point on row %d", row); + return -EFAULT; + } + AliHLTUInt8_t slice = AliHLTTPCDefinitions::GetMinSliceNr(currentTrackPoint->GetId()); + AliHLTUInt8_t partition = AliHLTTPCDefinitions::GetMinPatchNr(currentTrackPoint->GetId()); + AliHLTUInt8_t nofClusters=0; + bReadSuccess=bReadSuccess && pInflater->InputBits(nofClusters, clusterCountBitLength); + if (!bReadSuccess) break; + + static const AliHLTTPCDefinitions::AliClusterParameterId_t kParameterIdMapping[] = { + AliHLTTPCDefinitions::kResidualPad, + AliHLTTPCDefinitions::kResidualTime, + AliHLTTPCDefinitions::kSigmaY2, + AliHLTTPCDefinitions::kSigmaZ2, + AliHLTTPCDefinitions::kCharge, + AliHLTTPCDefinitions::kQMax, + }; + + int parameterId=0; + int inClusterCnt=0; + AliHLTUInt64_t value=0; + AliHLTUInt32_t length=0; + while (bReadSuccess && inClusterCntNextValue(value, length)) { + const AliHLTTPCDefinitions::AliClusterParameter& parameter + =AliHLTTPCDefinitions::fgkClusterParameterDefinitions[kParameterIdMapping[parameterId]]; + + if (parameter.fBitLength!=(int)length) { + HLTError("decode error: expecting length %d for parameter %s, but got %d", + parameter.fBitLength, parameter.fName, length); + break; + } + + static float deltapad=0.; + static float deltatime=0.; + bool lastParameter=false; + switch (kParameterIdMapping[parameterId]) { + case AliHLTTPCDefinitions::kResidualPad: + { + AliHLTUInt8_t sign=0; + bReadSuccess=bReadSuccess && pInflater->InputBit(sign); + float pad=value*(sign?-1.:1.); pad/=parameter.fScale; + deltapad=pad; + pad+=currentTrackPoint->GetU(); + c.SetPad(pad); + break; + } + case AliHLTTPCDefinitions::kResidualTime: + { + AliHLTUInt8_t sign=0; + bReadSuccess=bReadSuccess && pInflater->InputBit(sign); + float time=value*(sign?-1.:1.); time/=parameter.fScale; + deltatime=time; + time+=currentTrackPoint->GetV(); + c.SetTime(time); + break; + } + case AliHLTTPCDefinitions::kSigmaY2: + {float sigmaY2=value; sigmaY2/=parameter.fScale; c.SetSigmaY2(sigmaY2); break;} + case AliHLTTPCDefinitions::kSigmaZ2: + {float sigmaZ2=value; sigmaZ2/=parameter.fScale; c.SetSigmaZ2(sigmaZ2); break;} + case AliHLTTPCDefinitions::kCharge: + {c.SetCharge(value); break;} + case AliHLTTPCDefinitions::kQMax: + {c.SetQMax(value); lastParameter=true; break;} + default: + { + HLTError("parameter %d not expected", kParameterIdMapping[parameterId]); + } + } + if (lastParameter) { + // switch to next cluster + c.SetPadRow(row); + // cout << " row " << setfill(' ') << setw(3) << fixed << right << c.GetRow() + // << " pad " << setfill(' ') << setw(7) << fixed << right << setprecision (4) << c.GetPad() + // << " dpad " << setfill(' ') << setw(7) << fixed << right << setprecision (4) << deltapad + // << " time " << setfill(' ') << setw(7) << fixed << right << setprecision (4) << c.GetTimeBin() + // << " dtime " << setfill(' ') << setw(7) << fixed << right << setprecision (4) << deltatime + // << " charge " << setfill(' ') << setw(5) << fixed << right << setprecision (0) << c.GetQ() + // << " qmax " << setfill(' ') << setw(4) << fixed << right << setprecision (0) << c.GetMax() + // << endl; + c.Next(slice, partition); + inClusterCnt++; + parameterId=-1; + } + parameterId++; + } + if (iResult>=0 && nofClusters!=inClusterCnt) { + // is this a Fatal? + HLTError("error reading track model compressed cluster format of track: expected %d, read only %d cluster(s)", nofClusters, inClusterCnt); + return -EPROTO; + } + currentTrackPoint++; + } + return iResult; +} +#endif diff --git a/HLT/TPCLib/comp/AliHLTTPCDataCompressionMonitorComponent.cxx b/HLT/TPCLib/comp/AliHLTTPCDataCompressionMonitorComponent.cxx index daf47c721c8..d00b11bb269 100644 --- a/HLT/TPCLib/comp/AliHLTTPCDataCompressionMonitorComponent.cxx +++ b/HLT/TPCLib/comp/AliHLTTPCDataCompressionMonitorComponent.cxx @@ -23,6 +23,7 @@ #include "AliHLTTPCDataCompressionMonitorComponent.h" #include "AliHLTTPCDataCompressionComponent.h" +#include "AliHLTTPCDataCompressionDecoder.h" #include "AliHLTTPCDefinitions.h" #include "AliHLTTPCHWCFData.h" #include "AliHLTTPCDefinitions.h" @@ -163,9 +164,11 @@ int AliHLTTPCDataCompressionMonitorComponent::DoEvent( const AliHLTComponentEven iResult=fMonitoringContainer->AddClusterIds(pDesc); } + // read data + AliHLTTPCDataCompressionDecoder decoder; for (pDesc=GetFirstInputBlock(AliHLTTPCDefinitions::RemainingClustersCompressedDataType()); pDesc!=NULL; pDesc=GetNextInputBlock()) { - iResult=ReadRemainingClustersCompressed(fMonitoringContainer->BeginRemainingClusterBlock(0, pDesc->fSpecification), + iResult=decoder.ReadRemainingClustersCompressed(fMonitoringContainer->BeginRemainingClusterBlock(0, pDesc->fSpecification), reinterpret_cast(pDesc->fPtr), pDesc->fSize, pDesc->fSpecification); @@ -173,7 +176,7 @@ int AliHLTTPCDataCompressionMonitorComponent::DoEvent( const AliHLTComponentEven for (pDesc=GetFirstInputBlock(AliHLTTPCDefinitions::ClusterTracksCompressedDataType()); pDesc!=NULL; pDesc=GetNextInputBlock()) { - iResult=ReadTrackModelClustersCompressed(fMonitoringContainer->BeginTrackModelClusterBlock(0), + iResult=decoder.ReadTrackModelClustersCompressed(fMonitoringContainer->BeginTrackModelClusterBlock(0), reinterpret_cast(pDesc->fPtr), pDesc->fSize, pDesc->fSpecification); @@ -325,379 +328,6 @@ int AliHLTTPCDataCompressionMonitorComponent::ScanConfigurationArgument(int argc return iResult; } -int AliHLTTPCDataCompressionMonitorComponent::ReadRemainingClustersCompressed(AliHLTTPCDataCompressionMonitorComponent::T& c, const AliHLTUInt8_t* pData, int dataSize, AliHLTUInt32_t specification) -{ - // read cluster data from AliHLTTPCClusterData - int iResult=0; - if (!pData || dataSize<4) return -EINVAL; - - const AliHLTUInt8_t* pBuffer=pData; - AliHLTUInt32_t size=dataSize; - const AliHLTTPCRawClusterData* clusterData = reinterpret_cast(pBuffer); - Int_t nCount = (Int_t) clusterData->fCount; - - AliHLTDataInflater* inflater=CreateInflater(clusterData->fVersion, 1); - if (!inflater) return -ENODEV; - - if ((iResult=inflater->InitBitDataInput(reinterpret_cast(clusterData->fClusters), - size-sizeof(AliHLTTPCRawClusterData)))<0) { - return iResult; - } - - iResult=ReadRemainingClustersCompressed(c, inflater, nCount, specification); - - return iResult; -} - -int AliHLTTPCDataCompressionMonitorComponent::ReadRemainingClustersCompressed(AliHLTTPCDataCompressionMonitorComponent::T& c, AliHLTDataInflater* pInflater, int nofClusters, AliHLTUInt32_t specification) -{ - // read cluster data - - int iResult=0; - if (!pInflater) return -EINVAL; - - AliHLTUInt8_t partition = AliHLTTPCDefinitions::GetMinPatchNr(specification); - // the compressed format stores the difference of the local row number in - // the partition to the row of the last cluster - // add the first row in the partition to get global row number - // offline uses row number in physical sector, inner sector consists of - // partitions 0 and 1, outer sector of partition 2-5 - int rowOffset=AliHLTTPCTransform::GetFirstRow(partition);//-(partition<2?0:AliHLTTPCTransform::GetFirstRow(2)); - - int parameterId=0; - int outClusterCnt=0; - AliHLTUInt64_t value=0; - AliHLTUInt32_t length=0; - AliHLTUInt32_t lastPadRow=0; - while (outClusterCntNextValue(value, length)) { - const AliHLTTPCDefinitions::AliClusterParameter& parameter - =AliHLTTPCDefinitions::fgkClusterParameterDefinitions[parameterId]; - - if (parameter.fBitLength!=(int)length) { - HLTError("decode error: expecting length %d for parameter %s, but got %d", - parameter.fBitLength, parameter.fName, length); - break; - } - - switch (parameterId) { - case AliHLTTPCDefinitions::kPadRow: - {c.SetPadRow(value+lastPadRow+rowOffset); lastPadRow+=value;break;} - case AliHLTTPCDefinitions::kPad: - {float pad=value; pad/=parameter.fScale; c.SetPad(pad); break;} - case AliHLTTPCDefinitions::kTime: - {float time=value; time/=parameter.fScale; c.SetTime(time); break;} - case AliHLTTPCDefinitions::kSigmaY2: - {float sigmaY2=value; sigmaY2/=parameter.fScale; c.SetSigmaY2(sigmaY2); break;} - case AliHLTTPCDefinitions::kSigmaZ2: - {float sigmaZ2=value; sigmaZ2/=parameter.fScale; c.SetSigmaZ2(sigmaZ2); break;} - case AliHLTTPCDefinitions::kCharge: - {c.SetCharge(value); break;} - case AliHLTTPCDefinitions::kQMax: - {c.SetQMax(value); break;} - } - if (parameterId>=AliHLTTPCDefinitions::kLast) { - // switch to next cluster - ++c; - outClusterCnt++; - parameterId=-1; - } - parameterId++; - } - pInflater->Pad8Bits(); - AliHLTUInt8_t bit=0; - if (pInflater->InputBit(bit)) { - HLTWarning("format error of compressed clusters, there is more data than expected"); - } - pInflater->CloseBitDataInput(); - if (iResult>=0 && nofClusters!=outClusterCnt) { - // is this a Fatal? - HLTError("error reading compressed cluster format of block 0x%08x: expected %d, read only %d cluster(s)", specification, nofClusters, outClusterCnt); - return -EPROTO; - } - return iResult; -} - -int AliHLTTPCDataCompressionMonitorComponent::ReadTrackModelClustersCompressed(AliHLTTPCDataCompressionMonitorComponent::T& c, const AliHLTUInt8_t* pData, int dataSize, AliHLTUInt32_t /*specification*/) -{ - // read cluster data from the track model data block - int iResult=0; - int dataOffset=sizeof(AliHLTTPCDataCompressionComponent::AliHLTTPCTrackModelBlock); - if (!pData || dataSize(pData); - if (trackModelBlock->fVersion!=1) { - HLTError("unknown version %d", trackModelBlock->fVersion); - return -EINVAL; - } - std::auto_ptr pInflater(CreateInflater(trackModelBlock->fDeflaterMode, 2)); - if (!pInflater.get()) { - HLTError("failed to create the data inflater for mode %d", trackModelBlock->fDeflaterMode); - } - int nofTracks=trackModelBlock->fTrackCount; - dataOffset+=trackModelBlock->fGlobalParameterCnt*sizeof(trackModelBlock->fGlobalParameters); - if (dataSizefGlobalParameterCnt); - return -ENOSPC; - } - float bz=0.0; - float driftTimeFactorA=0.; - float driftTimeOffsetA=0.; - float driftTimeFactorC=0.; - float driftTimeOffsetC=0.; - - AliHLTUInt32_t parameterIndex=0; - switch (trackModelBlock->fGlobalParameterCnt) { - case 5: - bz =trackModelBlock->fGlobalParameters[parameterIndex++]; - driftTimeFactorA=trackModelBlock->fGlobalParameters[parameterIndex++]; - driftTimeOffsetA=trackModelBlock->fGlobalParameters[parameterIndex++]; - driftTimeFactorC=trackModelBlock->fGlobalParameters[parameterIndex++]; - driftTimeOffsetC=trackModelBlock->fGlobalParameters[parameterIndex++]; - break; - default: - HLTError("unknown version of global parameters %d", trackModelBlock->fGlobalParameterCnt); - return -ENODATA; - } - - if (parameterIndex!=trackModelBlock->fGlobalParameterCnt) { - HLTError("internal error, size of parameter array has changed without providing all values"); - return -EFAULT; - } - - for (int trackno=0; tracknoInitBitDataInput(pData+dataOffset, clusterBlockSize))<0) { - return iResult; - } - if ((iResult=ReadTrackClustersCompressed(c, pInflater.get(), &trackpoints))<0) { - HLTError("reading of associated clusters failed for track %d", trackno); - return iResult; - } - pInflater->Pad8Bits(); - AliHLTUInt8_t bit=0; - if (pInflater->InputBit(bit)) { - HLTWarning("format error of compressed clusters, there is more data than expected"); - } - pInflater->CloseBitDataInput(); - dataOffset+=clusterBlockSize; - } - - return iResult; -} - -int AliHLTTPCDataCompressionMonitorComponent::ReadTrackClustersCompressed(AliHLTTPCDataCompressionMonitorComponent::T& c, AliHLTDataInflater* pInflater, AliHLTTPCTrackGeometry* pTrackPoints) -{ - // read cluster data - - int iResult=0; - if (!pInflater || !pTrackPoints) return -EINVAL; - - const vector& rawTrackPoints=pTrackPoints->GetRawPoints(); - vector::const_iterator currentTrackPoint=rawTrackPoints.begin(); - - bool bReadSuccess=true; - AliHLTUInt32_t clusterCountBitLength=AliHLTTPCDefinitions::fgkClusterParameterDefinitions[AliHLTTPCDefinitions::kClusterCount].fBitLength; - //unsigned long dataPosition=pInflater->GetCurrentByteInputPosition(); - for (unsigned row=0; row<159 && bReadSuccess; row++) { - AliHLTUInt8_t haveClusters=0; - // 1 bit for clusters on that padrow - bReadSuccess=bReadSuccess && pInflater->InputBit(haveClusters); - if (!haveClusters) continue; - bool bEscape=false; - do { - if (currentTrackPoint==rawTrackPoints.end()) { - if (bEscape || rawTrackPoints.begin()==rawTrackPoints.end()) break; - currentTrackPoint=rawTrackPoints.begin(); - bEscape=true; - } - if (AliHLTTPCTransform::GetFirstRow(AliHLTTPCSpacePointData::GetPatch(currentTrackPoint->GetId())) + - AliHLTTPCSpacePointData::GetNumber(currentTrackPoint->GetId()) == row) { - break; - } - currentTrackPoint++; - } while (!bEscape); - if (currentTrackPoint==rawTrackPoints.end()) { - HLTError("decoding error, can not find track point on row %d", row); - return -EFAULT; - } - AliHLTUInt8_t nofClusters=0; - bReadSuccess=bReadSuccess && pInflater->InputBits(nofClusters, clusterCountBitLength); - if (!bReadSuccess) break; - - static const AliHLTTPCDefinitions::AliClusterParameterId_t kParameterIdMapping[] = { - AliHLTTPCDefinitions::kResidualPad, - AliHLTTPCDefinitions::kResidualTime, - AliHLTTPCDefinitions::kSigmaY2, - AliHLTTPCDefinitions::kSigmaZ2, - AliHLTTPCDefinitions::kCharge, - AliHLTTPCDefinitions::kQMax, - }; - - int parameterId=0; - int inClusterCnt=0; - AliHLTUInt64_t value=0; - AliHLTUInt32_t length=0; - while (bReadSuccess && inClusterCntNextValue(value, length)) { - const AliHLTTPCDefinitions::AliClusterParameter& parameter - =AliHLTTPCDefinitions::fgkClusterParameterDefinitions[kParameterIdMapping[parameterId]]; - - if (parameter.fBitLength!=(int)length) { - HLTError("decode error: expecting length %d for parameter %s, but got %d", - parameter.fBitLength, parameter.fName, length); - break; - } - - static float deltapad=0.; - static float deltatime=0.; - bool lastParameter=false; - switch (kParameterIdMapping[parameterId]) { - case AliHLTTPCDefinitions::kResidualPad: - { - AliHLTUInt8_t sign=0; - bReadSuccess=bReadSuccess && pInflater->InputBit(sign); - float pad=value*(sign?-1.:1.); pad/=parameter.fScale; - deltapad=pad; - pad+=currentTrackPoint->GetU(); - c.SetPad(pad); - break; - } - case AliHLTTPCDefinitions::kResidualTime: - { - AliHLTUInt8_t sign=0; - bReadSuccess=bReadSuccess && pInflater->InputBit(sign); - float time=value*(sign?-1.:1.); time/=parameter.fScale; - deltatime=time; - time+=currentTrackPoint->GetV(); - c.SetTime(time); - break; - } - case AliHLTTPCDefinitions::kSigmaY2: - {float sigmaY2=value; sigmaY2/=parameter.fScale; c.SetSigmaY2(sigmaY2); break;} - case AliHLTTPCDefinitions::kSigmaZ2: - {float sigmaZ2=value; sigmaZ2/=parameter.fScale; c.SetSigmaZ2(sigmaZ2); break;} - case AliHLTTPCDefinitions::kCharge: - {c.SetCharge(value); break;} - case AliHLTTPCDefinitions::kQMax: - {c.SetQMax(value); lastParameter=true; break;} - default: - { - HLTError("parameter %d not expected", kParameterIdMapping[parameterId]); - } - } - if (lastParameter) { - // switch to next cluster - c.SetPadRow(row); - // cout << " row " << setfill(' ') << setw(3) << fixed << right << c.GetRow() - // << " pad " << setfill(' ') << setw(7) << fixed << right << setprecision (4) << c.GetPad() - // << " dpad " << setfill(' ') << setw(7) << fixed << right << setprecision (4) << deltapad - // << " time " << setfill(' ') << setw(7) << fixed << right << setprecision (4) << c.GetTimeBin() - // << " dtime " << setfill(' ') << setw(7) << fixed << right << setprecision (4) << deltatime - // << " charge " << setfill(' ') << setw(5) << fixed << right << setprecision (0) << c.GetQ() - // << " qmax " << setfill(' ') << setw(4) << fixed << right << setprecision (0) << c.GetMax() - // << endl; - ++c; - inClusterCnt++; - parameterId=-1; - } - parameterId++; - } - if (iResult>=0 && nofClusters!=inClusterCnt) { - // is this a Fatal? - HLTError("error reading track model compressed cluster format of track: expected %d, read only %d cluster(s)", nofClusters, inClusterCnt); - return -EPROTO; - } - currentTrackPoint++; - } - return iResult; -} - -AliHLTDataInflater* AliHLTTPCDataCompressionMonitorComponent::CreateInflater(int deflater, int mode) const -{ - // create the inflater for the specified mode - vector parameterids; - switch (mode) { - case 1: - parameterids.push_back(AliHLTTPCDefinitions::kPadRow ); - parameterids.push_back(AliHLTTPCDefinitions::kPad ); - parameterids.push_back(AliHLTTPCDefinitions::kTime ); - parameterids.push_back(AliHLTTPCDefinitions::kSigmaY2); - parameterids.push_back(AliHLTTPCDefinitions::kSigmaZ2); - parameterids.push_back(AliHLTTPCDefinitions::kCharge ); - parameterids.push_back(AliHLTTPCDefinitions::kQMax ); - break; - case 2: - parameterids.push_back(AliHLTTPCDefinitions::kResidualPad ); - parameterids.push_back(AliHLTTPCDefinitions::kResidualTime); - parameterids.push_back(AliHLTTPCDefinitions::kSigmaY2); - parameterids.push_back(AliHLTTPCDefinitions::kSigmaZ2); - parameterids.push_back(AliHLTTPCDefinitions::kCharge ); - parameterids.push_back(AliHLTTPCDefinitions::kQMax ); - break; - default: - HLTError("invalid mode %d for inflater initialization", mode); - } - - switch (deflater) { - case 1: - { - std::auto_ptr inflatersimple(new AliHLTDataInflaterSimple); - if (!inflatersimple.get()) return NULL; - for (vector::const_iterator id=parameterids.begin(); - id!=parameterids.end(); id++) { - const AliHLTTPCDefinitions::AliClusterParameter& parameter=AliHLTTPCDefinitions::fgkClusterParameterDefinitions[*id]; - if (inflatersimple->AddParameterDefinition(parameter.fName, - parameter.fBitLength, - parameter.fOptional)<0) { - HLTError("error adding parameter definition %s to inflater", parameter.fName); - return NULL; - } - } - return inflatersimple.release(); - } - break; - case 2: - { - std::auto_ptr inflaterhuffman(new AliHLTDataInflaterHuffman); - if (!inflaterhuffman.get()) return NULL; - TString cdbPath("HLT/ConfigTPC/TPCDataCompressorHuffmanTables"); - TObject* pConf=LoadAndExtractOCDBObject(cdbPath); - if (!pConf) { - HLTError("can not load configuration object %s", cdbPath.Data()); - return NULL; - } - if (dynamic_cast(pConf)==NULL) { - HLTError("huffman table configuration object of inconsistent type"); - return NULL; - } - inflaterhuffman->InitDecoders(dynamic_cast(pConf)); - for (vector::const_iterator id=parameterids.begin(); - id!=parameterids.end(); id++) { - const AliHLTTPCDefinitions::AliClusterParameter& parameter=AliHLTTPCDefinitions::fgkClusterParameterDefinitions[*id]; - if (inflaterhuffman->AddParameterDefinition(parameter.fName, - parameter.fBitLength)<0) { - HLTError("error adding parameter definition %s to inflater", parameter.fName); - return NULL; - } - } - return inflaterhuffman.release(); - } - break; - default: - HLTError("unknown inflater requested %d", deflater); - } - return NULL; -} - AliHLTTPCDataCompressionMonitorComponent::AliDataContainer::AliDataContainer() : fHistograms(new TObjArray) , fHistogramPointers() @@ -761,7 +391,6 @@ AliHLTTPCDataCompressionMonitorComponent::AliDataContainer::iterator& AliHLTTPCD else fCurrentClusterIds=NULL; fBegin=iterator(this); - fEnd=iterator(); return fBegin; } @@ -773,16 +402,9 @@ AliHLTTPCDataCompressionMonitorComponent::AliDataContainer::iterator& AliHLTTPCD else fCurrentClusterIds=NULL; fBegin=iterator(this); - fEnd=iterator(); return fBegin; } -const AliHLTTPCDataCompressionMonitorComponent::AliDataContainer::iterator& AliHLTTPCDataCompressionMonitorComponent::AliDataContainer::End() -{ - /// get end iterator - return fEnd; -} - int AliHLTTPCDataCompressionMonitorComponent::AliDataContainer::AddRawData(const AliHLTComponentBlockData* pDesc) { /// add raw data bloack diff --git a/HLT/TPCLib/comp/AliHLTTPCDataCompressionMonitorComponent.h b/HLT/TPCLib/comp/AliHLTTPCDataCompressionMonitorComponent.h index 6b7c4d7306e..87e67d17ed7 100644 --- a/HLT/TPCLib/comp/AliHLTTPCDataCompressionMonitorComponent.h +++ b/HLT/TPCLib/comp/AliHLTTPCDataCompressionMonitorComponent.h @@ -144,6 +144,8 @@ public: void SetCharge(unsigned charge) {if (fData) fData->FillCharge(charge, fClusterId);} void SetQMax(unsigned qmax) {if (fData) fData->FillQMax(qmax, fClusterId);} + // switch to next cluster + iterator& Next(int /*slice*/, int /*partition*/) {return operator++();} // prefix operators iterator& operator++() {fClusterNo++; fClusterId=fData?fData->GetClusterId(fClusterNo):kAliHLTVoidDataSpec;return *this;} iterator& operator--() {fClusterNo--; fClusterId=fData?fData->GetClusterId(fClusterNo):kAliHLTVoidDataSpec;return *this;} @@ -164,8 +166,6 @@ public: iterator& BeginRemainingClusterBlock(int count, AliHLTUInt32_t specification); /// iterator of track model clusters iterator& BeginTrackModelClusterBlock(int count); - /// end iterator - const iterator& End(); /// add raw data bloack int AddRawData(const AliHLTComponentBlockData* pDesc); @@ -225,15 +225,6 @@ private: AliHLTTPCDataCompressionMonitorComponent(const AliHLTTPCDataCompressionMonitorComponent&); AliHLTTPCDataCompressionMonitorComponent& operator=(const AliHLTTPCDataCompressionMonitorComponent&); - typedef AliDataContainer::iterator T; - int ReadRemainingClustersCompressed(T& c, const AliHLTUInt8_t* pData, int dataSize, AliHLTUInt32_t specification); - int ReadRemainingClustersCompressed(T& c, AliHLTDataInflater* pInflater, int nofClusters, AliHLTUInt32_t specification); - - int ReadTrackModelClustersCompressed(T& c, const AliHLTUInt8_t* pData, int dataSize, AliHLTUInt32_t specification); - int ReadTrackClustersCompressed(T& c, AliHLTDataInflater* pInflater, AliHLTTPCTrackGeometry* pTrackPoints); - - AliHLTDataInflater* CreateInflater(int deflater, int mode) const; - AliHLTTPCHWCFData* fpHWClusterDecoder; //! data decoder for HW clusters TH2* fHistoHWCFDataSize; //! hwcf data size vs. event size