]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDrawStream.h
Submit missing classes to previous release
[u/mrichter/AliRoot.git] / TRD / AliTRDrawStream.h
CommitLineData
0508ca31 1/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
2 * See cxx source for full Copyright notice */
3
4//-----------------------------------
5//
6// decoding of TRD raw data stream
7// and translation into digits
8//
9//----------------------------------
10
d60fe037 11#ifndef ALITRDRAWSTREAM_H
12#define ALITRDRAWSTREAM_H
13
14#include "TObject.h"
f4b3235e 15#include "TClonesArray.h"
16#include "TTree.h"
d60fe037 17
18#include "AliTRDrawStreamBase.h"
d60fe037 19
20class TObjArray;
21class TString;
cc26f39c 22class TBranch;
d60fe037 23
24class AliRawReader;
25class AliTRDdigitsManager;
26class AliTRDdigitsParam;
27class AliTRDarrayADC;
28class AliTRDSignalIndex;
cc26f39c 29class AliTRDtrackletContainer;
d60fe037 30
31class AliTRDrawStream : public AliTRDrawStreamBase
32{
33 public:
34 AliTRDrawStream(AliRawReader *rawReader = 0x0);
35 ~AliTRDrawStream();
36
37 Bool_t SetReader(AliRawReader *rawReader) { fRawReader = rawReader; return kTRUE; }
38 void SetDigitsManager(AliTRDdigitsManager *digMgr) { fDigitsManager = digMgr; }
5fdfc9e4 39 void SetTrackletArray(TClonesArray *ar) { fTracklets = ar; }
40 void SetTrackArray(TClonesArray *ar) { fTracks = ar; }
41 void SetMarkerArray(TClonesArray *ar) { fMarkers = ar; }
42
43 TClonesArray* GetTrackletArray() const { return fTracklets; }
44 TClonesArray* GetTrackArray() const { return fTracks; }
45 TClonesArray* GetMarkerArray() const { return fMarkers; }
d60fe037 46
f4b3235e 47 AliTRDdigitsManager* GetDigitsManager() const { return fDigitsManager; }
48 TTree *GetTrackletTree() const { return fTrackletTree; }
49
d60fe037 50 Bool_t ReadEvent(TTree *trackletTree = 0x0);
51
52 Bool_t NextDDL();
53 Int_t NextChamber(AliTRDdigitsManager *digMgr,
54 UInt_t ** /* trackletContainer */, UShort_t ** /* errorContainer */);
55
67271412 56 Bool_t ConnectTracklets(TTree *trklTree);
57
5fdfc9e4 58 void StoreErrorsInTree() { fStoreError = &AliTRDrawStream::StoreErrorTree; }
59 void StoreErrorsInArray() { fStoreError = &AliTRDrawStream::StoreErrorArray; }
f4b3235e 60 void EnableErrorStorage() { fStoreError = &AliTRDrawStream::StoreErrorTree; }
61 void DisableErrorStorage() { fStoreError = &AliTRDrawStream::ForgetError; }
62
d60fe037 63 // legacy code, to be removed
64 Bool_t SetRawVersion(Int_t) { return kTRUE; }
65 void SetSharedPadReadout(Bool_t) {}
66 void SetNoErrorWarning() {}
67
68 // error handling
69 enum ErrorCode_t {
70 kUnknown = 0,
71 kLinkMonitor,
72 kPtrgCntMismatch,
73 kNonTrdEq,
74 kStackHeaderInvalid,
75 kInvalidDetector,
76 kNoDigits,
77 kHCmismatch,
78 kHCcheckFailed,
79 kPosUnexp,
80 kTPmodeInvalid,
81 kTPmismatch,
82 kNtimebinsChanged,
83 kAdcMaskInconsistent,
84 kAdcCheckInvalid,
85 kAdcDataAbort,
86 kAdcChannelsMiss,
87 kMissMcmHeaders,
88 kLastErrorCode
89 };
90
cc26f39c 91 enum ErrorBehav_t {
92223bf6 92 kTolerate = 0,
93 kAbort = 1,
94 kDiscardMCM = 2,
95 kDiscardHC = 4
cc26f39c 96 };
97
5fdfc9e4 98 enum MarkerCode_t {
99 kHCactive = 1
100 };
101
0508ca31 102 TTree* GetErrorTree() const { return fErrors; }
d60fe037 103 static const char* GetErrorMessage(ErrorCode_t errCode);
104
cc26f39c 105 // event statistics
106 class AliTRDrawStats : public TObject {
107 public:
108 AliTRDrawStats() : TObject(), fBytesRead(0) {}
109 void ClearStats();
110
111 class AliTRDrawStatsSector : public TObject {
112 public:
113 AliTRDrawStatsSector() : TObject(), fBytes(0), fBytesRead(0), fNTracklets(0), fNMCMs(0), fNChannels(0) {}
114 void ClearStats();
115
116 class AliTRDrawStatsHC : public TObject {
117 public:
118 AliTRDrawStatsHC() : TObject(), fBytes(0), fBytesRead(0), fNTracklets(0), fNMCMs(0), fNChannels(0) {}
119 void ClearStats();
120
121 Int_t fBytes; // number of bytes (not necessarily read)
122 Int_t fBytesRead; // number of bytes read
123 Int_t fNTracklets; // number of tracklets
124 Int_t fNMCMs; // number of MCMs (from MCM headers)
125 Int_t fNChannels; // number of channels
126 ClassDef(AliTRDrawStatsHC, 1);
127 };
128
129 Int_t fBytes; // number of bytes (not necessarily read)
130 Int_t fBytesRead; // number of bytes read
131 Int_t fNTracklets; // number of tracklets
132 Int_t fNMCMs; // number of MCMs (from MCM headers)
133 Int_t fNChannels; // number of channels
134 AliTRDrawStatsHC fStatsHC[60]; //[60] HC-wise statistics
135 ClassDef(AliTRDrawStatsSector, 1);
136 };
137
cc26f39c 138 AliTRDrawStatsSector fStatsSector[18]; //[18] sector-wise statistics
139 Int_t fBytesRead; // number of bytes read
140 ClassDef(AliTRDrawStats, 1);
141 };
142
143 AliTRDrawStats fStats; // event statistics, clearing must be done by the user
144
145 AliTRDrawStats* GetStats() { return &fStats; }
146 Int_t GetEventSize(Int_t sector) { return fStats.fStatsSector[sector].fBytes; }
147 Int_t GetNTracklets(Int_t sector) { return fStats.fStatsSector[sector].fNTracklets; }
148 Int_t GetNMCMs(Int_t sector) { return fStats.fStatsSector[sector].fNMCMs; }
149 Int_t GetNChannels(Int_t sector) { return fStats.fStatsSector[sector].fNChannels; }
150
151 // raw data dumping
152 void SetDumpMCM(Int_t det, Int_t rob, Int_t mcm, Bool_t dump = kTRUE);
153
154 Bool_t IsDumping() { return (fNDumpMCMs > 0); }
155 Bool_t DumpingMCM(Int_t det, Int_t rob, Int_t mcm);
156
157 void DumpRaw(TString title, UInt_t *start, Int_t length);
158
d60fe037 159 protected:
160 Int_t ReadSmHeader();
161 Int_t ReadStackIndexHeader(Int_t stack);
162
163 Int_t ReadLinkData();
164 Int_t ReadTracklets();
165 Int_t ReadHcHeader();
166 Int_t ReadTPData(Int_t mode = 1);
167 Int_t ReadZSData();
168 Int_t ReadNonZSData();
169
92223bf6 170 Int_t SeekNextLink();
171
d60fe037 172 // MCM header decoding
0508ca31 173 Int_t ROB(UInt_t mcmhdr) const { return 0x7 & mcmhdr >> 28; }
174 Int_t MCM(UInt_t mcmhdr) const { return 0xf & mcmhdr >> 24; }
175 Int_t Row(UInt_t mcmhdr) const { return (ROB(mcmhdr) / 2) * 4 + MCM(mcmhdr) / 4; }
176 Int_t AdcColOffset(UInt_t mcmhdr) const { return (MCM(mcmhdr) % 4 + 1) * 21 + (ROB(mcmhdr) % 2) * 84 - 1; }
177 Int_t PadColOffset(UInt_t mcmhdr) const { return (MCM(mcmhdr) % 4 + 1) * 18 + (ROB(mcmhdr) % 2) * 72 + 1; }
178 Int_t EvNo(UInt_t mcmhdr) const { return 0xfffff & mcmhdr >> 4; }
179 Int_t Check(UInt_t mcmhdr) const { return 0xf & mcmhdr; }
180 Int_t CouldBeMCMhdr(UInt_t mcmhdr) const { return ((0xf & mcmhdr) == 0xc); }
181
182 Int_t GetMCMReadoutPos(Int_t mcm) const { return (mcm > -1 && mcm < 16) ? fgkMcmOrder[mcm] : -1; }
183 Int_t GetROBReadoutPos(Int_t rob) const { return (rob > -1 && rob < 4) ? fgkRobOrder[rob] : -1; }
d60fe037 184
185 // ADC mask decoding
0508ca31 186 Int_t GetActiveChannels(UInt_t adcmask) const { return 0x1fffff & adcmask >> 4; }
82029d44 187 inline Int_t GetNActiveChannelsFromMask(UInt_t adcmask) const; // { Int_t nch = 0; for (Int_t i = 0; i < 21; i++) if ((GetActiveChannels(adcmask) & 1 << i)) nch++; return nch; }
0508ca31 188 Int_t GetNActiveChannels(UInt_t adcmask) const { return (0x1f & ~(adcmask >> 25)); }
189 Int_t CouldBeADCmask(UInt_t adcmask) const { return ((0xf & adcmask) == 0xc && (0x3 & adcmask >> 30) == 0x1); }
d60fe037 190
191 // error message generation
1d62be37 192 void EquipmentError(ErrorCode_t err = kUnknown, const char *const msg = "", ...);
193 void StackError (ErrorCode_t err = kUnknown, const char *const msg = "", ...);
194 void LinkError (ErrorCode_t err = kUnknown, const char *const msg = "", ...);
195 void ROBError (ErrorCode_t err = kUnknown, const char *const msg = "", ...);
196 void MCMError (ErrorCode_t err = kUnknown, const char *const msg = "", ...);
f4b3235e 197 void StoreErrorTree() { fErrors->Fill(); }
5fdfc9e4 198 void StoreErrorArray() { new ((*fMarkers)[fMarkers->GetEntriesFast()]) AliTRDrawStreamError(fLastError); }
f4b3235e 199 void ForgetError() { return; }
200 void (AliTRDrawStream::*fStoreError)(); //! function pointer to method used for storing the error
d60fe037 201
92223bf6 202 static const char* fgErrorMessages[kLastErrorCode]; // error messages corresponding to the error codes
203 static const Int_t fgErrorDebugLevel[kLastErrorCode]; // error debug level
204 static ErrorBehav_t fgErrorBehav[kLastErrorCode]; // bevhaviour in case of error of given type
d60fe037 205
206 // I/O
0508ca31 207 AliRawReader *fRawReader; // pointer to the raw reader to take the data from
208 AliTRDdigitsManager *fDigitsManager; // pointer to the digitsManager to fill the data
209 AliTRDdigitsParam *fDigitsParam; // pointer to the parameters belonging to the digits
d60fe037 210
0508ca31 211 TTree *fErrors; // tree containing the occured error codes
f4b3235e 212 class AliTRDrawStreamError {
213 public:
214 AliTRDrawStreamError(Int_t error = 0, Int_t sector = -1, Int_t stack = -1, Int_t link = -1, Int_t rob = -1, Int_t mcm = -1);
4718cfce 215 virtual ~AliTRDrawStreamError() {}
f4b3235e 216 Int_t fError; // error code
217 Int_t fSector; // sector
218 Int_t fStack; // stack
219 Int_t fLink; // link
220 Int_t fRob; // ROB no
221 Int_t fMcm; // MCM no
222 ClassDef(AliTRDrawStreamError, 1);
223 } fLastError; // last error which occured
92223bf6 224 UInt_t fErrorFlags; // error flags used to steer subsequent reading
225 char fErrorBuffer[100]; // buffer for error message
d60fe037 226
0508ca31 227 UInt_t *fPayloadStart; // pointer to start of data payload
228 UInt_t *fPayloadCurr; // pointer to current reading position in the payload
cc26f39c 229 Int_t fPayloadSize; // size of the payload (in UInt_t words)
d60fe037 230
0508ca31 231 static const Int_t fgkNlinks; // number of links to read
232 static const Int_t fgkNstacks; // number of stacks to read
233 static const UInt_t fgkDataEndmarker; // data endmarker
234 static const UInt_t fgkTrackletEndmarker; // tracklet endmarker
235 static const Int_t fgkMcmOrder []; // expected readout order of the MCMs
236 static const Int_t fgkRobOrder []; // expected readout order of the ROBs
d60fe037 237
238 // persistent information
0508ca31 239 Int_t fNtimebins; // number of timebins
240 Int_t fLastEvId; // Event ID of last event
d60fe037 241
242 // information valid at current reader position
0508ca31 243 // all the variables fCurr... refer to the value at the current
244 // reading position
245 Int_t fCurrSlot; // current slot
246 Int_t fCurrLink; // current link
247 Int_t fCurrRobPos; // current ROB number
248 Int_t fCurrMcmPos; // current MCM number
d60fe037 249
250 // DDL header
0508ca31 251 UInt_t fCurrEquipmentId; // current Equipment ID
d60fe037 252
253 // SMU index header
0508ca31 254 UInt_t fCurrSmuIndexHeaderSize; // current size of the SMU index header
255 UInt_t fCurrSmuIndexHeaderVersion; // current version of the SMU index header
256 UInt_t fCurrTrackEnable; // current value of track enable
257 UInt_t fCurrTrackletEnable; // current value of tracklet enable
258 UInt_t fCurrStackMask; // current mask of active stacks
d60fe037 259
260 // Stack index header
0508ca31 261 UInt_t *fCurrStackIndexWord; // current stack index words
262 UInt_t *fCurrStackHeaderSize; // current stack index sizes
263 UInt_t *fCurrStackHeaderVersion; // current stack header versions
264 UInt_t *fCurrLinkMask; // current link masks
265 UInt_t *fCurrCleanCheckout; // current clean checkout flags
266 UInt_t *fCurrBoardId; // current board IDs
267 UInt_t *fCurrHwRev; // current hardware revision
268 UInt_t *fCurrLinkMonitorFlags; // current link monitor flags
269 UInt_t *fCurrLinkDataTypeFlags; // current link data flags
270 UInt_t *fCurrLinkDebugFlags; // current link debug flags
d60fe037 271
272 // HC information
0508ca31 273 Int_t fCurrSpecial; // current value of the special flag
274 Int_t fCurrMajor; // current major version
275 Int_t fCurrMinor; // current minor version
276 Int_t fCurrAddHcWords; // current number of additional HC-header words
277 Int_t fCurrSm; // current sector
278 Int_t fCurrStack; // current stack
279 Int_t fCurrLayer; // current layer
280 Int_t fCurrSide; // current side
281 Int_t fCurrHC; // current HC
282 Int_t fCurrCheck; // current check bits
283 Int_t fCurrNtimebins; // current number of timebins
284 Int_t fCurrBC; // current BC
285 Int_t fCurrPtrgCnt; // current pretrigger count
286 Int_t fCurrPtrgPhase; // current pretrigger phase
d60fe037 287
cc26f39c 288 // settings for dumping
289 Int_t fDumpMCM[100]; // MCMs to dump
290 Int_t fNDumpMCMs; // number of MCMs to dump
291
d60fe037 292 // tracklet information
0508ca31 293 TClonesArray *fTrackletArray; // pointer to array for tracklet storage
d60fe037 294
295 // output data
0508ca31 296 AliTRDarrayADC *fAdcArray; // pointer to ADC array
297 AliTRDSignalIndex *fSignalIndex; // pointer to the signal index
298 TTree *fTrackletTree; // pointer to the tree for tracklet storage
5fdfc9e4 299 TClonesArray *fTracklets; // pointer to array of tracklets
300 TClonesArray *fTracks; // pointer to array of GTU tracks
301 TClonesArray *fMarkers; // pointer to array of markers (data present, errors, ...)
d60fe037 302
303 AliTRDrawStream(const AliTRDrawStream&); // not implemented
0508ca31 304 AliTRDrawStream& operator=(const AliTRDrawStream&); // not implemented
d60fe037 305
306 ClassDef(AliTRDrawStream, 0);
307};
308
82029d44 309Int_t AliTRDrawStream::GetNActiveChannelsFromMask(UInt_t adcmask) const
310{
311 // return number of active bits in the ADC mask
312
313 adcmask = GetActiveChannels(adcmask);
314 adcmask = adcmask - ((adcmask >> 1) & 0x55555555);
315 adcmask = (adcmask & 0x33333333) + ((adcmask >> 2) & 0x33333333);
316 return (((adcmask + (adcmask >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24;
317}
318
d60fe037 319#endif