]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/rec/AliRawReaderHLT.cxx
fixed overlaps and volume names according convention
[u/mrichter/AliRoot.git] / HLT / rec / AliRawReaderHLT.cxx
CommitLineData
7e914051 1// $Id$
9c7b5023 2
3/**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
6 * *
7 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 * for The ALICE HLT Project. *
9 * *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
18
19/** @file AliRawReaderHLT.cxx
20 @author Matthias Richter
21 @date
22 @brief AliRawReader implementation which replaces original input of
23 detectors with the appropriate HLT output. */
24
25// see header file for class documentation
26// or
27// refer to README to build package
28// or
29// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
30
31#include "AliRawReaderHLT.h"
13b78f4c 32#include "AliHLTOUTRawReader.h"
33#include "AliHLTModuleAgent.h"
626bfcc1 34#include "AliHLTOUTHandler.h"
35#include "AliHLTOUTHandlerEquId.h"
a3ef3c1d 36#include "AliHLTSystem.h"
e3917543 37#include "AliLog.h"
13b78f4c 38#include "AliDAQ.h" // RAW, for detector names and equipment ids
39#include "TObjString.h"
40#include <cassert>
9c7b5023 41
42/** ROOT macro for the implementation of ROOT specific class methods */
43ClassImp(AliRawReaderHLT)
44
45AliRawReaderHLT::AliRawReaderHLT(AliRawReader* pRawreader, const char* options)
46 :
47 AliRawReader(),
a3ef3c1d 48 AliHLTReconstructorBase(),
9c7b5023 49 fpParentReader(pRawreader),
13b78f4c 50 fOptions(),
a3ef3c1d 51 fSystemOptions(),
13b78f4c 52 fpData(NULL),
53 fDataSize(0),
54 fOffset(0),
d3833f99 55 fPosition(0),
13b78f4c 56 fEquipmentId(-1),
57 fbHaveHLTData(false),
58 fDetectors(),
626bfcc1 59 fpHLTOUT(NULL),
44dc7683 60 fbReadFirst(true),
626bfcc1 61 fpDataHandler(NULL)
9c7b5023 62{
63 // see header file for class documentation
64 // or
65 // refer to README to build package
66 // or
67 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
68 fOptions=options;
13b78f4c 69 ScanOptions(options);
9c7b5023 70}
71
72AliRawReaderHLT::~AliRawReaderHLT()
73{
74 // see header file for class documentation
d3833f99 75 ReleaseHLTData();
9c7b5023 76}
77
78UInt_t AliRawReaderHLT::GetType() const
79{
80 // see header file for class documentation
81 return fpParentReader->GetType();
82}
83
84UInt_t AliRawReaderHLT::GetRunNumber() const
85{
86 // see header file for class documentation
87 return fpParentReader->GetRunNumber();
88}
89
90const UInt_t* AliRawReaderHLT::GetEventId() const
91{
92 // see header file for class documentation
93 return fpParentReader->GetEventId();
94}
95
96const UInt_t* AliRawReaderHLT::GetTriggerPattern() const
97{
98 // see header file for class documentation
99 return fpParentReader->GetTriggerPattern();
100}
101
102const UInt_t* AliRawReaderHLT::GetDetectorPattern() const
103{
104 // see header file for class documentation
105 return fpParentReader->GetDetectorPattern();
106}
107
108const UInt_t* AliRawReaderHLT::GetAttributes() const
109{
110 // see header file for class documentation
111 return fpParentReader->GetAttributes();
112}
113
114const UInt_t* AliRawReaderHLT::GetSubEventAttributes() const
115{
116 // see header file for class documentation
117 return fpParentReader->GetSubEventAttributes();
118}
119
120UInt_t AliRawReaderHLT::GetLDCId() const
121{
122 // see header file for class documentation
123 return fpParentReader->GetLDCId();
124}
125
126UInt_t AliRawReaderHLT::GetGDCId() const
127{
128 // see header file for class documentation
129 return fpParentReader->GetGDCId();
130}
131
132UInt_t AliRawReaderHLT::GetTimestamp() const
133{
134 // see header file for class documentation
135 return fpParentReader->GetTimestamp();
136}
137
138const UInt_t* AliRawReaderHLT::GetEquipmentAttributes() const
139{
140 // see header file for class documentation
141 return fpParentReader->GetEquipmentAttributes();
142}
143
144Int_t AliRawReaderHLT::GetEquipmentElementSize() const
145{
146 // see header file for class documentation
13b78f4c 147 // don't know what it really means, bu the AliRawReaderFile
148 // just sets it to 0
149 // do the same if we have a valid equipment data set from
150 // the HLT stream
151 if (fEquipmentId>=0) return 0;
9c7b5023 152 return fpParentReader->GetEquipmentElementSize();
153}
154
155Int_t AliRawReaderHLT::GetEquipmentHeaderSize() const
156{
157 // see header file for class documentation
13b78f4c 158
159 // equipment header means the additional data header?
160 // if we have a valid equipment data set from the HLT stream
161 // there is no additional header
162 if (fEquipmentId>=0) return 0;
9c7b5023 163 return fpParentReader->GetEquipmentHeaderSize();
164}
165
166Int_t AliRawReaderHLT::GetEquipmentSize() const
167{
168 // see header file for class documentation
13b78f4c 169 if (fEquipmentId>=0) return fDataSize+sizeof(AliRawDataHeader);
9c7b5023 170 return fpParentReader->GetEquipmentSize();
171}
172
173Int_t AliRawReaderHLT::GetEquipmentType() const
174{
175 // see header file for class documentation
176 return fpParentReader->GetEquipmentType();
177}
178
179Int_t AliRawReaderHLT::GetEquipmentId() const
180{
181 // see header file for class documentation
13b78f4c 182 Int_t id=-1;
183 if (fEquipmentId>=0) id=fEquipmentId;
184 else id=fpParentReader->GetEquipmentId();
e3917543 185 return id;
9c7b5023 186}
187
188Bool_t AliRawReaderHLT::ReadHeader()
189{
190 // see header file for class documentation
e94eb049 191 Bool_t result=kFALSE;
d3833f99 192 Bool_t firstParentCycle=fbHaveHLTData;
193 while (fbHaveHLTData=(fbHaveHLTData && ReadNextHLTData())) {
e94eb049 194 // all internal data variables set
195 assert(fpData!=NULL);
196 fHeader=reinterpret_cast<AliRawDataHeader*>(const_cast<AliHLTUInt8_t*>(fpData));
d3833f99 197 fOffset=sizeof(AliRawDataHeader);
198 fPosition=fOffset;
e94eb049 199 if (result=IsSelected()) break;
200 }
d3833f99 201 firstParentCycle&=!fbHaveHLTData; // true if it just changed from true to false
202 while (!result) {
203 if (firstParentCycle) {
204 firstParentCycle=kFALSE;
205 // reset and set the selection back to the original one
206 fpParentReader->Reset();
207 fpParentReader->SelectEquipment(fSelectEquipmentType, fSelectMinEquipmentId, fSelectMaxEquipmentId);
208 }
e94eb049 209
d3833f99 210 if (!(result=fpParentReader->ReadHeader())) {
211 fHeader=NULL;
212 break;
213 }
e94eb049 214 fHeader=const_cast<AliRawDataHeader*>(fpParentReader->GetDataHeader());
d3833f99 215
216 // filter out all equipment ids which should be taken from the HLT stream
217 int id=fpParentReader->GetEquipmentId();
218 if (result=!IsHLTInput(id)) break;
e94eb049 219 }
e3917543 220 return result;
9c7b5023 221}
222
223Bool_t AliRawReaderHLT::ReadNextData(UChar_t*& data)
224{
225 // see header file for class documentation
13b78f4c 226
227 // this function is the backbone of the ReadNext functions, it gets the
228 // whole data block either from the HLT stream or the parent raw reader.
229 // Each call of ReadNextData directly jumps to the next data set.
d3833f99 230 Bool_t result=kTRUE;
231
232 // read new header if data already read
233 if (fPosition<fDataSize || (result=ReadHeader())) {
44dc7683 234 if (fbHaveHLTData && fpHLTOUT!=NULL) {
d3833f99 235 // all internal data variables set
236 result=kTRUE;
237 data=const_cast<AliHLTUInt8_t*>(fpData+sizeof(AliRawDataHeader));
21743c3a 238 // fpData includes the CDH, set offset behind CDH
239 fOffset=sizeof(AliRawDataHeader);
13b78f4c 240 } else {
d3833f99 241 // no data in the HLT stream, read real data
242 //AliInfo(Form("read from parent reader: min=%d max=%d", fSelectMinEquipmentId, fSelectMaxEquipmentId));
243
244 // read data
245 result=fpParentReader->ReadNextData(data);
246 if (result) {
247 fpData=data;
248 fDataSize=fpParentReader->GetDataSize();
21743c3a 249 // fpData is without CDH
250 fOffset=0;
d3833f99 251 } else {
252 fpData=NULL;
253 fDataSize=0;
254 }
255
256 fEquipmentId=-1;
13b78f4c 257 }
d3833f99 258 fPosition=fDataSize;
13b78f4c 259 }
e3917543 260 return result;
9c7b5023 261}
262
263Bool_t AliRawReaderHLT::ReadNextInt(UInt_t& data)
264{
265 // see header file for class documentation
13b78f4c 266 int iCopy=sizeof(UInt_t);
267 UChar_t* dummy=NULL;
268 do {
269 if (fpData && (fDataSize-fOffset)>=iCopy) {
270 data=*reinterpret_cast<const UInt_t*>(fpData+fOffset);
271 fOffset+=iCopy;
272 return kTRUE;
273 }
274 } while (ReadNextData(dummy));
275 return kFALSE;
9c7b5023 276}
277
278Bool_t AliRawReaderHLT::ReadNextShort(UShort_t& data)
279{
280 // see header file for class documentation
13b78f4c 281 int iCopy=sizeof(UShort_t);
282 UChar_t* dummy=NULL;
283 do {
284 if (fpData && (fDataSize-fOffset)>=iCopy) {
285 data=*reinterpret_cast<const UShort_t*>(fpData+fOffset);
286 fOffset+=iCopy;
287 return kTRUE;
288 }
289 } while (ReadNextData(dummy));
290 return kFALSE;
9c7b5023 291}
292
293Bool_t AliRawReaderHLT::ReadNextChar(UChar_t& data)
294{
295 // see header file for class documentation
13b78f4c 296 int iCopy=sizeof(UChar_t);
297 UChar_t* dummy=NULL;
298 do {
299 if (fpData && (fDataSize-fOffset)>=iCopy) {
300 data=*reinterpret_cast<const UChar_t*>(fpData+fOffset);
301 fOffset+=iCopy;
302 return kTRUE;
303 }
304 } while (ReadNextData(dummy));
305 return kFALSE;
9c7b5023 306}
307
308Bool_t AliRawReaderHLT::ReadNext(UChar_t* data, Int_t size)
309{
310 // see header file for class documentation
13b78f4c 311 UChar_t* dummy=NULL;
312 do {
313 if (fpData && (fDataSize-fOffset)>=size) {
314 // copy remaining data
315 int iCopy=fDataSize-fOffset;
316 if (iCopy>size) iCopy=size;
317 memcpy(data, fpData+fOffset, iCopy);
318 fOffset+=iCopy;
319 return kTRUE;
320 }
321 } while (ReadNextData(dummy));
322 return kFALSE;
9c7b5023 323}
324
325Bool_t AliRawReaderHLT::Reset()
326{
327 // see header file for class documentation
44dc7683 328 ReleaseHLTData(false/* keep HLTOUT instance */);
13b78f4c 329 Bool_t result=fpParentReader->Reset();
13b78f4c 330 fEquipmentId=-1;
626bfcc1 331
d3833f99 332 // check if redirection is enabled for at least one detector in the selected range
333 fbHaveHLTData=EvaluateSelection();
626bfcc1 334
44dc7683 335 // start reading HLTOUT data blocks from the beginning
336 fbReadFirst=true;
337
13b78f4c 338 return result;
9c7b5023 339}
340
341Bool_t AliRawReaderHLT::NextEvent()
342{
343 // see header file for class documentation
44dc7683 344
345 ReleaseHLTData();
346
e3917543 347 Bool_t result=fpParentReader->NextEvent();
13b78f4c 348 if (result) {
349 fEventNumber++;
350 Reset();
351 }
e3917543 352 return result;
9c7b5023 353}
354
355Bool_t AliRawReaderHLT::RewindEvents()
356{
357 // see header file for class documentation
e3917543 358 fEventNumber=-1;
13b78f4c 359 Reset();
9c7b5023 360 return fpParentReader->RewindEvents();
361}
362
e3917543 363void AliRawReaderHLT::Select(Int_t detectorID, Int_t minDDLID, Int_t maxDDLID)
364{
13b78f4c 365 // see header file for class documentation
e3917543 366 AliRawReader::Select(detectorID, minDDLID, maxDDLID);
367 fpParentReader->Select(detectorID, minDDLID, maxDDLID);
d3833f99 368 fbHaveHLTData=EvaluateSelection();
e3917543 369}
370
371// most likely we do not need this method since the base class directly forwards
372// to this method
373// void AliRawReaderHLT::Select(const char *detectorName, Int_t minDDLID, Int_t maxDDLID)
374// {
375// AliInfo(Form("detectorName=%s, minDDLID=%d, maxDDLID=%d", detectorName, minDDLID, maxDDLID));
376// AliRawReader::Select(detectorName, minDDLID, maxDDLID);
377// fpParentReader->Select(detectorName, minDDLID, maxDDLID);
378// }
379
380void AliRawReaderHLT::SelectEquipment(Int_t equipmentType, Int_t minEquipmentId, Int_t maxEquipmentId)
381{
13b78f4c 382 // see header file for class documentation
383
093f4dba 384 //AliInfo(Form("equipmentType=%d, minEquipmentId=%d, maxEquipmentId=%d", equipmentType, minEquipmentId, maxEquipmentId));
d3833f99 385 AliRawReader::SelectEquipment(equipmentType, minEquipmentId, maxEquipmentId);
386 fpParentReader->SelectEquipment(equipmentType, minEquipmentId, maxEquipmentId);
387 fbHaveHLTData=EvaluateSelection();
e3917543 388}
389
390void AliRawReaderHLT::SkipInvalid(Bool_t skip)
391{
13b78f4c 392 // see header file for class documentation
393
e3917543 394 AliRawReader::SkipInvalid(skip);
395 fpParentReader->SkipInvalid(skip);
396}
397
398void AliRawReaderHLT::SelectEvents(Int_t type)
399{
13b78f4c 400 // see header file for class documentation
401
093f4dba 402 //AliInfo(Form("type=%d", type));
e3917543 403 AliRawReader::SelectEvents(type);
404 fpParentReader->SelectEvents(type);
405}
406
13b78f4c 407int AliRawReaderHLT::ScanOptions(const char* options)
408{
409 // see header file for class documentation
410 int iResult=0;
411 TString optString(options);
412 TString argument;
413 TString parameter;
21743c3a 414 TString detectors;
13b78f4c 415 TObjArray* pTokens=optString.Tokenize(" ");
416 if (pTokens) {
417 int iEntries=pTokens->GetEntries();
418 for (int i =0; i<iEntries; i++) {
419 argument=((TObjString*)pTokens->At(i))->GetString();
420 // first scan all the other options
421 // no other options for the moment
422
423 // it must be a detector name
424 int detId=AliDAQ::DetectorID(argument.Data());
425 if (detId>=0) {
426 fDetectors.push_back(detId);
21743c3a 427 if (!detectors.IsNull()) detectors+=" ";
428 detectors+=argument;
a3ef3c1d 429 } else {
430 if (!fSystemOptions.IsNull()) fSystemOptions+=" ";
431 fSystemOptions+=argument;
13b78f4c 432 }
433 }
434 delete pTokens;
435 }
436
21743c3a 437 if (iResult>=0 && !detectors.IsNull()) {
438 AliInfo(Form("running reconstruction from HLT data: %s", detectors.Data()));
439 }
13b78f4c 440 return iResult;
441}
442
443Bool_t AliRawReaderHLT::ReadNextHLTData()
444{
445 // see header file for class documentation
446 bool result=kTRUE;
44dc7683 447 if (fbReadFirst || !fpHLTOUT) {
448 if (!fpHLTOUT) {
13b78f4c 449 fpHLTOUT=new AliHLTOUTRawReader(fpParentReader);
450 if (result=(fpHLTOUT!=NULL)) {
a3ef3c1d 451 AliHLTSystem* pSystem=GetInstance();
452 if (pSystem) {
453 pSystem->ScanOptions(fSystemOptions.Data());
454 }
13b78f4c 455 if (result=(fpHLTOUT->Init()>=0)) {
13b78f4c 456 }
457 }
44dc7683 458 }
459 if (result) {
460 result=fpHLTOUT->SelectFirstDataBlock(kAliHLTAnyDataType, kAliHLTVoidDataSpec,
461 AliHLTModuleAgent::kRawReader)>=0;
462 }
463 fbReadFirst=false;
13b78f4c 464 } else {
626bfcc1 465 // first release the data buffer
d3833f99 466 ReleaseHLTData(false /* keep HLTOUT instance */);
467 result=fpHLTOUT->SelectNextDataBlock()>=0;
13b78f4c 468 }
469 if (result) {
626bfcc1 470 AliHLTComponentDataType dt=kAliHLTVoidDataType;
471 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
472 fpHLTOUT->GetDataBlockDescription(dt, spec);
13b78f4c 473 AliHLTUInt32_t size=0;
626bfcc1 474 AliHLTOUTHandler* pHandler=fpHLTOUT->GetHandler();
475 if (pHandler) {
476 if (dynamic_cast<AliHLTOUTHandlerEquId*>(pHandler)!=NULL) {
477 AliHLTOUT::AliHLTOUTLockGuard g(fpHLTOUT);
478 fEquipmentId=pHandler->ProcessData(fpHLTOUT);
479 fpData=NULL;
480 fDataSize=pHandler->GetProcessedData(fpData);
481 if (!fpData) {
482 result=fpHLTOUT->GetDataBuffer(fpData, size)>=0;
44dc7683 483 fpDataHandler=NULL;
626bfcc1 484 AliDebug(AliLog::kDebug, Form("forward data block from HLTOUT stream to equipment %d", fEquipmentId));
485 fDataSize=(int)size;
486 } else {
487 // remember the current handler in order to properly release the data buffer
488 fpDataHandler=pHandler;
489 AliDebug(AliLog::kDebug, Form("forward decoded data block provided by handler to equipment %d", fEquipmentId));
490 }
e94eb049 491 return kTRUE;
626bfcc1 492 } else {
493 AliError(Form("handler is not of type AliHLTOUTHandlerEquId for block %x data type %s spec %#x; data block skipped",
494 fpHLTOUT->GetDataBlockIndex(), AliHLTComponent::DataType2Text(dt).c_str(), spec));
495 }
496 } else {
497 AliWarning(Form("no data handler found for block %x data type %s spec %#x; data block skipped",
498 fpHLTOUT->GetDataBlockIndex(), AliHLTComponent::DataType2Text(dt).c_str(), spec));
499 }
13b78f4c 500 } else {
44dc7683 501 ReleaseHLTData(false /* keep HLTOUT instance */);
13b78f4c 502 }
e94eb049 503 return kFALSE;
13b78f4c 504}
505
506Bool_t AliRawReaderHLT::IsHLTInput(int ddlid)
507{
508 // see header file for class documentation
509 vector<int>::iterator detector=fDetectors.begin();
510 for (; detector!=fDetectors.end(); detector++) {
511 int ddlOffset=AliDAQ::DdlIDOffset(*detector);
512 int nofDDLs=AliDAQ::NumberOfDdls(*detector);
513 if (ddlid>=ddlOffset && ddlid<ddlOffset+nofDDLs)
514 return kTRUE;
515 }
516 return kFALSE;
517}
518
d3833f99 519int AliRawReaderHLT::ReleaseHLTData(bool bReleaseHLTOUT)
520{
521 // see header file for class documentation
522 if (fpHLTOUT) {
523 if (fpDataHandler) fpDataHandler->ReleaseProcessedData(fpData, fDataSize);
524 else fpHLTOUT->ReleaseDataBuffer(fpData);
525 fpDataHandler=NULL;
526 if (bReleaseHLTOUT) {
527 delete fpHLTOUT;
528 fpHLTOUT=NULL;
529 }
530 }
531
532 fpData=NULL;
533 fDataSize=0;
534 fOffset=0;
535 fPosition=0;
536 fEquipmentId=-1;
537
538 return 0;
539}
540
541Bool_t AliRawReaderHLT::EvaluateSelection()
542{
543 // see header file for class documentation
544 Bool_t bHaveHLTData=kFALSE;
545 if (bHaveHLTData=(fDetectors.size()>0)) {
546 vector<int>::iterator detector=fDetectors.begin();
547 for (; detector!=fDetectors.end(); detector++) {
548 int ddlOffset=AliDAQ::DdlIDOffset(*detector);
549 int nofDDLs=AliDAQ::NumberOfDdls(*detector);
550 if ((fSelectMinEquipmentId<0 || fSelectMinEquipmentId<ddlOffset+nofDDLs) &&
551 (fSelectMaxEquipmentId<0 || fSelectMaxEquipmentId>=ddlOffset))
552 break;
553 }
554 bHaveHLTData=detector!=fDetectors.end();
555 }
556 return bHaveHLTData;
557}
558
9c7b5023 559AliRawReader* AliRawReaderHLTCreateInstance(AliRawReader* pParentReader, const char* options)
560{
561 // see header file for class documentation
e3917543 562 if (!pParentReader) return NULL;
9c7b5023 563 return new AliRawReaderHLT(pParentReader, options);
564}