LCOV - code coverage report
Current view: top level - HLT/TPCLib/HWCFemulator - AliHLTTPCHWClusterMerger.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 59 1.7 %
Date: 2016-06-14 17:26:59 Functions: 1 48 2.1 %

          Line data    Source code
       1             : //-*- Mode: C++ -*-
       2             : // $Id$
       3             : 
       4             : #ifndef ALIHLTTPCHWCLUSTERMERGER_H
       5             : #define ALIHLTTPCHWCLUSTERMERGER_H
       6             : //* This file is property of and copyright by the ALICE HLT Project        * 
       7             : //* ALICE Experiment at CERN, All rights reserved.                         *
       8             : //* See cxx source for full Copyright notice                               *
       9             : 
      10             : //  @file   AliHLTTPCHWClusterMerger.h
      11             : //  @author Matthias Richter, Sergey Gorbunov
      12             : //  @date   2011-11-25
      13             : //  @brief  Merger class for HLT TPC Hardware clusters
      14             : //          Handles merging of branch border clusters
      15             : 
      16             : #include "AliHLTTPCRawCluster.h"
      17             : #include "AliHLTTPCClusterMCData.h"
      18             : #include "AliHLTLogging.h"
      19             : #include <vector>
      20             : #include "TObject.h"
      21             : 
      22             : /**
      23             :  * @class AliHLTTPCHWClusterMerger
      24             :  *
      25             :  * @ingroup alihlt_base
      26             :  */
      27             : class AliHLTTPCHWClusterMerger : public AliHLTLogging
      28             : {
      29             :  public:
      30             :   /// standard constructor
      31             :   AliHLTTPCHWClusterMerger();
      32             :   /// destructor
      33             :   ~AliHLTTPCHWClusterMerger();
      34             : 
      35             :   void Init();
      36             : 
      37             :   //////////////////////////////////////////////////////////////////////////////////////////////////////////
      38             :   //////////////////////////////////////////////////////////////////////////////////////////////////////////
      39             : 
      40             :   /// check if a cluster is a candidate for merging
      41             :   template<typename T> 
      42             :   bool CheckCandidate(int slice, int partition, const T& c) {
      43           0 :     return CheckCandidate(slice, partition, c.GetPadRow(), c.GetPad(), c.GetTime(), c.GetSigmaPad2() );
      44             :   }
      45             : 
      46             :   /// check if a cluster is a candidate for merging
      47             :   bool CheckCandidate(int slice,
      48             :                       int partition,
      49             :                       int partitionrow, // local row in partition
      50             :                       float pad,
      51             :                       float time,
      52             :                       float sigmaPad2) ;
      53             : 
      54             :   /// cache cluster for later merging
      55             :   template<typename T> 
      56             :   int AddCandidate(int slice,
      57             :                    int partition,
      58             :                    AliHLTUInt32_t id,
      59             :                    const T& c) {
      60             :     return AddCandidate(slice,
      61             :                         partition,
      62             :                         c.GetPadRow(),
      63             :                         c.GetPad(),
      64             :                         c.GetTime(),
      65             :                         c.GetSigmaY2(),
      66             :                         c.GetSigmaZ2(),
      67             :                         c.GetCharge(),
      68             :                         c.GetQMax(),
      69             :                         c.GetFlags(),
      70             :                         id
      71             :                         );
      72             :   }
      73             : 
      74             :   // cache cluster for later merging
      75             :   template<typename T> 
      76             :   int AddCandidate(int slice,
      77             :                    int partition,
      78             :                    AliHLTUInt32_t id,
      79             :                    const T& c,
      80             :                    const AliHLTTPCClusterMCLabel *mc) {
      81           0 :     return AddCandidate(slice,
      82             :                         partition,
      83           0 :                         c.GetPadRow(),
      84           0 :                         c.GetPad(),
      85           0 :                         c.GetTime(),
      86           0 :                         c.GetSigmaPad2(),
      87           0 :                         c.GetSigmaTime2(),
      88           0 :                         c.GetCharge(),
      89           0 :                         c.GetQMax(),
      90           0 :                         c.GetFlags(),
      91             :                         id,
      92             :                         mc
      93             :                         );
      94             :   }
      95             : 
      96             :   /// cache cluster for later merging
      97             :   int AddCandidate(int slice,
      98             :                    int partition,
      99             :                    short partitionrow, // local row in the partition
     100             :                    float pad,
     101             :                    float time,
     102             :                    float sigmaY2,
     103             :                    float sigmaZ2,
     104             :                    unsigned short charge,
     105             :                    unsigned short qmax,
     106             :                    unsigned short flags,
     107             :                    AliHLTUInt32_t id=~AliHLTUInt32_t(0),
     108             :                    const AliHLTTPCClusterMCLabel *mc=NULL
     109             :                    );
     110             : 
     111             :   /// merge clusters
     112             :   int Merge();
     113             : 
     114             :   /// cleanup
     115             :   void Clear();
     116             : 
     117             :   //////////////////////////////////////////////////////////////////////////////////////////////////////////
     118             :   //////////////////////////////////////////////////////////////////////////////////////////////////////////
     119             : 
     120             :   /// helper class to store relevant data for a cluster at border
     121             :   struct AliBorderRecord {
     122             :     AliHLTInt64_t fClusterRecordID;
     123             :     AliHLTUInt32_t fTimeBin;    
     124             :   };
     125             :  
     126             :   
     127             :   /// helper class to store relevant data for a cluster candidate
     128             :   class AliClusterRecord {
     129             :   public:
     130             :     AliClusterRecord()
     131             :       : fSlice(-1), fPartition(-1), fBorder(-1), fMergedFlag(-1), fId(~AliHLTUInt32_t(0)), fCluster(), fMC() {}
     132             :     AliClusterRecord(int slice, int partition, int border,int merged, AliHLTUInt32_t id, const AliHLTTPCRawCluster &cluster)
     133             :       : fSlice(slice), fPartition(partition), fBorder(border), fMergedFlag(merged), fId(id), fCluster(cluster), fMC() {}
     134             :     AliClusterRecord(int slice, int partition, int border,int merged, AliHLTUInt32_t id, const AliHLTTPCRawCluster &cluster, const AliHLTTPCClusterMCLabel &mc)
     135           0 :       : fSlice(slice), fPartition(partition), fBorder(border), fMergedFlag(merged), fId(id), fCluster(cluster), fMC(mc) {}
     136             : 
     137             :     AliClusterRecord(const AliClusterRecord& other)
     138           0 :       : fSlice(other.fSlice), fPartition(other.fPartition), fBorder(other.fBorder), fMergedFlag(other.fMergedFlag), fId(other.fId), fCluster(other.fCluster), fMC(other.fMC) {}
     139             :     AliClusterRecord& operator=(const AliClusterRecord& other) {
     140             :       if (this==&other) return *this;
     141             :       this->~AliClusterRecord();
     142             :       new (this) AliClusterRecord(other);
     143             :       return *this;
     144             :     }
     145             : 
     146           0 :     ~AliClusterRecord() {}    
     147             :     
     148             :     AliClusterRecord& operator=(const AliHLTTPCRawCluster& c) {
     149             :       fCluster=c;
     150             :       return *this;
     151             :     }
     152             : 
     153           0 :     int IsMergedTo() const { return fMergedFlag; }
     154           0 :     int GetSlice() const {return fSlice;}
     155           0 :     int GetBorder() const {return fBorder;}
     156           0 :     int GetPartition() const {return fPartition;}
     157           0 :     AliHLTUInt32_t GetId() const {return fId;}
     158             :     operator AliHLTTPCRawCluster() const {return fCluster;}
     159           0 :     const AliHLTTPCRawCluster& GetCluster() const {return fCluster;}
     160           0 :     const AliHLTTPCClusterMCLabel& GetMCLabel() const {return fMC;}
     161           0 :     void SetMergedTo( int ind ){ fMergedFlag = ind;}
     162           0 :     AliHLTTPCRawCluster &Cluster(){ return fCluster; }
     163           0 :     AliHLTTPCClusterMCLabel& MCLabel(){ return fMC; }
     164             :   private:
     165             :     int fSlice; //!
     166             :     int fPartition; //!
     167             :     int fBorder; //!
     168             :     int fMergedFlag; //!
     169             :     AliHLTUInt32_t fId; //!
     170             :     AliHLTTPCRawCluster fCluster; //!
     171             :     AliHLTTPCClusterMCLabel fMC; //!
     172             :   };
     173             : 
     174             :   //////////////////////////////////////////////////////////////////////////////////////////////////////////
     175             :   //////////////////////////////////////////////////////////////////////////////////////////////////////////
     176             : 
     177             :   /// iterator class to access merged and remaining clusters
     178             :   class iterator {
     179             :   public:
     180           0 :     iterator() : fArray(NULL), fIter() {}
     181           0 :     iterator(vector<AliClusterRecord>* pArray) : fArray(pArray), fIter() {if (fArray) fIter=fArray->begin();}
     182           0 :     iterator(const iterator& other) : fArray(other.fArray), fIter(other.fIter) {}
     183             :     iterator& operator=(const iterator& other) {
     184           0 :       if (this==&other) return *this;
     185           0 :       fArray=other.fArray; fIter=other.fIter; return *this;
     186           0 :     }
     187           0 :     ~iterator() {}
     188             : 
     189           0 :     AliClusterRecord& operator*() {return *fIter;}
     190             : 
     191             :     // prefix operators
     192             :     iterator& operator++() {
     193           0 :       if (!fArray || fIter==fArray->end()) return *this;
     194           0 :       while ((++fIter)!=fArray->end()) {
     195           0 :         if ( fIter->IsMergedTo()<0 ) break;       
     196             :       }      
     197           0 :       return *this;
     198           0 :     }
     199             :     iterator& operator--() {
     200             :       if (!fArray) return *this;
     201             :       while (fIter!=fArray->begin()) {
     202             :         --fIter;
     203             :         if ( fIter->IsMergedTo()<0 ) break;       
     204             :       }
     205             :       return *this;
     206             :     }
     207             : 
     208             :     // postfix operators
     209           0 :     iterator operator++(int) {iterator i(*this); this->operator++(); return i;}
     210             :     iterator operator--(int) {iterator i(*this); this->operator--(); return i;}
     211             : 
     212             :     iterator& operator+=(int step) {
     213           0 :       if (!fArray) return *this;
     214           0 :       while ((fIter)!=fArray->end() && step-->0) {++fIter;}
     215           0 :       return *this;
     216           0 :     }
     217             : 
     218             :     bool operator==(const iterator& other) {
     219             :       return (other.fArray!=NULL && fArray!=NULL && other.fIter==fIter);
     220             :     }
     221             : 
     222             :     bool operator!=(const iterator& other) {
     223           0 :       return (other.fArray!=NULL && fArray!=NULL && other.fIter!=fIter);
     224             :     }
     225             : 
     226             :   protected:
     227             :   private:
     228             :     vector<AliClusterRecord>* fArray; //!
     229             :     vector<AliClusterRecord>::iterator fIter; //!
     230             :   };
     231             : 
     232             :   //////////////////////////////////////////////////////////////////////////////////////////////////////////
     233             :   //////////////////////////////////////////////////////////////////////////////////////////////////////////
     234             : 
     235             :   /// iterator function, start iteration
     236             :   iterator& begin() {
     237           0 :     fIter.~iterator();
     238           0 :     new (&fIter) iterator(&fClusters);
     239           0 :     fEnd=fIter;  fEnd+=fClusters.size();    
     240             :     // skip empty (merged) clusters
     241           0 :     while (fIter!=fEnd && ( (*fIter).IsMergedTo()>=0) ) {
     242           0 :       fIter++;
     243             :     }
     244           0 :     return fIter;
     245             :   }
     246             : 
     247             :   /// iterator function, end marker
     248             :   iterator& end() {
     249           0 :     return fEnd;
     250             :   }
     251             : 
     252           0 :   const vector<AliHLTTPCHWClusterMerger::AliClusterRecord> &GetRecords(){ return fClusters; }
     253           0 :   static int GetNSlices(){ return fkNSlices; }
     254           0 :   int GetNBorders() const { return fNBorders; }
     255           0 :   int GetBorderNClusters( int ib ) const { return fBorderNClusters[ib]; }
     256           0 :   int GetBorderFirstCluster( int ib ) const { return fBorderFirstCluster[ib]; }
     257           0 :   const AliHLTTPCHWClusterMerger::AliBorderRecord *GetBorderClusters() const { return fBorderClusters;}
     258             : 
     259             :   //////////////////////////////////////////////////////////////////////////////////////////////////////////
     260             :   //////////////////////////////////////////////////////////////////////////////////////////////////////////
     261             : 
     262             :  protected:
     263             : 
     264             :  private:
     265             :   /// copy constructor
     266             :   AliHLTTPCHWClusterMerger(const AliHLTTPCHWClusterMerger&);
     267             :   /// assignment operator
     268             :   AliHLTTPCHWClusterMerger& operator=(const AliHLTTPCHWClusterMerger&);
     269             : 
     270             :   int FillIndex();
     271             :   static bool CompareTime( const AliBorderRecord &b1, const AliBorderRecord &b2){
     272           0 :     return b1.fTimeBin > b2.fTimeBin;
     273             :   }
     274             :  
     275             :   static bool CompareMCWeights(const AliHLTTPCClusterMCWeight &a, const AliHLTTPCClusterMCWeight &b){
     276           0 :     return a.fWeight > b.fWeight;
     277             :   }
     278             :   static bool CompareMCLabels(const AliHLTTPCClusterMCWeight &a, const AliHLTTPCClusterMCWeight &b){
     279           0 :     return a.fMCID < b.fMCID;
     280             :   }
     281             : 
     282             :   AliHLTInt16_t *fMapping;//!
     283             :   int fNRows;//!
     284             :   int fNRowPads;//!
     285             :   int fNBorders;//!
     286             :   AliHLTFloat32_t *fBorders; //!
     287             :   int *fBorderNClusters; //!
     288             :   int *fBorderFirstCluster; //!
     289             :   AliBorderRecord *fBorderClusters;
     290             :   int fBorderNClustersTotal; //!
     291             : 
     292             :   vector<AliClusterRecord> fClusters; //! array of candidates
     293             :   vector<AliHLTUInt32_t> fRemovedClusterIds; //! array of removed clusters by id
     294             :   iterator fIter; //!
     295             :   iterator fEnd; //!
     296             :   static const int fkMergeWidth = 3;
     297             :   static const int fkNSlices = 36;
     298             :   static const int fkMergeTimeWindow = 3;
     299           6 :   ClassDef(AliHLTTPCHWClusterMerger, 0)
     300             : };
     301             : 
     302             : #endif //ALIHLTTPCHWCLUSTERMERGER_H

Generated by: LCOV version 1.11