]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCClusterAccessHLTOUT.h
minor compilation warning fixed
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCClusterAccessHLTOUT.h
1 //-*- Mode: C++ -*-
2 // $Id$
3 #ifndef ALIHLTTPCCLUSTERACCESSHLTOUT_H
4 #define ALIHLTTPCCLUSTERACCESSHLTOUT_H
5 //* This file is property of and copyright by the ALICE Project            * 
6 //* ALICE Experiment at CERN, All rights reserved.                         *
7 //* See cxx source for full Copyright notice                               *
8
9 /// @file   AliHLTTPCClusterAccessHLTOUT.h
10 /// @author Matthias Richter
11 /// @date   2011-06-06
12 /// @brief  Interface to HLT TPC clusters
13 ///
14
15 #include "TObject.h"
16 #include "AliHLTDataTypes.h"
17 #include "AliHLTTPCClusterMCData.h"
18 #include "AliHLTTPCRawCluster.h"
19 #include <map>
20
21 class AliTPCParam;
22 class AliTPCClustersRow;
23 class AliTPCclusterMI;
24 class AliHLTOUT;
25 class TClonesArray;
26 class AliHLTTPCDataCompressionDecoder;
27
28 /**
29  * @class AliHLTTPCClusterAccessHLTOUT
30  * Generator for TPC cluster array from HLT TPC clusters in the HLTOUT
31  * data stream. It uses the TObject method interface. Combined with dynamic
32  * loading, any cross dependency between the TPC code and HLT libraries
33  * can be avoided.
34  *
35  * Creating the instance: 
36  * The class is implemented in libAliHLTTPC.so and can be loaded
37  * through the TClass interface (you might want to add
38  * further error messages on the various error conditions).
39  * <pre>
40  *     TObject* pClusterAccess=NULL;
41  *     TClass* pCl=NULL;
42  *     ROOT::NewFunc_t pNewFunc=NULL;
43  *     do {
44  *       pCl=TClass::GetClass("AliHLTTPCClusterAccessHLTOUT");
45  *     } while (!pCl && gSystem->Load("libAliHLTTPC.so")==0);
46  *     if (pCl && (pNewFunc=pCl->GetNew())!=NULL) {
47  *       void* p=(*pNewFunc)(NULL);
48  *       if (p) {
49  *         pClusterAccess=reinterpret_cast<TObject*>(p);
50  *       }
51  *     }
52  * </pre>
53  * 
54  * Usage:
55  * TObject::Execute can be used to execute commands. Command 'read'
56  * will get hold on the HLTOUT data and read the clusters. The const char*
57  * parameter 'param' is used to select the region.
58  * - param="sector=sectorno"
59  * 'sectorno' specifies sector number in the offline code, range 0 and 71,
60  * enumerating first the 36 inner (partitions 0+1)  and then 36 outer sectors
61  * (partitions 2-5).<br>
62  * If the error pointer parameter is provided the result code is returned
63  * - >=0 success, number of clusters
64  * - -ENODATA  no data in HLTOUT
65  * - -EINVAL   invalid parameter/argument
66  * - -ENOMEM   memory allocation failed
67  * - -EACCESS  no access to HLTOUT
68  * - -NODEV    internal error, can not get AliHLTSystem
69  * - -ENOBUFS  internal error, can not get cluster array
70  * 
71  * Command 'verbosity=level' sets the verbositylevel which is default 0
72  * (no info output).
73  *
74  * <pre>
75  *     pClusterAccess->Execute("read", param);
76  *     TObject* pClusterAccess->FindObject("clusterarray");
77  * </pre>
78  *
79  * After processing the loop of sectors, the instance should be cleaned.
80  * <pre>
81  *     pClusterAccess->Clear("event");
82  * </pre>
83  * 
84  * @ingroup alihlt_tpc
85  */
86 class AliHLTTPCClusterAccessHLTOUT : public TObject
87 {
88  public:
89   /** standard constructor */
90   AliHLTTPCClusterAccessHLTOUT();
91   /** destructor */
92   ~AliHLTTPCClusterAccessHLTOUT();
93
94   /// inherited from TObject: abstract command interface
95   virtual void        Execute(const char *method,  const char *params, Int_t *error=0);
96
97   /// inherited from TObject: return the cluster array if name id "clusterarray"
98   virtual TObject    *FindObject(const char *name) const;
99
100   /// inherited from TObject: supports writing of data to AliTPCClustersRow
101   virtual void Copy(TObject &object) const;
102
103   /// inherited from TObject: cleanup
104   virtual void        Clear(Option_t * option ="");
105
106   /// inherited from TObject
107   virtual void        Print(Option_t *option="") const;
108
109   /// process the cluster data block of various formats from HLTOUT
110   int ProcessClusters(const char* params);
111
112   /// helper struct to store cluster pointers in a map together with MC info
113   struct AliRawClusterEntry {
114     AliRawClusterEntry() : fCluster(NULL), fMC(NULL) {}
115     AliRawClusterEntry(AliHLTTPCRawCluster* pCluster) : fCluster(pCluster), fMC(NULL) {}
116     AliRawClusterEntry(const AliRawClusterEntry& other) : fCluster(other.fCluster), fMC(other.fMC) {}
117     AliRawClusterEntry& operator=(const AliRawClusterEntry& other) {
118       if (&other==this) return *this;
119       fCluster=other.fCluster; fMC=other.fMC;
120       return *this;
121     }
122     AliHLTTPCRawCluster* fCluster; //! pointer to cluster in the array of all clusters
123     const AliHLTTPCClusterMCLabel* fMC; //! pointer to corresponding MC data in HLTOUT block 
124   };
125   
126   typedef vector<AliHLTTPCRawCluster> AliHLTTPCRawClusterVector;
127   typedef vector<AliRawClusterEntry> AliRawClusterEntryVector;
128
129   /**
130    * @class AliRawClusterContainer
131    * Cluster read interface for offline.
132    * The class implements the interface to be used in the decoding
133    * of compressed TPC data.
134    */
135   class AliRawClusterContainer {
136   public:
137     AliRawClusterContainer();
138     virtual ~AliRawClusterContainer();
139
140     struct AliClusterIdBlock {
141       AliClusterIdBlock() : fIds(NULL), fSize(0) {}
142       AliHLTUInt32_t* fIds; //!
143       AliHLTUInt32_t  fSize; //!
144     };
145
146     class iterator {
147     public:
148       iterator() : fClusterNo(-1), fData(NULL), fEntry(NULL), fRowOffset(0) {}
149       iterator(AliRawClusterContainer* pData) : fClusterNo(-1), fData(pData), fEntry(NULL), fRowOffset(0) {}
150       iterator(const iterator& other) : fClusterNo(other.fClusterNo), fData(other.fData), fEntry(other.fEntry), fRowOffset(other.fRowOffset) {}
151       iterator& operator=(const iterator& other) {
152         if (this==&other) return *this;
153         fClusterNo=other.fClusterNo; fData=other.fData; fEntry=other.fEntry; fRowOffset=other.fRowOffset; return *this;
154       }
155       ~iterator() {}
156
157       void SetPadRow(int row)          {if (fEntry && fEntry->fCluster) fEntry->fCluster->SetPadRow(row-fRowOffset);}
158       void SetPad(float pad)           {if (fEntry && fEntry->fCluster) fEntry->fCluster->SetPad(pad);}
159       void SetTime(float time)         {if (fEntry && fEntry->fCluster) fEntry->fCluster->SetTime(time);}
160       void SetSigmaY2(float sigmaY2)   {if (fEntry && fEntry->fCluster) fEntry->fCluster->SetSigmaY2(sigmaY2);}
161       void SetSigmaZ2(float sigmaZ2)   {if (fEntry && fEntry->fCluster) fEntry->fCluster->SetSigmaZ2(sigmaZ2);}
162       void SetCharge(unsigned charge)  {if (fEntry && fEntry->fCluster) fEntry->fCluster->SetCharge(charge);}
163       void SetQMax(unsigned qmax)      {if (fEntry && fEntry->fCluster) fEntry->fCluster->SetQMax(qmax);}
164       void SetMC(const AliHLTTPCClusterMCLabel* pMC) {
165         if (fEntry) fEntry->fMC=pMC;
166       }
167
168       // switch to next cluster
169       iterator& Next(int slice, int partition);
170
171     private:
172       int fClusterNo; //! cluster no in the current block
173       AliRawClusterContainer* fData; //! pointer to actual data
174       AliRawClusterEntry* fEntry; //! pointer to current cluster
175       int fRowOffset;  //! row offset for current partition
176     };
177
178     /// iterator of remaining clusters block of specification
179     iterator& BeginRemainingClusterBlock(int count, AliHLTUInt32_t specification);
180     /// iterator of track model clusters
181     iterator& BeginTrackModelClusterBlock(int count);
182
183     /// internal cleanup
184     virtual void  Clear(Option_t * option="");
185     /// get the cluster array for a sector
186     TObjArray* GetSectorArray(unsigned sector) const;
187     /// fill the cluster array for a sector and specific row if specified
188     int FillSectorArray(TClonesArray* pSectorArray, unsigned sector, int row=-1) const;
189     /// print info
190     virtual void Print(Option_t *option=NULL) const;
191
192   protected:
193     /// load next cluster from array of the sepcific sector
194     AliRawClusterEntry* NextCluster(int slice, int partition);
195
196   private:
197     /// copy constructor prohibited
198     AliRawClusterContainer(const AliRawClusterContainer&);
199     /// assignment operator prohibited
200     AliRawClusterContainer& operator=(const AliRawClusterContainer&);
201
202     vector<AliHLTTPCRawClusterVector*> fClusterVectors; //! instances of cluster arrays
203     vector<AliRawClusterEntryVector*> fClusterMaps; //! cluster pointer vectors per sector (offline notation 0-71)
204     TClonesArray* fSectorArray; //! current sector array of clusters provided to caller
205     iterator fIterator; //!
206   };
207
208  private:
209   /// copy constructor prohibited
210   AliHLTTPCClusterAccessHLTOUT(const AliHLTTPCClusterAccessHLTOUT&);
211   /// assignment operator prohibited
212   AliHLTTPCClusterAccessHLTOUT& operator=(const AliHLTTPCClusterAccessHLTOUT&);
213
214   enum EOptions {
215     // skip the track clusters
216     kSkipTrackClusters = BIT(15),
217     // skip the partition (remaining) clusters
218     kSkipPartitionClusters = BIT(16)
219   };
220
221   int fVerbosity; //! verbosity level
222   AliRawClusterContainer* fClusters; //! cluster container
223   int fCurrentSector; //! current sector
224   AliHLTTPCDataCompressionDecoder* fpDecoder; //! decoder instance
225   AliTPCParam* fTPCParam; //! pointer to TPC param
226
227   ClassDef(AliHLTTPCClusterAccessHLTOUT, 0)
228 };
229 #endif