]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/util/AliHLTRawReaderPublisherComponent.cxx
added RawReader offline source component
[u/mrichter/AliRoot.git] / HLT / BASE / util / AliHLTRawReaderPublisherComponent.cxx
CommitLineData
6666bfe5 1// @(#) $Id$
2
3/**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
6 * *
7 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 * for The ALICE HLT Project. *
9 * *
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 **************************************************************************/
18
19/** @file AliHLTRawReaderPublisherComponent.cxx
20 @author Matthias Richter
21 @date
22 @brief A general tree publisher component for the AliRawReader.
23*/
24
25// see header file for class documentation
26// or
27// refer to README to build package
28// or
29// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
30
31#include "AliHLTRawReaderPublisherComponent.h"
32#include "AliRawReader.h"
33#include "AliLog.h"
34#include <cerrno>
35#include <cassert>
36
37/** global instance for agent registration */
38AliHLTRawReaderPublisherComponent gAliHLTRawReaderPublisherComponent;
39
40/** ROOT macro for the implementation of ROOT specific class methods */
41ClassImp(AliHLTRawReaderPublisherComponent)
42
43AliHLTRawReaderPublisherComponent::AliHLTRawReaderPublisherComponent()
44 :
45 fMaxSize(50000),
46 fDetector(),
47 fMinEquId(-1),
48 fMaxEquId(-1),
49 fVerbose(kFALSE),
50 fDataType(kAliHLTAnyDataType),
51 fSpecification(0)
52{
53 // see header file for class documentation
54 // or
55 // refer to README to build package
56 // or
57 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
58}
59
60AliHLTRawReaderPublisherComponent::~AliHLTRawReaderPublisherComponent()
61{
62 // see header file for class documentation
63}
64
65const char* AliHLTRawReaderPublisherComponent::GetComponentID()
66{
67 // see header file for class documentation
68 return "AliRawReaderPublisher";
69}
70
71AliHLTComponentDataType AliHLTRawReaderPublisherComponent::GetOutputDataType()
72{
73 return fDataType;
74}
75
76void AliHLTRawReaderPublisherComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
77{
78 constBase=fMaxSize;
79 inputMultiplier=1;
80}
81
82AliHLTComponent* AliHLTRawReaderPublisherComponent::Spawn()
83{
84 // see header file for class documentation
85 return new AliHLTRawReaderPublisherComponent;
86}
87
88int AliHLTRawReaderPublisherComponent::DoInit( int argc, const char** argv )
89{
90 // see header file for class documentation
91 int iResult=0;
92
93 // scan arguments
94 TString argument="";
95 int bMissingParam=0;
96 for (int i=0; i<argc && iResult>=0; i++) {
97 argument=argv[i];
98 if (argument.IsNull()) continue;
99
100 // -detector
101 if (argument.CompareTo("-detector")==0) {
102 if ((bMissingParam=(++i>=argc))) break;
103 fDetector=argv[i];
104
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();
113 } else {
114 HLTError("wrong parameter for argument %s, number expected", argument.Data());
115 iResult=-EINVAL;
116 }
117
118 // -maxid
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();
125 } else {
126 HLTError("wrong parameter for argument %s, number expected", argument.Data());
127 iResult=-EINVAL;
128 }
129
130 // -verbose
131 } else if (argument.CompareTo("-verbose")==0) {
132 fVerbose=kTRUE;
133
134 // -datatype
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])));
140
141 // -dataspec
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);
151 } else {
152 HLTError("wrong parameter for argument %s, number expected", argument.Data());
153 iResult=-EINVAL;
154 }
155 } else {
156 HLTError("unknown argument %s", argument.Data());
157 iResult=-EINVAL;
158 }
159 }
160 if (bMissingParam) {
161 HLTError("missing parameter for argument %s", argument.Data());
162 iResult=-EINVAL;
163 }
164
165 if (iResult<0) return iResult;
166
167 if (fDetector.IsNull()) {
168 AliErrorStream() << "detector required, use \'-detector\' option" << endl;
169 return -EINVAL;
170 }
171
172 if (fMinEquId>fMaxEquId) fMaxEquId=fMinEquId;
173
174 if (fMinEquId<0) {
175 AliErrorStream() << "equipment id required, use \'-equipmentid\' option" << endl;
176 return -EINVAL;
177 }
178
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;
182 //return -EINVAL;
183 }
184
185 AliRawReader* pRawReader=GetRawReader();
186 if ((pRawReader=GetRawReader())!=NULL) {
187 pRawReader->Select(fDetector.Data(), fMinEquId, fMaxEquId);
188 if (!pRawReader->RewindEvents()) {
189 AliWarning(Form("can not rewind RawReader %p", pRawReader));
190 }
191 } else {
192 AliErrorStream() << "RawReader instance needed" << endl;
193 return -EINVAL;
194 }
195
196 return iResult;
197}
198
199int AliHLTRawReaderPublisherComponent::DoDeinit()
200{
201 // see header file for class documentation
202 int iResult=0;
203 return iResult;
204}
205
206int AliHLTRawReaderPublisherComponent::GetEvent(const AliHLTComponentEventData& evtData,
207 AliHLTComponentTriggerData& trigData,
208 AliHLTUInt8_t* outputPtr,
209 AliHLTUInt32_t& size,
210 vector<AliHLTComponentBlockData>& outputBlocks)
211{
212 // see header file for class documentation
213 int iResult=0;
214 int offset=0;
215 AliHLTUInt8_t* pTgt=outputPtr;
216 assert(outputPtr!=NULL);
217 AliRawReader* pRawReader=GetRawReader();
218 if (pRawReader) {
219 AliInfo(Form("get event from RawReader %p", pRawReader));
220 while (pRawReader->ReadHeader() && (iResult>=0 || iResult==-ENOSPC)) {
221 int readSize=pRawReader->GetDataSize();
222 int id=pRawReader->GetEquipmentId();
223 AliInfo(Form("got header for id %d, size %d", readSize, id));
224 if (fMinEquId<id || fMaxEquId>id) {
225 AliError(Form("id %d returned from RawReader is outside range [%d,%d]", id, fMinEquId, fMaxEquId));
226 continue;
227 }
228 if (readSize>0) {
229 if (readSize<=size-offset) {
230 if (!pRawReader->ReadNext(pTgt, readSize)) {
231 AliError(Form("error reading %d bytes from RawReader %p", readSize, pRawReader));
232 iResult=-ENODATA;
233 break;
234 }
235 } else {
236 fMaxSize=offset+readSize;
237 iResult=-ENOSPC;
238 }
239 }
240 if (iResult>=0) {
241 AliHLTComponentBlockData bd;
242 FillBlockData( bd );
243 bd.fOffset = offset;
244 bd.fSize = readSize;
245 bd.fDataType = fDataType;
246 bd.fSpecification = 0;
247 GetSpecificationFromEquipmentId(id, bd.fSpecification);
248 outputBlocks.push_back( bd );
249 }
250 offset+=readSize;
251 }
252 // go to next event, or beginning if last event was processed
253 if (pRawReader->NextEvent()) {
254 pRawReader->RewindEvents();
255 }
256 if (offset<=size) size=offset;
257 } else {
258 AliErrorStream() << "RawReader uninitialized" << endl;
259 iResult=-EFAULT;
260 }
261 return iResult;
262}
263
264int AliHLTRawReaderPublisherComponent::GetSpecificationFromEquipmentId(int id, AliHLTUInt32_t& /*specification*/) const {
265 return -ENOSYS;
266}