]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDrawStream.h
deleting duplicate files
[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//
5f006bd7 6// decoding of TRD raw data stream
0508ca31 7// and translation into digits
8//
9//----------------------------------
10
d60fe037 11#ifndef ALITRDRAWSTREAM_H
12#define ALITRDRAWSTREAM_H
13
f4b3235e 14#include "TTree.h"
9cb9c409 15#include "AliLog.h"
6419bebb 16#include "TClonesArray.h"
9cb9c409 17
6419bebb 18class TObject;
d60fe037 19class TObjArray;
20class TString;
cc26f39c 21class TBranch;
d60fe037 22
23class AliRawReader;
24class AliTRDdigitsManager;
25class AliTRDdigitsParam;
26class AliTRDarrayADC;
27class AliTRDSignalIndex;
cc26f39c 28class AliTRDtrackletContainer;
d60fe037 29
8df1f8f5 30class AliTRDrawStream : public TObject
d60fe037 31{
32 public:
33 AliTRDrawStream(AliRawReader *rawReader = 0x0);
34 ~AliTRDrawStream();
35
9cb9c409 36 enum { kDDLOffset = 0x400, // Offset for DDL numbers
37 kDDLMax = 0x411 }; // Max DDL number for TRD SM
84f471a7 38
d60fe037 39 Bool_t SetReader(AliRawReader *rawReader) { fRawReader = rawReader; return kTRUE; }
40 void SetDigitsManager(AliTRDdigitsManager *digMgr) { fDigitsManager = digMgr; }
5fdfc9e4 41 void SetTrackletArray(TClonesArray *ar) { fTracklets = ar; }
42 void SetTrackArray(TClonesArray *ar) { fTracks = ar; }
43 void SetMarkerArray(TClonesArray *ar) { fMarkers = ar; }
44
45 TClonesArray* GetTrackletArray() const { return fTracklets; }
46 TClonesArray* GetTrackArray() const { return fTracks; }
47 TClonesArray* GetMarkerArray() const { return fMarkers; }
d60fe037 48
f4b3235e 49 AliTRDdigitsManager* GetDigitsManager() const { return fDigitsManager; }
50 TTree *GetTrackletTree() const { return fTrackletTree; }
51
d60fe037 52 Bool_t ReadEvent(TTree *trackletTree = 0x0);
53
54 Bool_t NextDDL();
5f006bd7 55 Int_t NextChamber(AliTRDdigitsManager *digMgr);
9cb9c409 56 Int_t NextChamber(AliTRDdigitsManager *digMgr,
2519cca4 57 UInt_t ** /* trackletContainer */, UShort_t ** /* errorContainer */) { AliError("Deprecated, use NextChamber(AliTRDdigitsManger*) instead!"); return NextChamber(digMgr); }
d60fe037 58
67271412 59 Bool_t ConnectTracklets(TTree *trklTree);
60
5fdfc9e4 61 void StoreErrorsInTree() { fStoreError = &AliTRDrawStream::StoreErrorTree; }
62 void StoreErrorsInArray() { fStoreError = &AliTRDrawStream::StoreErrorArray; }
f4b3235e 63 void EnableErrorStorage() { fStoreError = &AliTRDrawStream::StoreErrorTree; }
64 void DisableErrorStorage() { fStoreError = &AliTRDrawStream::ForgetError; }
65
d60fe037 66 // error handling
5f006bd7 67 enum ErrorCode_t {
68 kUnknown = 0,
69 kLinkMonitor,
52a2b6c0 70 kEvCntMismatch,
d60fe037 71 kNonTrdEq,
72 kStackHeaderInvalid,
73 kInvalidDetector,
74 kNoDigits,
75 kHCmismatch,
76 kHCcheckFailed,
77 kPosUnexp,
78 kTPmodeInvalid,
79 kTPmismatch,
80 kNtimebinsChanged,
81 kAdcMaskInconsistent,
82 kAdcCheckInvalid,
83 kAdcDataAbort,
84 kAdcChannelsMiss,
85 kMissMcmHeaders,
2519cca4 86 kMissTpData,
52a2b6c0 87 kCRCmismatch,
d60fe037 88 kLastErrorCode
5f006bd7 89 };
d60fe037 90
cc26f39c 91 enum ErrorBehav_t {
92223bf6 92 kTolerate = 0,
5f006bd7 93 kAbort = 1,
92223bf6 94 kDiscardMCM = 2,
95 kDiscardHC = 4
cc26f39c 96 };
97
5fdfc9e4 98 enum MarkerCode_t {
8df9496c 99 kHCactive = 1,
100 kSecactive = 2
5fdfc9e4 101 };
102
0508ca31 103 TTree* GetErrorTree() const { return fErrors; }
d60fe037 104 static const char* GetErrorMessage(ErrorCode_t errCode);
9cb9c409 105 static void SetErrorDebugLevel(ErrorCode_t error, Int_t level) { fgErrorDebugLevel[error] = level; }
106 static void SetErrorBehaviour(ErrorCode_t error, ErrorBehav_t behav) { fgErrorBehav[error] = behav; }
d60fe037 107
8df9496c 108 class AliTRDrawStreamError : public TObject {
109 public:
5f006bd7 110 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);
8df9496c 111 virtual ~AliTRDrawStreamError() {}
112 Int_t fError; // error code
113 Int_t fSector; // sector
114 Int_t fStack; // stack
115 Int_t fLink; // link
116 Int_t fRob; // ROB no
117 Int_t fMcm; // MCM no
118 ClassDef(AliTRDrawStreamError, 1);
119 };
120
cc26f39c 121 // event statistics
122 class AliTRDrawStats : public TObject {
123 public:
124 AliTRDrawStats() : TObject(), fBytesRead(0) {}
125 void ClearStats();
126
127 class AliTRDrawStatsSector : public TObject {
128 public:
129 AliTRDrawStatsSector() : TObject(), fBytes(0), fBytesRead(0), fNTracklets(0), fNMCMs(0), fNChannels(0) {}
130 void ClearStats();
131
132 class AliTRDrawStatsHC : public TObject {
133 public:
134 AliTRDrawStatsHC() : TObject(), fBytes(0), fBytesRead(0), fNTracklets(0), fNMCMs(0), fNChannels(0) {}
135 void ClearStats();
136
137 Int_t fBytes; // number of bytes (not necessarily read)
138 Int_t fBytesRead; // number of bytes read
139 Int_t fNTracklets; // number of tracklets
140 Int_t fNMCMs; // number of MCMs (from MCM headers)
141 Int_t fNChannels; // number of channels
142 ClassDef(AliTRDrawStatsHC, 1);
143 };
144
145 Int_t fBytes; // number of bytes (not necessarily read)
146 Int_t fBytesRead; // number of bytes read
147 Int_t fNTracklets; // number of tracklets
148 Int_t fNMCMs; // number of MCMs (from MCM headers)
149 Int_t fNChannels; // number of channels
150 AliTRDrawStatsHC fStatsHC[60]; //[60] HC-wise statistics
151 ClassDef(AliTRDrawStatsSector, 1);
152 };
153
cc26f39c 154 AliTRDrawStatsSector fStatsSector[18]; //[18] sector-wise statistics
155 Int_t fBytesRead; // number of bytes read
156 ClassDef(AliTRDrawStats, 1);
157 };
158
cc26f39c 159 AliTRDrawStats* GetStats() { return &fStats; }
92305359 160 Int_t GetEventSize(Int_t sector) const { return fStats.fStatsSector[sector].fBytes; }
161 Int_t GetNTracklets(Int_t sector) const { return fStats.fStatsSector[sector].fNTracklets; }
162 Int_t GetNMCMs(Int_t sector) const { return fStats.fStatsSector[sector].fNMCMs; }
163 Int_t GetNChannels(Int_t sector) const { return fStats.fStatsSector[sector].fNChannels; }
cc26f39c 164
2519cca4 165 ULong64_t GetTrkFlags(Int_t sector, Int_t stack) const { return fCurrTrkFlags[sector*fgkNstacks + stack]; }
166 UInt_t GetTriggerFlags(Int_t sector) const { return fCurrTrgFlags[sector]; }
167
cc26f39c 168 // raw data dumping
169 void SetDumpMCM(Int_t det, Int_t rob, Int_t mcm, Bool_t dump = kTRUE);
170
92305359 171 Bool_t IsDumping() const { return (fNDumpMCMs > 0); }
172 Bool_t DumpingMCM(Int_t det, Int_t rob, Int_t mcm) const;
cc26f39c 173
6419bebb 174 TString DumpRaw(TString title, const UInt_t *start, Int_t length, UInt_t endmarker = 0xffffffff);
9cb9c409 175 TString DumpMcmHeader(TString title, UInt_t word);
176 TString DumpAdcMask(TString title, UInt_t word);
177
52a2b6c0 178 static void SortTracklets(TClonesArray *trklArray, TList &sortedTracklets, Int_t *indices);
179
9cb9c409 180 // temporary: allow to change expected readout order
181 static void SetMCMReadoutPos(Int_t mcm, Int_t pos) { if (mcm > -1 && mcm < 16) fgMcmOrder[mcm] = pos; }
182 static void SetROBReadoutPos(Int_t robpair, Int_t pos) { if (robpair > -1 && robpair < 4) fgMcmOrder[robpair] = pos; }
cc26f39c 183
d60fe037 184 protected:
9cb9c409 185 Int_t ReadGTUHeaders(UInt_t *buffer);
d60fe037 186 Int_t ReadSmHeader();
9cb9c409 187 Int_t ReadTrackingHeader(Int_t stack);
188 Int_t ReadTriggerHeaders();
189 Int_t ReadStackHeader(Int_t stack);
190 Int_t DecodeGTUtracks();
191 Int_t ReadGTUTrailer();
d60fe037 192
193 Int_t ReadLinkData();
194 Int_t ReadTracklets();
195 Int_t ReadHcHeader();
196 Int_t ReadTPData(Int_t mode = 1);
197 Int_t ReadZSData();
198 Int_t ReadNonZSData();
199
52a2b6c0 200 Int_t SeekNextStack();
92223bf6 201 Int_t SeekNextLink();
202
d60fe037 203 // MCM header decoding
0508ca31 204 Int_t ROB(UInt_t mcmhdr) const { return 0x7 & mcmhdr >> 28; }
205 Int_t MCM(UInt_t mcmhdr) const { return 0xf & mcmhdr >> 24; }
206 Int_t Row(UInt_t mcmhdr) const { return (ROB(mcmhdr) / 2) * 4 + MCM(mcmhdr) / 4; }
207 Int_t AdcColOffset(UInt_t mcmhdr) const { return (MCM(mcmhdr) % 4 + 1) * 21 + (ROB(mcmhdr) % 2) * 84 - 1; }
208 Int_t PadColOffset(UInt_t mcmhdr) const { return (MCM(mcmhdr) % 4 + 1) * 18 + (ROB(mcmhdr) % 2) * 72 + 1; }
209 Int_t EvNo(UInt_t mcmhdr) const { return 0xfffff & mcmhdr >> 4; }
210 Int_t Check(UInt_t mcmhdr) const { return 0xf & mcmhdr; }
211 Int_t CouldBeMCMhdr(UInt_t mcmhdr) const { return ((0xf & mcmhdr) == 0xc); }
212
9cb9c409 213 Int_t GetMCMReadoutPos(Int_t mcm) const { return (mcm > -1 && mcm < 16) ? fgMcmOrder[mcm] : -1; }
214 Int_t GetROBReadoutPos(Int_t rob) const { return (rob > -1 && rob < 4) ? fgRobOrder[rob] : -1; }
d60fe037 215
216 // ADC mask decoding
0508ca31 217 Int_t GetActiveChannels(UInt_t adcmask) const { return 0x1fffff & adcmask >> 4; }
82029d44 218 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 219 Int_t GetNActiveChannels(UInt_t adcmask) const { return (0x1f & ~(adcmask >> 25)); }
220 Int_t CouldBeADCmask(UInt_t adcmask) const { return ((0xf & adcmask) == 0xc && (0x3 & adcmask >> 30) == 0x1); }
5f006bd7 221
d60fe037 222 // error message generation
1dd71b58 223 void EquipmentError(ErrorCode_t err = kUnknown, const char *const msg = " ", ...);
224 void StackError (ErrorCode_t err = kUnknown, const char *const msg = " ", ...);
225 void LinkError (ErrorCode_t err = kUnknown, const char *const msg = " ", ...);
226 void ROBError (ErrorCode_t err = kUnknown, const char *const msg = " ", ...);
227 void MCMError (ErrorCode_t err = kUnknown, const char *const msg = " ", ...);
f4b3235e 228 void StoreErrorTree() { fErrors->Fill(); }
5fdfc9e4 229 void StoreErrorArray() { new ((*fMarkers)[fMarkers->GetEntriesFast()]) AliTRDrawStreamError(fLastError); }
f4b3235e 230 void ForgetError() { return; }
231 void (AliTRDrawStream::*fStoreError)(); //! function pointer to method used for storing the error
d60fe037 232
92305359 233 static const char* fgkErrorMessages[kLastErrorCode]; // error messages corresponding to the error codes
234 static Int_t fgErrorDebugLevel[kLastErrorCode]; // error debug level
92223bf6 235 static ErrorBehav_t fgErrorBehav[kLastErrorCode]; // bevhaviour in case of error of given type
d60fe037 236
237 // I/O
5f006bd7 238 AliRawReader *fRawReader; // pointer to the raw reader to take the data from
0508ca31 239 AliTRDdigitsManager *fDigitsManager; // pointer to the digitsManager to fill the data
240 AliTRDdigitsParam *fDigitsParam; // pointer to the parameters belonging to the digits
d60fe037 241
0508ca31 242 TTree *fErrors; // tree containing the occured error codes
8df9496c 243 AliTRDrawStreamError fLastError; // last error which occured
92223bf6 244 UInt_t fErrorFlags; // error flags used to steer subsequent reading
245 char fErrorBuffer[100]; // buffer for error message
d60fe037 246
2519cca4 247 AliTRDrawStats fStats; // event statistics, clearing must be done by the user
248
0508ca31 249 UInt_t *fPayloadStart; // pointer to start of data payload
250 UInt_t *fPayloadCurr; // pointer to current reading position in the payload
cc26f39c 251 Int_t fPayloadSize; // size of the payload (in UInt_t words)
d60fe037 252
0508ca31 253 static const Int_t fgkNlinks; // number of links to read
9cb9c409 254 static const Int_t fgkNsectors; // number of sectors
0508ca31 255 static const Int_t fgkNstacks; // number of stacks to read
9cb9c409 256 static const Int_t fgkNtriggers; // number of triggers in data stream
5f006bd7 257 static const UInt_t fgkDataEndmarker; // data endmarker
0508ca31 258 static const UInt_t fgkTrackletEndmarker; // tracklet endmarker
52a2b6c0 259 static const UInt_t fgkStackEndmarker[]; // stack endmarker (used from version 0xd on)
9cb9c409 260 static Int_t fgMcmOrder []; // expected readout order of the MCMs
261 static Int_t fgRobOrder []; // expected readout order of the ROBs
d60fe037 262
263 // persistent information
0508ca31 264 Int_t fNtimebins; // number of timebins
5f006bd7 265 Int_t fLastEvId; // Event ID of last event
d60fe037 266
267 // information valid at current reader position
0508ca31 268 // all the variables fCurr... refer to the value at the current
269 // reading position
5f006bd7 270 Int_t fCurrSlot; // current slot
0508ca31 271 Int_t fCurrLink; // current link
272 Int_t fCurrRobPos; // current ROB number
273 Int_t fCurrMcmPos; // current MCM number
d60fe037 274
275 // DDL header
0508ca31 276 UInt_t fCurrEquipmentId; // current Equipment ID
d60fe037 277
9cb9c409 278 // SM header
279 UInt_t fCurrSmHeaderSize; // current size of the SM header
280 UInt_t fCurrSmHeaderVersion; // current version of the SM header
281 UInt_t fCurrTrailerReadout; // current presence of trailer (after the payload)
282 UInt_t fCurrTrgHeaderAvail; // current trigger information availability
283 UInt_t fCurrTrgHeaderReadout; // current readout mode for the trigger headers
284 UInt_t fCurrTrkHeaderAvail; // current tracking information availability
52a2b6c0 285 UInt_t fCurrStackEndmarkerAvail; // current stack endmarker availability
9cb9c409 286 UInt_t fCurrEvType; // current event type
287 UInt_t fCurrTriggerEnable; // current trigger enable
288 UInt_t fCurrTriggerFired; // current trigger fired
0508ca31 289 UInt_t fCurrTrackEnable; // current value of track enable
290 UInt_t fCurrTrackletEnable; // current value of tracklet enable
291 UInt_t fCurrStackMask; // current mask of active stacks
d60fe037 292
9cb9c409 293 // Tracking header
294 UInt_t *fCurrTrkHeaderIndexWord; // current tracking header index word
295 UInt_t *fCurrTrkHeaderSize; // current tracking header index word
2519cca4 296 ULong64_t *fCurrTrkFlags; // current tracking done flags
9cb9c409 297
298 // Trigger header
299 UInt_t *fCurrTrgHeaderIndexWord; // current tracking header index word
300 UInt_t *fCurrTrgHeaderSize; // current tracking header index word
2519cca4 301 UInt_t *fCurrTrgFlags; // current trigger flags of all sectors
9cb9c409 302
303 // Stack header
0508ca31 304 UInt_t *fCurrStackIndexWord; // current stack index words
305 UInt_t *fCurrStackHeaderSize; // current stack index sizes
306 UInt_t *fCurrStackHeaderVersion; // current stack header versions
307 UInt_t *fCurrLinkMask; // current link masks
308 UInt_t *fCurrCleanCheckout; // current clean checkout flags
309 UInt_t *fCurrBoardId; // current board IDs
9cb9c409 310 UInt_t fCurrHwRev; // current hardware revision
311 UInt_t *fCurrHwRevTMU; // current hardware revision
0508ca31 312 UInt_t *fCurrLinkMonitorFlags; // current link monitor flags
313 UInt_t *fCurrLinkDataTypeFlags; // current link data flags
314 UInt_t *fCurrLinkDebugFlags; // current link debug flags
d60fe037 315
52a2b6c0 316 // CRC checks from trailer
317 Char_t fCurrMatchFlagsSRAM;
318 Char_t fCurrMatchFlagsPostBP;
319 UInt_t fCurrChecksumStack[5];
320 UInt_t fCurrChecksumSIU;
321
d60fe037 322 // HC information
0508ca31 323 Int_t fCurrSpecial; // current value of the special flag
324 Int_t fCurrMajor; // current major version
325 Int_t fCurrMinor; // current minor version
326 Int_t fCurrAddHcWords; // current number of additional HC-header words
327 Int_t fCurrSm; // current sector
328 Int_t fCurrStack; // current stack
329 Int_t fCurrLayer; // current layer
330 Int_t fCurrSide; // current side
331 Int_t fCurrHC; // current HC
332 Int_t fCurrCheck; // current check bits
333 Int_t fCurrNtimebins; // current number of timebins
334 Int_t fCurrBC; // current BC
335 Int_t fCurrPtrgCnt; // current pretrigger count
336 Int_t fCurrPtrgPhase; // current pretrigger phase
d60fe037 337
cc26f39c 338 // settings for dumping
339 Int_t fDumpMCM[100]; // MCMs to dump
340 Int_t fNDumpMCMs; // number of MCMs to dump
341
d60fe037 342 // tracklet information
0508ca31 343 TClonesArray *fTrackletArray; // pointer to array for tracklet storage
d60fe037 344
345 // output data
0508ca31 346 AliTRDarrayADC *fAdcArray; // pointer to ADC array
347 AliTRDSignalIndex *fSignalIndex; // pointer to the signal index
348 TTree *fTrackletTree; // pointer to the tree for tracklet storage
5fdfc9e4 349 TClonesArray *fTracklets; // pointer to array of tracklets
350 TClonesArray *fTracks; // pointer to array of GTU tracks
351 TClonesArray *fMarkers; // pointer to array of markers (data present, errors, ...)
d60fe037 352
353 AliTRDrawStream(const AliTRDrawStream&); // not implemented
0508ca31 354 AliTRDrawStream& operator=(const AliTRDrawStream&); // not implemented
d60fe037 355
356 ClassDef(AliTRDrawStream, 0);
357};
358
82029d44 359Int_t AliTRDrawStream::GetNActiveChannelsFromMask(UInt_t adcmask) const
360{
361 // return number of active bits in the ADC mask
362
363 adcmask = GetActiveChannels(adcmask);
364 adcmask = adcmask - ((adcmask >> 1) & 0x55555555);
365 adcmask = (adcmask & 0x33333333) + ((adcmask >> 2) & 0x33333333);
366 return (((adcmask + (adcmask >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24;
367}
368
d60fe037 369#endif