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 /** global instance for agent registration */
38 AliHLTRawReaderPublisherComponent gAliHLTRawReaderPublisherComponent;
40 /** ROOT macro for the implementation of ROOT specific class methods */
41 ClassImp(AliHLTRawReaderPublisherComponent)
43 AliHLTRawReaderPublisherComponent::AliHLTRawReaderPublisherComponent()
50 fDataType(kAliHLTVoidDataType),
51 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()
76 void AliHLTRawReaderPublisherComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
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
211 AliHLTUInt8_t* pTgt=outputPtr;
212 assert(outputPtr!=NULL || size==0);
213 AliRawReader* pRawReader=GetRawReader();
216 pRawReader->SelectEquipment(-1, fMinEquId, fMaxEquId);
217 AliInfo(Form("get event from RawReader %p equipment id range [%d,%d]", pRawReader, fMinEquId, fMaxEquId));
218 while (pRawReader->ReadHeader() && (iResult>=0 || iResult==-ENOSPC)) {
219 const AliRawDataHeader* pHeader=pRawReader->GetDataHeader();
220 assert(pHeader!=NULL);
221 if (pHeader==NULL) continue;
222 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 if (readSize<=size-offset) {
230 memcpy(pTgt, pHeader, sizeof(AliRawDataHeader));
231 pTgt+=sizeof(AliRawDataHeader);
233 if (!pRawReader->ReadNext(pTgt, readSize-sizeof(AliRawDataHeader))) {
234 AliError(Form("error reading %d bytes from RawReader %p", readSize-sizeof(AliRawDataHeader), pRawReader));
238 pTgt+=readSize-sizeof(AliRawDataHeader);
241 // we keep the loop going in order to collect the full size
242 fMaxSize=offset+readSize;
246 AliHLTComponentBlockData bd;
250 bd.fDataType = fDataType;
251 if (fSpecification == kAliHLTVoidDataSpec) {
252 GetSpecificationFromEquipmentId(id, bd.fSpecification);
254 bd.fSpecification=fSpecification;
256 outputBlocks.push_back( bd );
260 if (offset<=size) size=offset;
262 AliErrorStream() << "RawReader uninitialized" << endl;
268 int AliHLTRawReaderPublisherComponent::GetSpecificationFromEquipmentId(int id, AliHLTUInt32_t& specification) const {
269 return specification=id;