]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RAW/AliAltroRawStreamV3.h
ea7a21f3cec66f6fea45b4859afff6b22bce9bfc
[u/mrichter/AliRoot.git] / RAW / AliAltroRawStreamV3.h
1 #ifndef ALIALTRORAWSTREAMV3_H
2 #define ALIALTRORAWSTREAMV3_H
3 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4  * See cxx source for full Copyright notice                               */
5
6 ///////////////////////////////////////////////////////////////////////////////
7 ///
8 /// This is a base class for reading raw data digits in Altro format.
9 /// The class is able to read the RCU v3 and above formats.
10 /// The main difference between the format V3 and older ones is in
11 /// the coding of the 10-bit Altro payload words. In V3 3 10-bit words
12 /// are coded in one 32-bit word. The bits 30 and 31 are used to identify
13 /// the payload, altro header and RCU trailer contents.
14 ///
15 ///
16 /// cvetan.cheshkov@cern.ch 1/04/2009
17 ///////////////////////////////////////////////////////////////////////////////
18
19 #include <TObject.h>
20
21 class AliRawReader;
22 class AliAltroRawStream;
23
24 class AliAltroRawStreamV3: public TObject {
25   public :
26     AliAltroRawStreamV3(AliRawReader* rawReader);
27     virtual ~AliAltroRawStreamV3();
28
29     AliAltroRawStreamV3& operator = (const AliAltroRawStreamV3& stream);
30     AliAltroRawStreamV3(const AliAltroRawStreamV3& stream);
31
32     void SelectRawData(Int_t detId);                           // Select raw data for specific detector id
33     void SelectRawData(const char *detName);                   // Select raw data for specific detector name
34
35     virtual void   Reset();                                    // Reset the raw-stream object
36
37     virtual Bool_t NextDDL();                                  // Iterate over DDLs/RCUs
38     virtual Bool_t NextChannel();                              // Iterate over altro channels
39     virtual Bool_t NextBunch();                                // Iterate over altro bunches
40
41     Int_t  GetDDLNumber()      const { return fDDLNumber; }    // Provide current DDL number
42     Int_t  GetHWAddress()      const { return fHWAddress; }    // Provide current hardware address
43     Int_t  GetRCUId()          const { return fRCUId; }        // Provide current RCU identifier
44  
45     UInt_t GetStartTimeBin()   const { return fStartTimeBin; } // Provide the index if the first time-bin in current bunch
46     UInt_t GetEndTimeBin()     const { return fStartTimeBin-fBunchLength+1; } // Provide the index of the last time-bin in current bunch
47     Int_t  GetBunchLength()    const { return fBunchLength; }  // Provide the current bunch length
48     const UShort_t* GetSignals() const { return fBunchDataPointer; }  // Provide access to altro data itself
49     Bool_t IsChannelBad()      const { return fBadChannel; }   // Is the channel data bad or not
50
51     Int_t GetChannelPayloadSize() const { return fChannelPayloadSize; }
52
53     Int_t GetBranch()     const; // Provide the branch index for the current hardware address
54     Int_t GetFEC()        const; // Provide the front-end card index for the current hardware address
55     Int_t GetAltro()      const; // Provide the altro chip index for the current hardware address
56     Int_t GetChannel()    const; // Provide the channel index for the current hardware address
57
58     Bool_t  GetRCUTrailerData(UChar_t*& data) const;              // Provide a pointer to RCU trailer
59     Int_t   GetRCUTrailerSize() const { return fRCUTrailerSize; } // Provide size of RCU trailer
60
61     // RCU trailer related getters
62     UInt_t  GetFECERRA() const { return fFECERRA; }
63     UInt_t  GetFECERRB() const { return fFECERRB; }
64     UShort_t GetERRREG2() const { return fERRREG2; }
65     UShort_t GetNChAddrMismatch() const { return (fERRREG3 & 0xFFF); }
66     UShort_t GetNChLengthMismatch() const { return ((fERRREG3 >> 12) & 0x1FFF); }
67
68     UShort_t GetActiveFECsA() const { return fActiveFECsA; }
69     UShort_t GetActiveFECsB() const { return fActiveFECsB; }
70
71     UInt_t  GetAltroCFG1() const { return fAltroCFG1; }
72     UChar_t GetBaselineCorr() const { return fAltroCFG1 & 0xF; }
73     Bool_t  GetPolarity() const { return (fAltroCFG1 >> 4) & 0x1; }
74     UChar_t GetNPresamples() const  { return (fAltroCFG1 >> 5) & 0x3; }
75     UChar_t GetNPostsamples() const { return (fAltroCFG1 >> 7) & 0xF; }
76     Bool_t  GetSecondBaselineCorr() const { return (fAltroCFG1 >> 11) & 0x1; }
77     UChar_t GetGlitchFilter() const { return (fAltroCFG1 >> 12) & 0x3; }
78     UChar_t GetNNonZSPostsamples() const { return (fAltroCFG1 >> 14) & 0x7; }
79     UChar_t GetNNonZSPresamples() const  { return (fAltroCFG1 >> 17) & 0x3; }
80     Bool_t  GetZeroSupp() const          { return (fAltroCFG1 >> 19) & 0x1; }
81     
82     UInt_t   GetAltroCFG2() const { return fAltroCFG2; }
83     Bool_t   GetNAltroBuffers() const     { return (fAltroCFG2 >> 24) & 0x1; }
84     UChar_t  GetNPretriggerSamples() const{ return (fAltroCFG2 >> 20) & 0xF; }
85     UShort_t GetNSamplesPerCh() const     { return (fAltroCFG2 >> 10) & 0x3FF; }
86     Bool_t   GetSparseRO() const          { return (fAltroCFG2 >> 9) & 0x1; }
87     Double_t GetTSample() const;
88     Double_t GetL1Phase() const;
89     void     PrintRCUTrailer() const;
90  
91     void  SetShortDataHeader(Bool_t flag) { fIsShortDataHeader = flag; } // Specify whenever to assume or not a short CDH format
92
93     void  SetCheckAltroPayload(Bool_t check) { fCheckAltroPayload = check; }
94
95     enum EAltroRawStreamV3Error {
96       kRCUTrailerErr = 1,
97       kRCUVerErr = 2,
98       kRCUTrailerSizeErr = 3,
99       kAltroBunchHeadErr = 4,
100       kBunchLengthErr = 5,
101       kAltroPayloadErr = 6,
102       kBadAltroMapping = 7
103     };
104
105     enum {kMaxNTimeBins = 1024};
106
107   protected:
108
109     void             AddMappingErrorLog(const char *message = NULL);
110
111     Bool_t           fIsShortDataHeader; // flag used to select between normal and short CDH format
112
113   private:
114
115     UInt_t           Get32bitWord(Int_t index) const;
116     Bool_t           ReadRCUTrailer(UChar_t rcuVer);
117
118     Int_t            fDDLNumber;    // index of current DDL number
119     Int_t            fRCUId;        // current RCU identifier
120     Short_t          fHWAddress;    // current hardware address
121
122     AliRawReader*    fRawReader;    // object for reading the raw data
123
124     UChar_t*         fData;         // raw data
125
126     Int_t            fPosition;     // current position (32-bit words) in fData
127     Int_t            fCount;        // 
128     Int_t            fStartTimeBin; //
129     Int_t            fBunchLength;  //
130
131     Bool_t           fBadChannel;   //
132     Int_t            fPayloadSize;  //
133
134     Int_t            fChannelPayloadSize; //
135
136     UShort_t         fBunchData[kMaxNTimeBins];    // cache for the decoded altro payload
137     UShort_t*        fBunchDataPointer;            // pointer to the current bunch samples
138     Int_t            fBunchDataIndex;              // current position in the payload
139
140     UChar_t*         fRCUTrailerData; // pointer to RCU trailer data
141     Int_t            fRCUTrailerSize; // size of RCU trailer data in bytes
142
143     // RCU trailer contents
144     UInt_t           fFECERRA;      // contains errors related to ALTROBUS transactions
145     UInt_t           fFECERRB;      // contains errors related to ALTROBUS transactions
146     UShort_t         fERRREG2;      // contains errors related to ALTROBUS transactions or trailer of ALTRO channel block
147     UInt_t           fERRREG3;      // contains number of altro channels skipped due to an address mismatch 
148     UShort_t         fActiveFECsA;  // bit pattern of active FECs in branch A
149     UShort_t         fActiveFECsB;  // bit pattern of active FECs in branch B
150     UInt_t           fAltroCFG1;    // ALTROCFG1 register
151     UInt_t           fAltroCFG2;    // ALTROCFG2 and ALTROIF registers
152
153     AliAltroRawStream* fOldStream;  // streamer for old altro format
154
155     Bool_t           fCheckAltroPayload; // check altro payload correctness or not?
156
157     ClassDef(AliAltroRawStreamV3, 0)  // base class for reading Altro raw digits
158 };
159
160 #endif