]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RAW/AliRawReader.cxx
8caccf84d5d415411295c461fd811cb390630aef
[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 <TClass.h>
40 #include <TPluginManager.h>
41 #include <TROOT.h>
42 #include <TInterpreter.h>
43 #include <TSystem.h>
44 #include <TPRegexp.h>
45
46 #include <Riostream.h>
47 #include "AliRawReader.h"
48 #include "AliRawReaderFile.h"
49 #include "AliRawReaderDate.h"
50 #include "AliRawReaderRoot.h"
51 #include "AliRawReaderChain.h"
52 #include "AliDAQ.h"
53 #include "AliLog.h"
54
55 ClassImp(AliRawReader)
56
57
58 AliRawReader::AliRawReader() :
59   fEquipmentIdsIn(NULL),
60   fEquipmentIdsOut(NULL),
61   fRequireHeader(kTRUE),
62   fHeader(NULL),
63   fCount(0),
64   fSelectEquipmentType(-1),
65   fSelectMinEquipmentId(-1),
66   fSelectMaxEquipmentId(-1),
67   fSkipInvalid(kFALSE),
68   fSelectEventType(-1),
69   fSelectTriggerMask(0),
70   fSelectTriggerExpr(),
71   fErrorCode(0),
72   fEventNumber(-1),
73   fErrorLogs("AliRawDataErrorLog",100),
74   fHeaderSwapped(NULL),
75   fIsValid(kTRUE)
76 {
77 // default constructor: initialize data members
78 // Allocate the swapped header in case of Mac
79 #ifndef R__BYTESWAP
80   fHeaderSwapped=new AliRawDataHeader();
81 #endif
82 }
83
84 Bool_t AliRawReader::LoadEquipmentIdsMap(const char *fileName)
85 {
86   // Open the mapping file
87   // and load the mapping data
88   ifstream input(fileName);
89   if (input.is_open()) {
90     Warning("AliRawReader","Equipment ID mapping file is found !");
91     const Int_t kMaxDDL = 256;
92     fEquipmentIdsIn = new TArrayI(kMaxDDL);
93     fEquipmentIdsOut = new TArrayI(kMaxDDL);
94     Int_t equipIn, equipOut;
95     Int_t nIds = 0;
96     while (input >> equipIn >> equipOut) {
97       if (nIds >= kMaxDDL) {
98         Error("AliRawReader","Too many equipment Id mappings found ! Truncating the list !");
99         break;
100       }
101       fEquipmentIdsIn->AddAt(equipIn,nIds); 
102       fEquipmentIdsOut->AddAt(equipOut,nIds);
103       nIds++;
104     }
105     fEquipmentIdsIn->Set(nIds);
106     fEquipmentIdsOut->Set(nIds);
107     input.close();
108     return kTRUE;
109   }
110   else {
111     Error("AliRawReader","equipment id map file is not found ! Skipping the mapping !");
112     return kFALSE;
113   }
114 }
115
116 AliRawReader::AliRawReader(const AliRawReader& rawReader) :
117   TObject(rawReader),
118   fEquipmentIdsIn(rawReader.fEquipmentIdsIn),
119   fEquipmentIdsOut(rawReader.fEquipmentIdsOut),
120   fRequireHeader(rawReader.fRequireHeader),
121   fHeader(rawReader.fHeader),
122   fCount(rawReader.fCount),
123   fSelectEquipmentType(rawReader.fSelectEquipmentType),
124   fSelectMinEquipmentId(rawReader.fSelectMinEquipmentId),
125   fSelectMaxEquipmentId(rawReader.fSelectMaxEquipmentId),
126   fSkipInvalid(rawReader.fSkipInvalid),
127   fSelectEventType(rawReader.fSelectEventType),
128   fSelectTriggerMask(rawReader.fSelectTriggerMask),
129   fSelectTriggerExpr(rawReader.fSelectTriggerExpr),
130   fErrorCode(0),
131   fEventNumber(-1),
132   fErrorLogs("AliRawDataErrorLog",100),
133   fHeaderSwapped(NULL),
134   fIsValid(rawReader.fIsValid)
135 {
136 // copy constructor
137 // Allocate the swapped header in case of Mac
138 #ifndef R__BYTESWAP
139   fHeaderSwapped=new AliRawDataHeader(*rawReader.fHeaderSwapped);
140 #endif
141 }
142
143 AliRawReader& AliRawReader::operator = (const AliRawReader& rawReader)
144 {
145 // assignment operator
146   fEquipmentIdsIn = rawReader.fEquipmentIdsIn;
147   fEquipmentIdsOut = rawReader.fEquipmentIdsOut;
148
149   fHeader = rawReader.fHeader;
150   fCount = rawReader.fCount;
151
152   fSelectEquipmentType = rawReader.fSelectEquipmentType;
153   fSelectMinEquipmentId = rawReader.fSelectMinEquipmentId;
154   fSelectMaxEquipmentId = rawReader.fSelectMaxEquipmentId;
155   fSkipInvalid = rawReader.fSkipInvalid;
156   fSelectEventType = rawReader.fSelectEventType;
157   fSelectTriggerMask = rawReader.fSelectTriggerMask;
158   fSelectTriggerExpr = rawReader.fSelectTriggerExpr;
159
160   fErrorCode = rawReader.fErrorCode;
161
162   fEventNumber = rawReader.fEventNumber;
163   fErrorLogs = *((TClonesArray*)rawReader.fErrorLogs.Clone());
164
165   fIsValid = rawReader.fIsValid;
166
167   return *this;
168 }
169
170 AliRawReader::~AliRawReader()
171 {
172   // destructor
173   // delete the mapping arrays if
174   // initialized
175   if (fEquipmentIdsIn) delete fEquipmentIdsIn;
176   if (fEquipmentIdsOut) delete fEquipmentIdsOut;
177   fErrorLogs.Delete();
178   if (fHeaderSwapped) delete fHeaderSwapped;
179 }
180
181 AliRawReader* AliRawReader::Create(const char *uri)
182 {
183   // RawReader's factory
184   // It instantiate corresponding raw-reader implementation class object
185   // depending on the URI provided
186   // Normal URIs point to files, while the URI starting with
187   // 'mem://:' or 'mem://<filename>' will create
188   // AliRawReaderDateOnline object which is supposed to be used
189   // in the online reconstruction
190
191   TString strURI = uri;
192
193   if (strURI.IsNull()) {
194     AliWarningClass("No raw-reader created");
195     return NULL;
196   }
197
198   TObjArray *fields = strURI.Tokenize("?");
199   TString &fileURI = ((TObjString*)fields->At(0))->String();
200
201   AliRawReader *rawReader = NULL;
202   if (fileURI.BeginsWith("mem://") || fileURI.BeginsWith("^")) {
203     if (fileURI.BeginsWith("mem://")) fileURI.ReplaceAll("mem://","");
204     AliInfoClass(Form("Creating raw-reader in order to read events in shared memory (option=%s)",fileURI.Data()));
205
206     TPluginManager* pluginManager = gROOT->GetPluginManager();
207     TString rawReaderName = "AliRawReaderDateOnline";
208     TPluginHandler* pluginHandler = pluginManager->FindHandler("AliRawReader", "online");
209     // if not, add a plugin for it
210     if (!pluginHandler) {
211       pluginManager->AddHandler("AliRawReader", "online", 
212                                 "AliRawReaderDateOnline", "RAWDatarecOnline", "AliRawReaderDateOnline(const char*)");
213       pluginHandler = pluginManager->FindHandler("AliRawReader", "online");
214     }
215     if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
216       rawReader = (AliRawReader*)pluginHandler->ExecPlugin(1,fileURI.Data());
217     }
218     else {
219       delete fields;
220       return NULL;
221     }
222   }
223   else if (fileURI.BeginsWith("amore://")) {
224     // A special raw-data URL used in case
225     // the raw-data reading is steered from
226     // ouside, i.e. from AMORE
227     fileURI.ReplaceAll("amore://","");
228     AliInfoClass("Creating raw-reader in order to read events sent by AMORE");
229     rawReader = new AliRawReaderDate((void *)NULL);
230   }
231   else if (fileURI.BeginsWith("collection://")) {
232     fileURI.ReplaceAll("collection://","");
233     AliInfoClass(Form("Creating raw-reader in order to read raw-data files collection defined in %s",fileURI.Data()));
234     rawReader = new AliRawReaderChain(fileURI);
235   }
236   else if (fileURI.BeginsWith("raw://run")) {
237     fileURI.ReplaceAll("raw://run","");
238     if (fileURI.IsDigit()) {
239       rawReader = new AliRawReaderChain(fileURI.Atoi());
240     }
241     else {
242       AliErrorClass(Form("Invalid syntax: %s",fileURI.Data()));
243       fields->Delete();
244       return NULL;
245     }
246   }
247   else {
248     AliInfoClass(Form("Creating raw-reader in order to read raw-data file: %s",fileURI.Data()));
249     TString filename(gSystem->ExpandPathName(fileURI.Data()));
250     if (filename.EndsWith("/")) {
251       rawReader = new AliRawReaderFile(filename);
252     } else if (filename.EndsWith(".root")) {
253       rawReader = new AliRawReaderRoot(filename);
254     } else {
255       rawReader = new AliRawReaderDate(filename);
256     }
257   }
258
259   if (!rawReader->IsRawReaderValid()) {
260     AliErrorClass(Form("Raw-reader is invalid - check the input URI (%s)",fileURI.Data()));
261     delete rawReader;
262     fields->Delete();
263     delete fields;
264     return NULL;
265   }
266
267   // Now apply event selection criteria (if specified)
268   if (fields->GetEntries() > 1) {
269     Int_t eventType = -1;
270     ULong64_t triggerMask = 0;
271     TString triggerExpr;
272     for(Int_t i = 1; i < fields->GetEntries(); i++) {
273       if (!fields->At(i)) continue;
274       TString &option = ((TObjString*)fields->At(i))->String();
275       if (option.BeginsWith("EventType=",TString::kIgnoreCase)) {
276         option.ReplaceAll("EventType=","");
277         eventType = option.Atoi();
278         continue;
279       }
280       if (option.BeginsWith("Trigger=",TString::kIgnoreCase)) {
281         option.ReplaceAll("Trigger=","");
282         if (option.IsDigit()) {
283           triggerMask = option.Atoll();
284         }
285         else {
286           triggerExpr = option.Data();
287         }
288         continue;
289       }
290       AliWarningClass(Form("Ignoring invalid event selection option: %s",option.Data()));
291     }
292     AliInfoClass(Form("Event selection criteria specified:   eventype=%d   trigger mask=%llx   trigger expression=%s",
293                  eventType,triggerMask,triggerExpr.Data()));
294     rawReader->SelectEvents(eventType,triggerMask,triggerExpr.Data());
295   }
296
297   fields->Delete();
298   delete fields;
299
300   return rawReader;
301 }
302
303 Int_t AliRawReader::GetMappedEquipmentId() const
304 {
305   if (!fEquipmentIdsIn || !fEquipmentIdsOut) {
306     Error("AliRawReader","equipment Ids mapping is not initialized !");
307     return GetEquipmentId();
308   }
309   Int_t equipmentId = GetEquipmentId();
310   for(Int_t iId = 0; iId < fEquipmentIdsIn->GetSize(); iId++) {
311     if (equipmentId == fEquipmentIdsIn->At(iId)) {
312       equipmentId = fEquipmentIdsOut->At(iId);
313       break;
314     }
315   }
316   return equipmentId;
317 }
318
319 Int_t AliRawReader::GetDetectorID() const
320 {
321   // Get the detector ID
322   // The list of detector IDs
323   // can be found in AliDAQ.h
324   Int_t equipmentId;
325   if (fEquipmentIdsIn && fEquipmentIdsIn)
326     equipmentId = GetMappedEquipmentId();
327   else
328     equipmentId = GetEquipmentId();
329
330   if (equipmentId >= 0) {
331     Int_t ddlIndex;
332     return AliDAQ::DetectorIDFromDdlID(equipmentId,ddlIndex);
333   }
334   else
335     return -1;
336 }
337
338 Int_t AliRawReader::GetDDLID() const
339 {
340   // Get the DDL ID (within one sub-detector)
341   // The list of detector IDs
342   // can be found in AliDAQ.h
343   Int_t equipmentId;
344   if (fEquipmentIdsIn && fEquipmentIdsIn)
345     equipmentId = GetMappedEquipmentId();
346   else
347     equipmentId = GetEquipmentId();
348
349   if (equipmentId >= 0) {
350     Int_t ddlIndex;
351     AliDAQ::DetectorIDFromDdlID(equipmentId,ddlIndex);
352     return ddlIndex;
353   }
354   else
355     return -1;
356 }
357
358 void AliRawReader::Select(const char *detectorName, Int_t minDDLID, Int_t maxDDLID)
359 {
360 // read only data of the detector with the given name and in the given
361 // range of DDLs (minDDLID <= DDLID <= maxDDLID).
362 // no selection is applied if a value < 0 is used.
363   Int_t detectorID = AliDAQ::DetectorID(detectorName);
364   if(detectorID >= 0)
365     Select(detectorID,minDDLID,maxDDLID);
366 }
367
368 void AliRawReader::Select(Int_t detectorID, Int_t minDDLID, Int_t maxDDLID)
369 {
370 // read only data of the detector with the given ID and in the given
371 // range of DDLs (minDDLID <= DDLID <= maxDDLID).
372 // no selection is applied if a value < 0 is used.
373
374   fSelectEquipmentType = -1;
375
376   if (minDDLID < 0)
377     fSelectMinEquipmentId = AliDAQ::DdlIDOffset(detectorID);
378   else
379     fSelectMinEquipmentId = AliDAQ::DdlID(detectorID,minDDLID);
380
381   if (maxDDLID < 0)
382     fSelectMaxEquipmentId = AliDAQ::DdlID(detectorID,AliDAQ::NumberOfDdls(detectorID)-1);
383   else
384     fSelectMaxEquipmentId = AliDAQ::DdlID(detectorID,maxDDLID);
385 }
386
387 void AliRawReader::SelectEquipment(Int_t equipmentType, 
388                                    Int_t minEquipmentId, Int_t maxEquipmentId)
389 {
390 // read only data of the equipment with the given type and in the given
391 // range of IDs (minEquipmentId <= EquipmentId <= maxEquipmentId).
392 // no selection is applied if a value < 0 is used.
393
394   fSelectEquipmentType = equipmentType;
395   fSelectMinEquipmentId = minEquipmentId;
396   fSelectMaxEquipmentId = maxEquipmentId;
397 }
398
399 void AliRawReader::SelectEvents(Int_t type, ULong64_t triggerMask,
400                                 const char *triggerExpr)
401 {
402 // read only events with the given type and optionally
403 // trigger mask.
404 // no selection is applied if value = 0 is used.
405 // Trigger selection can be done via string (triggerExpr)
406 // which defines the trigger logic to be used. It works only
407 // after LoadTriggerClass() method is called for all involved
408 // trigger classes.
409
410   fSelectEventType = type;
411   fSelectTriggerMask = triggerMask;
412   if (triggerExpr) fSelectTriggerExpr = triggerExpr;
413 }
414
415 void AliRawReader::LoadTriggerClass(const char* name, Int_t index)
416 {
417   // Loads the list of trigger classes defined.
418   // Used in conjunction with IsEventSelected in the
419   // case when the trigger selection is given by
420   // fSelectedTriggerExpr
421
422   if (fSelectTriggerExpr.IsNull()) return;
423
424   if (index >= 0)
425     fSelectTriggerExpr.ReplaceAll(name,Form("[%d]",index));
426   else
427     fSelectTriggerExpr.ReplaceAll(name,"0");
428 }
429
430 Bool_t AliRawReader::IsSelected() const
431 {
432 // apply the selection (if any)
433
434   if (fSkipInvalid && !IsValid()) return kFALSE;
435
436   if (fSelectEquipmentType >= 0)
437     if (GetEquipmentType() != fSelectEquipmentType) return kFALSE;
438
439   Int_t equipmentId;
440   if (fEquipmentIdsIn && fEquipmentIdsIn)
441     equipmentId = GetMappedEquipmentId();
442   else
443     equipmentId = GetEquipmentId();
444
445   if ((fSelectMinEquipmentId >= 0) && 
446       (equipmentId < fSelectMinEquipmentId))
447     return kFALSE;
448   if ((fSelectMaxEquipmentId >= 0) && 
449       (equipmentId > fSelectMaxEquipmentId))
450     return kFALSE;
451
452   return kTRUE;
453 }
454
455 Bool_t AliRawReader::IsEventSelected() const
456 {
457   // apply the event selection (if any)
458
459   // First check the event type
460   if (fSelectEventType >= 0) {
461     if (GetType() != (UInt_t) fSelectEventType) return kFALSE;
462   }
463
464   // Then check the trigger pattern and compared it
465   // to the required trigger mask
466   if (fSelectTriggerMask != 0) {
467     if ((GetClassMask() & fSelectTriggerMask) != fSelectTriggerMask) return kFALSE;
468   }
469
470   if (!fSelectTriggerExpr.IsNull()) {
471     TString expr(fSelectTriggerExpr);
472     ULong64_t mask = GetClassMask();
473     for(Int_t itrigger = 0; itrigger < 50; itrigger++) {
474       if (mask & (1 << itrigger)) {
475         expr.ReplaceAll(Form("[%d]",itrigger),"1");
476       }
477       else {
478         expr.ReplaceAll(Form("[%d]",itrigger),"0");
479       }
480     }
481     // Possibility to introduce downscaling
482     TPRegexp("(%\\s*\\d+)").Substitute(expr,Form("&& !(%d$1)",GetEventIndex()),"g");
483     Int_t error;
484     if ((gROOT->ProcessLineFast(expr.Data(),&error) == 0) &&
485         (error == TInterpreter::kNoError)) {
486       return kFALSE;
487     }
488   }
489
490   return kTRUE;
491 }
492
493 UInt_t AliRawReader::SwapWord(UInt_t x) const
494 {
495    // Swap the endianess of the integer value 'x'
496
497    return (((x & 0x000000ffU) << 24) | ((x & 0x0000ff00U) <<  8) |
498            ((x & 0x00ff0000U) >>  8) | ((x & 0xff000000U) >> 24));
499 }
500
501 UShort_t AliRawReader::SwapShort(UShort_t x) const
502 {
503    // Swap the endianess of the short value 'x'
504
505    return (((x & 0x00ffU) <<  8) | ((x & 0xff00U) >>  8)) ;
506 }
507
508 Bool_t AliRawReader::ReadNextInt(UInt_t& data)
509 {
510 // reads the next 4 bytes at the current position
511 // returns kFALSE if the data could not be read
512
513   while (fCount == 0) {
514     if (!ReadHeader()) return kFALSE;
515   }
516   if (fCount < (Int_t) sizeof(data)) {
517     Error("ReadNextInt", 
518           "too few data left (%d bytes) to read an UInt_t!", fCount);
519     return kFALSE;
520   }
521   if (!ReadNext((UChar_t*) &data, sizeof(data))) {
522     Error("ReadNextInt", "could not read data!");
523     return kFALSE;
524   }
525 #ifndef R__BYTESWAP
526   data=SwapWord(data);
527 #endif
528   return kTRUE;
529 }
530
531 Bool_t AliRawReader::ReadNextShort(UShort_t& data)
532 {
533 // reads the next 2 bytes at the current position
534 // returns kFALSE if the data could not be read
535
536   while (fCount == 0) {
537     if (!ReadHeader()) return kFALSE;
538   }
539   if (fCount < (Int_t) sizeof(data)) {
540     Error("ReadNextShort", 
541           "too few data left (%d bytes) to read an UShort_t!", fCount);
542     return kFALSE;
543   }
544   if (!ReadNext((UChar_t*) &data, sizeof(data))) {
545     Error("ReadNextShort", "could not read data!");
546     return kFALSE;
547   }
548 #ifndef R__BYTESWAP
549   data=SwapShort(data);
550 #endif
551   return kTRUE;
552 }
553
554 Bool_t AliRawReader::ReadNextChar(UChar_t& data)
555 {
556 // reads the next 1 byte at the current stream position
557 // returns kFALSE if the data could not be read
558
559   while (fCount == 0) {
560     if (!ReadHeader()) return kFALSE;
561   }
562   if (!ReadNext((UChar_t*) &data, sizeof(data))) {
563     Error("ReadNextChar", "could not read data!");
564     return kFALSE;
565   }
566   return kTRUE;
567 }
568
569 Bool_t  AliRawReader::GotoEvent(Int_t event)
570 {
571   // Random access to certain
572   // event index. Could be very slow
573   // for some non-root raw-readers.
574   // So it should be reimplemented there.
575   if (event < fEventNumber) RewindEvents();
576
577   while (fEventNumber < event) {
578     if (!NextEvent()) return kFALSE;
579   }
580
581   return kTRUE;
582 }
583
584 Int_t AliRawReader::CheckData() const
585 {
586 // check the consistency of the data
587 // derived classes should overwrite the default method which returns 0 (no err)
588
589   return 0;
590 }
591
592
593 void AliRawReader::DumpData(Int_t limit)
594 {
595 // print the raw data
596 // if limit is not negative, only the first and last "limit" lines of raw data
597 // are printed
598
599   Reset();
600   if (!ReadHeader()) {
601     Error("DumpData", "no header");
602     return;
603   }
604   printf("header:\n"
605          " type = %d  run = %d  ", GetType(), GetRunNumber());
606   if (GetEventId()) {
607     printf("event = %8.8x %8.8x\n", GetEventId()[1], GetEventId()[0]);
608   } else {
609     printf("event = -------- --------\n");
610   }
611   if (GetTriggerPattern()) {
612     printf(" trigger = %8.8x %8.8x  ",
613            GetTriggerPattern()[1], GetTriggerPattern()[0]);
614   } else {
615     printf(" trigger = -------- --------  ");
616   }
617   if (GetDetectorPattern()) {
618     printf("detector = %8.8x\n", GetDetectorPattern()[0]);
619   } else {
620     printf("detector = --------\n");
621   }
622   if (GetAttributes()) {
623     printf(" attributes = %8.8x %8.8x %8.8x  ",
624            GetAttributes()[2], GetAttributes()[1], GetAttributes()[0]);
625   } else {
626     printf(" attributes = -------- -------- --------  ");
627   }
628   printf("GDC = %d\n", GetGDCId());
629   printf("\n");
630
631   do {
632     printf("-------------------------------------------------------------------------------\n");
633     printf("LDC = %d\n", GetLDCId());
634
635     printf("equipment:\n"
636            " size = %d  type = %d  id = %d\n",
637            GetEquipmentSize(), GetEquipmentType(), GetEquipmentId());
638     if (GetEquipmentAttributes()) {
639       printf(" attributes = %8.8x %8.8x %8.8x  ", GetEquipmentAttributes()[2],
640              GetEquipmentAttributes()[1], GetEquipmentAttributes()[0]);
641     } else {
642       printf(" attributes = -------- -------- --------  ");
643     }
644     printf("element size = %d\n", GetEquipmentElementSize());
645
646     printf("data header:\n"
647            " size = %d  version = %d  valid = %d  compression = %d\n",
648            GetDataSize(), GetVersion(), IsValid(), IsCompressed());
649
650     printf("\n");
651     if (limit == 0) continue;
652
653     Int_t size = GetDataSize();
654     char line[70];
655     for (Int_t i = 0; i < 70; i++) line[i] = ' ';
656     line[69] = '\0';
657     Int_t pos = 0;
658     Int_t max = 16;
659     UChar_t byte;
660
661     for (Int_t n = 0; n < size; n++) {
662       if (!ReadNextChar(byte)) {
663         Error("DumpData", "couldn't read byte number %d\n", n);
664         break;
665       }
666       if (pos >= max) {
667         printf("%8.8x  %s\n", n-pos, line);
668         for (Int_t i = 0; i < 70; i++) line[i] = ' ';
669         line[69] = '\0';
670         pos = 0;
671         if ((limit > 0) && (n/max == limit)) {
672           Int_t nContinue = ((size-1)/max+1-limit) * max;
673           if (nContinue > n) {
674             printf(" [skipping %d bytes]\n", nContinue-n);
675             n = nContinue-1;
676             continue;
677           }
678         }
679       }
680       Int_t offset = pos/4;
681       if ((byte > 0x20) && (byte < 0x7f)) {
682         line[pos+offset] = byte;
683       } else {
684         line[pos+offset] = '.';
685       }
686       char hex[3];
687       snprintf(hex, 3, "%2.2x", byte);
688       line[max+max/4+3+2*pos+offset] = hex[0];
689       line[max+max/4+4+2*pos+offset] = hex[1];
690       pos++;
691     }
692
693     if (pos > 0) printf("%8.8x  %s\n", size-pos, line);
694     printf("\n");
695            
696   } while (ReadHeader());
697 }
698
699 void AliRawReader::AddErrorLog(AliRawDataErrorLog::ERawDataErrorLevel level,
700                                Int_t code,
701                                const char *message)
702 {
703   // Add a raw data error message to the list
704   // of raw-data decoding errors
705   if (fEventNumber < 0) {
706     return;
707   }
708   Int_t ddlId = GetEquipmentId();
709   if (ddlId < 0) {
710     AliError("No ddl raw data have been read so far! Impossible to add a raw data error log!");
711     return;
712   }
713
714   Int_t prevEventNumber = -1;
715   Int_t prevDdlId = -1;
716   Int_t prevErrorCode = -1;
717   AliRawDataErrorLog *prevLog = (AliRawDataErrorLog *)fErrorLogs.Last();
718   if (prevLog) {
719     prevEventNumber = prevLog->GetEventNumber();
720     prevDdlId       = prevLog->GetDdlID();
721     prevErrorCode   = prevLog->GetErrorCode();
722   }
723
724   if ((prevEventNumber != fEventNumber) ||
725       (prevDdlId != ddlId) ||
726       (prevErrorCode != code)) {
727     new (fErrorLogs[fErrorLogs.GetEntriesFast()])
728       AliRawDataErrorLog(fEventNumber,
729                          ddlId,
730                          level,
731                          code,
732                          message);
733   }
734   else
735     if (prevLog) prevLog->AddCount();
736
737 }
738
739 Bool_t AliRawReader::GotoEventWithID(Int_t event, 
740                                      UInt_t period,
741                                      UInt_t orbitID,
742                                      UShort_t bcID)
743 {
744   // Go to certain event number by
745   // checking the event ID.
746   // Useful in case event-selection
747   // is applied and the 'event' is
748   // relative
749   if (!GotoEvent(event)) return kFALSE;
750
751   while (GetBCID()    != period  ||
752          GetOrbitID() != orbitID ||
753          GetPeriod()  != bcID) {
754     if (!NextEvent()) return kFALSE;
755   }
756
757   return kTRUE;
758 }
759