remove histogram
[u/mrichter/AliRoot.git] / RAW / AliRawReader.cxx
CommitLineData
a6e7b125 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
bea6b2a4 16/* $Id$ */
17
a6e7b125 18///////////////////////////////////////////////////////////////////////////////
bea6b2a4 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///
a6e7b125 37///////////////////////////////////////////////////////////////////////////////
38
43787b8e 39#include <TClass.h>
40#include <TPluginManager.h>
41#include <TROOT.h>
56918e2f 42#include <TInterpreter.h>
13b20641 43#include <TSystem.h>
764daca3 44#include <TPRegexp.h>
43787b8e 45
0cfe2438 46#include <Riostream.h>
a6e7b125 47#include "AliRawReader.h"
43787b8e 48#include "AliRawReaderFile.h"
49#include "AliRawReaderDate.h"
50#include "AliRawReaderRoot.h"
a6e0640d 51#include "AliRawReaderChain.h"
362c9d61 52#include "AliDAQ.h"
38cf12f3 53#include "AliLog.h"
8de97894 54
a6e7b125 55ClassImp(AliRawReader)
56
57
c946ab02 58AliRawReader::AliRawReader() :
0cfe2438 59 fEquipmentIdsIn(NULL),
60 fEquipmentIdsOut(NULL),
18882b3b 61 fRequireHeader(kTRUE),
39f9963f 62 fHeader(NULL),
c946ab02 63 fCount(0),
f224de6c 64 fSelectEquipmentType(-1),
65 fSelectMinEquipmentId(-1),
66 fSelectMaxEquipmentId(-1),
39f9963f 67 fSkipInvalid(kFALSE),
dd9a70fe 68 fSelectEventType(-1),
00665a00 69 fSelectTriggerMask(0),
56918e2f 70 fSelectTriggerExpr(),
38cf12f3 71 fErrorCode(0),
72 fEventNumber(-1),
edd06192 73 fErrorLogs("AliRawDataErrorLog",100),
a97af23d 74 fHeaderSwapped(NULL),
75 fIsValid(kTRUE)
a6e7b125 76{
42d20574 77// default constructor: initialize data members
edd06192 78// Allocate the swapped header in case of Mac
79#ifndef R__BYTESWAP
80 fHeaderSwapped=new AliRawDataHeader();
81#endif
0cfe2438 82}
42d20574 83
0cfe2438 84Bool_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 }
a6e7b125 114}
115
42d20574 116AliRawReader::AliRawReader(const AliRawReader& rawReader) :
c946ab02 117 TObject(rawReader),
0cfe2438 118 fEquipmentIdsIn(rawReader.fEquipmentIdsIn),
119 fEquipmentIdsOut(rawReader.fEquipmentIdsOut),
18882b3b 120 fRequireHeader(rawReader.fRequireHeader),
39f9963f 121 fHeader(rawReader.fHeader),
c946ab02 122 fCount(rawReader.fCount),
f224de6c 123 fSelectEquipmentType(rawReader.fSelectEquipmentType),
124 fSelectMinEquipmentId(rawReader.fSelectMinEquipmentId),
125 fSelectMaxEquipmentId(rawReader.fSelectMaxEquipmentId),
39f9963f 126 fSkipInvalid(rawReader.fSkipInvalid),
dd9a70fe 127 fSelectEventType(rawReader.fSelectEventType),
00665a00 128 fSelectTriggerMask(rawReader.fSelectTriggerMask),
56918e2f 129 fSelectTriggerExpr(rawReader.fSelectTriggerExpr),
38cf12f3 130 fErrorCode(0),
131 fEventNumber(-1),
edd06192 132 fErrorLogs("AliRawDataErrorLog",100),
a97af23d 133 fHeaderSwapped(NULL),
134 fIsValid(rawReader.fIsValid)
42d20574 135{
136// copy constructor
edd06192 137// Allocate the swapped header in case of Mac
138#ifndef R__BYTESWAP
139 fHeaderSwapped=new AliRawDataHeader(*rawReader.fHeaderSwapped);
140#endif
42d20574 141}
142
143AliRawReader& AliRawReader::operator = (const AliRawReader& rawReader)
144{
145// assignment operator
2a4ff083 146 if(&rawReader == this) return *this;
0cfe2438 147 fEquipmentIdsIn = rawReader.fEquipmentIdsIn;
148 fEquipmentIdsOut = rawReader.fEquipmentIdsOut;
42d20574 149
39f9963f 150 fHeader = rawReader.fHeader;
42d20574 151 fCount = rawReader.fCount;
152
39f9963f 153 fSelectEquipmentType = rawReader.fSelectEquipmentType;
154 fSelectMinEquipmentId = rawReader.fSelectMinEquipmentId;
155 fSelectMaxEquipmentId = rawReader.fSelectMaxEquipmentId;
156 fSkipInvalid = rawReader.fSkipInvalid;
dd9a70fe 157 fSelectEventType = rawReader.fSelectEventType;
00665a00 158 fSelectTriggerMask = rawReader.fSelectTriggerMask;
56918e2f 159 fSelectTriggerExpr = rawReader.fSelectTriggerExpr;
42d20574 160
b4857df7 161 fErrorCode = rawReader.fErrorCode;
162
38cf12f3 163 fEventNumber = rawReader.fEventNumber;
164 fErrorLogs = *((TClonesArray*)rawReader.fErrorLogs.Clone());
165
a97af23d 166 fIsValid = rawReader.fIsValid;
167
42d20574 168 return *this;
169}
170
0cfe2438 171AliRawReader::~AliRawReader()
172{
173 // destructor
174 // delete the mapping arrays if
175 // initialized
176 if (fEquipmentIdsIn) delete fEquipmentIdsIn;
177 if (fEquipmentIdsOut) delete fEquipmentIdsOut;
79dac785 178 fErrorLogs.Delete();
edd06192 179 if (fHeaderSwapped) delete fHeaderSwapped;
0cfe2438 180}
181
43787b8e 182AliRawReader* 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
3f7450e0 199 TObjArray *fields = strURI.Tokenize("?");
200 TString &fileURI = ((TObjString*)fields->At(0))->String();
201
43787b8e 202 AliRawReader *rawReader = NULL;
3ae8c60d 203 if (fileURI.BeginsWith("mem://") || fileURI.BeginsWith("^")) {
204 if (fileURI.BeginsWith("mem://")) fileURI.ReplaceAll("mem://","");
3f7450e0 205 AliInfoClass(Form("Creating raw-reader in order to read events in shared memory (option=%s)",fileURI.Data()));
43787b8e 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)) {
3f7450e0 217 rawReader = (AliRawReader*)pluginHandler->ExecPlugin(1,fileURI.Data());
43787b8e 218 }
219 else {
a6e0640d 220 delete fields;
43787b8e 221 return NULL;
222 }
223 }
2f954aba 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 }
a6e0640d 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 }
bb0edcaf 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 }
a6e0640d 248 else {
249 AliInfoClass(Form("Creating raw-reader in order to read raw-data file: %s",fileURI.Data()));
13b20641 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);
a6e0640d 255 } else {
13b20641 256 rawReader = new AliRawReaderDate(filename);
a6e0640d 257 }
258 }
43787b8e 259
a97af23d 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
3f7450e0 268 // Now apply event selection criteria (if specified)
269 if (fields->GetEntries() > 1) {
270 Int_t eventType = -1;
271 ULong64_t triggerMask = 0;
56918e2f 272 TString triggerExpr;
3f7450e0 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=","");
56918e2f 283 if (option.IsDigit()) {
284 triggerMask = option.Atoll();
285 }
286 else {
287 triggerExpr = option.Data();
288 }
3f7450e0 289 continue;
290 }
291 AliWarningClass(Form("Ignoring invalid event selection option: %s",option.Data()));
292 }
56918e2f 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());
3f7450e0 296 }
297
298 fields->Delete();
299 delete fields;
300
43787b8e 301 return rawReader;
302}
303
0cfe2438 304Int_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
320Int_t AliRawReader::GetDetectorID() const
321{
322 // Get the detector ID
323 // The list of detector IDs
362c9d61 324 // can be found in AliDAQ.h
0cfe2438 325 Int_t equipmentId;
326 if (fEquipmentIdsIn && fEquipmentIdsIn)
327 equipmentId = GetMappedEquipmentId();
328 else
329 equipmentId = GetEquipmentId();
330
362c9d61 331 if (equipmentId >= 0) {
332 Int_t ddlIndex;
333 return AliDAQ::DetectorIDFromDdlID(equipmentId,ddlIndex);
334 }
0cfe2438 335 else
336 return -1;
337}
338
339Int_t AliRawReader::GetDDLID() const
340{
341 // Get the DDL ID (within one sub-detector)
342 // The list of detector IDs
362c9d61 343 // can be found in AliDAQ.h
0cfe2438 344 Int_t equipmentId;
345 if (fEquipmentIdsIn && fEquipmentIdsIn)
346 equipmentId = GetMappedEquipmentId();
347 else
348 equipmentId = GetEquipmentId();
349
362c9d61 350 if (equipmentId >= 0) {
351 Int_t ddlIndex;
352 AliDAQ::DetectorIDFromDdlID(equipmentId,ddlIndex);
353 return ddlIndex;
354 }
0cfe2438 355 else
356 return -1;
357}
8de97894 358
362c9d61 359void 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
8de97894 369void AliRawReader::Select(Int_t detectorID, Int_t minDDLID, Int_t maxDDLID)
a6e7b125 370{
8de97894 371// read only data of the detector with the given ID and in the given
f224de6c 372// range of DDLs (minDDLID <= DDLID <= maxDDLID).
8de97894 373// no selection is applied if a value < 0 is used.
a6e7b125 374
0cfe2438 375 fSelectEquipmentType = -1;
362c9d61 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);
8de97894 386}
a6e7b125 387
f224de6c 388void 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
56918e2f 400void AliRawReader::SelectEvents(Int_t type, ULong64_t triggerMask,
401 const char *triggerExpr)
dd9a70fe 402{
00665a00 403// read only events with the given type and optionally
404// trigger mask.
56918e2f 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.
dd9a70fe 410
411 fSelectEventType = type;
00665a00 412 fSelectTriggerMask = triggerMask;
56918e2f 413 if (triggerExpr) fSelectTriggerExpr = triggerExpr;
414}
415
416void 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
764daca3 425 if (index >= 0)
426 fSelectTriggerExpr.ReplaceAll(name,Form("[%d]",index));
427 else
428 fSelectTriggerExpr.ReplaceAll(name,"0");
dd9a70fe 429}
430
42d20574 431Bool_t AliRawReader::IsSelected() const
a6e7b125 432{
8de97894 433// apply the selection (if any)
434
39f9963f 435 if (fSkipInvalid && !IsValid()) return kFALSE;
f224de6c 436
0cfe2438 437 if (fSelectEquipmentType >= 0)
f224de6c 438 if (GetEquipmentType() != fSelectEquipmentType) return kFALSE;
0cfe2438 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;
f224de6c 452
8de97894 453 return kTRUE;
a6e7b125 454}
455
dd9a70fe 456Bool_t AliRawReader::IsEventSelected() const
457{
00665a00 458 // apply the event selection (if any)
dd9a70fe 459
00665a00 460 // First check the event type
dd9a70fe 461 if (fSelectEventType >= 0) {
462 if (GetType() != (UInt_t) fSelectEventType) return kFALSE;
463 }
464
00665a00 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
56918e2f 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 }
31572b9e 482 // Possibility to introduce downscaling
764daca3 483 TPRegexp("(%\\s*\\d+)").Substitute(expr,Form("&& !(%d$1)",GetEventIndex()),"g");
56918e2f 484 Int_t error;
485 if ((gROOT->ProcessLineFast(expr.Data(),&error) == 0) &&
486 (error == TInterpreter::kNoError)) {
487 return kFALSE;
488 }
489 }
490
dd9a70fe 491 return kTRUE;
492}
493
91f76e9b 494UInt_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
502UShort_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}
a6e7b125 508
a6e7b125 509Bool_t AliRawReader::ReadNextInt(UInt_t& data)
510{
8de97894 511// reads the next 4 bytes at the current position
512// returns kFALSE if the data could not be read
a6e7b125 513
514 while (fCount == 0) {
c946ab02 515 if (!ReadHeader()) return kFALSE;
a6e7b125 516 }
8de97894 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))) {
a6e7b125 523 Error("ReadNextInt", "could not read data!");
524 return kFALSE;
525 }
91f76e9b 526#ifndef R__BYTESWAP
527 data=SwapWord(data);
528#endif
a6e7b125 529 return kTRUE;
530}
531
532Bool_t AliRawReader::ReadNextShort(UShort_t& data)
533{
8de97894 534// reads the next 2 bytes at the current position
535// returns kFALSE if the data could not be read
a6e7b125 536
537 while (fCount == 0) {
c946ab02 538 if (!ReadHeader()) return kFALSE;
a6e7b125 539 }
8de97894 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))) {
a6e7b125 546 Error("ReadNextShort", "could not read data!");
547 return kFALSE;
548 }
91f76e9b 549#ifndef R__BYTESWAP
550 data=SwapShort(data);
551#endif
a6e7b125 552 return kTRUE;
553}
554
555Bool_t AliRawReader::ReadNextChar(UChar_t& data)
556{
557// reads the next 1 byte at the current stream position
8de97894 558// returns kFALSE if the data could not be read
a6e7b125 559
560 while (fCount == 0) {
c946ab02 561 if (!ReadHeader()) return kFALSE;
a6e7b125 562 }
8de97894 563 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
a6e7b125 564 Error("ReadNextChar", "could not read data!");
565 return kFALSE;
566 }
a6e7b125 567 return kTRUE;
568}
569
66964465 570Bool_t AliRawReader::GotoEvent(Int_t event)
636c1780 571{
66964465 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;
636c1780 583}
b4857df7 584
585Int_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
509a7696 593
594void 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
39f9963f 647 printf("data header:\n"
648 " size = %d version = %d valid = %d compression = %d\n",
649 GetDataSize(), GetVersion(), IsValid(), IsCompressed());
509a7696 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];
669f9a12 688 snprintf(hex, 3, "%2.2x", byte);
509a7696 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}
38cf12f3 699
9fc249d9 700void AliRawReader::AddErrorLog(AliRawDataErrorLog::ERawDataErrorLevel level,
701 Int_t code,
38cf12f3 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) {
38cf12f3 707 return;
708 }
3aea4e5e 709 Int_t ddlId = GetEquipmentId();
38cf12f3 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
79dac785 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
38cf12f3 738}
66964465 739
740Bool_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