3 /**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
7 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 * for The ALICE HLT Project. *
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 **************************************************************************/
19 /** @file AliRawReaderHLT.cxx
20 @author Matthias Richter
22 @brief AliRawReader implementation which replaces original input of
23 detectors with the appropriate HLT output. */
25 // see header file for class documentation
27 // refer to README to build package
29 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
31 #include "AliRawReaderHLT.h"
32 #include "AliHLTOUTRawReader.h"
33 #include "AliHLTModuleAgent.h"
35 #include "AliDAQ.h" // RAW, for detector names and equipment ids
36 #include "TObjString.h"
39 /** ROOT macro for the implementation of ROOT specific class methods */
40 ClassImp(AliRawReaderHLT)
42 AliRawReaderHLT::AliRawReaderHLT(AliRawReader* pRawreader, const char* options)
45 fpParentReader(pRawreader),
55 // see header file for class documentation
57 // refer to README to build package
59 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
64 AliRawReaderHLT::~AliRawReaderHLT()
66 // see header file for class documentation
69 UInt_t AliRawReaderHLT::GetType() const
71 // see header file for class documentation
72 return fpParentReader->GetType();
75 UInt_t AliRawReaderHLT::GetRunNumber() const
77 // see header file for class documentation
78 return fpParentReader->GetRunNumber();
81 const UInt_t* AliRawReaderHLT::GetEventId() const
83 // see header file for class documentation
84 return fpParentReader->GetEventId();
87 const UInt_t* AliRawReaderHLT::GetTriggerPattern() const
89 // see header file for class documentation
90 return fpParentReader->GetTriggerPattern();
93 const UInt_t* AliRawReaderHLT::GetDetectorPattern() const
95 // see header file for class documentation
96 return fpParentReader->GetDetectorPattern();
99 const UInt_t* AliRawReaderHLT::GetAttributes() const
101 // see header file for class documentation
102 return fpParentReader->GetAttributes();
105 const UInt_t* AliRawReaderHLT::GetSubEventAttributes() const
107 // see header file for class documentation
108 return fpParentReader->GetSubEventAttributes();
111 UInt_t AliRawReaderHLT::GetLDCId() const
113 // see header file for class documentation
114 return fpParentReader->GetLDCId();
117 UInt_t AliRawReaderHLT::GetGDCId() const
119 // see header file for class documentation
120 return fpParentReader->GetGDCId();
123 UInt_t AliRawReaderHLT::GetTimestamp() const
125 // see header file for class documentation
126 return fpParentReader->GetTimestamp();
129 const UInt_t* AliRawReaderHLT::GetEquipmentAttributes() const
131 // see header file for class documentation
132 return fpParentReader->GetEquipmentAttributes();
135 Int_t AliRawReaderHLT::GetEquipmentElementSize() const
137 // see header file for class documentation
138 // don't know what it really means, bu the AliRawReaderFile
140 // do the same if we have a valid equipment data set from
142 if (fEquipmentId>=0) return 0;
143 return fpParentReader->GetEquipmentElementSize();
146 Int_t AliRawReaderHLT::GetEquipmentHeaderSize() const
148 // see header file for class documentation
150 // equipment header means the additional data header?
151 // if we have a valid equipment data set from the HLT stream
152 // there is no additional header
153 if (fEquipmentId>=0) return 0;
154 return fpParentReader->GetEquipmentHeaderSize();
157 Int_t AliRawReaderHLT::GetEquipmentSize() const
159 // see header file for class documentation
160 if (fEquipmentId>=0) return fDataSize+sizeof(AliRawDataHeader);
161 return fpParentReader->GetEquipmentSize();
164 Int_t AliRawReaderHLT::GetEquipmentType() const
166 // see header file for class documentation
167 return fpParentReader->GetEquipmentType();
170 Int_t AliRawReaderHLT::GetEquipmentId() const
172 // see header file for class documentation
174 if (fEquipmentId>=0) id=fEquipmentId;
175 else id=fpParentReader->GetEquipmentId();
179 Bool_t AliRawReaderHLT::ReadHeader()
181 // see header file for class documentation
182 Bool_t result=fpParentReader->ReadHeader();
183 fHeader=const_cast<AliRawDataHeader*>(fpParentReader->GetDataHeader());
187 Bool_t AliRawReaderHLT::ReadNextData(UChar_t*& data)
189 // see header file for class documentation
191 // this function is the backbone of the ReadNext functions, it gets the
192 // whole data block either from the HLT stream or the parent raw reader.
193 // Each call of ReadNextData directly jumps to the next data set.
194 Bool_t result=kFALSE;
195 if (fbHaveHLTData&=ReadNextHLTData()) {
196 // all internal data variables set
197 assert(fpData!=NULL);
198 data=const_cast<AliHLTUInt8_t*>(fpData);
202 // no data in the HLT stream, read real data
203 //AliInfo(Form("read from parent reader: min=%d max=%d", fSelectMinEquipmentId, fSelectMaxEquipmentId));
205 // first set the selection back to the original one
206 fpParentReader->SelectEquipment(fSelectEquipmentType, fSelectMinEquipmentId, fSelectMaxEquipmentId);
209 while (result=fpParentReader->ReadNextData(data)) {
210 // continue if the Equipment Id is supposed to be replaced by the HLT stream
211 // in that case we do not want to read it from the parent raw reader
212 if (!IsHLTInput(fpParentReader->GetEquipmentId())) break;
215 // set the header of this reader from the parent reader.
216 // This is necessary because of a few base class methods working directly
218 fHeader=const_cast<AliRawDataHeader*>(fpParentReader->GetDataHeader());
221 fDataSize=fpParentReader->GetDataSize();
232 Bool_t AliRawReaderHLT::ReadNextInt(UInt_t& data)
234 // see header file for class documentation
235 int iCopy=sizeof(UInt_t);
238 if (fpData && (fDataSize-fOffset)>=iCopy) {
239 data=*reinterpret_cast<const UInt_t*>(fpData+fOffset);
243 } while (ReadNextData(dummy));
247 Bool_t AliRawReaderHLT::ReadNextShort(UShort_t& data)
249 // see header file for class documentation
250 int iCopy=sizeof(UShort_t);
253 if (fpData && (fDataSize-fOffset)>=iCopy) {
254 data=*reinterpret_cast<const UShort_t*>(fpData+fOffset);
258 } while (ReadNextData(dummy));
262 Bool_t AliRawReaderHLT::ReadNextChar(UChar_t& data)
264 // see header file for class documentation
265 int iCopy=sizeof(UChar_t);
268 if (fpData && (fDataSize-fOffset)>=iCopy) {
269 data=*reinterpret_cast<const UChar_t*>(fpData+fOffset);
273 } while (ReadNextData(dummy));
277 Bool_t AliRawReaderHLT::ReadNext(UChar_t* data, Int_t size)
279 // see header file for class documentation
282 if (fpData && (fDataSize-fOffset)>=size) {
283 // copy remaining data
284 int iCopy=fDataSize-fOffset;
285 if (iCopy>size) iCopy=size;
286 memcpy(data, fpData+fOffset, iCopy);
290 } while (ReadNextData(dummy));
294 Bool_t AliRawReaderHLT::Reset()
296 // see header file for class documentation
297 Bool_t result=fpParentReader->Reset();
302 if (fbHaveHLTData=(fDetectors.size()>0)) {
303 vector<int>::iterator detector=fDetectors.begin();
304 for (; detector!=fDetectors.end(); detector++) {
305 int ddlOffset=AliDAQ::DdlIDOffset(*detector);
306 int nofDDLs=AliDAQ::NumberOfDdls(*detector);
307 if ((fSelectMinEquipmentId>=0 && fSelectMinEquipmentId>ddlOffset+nofDDLs) ||
308 (fSelectMinEquipmentId>=0 && fSelectMaxEquipmentId<ddlOffset))
312 fbHaveHLTData=detector!=fDetectors.end();
317 Bool_t AliRawReaderHLT::NextEvent()
319 // see header file for class documentation
320 Bool_t result=fpParentReader->NextEvent();
328 Bool_t AliRawReaderHLT::RewindEvents()
330 // see header file for class documentation
333 return fpParentReader->RewindEvents();
336 void AliRawReaderHLT::Select(Int_t detectorID, Int_t minDDLID, Int_t maxDDLID)
338 // see header file for class documentation
339 AliRawReader::Select(detectorID, minDDLID, maxDDLID);
340 fpParentReader->Select(detectorID, minDDLID, maxDDLID);
343 // most likely we do not need this method since the base class directly forwards
345 // void AliRawReaderHLT::Select(const char *detectorName, Int_t minDDLID, Int_t maxDDLID)
347 // AliInfo(Form("detectorName=%s, minDDLID=%d, maxDDLID=%d", detectorName, minDDLID, maxDDLID));
348 // AliRawReader::Select(detectorName, minDDLID, maxDDLID);
349 // fpParentReader->Select(detectorName, minDDLID, maxDDLID);
352 void AliRawReaderHLT::SelectEquipment(Int_t equipmentType, Int_t minEquipmentId, Int_t maxEquipmentId)
354 // see header file for class documentation
356 //AliInfo(Form("equipmentType=%d, minEquipmentId=%d, maxEquipmentId=%d", equipmentType, minEquipmentId, maxEquipmentId));
357 AliRawReader::Select(equipmentType, minEquipmentId, maxEquipmentId);
358 fpParentReader->Select(equipmentType, minEquipmentId, maxEquipmentId);
361 void AliRawReaderHLT::SkipInvalid(Bool_t skip)
363 // see header file for class documentation
365 AliRawReader::SkipInvalid(skip);
366 fpParentReader->SkipInvalid(skip);
369 void AliRawReaderHLT::SelectEvents(Int_t type)
371 // see header file for class documentation
373 //AliInfo(Form("type=%d", type));
374 AliRawReader::SelectEvents(type);
375 fpParentReader->SelectEvents(type);
378 int AliRawReaderHLT::ScanOptions(const char* options)
380 // see header file for class documentation
382 TString optString(options);
385 TObjArray* pTokens=optString.Tokenize(" ");
387 int iEntries=pTokens->GetEntries();
388 for (int i =0; i<iEntries; i++) {
389 argument=((TObjString*)pTokens->At(i))->GetString();
390 // first scan all the other options
391 // no other options for the moment
393 // it must be a detector name
394 int detId=AliDAQ::DetectorID(argument.Data());
396 fDetectors.push_back(detId);
405 Bool_t AliRawReaderHLT::ReadNextHLTData()
407 // see header file for class documentation
410 fpHLTOUT=new AliHLTOUTRawReader(fpParentReader);
411 if (result=(fpHLTOUT!=NULL)) {
412 if (result=(fpHLTOUT->Init()>=0)) {
413 result=fpHLTOUT->SelectFirstDataBlock(kAliHLTAnyDataType, kAliHLTVoidDataSpec,
414 AliHLTModuleAgent::kRawReader)>=0;
418 fpHLTOUT->ReleaseDataBuffer(fpData);
419 if (!(result=fpHLTOUT->SelectNextDataBlock()>=0)) {
425 AliHLTUInt32_t size=0;
426 result=fpHLTOUT->GetDataBuffer(fpData, size)>=0;
438 Bool_t AliRawReaderHLT::IsHLTInput(int ddlid)
440 // see header file for class documentation
441 vector<int>::iterator detector=fDetectors.begin();
442 for (; detector!=fDetectors.end(); detector++) {
443 int ddlOffset=AliDAQ::DdlIDOffset(*detector);
444 int nofDDLs=AliDAQ::NumberOfDdls(*detector);
445 if (ddlid>=ddlOffset && ddlid<ddlOffset+nofDDLs)
451 AliRawReader* AliRawReaderHLTCreateInstance(AliRawReader* pParentReader, const char* options)
453 // see header file for class documentation
454 if (!pParentReader) return NULL;
455 return new AliRawReaderHLT(pParentReader, options);