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"
38 /** ROOT macro for the implementation of ROOT specific class methods */
39 ClassImp(AliHLTRawReaderPublisherComponent)
41 AliHLTRawReaderPublisherComponent::AliHLTRawReaderPublisherComponent()
48 fDataType(kAliHLTVoidDataType),
49 fSpecification(kAliHLTVoidDataSpec)
51 // see header file for class documentation
53 // refer to README to build package
55 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
58 AliHLTRawReaderPublisherComponent::~AliHLTRawReaderPublisherComponent()
60 // see header file for class documentation
63 const char* AliHLTRawReaderPublisherComponent::GetComponentID()
65 // see header file for class documentation
66 return "AliRawReaderPublisher";
69 AliHLTComponentDataType AliHLTRawReaderPublisherComponent::GetOutputDataType()
71 // see header file for class documentation
75 void AliHLTRawReaderPublisherComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
77 // see header file for class documentation
82 AliHLTComponent* AliHLTRawReaderPublisherComponent::Spawn()
84 // see header file for class documentation
85 return new AliHLTRawReaderPublisherComponent;
88 int AliHLTRawReaderPublisherComponent::DoInit( int argc, const char** argv )
90 // see header file for class documentation
96 for (int i=0; i<argc && iResult>=0; i++) {
98 if (argument.IsNull()) continue;
101 if (argument.CompareTo("-detector")==0) {
102 if ((bMissingParam=(++i>=argc))) break;
105 // -equipmentid, -minid
106 } else if (argument.CompareTo("-equipmentid")==0 ||
107 argument.CompareTo("-minid")==0) {
108 if ((bMissingParam=(++i>=argc))) break;
109 TString parameter(argv[i]);
110 parameter.Remove(TString::kLeading, ' '); // remove all blanks
111 if (parameter.IsDigit()) {
112 fMinEquId=(AliHLTUInt32_t)parameter.Atoi();
114 HLTError("wrong parameter for argument %s, number expected", argument.Data());
119 } else if (argument.CompareTo("-maxid")==0) {
120 if ((bMissingParam=(++i>=argc))) break;
121 TString parameter(argv[i]);
122 parameter.Remove(TString::kLeading, ' '); // remove all blanks
123 if (parameter.IsDigit()) {
124 fMaxEquId=(AliHLTUInt32_t)parameter.Atoi();
126 HLTError("wrong parameter for argument %s, number expected", argument.Data());
131 } else if (argument.CompareTo("-verbose")==0) {
135 } else if (argument.CompareTo("-datatype")==0) {
136 if ((bMissingParam=(++i>=argc))) break;
137 memcpy(&fDataType.fID, argv[i], TMath::Min(kAliHLTComponentDataTypefIDsize, (Int_t)strlen(argv[i])));
138 if ((bMissingParam=(++i>=argc))) break;
139 memcpy(&fDataType.fOrigin, argv[i], TMath::Min(kAliHLTComponentDataTypefOriginSize, (Int_t)strlen(argv[i])));
142 } else if (argument.CompareTo("-dataspec")==0) {
143 if ((bMissingParam=(++i>=argc))) break;
144 TString parameter(argv[i]);
145 parameter.Remove(TString::kLeading, ' '); // remove all blanks
146 if (parameter.IsDigit()) {
147 fSpecification=(AliHLTUInt32_t)parameter.Atoi();
148 } else if (parameter.BeginsWith("0x") &&
149 parameter.Replace(0,2,"",0).IsHex()) {
150 sscanf(parameter.Data(),"%x", &fSpecification);
152 HLTError("wrong parameter for argument %s, number expected", argument.Data());
156 HLTError("unknown argument %s", argument.Data());
161 HLTError("missing parameter for argument %s", argument.Data());
165 if (iResult<0) return iResult;
167 if (fMinEquId>fMaxEquId) fMaxEquId=fMinEquId;
170 AliErrorStream() << "equipment id required, use \'-equipmentid\' option" << endl;
174 if (!fDetector.IsNull()) {
175 AliErrorStream() << "option \'-detector\' not implemented" << endl;
179 AliHLTUInt32_t dummy;
180 if (fMinEquId!=fMaxEquId && GetSpecificationFromEquipmentId(0, dummy)==-ENOSYS) {
181 AliWarningStream() << "publication of multiple equipment ids needs implementation of a child and function GetSpecificationFromEquipmentId to set correct specifications" << endl;
185 AliRawReader* pRawReader=GetRawReader();
186 if ((pRawReader=GetRawReader())!=NULL) {
188 AliErrorStream() << "RawReader instance needed" << endl;
195 int AliHLTRawReaderPublisherComponent::DoDeinit()
197 // see header file for class documentation
202 int AliHLTRawReaderPublisherComponent::GetEvent(const AliHLTComponentEventData& /*evtData*/,
203 AliHLTComponentTriggerData& /*trigData*/,
204 AliHLTUInt8_t* outputPtr,
205 AliHLTUInt32_t& size,
206 vector<AliHLTComponentBlockData>& outputBlocks)
208 // see header file for class documentation
210 unsigned int offset=0;
211 assert(outputPtr!=NULL || size==0);
212 AliRawReader* pRawReader=GetRawReader();
215 pRawReader->SelectEquipment(-1, fMinEquId, fMaxEquId);
216 AliInfo(Form("get event from RawReader %p equipment id range [%d,%d]", pRawReader, fMinEquId, fMaxEquId));
217 list<int> processedIds;
218 while (pRawReader->ReadHeader() && (iResult>=0 || iResult==-ENOSPC)) {
219 const AliRawDataHeader* pHeader=pRawReader->GetDataHeader();
220 assert(pHeader!=NULL);
221 if (pHeader==NULL) continue;
222 unsigned int readSize=pRawReader->GetDataSize()+sizeof(AliRawDataHeader);
223 int id=pRawReader->GetEquipmentId();
224 AliInfo(Form("got header for id %d, size %d", id, readSize));
225 if (fMinEquId>id || fMaxEquId<id) {
226 AliError(Form("id %d returned from RawReader is outside range [%d,%d]", id, fMinEquId, fMaxEquId));
229 processedIds.push_back(id);
230 if (readSize<=size-offset) {
231 memcpy(outputPtr+offset, pHeader, sizeof(AliRawDataHeader));
232 if (readSize>sizeof(AliRawDataHeader)) {
233 if (!pRawReader->ReadNext(outputPtr+offset+sizeof(AliRawDataHeader), readSize-sizeof(AliRawDataHeader))) {
234 AliError(Form("error reading %d bytes from RawReader %p", readSize-sizeof(AliRawDataHeader), pRawReader));
239 AliHLTComponentBlockData bd;
243 bd.fDataType = fDataType;
244 if (fSpecification == kAliHLTVoidDataSpec) {
245 GetSpecificationFromEquipmentId(id, bd.fSpecification);
247 bd.fSpecification=fSpecification;
249 outputBlocks.push_back( bd );
251 // we keep the loop going in order to collect the full size
252 fMaxSize=offset+readSize;
257 if (processedIds.size()!=size_t(fMaxEquId-fMinEquId+1)) {
258 // add further empty data blocks
259 AliRawDataHeader header;
260 header.fSize=sizeof(AliRawDataHeader);
262 list<int>::iterator curr=processedIds.begin();
263 for (int id=fMinEquId; id<=fMaxEquId; id++) {
264 if (curr!=processedIds.end() && *curr<=id) {
267 if (sizeof(AliRawDataHeader)<=size-offset) {
268 HLTInfo("add empty data block for equipment id %d", id);
269 memcpy(outputPtr+offset, &header, sizeof(AliRawDataHeader));
270 AliHLTComponentBlockData bd;
273 bd.fSize = sizeof(AliRawDataHeader);
274 bd.fDataType = fDataType;
275 if (fSpecification == kAliHLTVoidDataSpec) {
276 GetSpecificationFromEquipmentId(id, bd.fSpecification);
278 bd.fSpecification=fSpecification;
280 outputBlocks.push_back( bd );
282 // we keep the loop going in order to collect the full size
283 fMaxSize=offset+sizeof(AliRawDataHeader);
286 offset+=sizeof(AliRawDataHeader);
294 outputBlocks.clear();
297 AliErrorStream() << "RawReader uninitialized" << endl;
303 int AliHLTRawReaderPublisherComponent::GetSpecificationFromEquipmentId(int id, AliHLTUInt32_t& specification) const {
304 // see header file for class documentation
305 return specification=id;