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("-skipempty")==0) {
141 } else if (argument.CompareTo("-datatype")==0) {
142 if ((bMissingParam=(++i>=argc))) break;
143 memcpy(&fDataType.fID, argv[i], TMath::Min(kAliHLTComponentDataTypefIDsize, (Int_t)strlen(argv[i])));
144 if ((bMissingParam=(++i>=argc))) break;
145 memcpy(&fDataType.fOrigin, argv[i], TMath::Min(kAliHLTComponentDataTypefOriginSize, (Int_t)strlen(argv[i])));
148 } else if (argument.CompareTo("-dataspec")==0) {
149 if ((bMissingParam=(++i>=argc))) break;
150 TString parameter(argv[i]);
151 parameter.Remove(TString::kLeading, ' '); // remove all blanks
152 if (parameter.IsDigit()) {
153 fSpecification=(AliHLTUInt32_t)parameter.Atoi();
154 } else if (parameter.BeginsWith("0x") &&
155 parameter.Replace(0,2,"",0).IsHex()) {
156 sscanf(parameter.Data(),"%x", &fSpecification);
158 HLTError("wrong parameter for argument %s, number expected", argument.Data());
162 HLTError("unknown argument %s", argument.Data());
167 HLTError("missing parameter for argument %s", argument.Data());
171 if (iResult<0) return iResult;
173 if (!fDetector.IsNull()) {
176 if ((ddloffset=AliDAQ::DdlIDOffset(fDetector))<0 ||
177 (ddlcount=AliDAQ::NumberOfDdls(fDetector))<0) {
180 if (fMinEquId<0) fMinEquId=ddloffset;
181 else fMinEquId+=ddloffset;
183 if (fMaxEquId<0 || fMaxEquId>ddlcount) fMaxEquId=ddloffset+ddlcount;
184 else fMaxEquId+=ddloffset;
187 if (fMinEquId>fMaxEquId) fMaxEquId=fMinEquId;
190 AliErrorStream() << "equipment id required, use \'-equipmentid\' or \'-detector\' option" << endl;
194 AliHLTUInt32_t dummy;
195 if (fMinEquId!=fMaxEquId && GetSpecificationFromEquipmentId(0, dummy)==-ENOSYS) {
196 AliWarningStream() << "publication of multiple equipment ids needs implementation of a child and function GetSpecificationFromEquipmentId to set correct specifications" << endl;
200 AliRawReader* pRawReader=GetRawReader();
201 if ((pRawReader=GetRawReader())!=NULL) {
203 AliErrorStream() << "RawReader instance needed" << endl;
210 int AliHLTRawReaderPublisherComponent::DoDeinit()
212 // see header file for class documentation
217 int AliHLTRawReaderPublisherComponent::GetEvent(const AliHLTComponentEventData& /*evtData*/,
218 AliHLTComponentTriggerData& /*trigData*/,
219 AliHLTUInt8_t* outputPtr,
220 AliHLTUInt32_t& size,
221 vector<AliHLTComponentBlockData>& outputBlocks)
223 // see header file for class documentation
225 unsigned int offset=0;
226 assert(outputPtr!=NULL || size==0);
227 AliRawReader* pRawReader=GetRawReader();
230 pRawReader->SelectEquipment(-1, fMinEquId, fMaxEquId);
232 AliInfo(Form("get event from RawReader %p equipment id range [%d,%d]", pRawReader, fMinEquId, fMaxEquId));
234 AliDebug(0, Form("get event from RawReader %p equipment id range [%d,%d]", pRawReader, fMinEquId, fMaxEquId));
236 list<int> processedIds;
237 while (pRawReader->ReadHeader() && (iResult>=0 || iResult==-ENOSPC)) {
238 const AliRawDataHeader* pHeader=pRawReader->GetDataHeader();
240 HLTError("can not get data header from RawReader, skipping data block ...");
243 unsigned int readSize=pRawReader->GetDataSize()+sizeof(AliRawDataHeader);
244 int id=pRawReader->GetEquipmentId();
245 AliInfo(Form("got header for id %d, size %d", id, readSize));
246 if (fMinEquId>id || fMaxEquId<id) {
247 AliError(Form("id %d returned from RawReader is outside range [%d,%d]", id, fMinEquId, fMaxEquId));
250 processedIds.push_back(id);
251 if (readSize<=size-offset) {
252 memcpy(outputPtr+offset, pHeader, sizeof(AliRawDataHeader));
253 if (readSize>sizeof(AliRawDataHeader)) {
254 if (!pRawReader->ReadNext(outputPtr+offset+sizeof(AliRawDataHeader), readSize-sizeof(AliRawDataHeader))) {
255 AliError(Form("error reading %d bytes from RawReader %p", readSize-sizeof(AliRawDataHeader), pRawReader));
260 AliHLTComponentBlockData bd;
264 bd.fDataType = fDataType;
265 if (fSpecification == kAliHLTVoidDataSpec) {
266 GetSpecificationFromEquipmentId(id, bd.fSpecification);
268 bd.fSpecification=fSpecification;
270 outputBlocks.push_back( bd );
272 // we keep the loop going in order to collect the full size
273 fMaxSize=offset+readSize;
278 if (!fSkipEmpty && processedIds.size()!=size_t(fMaxEquId-fMinEquId+1)) {
279 // add further empty data blocks
280 AliRawDataHeader header;
281 header.fSize=sizeof(AliRawDataHeader);
283 list<int>::iterator curr=processedIds.begin();
284 for (int id=fMinEquId; id<=fMaxEquId; id++) {
285 if (curr!=processedIds.end() && *curr<=id) {
288 if (sizeof(AliRawDataHeader)<=size-offset) {
289 HLTInfo("add empty data block for equipment id %d", id);
290 memcpy(outputPtr+offset, &header, sizeof(AliRawDataHeader));
291 AliHLTComponentBlockData bd;
294 bd.fSize = sizeof(AliRawDataHeader);
295 bd.fDataType = fDataType;
296 if (fSpecification == kAliHLTVoidDataSpec) {
297 GetSpecificationFromEquipmentId(id, bd.fSpecification);
299 bd.fSpecification=fSpecification;
301 outputBlocks.push_back( bd );
303 // we keep the loop going in order to collect the full size
304 fMaxSize=offset+sizeof(AliRawDataHeader);
307 offset+=sizeof(AliRawDataHeader);
315 outputBlocks.clear();
318 AliErrorStream() << "RawReader uninitialized" << endl;
324 int AliHLTRawReaderPublisherComponent::GetSpecificationFromEquipmentId(int id, AliHLTUInt32_t& specification) const {
325 // see header file for class documentation
326 return specification=id;