+AliHLTSpacePointContainer::AliHLTSpacePointPropertyGrid* AliHLTTPCRawSpacePointContainer::AllocateIndexGrid()
+{
+ // allocate index grid, one single point to define the dimensions
+
+ // max 33 padrows, step 1 padrow
+ // max 140 pads, step 2x max delta pad
+ // max 1024 time bins, step 2x max delta time
+ return new AliHLTSpacePointPropertyGrid(33, 1.0,
+ 140, 2*AliHLTTPCDefinitions::GetMaxClusterDeltaPad(),
+ 1024, 2*AliHLTTPCDefinitions::GetMaxClusterDeltaTime()
+ );
+}
+
+int AliHLTTPCRawSpacePointContainer::PopulateAccessGrid(AliHLTSpacePointPropertyGrid* pGrid, AliHLTUInt32_t mask) const
+{
+ // populate an access grid
+ if (!pGrid) return -EINVAL;
+
+ pGrid->Clear();
+
+ AliHLTUInt8_t slice = AliHLTTPCDefinitions::GetMinSliceNr(mask);
+ AliHLTUInt8_t partition = AliHLTTPCDefinitions::GetMinPatchNr(mask);
+ AliHLTUInt32_t decoderIndex=AliHLTTPCSpacePointData::GetID(slice, partition, 0);
+ std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointBlock>::const_iterator block=fBlocks.find(decoderIndex);
+ if (block==fBlocks.end()) {
+ HLTError("can not find data block of id 0x%08x", mask);
+ return -ENOENT;
+ }
+ return PopulateAccessGrid(pGrid, block->second.GetDecoder(), slice, partition);
+}
+
+int AliHLTTPCRawSpacePointContainer::PopulateAccessGrid(AliHLTSpacePointPropertyGrid* pGrid, AliHLTTPCRawClusterData* pDecoder,
+ int slice, int partition) const
+{
+ // populate an access grid
+ if (!pDecoder) return -EINVAL;
+ int iResult=0;
+
+ for( UInt_t icl=0; icl<pDecoder->fCount; icl++){
+ const AliHLTTPCRawCluster &cl = pDecoder->fClusters[icl];
+ iResult=pGrid->CountSpacePoint(cl.GetPadRow(), cl.GetPad(), cl.GetTime());
+ if (iResult<0)
+ HLTError("CountSpacePoint %f %f %f failed: %d", cl.GetPadRow(), cl.GetPad(), cl.GetTime(), iResult);
+ }
+
+ for( UInt_t icl=0; icl<pDecoder->fCount; icl++ ){
+ const AliHLTTPCRawCluster &cl = pDecoder->fClusters[icl];
+ AliHLTUInt32_t id=AliHLTTPCSpacePointData::GetID(slice, partition, icl);
+ iResult=pGrid->AddSpacePoint(AliHLTSpacePointProperties(id), cl.GetPadRow(), cl.GetPad(), cl.GetTime());
+ if (iResult<0)
+ HLTError("AddSpacePoint 0x%08x %f %f %f failed: %d", id, cl.GetPadRow(), cl.GetPad(), cl.GetTime(), iResult);
+ }
+
+ return 0;
+}
+
+const AliHLTSpacePointContainer::AliHLTSpacePointPropertyGrid* AliHLTTPCRawSpacePointContainer::GetSpacePointPropertyGrid(AliHLTUInt32_t mask) const
+{
+ // get the access grid for a data block
+ AliHLTUInt8_t slice = AliHLTTPCDefinitions::GetMinSliceNr(mask);
+ AliHLTUInt8_t part = AliHLTTPCDefinitions::GetMinPatchNr(mask);
+ AliHLTUInt32_t decoderIndex=AliHLTTPCSpacePointData::GetID(slice, part, 0);
+ std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointBlock>::const_iterator block=fBlocks.find(decoderIndex);
+ if (block==fBlocks.end()) {
+ HLTError("can not find data block of id 0x%08x", mask);
+ return NULL;
+ }
+ return block->second.GetGrid();
+}
+
+int AliHLTTPCRawSpacePointContainer::SetSpacePointPropertyGrid(AliHLTUInt32_t mask, AliHLTSpacePointContainer::AliHLTSpacePointPropertyGrid* pGrid)
+{
+ // set the access grid for a data block
+ AliHLTUInt8_t slice = AliHLTTPCDefinitions::GetMinSliceNr(mask);
+ AliHLTUInt8_t part = AliHLTTPCDefinitions::GetMinPatchNr(mask);
+ AliHLTUInt32_t decoderIndex=AliHLTTPCSpacePointData::GetID(slice, part, 0);
+ std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointBlock>::iterator block=fBlocks.find(decoderIndex);
+ if (block==fBlocks.end()) {
+ HLTError("can not find data block of id 0x%08x", mask);
+ return -ENOENT;
+ }
+ if (block->second.GetGrid()!=NULL && pGrid!=NULL && block->second.GetGrid()!=pGrid) {
+ // there is trouble ahead because this will delete the index grid instance
+ // but it might be an external pointer supposed to be deleted by someone else
+ ALIHLTERRORGUARD(1, "overriding previous instance of index grid, potential memory leak or invalid deallocation ahead");
+ }
+ block->second.SetGrid(pGrid);
+ return 0;
+}
+