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