]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDRawStreamV2.h
Coding conventions
[u/mrichter/AliRoot.git] / TRD / AliTRDRawStreamV2.h
1 #ifndef ALITRDRAWSTREAMV2_H
2 #define ALITRDRAWSTREAMV2_H
3 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4  * See cxx source for full Copyright notice                               */
5
6 /* $Id$ */
7
8 ///////////////////////////////////////////////////////////////////////////////
9 //                                                                           //
10 // This class provides access to TRD digits in raw data.                     //
11 //                                                                           //
12 ///////////////////////////////////////////////////////////////////////////////
13
14 #include <TObject.h>
15
16 class AliTRDgeometry;
17 class AliRawReader;
18 class AliTRDdigitsManager;
19
20 class AliTRDRawStreamV2: public TObject {
21
22   public :
23
24     AliTRDRawStreamV2();
25     AliTRDRawStreamV2(AliRawReader *rawReader);
26     virtual ~AliTRDRawStreamV2();
27
28     virtual Bool_t       Next();                                //  Read the next data
29     virtual Int_t        NextChamber(AliTRDdigitsManager *man); //  Read next chamber data
30     virtual Int_t        Init();                                //  Init for the fRawVersion > 1
31
32     enum { kDDLOffset = 0x400 };                                //  Offset for DDL numbers
33
34     Bool_t               SetRawVersion(Int_t rv);
35     Int_t                GetRawVersion() const                      { return fRawVersion;     };
36     void                 SetRawReader(AliRawReader *rawReader);
37
38     // Get Filter settings (does not make a lot of sense):
39     Int_t                TRAPfilterTCon() const                     { return fTCon;           };
40     Int_t                TRAPfilterPEDon() const                    { return fPEDon;          };
41     Int_t                TRAPfilterGAINon() const                   { return fGAINon;         };
42     Int_t                TRAPsendsUnfilteredData() const            { return fBypass;         };
43
44     // Get Tracklet parameters (does not make a lot of sense):
45     Float_t              GetTrackletPID() const                     { return fTracklPID;      };
46     Float_t              GetTrackletDeflLength() const              { return fTracklDefL;     };
47     Float_t              GetTrackletPadPos() const                  { return fTracklPadPos;   };
48     Int_t                GetTrackletPadRow() const                  { return fTracklPadRow;   };
49
50     // Check if the link has optical power (HC sends data)
51     Bool_t               IsGTULinkActive(Int_t sm, Int_t la, Int_t sta, Int_t side)
52       { return ( ((fGTUlinkMask[sm][sta]) >> (2*la+side)) & 0x1 ); };
53
54     Int_t *GetSignals()          { return fSig;     } //  Signals in the three time bins from Data Word
55     Int_t GetADC() const         { return fADC;     } //  MCM ADC channel and Time Bin of word 1
56     Int_t GetTimeBin() const     { return fTB - 3;  } //  MCM ADC channel and Time Bin of word 1
57     Int_t GetEventNumber() const { return fEv;      } //  MCM Event number and position of current MCM on TRD chamber
58     Int_t GetROB() const         { return fROB;     } //  MCM Event number and position of current MCM on TRD chamber
59     Int_t GetMCM() const         { return fMCM;     } //  MCM Event number and position of current MCM on TRD chamber
60     Int_t GetSM() const          { return fSM;      } //  Position of CURRENT half chamber in full TRD
61     Int_t GetLayer() const       { return fLAYER;   } //  PLANE = Position of CURRENT half chamber in full TRD
62     Int_t GetStack() const       { return fSTACK;   } //  CHAMBER = Position of CURRENT half chamber in full TRD
63     Int_t GetROC() const         { return fROC;     } //  Position of CURRENT half chamber in full TRD
64     Int_t GetSide() const        { return fSIDE;    } //  Position of CURRENT half chamber in full TRD
65     Int_t GetDCS() const         { return fDCS;     } //  DCS board number read from data (HC header)
66     Int_t GetRow() const         { return fROW;     }
67     Int_t GetCol() const         { return fCOL;     } //  Detector Pad coordinates
68     Int_t GetDet() const         { return fDET;     } //  Helper
69     Int_t GetLastDet() const     { return fLastDET; } //  Helper
70     Int_t GetMaxRow() const      { return fRowMax;  }
71     Int_t GetMaxCol() const      { return fColMax;  }
72     Int_t GetNumberOfTimeBins() const 
73                                  { return fTBins;   }
74
75  protected:
76
77     AliTRDgeometry *fGeo;                     //  TRD geometry
78
79     Bool_t DecodeGTUlinkMask();
80     Bool_t DecodeNextRawWord();
81     Bool_t DecodeMCM();
82     Bool_t DecodeHC();
83     Bool_t DecodeSM();
84     inline void ChangeStatus(Int_t kstat);
85 /*       { */
86 /*      fLastStatus = fNextStatus; */
87 /*      fNextStatus = kstat;   */
88 /*       } */
89
90     void  DecodeHCheader(Int_t timeBins = 0);
91     void  DecodeMCMheader();
92     void  DecodeTracklet();
93
94     void  SetRawDigitThreshold (Int_t ith) 
95                 { fRawDigitThreshold = ith; } //  Set the naive zero suppression threshold
96
97     Int_t NextData();                         //  Get the next piece of memory
98     Int_t ChannelsToRead(Int_t ADCmask);      //  Get the active ADC channels from the mask (V3 and 2)
99
100     enum { kStart
101          , kStop
102          , kWordOK
103          , kNoMoreData
104          , kNextSM
105          , kNextHC
106          , kSeekNonEoTracklet
107          , kDecodeHC
108          , kNextMCM
109          , kNextData
110          , kReading };
111
112     // Some constants:
113     static const UInt_t fgkEndoftrackletmarker = 0xAAAAAAAA;     //  This marks the end of tracklet data words
114     static const UInt_t fgkEndofrawdatamarker  = 0x00000000;     //  This marks the end of half-chamber-data
115     static const UInt_t fgkSizeWord            = sizeof(UInt_t); //  Size of a word in bytes
116
117   private :
118
119     Int_t    fSig[3];                                            //  Signals in the three time bins from Data Word
120     Int_t    fADC;                                               //  MCM ADC channel and Time Bin of word 1
121     Int_t    fTB;                                                //  MCM ADC channel and Time Bin of word 1
122     Int_t    fEv;                                                //  MCM Event number and position of current MCM on TRD chamber
123     Int_t    fROB;                                               //  MCM Event number and position of current MCM on TRD chamber
124     Int_t    fMCM;                                               //  MCM Event number and position of current MCM on TRD chamber
125     Int_t    fSM;                                                //  Position of CURRENT half chamber in full TRD
126     Int_t    fLAYER;                                             //  Position of CURRENT half chamber in full TRD
127     Int_t    fSTACK;                                             //  Position of CURRENT half chamber in full TRD
128     Int_t    fROC;                                               //  Position of CURRENT half chamber in full TRD
129     Int_t    fSIDE;                                              //  Position of CURRENT half chamber in full TRD
130     Int_t    fDCS;                                               //  DCS board number read from data (HC header)
131     Int_t    fROW;                                               //  Detector Row coordinates
132     Int_t    fCOL;                                               //  Detector Pad coordinates
133     Int_t    fDET;                                               //  Current detector - version > 1
134     Int_t    fLastDET;                                           //  Previous detector - version > 1
135
136     Int_t    fBCctr;                                             //  Counters from HC header (>=V2)
137     Int_t    fPTctr;                                             //  Counters from HC header (>=V2)
138     Int_t    fPTphase;                                           //  Counters from HC header (>=V2)
139     Int_t    fRVmajor;                                           //  Raw version numbers and number of additional HC headerwords (>=V2)
140     Int_t    fRVminor;                                           //  Raw version numbers and number of additional HC headerwords (>=V2)
141     Int_t    fHCHWords;                                          //  Raw version numbers and number of additional HC headerwords (>=V2)
142     Int_t    fTBins;                                             //  Number of time bins read from HC header (>=V2)
143     Bool_t   fTCon;                                              //  Filter settings read from HC header (>=V2)
144     Bool_t   fPEDon;                                             //  Filter settings read from HC header (>=V2)
145     Bool_t   fGAINon;                                            //  Filter settings read from HC header (>=V2)
146     Bool_t   fXTon;                                              //  Filter settings read from HC header (>=V2)
147     Bool_t   fNonLinOn;                                          //  Filter settings read from HC header (>=V2)
148     Bool_t   fBypass;                                            //  Filter settings read from HC header (>=V2)
149     Int_t    fCommonAdditive;                                    //  Common baseline additive read from HC header (>=V2)
150
151     Bool_t   fZeroSuppressed;                                    //  Data is zero suppressed
152
153     Int_t    fHCHctr1;                        //  HC and MCM Header counter
154     Int_t    fHCHctr2;                        //  HC and MCM Header counter
155     Int_t    fMCMHctr1;                       //  HC and MCM Header counter
156     Int_t    fMCMHctr2;                       //  HC and MCM Header counter
157     Int_t    fGTUctr1;                        //  GTU LinkMask Counter
158     Int_t    fGTUctr2;                        //  GTU LinkMask Counter
159     Int_t    fHCdataCtr;                      //  Data Counter for half chamber
160     
161     Float_t  fTracklPID;                      //  Tracklet parameters
162     Float_t  fTracklDefL;                     //  Tracklet parameters
163     Float_t  fTracklPadPos;                   //  Tracklet parameters
164     Int_t    fTracklPadRow;                   //  Tracklet parameters
165
166     UShort_t fGTUlinkMask[18][5];             //  Mask with active links
167
168     Int_t    fMCMWordCrt;                     //  Word Counter for a single MCM
169     Int_t    fMCMWordsExpected;               //  Expected Words from MCM 
170
171     AliTRDRawStreamV2(const AliTRDRawStreamV2 &stream);
172     AliTRDRawStreamV2 &operator=(const AliTRDRawStreamV2 &stream);
173
174     AliRawReader *fRawReader;                 //  Object for reading the raw data
175
176     Int_t    fRawVersion;                     //  Which version of raw data decoding is used
177     Int_t    fRawDigitThreshold;              //  Naive "zero"(threshold) supression. Usefull for Raw Data ver 2.
178
179     Int_t    fNextStatus;                     //  Navigation in raw versions > 1
180     Int_t    fLastStatus;                     //  Navigation in raw versions > 1
181     UInt_t   fTbSwitch;                       //  Time Bin Switch for internal use
182     UInt_t   fTbSwitchCtr;                    //  Counter for internal use
183     UInt_t   fTimeWords;                      //  Number of Words needed to store the data of 1 ADC ch.
184     UInt_t   fWordCtr;                        //  Word Counter
185
186     Int_t    fRowMax;                         //  Maximum number of pad rows and columns
187     Int_t    fColMax;                         //  Maximum number of pad rows and columns
188
189     Bool_t   fADCmask[21];                    //  Mask of active ADCs for zero suppression
190     UInt_t   fLastADCmask;                    //  Last ADC read out
191
192     UShort_t fChamberDone[540];               //  Chamber was processed already (1=1HC, 2=full chamber)
193
194     Int_t    fRetVal;                         //  Datadecode return
195     Int_t    fEqID;                           //  Equipment id
196     UInt_t   fDataSize;                       //  Size of the data available in the current buffer
197     Bool_t   fSizeOK;                         //  Did we read anything
198     UInt_t   fCountBytes;                     //  Bytes traversed in the buffer
199     UInt_t   fBufSize;                        //  Size of the current RawReader buffer
200     Bool_t   fkBufferSet;                     //  Is the RawReader buffer available
201     UChar_t *fPos;                            //  Position in the buffer of the RawReader
202     UInt_t  *fDataWord;                       //  The pointer to the current 32 bit data word
203     UInt_t   fTimeBinsCalib;                  //  N of time bins retrieved from calibration
204
205     Int_t    fADClookup[32];                  //  Lookup for version 3 (1[entries]+1[index]+30[fADC channels] = 32)
206     Int_t    fNActiveADCs;                    //  Number of active ADC channels
207     Bool_t   fEndOfDataFlag;                  //  End of data flag
208
209     enum ETRDzRawStreamError {
210        kHCWordMissing       =  1              //
211       ,kMCMADCMaskMissing   =  2              //
212       ,kWrongMCMorROB       =  3              //
213       ,kGTULinkMaskMissing  =  4              //
214       ,kHCHeaderCorrupt     =  5              //
215       ,kHCHeaderMissing     =  6              //
216       ,kROBSideMismatch     =  7              //
217       ,kWrongPadrow         =  8              //
218       ,kWrongPadcolumn      =  9              //
219       ,kTrackletRowMismatch = 10              //
220       ,kDataMaskError       = 11              //
221       ,kADCNumberOverflow   = 12              //
222       ,kADCChannelOverflow  = 13              //
223     };
224     
225     ClassDef(AliTRDRawStreamV2,1)                                //  Class for reading TRD raw digits
226
227 };
228 #endif