]>
Commit | Line | Data |
---|---|---|
81929b85 | 1 | // $Id$ |
2 | ||
a3c9b745 | 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 | //************************************************************************** | |
81929b85 | 18 | |
19 | /** @file AliHLTDataGenerator.cxx | |
20 | @author Matthias Richter | |
21 | @date | |
22 | @brief HLT file publisher component implementation. */ | |
23 | ||
3a7c0444 | 24 | // see header file for class documentation |
25 | // or | |
26 | // refer to README to build package | |
27 | // or | |
28 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
29 | ||
81929b85 | 30 | #if __GNUC__>= 3 |
31 | using namespace std; | |
32 | #endif | |
33 | ||
34 | #include "AliHLTDataGenerator.h" | |
35 | #include "TString.h" | |
36 | ||
81929b85 | 37 | /** ROOT macro for the implementation of ROOT specific class methods */ |
38 | ClassImp(AliHLTDataGenerator) | |
39 | ||
40 | AliHLTDataGenerator::AliHLTDataGenerator() | |
41 | : | |
a3c9b745 | 42 | AliHLTProcessor(), |
81929b85 | 43 | fDataType(kAliHLTVoidDataType), |
44 | fSpecification(~(AliHLTUInt32_t)0), | |
45 | fSize(0), | |
46 | fCurrSize(0), | |
81929b85 | 47 | fDivisor(0), |
a3c9b745 | 48 | fDecrement(0), |
49 | fModulo(0), | |
50 | fOffset(0), | |
51 | fMultiplier(0.0), | |
52 | fRange(0.0) | |
81929b85 | 53 | { |
54 | // see header file for class documentation | |
55 | // or | |
56 | // refer to README to build package | |
57 | // or | |
58 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
59 | ||
60 | // make the lists owners of their objects in order to automatically | |
61 | // de-allocate the objects | |
62 | } | |
63 | ||
64 | AliHLTDataGenerator::~AliHLTDataGenerator() | |
65 | { | |
66 | // see header file for class documentation | |
67 | ||
68 | } | |
69 | ||
70 | const char* AliHLTDataGenerator::GetComponentID() | |
71 | { | |
72 | // see header file for class documentation | |
73 | return "DataGenerator"; | |
74 | } | |
75 | ||
a3c9b745 | 76 | void AliHLTDataGenerator::GetInputDataTypes(AliHLTComponentDataTypeList& list) |
77 | { | |
78 | // see header file for class documentation | |
79 | list.clear(); | |
80 | list.push_back(kAliHLTAnyDataType); | |
81 | } | |
82 | ||
81929b85 | 83 | AliHLTComponentDataType AliHLTDataGenerator::GetOutputDataType() |
84 | { | |
85 | // see header file for class documentation | |
86 | return kAliHLTMultipleDataType; | |
87 | } | |
88 | ||
89 | int AliHLTDataGenerator::GetOutputDataTypes(vector<AliHLTComponentDataType>& tgtList) | |
90 | { | |
3a7c0444 | 91 | // see header file for class documentation |
81929b85 | 92 | int count=0; |
93 | tgtList.clear(); | |
94 | tgtList.push_back(fDataType); | |
95 | return count; | |
96 | } | |
97 | ||
98 | void AliHLTDataGenerator::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) | |
99 | { | |
100 | // see header file for class documentation | |
a3c9b745 | 101 | if (fSize>0) |
102 | constBase=(unsigned long)(fCurrSize*(1+fRange)); | |
103 | else | |
104 | constBase=(unsigned long)(fOffset*(1+fRange)); | |
105 | inputMultiplier=fMultiplier; | |
81929b85 | 106 | } |
107 | ||
108 | AliHLTComponent* AliHLTDataGenerator::Spawn() | |
109 | { | |
110 | // see header file for class documentation | |
111 | return new AliHLTDataGenerator; | |
112 | } | |
113 | ||
114 | int AliHLTDataGenerator::DoInit( int argc, const char** argv ) | |
115 | { | |
116 | // see header file for class documentation | |
117 | ||
118 | //HLTDebug("%d %s", argc, argv[0]); | |
119 | int iResult=0; | |
120 | TString argument=""; | |
121 | int bMissingParam=0; | |
122 | for (int i=0; i<argc && iResult>=0; i++) { | |
123 | argument=argv[i]; | |
124 | if (argument.IsNull()) continue; | |
125 | ||
126 | // -datatype | |
127 | if (argument.CompareTo("-datatype")==0) { | |
128 | if ((bMissingParam=(++i>=argc))) break; | |
129 | memcpy(&fDataType.fID, argv[i], TMath::Min(kAliHLTComponentDataTypefIDsize, (Int_t)strlen(argv[i]))); | |
130 | if ((bMissingParam=(++i>=argc))) break; | |
131 | memcpy(&fDataType.fOrigin, argv[i], TMath::Min(kAliHLTComponentDataTypefOriginSize, (Int_t)strlen(argv[i]))); | |
132 | ||
133 | // -dataspec | |
134 | } else if (argument.CompareTo("-dataspec")==0) { | |
135 | if ((bMissingParam=(++i>=argc))) break; | |
136 | TString parameter(argv[i]); | |
137 | parameter.Remove(TString::kLeading, ' '); // remove all blanks | |
138 | if (parameter.IsDigit()) { | |
139 | fSpecification=(AliHLTUInt32_t)parameter.Atoi(); | |
140 | } else if (parameter.BeginsWith("0x") && | |
141 | parameter.Replace(0,2,"",0).IsHex()) { | |
142 | sscanf(parameter.Data(),"%x", &fSpecification); | |
143 | } else { | |
144 | HLTError("wrong parameter for argument %s, number expected", argument.Data()); | |
145 | iResult=-EINVAL; | |
146 | } | |
147 | // -size | |
148 | } else if (argument.CompareTo("-size")==0) { | |
149 | if ((bMissingParam=(++i>=argc))) break; | |
150 | if ((iResult=ScanSizeArgument(fSize, argv[i]))==-ERANGE) { | |
151 | HLTError("wrong parameter for argument %s, number expected", argument.Data()); | |
152 | iResult=-EINVAL; | |
153 | } | |
154 | // -range | |
155 | } else if (argument.CompareTo("-range")==0) { | |
156 | if ((bMissingParam=(++i>=argc))) break; | |
a3c9b745 | 157 | if ((iResult=ScanFloatArgument(fRange, argv[i]))==-ERANGE) { |
81929b85 | 158 | HLTError("wrong parameter for argument %s, number expected", argument.Data()); |
159 | iResult=-EINVAL; | |
160 | } | |
161 | // -divisor | |
162 | } else if (argument.CompareTo("-divisor")==0) { | |
163 | if ((bMissingParam=(++i>=argc))) break; | |
164 | if ((iResult=ScanSizeArgument(fDivisor, argv[i]))==-ERANGE) { | |
165 | HLTError("wrong parameter for argument %s, number expected", argument.Data()); | |
166 | iResult=-EINVAL; | |
167 | } | |
a3c9b745 | 168 | // -decrement |
169 | } else if (argument.CompareTo("-decrement")==0) { | |
81929b85 | 170 | if ((bMissingParam=(++i>=argc))) break; |
a3c9b745 | 171 | if ((iResult=ScanSizeArgument(fDecrement, argv[i]))==-ERANGE) { |
81929b85 | 172 | HLTError("wrong parameter for argument %s, number expected", argument.Data()); |
173 | iResult=-EINVAL; | |
174 | } | |
175 | // -modulo | |
176 | } else if (argument.CompareTo("-modulo")==0) { | |
177 | if ((bMissingParam=(++i>=argc))) break; | |
178 | if ((iResult=ScanSizeArgument(fModulo, argv[i]))==-ERANGE) { | |
179 | HLTError("wrong parameter for argument %s, number expected", argument.Data()); | |
180 | iResult=-EINVAL; | |
181 | } | |
a3c9b745 | 182 | // -offset |
183 | } else if (argument.CompareTo("-offset")==0) { | |
184 | if ((bMissingParam=(++i>=argc))) break; | |
185 | if ((iResult=ScanSizeArgument(fOffset, argv[i]))==-ERANGE) { | |
186 | HLTError("wrong parameter for argument %s, number expected", argument.Data()); | |
187 | iResult=-EINVAL; | |
188 | } | |
189 | // -multiplier | |
190 | } else if (argument.CompareTo("-multiplier")==0) { | |
191 | if ((bMissingParam=(++i>=argc))) break; | |
192 | if ((iResult=ScanFloatArgument(fMultiplier, argv[i]))==-ERANGE) { | |
193 | HLTError("wrong parameter for argument %s, number expected", argument.Data()); | |
194 | iResult=-EINVAL; | |
195 | } | |
81929b85 | 196 | } else { |
197 | if ((iResult=ScanArgument(argc-i, &argv[i]))==-EINVAL) { | |
198 | HLTError("unknown argument %s", argument.Data()); | |
199 | break; | |
200 | } else if (iResult==-EPROTO) { | |
201 | bMissingParam=1; | |
202 | break; | |
203 | } else if (iResult>=0) { | |
204 | i+=iResult; | |
205 | iResult=0; | |
206 | } | |
207 | } | |
208 | } | |
209 | ||
210 | if (bMissingParam) { | |
211 | HLTError("missing parameter for argument %s", argument.Data()); | |
212 | iResult=-EINVAL; | |
213 | } | |
214 | ||
215 | fCurrSize=fSize; | |
216 | ||
217 | return iResult; | |
218 | } | |
219 | ||
220 | int AliHLTDataGenerator::ScanSizeArgument(AliHLTUInt32_t &size, const char* arg) | |
221 | { | |
3a7c0444 | 222 | // see header file for class documentation |
81929b85 | 223 | int iResult=0; |
224 | if (arg) { | |
225 | TString parameter(arg); | |
226 | AliHLTUInt32_t base=1; | |
227 | parameter.Remove(TString::kLeading, ' '); // remove all blanks | |
228 | if (parameter.EndsWith("k")) { | |
229 | base=0x400; // one k | |
230 | parameter.Remove(TString::kTrailing, 'k'); | |
231 | } else if (parameter.EndsWith("M")) { | |
232 | base=0x100000; // one M | |
233 | parameter.Remove(TString::kTrailing, 'M'); | |
234 | } | |
235 | if (parameter.IsDigit()) { | |
236 | size=(AliHLTUInt32_t)parameter.Atoi()*base; | |
237 | } else { | |
238 | iResult=-ERANGE; | |
239 | } | |
240 | } else { | |
241 | iResult=-EINVAL; | |
242 | } | |
243 | return iResult; | |
244 | } | |
245 | ||
a3c9b745 | 246 | int AliHLTDataGenerator::ScanFloatArgument(float &value, const char* arg) |
247 | { | |
248 | // see header file for class documentation | |
249 | int iResult=0; | |
250 | if (arg) { | |
251 | TString parameter(arg); | |
252 | parameter.Remove(TString::kLeading, ' '); // remove all blanks | |
253 | if (parameter.IsFloat()) { | |
254 | value=(AliHLTUInt32_t)parameter.Atof(); | |
255 | } else { | |
256 | iResult=-ERANGE; | |
257 | } | |
258 | } else { | |
259 | iResult=-EINVAL; | |
260 | } | |
261 | return iResult; | |
262 | } | |
263 | ||
81929b85 | 264 | int AliHLTDataGenerator::ScanArgument(int argc, const char** argv) |
265 | { | |
266 | // see header file for class documentation | |
267 | ||
268 | // there are no other arguments than the standard ones | |
269 | if (argc==0 && argv==NULL) { | |
270 | // this is just to get rid of the warning "unused parameter" | |
271 | } | |
272 | return -EPROTO; | |
273 | } | |
274 | ||
275 | int AliHLTDataGenerator::DoDeinit() | |
276 | { | |
277 | // see header file for class documentation | |
278 | int iResult=0; | |
279 | return iResult; | |
280 | } | |
281 | ||
a3c9b745 | 282 | int AliHLTDataGenerator::DoEvent( const AliHLTComponentEventData& evtData, |
283 | const AliHLTComponentBlockData* blocks, | |
284 | AliHLTComponentTriggerData& /*trigData*/, | |
285 | AliHLTUInt8_t* outputPtr, | |
286 | AliHLTUInt32_t& size, | |
287 | AliHLTComponentBlockDataList& outputBlocks ) | |
81929b85 | 288 | { |
3a7c0444 | 289 | // see header file for class documentation |
81929b85 | 290 | int iResult=0; |
81929b85 | 291 | |
a3c9b745 | 292 | AliHLTUInt32_t space=size; |
293 | size=0; | |
294 | AliHLTUInt32_t generated=0; | |
295 | if (fSize>0) { | |
296 | // mode 1: fake independent of input data size | |
297 | generated=fCurrSize; | |
81929b85 | 298 | if (fModulo>0 && ((GetEventCount()+1)%fModulo)==0) { |
299 | // manipulate the size | |
300 | if (fDivisor>0) { | |
301 | fCurrSize/=fDivisor; | |
302 | if (fCurrSize==0) fCurrSize=fSize; //reset | |
303 | } | |
a3c9b745 | 304 | if (fDecrement>0) { |
305 | if (fCurrSize<fDecrement) { | |
81929b85 | 306 | fCurrSize=fSize; // reset |
307 | } else { | |
a3c9b745 | 308 | fCurrSize-=fDecrement; |
81929b85 | 309 | } |
310 | } | |
311 | HLTDebug("manipulated output size: %d", fCurrSize); | |
312 | } | |
313 | ||
a3c9b745 | 314 | } else { |
315 | for (unsigned int i=0; i<evtData.fBlockCnt; i++) { | |
316 | generated+=blocks[i].fSize; | |
317 | } | |
318 | generated=(AliHLTUInt32_t)(generated*fMultiplier); | |
319 | generated+=fOffset; | |
320 | } | |
321 | ||
322 | if (generated<=space ) { | |
323 | AliHLTComponentBlockData bd; | |
324 | FillBlockData(bd); | |
325 | bd.fPtr=outputPtr; | |
326 | bd.fOffset=0; | |
327 | bd.fSize=generated; | |
328 | bd.fDataType=fDataType; | |
329 | bd.fSpecification=fSpecification; | |
330 | outputBlocks.push_back(bd); | |
331 | size=generated; | |
81929b85 | 332 | } else { |
333 | iResult=-ENOSPC; | |
334 | } | |
335 | ||
336 | return iResult; | |
337 | } |