]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDrawStream.h
Distortion macros - very preliminary version
[u/mrichter/AliRoot.git] / TRD / AliTRDrawStream.h
1 #ifndef ALITRDRAWSTREAM_H
2 #define ALITRDRAWSTREAM_H
3
4 #include "TObject.h"
5
6 #include "AliTRDrawStreamBase.h"
7 //#include "AliRawReader.h"
8
9 class TObjArray;
10 class TString;
11 class TTree;
12
13 class AliRawReader;
14 class AliTRDdigitsManager;
15 class AliTRDdigitsParam;
16 class AliTRDarrayADC;
17 class AliTRDSignalIndex;
18
19 class AliTRDrawStream : public AliTRDrawStreamBase
20 {
21  public:
22   AliTRDrawStream(AliRawReader *rawReader = 0x0);
23   ~AliTRDrawStream();
24
25   Bool_t SetReader(AliRawReader *rawReader) { fRawReader = rawReader; return kTRUE; }
26   void SetDigitsManager(AliTRDdigitsManager *digMgr) { fDigitsManager = digMgr; }
27
28   Bool_t ReadEvent(TTree *trackletTree = 0x0);
29
30   Bool_t NextDDL();
31   Int_t NextChamber(AliTRDdigitsManager *digMgr, 
32                     UInt_t ** /* trackletContainer */, UShort_t ** /* errorContainer */);
33
34   // legacy code, to be removed
35   Bool_t SetRawVersion(Int_t) { return kTRUE; }
36   void SetSharedPadReadout(Bool_t) {}
37   void SetNoErrorWarning() {}
38
39   // error handling
40   enum ErrorCode_t { 
41     kUnknown = 0, 
42     kLinkMonitor, 
43     kPtrgCntMismatch, 
44     kNonTrdEq,
45     kStackHeaderInvalid,
46     kInvalidDetector,
47     kNoDigits,
48     kHCmismatch,
49     kHCcheckFailed,
50     kPosUnexp,
51     kTPmodeInvalid,
52     kTPmismatch,
53     kNtimebinsChanged,
54     kAdcMaskInconsistent,
55     kAdcCheckInvalid,
56     kAdcDataAbort,
57     kAdcChannelsMiss,
58     kMissMcmHeaders,
59     kLastErrorCode
60   }; 
61
62   TTree* GetErrorTree() { return fErrors; }
63   static const char* GetErrorMessage(ErrorCode_t errCode);
64
65  protected:
66   Int_t ReadSmHeader();
67   Int_t ReadStackIndexHeader(Int_t stack);
68
69   Int_t ReadLinkData();
70   Int_t ReadTracklets();
71   Int_t ReadHcHeader();
72   Int_t ReadTPData(Int_t mode = 1);
73   Int_t ReadZSData();
74   Int_t ReadNonZSData();
75
76   // MCM header decoding
77   Int_t ROB(UInt_t mcmhdr) { return 0x7 & mcmhdr >> 28; }
78   Int_t MCM(UInt_t mcmhdr) { return 0xf & mcmhdr >> 24; }
79   Int_t Row(UInt_t mcmhdr) { return (ROB(mcmhdr) / 2) * 4 + MCM(mcmhdr) / 4; }
80   Int_t AdcColOffset(UInt_t mcmhdr) { return (MCM(mcmhdr) % 4 + 1) * 21 + (ROB(mcmhdr) % 2) * 84 - 1; }
81   Int_t PadColOffset(UInt_t mcmhdr) { return (MCM(mcmhdr) % 4 + 1) * 18 + (ROB(mcmhdr) % 2) * 72 + 1; }
82   Int_t EvNo(UInt_t mcmhdr) { return 0xfffff & mcmhdr >> 4; }
83   Int_t Check(UInt_t mcmhdr) { return 0xf & mcmhdr; }
84   Int_t CouldBeMCMhdr(UInt_t mcmhdr) { return ((0xf & mcmhdr) == 0xc); }
85
86   Int_t GetMCMReadoutPos(Int_t mcm) { return (mcm > -1 && mcm < 16) ? fgkMcmOrder[mcm] : -1; }
87   Int_t GetROBReadoutPos(Int_t rob) { return (rob > -1 && rob < 4) ? fgkRobOrder[rob] : -1; }
88
89   // ADC mask decoding
90   Int_t GetActiveChannels(UInt_t adcmask) { return 0x1fffff & adcmask >> 4; }
91   Int_t GetNActiveChannelsFromMask(UInt_t adcmask); // { Int_t nch = 0; for (Int_t i = 0; i < 21; i++) if ((GetActiveChannels(adcmask) & 1 << i)) nch++; return nch; }
92   Int_t GetNActiveChannels(UInt_t adcmask) { return (0x1f & ~(adcmask >> 25)); }
93   Int_t CouldBeADCmask(UInt_t adcmask) { return ((0xf & adcmask) == 0xc && (0x3 & adcmask >> 30) == 0x1); }
94       
95   // error message generation
96   TString EquipmentError(ErrorCode_t err = kUnknown, TString msg = ""); 
97   TString StackError    (ErrorCode_t err = kUnknown, TString msg = "");     
98   TString LinkError     (ErrorCode_t err = kUnknown, TString msg = ""); 
99   TString ROBError      (ErrorCode_t err = kUnknown, TString msg = ""); 
100   TString MCMError      (ErrorCode_t err = kUnknown, TString msg = ""); 
101
102   static char* fgErrorMessages[kLastErrorCode];
103
104   // I/O
105   AliRawReader *fRawReader;
106   AliTRDdigitsManager *fDigitsManager;
107   AliTRDdigitsParam   *fDigitsParam;
108
109   TTree *fErrors; 
110   struct { Int_t fSector; Int_t fStack; Int_t fLink; Int_t fError; Int_t fRob; Int_t fMcm; } fLastError; 
111
112   UInt_t *fPayloadStart;
113   UInt_t *fPayloadCurr;
114   Int_t   fPayloadSize;
115
116   static const Int_t fgkNlinks;
117   static const Int_t fgkNstacks;
118   static const UInt_t fgkDataEndmarker;
119   static const UInt_t fgkTrackletEndmarker;
120   static const Int_t fgkMcmOrder [];
121   static const Int_t fgkRobOrder [];
122
123   // persistent information
124   Int_t  fNtimebins;
125   Int_t  fLastEvId;
126
127   // information valid at current reader position
128   Int_t fCurrSlot;
129   Int_t fCurrLink;
130   Int_t fCurrRobPos; 
131   Int_t fCurrMcmPos;
132
133   // DDL header
134   UInt_t fCurrEquipmentId;
135
136   // SMU index header
137   UInt_t fCurrSmuIndexHeaderSize;
138   UInt_t fCurrSmuIndexHeaderVersion;
139   UInt_t fCurrTrackEnable;
140   UInt_t fCurrTrackletEnable; 
141   UInt_t fCurrStackMask;
142
143   // Stack index header
144   UInt_t *fCurrStackIndexWord;
145   UInt_t *fCurrStackHeaderSize;
146   UInt_t *fCurrStackHeaderVersion;
147   UInt_t *fCurrLinkMask;
148   UInt_t *fCurrCleanCheckout;
149   UInt_t *fCurrBoardId;
150   UInt_t *fCurrHwRev;
151   UInt_t *fCurrLinkMonitorFlags;
152   UInt_t *fCurrLinkDataTypeFlags;
153   UInt_t *fCurrLinkDebugFlags;
154
155   // HC information
156   Int_t fCurrSpecial;
157   Int_t fCurrMajor;
158   Int_t fCurrMinor;
159   Int_t fCurrAddHcWords;
160   Int_t fCurrSm;
161   Int_t fCurrStack;
162   Int_t fCurrLayer;
163   Int_t fCurrSide;
164   Int_t fCurrHC;
165   Int_t fCurrCheck;
166   Int_t fCurrNtimebins;
167   Int_t fCurrBC;
168   Int_t fCurrPtrgCnt;
169   Int_t fCurrPtrgPhase;
170
171   // tracklet information
172   TClonesArray *fTrackletArray;
173
174   // output data
175   AliTRDarrayADC *fAdcArray;
176   AliTRDSignalIndex *fSignalIndex;
177   TTree *fTrackletTree; 
178
179   AliTRDrawStream(const AliTRDrawStream&);           // not implemented
180   AliTRDrawStream operator=(const AliTRDrawStream&); // not implemented
181
182   ClassDef(AliTRDrawStream, 0);
183 };
184
185 #endif