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