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 AliRawReader* pRawReader=GetRawReader();
205 if ((pRawReader=GetRawReader())!=NULL) {
207 AliErrorStream() << "RawReader instance needed" << endl;
214 int AliHLTRawReaderPublisherComponent::DoDeinit()
216 // see header file for class documentation
221 int AliHLTRawReaderPublisherComponent::GetEvent(const AliHLTComponentEventData& /*evtData*/,
222 AliHLTComponentTriggerData& /*trigData*/,
223 AliHLTUInt8_t* outputPtr,
224 AliHLTUInt32_t& size,
225 vector<AliHLTComponentBlockData>& outputBlocks)
227 // see header file for class documentation
229 AliHLTUInt32_t capacity=size;
232 // process data events only
233 if (!IsDataEvent()) return 0;
235 unsigned int offset=0;
236 assert(outputPtr!=NULL || size==0);
237 AliRawReader* pRawReader=GetRawReader();
240 pRawReader->SelectEquipment(-1, fMinEquId, fMaxEquId);
242 AliInfo(Form("get event from RawReader %p equipment id range [%d,%d]", pRawReader, fMinEquId, fMaxEquId));
244 AliDebug(0, Form("get event from RawReader %p equipment id range [%d,%d]", pRawReader, fMinEquId, fMaxEquId));
246 list<int> processedIds;
247 while (pRawReader->ReadHeader() && (iResult>=0 || iResult==-ENOSPC)) {
248 const AliRawDataHeader* pHeader=pRawReader->GetDataHeader();
250 HLTError("can not get data header from RawReader, skipping data block ...");
253 unsigned int readSize=pRawReader->GetDataSize()+sizeof(AliRawDataHeader);
254 int id=pRawReader->GetEquipmentId();
256 AliInfo(Form("got header for id %d, size %d", id, readSize));
258 AliDebug(0, Form("got header for id %d, size %d", id, readSize));
260 if (fMinEquId>id || fMaxEquId<id) {
261 AliError(Form("id %d returned from RawReader is outside range [%d,%d]", id, fMinEquId, fMaxEquId));
264 processedIds.push_back(id);
265 if (readSize+offset<=capacity) {
266 memcpy(outputPtr+offset, pHeader, sizeof(AliRawDataHeader));
267 if (readSize>sizeof(AliRawDataHeader)) {
268 if (!pRawReader->ReadNext(outputPtr+offset+sizeof(AliRawDataHeader), readSize-sizeof(AliRawDataHeader))) {
269 AliError(Form("error reading %d bytes from RawReader %p", readSize-sizeof(AliRawDataHeader), pRawReader));
274 AliHLTComponentBlockData bd;
278 bd.fDataType = fDataType;
279 if (fSpecification == kAliHLTVoidDataSpec) {
280 GetSpecificationFromEquipmentId(id, bd.fSpecification);
282 bd.fSpecification=fSpecification;
284 outputBlocks.push_back( bd );
286 // we keep the loop going in order to collect the full size
287 fMaxSize=offset+readSize;
292 if (!fSkipEmpty && processedIds.size()!=size_t(fMaxEquId-fMinEquId+1)) {
293 // add further empty data blocks
294 AliRawDataHeader header;
295 header.fSize=sizeof(AliRawDataHeader);
297 list<int>::iterator curr=processedIds.begin();
298 for (int id=fMinEquId; id<=fMaxEquId; id++) {
299 if (curr!=processedIds.end() && *curr<=id) {
302 if (sizeof(AliRawDataHeader)<=capacity-offset) {
303 HLTInfo("add empty data block for equipment id %d", id);
304 memcpy(outputPtr+offset, &header, sizeof(AliRawDataHeader));
305 AliHLTComponentBlockData bd;
308 bd.fSize = sizeof(AliRawDataHeader);
309 bd.fDataType = fDataType;
310 if (fSpecification == kAliHLTVoidDataSpec) {
311 GetSpecificationFromEquipmentId(id, bd.fSpecification);
313 bd.fSpecification=fSpecification;
315 outputBlocks.push_back( bd );
317 // we keep the loop going in order to collect the full size
318 fMaxSize=offset+sizeof(AliRawDataHeader);
321 offset+=sizeof(AliRawDataHeader);
325 if (offset<=capacity) {
328 outputBlocks.clear();
331 AliErrorStream() << "RawReader uninitialized" << endl;
337 int AliHLTRawReaderPublisherComponent::GetSpecificationFromEquipmentId(int id, AliHLTUInt32_t& specification) const {
338 // see header file for class documentation
339 return specification=id;