]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RAW/AliRawReader.cxx
access to equipment header data, reading of DATE files, support of DATE events withou...
[u/mrichter/AliRoot.git] / RAW / AliRawReader.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 ///////////////////////////////////////////////////////////////////////////////
17 //
18 // This is the base class for reading raw data and providing
19 // information about digits
20 //
21 // The derived classes, which operate on concrete raw data formats,
22 // should implement
23 // - ReadHeader to read the next (mini or equipment) header
24 // - ReadNextData to read the next raw data block (=1 DDL)
25 // - ReadNext to read a given number of bytes
26 // - several getters like GetType
27 //
28 // Sequential access to the raw data is provided by the methods
29 // ReadHeader, ReadNextData, ReadNextInt, ReadNextShort, ReadNextChar
30 //
31 // If only data from a specific detector (and a given range of DDL numbers)
32 // should be read, this can be achieved by the Select method.
33 // Several getter provide information about the current event and the
34 // current type of raw data.
35 //
36 ///////////////////////////////////////////////////////////////////////////////
37
38 #include "AliRawReader.h"
39
40
41 ClassImp(AliRawReader)
42
43
44 AliRawReader::AliRawReader() :
45   fMiniHeader(NULL),
46   fCount(0),
47   fSelectDetectorID(-1),
48   fSelectMinDDLID(-1),
49   fSelectMaxDDLID(-1),
50   fErrorCode(0)
51 {
52 // default constructor: initialize data members
53
54 }
55
56 AliRawReader::AliRawReader(const AliRawReader& rawReader) :
57   TObject(rawReader),
58   fMiniHeader(rawReader.fMiniHeader),
59   fCount(rawReader.fCount),
60   fSelectDetectorID(rawReader.fSelectDetectorID),
61   fSelectMinDDLID(rawReader.fSelectMinDDLID),
62   fSelectMaxDDLID(rawReader.fSelectMaxDDLID),
63   fErrorCode(0)
64 {
65 // copy constructor
66
67 }
68
69 AliRawReader& AliRawReader::operator = (const AliRawReader& rawReader)
70 {
71 // assignment operator
72
73   fMiniHeader = rawReader.fMiniHeader;
74   fCount = rawReader.fCount;
75
76   fSelectDetectorID = rawReader.fSelectDetectorID;
77   fSelectMinDDLID = rawReader.fSelectMinDDLID;
78   fSelectMaxDDLID = rawReader.fSelectMaxDDLID;
79
80   fErrorCode = rawReader.fErrorCode;
81
82   return *this;
83 }
84
85
86 void AliRawReader::Select(Int_t detectorID, Int_t minDDLID, Int_t maxDDLID)
87 {
88 // read only data of the detector with the given ID and in the given
89 // range of DDLs (minDDLID <= DDLID < maxDDLID).
90 // no selection is applied if a value < 0 is used.
91
92   fSelectDetectorID = detectorID;
93   fSelectMinDDLID = minDDLID;
94   fSelectMaxDDLID = maxDDLID;
95 }
96
97 Bool_t AliRawReader::IsSelected() const
98 {
99 // apply the selection (if any)
100
101   if (fSelectDetectorID >= 0) {
102     if (!fMiniHeader) return kFALSE;
103     if (fMiniHeader->fDetectorID != fSelectDetectorID) return kFALSE;
104     if ((fSelectMinDDLID >= 0) && (fMiniHeader->fDDLID < fSelectMinDDLID))
105       return kFALSE;
106     if ((fSelectMaxDDLID >= 0) && (fMiniHeader->fDDLID >= fSelectMaxDDLID))
107       return kFALSE;
108   }
109   return kTRUE;
110 }
111
112
113 Bool_t AliRawReader::CheckMiniHeader(AliMiniHeader* miniHeader) const
114 {
115 // check the magic number of the mini header
116
117   if (!miniHeader) miniHeader = fMiniHeader;
118   if (!miniHeader) return kFALSE;
119   if ((miniHeader->fMagicWord[2] != 0x12) ||
120       (miniHeader->fMagicWord[1] != 0x34) ||
121       (miniHeader->fMagicWord[0] != 0x56)) {
122     return kFALSE;
123   }
124   return kTRUE;
125 }
126
127 Bool_t AliRawReader::ReadNextInt(UInt_t& data)
128 {
129 // reads the next 4 bytes at the current position
130 // returns kFALSE if the data could not be read
131
132   while (fCount == 0) {
133     if (!ReadHeader()) return kFALSE;
134   }
135   if (fCount < (Int_t) sizeof(data)) {
136     Error("ReadNextInt", 
137           "too few data left (%d bytes) to read an UInt_t!", fCount);
138     return kFALSE;
139   }
140   if (!ReadNext((UChar_t*) &data, sizeof(data))) {
141     Error("ReadNextInt", "could not read data!");
142     return kFALSE;
143   }
144   return kTRUE;
145 }
146
147 Bool_t AliRawReader::ReadNextShort(UShort_t& data)
148 {
149 // reads the next 2 bytes at the current position
150 // returns kFALSE if the data could not be read
151
152   while (fCount == 0) {
153     if (!ReadHeader()) return kFALSE;
154   }
155   if (fCount < (Int_t) sizeof(data)) {
156     Error("ReadNextShort", 
157           "too few data left (%d bytes) to read an UShort_t!", fCount);
158     return kFALSE;
159   }
160   if (!ReadNext((UChar_t*) &data, sizeof(data))) {
161     Error("ReadNextShort", "could not read data!");
162     return kFALSE;
163   }
164   return kTRUE;
165 }
166
167 Bool_t AliRawReader::ReadNextChar(UChar_t& data)
168 {
169 // reads the next 1 byte at the current stream position
170 // returns kFALSE if the data could not be read
171
172   while (fCount == 0) {
173     if (!ReadHeader()) return kFALSE;
174   }
175   if (!ReadNext((UChar_t*) &data, sizeof(data))) {
176     Error("ReadNextChar", "could not read data!");
177     return kFALSE;
178   }
179   return kTRUE;
180 }
181
182
183 Int_t AliRawReader::CheckData() const
184 {
185 // check the consistency of the data
186 // derived classes should overwrite the default method which returns 0 (no err)
187
188   return 0;
189 }
190