]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDrawStream.h
updates requested by HLT
[u/mrichter/AliRoot.git] / TRD / AliTRDrawStream.h
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
11 #ifndef ALITRDRAWSTREAM_H
12 #define ALITRDRAWSTREAM_H
13
14 #include "TObject.h"
15
16 #include "AliTRDrawStreamBase.h"
17 //#include "AliRawReader.h"
18
19 class TObjArray;
20 class TString;
21 class TTree;
22
23 class AliRawReader;
24 class AliTRDdigitsManager;
25 class AliTRDdigitsParam;
26 class AliTRDarrayADC;
27 class AliTRDSignalIndex;
28
29 class AliTRDrawStream : public AliTRDrawStreamBase
30 {
31  public:
32   AliTRDrawStream(AliRawReader *rawReader = 0x0);
33   ~AliTRDrawStream();
34
35   Bool_t SetReader(AliRawReader *rawReader) { fRawReader = rawReader; return kTRUE; }
36   void SetDigitsManager(AliTRDdigitsManager *digMgr) { fDigitsManager = digMgr; }
37
38   Bool_t ReadEvent(TTree *trackletTree = 0x0);
39
40   Bool_t NextDDL();
41   Int_t NextChamber(AliTRDdigitsManager *digMgr, 
42                     UInt_t ** /* trackletContainer */, UShort_t ** /* errorContainer */);
43
44   Bool_t ConnectTracklets(TTree *trklTree);
45
46   // legacy code, to be removed
47   Bool_t SetRawVersion(Int_t) { return kTRUE; }
48   void SetSharedPadReadout(Bool_t) {}
49   void SetNoErrorWarning() {}
50
51   // error handling
52   enum ErrorCode_t { 
53     kUnknown = 0, 
54     kLinkMonitor, 
55     kPtrgCntMismatch, 
56     kNonTrdEq,
57     kStackHeaderInvalid,
58     kInvalidDetector,
59     kNoDigits,
60     kHCmismatch,
61     kHCcheckFailed,
62     kPosUnexp,
63     kTPmodeInvalid,
64     kTPmismatch,
65     kNtimebinsChanged,
66     kAdcMaskInconsistent,
67     kAdcCheckInvalid,
68     kAdcDataAbort,
69     kAdcChannelsMiss,
70     kMissMcmHeaders,
71     kLastErrorCode
72   }; 
73
74   TTree* GetErrorTree() const { return fErrors; }
75   static const char* GetErrorMessage(ErrorCode_t errCode);
76
77  protected:
78   Int_t ReadSmHeader();
79   Int_t ReadStackIndexHeader(Int_t stack);
80
81   Int_t ReadLinkData();
82   Int_t ReadTracklets();
83   Int_t ReadHcHeader();
84   Int_t ReadTPData(Int_t mode = 1);
85   Int_t ReadZSData();
86   Int_t ReadNonZSData();
87
88   // MCM header decoding
89   Int_t ROB(UInt_t mcmhdr) const { return 0x7 & mcmhdr >> 28; }
90   Int_t MCM(UInt_t mcmhdr) const { return 0xf & mcmhdr >> 24; }
91   Int_t Row(UInt_t mcmhdr) const { return (ROB(mcmhdr) / 2) * 4 + MCM(mcmhdr) / 4; }
92   Int_t AdcColOffset(UInt_t mcmhdr) const { return (MCM(mcmhdr) % 4 + 1) * 21 + (ROB(mcmhdr) % 2) * 84 - 1; }
93   Int_t PadColOffset(UInt_t mcmhdr) const { return (MCM(mcmhdr) % 4 + 1) * 18 + (ROB(mcmhdr) % 2) * 72 + 1; }
94   Int_t EvNo(UInt_t mcmhdr) const { return 0xfffff & mcmhdr >> 4; }
95   Int_t Check(UInt_t mcmhdr) const { return 0xf & mcmhdr; }
96   Int_t CouldBeMCMhdr(UInt_t mcmhdr) const { return ((0xf & mcmhdr) == 0xc); }
97
98   Int_t GetMCMReadoutPos(Int_t mcm) const { return (mcm > -1 && mcm < 16) ? fgkMcmOrder[mcm] : -1; }
99   Int_t GetROBReadoutPos(Int_t rob) const { return (rob > -1 && rob < 4) ? fgkRobOrder[rob] : -1; }
100
101   // ADC mask decoding
102   Int_t GetActiveChannels(UInt_t adcmask) const { return 0x1fffff & adcmask >> 4; }
103   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; }
104   Int_t GetNActiveChannels(UInt_t adcmask) const { return (0x1f & ~(adcmask >> 25)); }
105   Int_t CouldBeADCmask(UInt_t adcmask) const { return ((0xf & adcmask) == 0xc && (0x3 & adcmask >> 30) == 0x1); }
106       
107   // error message generation
108   TString EquipmentError(ErrorCode_t err = kUnknown, TString msg = ""); 
109   TString StackError    (ErrorCode_t err = kUnknown, TString msg = "");     
110   TString LinkError     (ErrorCode_t err = kUnknown, TString msg = ""); 
111   TString ROBError      (ErrorCode_t err = kUnknown, TString msg = ""); 
112   TString MCMError      (ErrorCode_t err = kUnknown, TString msg = ""); 
113
114   static char* fgErrorMessages[kLastErrorCode]; // error messages corresponding to the error codes
115
116   // I/O
117   AliRawReader *fRawReader;                     // pointer to the raw reader to take the data from 
118   AliTRDdigitsManager *fDigitsManager;          // pointer to the digitsManager to fill the data
119   AliTRDdigitsParam   *fDigitsParam;            // pointer to the parameters belonging to the digits
120
121   TTree *fErrors;                               // tree containing the occured error codes
122   struct { Int_t fSector; Int_t fStack; Int_t fLink; Int_t fError; Int_t fRob; Int_t fMcm; } 
123   fLastError;                                   // last error which occured
124
125   UInt_t *fPayloadStart;                        // pointer to start of data payload
126   UInt_t *fPayloadCurr;                         // pointer to current reading position in the payload
127   Int_t   fPayloadSize;                         // size of the payload
128
129   static const Int_t fgkNlinks;                 // number of links to read
130   static const Int_t fgkNstacks;                // number of stacks to read
131   static const UInt_t fgkDataEndmarker;         // data endmarker 
132   static const UInt_t fgkTrackletEndmarker;     // tracklet endmarker
133   static const Int_t fgkMcmOrder [];            // expected readout order of the MCMs
134   static const Int_t fgkRobOrder [];            // expected readout order of the ROBs
135
136   // persistent information
137   Int_t  fNtimebins;                            // number of timebins
138   Int_t  fLastEvId;                             // Event ID of last event 
139
140   // information valid at current reader position
141   // all the variables fCurr... refer to the value at the current
142   // reading position
143   Int_t fCurrSlot;                              // current slot 
144   Int_t fCurrLink;                              // current link
145   Int_t fCurrRobPos;                            // current ROB number
146   Int_t fCurrMcmPos;                            // current MCM number
147
148   // DDL header
149   UInt_t fCurrEquipmentId;                      // current Equipment ID
150
151   // SMU index header
152   UInt_t fCurrSmuIndexHeaderSize;               // current size of the SMU index header
153   UInt_t fCurrSmuIndexHeaderVersion;            // current version of the SMU index header
154   UInt_t fCurrTrackEnable;                      // current value of track enable
155   UInt_t fCurrTrackletEnable;                   // current value of tracklet enable
156   UInt_t fCurrStackMask;                        // current mask of active stacks
157
158   // Stack index header
159   UInt_t *fCurrStackIndexWord;                  // current stack index words
160   UInt_t *fCurrStackHeaderSize;                 // current stack index sizes
161   UInt_t *fCurrStackHeaderVersion;              // current stack header versions
162   UInt_t *fCurrLinkMask;                        // current link masks
163   UInt_t *fCurrCleanCheckout;                   // current clean checkout flags
164   UInt_t *fCurrBoardId;                         // current board IDs
165   UInt_t *fCurrHwRev;                           // current hardware revision
166   UInt_t *fCurrLinkMonitorFlags;                // current link monitor flags
167   UInt_t *fCurrLinkDataTypeFlags;               // current link data flags
168   UInt_t *fCurrLinkDebugFlags;                  // current link debug flags
169
170   // HC information
171   Int_t fCurrSpecial;                           // current value of the special flag
172   Int_t fCurrMajor;                             // current major version
173   Int_t fCurrMinor;                             // current minor version
174   Int_t fCurrAddHcWords;                        // current number of additional HC-header words
175   Int_t fCurrSm;                                // current sector
176   Int_t fCurrStack;                             // current stack
177   Int_t fCurrLayer;                             // current layer
178   Int_t fCurrSide;                              // current side
179   Int_t fCurrHC;                                // current HC
180   Int_t fCurrCheck;                             // current check bits
181   Int_t fCurrNtimebins;                         // current number of timebins
182   Int_t fCurrBC;                                // current BC
183   Int_t fCurrPtrgCnt;                           // current pretrigger count
184   Int_t fCurrPtrgPhase;                         // current pretrigger phase
185
186   // tracklet information
187   TClonesArray *fTrackletArray;                 // pointer to array for tracklet storage
188
189   // output data
190   AliTRDarrayADC *fAdcArray;                    // pointer to ADC array
191   AliTRDSignalIndex *fSignalIndex;              // pointer to the signal index
192   TTree *fTrackletTree;                         // pointer to the tree for tracklet storage
193
194   AliTRDrawStream(const AliTRDrawStream&);           // not implemented
195   AliTRDrawStream& operator=(const AliTRDrawStream&); // not implemented
196
197   ClassDef(AliTRDrawStream, 0);
198 };
199
200 #endif