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