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