LCOV - code coverage report
Current view: top level - HLT/TPCLib - AliHLTTPCRawSpacePointContainer.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 523 0.2 %
Date: 2016-06-14 17:26:59 Functions: 1 53 1.9 %

          Line data    Source code
       1             : // $Id$
       2             : 
       3             : //**************************************************************************
       4             : //* This file is property of and copyright by the ALICE HLT Project        * 
       5             : //* ALICE Experiment at CERN, All rights reserved.                         *
       6             : //*                                                                        *
       7             : //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
       8             : //*                  for The ALICE HLT Project.                            *
       9             : //*                                                                        *
      10             : //* Permission to use, copy, modify and distribute this software and its   *
      11             : //* documentation strictly for non-commercial purposes is hereby granted   *
      12             : //* without fee, provided that the above copyright notice appears in all   *
      13             : //* copies and that both the copyright notice and this permission notice   *
      14             : //* appear in the supporting documentation. The authors make no claims     *
      15             : //* about the suitability of this software for any purpose. It is          *
      16             : //* provided "as is" without express or implied warranty.                  *
      17             : //**************************************************************************
      18             : 
      19             : /// @file   AliHLTTPCRawSpacePointContainer.cxx
      20             : /// @author Matthias Richter, Sergey Gorbunov
      21             : /// @date   2011-08-08
      22             : /// @brief  Helper class for handling of HLT TPC raw cluster data blocks
      23             : 
      24             : #include "AliHLTTPCRawSpacePointContainer.h"
      25             : #include "AliHLTErrorGuard.h"
      26             : #include "AliHLTTPCDefinitions.h"
      27             : #include "AliHLTTPCSpacePointData.h"
      28             : #include "AliHLTTPCRawCluster.h"
      29             : #include "AliHLTTPCClusterFlagsData.h"
      30             : #include "AliHLTTPCGeometry.h"
      31             : #include "AliHLTComponent.h"
      32             : #include "AliHLTTemplates.h"
      33             : #include "AliHLTDataDeflater.h"
      34             : #include "AliLog.h"
      35             : #include "TMath.h"
      36             : #include <memory>
      37             : #include <algorithm>
      38             : #include <cmath>
      39             : #include <iostream>
      40             : #include <sstream>
      41             : #include <iomanip>
      42             : 
      43             : 
      44             : /** ROOT macro for the implementation of ROOT specific class methods */
      45           6 : ClassImp(AliHLTTPCRawSpacePointContainer)
      46             : 
      47             : AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointContainer(int mode, int createFlags)
      48           0 :   : AliHLTSpacePointContainer()
      49           0 :   , fClusters()
      50           0 :   , fSelections()
      51           0 :   , fBlocks()
      52           0 :   , fSingleBlock()
      53           0 :   , fMode(mode)
      54           0 :   , fCreateFlags(createFlags)
      55           0 :   , fWrittenClusterIds(NULL)
      56           0 : {
      57             :   // see header file for class documentation
      58             :   // or
      59             :   // refer to README to build package
      60             :   // or
      61             :   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
      62           0 :   if (fMode&kModeSingle) {
      63           0 :     fSingleBlock.SetDecoder(NULL);
      64           0 :     fSingleBlock.SetGrid(AllocateIndexGrid());
      65           0 :   }
      66           0 : }
      67             : 
      68             : AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointContainer(const AliHLTTPCRawSpacePointContainer& c)
      69           0 :   : AliHLTSpacePointContainer(c)
      70           0 :   , fClusters(c.fClusters.begin(), c.fClusters.end())
      71           0 :   , fSelections()
      72           0 :   , fBlocks()
      73           0 :   , fSingleBlock()
      74           0 :   , fMode(c.fMode)
      75           0 :   , fCreateFlags(c.fCreateFlags)
      76           0 :   , fWrittenClusterIds(NULL)
      77           0 : {
      78             :   /// copy constructor
      79           0 : }
      80             : 
      81             : AliHLTTPCRawSpacePointContainer& AliHLTTPCRawSpacePointContainer::operator=(const AliHLTTPCRawSpacePointContainer& c)
      82             : {
      83             :   /// assignment operator
      84           0 :   if (&c==this) return *this;
      85           0 :   AliHLTSpacePointContainer::operator=(c);
      86           0 :   fClusters=c.fClusters;
      87           0 :   fMode=c.fMode;
      88           0 :   fCreateFlags = c.fCreateFlags;
      89           0 :   fWrittenClusterIds=NULL;
      90             : 
      91           0 :   return *this;
      92           0 : }
      93             : 
      94           0 : AliHLTTPCRawSpacePointContainer::~AliHLTTPCRawSpacePointContainer()
      95           0 : {
      96             :   // destructor
      97           0 :   Clear();
      98           0 :   if (fSingleBlock.GetGrid()) delete fSingleBlock.GetGrid();
      99           0 :   if (fWrittenClusterIds) delete fWrittenClusterIds;
     100           0 : }
     101             : 
     102             : int AliHLTTPCRawSpacePointContainer::AddInputBlock(const AliHLTComponentBlockData* pDesc)
     103             : {
     104             :   // add input block to the collection
     105           0 :   if (!pDesc) return -EINVAL;
     106             :   int iResult=0;
     107             :   int count=0;
     108           0 :   if (pDesc->fDataType!=AliHLTTPCDefinitions::fgkRawClustersDataType && pDesc->fDataType!=AliHLTTPCDefinitions::fgkRawClustersDataTypeNotCompressed) {
     109           0 :     HLTWarning("ignoring data block of type %s", AliHLTComponent::DataType2Text(pDesc->fDataType).c_str());
     110           0 :     return 0;
     111             :   }
     112           0 :   if (!pDesc->fPtr) return -ENODATA;
     113           0 :   if (pDesc->fSize<sizeof(AliHLTTPCRawClusterData)) return 0;
     114             : 
     115           0 :   AliHLTTPCRawClusterData* rawClusters = (AliHLTTPCRawClusterData*)(pDesc->fPtr);  
     116             : 
     117           0 :   AliHLTUInt8_t slice = AliHLTTPCDefinitions::GetMinSliceNr( pDesc->fSpecification );
     118           0 :   AliHLTUInt8_t part  = AliHLTTPCDefinitions::GetMinPatchNr( pDesc->fSpecification );
     119             : 
     120           0 :   AliHLTUInt32_t decoderIndex=AliHLTTPCSpacePointData::GetID(slice, part, 0);
     121             : 
     122             :   AliHLTSpacePointPropertyGrid* pGrid=NULL;
     123           0 :   if (fMode&kModeSingle) {
     124           0 :     pGrid=fSingleBlock.GetGrid();
     125           0 :   } else {
     126           0 :     if (fBlocks.find(decoderIndex)!=fBlocks.end()) {
     127           0 :       HLTError("data block of slice %d partition %d already added, skipping data block", slice, part);
     128           0 :       return -EEXIST;
     129             :     }
     130             :   }
     131             : 
     132           0 :   if (fMode&kModeSingle && !pGrid) {
     133           0 :     pGrid=AllocateIndexGrid();
     134           0 :     if (!pGrid) {
     135           0 :       return -ENOMEM;
     136             :     }
     137             :   }
     138             : 
     139           0 :   if (fMode&kModeCreateMap) { // register immediately
     140             : 
     141             :     //UInt_t nofClusters=rawClusters->fCount;
     142             : 
     143           0 :     for( UInt_t icl=0; icl<rawClusters->fCount; icl++){      
     144           0 :       const AliHLTTPCRawCluster &cl = rawClusters->fClusters[icl];
     145           0 :       AliHLTUInt32_t clusterID=~(AliHLTUInt32_t)0;
     146             :       // cluster ID from slice, partition and index
     147           0 :       clusterID=AliHLTTPCSpacePointData::GetID(slice, part, icl);
     148             : 
     149           0 :       if (fClusters.find(clusterID)==fClusters.end()) {
     150             :         // new cluster
     151           0 :         fClusters[clusterID]=AliHLTTPCRawSpacePointProperties(&cl);
     152           0 :         count++;
     153           0 :       } else {
     154           0 :         HLTError("cluster with ID 0x%08x already existing, skipping cluster %d of data block 0x%08x",
     155             :                  clusterID, icl, pDesc->fSpecification);
     156             :       }
     157           0 :     }
     158           0 :   }
     159             : 
     160           0 :   if (pGrid && (iResult=PopulateAccessGrid(pGrid, rawClusters, slice, part))<0) {
     161           0 :     HLTError("failed to populate access grid for block %s 0x%09x: %d",
     162             :              AliHLTComponent::DataType2Text(pDesc->fDataType).c_str(), pDesc->fSpecification, iResult);
     163           0 :     return iResult;
     164             :   }
     165             :   
     166           0 :   if (fMode&kModeSingle) {
     167           0 :     fSingleBlock.SetDecoder(rawClusters);
     168           0 :     fSingleBlock.SetGrid(pGrid);
     169           0 :     fSingleBlock.SetId(decoderIndex);
     170           0 :   } else {
     171           0 :     fBlocks[decoderIndex]=AliHLTTPCRawSpacePointBlock(decoderIndex, rawClusters, pGrid);
     172             :   }
     173           0 :   return count;
     174           0 : }
     175             : 
     176             : AliHLTSpacePointContainer::AliHLTSpacePointPropertyGrid* AliHLTTPCRawSpacePointContainer::AllocateIndexGrid()
     177             : {
     178             :   // allocate index grid, one single point to define the dimensions
     179             :   
     180             :   // max 33 padrows, step 1 padrow
     181             :   // max 140 pads, step 2x max delta pad
     182             :   // max 1024 time bins, step 2x max delta time
     183           0 :   return new AliHLTSpacePointPropertyGrid(33, 1.0,
     184           0 :                                           140, 2*AliHLTTPCDefinitions::GetMaxClusterDeltaPad(),
     185           0 :                                           1024, 2*AliHLTTPCDefinitions::GetMaxClusterDeltaTime()
     186             :                                           );
     187           0 : }
     188             : 
     189             : int AliHLTTPCRawSpacePointContainer::PopulateAccessGrid(AliHLTSpacePointPropertyGrid* pGrid, AliHLTUInt32_t mask) const
     190             : {
     191             :   // populate an access grid
     192           0 :   if (!pGrid) return -EINVAL;
     193             : 
     194           0 :   pGrid->Clear();
     195             :   
     196           0 :   AliHLTUInt8_t slice = AliHLTTPCDefinitions::GetMinSliceNr(mask);
     197           0 :   AliHLTUInt8_t partition  = AliHLTTPCDefinitions::GetMinPatchNr(mask);
     198           0 :   AliHLTUInt32_t decoderIndex=AliHLTTPCSpacePointData::GetID(slice, partition, 0);
     199           0 :   std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointBlock>::const_iterator block=fBlocks.find(decoderIndex);
     200           0 :   if (block==fBlocks.end()) {
     201           0 :     HLTError("can not find data block of id 0x%08x", mask);
     202           0 :     return -ENOENT;
     203             :   }
     204           0 :   return PopulateAccessGrid(pGrid, block->second.GetDecoder(), slice, partition);
     205           0 : }
     206             : 
     207             : int AliHLTTPCRawSpacePointContainer::PopulateAccessGrid(AliHLTSpacePointPropertyGrid* pGrid, AliHLTTPCRawClusterData* pDecoder,
     208             :                                                          int slice, int partition) const
     209             : {
     210             :   // populate an access grid
     211           0 :   if (!pDecoder) return -EINVAL;
     212             :   int iResult=0;
     213             : 
     214           0 :   for( UInt_t icl=0; icl<pDecoder->fCount; icl++){
     215           0 :     const AliHLTTPCRawCluster &cl = pDecoder->fClusters[icl];
     216           0 :     iResult=pGrid->CountSpacePoint(cl.GetPadRow(), cl.GetPad(), cl.GetTime());
     217           0 :     if (iResult<0)
     218           0 :       HLTError("CountSpacePoint %d %f %f failed: %d", cl.GetPadRow(), cl.GetPad(), cl.GetTime(), iResult);
     219             :   }
     220             :   
     221           0 :   for( UInt_t icl=0; icl<pDecoder->fCount; icl++ ){
     222           0 :     const AliHLTTPCRawCluster &cl = pDecoder->fClusters[icl];
     223           0 :     AliHLTUInt32_t id=AliHLTTPCSpacePointData::GetID(slice, partition, icl);
     224           0 :     iResult=pGrid->AddSpacePoint(AliHLTSpacePointProperties(id), cl.GetPadRow(), cl.GetPad(), cl.GetTime());
     225           0 :     if (iResult<0)
     226           0 :       HLTError("AddSpacePoint 0x%08x %d %f %f failed: %d", id, cl.GetPadRow(), cl.GetPad(), cl.GetTime(), iResult);
     227             :   }
     228             : 
     229             :   return 0;
     230           0 : }
     231             : 
     232             : const AliHLTSpacePointContainer::AliHLTSpacePointPropertyGrid* AliHLTTPCRawSpacePointContainer::GetSpacePointPropertyGrid(AliHLTUInt32_t mask) const
     233             : {
     234             :   // get the access grid for a data block
     235           0 :   AliHLTUInt8_t slice = AliHLTTPCDefinitions::GetMinSliceNr(mask);
     236           0 :   AliHLTUInt8_t part  = AliHLTTPCDefinitions::GetMinPatchNr(mask);
     237           0 :   AliHLTUInt32_t decoderIndex=AliHLTTPCSpacePointData::GetID(slice, part, 0);
     238           0 :   std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointBlock>::const_iterator block=fBlocks.find(decoderIndex);
     239           0 :   if (block==fBlocks.end()) {
     240           0 :     HLTError("can not find data block of id 0x%08x", mask);
     241           0 :     return NULL;
     242             :   }
     243           0 :   return block->second.GetGrid();
     244           0 : }
     245             : 
     246             : int AliHLTTPCRawSpacePointContainer::SetSpacePointPropertyGrid(AliHLTUInt32_t mask, AliHLTSpacePointContainer::AliHLTSpacePointPropertyGrid* pGrid)
     247             : {
     248             :   // set the access grid for a data block
     249           0 :   AliHLTUInt8_t slice = AliHLTTPCDefinitions::GetMinSliceNr(mask);
     250           0 :   AliHLTUInt8_t part  = AliHLTTPCDefinitions::GetMinPatchNr(mask);
     251           0 :   AliHLTUInt32_t decoderIndex=AliHLTTPCSpacePointData::GetID(slice, part, 0);
     252           0 :   std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointBlock>::iterator block=fBlocks.find(decoderIndex);
     253           0 :   if (block==fBlocks.end()) {
     254           0 :     HLTError("can not find data block of id 0x%08x", mask);
     255           0 :     return -ENOENT;
     256             :   }
     257           0 :   if (block->second.GetGrid()!=NULL && pGrid!=NULL && block->second.GetGrid()!=pGrid) {
     258             :     // there is trouble ahead because this will delete the index grid instance
     259             :     // but it might be an external pointer supposed to be deleted by someone else
     260           0 :     ALIHLTERRORGUARD(1, "overriding previous instance of index grid, potential memory leak or invalid deallocation ahead");
     261           0 :   }
     262           0 :   block->second.SetGrid(pGrid);
     263           0 :   return 0;
     264           0 : }
     265             : 
     266             : int AliHLTTPCRawSpacePointContainer::GetClusterIDs(vector<AliHLTUInt32_t>& tgt) const
     267             : {
     268             :   // get array of cluster IDs
     269           0 :   tgt.clear();
     270           0 :   transform(fClusters.begin(), fClusters.end(), back_inserter(tgt), HLT::AliGetKey());
     271           0 :   return tgt.size();
     272             : }
     273             : 
     274             : bool AliHLTTPCRawSpacePointContainer::Check(AliHLTUInt32_t clusterID) const
     275             : {
     276             :   // check if the cluster is available
     277           0 :   return fClusters.find(clusterID)!=fClusters.end();
     278             : }
     279             : 
     280             : const vector<AliHLTUInt32_t>* AliHLTTPCRawSpacePointContainer::GetClusterIDs(AliHLTUInt32_t mask)
     281             : {
     282             :   // get array of cluster IDs filtered by mask
     283           0 :   if (fSelections.find(mask)!=fSelections.end()) {
     284             :     // return existing selection
     285           0 :     return fSelections.find(mask)->second;
     286             :   }
     287             :   // create new collection
     288           0 :   vector<AliHLTUInt32_t>* selected=new vector<AliHLTUInt32_t>;
     289           0 :   if (!selected) return NULL;
     290           0 :   UInt_t slice=AliHLTTPCSpacePointData::GetSlice(mask);
     291           0 :   UInt_t partition=AliHLTTPCSpacePointData::GetPatch(mask);
     292             :   //HLTInfo("creating collection 0x%08x", mask);
     293             : 
     294             :   // the first cluster with number 0 has equal ID to mask unless
     295             :   // the mask selects multiple partitions/slices
     296           0 :   std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointProperties>::const_iterator cl=fClusters.find(mask);
     297             :   bool bAll=false;
     298           0 :   if (slice>=(unsigned)AliHLTTPCGeometry::GetNSlice() ||
     299           0 :       partition>=(unsigned)AliHLTTPCGeometry::GetNumberOfPatches()) {
     300           0 :     cl=fClusters.begin();
     301             :     bAll=true;
     302           0 :   }
     303           0 :   for (; cl!=fClusters.end(); cl++) {
     304           0 :     UInt_t s=AliHLTTPCSpacePointData::GetSlice(cl->first);
     305           0 :     UInt_t p=AliHLTTPCSpacePointData::GetPatch(cl->first);
     306           0 :     if ((slice>=(unsigned)AliHLTTPCGeometry::GetNSlice() || s==slice) && 
     307           0 :         (partition>=(unsigned)AliHLTTPCGeometry::GetNumberOfPatches() || p==partition)) {
     308           0 :       selected->push_back(cl->first);
     309           0 :     } else if (!bAll) {
     310             :       // no need to continue, we are out of the range
     311           0 :       break;
     312             :     }
     313           0 :   }
     314             :   //HLTInfo("collection 0x%08x with %d spacepoints", mask, selected->size());
     315           0 :   fSelections[mask]=selected;
     316             :   return selected;
     317           0 : }
     318             : 
     319             : float AliHLTTPCRawSpacePointContainer::GetX(AliHLTUInt32_t clusterID) const
     320             : {
     321             :   // get X coordinate
     322           0 :   std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointProperties>::const_iterator cl=fClusters.find(clusterID);
     323           0 :   if (cl==fClusters.end() ||
     324           0 :       cl->second.GetCluster()==NULL) return 0.0;
     325             :   // FIXME: understand deviation from the nominal x value
     326             :   // there is a small deviation in the x coordinate - padrow number correlation
     327             :   // in principle, the clusterfinder only uses the mapping to set the x parameter.
     328             :   // now extracting the x value from the padrow no.
     329             :   //return cl->second.Decoder()->fX;
     330           0 :   return cl->second.GetCluster()->GetPadRow();
     331           0 : }
     332             : 
     333             : float AliHLTTPCRawSpacePointContainer::GetXWidth(AliHLTUInt32_t clusterID) const
     334             : {
     335             :   // get error for X coordinate
     336           0 :   std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointProperties>::const_iterator cl=fClusters.find(clusterID);
     337           0 :   if (cl==fClusters.end() ||
     338           0 :       cl->second.GetCluster()==NULL) return 0.0;
     339           0 :   return 0.0; // fixed in padrow number
     340           0 : }
     341             : 
     342             : float AliHLTTPCRawSpacePointContainer::GetY(AliHLTUInt32_t clusterID) const
     343             : {
     344             :   // get Y coordinate
     345           0 :   std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointProperties>::const_iterator cl=fClusters.find(clusterID);
     346           0 :   if (cl==fClusters.end() ||
     347           0 :       cl->second.GetCluster()==NULL) return 0.0;
     348           0 :   return cl->second.GetCluster()->GetPad();
     349           0 : }
     350             : 
     351             : float AliHLTTPCRawSpacePointContainer::GetYWidth(AliHLTUInt32_t clusterID) const
     352             : {
     353             :   // get error for Y coordinate
     354           0 :   std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointProperties>::const_iterator cl=fClusters.find(clusterID);
     355           0 :   if (cl==fClusters.end() ||
     356           0 :       cl->second.GetCluster()==NULL) return 0.0;  
     357           0 :   return cl->second.GetCluster()->GetSigmaPad2();
     358           0 : }
     359             : 
     360             : float AliHLTTPCRawSpacePointContainer::GetZ(AliHLTUInt32_t clusterID) const
     361             : {
     362             :   // get Z coordinate
     363           0 :   std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointProperties>::const_iterator cl=fClusters.find(clusterID);
     364           0 :   if (cl==fClusters.end() ||
     365           0 :       cl->second.GetCluster()==NULL) return 0.0;
     366           0 :   return cl->second.GetCluster()->GetTime();
     367           0 : }
     368             : 
     369             : float AliHLTTPCRawSpacePointContainer::GetZWidth(AliHLTUInt32_t clusterID) const
     370             : {
     371             :   // get error for Z coordinate
     372           0 :   std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointProperties>::const_iterator cl=fClusters.find(clusterID);
     373           0 :   if (cl==fClusters.end() ||
     374           0 :       cl->second.GetCluster()==NULL) return 0.0;
     375           0 :   return cl->second.GetCluster()->GetSigmaTime2();
     376           0 : }
     377             : 
     378             : float AliHLTTPCRawSpacePointContainer::GetCharge(AliHLTUInt32_t clusterID) const
     379             : {
     380             :   // get charge
     381           0 :   std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointProperties>::const_iterator cl=fClusters.find(clusterID);
     382           0 :   if (cl==fClusters.end() ||
     383           0 :       cl->second.GetCluster()==NULL) return 0.0;
     384           0 :   return cl->second.GetCluster()->GetCharge();
     385           0 : }
     386             : 
     387             : float AliHLTTPCRawSpacePointContainer::GetQMax(AliHLTUInt32_t clusterID) const
     388             : {
     389             :   // get charge
     390           0 :   std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointProperties>::const_iterator cl=fClusters.find(clusterID);
     391           0 :   if (cl==fClusters.end() ||
     392           0 :       cl->second.GetCluster()==NULL) return 0.0;
     393           0 :   return cl->second.GetCluster()->GetQMax();
     394           0 : }
     395             : 
     396             : float AliHLTTPCRawSpacePointContainer::GetPhi(AliHLTUInt32_t clusterID) const
     397             : {
     398             :   // get charge
     399             : 
     400             :   // phi can be derived directly from the id, no need to search
     401             :   // for existing cluster
     402           0 :   int slice=AliHLTTPCSpacePointData::GetSlice(clusterID);
     403           0 :   return ( slice + 0.5 ) * TMath::Pi() / 9.0;
     404             : }
     405             : 
     406             : void AliHLTTPCRawSpacePointContainer::Clear(Option_t * option)
     407             : {
     408             :   // clear the object and reset pointer references
     409           0 :   fClusters.clear();
     410             : 
     411           0 :   for (std::map<AliHLTUInt32_t, vector<AliHLTUInt32_t>*>::iterator selection=fSelections.begin();
     412           0 :        selection!=fSelections.end(); selection++) {
     413           0 :     if (selection->second) delete selection->second;
     414             :   }
     415           0 :   fSelections.clear();
     416             : 
     417           0 :   for (std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointBlock>::iterator block=fBlocks.begin();
     418           0 :        block!=fBlocks.end(); block++) {
     419           0 :     if (block->second.GetGrid()) delete block->second.GetGrid();
     420             :   }
     421           0 :   fBlocks.clear();
     422             : 
     423           0 :   fSingleBlock.SetDecoder(NULL);
     424           0 :   if (fSingleBlock.GetGrid()) fSingleBlock.GetGrid()->Clear();
     425             : 
     426           0 :   AliHLTSpacePointContainer::Clear(option);
     427           0 : }
     428             : 
     429             : void AliHLTTPCRawSpacePointContainer::Print(ostream& out, Option_t */*option*/) const
     430             : {
     431             :   // print to stream
     432           0 :   std::stringstream str;
     433           0 :   str << "AliHLTTPCRawSpacePointContainer::Print" << endl;
     434           0 :   str << "n clusters: " << fClusters.size() << endl;
     435           0 :   for (std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointProperties>::const_iterator cl=fClusters.begin();
     436           0 :        cl!=fClusters.end(); cl++) {
     437           0 :     str << " 0x" << hex << setw(8) << setfill('0') << cl->first << dec << cl->second << endl;
     438             :   }
     439           0 :   out << str.rdbuf();
     440           0 : }
     441             : 
     442             : AliHLTSpacePointContainer* AliHLTTPCRawSpacePointContainer::SelectByMask(AliHLTUInt32_t mask, bool /*bAlloc*/) const
     443             : {
     444             :   /// create a collection of clusters for a space point mask
     445           0 :   std::auto_ptr<AliHLTTPCRawSpacePointContainer> c(new AliHLTTPCRawSpacePointContainer);
     446           0 :   if (!c.get()) return NULL;
     447             : 
     448           0 :   UInt_t slice=AliHLTTPCSpacePointData::GetSlice(mask);
     449           0 :   UInt_t partition=AliHLTTPCSpacePointData::GetPatch(mask);
     450           0 :   for (std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointProperties>::const_iterator cl=fClusters.begin();
     451           0 :        cl!=fClusters.end(); cl++) {
     452           0 :     UInt_t s=AliHLTTPCSpacePointData::GetSlice(cl->first);
     453           0 :     UInt_t p=AliHLTTPCSpacePointData::GetPatch(cl->first);
     454           0 :     if ((slice>=(unsigned)AliHLTTPCGeometry::GetNSlice() || s==slice) && 
     455           0 :         (partition>=(unsigned)AliHLTTPCGeometry::GetNumberOfPatches() || p==partition)) {
     456           0 :       c->fClusters[cl->first]=cl->second;
     457           0 :     }
     458             :   }
     459           0 :   return c.release();
     460           0 : }
     461             : 
     462             : AliHLTSpacePointContainer* AliHLTTPCRawSpacePointContainer::SelectByTrack(int trackId, bool /*bAlloc*/) const
     463             : {
     464             :   /// create a collection of clusters for a specific track
     465           0 :   std::auto_ptr<AliHLTTPCRawSpacePointContainer> c(new AliHLTTPCRawSpacePointContainer);
     466           0 :   if (!c.get()) return NULL;
     467             : 
     468           0 :   HLT::copy_map_if(fClusters.begin(), fClusters.end(), c->fClusters, HLT::AliHLTUnaryPredicate<AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties, int>(&AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties::GetTrackId,trackId));
     469           0 :   return c.release();
     470           0 : }
     471             : 
     472             : AliHLTSpacePointContainer* AliHLTTPCRawSpacePointContainer::SelectByMC(int mcId, bool /*bAlloc*/) const
     473             : {
     474             :   /// create a collection of clusters for a specific MC track
     475           0 :   std::auto_ptr<AliHLTTPCRawSpacePointContainer> c(new AliHLTTPCRawSpacePointContainer);
     476           0 :   if (!c.get()) return NULL;
     477             : 
     478           0 :   HLT::copy_map_if(fClusters.begin(), fClusters.end(), c->fClusters, HLT::AliHLTUnaryPredicate<AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties, int>(&AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties::GetMCId,mcId));
     479           0 :   return c.release();
     480           0 : }
     481             : 
     482             : AliHLTSpacePointContainer* AliHLTTPCRawSpacePointContainer::UsedClusters(bool /*bAlloc*/) const
     483             : {
     484             :   /// create a collection of all used clusters
     485           0 :   std::auto_ptr<AliHLTTPCRawSpacePointContainer> c(new AliHLTTPCRawSpacePointContainer);
     486           0 :   if (!c.get()) return NULL;
     487             : 
     488           0 :   HLT::copy_map_if(fClusters.begin(), fClusters.end(), c->fClusters, HLT::AliHLTUnaryPredicate<AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties, bool>(&AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties::IsUsed,true));
     489           0 :   return c.release();
     490           0 : }
     491             : 
     492             : AliHLTSpacePointContainer* AliHLTTPCRawSpacePointContainer::UnusedClusters(bool /*bAlloc*/) const
     493             : {
     494             :   /// create a collection of all unused clusters
     495           0 :   std::auto_ptr<AliHLTTPCRawSpacePointContainer> c(new AliHLTTPCRawSpacePointContainer);
     496           0 :   if (!c.get()) return NULL;
     497             : 
     498           0 :   HLT::copy_map_if(fClusters.begin(), fClusters.end(), c->fClusters, HLT::AliHLTUnaryPredicate<AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties, bool>(&AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties::IsUsed,false));
     499           0 :   return c.release();
     500           0 : }
     501             : 
     502             : int AliHLTTPCRawSpacePointContainer::MarkUsed(const AliHLTUInt32_t* clusterIDs, int arraySize)
     503             : {
     504             :   /// mark the clusters with specified IDs as used
     505           0 :   if (!clusterIDs) return -EINVAL;
     506             :   int iCount=0;
     507           0 :   for (int i=0; i<arraySize; i++) {
     508           0 :     if (fClusters.find(clusterIDs[i])==fClusters.end()) continue;
     509           0 :     fClusters[clusterIDs[i]].MarkUsed();
     510           0 :     iCount++;
     511           0 :   }
     512             :   return iCount;
     513           0 : }
     514             : 
     515             : int AliHLTTPCRawSpacePointContainer::SetTrackID(int trackID, const AliHLTUInt32_t* clusterIDs, int arraySize)
     516             : {
     517             :   /// set track id for specified clusters
     518           0 :   if (!clusterIDs) return -EINVAL;
     519             :   int iCount=0;
     520           0 :   for (int i=0; i<arraySize; i++) {
     521           0 :     if (fClusters.find(clusterIDs[i])==fClusters.end()) continue;
     522           0 :     fClusters[clusterIDs[i]].SetTrackId(trackID);
     523           0 :     iCount++;
     524           0 :   }
     525             :   return iCount;
     526           0 : }
     527             : 
     528             : int AliHLTTPCRawSpacePointContainer::GetTrackID(AliHLTUInt32_t clusterID) const
     529             : {
     530             :   /// get track id for specified cluster
     531           0 :   map<AliHLTUInt32_t, AliHLTTPCRawSpacePointProperties>::const_iterator element=fClusters.find(clusterID);
     532           0 :   if (element==fClusters.end()) return -1;
     533           0 :   return element->second.GetTrackId();
     534           0 : }
     535             : 
     536             : int AliHLTTPCRawSpacePointContainer::SetMCID(int mcID, const AliHLTUInt32_t* clusterIDs, int arraySize)
     537             : {
     538             :   /// set mc id for specified clusters
     539           0 :   if (!clusterIDs) return -EINVAL;
     540             :   int iCount=0;
     541           0 :   for (int i=0; i<arraySize; i++) {
     542           0 :     if (fClusters.find(clusterIDs[i])==fClusters.end()) continue;
     543           0 :     fClusters[clusterIDs[i]].SetMCId(mcID);
     544           0 :     iCount++;
     545           0 :   }
     546             :   return iCount;
     547           0 : }
     548             : 
     549             : int AliHLTTPCRawSpacePointContainer::Write(AliHLTUInt8_t* outputPtr,
     550             :                                             AliHLTUInt32_t size,
     551             :                                             AliHLTComponentBlockDataList&
     552             :                                             outputBlocks,
     553             :                                             AliHLTDataDeflater* pDeflater,
     554             :                                             const char* option) const
     555             : {
     556             :   /// write blocks to HLT component output
     557             :   AliHLTUInt32_t offset=0;
     558           0 :   if (outputBlocks.size()>0) {
     559           0 :     offset=outputBlocks.back().fOffset+outputBlocks.back().fSize;
     560           0 :   }
     561           0 :   return Write(outputPtr, size, offset, outputBlocks, pDeflater, option);
     562             : }
     563             : 
     564             : int AliHLTTPCRawSpacePointContainer::Write(AliHLTUInt8_t* outputPtr,
     565             :                                             AliHLTUInt32_t size,
     566             :                                             AliHLTUInt32_t offset,
     567             :                                             AliHLTComponentBlockDataList&
     568             :                                             outputBlocks,
     569             :                                             AliHLTDataDeflater* pDeflater,
     570             :                                             const char* option) const
     571             : {
     572             :   /// write blocks to HLT component output
     573           0 :   return WriteSorted(outputPtr, size, offset, outputBlocks, pDeflater, option);
     574             : }
     575             : 
     576             : int AliHLTTPCRawSpacePointContainer::WriteSorted(AliHLTUInt8_t* outputPtr,
     577             :                                                   AliHLTUInt32_t size,
     578             :                                                   AliHLTUInt32_t offset,
     579             :                                                   AliHLTComponentBlockDataList&
     580             :                                                   outputBlocks,
     581             :                                                   AliHLTDataDeflater* pDeflater,
     582             :                                                   const char* option) const
     583             : {
     584             :   /// write blocks to HLT component output
     585             :   int iResult=0;
     586             : 
     587           0 :   if (fMode&kModeSingle) {
     588           0 :     iResult=WriteSorted(outputPtr, size, offset, fSingleBlock.GetDecoder(), fSingleBlock.GetGrid(), fSingleBlock.GetId(), outputBlocks, pDeflater, option);
     589           0 :   } else {
     590             :     iResult=-ENOENT;
     591           0 :     for (std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointBlock>::const_iterator block=fBlocks.begin();
     592           0 :          block!=fBlocks.end(); block++) {
     593           0 :       AliHLTTPCRawClusterData* pDecoder=block->second.GetDecoder();
     594           0 :       AliHLTSpacePointPropertyGrid* pGrid=block->second.GetGrid();
     595           0 :       AliHLTUInt32_t mask=block->first;
     596             :       // FIXME: have to propagate the parameter which block is currently to be written
     597             :       // for now the index grid is only set for that one
     598           0 :       if (!pGrid) continue;
     599           0 :       iResult=WriteSorted(outputPtr, size, offset, pDecoder, pGrid, mask, outputBlocks, pDeflater, option);
     600           0 :       break; // only one is supposed to be written
     601             :     }
     602           0 :     if (iResult==-ENOENT) {
     603           0 :       HLTError("could not find the index grid of the partition to be written");
     604             :     }
     605             :   }
     606           0 :   return iResult;
     607             : }
     608             : 
     609             : int AliHLTTPCRawSpacePointContainer::WriteSorted(AliHLTUInt8_t* outputPtr,
     610             :                                                   AliHLTUInt32_t size,
     611             :                                                   AliHLTUInt32_t offset,
     612             :                                                   AliHLTTPCRawClusterData* pDecoder,
     613             :                                                   AliHLTSpacePointPropertyGrid* pGrid,
     614             :                                                   AliHLTUInt32_t mask,
     615             :                                                   AliHLTComponentBlockDataList&
     616             :                                                   outputBlocks,
     617             :                                                   AliHLTDataDeflater* pDeflater,
     618             :                                                   const char* option) const
     619             : {
     620             :   /// write blocks to HLT component output
     621             : 
     622           0 :   if (!outputPtr || !pDecoder || !pGrid) return -EINVAL;
     623           0 :   if (pDecoder->fCount==0) return 0;
     624           0 :   if (option) {
     625             :     // this is only for sending mc labels in simulation and testing
     626             :     // no impact to real running
     627           0 :     if (!fWrittenClusterIds && strcmp(option, "write-cluster-ids")==0) {
     628           0 :       const_cast<AliHLTTPCRawSpacePointContainer*>(this)->fWrittenClusterIds=new vector<AliHLTUInt32_t>;
     629           0 :     }
     630             :   }
     631             :   int iResult=0;
     632             :   const AliHLTUInt32_t capacity=size;
     633             :   size=0;
     634             : 
     635           0 :   int slice=AliHLTTPCSpacePointData::GetSlice(mask);
     636           0 :   int part=AliHLTTPCSpacePointData::GetPatch(mask);
     637             : 
     638             :   // Note: the offset parameter is only for the block descriptors, output pointer and size
     639             :   // consider already the offset
     640             : 
     641           0 :   if( fWrittenClusterIds ) fWrittenClusterIds->clear();
     642             : 
     643           0 :   if( capacity < sizeof(AliHLTTPCRawClusterData) ) return -ENOSPC;
     644             :  
     645           0 :   AliHLTTPCRawClusterData* blockout=reinterpret_cast<AliHLTTPCRawClusterData*>(outputPtr);
     646           0 :   blockout->fVersion=0;
     647           0 :   blockout->fCount=0;
     648             :  
     649             :   size = sizeof(AliHLTTPCRawClusterData);
     650             : 
     651           0 :   if (pDeflater) {
     652           0 :     pDeflater->Clear();
     653           0 :     pDeflater->InitBitDataOutput(reinterpret_cast<AliHLTUInt8_t*>(blockout->fClusters), capacity-size);
     654           0 :     blockout->fVersion=pDeflater->GetDeflaterVersion();
     655           0 :     if (fMode&kModeDifferentialPadTime) blockout->fVersion+=2;
     656             :   }
     657             : 
     658             :   unsigned lastPadRow=0;
     659             :   AliHLTUInt64_t lastPad64=0;
     660             :   AliHLTUInt64_t lastTime64=0;
     661           0 :   pDeflater->StartEncoder();
     662           0 :   AliHLTSpacePointPropertyGrid::iterator clusterID=pGrid->begin();
     663             : 
     664           0 :   for (; clusterID!=pGrid->end(); clusterID++) {
     665           0 :     if (clusterID.Data().fTrackId>-1) {
     666             :       // this is an assigned cluster, skip
     667             :       // TODO: introduce selectors into AliHLTIndexGrid::begin to loop
     668             :       // consistently over entries, e.g. this check has to be done also
     669             :       // in the forwarding of MC labels in
     670             :       // AliHLTTPCDataCompressionComponent::ForwardMCLabels
     671             :       continue;
     672             :     }
     673           0 :     if ((unsigned)slice!=AliHLTTPCSpacePointData::GetSlice(clusterID.Data().fId) ||
     674           0 :         (unsigned)part!=AliHLTTPCSpacePointData::GetPatch(clusterID.Data().fId)) {
     675           0 :       HLTError("cluster id 0x%08x out of slice %d partition %d", clusterID.Data().fId, slice, part);
     676             :       iResult = -EBADMSG;
     677           0 :       break;
     678             :     }
     679           0 :     int index=AliHLTTPCSpacePointData::GetNumber(clusterID.Data().fId);
     680             : 
     681           0 :     if( index<0 || index>= (int)pDecoder->fCount ){
     682           0 :       HLTError("cluster index %d id 0x%08x out of range %d", index, clusterID.Data().fId, (int)pDecoder->fCount);
     683             :       iResult = -EBADMSG;
     684           0 :       break;
     685             :       continue;
     686             :     }
     687             : 
     688           0 :     if( size + sizeof(AliHLTTPCRawCluster) > capacity ){
     689             :       iResult = -ENOSPC;
     690           0 :       break;
     691             :     }
     692             : 
     693           0 :     const AliHLTTPCRawCluster &input = pDecoder->fClusters[index];
     694             : 
     695             :     //const AliHLTTPCRawData::iterator& input=pDecoder->find(index);
     696             :     //if (!(input!=pDecoder->end())) continue;
     697           0 :     if (fWrittenClusterIds) fWrittenClusterIds->push_back(clusterID.Data().fId);
     698             : 
     699           0 :     int padrow=input.GetPadRow();
     700           0 :     float pad =input.GetPad();
     701           0 :     float time =input.GetTime();
     702           0 :     float sigmaY2=input.GetSigmaPad2();
     703           0 :     float sigmaZ2=input.GetSigmaTime2();
     704             : 
     705           0 :     if (padrow<0 || pad<0 || time<0 || sigmaY2<0 || sigmaZ2<0 ) {
     706             :       // something wrong here, padrow is stored in the cluster header
     707             :       // word which has bit pattern 0x3 in bits bit 30 and 31 which was
     708             :       // not recognized
     709           0 :       HLTError("wrong cluster data: padrow %d pad %f time %f sigmaY2 %f sigmaZ2 %f", padrow, pad, time, sigmaY2, sigmaZ2 );
     710             :       iResult = -EBADMSG;
     711           0 :       break;
     712             :     }
     713             : 
     714           0 :     if (!pDeflater) {
     715           0 :       AliHLTTPCRawCluster& c=blockout->fClusters[blockout->fCount];
     716           0 :       padrow+=AliHLTTPCGeometry::GetFirstRow(part);
     717           0 :       c.SetPadRow(padrow);
     718           0 :       c.SetCharge(input.GetCharge());
     719           0 :       c.SetPad(pad);  
     720           0 :       c.SetTime(time);
     721           0 :       c.SetSigmaPad2(sigmaY2);
     722           0 :       c.SetSigmaTime2(sigmaZ2);
     723           0 :       c.SetQMax(input.GetQMax());
     724           0 :       size += sizeof(AliHLTTPCRawCluster);
     725           0 :     } else {
     726           0 :       AliHLTUInt32_t oldSize = pDeflater->GetBitDataOutputSizeBytes(); 
     727             :       
     728           0 :       AliHLTUInt64_t padrow64=input.GetPadRow();
     729           0 :       if (padrow64==lastPadRow) {
     730           0 :         padrow64-=lastPadRow;
     731           0 :       } else if (padrow64>lastPadRow) {
     732           0 :         padrow64-=lastPadRow;
     733           0 :         lastPadRow+=padrow64;
     734             :       } else {
     735           0 :         HLTError("padrows are not ordered, skip data");
     736             :         iResult = -EBADMSG;
     737           0 :         break;
     738             :       }
     739             :       
     740           0 :       AliHLTUInt32_t padType=0;
     741           0 :       AliHLTUInt32_t signdPad=0;
     742           0 :       AliHLTUInt64_t pad64=0;
     743           0 :       if ((fMode&kModeDifferentialPadTime)!=0 && sigmaY2<.00001) {
     744             :         // single pad cluster
     745             :         // use twice the pad position to take account for the 0.5 offset
     746             :         // added in the AliHLTTPCRawData decoder in accordance with the
     747             :         // offline definition. Using the factor 2, this offset is not
     748             :         // cut off by rounding
     749           0 :         pad64=(AliHLTUInt64_t)round(2*pad);
     750           0 :         padType=1;
     751           0 :       } else {
     752           0 :         if (!isnan(pad)) pad64=(AliHLTUInt64_t)round(pad*AliHLTTPCDefinitions::fgkClusterParameterDefinitions[AliHLTTPCDefinitions::kPad].fScale);
     753             :       }
     754           0 :       if (fMode&kModeDifferentialPadTime && padType==0) {
     755             :         AliHLTUInt64_t dpad64=0;
     756           0 :         if (pad64<lastPad64) {
     757           0 :           dpad64=lastPad64-pad64;
     758           0 :           signdPad=1;
     759           0 :         } else {
     760           0 :           dpad64=pad64-lastPad64;
     761           0 :           signdPad=0;
     762             :         }
     763           0 :         lastPad64=pad64;
     764           0 :         pad64=dpad64;
     765           0 :       }
     766           0 :       AliHLTUInt32_t signdTime=0;
     767           0 :       AliHLTUInt64_t time64=0;
     768           0 :       if (!isnan(time)) time64=(AliHLTUInt64_t)round(time*AliHLTTPCDefinitions::fgkClusterParameterDefinitions[AliHLTTPCDefinitions::kTime].fScale);
     769           0 :       if (fMode&kModeDifferentialPadTime) {
     770             :         AliHLTUInt64_t dtime64=0;
     771           0 :         if (time64<lastTime64) {
     772           0 :           dtime64=lastTime64-time64;
     773           0 :           signdTime=1;
     774           0 :         } else {
     775           0 :           dtime64=time64-lastTime64;
     776           0 :           signdTime=0;
     777             :         }
     778           0 :         lastTime64=time64;
     779           0 :         time64=dtime64;
     780           0 :       }
     781           0 :       AliHLTUInt64_t sigmaY264=0;
     782           0 :       if (!isnan(sigmaY2)) sigmaY264=(AliHLTUInt64_t)round(sigmaY2*AliHLTTPCDefinitions::fgkClusterParameterDefinitions[AliHLTTPCDefinitions::kSigmaY2].fScale);
     783             :       // we can safely use the upper limit as this is an unphysical cluster, no impact to physics
     784           0 :       if (sigmaY264 >= (unsigned)1<<AliHLTTPCDefinitions::fgkClusterParameterDefinitions[AliHLTTPCDefinitions::kSigmaY2].fBitLength) {
     785           0 :         sigmaY264 = (1<<AliHLTTPCDefinitions::fgkClusterParameterDefinitions[AliHLTTPCDefinitions::kSigmaY2].fBitLength)-1;
     786           0 :       }
     787           0 :       AliHLTUInt64_t sigmaZ264=0;
     788           0 :       if (!isnan(sigmaZ2)) sigmaZ264=(AliHLTUInt64_t)round(sigmaZ2*AliHLTTPCDefinitions::fgkClusterParameterDefinitions[AliHLTTPCDefinitions::kSigmaZ2].fScale);
     789             :       // we can safely use the upper limit as this is an unphysical cluster, no impact to physics
     790           0 :       if (sigmaZ264 >= (unsigned)1<<AliHLTTPCDefinitions::fgkClusterParameterDefinitions[AliHLTTPCDefinitions::kSigmaZ2].fBitLength) {
     791           0 :         sigmaZ264 = (1<<AliHLTTPCDefinitions::fgkClusterParameterDefinitions[AliHLTTPCDefinitions::kSigmaZ2].fBitLength)-1;
     792           0 :       }
     793           0 :       pDeflater->OutputParameterBits(AliHLTTPCDefinitions::kPadRow , padrow64);
     794           0 :       pDeflater->OutputParameterBits(AliHLTTPCDefinitions::kPad    , pad64);
     795           0 :       if (fMode&kModeDifferentialPadTime) pDeflater->OutputBit(padType);
     796           0 :       if (fMode&kModeDifferentialPadTime && padType==0) pDeflater->OutputBit(signdPad);
     797           0 :       pDeflater->OutputParameterBits(AliHLTTPCDefinitions::kTime   , time64);
     798           0 :       if (fMode&kModeDifferentialPadTime) pDeflater->OutputBit(signdTime);
     799           0 :       if (padType==0) pDeflater->OutputParameterBits(AliHLTTPCDefinitions::kSigmaY2, sigmaY264);
     800           0 :       pDeflater->OutputParameterBits(AliHLTTPCDefinitions::kSigmaZ2, sigmaZ264);
     801           0 :       pDeflater->OutputParameterBits(AliHLTTPCDefinitions::kCharge , input.GetCharge());
     802           0 :       pDeflater->OutputParameterBits(AliHLTTPCDefinitions::kQMax   , input.GetQMax());
     803             :       
     804           0 :       size += pDeflater->GetBitDataOutputSizeBytes() - oldSize;
     805           0 :     }
     806           0 :     blockout->fCount++;
     807           0 :   }
     808           0 :   pDeflater->StopEncoder();
     809           0 :   AliHLTComponent_BlockData bd;
     810           0 :   AliHLTComponent::FillBlockData(bd);
     811           0 :   bd.fOffset        = offset;
     812           0 :   if (!pDeflater) {
     813           0 :     bd.fSize        = sizeof(AliHLTTPCRawClusterData)+blockout->fCount*sizeof(AliHLTTPCRawCluster);
     814           0 :     bd.fDataType    = AliHLTTPCDefinitions::fgkRawClustersDataTypeNotCompressed;
     815           0 :   } else {
     816           0 :     pDeflater->Pad8Bits();
     817           0 :     bd.fSize        = sizeof(AliHLTTPCRawClusterData)+pDeflater->GetBitDataOutputSizeBytes();
     818           0 :     pDeflater->CloseBitDataOutput();
     819           0 :     bd.fDataType    = AliHLTTPCDefinitions::RemainingClustersCompressedDataType();
     820             :   }
     821           0 :   bd.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification(slice, slice, part, part);
     822             : 
     823           0 :   if (iResult>=0 && bd.fSize+size<=capacity) {
     824           0 :     outputBlocks.push_back(bd);
     825           0 :     size = bd.fSize;
     826           0 :   } else {
     827             :     iResult=-ENOSPC;
     828             :   }
     829             :   
     830           0 :   if (iResult >= 0 && fCreateFlags)
     831             :   {
     832           0 :     if (size + sizeof(AliHLTTPCClusterFlagsData) > capacity)
     833             :     {
     834             :       iResult = -ENOSPC;
     835           0 :     }
     836             :     else
     837             :     {
     838           0 :       AliHLTComponent::FillBlockData(bd);
     839           0 :       bd.fOffset = size + offset;
     840           0 :       bd.fDataType = AliHLTTPCDefinitions::ClustersFlagsDataType();
     841           0 :       bd.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification(slice, slice, part, part);
     842             :  
     843           0 :       AliHLTTPCClusterFlagsData* clusterFlagsData = (AliHLTTPCClusterFlagsData*) (outputPtr + size);
     844           0 :       clusterFlagsData->fVersion = 1;
     845           0 :       clusterFlagsData->fNumberOfFlags = 2;
     846             : 
     847             :       unsigned int tmpVal = 0;
     848             :       unsigned int tmppos = 0;
     849             :       unsigned int nEntries = 0;
     850             :       unsigned int nClusters = 0;
     851           0 :       for (AliHLTSpacePointPropertyGrid::iterator clusterID=pGrid->begin(); clusterID!=pGrid->end(); clusterID++)
     852             :       {
     853           0 :         if (clusterID.Data().fTrackId>-1) continue;  //Cannot handle clusters associated to tracks yet
     854             : 
     855           0 :         if (size + sizeof(AliHLTTPCClusterFlagsData) + (nEntries + 2) * sizeof(tmpVal) > capacity)
     856             :         {
     857             :           iResult = -ENOSPC;
     858           0 :           break;
     859             :         }
     860             : 
     861           0 :         int index=AliHLTTPCSpacePointData::GetNumber(clusterID.Data().fId);
     862           0 :         const AliHLTTPCRawCluster &input = pDecoder->fClusters[index];
     863             : 
     864           0 :         unsigned int tmpFlags = input.fFlags & ((1 << clusterFlagsData->fNumberOfFlags) - 1);
     865           0 :         tmpVal |= tmpFlags << tmppos;
     866           0 :         tmppos += clusterFlagsData->fNumberOfFlags;
     867           0 :         nClusters++;
     868           0 :         if (tmppos >= sizeof(tmpVal) * 8)
     869             :         {
     870           0 :           tmppos -= sizeof(tmpVal) * 8;
     871           0 :           ((unsigned int*) clusterFlagsData->fData)[nEntries++] = tmpVal;
     872             :           tmpVal = 0;
     873           0 :           if (tmppos) tmpVal |= tmpFlags >> (clusterFlagsData->fNumberOfFlags - tmppos);
     874             :         }
     875           0 :       }
     876           0 :       if (iResult >= 0)
     877             :       {
     878           0 :         if (tmppos) ((unsigned int*) clusterFlagsData->fData)[nEntries++] = tmpVal;
     879           0 :         clusterFlagsData->fNumberOfClusters = nClusters;
     880           0 :         bd.fSize = sizeof(AliHLTTPCClusterFlagsData) + nEntries * sizeof(tmpVal);
     881           0 :         outputBlocks.push_back(bd);
     882           0 :         size += bd.fSize;
     883           0 :       }
     884             :     }
     885             :   }
     886             : 
     887           0 :   if ( (iResult>=0) && fWrittenClusterIds && (fWrittenClusterIds->size()>0) ) {
     888           0 :     AliHLTComponent::FillBlockData(bd);
     889           0 :     bd.fOffset        = size+offset;
     890           0 :     bd.fSize        = fWrittenClusterIds->size()*sizeof(vector<AliHLTUInt32_t>::value_type);
     891           0 :     if (bd.fSize+size<=capacity) {
     892           0 :       memcpy(outputPtr+size, &(*fWrittenClusterIds)[0], bd.fSize);
     893           0 :       bd.fDataType    = AliHLTTPCDefinitions::RemainingClusterIdsDataType();
     894           0 :       bd.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification(slice, slice, part, part);
     895           0 :       outputBlocks.push_back(bd);    
     896           0 :       size += bd.fSize;
     897           0 :     } else {
     898             :       iResult=-ENOSPC;
     899             :     }
     900             :   }
     901             :   
     902           0 :   if (fWrittenClusterIds ) fWrittenClusterIds->clear();
     903             :  
     904           0 :   if (iResult<0) return iResult;
     905           0 :   return size;
     906           0 : }
     907             : 
     908             : AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties::AliHLTTPCRawSpacePointProperties()
     909           0 :   : fpCluster(NULL)
     910           0 :   , fUsed(false)
     911           0 :   , fTrackId(-1)
     912           0 :   , fMCId(-1)
     913           0 : {
     914             :   // constructor
     915           0 : }
     916             : 
     917             : AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties::AliHLTTPCRawSpacePointProperties(const AliHLTTPCRawCluster* pCluster)
     918           0 :   : fpCluster(pCluster)
     919           0 :   , fUsed(false)
     920           0 :   , fTrackId(-1)
     921           0 :   , fMCId(-1)
     922           0 : {
     923             :   // constructor
     924           0 : }
     925             : 
     926             : AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties::AliHLTTPCRawSpacePointProperties(const AliHLTTPCRawSpacePointProperties& src)
     927           0 :   : fpCluster(src.fpCluster)
     928           0 :   , fUsed(src.fUsed)
     929           0 :   , fTrackId(src.fTrackId)
     930           0 :   , fMCId(src.fMCId)
     931           0 : {
     932             :   // copy constructor
     933           0 : }
     934             : 
     935             : AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties& AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties::operator=(const AliHLTTPCRawSpacePointProperties& src)
     936             : {
     937             :   // assignment operator
     938           0 :   if (&src==this) return *this;
     939           0 :   fpCluster=src.fpCluster;
     940           0 :   fUsed=src.fUsed;
     941           0 :   fTrackId=src.fTrackId;
     942           0 :   fMCId=src.fMCId;
     943             : 
     944           0 :   return *this;
     945           0 : }
     946             : 
     947             : void AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties::Print(ostream& out, Option_t */*option*/) const
     948             : {
     949             :   // print info
     950           0 :   if (!fpCluster) {
     951           0 :     out << "no data";
     952           0 :     return;
     953             :   }
     954           0 :   std::stringstream str;
     955             : 
     956           0 :   str.setf(ios::fixed,ios::floatfield);
     957           0 :   str << " " << setfill(' ') << setw(3) << fpCluster->GetPadRow() 
     958           0 :       << " " << setw(8) << setprecision(3) << fpCluster->GetPad()
     959           0 :       << " " << setw(8) << setprecision(3) << fpCluster->GetTime()
     960           0 :       << " " << setw(8) << setprecision(1) << fpCluster->GetSigmaPad2() 
     961           0 :       << " " << setw(9) << setprecision(1) << fpCluster->GetSigmaTime2()
     962           0 :       << " " << setw(5) << fpCluster->GetCharge() 
     963           0 :       << " " << setw(5) << fpCluster->GetQMax()
     964           0 :       << " " << fTrackId << " " << fMCId << " " << fUsed;
     965           0 :   out << str.rdbuf();
     966           0 : }
     967             : 
     968             : ostream& operator<<(ostream &out, const AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties& p)
     969             : {
     970           0 :   p.Print(out);
     971           0 :   return out;
     972             : }

Generated by: LCOV version 1.11