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