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),
52 // see header file for class documentation
54 // refer to README to build package
56 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
59 AliHLTRawReaderPublisherComponent::~AliHLTRawReaderPublisherComponent()
61 // see header file for class documentation
64 const char* AliHLTRawReaderPublisherComponent::GetComponentID()
66 // see header file for class documentation
67 return "AliRawReaderPublisher";
70 AliHLTComponentDataType AliHLTRawReaderPublisherComponent::GetOutputDataType()
72 // see header file for class documentation
76 void AliHLTRawReaderPublisherComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
78 // see header file for class documentation
83 AliHLTComponent* AliHLTRawReaderPublisherComponent::Spawn()
85 // see header file for class documentation
86 return new AliHLTRawReaderPublisherComponent;
89 int AliHLTRawReaderPublisherComponent::DoInit( int argc, const char** argv )
91 // see header file for class documentation
97 for (int i=0; i<argc && iResult>=0; i++) {
99 if (argument.IsNull()) continue;
102 if (argument.CompareTo("-detector")==0) {
103 if ((bMissingParam=(++i>=argc))) break;
106 // -equipmentid, -minid
107 } else if (argument.CompareTo("-equipmentid")==0 ||
108 argument.CompareTo("-minid")==0) {
109 if ((bMissingParam=(++i>=argc))) break;
110 TString parameter(argv[i]);
111 parameter.Remove(TString::kLeading, ' '); // remove all blanks
112 if (parameter.IsDigit()) {
113 fMinEquId=(AliHLTUInt32_t)parameter.Atoi();
115 HLTError("wrong parameter for argument %s, number expected", argument.Data());
120 } else if (argument.CompareTo("-maxid")==0) {
121 if ((bMissingParam=(++i>=argc))) break;
122 TString parameter(argv[i]);
123 parameter.Remove(TString::kLeading, ' '); // remove all blanks
124 if (parameter.IsDigit()) {
125 fMaxEquId=(AliHLTUInt32_t)parameter.Atoi();
127 HLTError("wrong parameter for argument %s, number expected", argument.Data());
132 } else if (argument.CompareTo("-verbose")==0) {
136 } else if (argument.CompareTo("-skipempty")==0) {
140 } else if (argument.CompareTo("-datatype")==0) {
141 if ((bMissingParam=(++i>=argc))) break;
142 memcpy(&fDataType.fID, argv[i], TMath::Min(kAliHLTComponentDataTypefIDsize, (Int_t)strlen(argv[i])));
143 if ((bMissingParam=(++i>=argc))) break;
144 memcpy(&fDataType.fOrigin, argv[i], TMath::Min(kAliHLTComponentDataTypefOriginSize, (Int_t)strlen(argv[i])));
147 } else if (argument.CompareTo("-dataspec")==0) {
148 if ((bMissingParam=(++i>=argc))) break;
149 TString parameter(argv[i]);
150 parameter.Remove(TString::kLeading, ' '); // remove all blanks
151 if (parameter.IsDigit()) {
152 fSpecification=(AliHLTUInt32_t)parameter.Atoi();
153 } else if (parameter.BeginsWith("0x") &&
154 parameter.Replace(0,2,"",0).IsHex()) {
155 sscanf(parameter.Data(),"%x", &fSpecification);
157 HLTError("wrong parameter for argument %s, number expected", argument.Data());
161 HLTError("unknown argument %s", argument.Data());
166 HLTError("missing parameter for argument %s", argument.Data());
170 if (iResult<0) return iResult;
172 if (fMinEquId>fMaxEquId) fMaxEquId=fMinEquId;
175 AliErrorStream() << "equipment id required, use \'-equipmentid\' option" << endl;
179 if (!fDetector.IsNull()) {
180 AliErrorStream() << "option \'-detector\' not implemented" << endl;
184 AliHLTUInt32_t dummy;
185 if (fMinEquId!=fMaxEquId && GetSpecificationFromEquipmentId(0, dummy)==-ENOSYS) {
186 AliWarningStream() << "publication of multiple equipment ids needs implementation of a child and function GetSpecificationFromEquipmentId to set correct specifications" << endl;
190 AliRawReader* pRawReader=GetRawReader();
191 if ((pRawReader=GetRawReader())!=NULL) {
193 AliErrorStream() << "RawReader instance needed" << endl;
200 int AliHLTRawReaderPublisherComponent::DoDeinit()
202 // see header file for class documentation
207 int AliHLTRawReaderPublisherComponent::GetEvent(const AliHLTComponentEventData& /*evtData*/,
208 AliHLTComponentTriggerData& /*trigData*/,
209 AliHLTUInt8_t* outputPtr,
210 AliHLTUInt32_t& size,
211 vector<AliHLTComponentBlockData>& outputBlocks)
213 // see header file for class documentation
215 unsigned int offset=0;
216 assert(outputPtr!=NULL || size==0);
217 AliRawReader* pRawReader=GetRawReader();
220 pRawReader->SelectEquipment(-1, fMinEquId, fMaxEquId);
222 AliInfo(Form("get event from RawReader %p equipment id range [%d,%d]", pRawReader, fMinEquId, fMaxEquId));
224 AliDebug(0, Form("get event from RawReader %p equipment id range [%d,%d]", pRawReader, fMinEquId, fMaxEquId));
226 list<int> processedIds;
227 while (pRawReader->ReadHeader() && (iResult>=0 || iResult==-ENOSPC)) {
228 const AliRawDataHeader* pHeader=pRawReader->GetDataHeader();
229 assert(pHeader!=NULL);
230 if (pHeader==NULL) continue;
231 unsigned int readSize=pRawReader->GetDataSize()+sizeof(AliRawDataHeader);
232 int id=pRawReader->GetEquipmentId();
233 AliInfo(Form("got header for id %d, size %d", id, readSize));
234 if (fMinEquId>id || fMaxEquId<id) {
235 AliError(Form("id %d returned from RawReader is outside range [%d,%d]", id, fMinEquId, fMaxEquId));
238 processedIds.push_back(id);
239 if (readSize<=size-offset) {
240 memcpy(outputPtr+offset, pHeader, sizeof(AliRawDataHeader));
241 if (readSize>sizeof(AliRawDataHeader)) {
242 if (!pRawReader->ReadNext(outputPtr+offset+sizeof(AliRawDataHeader), readSize-sizeof(AliRawDataHeader))) {
243 AliError(Form("error reading %d bytes from RawReader %p", readSize-sizeof(AliRawDataHeader), pRawReader));
248 AliHLTComponentBlockData bd;
252 bd.fDataType = fDataType;
253 if (fSpecification == kAliHLTVoidDataSpec) {
254 GetSpecificationFromEquipmentId(id, bd.fSpecification);
256 bd.fSpecification=fSpecification;
258 outputBlocks.push_back( bd );
260 // we keep the loop going in order to collect the full size
261 fMaxSize=offset+readSize;
266 if (!fSkipEmpty && processedIds.size()!=size_t(fMaxEquId-fMinEquId+1)) {
267 // add further empty data blocks
268 AliRawDataHeader header;
269 header.fSize=sizeof(AliRawDataHeader);
271 list<int>::iterator curr=processedIds.begin();
272 for (int id=fMinEquId; id<=fMaxEquId; id++) {
273 if (curr!=processedIds.end() && *curr<=id) {
276 if (sizeof(AliRawDataHeader)<=size-offset) {
277 HLTInfo("add empty data block for equipment id %d", id);
278 memcpy(outputPtr+offset, &header, sizeof(AliRawDataHeader));
279 AliHLTComponentBlockData bd;
282 bd.fSize = sizeof(AliRawDataHeader);
283 bd.fDataType = fDataType;
284 if (fSpecification == kAliHLTVoidDataSpec) {
285 GetSpecificationFromEquipmentId(id, bd.fSpecification);
287 bd.fSpecification=fSpecification;
289 outputBlocks.push_back( bd );
291 // we keep the loop going in order to collect the full size
292 fMaxSize=offset+sizeof(AliRawDataHeader);
295 offset+=sizeof(AliRawDataHeader);
303 outputBlocks.clear();
306 AliErrorStream() << "RawReader uninitialized" << endl;
312 int AliHLTRawReaderPublisherComponent::GetSpecificationFromEquipmentId(int id, AliHLTUInt32_t& specification) const {
313 // see header file for class documentation
314 return specification=id;