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