]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RAW/AliRawReader.cxx
fix coding convention violations
[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 /* $Id$ */
17
18 ///////////////////////////////////////////////////////////////////////////////
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 ///
37 ///////////////////////////////////////////////////////////////////////////////
38
39 #include "AliRawReader.h"
40
41
42 ClassImp(AliRawReader)
43
44
45 AliRawReader::AliRawReader() :
46   fHeader(NULL),
47   fCount(0),
48   fSelectEquipmentType(-1),
49   fSelectMinEquipmentId(-1),
50   fSelectMaxEquipmentId(-1),
51   fSkipInvalid(kFALSE),
52   fErrorCode(0)
53 {
54 // default constructor: initialize data members
55
56 }
57
58 AliRawReader::AliRawReader(const AliRawReader& rawReader) :
59   TObject(rawReader),
60   fHeader(rawReader.fHeader),
61   fCount(rawReader.fCount),
62   fSelectEquipmentType(rawReader.fSelectEquipmentType),
63   fSelectMinEquipmentId(rawReader.fSelectMinEquipmentId),
64   fSelectMaxEquipmentId(rawReader.fSelectMaxEquipmentId),
65   fSkipInvalid(rawReader.fSkipInvalid),
66   fErrorCode(0)
67 {
68 // copy constructor
69
70 }
71
72 AliRawReader& AliRawReader::operator = (const AliRawReader& rawReader)
73 {
74 // assignment operator
75
76   fHeader = rawReader.fHeader;
77   fCount = rawReader.fCount;
78
79   fSelectEquipmentType = rawReader.fSelectEquipmentType;
80   fSelectMinEquipmentId = rawReader.fSelectMinEquipmentId;
81   fSelectMaxEquipmentId = rawReader.fSelectMaxEquipmentId;
82   fSkipInvalid = rawReader.fSkipInvalid;
83
84   fErrorCode = rawReader.fErrorCode;
85
86   return *this;
87 }
88
89
90 void AliRawReader::Select(Int_t detectorID, Int_t minDDLID, Int_t maxDDLID)
91 {
92 // read only data of the detector with the given ID and in the given
93 // range of DDLs (minDDLID <= DDLID <= maxDDLID).
94 // no selection is applied if a value < 0 is used.
95
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;
101 }
102
103 void 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
115 Bool_t AliRawReader::IsSelected() const
116 {
117 // apply the selection (if any)
118
119   if (fSkipInvalid && !IsValid()) return kFALSE;
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
131   return kTRUE;
132 }
133
134
135 Bool_t AliRawReader::ReadNextInt(UInt_t& data)
136 {
137 // reads the next 4 bytes at the current position
138 // returns kFALSE if the data could not be read
139
140   while (fCount == 0) {
141     if (!ReadHeader()) return kFALSE;
142   }
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))) {
149     Error("ReadNextInt", "could not read data!");
150     return kFALSE;
151   }
152   return kTRUE;
153 }
154
155 Bool_t AliRawReader::ReadNextShort(UShort_t& data)
156 {
157 // reads the next 2 bytes at the current position
158 // returns kFALSE if the data could not be read
159
160   while (fCount == 0) {
161     if (!ReadHeader()) return kFALSE;
162   }
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))) {
169     Error("ReadNextShort", "could not read data!");
170     return kFALSE;
171   }
172   return kTRUE;
173 }
174
175 Bool_t AliRawReader::ReadNextChar(UChar_t& data)
176 {
177 // reads the next 1 byte at the current stream position
178 // returns kFALSE if the data could not be read
179
180   while (fCount == 0) {
181     if (!ReadHeader()) return kFALSE;
182   }
183   if (!ReadNext((UChar_t*) &data, sizeof(data))) {
184     Error("ReadNextChar", "could not read data!");
185     return kFALSE;
186   }
187   return kTRUE;
188 }
189
190
191 Int_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
199
200 void 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
253     printf("data header:\n"
254            " size = %d  version = %d  valid = %d  compression = %d\n",
255            GetDataSize(), GetVersion(), IsValid(), IsCompressed());
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 }