]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RAW/AliRawReader.h
remove the removal of galice.root
[u/mrichter/AliRoot.git] / RAW / AliRawReader.h
1 #ifndef ALIRAWREADER_H
2 #define ALIRAWREADER_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 is the base class for reading raw data.
11 ///
12 ///////////////////////////////////////////////////////////////////////////////
13
14 #include <TObject.h>
15 #include <TArrayI.h>
16 #include <TClonesArray.h>
17
18 #include "AliRawDataErrorLog.h"
19 #include "AliRawDataHeader.h"
20
21 class AliRawEventHeaderBase;
22
23 class AliRawReader: public TObject {
24   public :
25     AliRawReader();
26     AliRawReader(const AliRawReader& rawReader);
27     AliRawReader& operator = (const AliRawReader& rawReader);
28     virtual ~AliRawReader();
29
30     static  AliRawReader* Create(const char *uri);
31
32     virtual void     Select(Int_t detectorID, 
33                             Int_t minDDLID = -1, Int_t maxDDLID = -1);
34     virtual void     Select(const char *detectorName, 
35                             Int_t minDDLID = -1, Int_t maxDDLID = -1);
36     virtual void     SelectEquipment(Int_t equipmentType, 
37                                      Int_t minEquipmentId = -1, 
38                                      Int_t maxEquipmentId = -1);
39     virtual void     SkipInvalid(Bool_t skip = kTRUE)
40       {fSkipInvalid = skip;};
41     virtual void     SelectEvents(Int_t type);
42     virtual void     RequireHeader(Bool_t required)
43       {fRequireHeader = required;};
44
45     virtual const AliRawEventHeaderBase* GetEventHeader() const {return NULL;};
46
47     virtual UInt_t   GetType() const = 0;
48     virtual UInt_t   GetRunNumber() const = 0;
49     virtual const UInt_t* GetEventId() const = 0;
50     virtual const UInt_t* GetTriggerPattern() const = 0;
51     virtual const UInt_t* GetDetectorPattern() const = 0;
52     virtual const UInt_t* GetAttributes() const = 0;
53     virtual const UInt_t* GetSubEventAttributes() const = 0;
54     virtual UInt_t   GetLDCId() const = 0;
55     virtual UInt_t   GetGDCId() const = 0;
56     virtual UInt_t   GetTimestamp() const = 0;
57
58     virtual Int_t    GetEquipmentSize() const = 0;
59     virtual Int_t    GetEquipmentType() const = 0;
60     virtual Int_t    GetEquipmentId() const = 0;
61     Int_t            GetMappedEquipmentId() const;
62     Bool_t           LoadEquipmentIdsMap(const char *fileName);
63     virtual const UInt_t* GetEquipmentAttributes() const = 0;
64     virtual Int_t    GetEquipmentElementSize() const = 0;
65     virtual Int_t    GetEquipmentHeaderSize() const = 0;
66
67     Int_t            GetDetectorID() const;
68     Int_t            GetDDLID() const;
69
70     Int_t            GetDataSize() const 
71       {if (fHeader) {
72         if (fHeader->fSize != 0xFFFFFFFF) return fHeader->fSize - sizeof(AliRawDataHeader); 
73         else return GetEquipmentSize() - GetEquipmentHeaderSize() - sizeof(AliRawDataHeader);
74       } else return GetEquipmentSize() - GetEquipmentHeaderSize();};
75
76     Int_t            GetVersion() const 
77       {if (fHeader) return fHeader->GetVersion(); else return -1;};
78     Bool_t           IsValid() const 
79       {if (fHeader) return fHeader->TestAttribute(0); 
80       else return kFALSE;};
81     Bool_t           IsCompressed() const 
82       {if (fHeader) return fHeader->TestAttribute(1); 
83       else return kFALSE;};
84     Bool_t           TestBlockAttribute(Int_t index) const
85       {if (fHeader) return fHeader->TestAttribute(index); 
86       else return kFALSE;};
87     UChar_t          GetBlockAttributes() const 
88       {if (fHeader) return fHeader->GetAttributes(); 
89       else return 0;};
90     UInt_t           GetStatusBits() const
91       {if (fHeader) return fHeader->GetStatus(); 
92       else return 0;};
93     const AliRawDataHeader* GetDataHeader() const
94       {return fHeader;}
95
96     virtual Bool_t   ReadHeader() = 0;
97     virtual Bool_t   ReadNextData(UChar_t*& data) = 0;
98     virtual Bool_t   ReadNextInt(UInt_t& data);
99     virtual Bool_t   ReadNextShort(UShort_t& data);
100     virtual Bool_t   ReadNextChar(UChar_t& data);
101     virtual Bool_t   ReadNext(UChar_t* data, Int_t size) = 0;
102
103     virtual Bool_t   Reset() = 0;
104
105     virtual Bool_t   NextEvent() = 0;
106     virtual Bool_t   RewindEvents() = 0;
107
108     enum {kErrMagic=1, kErrNoDataHeader=2, 
109           kErrSize=4, kErrOutOfBounds=8};
110     virtual Int_t    CheckData() const;
111     Int_t            GetErrorCode() const {return fErrorCode;};
112
113     void             DumpData(Int_t limit = -1);
114
115     void             AddErrorLog(AliRawDataErrorLog::ERawDataErrorLevel level,
116                                  Int_t code,
117                                  const char *message = NULL);
118     void             AddMinorErrorLog(Int_t code,
119                                       const char *message = NULL) {
120       return AddErrorLog(AliRawDataErrorLog::kMinor,code,message);
121     }
122     void             AddMajorErrorLog(Int_t code,
123                                       const char *message = NULL) {
124       return AddErrorLog(AliRawDataErrorLog::kMajor,code,message);
125     }
126     void             AddFatalErrorLog(Int_t code,
127                                       const char *message = NULL) {
128       return AddErrorLog(AliRawDataErrorLog::kFatal,code,message);
129     }
130     Int_t            GetNumberOfErrorLogs() const { return fErrorLogs.GetEntriesFast(); }
131     const TClonesArray &GetAllErrorLogs() const { return fErrorLogs; }
132     AliRawDataErrorLog *GetErrorLog(Int_t i) const {
133       return (AliRawDataErrorLog *)fErrorLogs.UncheckedAt(i);
134     }
135
136   protected :
137     Bool_t           IsSelected() const;
138     Bool_t           IsEventSelected() const;
139
140     TArrayI         *fEquipmentIdsIn;       // array of equipment Ids to be mapped
141     TArrayI         *fEquipmentIdsOut;      // array of mapped equipment Ids
142
143     Bool_t           fRequireHeader;        // if false, data without header is accepted
144
145     AliRawDataHeader* fHeader;              // current data header
146     Int_t            fCount;                // counter of bytes to be read for current DDL
147
148     Int_t            fSelectEquipmentType;  // type of selected equipment (<0 = no selection)
149     Int_t            fSelectMinEquipmentId; // minimal index of selected equipment (<0 = no selection)
150     Int_t            fSelectMaxEquipmentId; // maximal index of selected equipment (<0 = no selection)
151     Bool_t           fSkipInvalid;          // skip invalid data
152     Int_t            fSelectEventType;      // type of selected events (<0 = no selection)
153
154     Int_t            fErrorCode;            // code of last error
155
156     Int_t            fEventNumber;          // current event number
157     TClonesArray     fErrorLogs;            // raw data decoding errors
158
159     AliRawDataHeader* fHeaderSwapped;       // temporary buffer for swapping header on PowerPC
160
161     UInt_t SwapWord(UInt_t x) const;
162     UShort_t SwapShort(UShort_t x) const;
163
164     ClassDef(AliRawReader, 0) // base class for reading raw digits
165 };
166
167 #endif