]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCClusterAccessHLTOUT.h
50c8d41bbb8ecc8fb7fb140b9c31764f8a70739d
[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 "AliTPCclusterMI.h"
19 #include <map>
20
21 class AliTPCClustersRow;
22 class AliHLTOUT;
23 class TClonesArray;
24 class AliHLTTPCDataCompressionDecoder;
25
26 typedef std::map<AliHLTUInt32_t, AliHLTTPCClusterMCLabel> AliHLTTPCClusterMCDataList;
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: 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   /**
110    * @class AliTPCclusterMIContainer
111    * Cluster read interface for offline.
112    * The class implements the interface to be used in the decoding
113    * of compressed TPC data.
114    */
115   class AliTPCclusterMIContainer {
116   public:
117     AliTPCclusterMIContainer();
118     virtual ~AliTPCclusterMIContainer();
119
120     struct AliClusterIdBlock {
121       AliClusterIdBlock() : fIds(NULL), fSize(0) {}
122       AliHLTUInt32_t* fIds; //!
123       AliHLTUInt32_t  fSize; //!
124     };
125
126     class iterator {
127     public:
128       iterator() : fClusterNo(-1), fData(NULL), fCluster(NULL), fRowOffset(0) {}
129       iterator(AliTPCclusterMIContainer* pData) : fClusterNo(-1), fData(pData), fCluster(NULL), fRowOffset(0) {}
130       iterator(const iterator& other) : fClusterNo(other.fClusterNo), fData(other.fData), fCluster(other.fCluster), fRowOffset(other.fRowOffset) {}
131       iterator& operator=(const iterator& other) {
132         if (this==&other) return *this;
133         fClusterNo=other.fClusterNo; fData=other.fData; fCluster=other.fCluster; fRowOffset=other.fRowOffset; return *this;
134       }
135       ~iterator() {}
136
137       void SetPadRow(int row)          {if (fCluster) fCluster->SetRow(row-fRowOffset);}
138       void SetPad(float pad)           {if (fCluster) fCluster->SetPad(pad);}
139       void SetTime(float time)         {if (fCluster) fCluster->SetTimeBin(time);}
140       void SetSigmaY2(float sigmaY2)   {if (fCluster) fCluster->SetSigmaY2(sigmaY2);}
141       void SetSigmaZ2(float sigmaZ2)   {if (fCluster) fCluster->SetSigmaZ2(sigmaZ2);}
142       void SetCharge(unsigned charge)  {if (fCluster) fCluster->SetQ(charge);}
143       void SetQMax(unsigned qmax)      {if (fCluster) fCluster->SetMax(qmax);}
144       void SetMC(const AliHLTTPCClusterMCLabel* pMC) {
145         if (!fCluster || !pMC) return;
146         for (int k=0; k<3; k++) fCluster->SetLabel(pMC->fClusterID[k].fMCID, k);
147       }
148
149       // switch to next cluster
150       iterator& Next(int slice, int partition);
151
152     private:
153       int fClusterNo; //! cluster no in the current block
154       AliTPCclusterMIContainer* fData; //! pointer to actual data
155       AliTPCclusterMI* fCluster; //! pointer to current cluster
156       int fRowOffset;  //! row offset for current partition
157     };
158
159     /// iterator of remaining clusters block of specification
160     iterator& BeginRemainingClusterBlock(int count, AliHLTUInt32_t specification);
161     /// iterator of track model clusters
162     iterator& BeginTrackModelClusterBlock(int count);
163
164     /// internal cleanup
165     virtual void  Clear(Option_t * option="");
166     /// get the cluster array for a sector
167     TObjArray* GetSectorArray(unsigned sector) const;
168     /// print info
169     virtual void Print(Option_t *option=NULL) const;
170
171   protected:
172     /// load next cluster from array of the sepcific sector
173     AliTPCclusterMI* NextCluster(int slice, int partition);
174
175   private:
176     AliTPCclusterMIContainer(const AliTPCclusterMIContainer&);
177     AliTPCclusterMIContainer& operator=(const AliTPCclusterMIContainer&);
178
179     vector<TClonesArray*> fClusterArrays; //! cluster arrays per sector (offline notation 0-71)
180     vector<AliClusterIdBlock> fRemainingClusterIds; //! clusters ids for remaining cluster ids
181     AliClusterIdBlock fTrackModelClusterIds; //! cluster ids for track model clusters
182     AliClusterIdBlock* fCurrentClusterIds; //! id block currently active in the iteration
183     vector<const AliHLTTPCClusterMCData*> fClusterMCData; //! references to MC data blocks
184     iterator fIterator; //!
185   };
186
187  private:
188   /// copy constructor prohibited
189   AliHLTTPCClusterAccessHLTOUT(const AliHLTTPCClusterAccessHLTOUT&);
190   /// assignment operator prohibited
191   AliHLTTPCClusterAccessHLTOUT& operator=(const AliHLTTPCClusterAccessHLTOUT&);
192
193   enum EOptions {
194     // skip the track clusters
195     kSkipTrackClusters = BIT(15),
196     // skip the partition (remaining) clusters
197     kSkipPartitionClusters = BIT(16)
198   };
199
200   int fVerbosity; //! verbosity level
201   AliTPCclusterMIContainer* fClusters; //! cluster container
202   int fCurrentSector; //! current sector
203   AliHLTTPCDataCompressionDecoder* fpDecoder; //! decoder instance
204
205   ClassDef(AliHLTTPCClusterAccessHLTOUT, 0)
206 };
207 #endif