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