Removing unused variables
[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
16///////////////////////////////////////////////////////////////////////////////
17//
8de97894 18// This is the base class for reading raw data and providing
a6e7b125 19// information about digits
20//
42d20574 21// The derived classes, which operate on concrete raw data formats,
22// should implement
c946ab02 23// - ReadHeader to read the next (mini or equipment) header
42d20574 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
c946ab02 29// ReadHeader, ReadNextData, ReadNextInt, ReadNextShort, ReadNextChar
42d20574 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//
a6e7b125 36///////////////////////////////////////////////////////////////////////////////
37
38#include "AliRawReader.h"
39
8de97894 40
a6e7b125 41ClassImp(AliRawReader)
42
43
c946ab02 44AliRawReader::AliRawReader() :
45 fMiniHeader(NULL),
46 fCount(0),
47 fSelectDetectorID(-1),
48 fSelectMinDDLID(-1),
49 fSelectMaxDDLID(-1),
f224de6c 50 fSelectEquipmentType(-1),
51 fSelectMinEquipmentId(-1),
52 fSelectMaxEquipmentId(-1),
c946ab02 53 fErrorCode(0)
a6e7b125 54{
42d20574 55// default constructor: initialize data members
56
a6e7b125 57}
58
42d20574 59AliRawReader::AliRawReader(const AliRawReader& rawReader) :
c946ab02 60 TObject(rawReader),
61 fMiniHeader(rawReader.fMiniHeader),
62 fCount(rawReader.fCount),
63 fSelectDetectorID(rawReader.fSelectDetectorID),
64 fSelectMinDDLID(rawReader.fSelectMinDDLID),
65 fSelectMaxDDLID(rawReader.fSelectMaxDDLID),
f224de6c 66 fSelectEquipmentType(rawReader.fSelectEquipmentType),
67 fSelectMinEquipmentId(rawReader.fSelectMinEquipmentId),
68 fSelectMaxEquipmentId(rawReader.fSelectMaxEquipmentId),
c946ab02 69 fErrorCode(0)
42d20574 70{
71// copy constructor
72
42d20574 73}
74
75AliRawReader& AliRawReader::operator = (const AliRawReader& rawReader)
76{
77// assignment operator
78
79 fMiniHeader = rawReader.fMiniHeader;
80 fCount = rawReader.fCount;
81
82 fSelectDetectorID = rawReader.fSelectDetectorID;
83 fSelectMinDDLID = rawReader.fSelectMinDDLID;
84 fSelectMaxDDLID = rawReader.fSelectMaxDDLID;
85
b4857df7 86 fErrorCode = rawReader.fErrorCode;
87
42d20574 88 return *this;
89}
90
8de97894 91
92void AliRawReader::Select(Int_t detectorID, Int_t minDDLID, Int_t maxDDLID)
a6e7b125 93{
8de97894 94// read only data of the detector with the given ID and in the given
f224de6c 95// range of DDLs (minDDLID <= DDLID <= maxDDLID).
8de97894 96// no selection is applied if a value < 0 is used.
a6e7b125 97
8de97894 98 fSelectDetectorID = detectorID;
99 fSelectMinDDLID = minDDLID;
100 fSelectMaxDDLID = maxDDLID;
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
119 if (fSelectDetectorID >= 0) {
c946ab02 120 if (!fMiniHeader) return kFALSE;
8de97894 121 if (fMiniHeader->fDetectorID != fSelectDetectorID) return kFALSE;
122 if ((fSelectMinDDLID >= 0) && (fMiniHeader->fDDLID < fSelectMinDDLID))
123 return kFALSE;
f224de6c 124 if ((fSelectMaxDDLID >= 0) && (fMiniHeader->fDDLID > fSelectMaxDDLID))
8de97894 125 return kFALSE;
a6e7b125 126 }
f224de6c 127
128 if (fSelectEquipmentType >= 0) {
129 if (GetEquipmentType() != fSelectEquipmentType) return kFALSE;
130 if ((fSelectMinEquipmentId >= 0) &&
131 (GetEquipmentId() < fSelectMinEquipmentId))
132 return kFALSE;
133 if ((fSelectMaxEquipmentId >= 0) &&
134 (GetEquipmentId() > fSelectMaxEquipmentId))
135 return kFALSE;
136 }
137
8de97894 138 return kTRUE;
a6e7b125 139}
140
141
b4857df7 142Bool_t AliRawReader::CheckMiniHeader(AliMiniHeader* miniHeader) const
a6e7b125 143{
8de97894 144// check the magic number of the mini header
a6e7b125 145
b4857df7 146 if (!miniHeader) miniHeader = fMiniHeader;
c946ab02 147 if (!miniHeader) return kFALSE;
509a7696 148 UInt_t magicWord = miniHeader->fMagicWord[2]*65536 +
149 miniHeader->fMagicWord[1]*256 + miniHeader->fMagicWord[0];
150 if (magicWord != AliMiniHeader::kMagicWord) {
8de97894 151 return kFALSE;
a6e7b125 152 }
a6e7b125 153 return kTRUE;
154}
155
156Bool_t AliRawReader::ReadNextInt(UInt_t& data)
157{
8de97894 158// reads the next 4 bytes at the current position
159// returns kFALSE if the data could not be read
a6e7b125 160
161 while (fCount == 0) {
c946ab02 162 if (!ReadHeader()) return kFALSE;
a6e7b125 163 }
8de97894 164 if (fCount < (Int_t) sizeof(data)) {
165 Error("ReadNextInt",
166 "too few data left (%d bytes) to read an UInt_t!", fCount);
167 return kFALSE;
168 }
169 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
a6e7b125 170 Error("ReadNextInt", "could not read data!");
171 return kFALSE;
172 }
a6e7b125 173 return kTRUE;
174}
175
176Bool_t AliRawReader::ReadNextShort(UShort_t& data)
177{
8de97894 178// reads the next 2 bytes at the current position
179// returns kFALSE if the data could not be read
a6e7b125 180
181 while (fCount == 0) {
c946ab02 182 if (!ReadHeader()) return kFALSE;
a6e7b125 183 }
8de97894 184 if (fCount < (Int_t) sizeof(data)) {
185 Error("ReadNextShort",
186 "too few data left (%d bytes) to read an UShort_t!", fCount);
187 return kFALSE;
188 }
189 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
a6e7b125 190 Error("ReadNextShort", "could not read data!");
191 return kFALSE;
192 }
a6e7b125 193 return kTRUE;
194}
195
196Bool_t AliRawReader::ReadNextChar(UChar_t& data)
197{
198// reads the next 1 byte at the current stream position
8de97894 199// returns kFALSE if the data could not be read
a6e7b125 200
201 while (fCount == 0) {
c946ab02 202 if (!ReadHeader()) return kFALSE;
a6e7b125 203 }
8de97894 204 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
a6e7b125 205 Error("ReadNextChar", "could not read data!");
206 return kFALSE;
207 }
a6e7b125 208 return kTRUE;
209}
210
b4857df7 211
212Int_t AliRawReader::CheckData() const
213{
214// check the consistency of the data
215// derived classes should overwrite the default method which returns 0 (no err)
216
217 return 0;
218}
219
509a7696 220
221void AliRawReader::DumpData(Int_t limit)
222{
223// print the raw data
224// if limit is not negative, only the first and last "limit" lines of raw data
225// are printed
226
227 Reset();
228 if (!ReadHeader()) {
229 Error("DumpData", "no header");
230 return;
231 }
232 printf("header:\n"
233 " type = %d run = %d ", GetType(), GetRunNumber());
234 if (GetEventId()) {
235 printf("event = %8.8x %8.8x\n", GetEventId()[1], GetEventId()[0]);
236 } else {
237 printf("event = -------- --------\n");
238 }
239 if (GetTriggerPattern()) {
240 printf(" trigger = %8.8x %8.8x ",
241 GetTriggerPattern()[1], GetTriggerPattern()[0]);
242 } else {
243 printf(" trigger = -------- -------- ");
244 }
245 if (GetDetectorPattern()) {
246 printf("detector = %8.8x\n", GetDetectorPattern()[0]);
247 } else {
248 printf("detector = --------\n");
249 }
250 if (GetAttributes()) {
251 printf(" attributes = %8.8x %8.8x %8.8x ",
252 GetAttributes()[2], GetAttributes()[1], GetAttributes()[0]);
253 } else {
254 printf(" attributes = -------- -------- -------- ");
255 }
256 printf("GDC = %d\n", GetGDCId());
257 printf("\n");
258
259 do {
260 printf("-------------------------------------------------------------------------------\n");
261 printf("LDC = %d\n", GetLDCId());
262
263 printf("equipment:\n"
264 " size = %d type = %d id = %d\n",
265 GetEquipmentSize(), GetEquipmentType(), GetEquipmentId());
266 if (GetEquipmentAttributes()) {
267 printf(" attributes = %8.8x %8.8x %8.8x ", GetEquipmentAttributes()[2],
268 GetEquipmentAttributes()[1], GetEquipmentAttributes()[0]);
269 } else {
270 printf(" attributes = -------- -------- -------- ");
271 }
272 printf("element size = %d\n", GetEquipmentElementSize());
273
274 printf("mini header:\n"
275 " size = %d detector = %d DDL = %d\n"
276 " version = %d compression = %d\n",
277 GetDataSize(), GetDetectorID(), GetDDLID(),
278 GetVersion(), IsCompressed());
279
280 printf("\n");
281 if (limit == 0) continue;
282
283 Int_t size = GetDataSize();
284 char line[70];
285 for (Int_t i = 0; i < 70; i++) line[i] = ' ';
286 line[69] = '\0';
287 Int_t pos = 0;
288 Int_t max = 16;
289 UChar_t byte;
290
291 for (Int_t n = 0; n < size; n++) {
292 if (!ReadNextChar(byte)) {
293 Error("DumpData", "couldn't read byte number %d\n", n);
294 break;
295 }
296 if (pos >= max) {
297 printf("%8.8x %s\n", n-pos, line);
298 for (Int_t i = 0; i < 70; i++) line[i] = ' ';
299 line[69] = '\0';
300 pos = 0;
301 if ((limit > 0) && (n/max == limit)) {
302 Int_t nContinue = ((size-1)/max+1-limit) * max;
303 if (nContinue > n) {
304 printf(" [skipping %d bytes]\n", nContinue-n);
305 n = nContinue-1;
306 continue;
307 }
308 }
309 }
310 Int_t offset = pos/4;
311 if ((byte > 0x20) && (byte < 0x7f)) {
312 line[pos+offset] = byte;
313 } else {
314 line[pos+offset] = '.';
315 }
316 char hex[3];
317 sprintf(hex, "%2.2x", byte);
318 line[max+max/4+3+2*pos+offset] = hex[0];
319 line[max+max/4+4+2*pos+offset] = hex[1];
320 pos++;
321 }
322
323 if (pos > 0) printf("%8.8x %s\n", size-pos, line);
324 printf("\n");
325
326 } while (ReadHeader());
327}