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