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 AliHLTRawReaderPublisherComponent.cxx
20 /// @author Matthias Richter
22 /// @brief A general tree publisher component for the AliRawReader.
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 "AliHLTRawReaderPublisherComponent.h"
32 #include "AliRawReader.h"
39 /** ROOT macro for the implementation of ROOT specific class methods */
40 ClassImp(AliHLTRawReaderPublisherComponent)
42 AliHLTRawReaderPublisherComponent::AliHLTRawReaderPublisherComponent()
49 fDataType(kAliHLTVoidDataType),
50 fSpecification(kAliHLTVoidDataSpec),
53 // see header file for class documentation
55 // refer to README to build package
57 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
60 AliHLTRawReaderPublisherComponent::~AliHLTRawReaderPublisherComponent()
62 // see header file for class documentation
65 const char* AliHLTRawReaderPublisherComponent::GetComponentID()
67 // see header file for class documentation
68 return "AliRawReaderPublisher";
71 AliHLTComponentDataType AliHLTRawReaderPublisherComponent::GetOutputDataType()
73 // see header file for class documentation
77 void AliHLTRawReaderPublisherComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
79 // see header file for class documentation
84 AliHLTComponent* AliHLTRawReaderPublisherComponent::Spawn()
86 // see header file for class documentation
87 return new AliHLTRawReaderPublisherComponent;
90 int AliHLTRawReaderPublisherComponent::DoInit( int argc, const char** argv )
92 // see header file for class documentation
98 for (int i=0; i<argc && iResult>=0; i++) {
100 if (argument.IsNull()) continue;
103 if (argument.CompareTo("-detector")==0) {
104 if ((bMissingParam=(++i>=argc))) break;
107 // -equipmentid, -minid
108 } else if (argument.CompareTo("-equipmentid")==0 ||
109 argument.CompareTo("-minid")==0) {
110 if ((bMissingParam=(++i>=argc))) break;
111 TString parameter(argv[i]);
112 parameter.Remove(TString::kLeading, ' '); // remove all blanks
113 if (parameter.IsDigit()) {
114 fMinEquId=(AliHLTUInt32_t)parameter.Atoi();
116 HLTError("wrong parameter for argument %s, number expected", argument.Data());
121 } else if (argument.CompareTo("-maxid")==0) {
122 if ((bMissingParam=(++i>=argc))) break;
123 TString parameter(argv[i]);
124 parameter.Remove(TString::kLeading, ' '); // remove all blanks
125 if (parameter.IsDigit()) {
126 fMaxEquId=(AliHLTUInt32_t)parameter.Atoi();
128 HLTError("wrong parameter for argument %s, number expected", argument.Data());
133 } else if (argument.CompareTo("-verbose")==0) {
137 } else if (argument.CompareTo("-silent")==0) {
141 } else if (argument.CompareTo("-skipempty")==0) {
145 } else if (argument.CompareTo("-datatype")==0) {
146 if ((bMissingParam=(++i>=argc))) break;
147 memcpy(&fDataType.fID, argv[i], TMath::Min(kAliHLTComponentDataTypefIDsize, (Int_t)strlen(argv[i])));
148 if ((bMissingParam=(++i>=argc))) break;
149 memcpy(&fDataType.fOrigin, argv[i], TMath::Min(kAliHLTComponentDataTypefOriginSize, (Int_t)strlen(argv[i])));
152 } else if (argument.CompareTo("-dataspec")==0) {
153 if ((bMissingParam=(++i>=argc))) break;
154 TString parameter(argv[i]);
155 parameter.Remove(TString::kLeading, ' '); // remove all blanks
156 if (parameter.IsDigit()) {
157 fSpecification=(AliHLTUInt32_t)parameter.Atoi();
158 } else if (parameter.BeginsWith("0x") &&
159 parameter.Replace(0,2,"",0).IsHex()) {
160 sscanf(parameter.Data(),"%x", &fSpecification);
162 HLTError("wrong parameter for argument %s, number expected", argument.Data());
166 HLTError("unknown argument %s", argument.Data());
171 HLTError("missing parameter for argument %s", argument.Data());
175 if (iResult<0) return iResult;
177 if (!fDetector.IsNull()) {
180 if ((ddloffset=AliDAQ::DdlIDOffset(fDetector))<0 ||
181 (ddlcount=AliDAQ::NumberOfDdls(fDetector))<0) {
184 if (fMinEquId<0) fMinEquId=ddloffset;
185 else fMinEquId+=ddloffset;
187 if (fMaxEquId<0 || fMaxEquId>ddlcount) fMaxEquId=ddloffset+ddlcount;
188 else fMaxEquId+=ddloffset;
191 if (fMinEquId>fMaxEquId) fMaxEquId=fMinEquId;
194 AliErrorStream() << "equipment id required, use \'-equipmentid\' or \'-detector\' option" << endl;
198 AliHLTUInt32_t dummy;
199 if (fMinEquId!=fMaxEquId && GetSpecificationFromEquipmentId(0, dummy)==-ENOSYS) {
200 AliWarningStream() << "publication of multiple equipment ids needs implementation of a child and function GetSpecificationFromEquipmentId to set correct specifications" << endl;
204 if (GetRawReader()!=NULL) {
206 AliErrorStream() << "RawReader instance needed" << endl;
213 int AliHLTRawReaderPublisherComponent::DoDeinit()
215 // see header file for class documentation
220 int AliHLTRawReaderPublisherComponent::GetEvent(const AliHLTComponentEventData& /*evtData*/,
221 AliHLTComponentTriggerData& /*trigData*/,
222 AliHLTUInt8_t* outputPtr,
223 AliHLTUInt32_t& size,
224 vector<AliHLTComponentBlockData>& outputBlocks)
226 // see header file for class documentation
228 AliHLTUInt32_t capacity=size;
231 // process data events only
232 if (!IsDataEvent()) return 0;
234 unsigned int offset=0;
235 assert(outputPtr!=NULL || size==0);
236 AliRawReader* pRawReader=GetRawReader();
239 pRawReader->SelectEquipment(-1, fMinEquId, fMaxEquId);
241 AliInfo(Form("get event from RawReader %p equipment id range [%d,%d]", pRawReader, fMinEquId, fMaxEquId));
243 AliDebug(0, Form("get event from RawReader %p equipment id range [%d,%d]", pRawReader, fMinEquId, fMaxEquId));
245 list<int> processedIds;
246 while (pRawReader->ReadHeader() && (iResult>=0 || iResult==-ENOSPC)) {
247 const AliRawDataHeader* pHeader=pRawReader->GetDataHeader();
249 HLTError("can not get data header from RawReader, skipping data block ...");
252 unsigned int readSize=pRawReader->GetDataSize()+sizeof(AliRawDataHeader);
253 int id=pRawReader->GetEquipmentId();
255 AliInfo(Form("got header for id %d, size %d", id, readSize));
257 AliDebug(0, Form("got header for id %d, size %d", id, readSize));
259 if (fMinEquId>id || fMaxEquId<id) {
260 AliError(Form("id %d returned from RawReader is outside range [%d,%d]", id, fMinEquId, fMaxEquId));
263 processedIds.push_back(id);
264 if (readSize+offset<=capacity) {
265 memcpy(outputPtr+offset, pHeader, sizeof(AliRawDataHeader));
266 if (readSize>sizeof(AliRawDataHeader)) {
267 if (!pRawReader->ReadNext(outputPtr+offset+sizeof(AliRawDataHeader), readSize-sizeof(AliRawDataHeader))) {
268 AliError(Form("error reading %ld bytes from RawReader %p", readSize-sizeof(AliRawDataHeader), pRawReader));
273 AliHLTComponentBlockData bd;
277 bd.fDataType = fDataType;
278 if (fSpecification == kAliHLTVoidDataSpec) {
279 GetSpecificationFromEquipmentId(id, bd.fSpecification);
281 bd.fSpecification=fSpecification;
283 outputBlocks.push_back( bd );
285 // we keep the loop going in order to collect the full size
286 fMaxSize=offset+readSize;
291 if (!fSkipEmpty && processedIds.size()!=size_t(fMaxEquId-fMinEquId+1)) {
292 // add further empty data blocks
293 AliRawDataHeader header;
294 header.fSize=sizeof(AliRawDataHeader);
295 const UInt_t* triggermask=pRawReader->GetTriggerPattern();
297 header.fTriggerClassLow=triggermask[0];
298 header.fROILowTriggerClassHigh=triggermask[1];
301 list<int>::iterator curr=processedIds.begin();
302 for (int id=fMinEquId; id<=fMaxEquId; id++) {
303 if (curr!=processedIds.end() && *curr<=id) {
306 if (sizeof(AliRawDataHeader)<=capacity-offset) {
307 HLTInfo("add empty data block for equipment id %d", id);
308 memcpy(outputPtr+offset, &header, sizeof(AliRawDataHeader));
309 AliHLTComponentBlockData bd;
312 bd.fSize = sizeof(AliRawDataHeader);
313 bd.fDataType = fDataType;
314 if (fSpecification == kAliHLTVoidDataSpec) {
315 GetSpecificationFromEquipmentId(id, bd.fSpecification);
317 bd.fSpecification=fSpecification;
319 outputBlocks.push_back( bd );
321 // we keep the loop going in order to collect the full size
322 fMaxSize=offset+sizeof(AliRawDataHeader);
325 offset+=sizeof(AliRawDataHeader);
329 if (offset<=capacity) {
332 outputBlocks.clear();
335 AliErrorStream() << "RawReader uninitialized" << endl;
341 int AliHLTRawReaderPublisherComponent::GetSpecificationFromEquipmentId(int id, AliHLTUInt32_t& specification) const {
342 // see header file for class documentation
343 return specification=id;