]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RAW/AliRawReader.cxx
fix coding convention violations
[u/mrichter/AliRoot.git] / RAW / AliRawReader.cxx
CommitLineData
a6e7b125 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
bea6b2a4 16/* $Id$ */
17
a6e7b125 18///////////////////////////////////////////////////////////////////////////////
bea6b2a4 19///
20/// This is the base class for reading raw data.
21///
22/// The derived classes, which operate on concrete raw data formats,
23/// should implement
24/// - ReadHeader to read the next (data/equipment) header
25/// - ReadNextData to read the next raw data block (=1 DDL)
26/// - ReadNext to read a given number of bytes
27/// - several getters like GetType
28///
29/// Sequential access to the raw data is provided by the methods
30/// ReadHeader, ReadNextData, ReadNextInt, ReadNextShort, ReadNextChar
31///
32/// If only data from a specific detector (and a given range of DDL numbers)
33/// should be read, this can be achieved by the Select method.
34/// Several getters provide information about the current event and the
35/// current type of raw data.
36///
a6e7b125 37///////////////////////////////////////////////////////////////////////////////
38
39#include "AliRawReader.h"
40
8de97894 41
a6e7b125 42ClassImp(AliRawReader)
43
44
c946ab02 45AliRawReader::AliRawReader() :
39f9963f 46 fHeader(NULL),
c946ab02 47 fCount(0),
f224de6c 48 fSelectEquipmentType(-1),
49 fSelectMinEquipmentId(-1),
50 fSelectMaxEquipmentId(-1),
39f9963f 51 fSkipInvalid(kFALSE),
c946ab02 52 fErrorCode(0)
a6e7b125 53{
42d20574 54// default constructor: initialize data members
55
a6e7b125 56}
57
42d20574 58AliRawReader::AliRawReader(const AliRawReader& rawReader) :
c946ab02 59 TObject(rawReader),
39f9963f 60 fHeader(rawReader.fHeader),
c946ab02 61 fCount(rawReader.fCount),
f224de6c 62 fSelectEquipmentType(rawReader.fSelectEquipmentType),
63 fSelectMinEquipmentId(rawReader.fSelectMinEquipmentId),
64 fSelectMaxEquipmentId(rawReader.fSelectMaxEquipmentId),
39f9963f 65 fSkipInvalid(rawReader.fSkipInvalid),
c946ab02 66 fErrorCode(0)
42d20574 67{
68// copy constructor
69
42d20574 70}
71
72AliRawReader& AliRawReader::operator = (const AliRawReader& rawReader)
73{
74// assignment operator
75
39f9963f 76 fHeader = rawReader.fHeader;
42d20574 77 fCount = rawReader.fCount;
78
39f9963f 79 fSelectEquipmentType = rawReader.fSelectEquipmentType;
80 fSelectMinEquipmentId = rawReader.fSelectMinEquipmentId;
81 fSelectMaxEquipmentId = rawReader.fSelectMaxEquipmentId;
82 fSkipInvalid = rawReader.fSkipInvalid;
42d20574 83
b4857df7 84 fErrorCode = rawReader.fErrorCode;
85
42d20574 86 return *this;
87}
88
8de97894 89
90void AliRawReader::Select(Int_t detectorID, Int_t minDDLID, Int_t maxDDLID)
a6e7b125 91{
8de97894 92// read only data of the detector with the given ID and in the given
f224de6c 93// range of DDLs (minDDLID <= DDLID <= maxDDLID).
8de97894 94// no selection is applied if a value < 0 is used.
a6e7b125 95
39f9963f 96 fSelectEquipmentType = 0;
97 if (minDDLID < 0) minDDLID = 0;
98 fSelectMinEquipmentId = (detectorID << 8) + minDDLID;
99 if (maxDDLID < 0) maxDDLID = 0xFF;
100 fSelectMaxEquipmentId = (detectorID << 8) + maxDDLID;
8de97894 101}
a6e7b125 102
f224de6c 103void AliRawReader::SelectEquipment(Int_t equipmentType,
104 Int_t minEquipmentId, Int_t maxEquipmentId)
105{
106// read only data of the equipment with the given type and in the given
107// range of IDs (minEquipmentId <= EquipmentId <= maxEquipmentId).
108// no selection is applied if a value < 0 is used.
109
110 fSelectEquipmentType = equipmentType;
111 fSelectMinEquipmentId = minEquipmentId;
112 fSelectMaxEquipmentId = maxEquipmentId;
113}
114
42d20574 115Bool_t AliRawReader::IsSelected() const
a6e7b125 116{
8de97894 117// apply the selection (if any)
118
39f9963f 119 if (fSkipInvalid && !IsValid()) return kFALSE;
f224de6c 120
121 if (fSelectEquipmentType >= 0) {
122 if (GetEquipmentType() != fSelectEquipmentType) return kFALSE;
123 if ((fSelectMinEquipmentId >= 0) &&
124 (GetEquipmentId() < fSelectMinEquipmentId))
125 return kFALSE;
126 if ((fSelectMaxEquipmentId >= 0) &&
127 (GetEquipmentId() > fSelectMaxEquipmentId))
128 return kFALSE;
129 }
130
8de97894 131 return kTRUE;
a6e7b125 132}
133
134
a6e7b125 135Bool_t AliRawReader::ReadNextInt(UInt_t& data)
136{
8de97894 137// reads the next 4 bytes at the current position
138// returns kFALSE if the data could not be read
a6e7b125 139
140 while (fCount == 0) {
c946ab02 141 if (!ReadHeader()) return kFALSE;
a6e7b125 142 }
8de97894 143 if (fCount < (Int_t) sizeof(data)) {
144 Error("ReadNextInt",
145 "too few data left (%d bytes) to read an UInt_t!", fCount);
146 return kFALSE;
147 }
148 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
a6e7b125 149 Error("ReadNextInt", "could not read data!");
150 return kFALSE;
151 }
a6e7b125 152 return kTRUE;
153}
154
155Bool_t AliRawReader::ReadNextShort(UShort_t& data)
156{
8de97894 157// reads the next 2 bytes at the current position
158// returns kFALSE if the data could not be read
a6e7b125 159
160 while (fCount == 0) {
c946ab02 161 if (!ReadHeader()) return kFALSE;
a6e7b125 162 }
8de97894 163 if (fCount < (Int_t) sizeof(data)) {
164 Error("ReadNextShort",
165 "too few data left (%d bytes) to read an UShort_t!", fCount);
166 return kFALSE;
167 }
168 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
a6e7b125 169 Error("ReadNextShort", "could not read data!");
170 return kFALSE;
171 }
a6e7b125 172 return kTRUE;
173}
174
175Bool_t AliRawReader::ReadNextChar(UChar_t& data)
176{
177// reads the next 1 byte at the current stream position
8de97894 178// returns kFALSE if the data could not be read
a6e7b125 179
180 while (fCount == 0) {
c946ab02 181 if (!ReadHeader()) return kFALSE;
a6e7b125 182 }
8de97894 183 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
a6e7b125 184 Error("ReadNextChar", "could not read data!");
185 return kFALSE;
186 }
a6e7b125 187 return kTRUE;
188}
189
b4857df7 190
191Int_t AliRawReader::CheckData() const
192{
193// check the consistency of the data
194// derived classes should overwrite the default method which returns 0 (no err)
195
196 return 0;
197}
198
509a7696 199
200void AliRawReader::DumpData(Int_t limit)
201{
202// print the raw data
203// if limit is not negative, only the first and last "limit" lines of raw data
204// are printed
205
206 Reset();
207 if (!ReadHeader()) {
208 Error("DumpData", "no header");
209 return;
210 }
211 printf("header:\n"
212 " type = %d run = %d ", GetType(), GetRunNumber());
213 if (GetEventId()) {
214 printf("event = %8.8x %8.8x\n", GetEventId()[1], GetEventId()[0]);
215 } else {
216 printf("event = -------- --------\n");
217 }
218 if (GetTriggerPattern()) {
219 printf(" trigger = %8.8x %8.8x ",
220 GetTriggerPattern()[1], GetTriggerPattern()[0]);
221 } else {
222 printf(" trigger = -------- -------- ");
223 }
224 if (GetDetectorPattern()) {
225 printf("detector = %8.8x\n", GetDetectorPattern()[0]);
226 } else {
227 printf("detector = --------\n");
228 }
229 if (GetAttributes()) {
230 printf(" attributes = %8.8x %8.8x %8.8x ",
231 GetAttributes()[2], GetAttributes()[1], GetAttributes()[0]);
232 } else {
233 printf(" attributes = -------- -------- -------- ");
234 }
235 printf("GDC = %d\n", GetGDCId());
236 printf("\n");
237
238 do {
239 printf("-------------------------------------------------------------------------------\n");
240 printf("LDC = %d\n", GetLDCId());
241
242 printf("equipment:\n"
243 " size = %d type = %d id = %d\n",
244 GetEquipmentSize(), GetEquipmentType(), GetEquipmentId());
245 if (GetEquipmentAttributes()) {
246 printf(" attributes = %8.8x %8.8x %8.8x ", GetEquipmentAttributes()[2],
247 GetEquipmentAttributes()[1], GetEquipmentAttributes()[0]);
248 } else {
249 printf(" attributes = -------- -------- -------- ");
250 }
251 printf("element size = %d\n", GetEquipmentElementSize());
252
39f9963f 253 printf("data header:\n"
254 " size = %d version = %d valid = %d compression = %d\n",
255 GetDataSize(), GetVersion(), IsValid(), IsCompressed());
509a7696 256
257 printf("\n");
258 if (limit == 0) continue;
259
260 Int_t size = GetDataSize();
261 char line[70];
262 for (Int_t i = 0; i < 70; i++) line[i] = ' ';
263 line[69] = '\0';
264 Int_t pos = 0;
265 Int_t max = 16;
266 UChar_t byte;
267
268 for (Int_t n = 0; n < size; n++) {
269 if (!ReadNextChar(byte)) {
270 Error("DumpData", "couldn't read byte number %d\n", n);
271 break;
272 }
273 if (pos >= max) {
274 printf("%8.8x %s\n", n-pos, line);
275 for (Int_t i = 0; i < 70; i++) line[i] = ' ';
276 line[69] = '\0';
277 pos = 0;
278 if ((limit > 0) && (n/max == limit)) {
279 Int_t nContinue = ((size-1)/max+1-limit) * max;
280 if (nContinue > n) {
281 printf(" [skipping %d bytes]\n", nContinue-n);
282 n = nContinue-1;
283 continue;
284 }
285 }
286 }
287 Int_t offset = pos/4;
288 if ((byte > 0x20) && (byte < 0x7f)) {
289 line[pos+offset] = byte;
290 } else {
291 line[pos+offset] = '.';
292 }
293 char hex[3];
294 sprintf(hex, "%2.2x", byte);
295 line[max+max/4+3+2*pos+offset] = hex[0];
296 line[max+max/4+4+2*pos+offset] = hex[1];
297 pos++;
298 }
299
300 if (pos > 0) printf("%8.8x %s\n", size-pos, line);
301 printf("\n");
302
303 } while (ReadHeader());
304}