///
#include "AliHLTTPCDataCompressionMonitorComponent.h"
+#include "AliHLTTPCDataCompressionComponent.h"
#include "AliHLTTPCDefinitions.h"
#include "AliHLTTPCHWCFData.h"
#include "AliHLTTPCDefinitions.h"
#include "AliHLTTPCClusterDataFormat.h"
#include "AliHLTTPCRawCluster.h"
#include "AliHLTTPCTransform.h"
+#include "AliHLTTPCTrackGeometry.h"
#include "AliHLTDataInflaterSimple.h"
#include "AliHLTDataInflaterHuffman.h"
#include "AliRawDataHeader.h"
iResult=ReadRemainingClustersCompressed(reinterpret_cast<AliHLTUInt8_t*>(pDesc->fPtr), pDesc->fSize, pDesc->fSpecification);
}
+ for (pDesc=GetFirstInputBlock(AliHLTTPCDefinitions::ClusterTracksCompressedDataType());
+ pDesc!=NULL; pDesc=GetNextInputBlock()) {
+ iResult=ReadTrackModelClustersCompressed(reinterpret_cast<AliHLTUInt8_t*>(pDesc->fPtr), pDesc->fSize, pDesc->fSpecification);
+ }
+
float ratio=0;
if (hwclustersDataSize) {ratio=(float)rawDataSize; ratio/=hwclustersDataSize;}
if (fHistoHWCFDataSize) fHistoHWCFDataSize->Fill(rawDataSize/1024, hwclustersDataSize/1024);
const AliHLTTPCRawClusterData* clusterData = reinterpret_cast<const AliHLTTPCRawClusterData*>(pBuffer);
Int_t nCount = (Int_t) clusterData->fCount;
- // this is encoded data of different formats
- switch (clusterData->fVersion) {
- case 1:
- {
- AliHLTDataInflaterSimple inflatersimple;
- {
- unsigned nofParameters=7;//AliHLTTPCDefinitions::GetNumberOfClusterParameterDefinitions();
- unsigned p=0;
- for (; p<nofParameters; p++) {
- const AliHLTTPCDefinitions::AliClusterParameter& parameter=AliHLTTPCDefinitions::fgkClusterParameterDefinitions[p];
- if (inflatersimple.AddParameterDefinition(parameter.fName,
- parameter.fBitLength,
- parameter.fOptional)!=(int)parameter.fId) {
- // for performance reason the parameter id is simply used as index in the array of
- // definitions, the position must match the id
- HLTError("mismatch between parameter id and position in array for parameter %s, rearrange definitions!", parameter.fName);
- return -EFAULT;
- }
- }
- }
- if ((iResult=inflatersimple.InitBitDataInput(reinterpret_cast<const AliHLTUInt8_t*>(clusterData->fClusters),
- size-sizeof(AliHLTTPCRawClusterData)))<0) {
- return iResult;
- }
+ AliHLTDataInflater* inflater=CreateInflater(clusterData->fVersion, 1);
+ if (!inflater) return -ENODEV;
- iResult=ReadRemainingClustersCompressed(&inflatersimple, nCount, specification);
- }
- break;
- case 2:
- {
- AliHLTDataInflaterHuffman inflaterhuffman;
- {
- TString cdbPath("HLT/ConfigTPC/TPCDataCompressorHuffmanTables");
- TObject* pConf=LoadAndExtractOCDBObject(cdbPath);
- if (!pConf) {
- HLTError("can not load configuration object %s", cdbPath.Data());
- return -ENOENT;
- }
- if (dynamic_cast<TList*>(pConf)==NULL) {
- HLTError("huffman table configuration object of inconsistent type");
- return -EINVAL;
- }
- inflaterhuffman.InitDecoders(dynamic_cast<TList*>(pConf));
- unsigned nofParameters=7;//AliHLTTPCDefinitions::GetNumberOfClusterParameterDefinitions();
- unsigned p=0;
- for (; p<nofParameters; p++) {
- const AliHLTTPCDefinitions::AliClusterParameter& parameter=AliHLTTPCDefinitions::fgkClusterParameterDefinitions[p];
- if (inflaterhuffman.AddParameterDefinition(parameter.fName,
- parameter.fBitLength)!=(int)parameter.fId) {
- // for performance reason the parameter id is simply used as index in the array of
- // definitions, the position must match the id
- HLTError("mismatch between parameter id and position in array for parameter %s, rearrange definitions!", parameter.fName);
- return -EFAULT;
- }
- }
- }
- if ((iResult=inflaterhuffman.InitBitDataInput(reinterpret_cast<const AliHLTUInt8_t*>(clusterData->fClusters),
- size-sizeof(AliHLTTPCRawClusterData)))<0) {
- return iResult;
- }
-
- iResult=ReadRemainingClustersCompressed(&inflaterhuffman, nCount, specification);
- }
- break;
- default:
- HLTError("invalid cluster format version %d", clusterData->fVersion);
- iResult=-EPROTO;
+ if ((iResult=inflater->InitBitDataInput(reinterpret_cast<const AliHLTUInt8_t*>(clusterData->fClusters),
+ size-sizeof(AliHLTTPCRawClusterData)))<0) {
+ return iResult;
}
+ iResult=ReadRemainingClustersCompressed(inflater, nCount, specification);
+
return iResult;
}
}
return iResult;
}
+
+int AliHLTTPCDataCompressionMonitorComponent::ReadTrackModelClustersCompressed(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<dataOffset) return -EINVAL;
+
+ const AliHLTTPCDataCompressionComponent::AliHLTTPCTrackModelBlock* trackModelBlock=reinterpret_cast<const AliHLTTPCDataCompressionComponent::AliHLTTPCTrackModelBlock*>(pData);
+ if (trackModelBlock->fVersion!=1) {
+ HLTError("unknown version %d", trackModelBlock->fVersion);
+ return -EINVAL;
+ }
+ std::auto_ptr<AliHLTDataInflater> 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 (dataSize<dataOffset) {
+ HLTError("inconsistent data block, size %d, expecting at least %d to read AliHLTTPCTrackModelBlock with %d global parameters", dataSize, dataOffset, trackModelBlock->fGlobalParameterCnt);
+ 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; trackno<nofTracks; trackno++) {
+ AliHLTTPCTrackGeometry trackpoints;
+ trackpoints.InitDriftTimeTransformation(driftTimeFactorA, driftTimeOffsetA, driftTimeFactorC, driftTimeOffsetC);
+ AliHLTUInt32_t clusterBlockSize=0;
+ if ((iResult=trackpoints.Read(pData+dataOffset, dataSize-dataOffset, bz, clusterBlockSize))<0) {
+ return iResult;
+ }
+ dataOffset+=iResult;
+ if (dataSize-dataOffset<(int)clusterBlockSize) {
+ HLTError("to little data in buffer to read cluster block of size %d for track no %d", clusterBlockSize, trackno);
+ return -ENODATA;
+ }
+ if ((iResult=pInflater->InitBitDataInput(pData+dataOffset, clusterBlockSize))<0) {
+ return iResult;
+ }
+ if ((iResult=ReadTrackClustersCompressed(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(AliHLTDataInflater* pInflater,
+ AliHLTTPCTrackGeometry* pTrackPoints)
+{
+ // read cluster data
+
+ int iResult=0;
+ if (!pInflater || !pTrackPoints) return -EINVAL;
+
+ const vector<AliHLTTrackGeometry::AliHLTTrackPoint>& rawTrackPoints=pTrackPoints->GetRawPoints();
+ vector<AliHLTTrackGeometry::AliHLTTrackPoint>::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;
+ AliTPCclusterMI* pCluster=new AliTPCclusterMI;
+ while (bReadSuccess && inClusterCnt<nofClusters && pInflater->NextValue(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();
+ pCluster->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();
+ pCluster->SetTimeBin(time);
+ break;
+ }
+ case AliHLTTPCDefinitions::kSigmaY2:
+ {float sigmaY2=value; sigmaY2/=parameter.fScale; pCluster->SetSigmaY2(sigmaY2); break;}
+ case AliHLTTPCDefinitions::kSigmaZ2:
+ {float sigmaZ2=value; sigmaZ2/=parameter.fScale; pCluster->SetSigmaZ2(sigmaZ2); break;}
+ case AliHLTTPCDefinitions::kCharge:
+ {pCluster->SetQ(value); break;}
+ case AliHLTTPCDefinitions::kQMax:
+ {pCluster->SetMax(value); lastParameter=true; break;}
+ default:
+ {
+ HLTError("parameter %d not expected", kParameterIdMapping[parameterId]);
+ }
+ }
+ if (lastParameter) {
+ // switch to next cluster
+ pCluster->SetRow(row);
+ // cout << " row " << setfill(' ') << setw(3) << fixed << right << pCluster->GetRow()
+ // << " pad " << setfill(' ') << setw(7) << fixed << right << setprecision (4) << pCluster->GetPad()
+ // << " dpad " << setfill(' ') << setw(7) << fixed << right << setprecision (4) << deltapad
+ // << " time " << setfill(' ') << setw(7) << fixed << right << setprecision (4) << pCluster->GetTimeBin()
+ // << " dtime " << setfill(' ') << setw(7) << fixed << right << setprecision (4) << deltatime
+ // << " charge " << setfill(' ') << setw(5) << fixed << right << setprecision (0) << pCluster->GetQ()
+ // << " qmax " << setfill(' ') << setw(4) << fixed << right << setprecision (0) << pCluster->GetMax()
+ // << endl;
+ 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++;
+ delete pCluster;
+ }
+ return iResult;
+}
+
+AliHLTDataInflater* AliHLTTPCDataCompressionMonitorComponent::CreateInflater(int deflater, int mode) const
+{
+ // create the inflater for the specified mode
+ vector<AliHLTTPCDefinitions::AliClusterParameterId_t> 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<AliHLTDataInflaterSimple> inflatersimple(new AliHLTDataInflaterSimple);
+ if (!inflatersimple.get()) return NULL;
+ for (vector<AliHLTTPCDefinitions::AliClusterParameterId_t>::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<AliHLTDataInflaterHuffman> 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<TList*>(pConf)==NULL) {
+ HLTError("huffman table configuration object of inconsistent type");
+ return NULL;
+ }
+ inflaterhuffman->InitDecoders(dynamic_cast<TList*>(pConf));
+ for (vector<AliHLTTPCDefinitions::AliClusterParameterId_t>::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;
+}