Bugfix for https://savannah.cern.ch/bugs/?97755
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCClusterAccessHLTOUT.h
CommitLineData
c54aa300 1//-*- Mode: C++ -*-
2// $Id$
3#ifndef ALIHLTTPCCLUSTERACCESSHLTOUT_H
4#define ALIHLTTPCCLUSTERACCESSHLTOUT_H
0cfe753c 5//* This file is property of and copyright by the ALICE Project *
c54aa300 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"
81e7f739 16#include "AliHLTDataTypes.h"
17#include "AliHLTTPCClusterMCData.h"
de2b5702 18#include "AliHLTTPCRawCluster.h"
81e7f739 19#include <map>
c54aa300 20
de2b5702 21class AliTPCParam;
c54aa300 22class AliTPCClustersRow;
de2b5702 23class AliTPCclusterMI;
c54aa300 24class AliHLTOUT;
25class TClonesArray;
768dad20 26class AliHLTTPCDataCompressionDecoder;
c54aa300 27
28/**
29 * @class AliHLTTPCClusterAccessHLTOUT
30 * Generator for TPC cluster array from HLT TPC clusters in the HLTOUT
81e7f739 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.
c54aa300 34 *
81e7f739 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.
81e7f739 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
b60d3f6a 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
81e7f739 70 *
71 * Command 'verbosity=level' sets the verbositylevel which is default 0
72 * (no info output).
b60d3f6a 73 *
81e7f739 74 * <pre>
81e7f739 75 * pClusterAccess->Execute("read", param);
76 * TObject* pClusterAccess->FindObject("clusterarray");
77 * </pre>
b60d3f6a 78 *
79 * After processing the loop of sectors, the instance should be cleaned.
80 * <pre>
81 * pClusterAccess->Clear("event");
82 * </pre>
81e7f739 83 *
c54aa300 84 * @ingroup alihlt_tpc
85 */
86class 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
de2b5702 100 /// inherited from TObject: supports writing of data to AliTPCClustersRow
101 virtual void Copy(TObject &object) const;
102
c54aa300 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
81e7f739 110 int ProcessClusters(const char* params);
111
21786b17 112 /// helper struct to store cluster in a map together with MC info
de2b5702 113 struct AliRawClusterEntry {
21786b17 114 AliRawClusterEntry() : fCluster(), fMC() {}
de2b5702 115 AliRawClusterEntry(const AliRawClusterEntry& other) : fCluster(other.fCluster), fMC(other.fMC) {}
116 AliRawClusterEntry& operator=(const AliRawClusterEntry& other) {
117 if (&other==this) return *this;
118 fCluster=other.fCluster; fMC=other.fMC;
119 return *this;
120 }
21786b17 121 AliHLTTPCRawCluster fCluster; //! cluster
122 AliHLTTPCClusterMCLabel fMC; //! MC labels
de2b5702 123 };
124
de2b5702 125 typedef vector<AliRawClusterEntry> AliRawClusterEntryVector;
126
b60d3f6a 127 /**
de2b5702 128 * @class AliRawClusterContainer
b60d3f6a 129 * Cluster read interface for offline.
130 * The class implements the interface to be used in the decoding
131 * of compressed TPC data.
132 */
de2b5702 133 class AliRawClusterContainer {
b60d3f6a 134 public:
de2b5702 135 AliRawClusterContainer();
136 virtual ~AliRawClusterContainer();
b60d3f6a 137
138 struct AliClusterIdBlock {
139 AliClusterIdBlock() : fIds(NULL), fSize(0) {}
140 AliHLTUInt32_t* fIds; //!
141 AliHLTUInt32_t fSize; //!
142 };
143
144 class iterator {
145 public:
de2b5702 146 iterator() : fClusterNo(-1), fData(NULL), fEntry(NULL), fRowOffset(0) {}
147 iterator(AliRawClusterContainer* pData) : fClusterNo(-1), fData(pData), fEntry(NULL), fRowOffset(0) {}
148 iterator(const iterator& other) : fClusterNo(other.fClusterNo), fData(other.fData), fEntry(other.fEntry), fRowOffset(other.fRowOffset) {}
b60d3f6a 149 iterator& operator=(const iterator& other) {
b22da46d 150 if (this==&other) return *this;
de2b5702 151 fClusterNo=other.fClusterNo; fData=other.fData; fEntry=other.fEntry; fRowOffset=other.fRowOffset; return *this;
b60d3f6a 152 }
153 ~iterator() {}
154
21786b17 155 void SetPadRow(int row) {if (fEntry ) fEntry->fCluster.SetPadRow(row-fRowOffset);}
156 void SetPad(float pad) {if (fEntry ) fEntry->fCluster.SetPad(pad);}
157 void SetTime(float time) {if (fEntry ) fEntry->fCluster.SetTime(time);}
158 void SetSigmaY2(float sigmaY2) {if (fEntry ) fEntry->fCluster.SetSigmaY2(sigmaY2);}
159 void SetSigmaZ2(float sigmaZ2) {if (fEntry ) fEntry->fCluster.SetSigmaZ2(sigmaZ2);}
160 void SetCharge(unsigned charge) {if (fEntry ) fEntry->fCluster.SetCharge(charge);}
161 void SetQMax(unsigned qmax) {if (fEntry ) fEntry->fCluster.SetQMax(qmax);}
1e7ff439 162 void SetMC(const AliHLTTPCClusterMCLabel* pMC) {
21786b17 163 if (fEntry && pMC ) fEntry->fMC=*pMC;
1e7ff439 164 }
b60d3f6a 165
166 // switch to next cluster
167 iterator& Next(int slice, int partition);
168
169 private:
21786b17 170
171 static const Int_t fkRowOffsetOuterSector; //! transient
172
b60d3f6a 173 int fClusterNo; //! cluster no in the current block
de2b5702 174 AliRawClusterContainer* fData; //! pointer to actual data
175 AliRawClusterEntry* fEntry; //! pointer to current cluster
21786b17 176 int fRowOffset; //! row offset for current partition
b60d3f6a 177 };
178
179 /// iterator of remaining clusters block of specification
180 iterator& BeginRemainingClusterBlock(int count, AliHLTUInt32_t specification);
181 /// iterator of track model clusters
182 iterator& BeginTrackModelClusterBlock(int count);
183
b60d3f6a 184 /// internal cleanup
185 virtual void Clear(Option_t * option="");
186 /// get the cluster array for a sector
187 TObjArray* GetSectorArray(unsigned sector) const;
de2b5702 188 /// fill the cluster array for a sector and specific row if specified
189 int FillSectorArray(TClonesArray* pSectorArray, unsigned sector, int row=-1) const;
b60d3f6a 190 /// print info
191 virtual void Print(Option_t *option=NULL) const;
192
193 protected:
194 /// load next cluster from array of the sepcific sector
de2b5702 195 AliRawClusterEntry* NextCluster(int slice, int partition);
b60d3f6a 196
197 private:
de2b5702 198 /// copy constructor prohibited
199 AliRawClusterContainer(const AliRawClusterContainer&);
200 /// assignment operator prohibited
201 AliRawClusterContainer& operator=(const AliRawClusterContainer&);
202
de2b5702 203 vector<AliRawClusterEntryVector*> fClusterMaps; //! cluster pointer vectors per sector (offline notation 0-71)
204 TClonesArray* fSectorArray; //! current sector array of clusters provided to caller
b60d3f6a 205 iterator fIterator; //!
206 };
207
c54aa300 208 private:
209 /// copy constructor prohibited
210 AliHLTTPCClusterAccessHLTOUT(const AliHLTTPCClusterAccessHLTOUT&);
211 /// assignment operator prohibited
212 AliHLTTPCClusterAccessHLTOUT& operator=(const AliHLTTPCClusterAccessHLTOUT&);
213
b60d3f6a 214 enum EOptions {
215 // skip the track clusters
216 kSkipTrackClusters = BIT(15),
217 // skip the partition (remaining) clusters
218 kSkipPartitionClusters = BIT(16)
219 };
220
81e7f739 221 int fVerbosity; //! verbosity level
de2b5702 222 AliRawClusterContainer* fClusters; //! cluster container
b60d3f6a 223 int fCurrentSector; //! current sector
768dad20 224 AliHLTTPCDataCompressionDecoder* fpDecoder; //! decoder instance
de2b5702 225 AliTPCParam* fTPCParam; //! pointer to TPC param
c54aa300 226
227 ClassDef(AliHLTTPCClusterAccessHLTOUT, 0)
228};
229#endif