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"
37 /** ROOT macro for the implementation of ROOT specific class methods */
38 ClassImp(AliHLTRawReaderPublisherComponent)
40 AliHLTRawReaderPublisherComponent::AliHLTRawReaderPublisherComponent()
47 fDataType(kAliHLTVoidDataType),
48 fSpecification(kAliHLTVoidDataSpec)
50 // see header file for class documentation
52 // refer to README to build package
54 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
57 AliHLTRawReaderPublisherComponent::~AliHLTRawReaderPublisherComponent()
59 // see header file for class documentation
62 const char* AliHLTRawReaderPublisherComponent::GetComponentID()
64 // see header file for class documentation
65 return "AliRawReaderPublisher";
68 AliHLTComponentDataType AliHLTRawReaderPublisherComponent::GetOutputDataType()
70 // see header file for class documentation
74 void AliHLTRawReaderPublisherComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
76 // see header file for class documentation
81 AliHLTComponent* AliHLTRawReaderPublisherComponent::Spawn()
83 // see header file for class documentation
84 return new AliHLTRawReaderPublisherComponent;
87 int AliHLTRawReaderPublisherComponent::DoInit( int argc, const char** argv )
89 // see header file for class documentation
95 for (int i=0; i<argc && iResult>=0; i++) {
97 if (argument.IsNull()) continue;
100 if (argument.CompareTo("-detector")==0) {
101 if ((bMissingParam=(++i>=argc))) break;
104 // -equipmentid, -minid
105 } else if (argument.CompareTo("-equipmentid")==0 ||
106 argument.CompareTo("-minid")==0) {
107 if ((bMissingParam=(++i>=argc))) break;
108 TString parameter(argv[i]);
109 parameter.Remove(TString::kLeading, ' '); // remove all blanks
110 if (parameter.IsDigit()) {
111 fMinEquId=(AliHLTUInt32_t)parameter.Atoi();
113 HLTError("wrong parameter for argument %s, number expected", argument.Data());
118 } else if (argument.CompareTo("-maxid")==0) {
119 if ((bMissingParam=(++i>=argc))) break;
120 TString parameter(argv[i]);
121 parameter.Remove(TString::kLeading, ' '); // remove all blanks
122 if (parameter.IsDigit()) {
123 fMaxEquId=(AliHLTUInt32_t)parameter.Atoi();
125 HLTError("wrong parameter for argument %s, number expected", argument.Data());
130 } else if (argument.CompareTo("-verbose")==0) {
134 } else if (argument.CompareTo("-datatype")==0) {
135 if ((bMissingParam=(++i>=argc))) break;
136 memcpy(&fDataType.fID, argv[i], TMath::Min(kAliHLTComponentDataTypefIDsize, (Int_t)strlen(argv[i])));
137 if ((bMissingParam=(++i>=argc))) break;
138 memcpy(&fDataType.fOrigin, argv[i], TMath::Min(kAliHLTComponentDataTypefOriginSize, (Int_t)strlen(argv[i])));
141 } else if (argument.CompareTo("-dataspec")==0) {
142 if ((bMissingParam=(++i>=argc))) break;
143 TString parameter(argv[i]);
144 parameter.Remove(TString::kLeading, ' '); // remove all blanks
145 if (parameter.IsDigit()) {
146 fSpecification=(AliHLTUInt32_t)parameter.Atoi();
147 } else if (parameter.BeginsWith("0x") &&
148 parameter.Replace(0,2,"",0).IsHex()) {
149 sscanf(parameter.Data(),"%x", &fSpecification);
151 HLTError("wrong parameter for argument %s, number expected", argument.Data());
155 HLTError("unknown argument %s", argument.Data());
160 HLTError("missing parameter for argument %s", argument.Data());
164 if (iResult<0) return iResult;
166 if (fMinEquId>fMaxEquId) fMaxEquId=fMinEquId;
169 AliErrorStream() << "equipment id required, use \'-equipmentid\' option" << endl;
173 if (!fDetector.IsNull()) {
174 AliErrorStream() << "option \'-detector\' not implemented" << endl;
178 AliHLTUInt32_t dummy;
179 if (fMinEquId!=fMaxEquId && GetSpecificationFromEquipmentId(0, dummy)==-ENOSYS) {
180 AliWarningStream() << "publication of multiple equipment ids needs implementation of a child and function GetSpecificationFromEquipmentId to set correct specifications" << endl;
184 AliRawReader* pRawReader=GetRawReader();
185 if ((pRawReader=GetRawReader())!=NULL) {
187 AliErrorStream() << "RawReader instance needed" << endl;
194 int AliHLTRawReaderPublisherComponent::DoDeinit()
196 // see header file for class documentation
201 int AliHLTRawReaderPublisherComponent::GetEvent(const AliHLTComponentEventData& evtData,
202 AliHLTComponentTriggerData& trigData,
203 AliHLTUInt8_t* outputPtr,
204 AliHLTUInt32_t& size,
205 vector<AliHLTComponentBlockData>& outputBlocks)
207 // see header file for class documentation
210 AliHLTUInt8_t* pTgt=outputPtr;
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 while (pRawReader->ReadHeader() && (iResult>=0 || iResult==-ENOSPC)) {
218 const AliRawDataHeader* pHeader=pRawReader->GetDataHeader();
219 assert(pHeader!=NULL);
220 if (pHeader==NULL) continue;
221 int readSize=pRawReader->GetDataSize()+sizeof(AliRawDataHeader);
222 int id=pRawReader->GetEquipmentId();
223 AliInfo(Form("got header for id %d, size %d", id, readSize));
224 if (fMinEquId>id || fMaxEquId<id) {
225 AliError(Form("id %d returned from RawReader is outside range [%d,%d]", id, fMinEquId, fMaxEquId));
228 if (readSize<=size-offset) {
229 memcpy(pTgt, pHeader, sizeof(AliRawDataHeader));
230 pTgt+=sizeof(AliRawDataHeader);
232 if (!pRawReader->ReadNext(pTgt, readSize-sizeof(AliRawDataHeader))) {
233 AliError(Form("error reading %d bytes from RawReader %p", readSize-sizeof(AliRawDataHeader), pRawReader));
237 pTgt+=readSize-sizeof(AliRawDataHeader);
240 // we keep the loop going in order to collect the full size
241 fMaxSize=offset+readSize;
245 AliHLTComponentBlockData bd;
249 bd.fDataType = fDataType;
250 if (fSpecification == kAliHLTVoidDataSpec) {
251 GetSpecificationFromEquipmentId(id, bd.fSpecification);
253 bd.fSpecification=fSpecification;
255 outputBlocks.push_back( bd );
259 if (offset<=size) size=offset;
261 AliErrorStream() << "RawReader uninitialized" << endl;
267 int AliHLTRawReaderPublisherComponent::GetSpecificationFromEquipmentId(int id, AliHLTUInt32_t& specification) const {
268 // see header file for class documentation
269 return specification=id;