changed name of function to filename
[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),
b21d9ff2 75 fIsValid(kTRUE),
76 fIsTriggerClassLoaded(kFALSE)
a6e7b125 77{
42d20574 78// default constructor: initialize data members
edd06192 79// Allocate the swapped header in case of Mac
80#ifndef R__BYTESWAP
81 fHeaderSwapped=new AliRawDataHeader();
82#endif
0cfe2438 83}
42d20574 84
0cfe2438 85Bool_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 }
a6e7b125 115}
116
42d20574 117AliRawReader::AliRawReader(const AliRawReader& rawReader) :
c946ab02 118 TObject(rawReader),
0cfe2438 119 fEquipmentIdsIn(rawReader.fEquipmentIdsIn),
120 fEquipmentIdsOut(rawReader.fEquipmentIdsOut),
18882b3b 121 fRequireHeader(rawReader.fRequireHeader),
39f9963f 122 fHeader(rawReader.fHeader),
c946ab02 123 fCount(rawReader.fCount),
f224de6c 124 fSelectEquipmentType(rawReader.fSelectEquipmentType),
125 fSelectMinEquipmentId(rawReader.fSelectMinEquipmentId),
126 fSelectMaxEquipmentId(rawReader.fSelectMaxEquipmentId),
39f9963f 127 fSkipInvalid(rawReader.fSkipInvalid),
dd9a70fe 128 fSelectEventType(rawReader.fSelectEventType),
00665a00 129 fSelectTriggerMask(rawReader.fSelectTriggerMask),
56918e2f 130 fSelectTriggerExpr(rawReader.fSelectTriggerExpr),
38cf12f3 131 fErrorCode(0),
132 fEventNumber(-1),
edd06192 133 fErrorLogs("AliRawDataErrorLog",100),
a97af23d 134 fHeaderSwapped(NULL),
b21d9ff2 135 fIsValid(rawReader.fIsValid),
136 fIsTriggerClassLoaded(rawReader.fIsTriggerClassLoaded)
42d20574 137{
138// copy constructor
edd06192 139// Allocate the swapped header in case of Mac
140#ifndef R__BYTESWAP
141 fHeaderSwapped=new AliRawDataHeader(*rawReader.fHeaderSwapped);
142#endif
42d20574 143}
144
145AliRawReader& AliRawReader::operator = (const AliRawReader& rawReader)
146{
147// assignment operator
2a4ff083 148 if(&rawReader == this) return *this;
0cfe2438 149 fEquipmentIdsIn = rawReader.fEquipmentIdsIn;
150 fEquipmentIdsOut = rawReader.fEquipmentIdsOut;
42d20574 151
39f9963f 152 fHeader = rawReader.fHeader;
42d20574 153 fCount = rawReader.fCount;
154
39f9963f 155 fSelectEquipmentType = rawReader.fSelectEquipmentType;
156 fSelectMinEquipmentId = rawReader.fSelectMinEquipmentId;
157 fSelectMaxEquipmentId = rawReader.fSelectMaxEquipmentId;
158 fSkipInvalid = rawReader.fSkipInvalid;
dd9a70fe 159 fSelectEventType = rawReader.fSelectEventType;
00665a00 160 fSelectTriggerMask = rawReader.fSelectTriggerMask;
56918e2f 161 fSelectTriggerExpr = rawReader.fSelectTriggerExpr;
42d20574 162
b4857df7 163 fErrorCode = rawReader.fErrorCode;
164
38cf12f3 165 fEventNumber = rawReader.fEventNumber;
166 fErrorLogs = *((TClonesArray*)rawReader.fErrorLogs.Clone());
167
a97af23d 168 fIsValid = rawReader.fIsValid;
b21d9ff2 169 fIsTriggerClassLoaded = rawReader.fIsTriggerClassLoaded;
a97af23d 170
42d20574 171 return *this;
172}
173
0cfe2438 174AliRawReader::~AliRawReader()
175{
176 // destructor
177 // delete the mapping arrays if
178 // initialized
179 if (fEquipmentIdsIn) delete fEquipmentIdsIn;
180 if (fEquipmentIdsOut) delete fEquipmentIdsOut;
79dac785 181 fErrorLogs.Delete();
edd06192 182 if (fHeaderSwapped) delete fHeaderSwapped;
0cfe2438 183}
184
43787b8e 185AliRawReader* 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
3f7450e0 202 TObjArray *fields = strURI.Tokenize("?");
203 TString &fileURI = ((TObjString*)fields->At(0))->String();
204
43787b8e 205 AliRawReader *rawReader = NULL;
3ae8c60d 206 if (fileURI.BeginsWith("mem://") || fileURI.BeginsWith("^")) {
207 if (fileURI.BeginsWith("mem://")) fileURI.ReplaceAll("mem://","");
3f7450e0 208 AliInfoClass(Form("Creating raw-reader in order to read events in shared memory (option=%s)",fileURI.Data()));
43787b8e 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)) {
3f7450e0 220 rawReader = (AliRawReader*)pluginHandler->ExecPlugin(1,fileURI.Data());
43787b8e 221 }
222 else {
a6e0640d 223 delete fields;
43787b8e 224 return NULL;
225 }
226 }
2f954aba 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 }
a6e0640d 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 }
bb0edcaf 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 }
a6e0640d 251 else {
252 AliInfoClass(Form("Creating raw-reader in order to read raw-data file: %s",fileURI.Data()));
13b20641 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);
a6e0640d 258 } else {
13b20641 259 rawReader = new AliRawReaderDate(filename);
a6e0640d 260 }
261 }
43787b8e 262
a97af23d 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
3f7450e0 271 // Now apply event selection criteria (if specified)
272 if (fields->GetEntries() > 1) {
273 Int_t eventType = -1;
274 ULong64_t triggerMask = 0;
56918e2f 275 TString triggerExpr;
3f7450e0 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=","");
56918e2f 286 if (option.IsDigit()) {
287 triggerMask = option.Atoll();
288 }
289 else {
290 triggerExpr = option.Data();
291 }
3f7450e0 292 continue;
293 }
294 AliWarningClass(Form("Ignoring invalid event selection option: %s",option.Data()));
295 }
56918e2f 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());
3f7450e0 299 }
300
301 fields->Delete();
302 delete fields;
303
43787b8e 304 return rawReader;
305}
306
0cfe2438 307Int_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
323Int_t AliRawReader::GetDetectorID() const
324{
325 // Get the detector ID
326 // The list of detector IDs
362c9d61 327 // can be found in AliDAQ.h
0cfe2438 328 Int_t equipmentId;
329 if (fEquipmentIdsIn && fEquipmentIdsIn)
330 equipmentId = GetMappedEquipmentId();
331 else
332 equipmentId = GetEquipmentId();
333
362c9d61 334 if (equipmentId >= 0) {
335 Int_t ddlIndex;
336 return AliDAQ::DetectorIDFromDdlID(equipmentId,ddlIndex);
337 }
0cfe2438 338 else
339 return -1;
340}
341
342Int_t AliRawReader::GetDDLID() const
343{
344 // Get the DDL ID (within one sub-detector)
345 // The list of detector IDs
362c9d61 346 // can be found in AliDAQ.h
0cfe2438 347 Int_t equipmentId;
348 if (fEquipmentIdsIn && fEquipmentIdsIn)
349 equipmentId = GetMappedEquipmentId();
350 else
351 equipmentId = GetEquipmentId();
352
362c9d61 353 if (equipmentId >= 0) {
354 Int_t ddlIndex;
355 AliDAQ::DetectorIDFromDdlID(equipmentId,ddlIndex);
356 return ddlIndex;
357 }
0cfe2438 358 else
359 return -1;
360}
8de97894 361
362c9d61 362void 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
8de97894 372void AliRawReader::Select(Int_t detectorID, Int_t minDDLID, Int_t maxDDLID)
a6e7b125 373{
8de97894 374// read only data of the detector with the given ID and in the given
f224de6c 375// range of DDLs (minDDLID <= DDLID <= maxDDLID).
8de97894 376// no selection is applied if a value < 0 is used.
a6e7b125 377
0cfe2438 378 fSelectEquipmentType = -1;
362c9d61 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);
8de97894 389}
a6e7b125 390
f224de6c 391void 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
56918e2f 403void AliRawReader::SelectEvents(Int_t type, ULong64_t triggerMask,
404 const char *triggerExpr)
dd9a70fe 405{
00665a00 406// read only events with the given type and optionally
407// trigger mask.
56918e2f 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.
dd9a70fe 413
414 fSelectEventType = type;
00665a00 415 fSelectTriggerMask = triggerMask;
56918e2f 416 if (triggerExpr) fSelectTriggerExpr = triggerExpr;
417}
418
419void 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
b21d9ff2 428 fIsTriggerClassLoaded = kTRUE;
429
764daca3 430 if (index >= 0)
431 fSelectTriggerExpr.ReplaceAll(name,Form("[%d]",index));
432 else
433 fSelectTriggerExpr.ReplaceAll(name,"0");
dd9a70fe 434}
435
42d20574 436Bool_t AliRawReader::IsSelected() const
a6e7b125 437{
8de97894 438// apply the selection (if any)
439
39f9963f 440 if (fSkipInvalid && !IsValid()) return kFALSE;
f224de6c 441
0cfe2438 442 if (fSelectEquipmentType >= 0)
f224de6c 443 if (GetEquipmentType() != fSelectEquipmentType) return kFALSE;
0cfe2438 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;
f224de6c 457
8de97894 458 return kTRUE;
a6e7b125 459}
460
dd9a70fe 461Bool_t AliRawReader::IsEventSelected() const
462{
00665a00 463 // apply the event selection (if any)
dd9a70fe 464
00665a00 465 // First check the event type
dd9a70fe 466 if (fSelectEventType >= 0) {
467 if (GetType() != (UInt_t) fSelectEventType) return kFALSE;
468 }
469
00665a00 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
b21d9ff2 476 if ( fIsTriggerClassLoaded && !fSelectTriggerExpr.IsNull()) {
56918e2f 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 }
31572b9e 487 // Possibility to introduce downscaling
764daca3 488 TPRegexp("(%\\s*\\d+)").Substitute(expr,Form("&& !(%d$1)",GetEventIndex()),"g");
56918e2f 489 Int_t error;
490 if ((gROOT->ProcessLineFast(expr.Data(),&error) == 0) &&
491 (error == TInterpreter::kNoError)) {
492 return kFALSE;
493 }
494 }
495
dd9a70fe 496 return kTRUE;
497}
498
91f76e9b 499UInt_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
507UShort_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}
a6e7b125 513
a6e7b125 514Bool_t AliRawReader::ReadNextInt(UInt_t& data)
515{
8de97894 516// reads the next 4 bytes at the current position
517// returns kFALSE if the data could not be read
a6e7b125 518
519 while (fCount == 0) {
c946ab02 520 if (!ReadHeader()) return kFALSE;
a6e7b125 521 }
8de97894 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))) {
a6e7b125 528 Error("ReadNextInt", "could not read data!");
529 return kFALSE;
530 }
91f76e9b 531#ifndef R__BYTESWAP
532 data=SwapWord(data);
533#endif
a6e7b125 534 return kTRUE;
535}
536
537Bool_t AliRawReader::ReadNextShort(UShort_t& data)
538{
8de97894 539// reads the next 2 bytes at the current position
540// returns kFALSE if the data could not be read
a6e7b125 541
542 while (fCount == 0) {
c946ab02 543 if (!ReadHeader()) return kFALSE;
a6e7b125 544 }
8de97894 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))) {
a6e7b125 551 Error("ReadNextShort", "could not read data!");
552 return kFALSE;
553 }
91f76e9b 554#ifndef R__BYTESWAP
555 data=SwapShort(data);
556#endif
a6e7b125 557 return kTRUE;
558}
559
560Bool_t AliRawReader::ReadNextChar(UChar_t& data)
561{
562// reads the next 1 byte at the current stream position
8de97894 563// returns kFALSE if the data could not be read
a6e7b125 564
565 while (fCount == 0) {
c946ab02 566 if (!ReadHeader()) return kFALSE;
a6e7b125 567 }
8de97894 568 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
a6e7b125 569 Error("ReadNextChar", "could not read data!");
570 return kFALSE;
571 }
a6e7b125 572 return kTRUE;
573}
574
66964465 575Bool_t AliRawReader::GotoEvent(Int_t event)
636c1780 576{
66964465 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;
636c1780 588}
b4857df7 589
590Int_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
509a7696 598
599void 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
39f9963f 652 printf("data header:\n"
653 " size = %d version = %d valid = %d compression = %d\n",
654 GetDataSize(), GetVersion(), IsValid(), IsCompressed());
509a7696 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];
669f9a12 693 snprintf(hex, 3, "%2.2x", byte);
509a7696 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}
38cf12f3 704
9fc249d9 705void AliRawReader::AddErrorLog(AliRawDataErrorLog::ERawDataErrorLevel level,
706 Int_t code,
38cf12f3 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) {
38cf12f3 712 return;
713 }
3aea4e5e 714 Int_t ddlId = GetEquipmentId();
38cf12f3 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
79dac785 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
38cf12f3 743}
66964465 744
745Bool_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