]>
Commit | Line | Data |
---|---|---|
f23a6e1a | 1 | // $Id$ |
2 | ||
3dd8541e | 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 | //* Timm Steinbeck <timm@kip.uni-heidelberg.de> * | |
9 | //* for The ALICE HLT Project. * | |
10 | //* * | |
11 | //* Permission to use, copy, modify and distribute this software and its * | |
12 | //* documentation strictly for non-commercial purposes is hereby granted * | |
13 | //* without fee, provided that the above copyright notice appears in all * | |
14 | //* copies and that both the copyright notice and this permission notice * | |
15 | //* appear in the supporting documentation. The authors make no claims * | |
16 | //* about the suitability of this software for any purpose. It is * | |
17 | //* provided "as is" without express or implied warranty. * | |
18 | //************************************************************************** | |
f23a6e1a | 19 | |
bfccbf68 | 20 | /** @file AliHLTComponent.cxx |
21 | @author Matthias Richter, Timm Steinbeck | |
22 | @date | |
23 | @brief Base class implementation for HLT components. */ | |
f23a6e1a | 24 | |
0c0c9d99 | 25 | #if __GNUC__>= 3 |
f23a6e1a | 26 | using namespace std; |
27 | #endif | |
28 | ||
66043029 | 29 | //#include "AliHLTStdIncludes.h" |
f23a6e1a | 30 | #include "AliHLTComponent.h" |
31 | #include "AliHLTComponentHandler.h" | |
a655eae3 | 32 | #include "AliHLTMessage.h" |
70ed7d01 | 33 | #include "TString.h" |
ed504011 | 34 | #include "TMath.h" |
a655eae3 | 35 | #include "TObjArray.h" |
79c114b5 | 36 | #include "TObjectTable.h" |
a655eae3 | 37 | #include "TClass.h" |
90ebac25 | 38 | #include "TStopwatch.h" |
79c114b5 | 39 | #include "AliHLTMemoryFile.h" |
579d9eb7 | 40 | #include "AliHLTMisc.h" |
ec25e4ca | 41 | #include <cassert> |
f23a6e1a | 42 | |
b22e91eb | 43 | /** ROOT macro for the implementation of ROOT specific class methods */ |
90ebac25 | 44 | ClassImp(AliHLTComponent); |
45 | ||
46 | /** stopwatch macro using the stopwatch guard */ | |
47 | #define ALIHLTCOMPONENT_STOPWATCH(type) AliHLTStopwatchGuard swguard(fpStopwatches!=NULL?reinterpret_cast<TStopwatch*>(fpStopwatches->At((int)type)):NULL) | |
48 | //#define ALIHLTCOMPONENT_STOPWATCH(type) | |
49 | ||
50 | /** stopwatch macro for operations of the base class */ | |
51 | #define ALIHLTCOMPONENT_BASE_STOPWATCH() ALIHLTCOMPONENT_STOPWATCH(kSWBase) | |
52 | /** stopwatch macro for operations of the detector algorithm (DA) */ | |
53 | #define ALIHLTCOMPONENT_DA_STOPWATCH() ALIHLTCOMPONENT_STOPWATCH(kSWDA) | |
f23a6e1a | 54 | |
f23a6e1a | 55 | AliHLTComponent::AliHLTComponent() |
85869391 | 56 | : |
53feaef5 | 57 | fEnvironment(), |
3cde846d | 58 | fCurrentEvent(0), |
a655eae3 | 59 | fEventCount(-1), |
60 | fFailedEvents(0), | |
61 | fCurrentEventData(), | |
62 | fpInputBlocks(NULL), | |
63 | fCurrentInputBlock(-1), | |
64 | fSearchDataType(kAliHLTVoidDataType), | |
65 | fClassName(), | |
66 | fpInputObjects(NULL), | |
67 | fpOutputBuffer(NULL), | |
68 | fOutputBufferSize(0), | |
69 | fOutputBufferFilled(0), | |
90ebac25 | 70 | fOutputBlocks(), |
79c114b5 | 71 | fpStopwatches(new TObjArray(kSWTypeCount)), |
559631d5 | 72 | fMemFiles(), |
73 | fpRunDesc(NULL), | |
579d9eb7 | 74 | fpDDLList(NULL), |
82c58a87 | 75 | fCDBSetRunNoFunc(false), |
a0aeb701 | 76 | fChainId(), |
77 | fpBenchmark(NULL), | |
78 | fRequireSteeringBlocks(false) | |
70ed7d01 | 79 | { |
80 | // see header file for class documentation | |
81 | // or | |
82 | // refer to README to build package | |
83 | // or | |
84 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
f23a6e1a | 85 | memset(&fEnvironment, 0, sizeof(AliHLTComponentEnvironment)); |
70ed7d01 | 86 | if (fgpComponentHandler) |
87 | fgpComponentHandler->ScheduleRegister(this); | |
7c781d33 | 88 | //SetLocalLoggingLevel(kHLTLogDefault); |
70ed7d01 | 89 | } |
90 | ||
f23a6e1a | 91 | AliHLTComponent::~AliHLTComponent() |
92 | { | |
70ed7d01 | 93 | // see header file for function documentation |
a0aeb701 | 94 | if (fpBenchmark) delete fpBenchmark; |
95 | fpBenchmark=NULL; | |
96 | ||
8451168b | 97 | CleanupInputObjects(); |
4498d7d1 | 98 | if (fpStopwatches!=NULL) delete fpStopwatches; |
99 | fpStopwatches=NULL; | |
2be3f004 | 100 | AliHLTMemoryFilePList::iterator element=fMemFiles.begin(); |
79c114b5 | 101 | while (element!=fMemFiles.end()) { |
102 | if (*element) { | |
103 | if ((*element)->IsClosed()==0) { | |
104 | HLTWarning("memory file has not been closed, possible data loss or incomplete buffer"); | |
105 | // close but do not flush as we dont know whether the buffer is still valid | |
29312178 | 106 | (*element)->CloseMemoryFile(0); |
79c114b5 | 107 | } |
108 | delete *element; | |
109 | *element=NULL; | |
110 | } | |
111 | element++; | |
112 | } | |
45c0a780 | 113 | if (fpRunDesc) { |
114 | delete fpRunDesc; | |
115 | fpRunDesc=NULL; | |
116 | } | |
f23a6e1a | 117 | } |
118 | ||
70ed7d01 | 119 | AliHLTComponentHandler* AliHLTComponent::fgpComponentHandler=NULL; |
b22e91eb | 120 | |
85869391 | 121 | int AliHLTComponent::SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite) |
122 | { | |
70ed7d01 | 123 | // see header file for function documentation |
85869391 | 124 | int iResult=0; |
70ed7d01 | 125 | if (fgpComponentHandler==NULL || bOverwrite!=0) |
126 | fgpComponentHandler=pCH; | |
85869391 | 127 | else |
128 | iResult=-EPERM; | |
129 | return iResult; | |
130 | } | |
131 | ||
70ed7d01 | 132 | int AliHLTComponent::UnsetGlobalComponentHandler() |
133 | { | |
134 | // see header file for function documentation | |
85869391 | 135 | return SetGlobalComponentHandler(NULL,1); |
136 | } | |
137 | ||
9a0ef890 | 138 | int AliHLTComponent::Init(const AliHLTComponentEnvironment* comenv, void* environParam, int argc, const char** argv ) |
f23a6e1a | 139 | { |
70ed7d01 | 140 | // see header file for function documentation |
b2065764 | 141 | HLTLogKeyword(GetComponentID()); |
f23a6e1a | 142 | int iResult=0; |
f7561f8d | 143 | if (comenv) { |
144 | memcpy(&fEnvironment, comenv, sizeof(AliHLTComponentEnvironment)); | |
70ed7d01 | 145 | fEnvironment.fParam=environParam; |
f23a6e1a | 146 | } |
8451168b | 147 | const char** pArguments=NULL; |
148 | int iNofChildArgs=0; | |
149 | TString argument=""; | |
150 | int bMissingParam=0; | |
151 | if (argc>0) { | |
152 | pArguments=new const char*[argc]; | |
153 | if (pArguments) { | |
154 | for (int i=0; i<argc && iResult>=0; i++) { | |
155 | argument=argv[i]; | |
156 | if (argument.IsNull()) continue; | |
157 | ||
158 | // benchmark | |
159 | if (argument.CompareTo("benchmark")==0) { | |
160 | ||
161 | // loglevel | |
162 | } else if (argument.CompareTo("loglevel")==0) { | |
163 | if ((bMissingParam=(++i>=argc))) break; | |
164 | TString parameter(argv[i]); | |
165 | parameter.Remove(TString::kLeading, ' '); // remove all blanks | |
166 | if (parameter.BeginsWith("0x") && | |
167 | parameter.Replace(0,2,"",0).IsHex()) { | |
168 | AliHLTComponentLogSeverity loglevel=kHLTLogNone; | |
7a5ccd96 | 169 | sscanf(parameter.Data(),"%x", (unsigned int*)&loglevel); |
8451168b | 170 | SetLocalLoggingLevel(loglevel); |
171 | } else { | |
172 | HLTError("wrong parameter for argument %s, hex number expected", argument.Data()); | |
173 | iResult=-EINVAL; | |
174 | } | |
175 | } else { | |
176 | pArguments[iNofChildArgs++]=argv[i]; | |
177 | } | |
178 | } | |
179 | } else { | |
180 | iResult=-ENOMEM; | |
181 | } | |
182 | } | |
183 | if (bMissingParam) { | |
184 | HLTError("missing parameter for argument %s", argument.Data()); | |
185 | iResult=-EINVAL; | |
186 | } | |
187 | if (iResult>=0) { | |
188 | iResult=DoInit(iNofChildArgs, pArguments); | |
189 | } | |
a0aeb701 | 190 | if (iResult>=0) { |
191 | fEventCount=0; | |
192 | ||
193 | // find out if the component wants to get the steering events | |
194 | // explicitly | |
195 | AliHLTComponentDataTypeList inputDt; | |
196 | GetInputDataTypes(inputDt); | |
197 | for (AliHLTComponentDataTypeList::iterator dt=inputDt.begin(); | |
198 | dt!=inputDt.end() && !fRequireSteeringBlocks; | |
199 | dt++) { | |
200 | fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeSOR); | |
201 | fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeRunType); | |
202 | fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeEOR); | |
203 | fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeDDL); | |
204 | fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeComponentStatistics); | |
205 | } | |
206 | } | |
8451168b | 207 | if (pArguments) delete [] pArguments; |
a0aeb701 | 208 | |
209 | #if defined(__DEBUG) || defined(HLT_COMPONENT_STATISTICS) | |
210 | // benchmarking stopwatch for the component statistics | |
211 | fpBenchmark=new TStopwatch; | |
212 | if (fpBenchmark) { | |
213 | fpBenchmark->Start(); | |
214 | } | |
215 | #endif | |
216 | ||
f23a6e1a | 217 | return iResult; |
218 | } | |
219 | ||
220 | int AliHLTComponent::Deinit() | |
221 | { | |
70ed7d01 | 222 | // see header file for function documentation |
b2065764 | 223 | HLTLogKeyword(GetComponentID()); |
f23a6e1a | 224 | int iResult=0; |
225 | iResult=DoDeinit(); | |
559631d5 | 226 | if (fpRunDesc) { |
227 | HLTWarning("did not receive EOR for run %d", fpRunDesc->fRunNo); | |
228 | AliHLTRunDesc* pRunDesc=fpRunDesc; | |
229 | fpRunDesc=NULL; | |
230 | delete pRunDesc; | |
231 | } | |
579d9eb7 | 232 | fEventCount=0; |
f23a6e1a | 233 | return iResult; |
234 | } | |
fa2e9b7c | 235 | |
82c58a87 | 236 | int AliHLTComponent::InitCDB(const char* cdbPath, AliHLTComponentHandler* pHandler) |
53feaef5 | 237 | { |
82c58a87 | 238 | // see header file for function documentation |
579d9eb7 | 239 | int iResult=0; |
703bcca6 | 240 | if (pHandler) { |
82c58a87 | 241 | // I have to think about separating the library handling from the |
242 | // component handler. Requiring the component hanlder here is not | |
243 | // the cleanest solution. | |
244 | // We presume the library already to be loaded | |
579d9eb7 | 245 | // find the symbol |
82c58a87 | 246 | AliHLTMiscInitCDB_t pFunc=(AliHLTMiscInitCDB_t)pHandler->FindSymbol(ALIHLTMISC_LIBRARY, ALIHLTMISC_INIT_CDB); |
579d9eb7 | 247 | if (pFunc) { |
703bcca6 | 248 | TString path; |
249 | if (cdbPath && cdbPath[0]!=0) { | |
250 | path=cdbPath; | |
251 | // very temporary fix, have to check for other formats | |
252 | if (!path.BeginsWith("local://")) { | |
253 | path="local://"; | |
254 | path+=cdbPath; | |
255 | } | |
8f30c1ea | 256 | } |
257 | if ((iResult=(*pFunc)(path.Data()))>=0) { | |
82c58a87 | 258 | if (!(fCDBSetRunNoFunc=pHandler->FindSymbol(ALIHLTMISC_LIBRARY, ALIHLTMISC_SET_CDB_RUNNO))) { |
259 | Message(NULL, kHLTLogWarning, "AliHLTComponent::InitCDB", "init CDB", | |
260 | "can not find function to set CDB run no"); | |
261 | } | |
262 | } | |
579d9eb7 | 263 | } else { |
264 | Message(NULL, kHLTLogError, "AliHLTComponent::InitCDB", "init CDB", | |
265 | "can not find initialization function"); | |
266 | iResult=-ENOSYS; | |
53feaef5 | 267 | } |
82c58a87 | 268 | } else { |
269 | iResult=-EINVAL; | |
270 | } | |
579d9eb7 | 271 | return iResult; |
272 | } | |
273 | ||
274 | int AliHLTComponent::SetCDBRunNo(int runNo) | |
275 | { | |
82c58a87 | 276 | // see header file for function documentation |
277 | if (!fCDBSetRunNoFunc) return 0; | |
278 | return (*((AliHLTMiscSetCDBRunNo_t)fCDBSetRunNoFunc))(runNo); | |
579d9eb7 | 279 | } |
280 | ||
45c0a780 | 281 | int AliHLTComponent::SetRunDescription(const AliHLTRunDesc* desc, const char* /*runType*/) |
282 | { | |
283 | // see header file for function documentation | |
284 | if (!desc) return -EINVAL; | |
285 | if (desc->fStructSize!=sizeof(AliHLTRunDesc)) { | |
286 | HLTError("invalid size of RunDesc struct (%ul)", desc->fStructSize); | |
287 | return -EINVAL; | |
288 | } | |
289 | ||
290 | if (!fpRunDesc) { | |
291 | fpRunDesc=new AliHLTRunDesc; | |
292 | if (!fpRunDesc) return -ENOMEM; | |
293 | *fpRunDesc=kAliHLTVoidRunDesc; | |
294 | } | |
295 | ||
296 | if (fpRunDesc->fRunNo!=kAliHLTVoidRunNo && fpRunDesc->fRunNo!=desc->fRunNo) { | |
297 | HLTWarning("Run description has already been set"); | |
298 | } | |
299 | *fpRunDesc=*desc; | |
300 | SetCDBRunNo(fpRunDesc->fRunNo); | |
301 | // TODO: we have to decide about the runType | |
302 | return 0; | |
303 | } | |
304 | ||
9a0ef890 | 305 | int AliHLTComponent::SetComponentDescription(const char* desc) |
306 | { | |
307 | // default implementation, childs can overload | |
308 | int iResult=0; | |
309 | if (!desc) return 0; | |
310 | ||
311 | TString descriptor=desc; | |
312 | TObjArray* pTokens=descriptor.Tokenize(" "); | |
313 | if (pTokens) { | |
314 | for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) { | |
315 | TString argument=((TObjString*)pTokens->At(i++))->GetString(); | |
316 | if (!argument || argument.IsNull()) continue; | |
317 | ||
318 | // -chainid | |
319 | if (argument.BeginsWith("-chainid")) { | |
320 | argument.ReplaceAll("-chainid", ""); | |
321 | if (argument.BeginsWith("=")) { | |
322 | fChainId=argument.Replace(0,1,""); | |
323 | } else { | |
324 | fChainId=""; | |
325 | } | |
326 | } else { | |
327 | HLTWarning("unknown argument %s", argument.Data()); | |
328 | } | |
329 | } | |
330 | } | |
331 | ||
332 | return iResult; | |
333 | } | |
334 | ||
579d9eb7 | 335 | int AliHLTComponent::DoInit( int /*argc*/, const char** /*argv*/) |
336 | { | |
337 | // default implementation, childs can overload | |
b543e186 | 338 | HLTLogKeyword("dummy"); |
53feaef5 | 339 | return 0; |
340 | } | |
341 | ||
342 | int AliHLTComponent::DoDeinit() | |
343 | { | |
579d9eb7 | 344 | // default implementation, childs can overload |
b543e186 | 345 | HLTLogKeyword("dummy"); |
579d9eb7 | 346 | return 0; |
347 | } | |
348 | ||
349 | int AliHLTComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/) | |
350 | { | |
351 | // default implementation, childs can overload | |
b543e186 | 352 | HLTLogKeyword("dummy"); |
353 | return 0; | |
354 | } | |
355 | ||
356 | int AliHLTComponent::ReadPreprocessorValues(const char* /*modules*/) | |
357 | { | |
358 | // default implementation, childs can overload | |
359 | HLTLogKeyword("dummy"); | |
53feaef5 | 360 | return 0; |
361 | } | |
362 | ||
45c0a780 | 363 | int AliHLTComponent::StartOfRun() |
364 | { | |
365 | // default implementation, childs can overload | |
366 | HLTLogKeyword("dummy"); | |
367 | return 0; | |
368 | } | |
369 | ||
370 | int AliHLTComponent::EndOfRun() | |
371 | { | |
372 | // default implementation, childs can overload | |
373 | HLTLogKeyword("dummy"); | |
374 | return 0; | |
375 | } | |
376 | ||
377 | ||
2be3f004 | 378 | int AliHLTComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& /*tgtList*/) |
de6593d0 | 379 | { |
82c58a87 | 380 | // default implementation, childs can overload |
3a7c0444 | 381 | HLTLogKeyword("dummy"); |
de6593d0 | 382 | return 0; |
383 | } | |
384 | ||
70ed7d01 | 385 | void AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2] ) const |
386 | { | |
387 | // see header file for function documentation | |
9ce4bf4a | 388 | memset( output, 0, kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2 ); |
389 | strncat( output, type.fOrigin, kAliHLTComponentDataTypefOriginSize ); | |
390 | strcat( output, ":" ); | |
391 | strncat( output, type.fID, kAliHLTComponentDataTypefIDsize ); | |
fa2e9b7c | 392 | } |
393 | ||
fbdb63fd | 394 | string AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, int mode) |
9ce4bf4a | 395 | { |
70ed7d01 | 396 | // see header file for function documentation |
9ce4bf4a | 397 | string out(""); |
fbdb63fd | 398 | |
399 | if (mode==2) { | |
400 | int i=0; | |
401 | char tmp[8]; | |
402 | for (i=0; i<kAliHLTComponentDataTypefOriginSize; i++) { | |
403 | sprintf(tmp, "'%d", type.fOrigin[i]); | |
404 | out+=tmp; | |
405 | } | |
406 | out+="':'"; | |
407 | for (i=0; i<kAliHLTComponentDataTypefIDsize; i++) { | |
408 | sprintf(tmp, "%d'", type.fID[i]); | |
409 | out+=tmp; | |
410 | } | |
411 | return out; | |
412 | } | |
413 | ||
414 | if (mode==1) { | |
415 | int i=0; | |
416 | char tmp[8]; | |
417 | for (i=0; i<kAliHLTComponentDataTypefOriginSize; i++) { | |
418 | unsigned char* puc=(unsigned char*)type.fOrigin; | |
419 | if ((puc[i])<32) | |
420 | sprintf(tmp, "'\\%x", type.fOrigin[i]); | |
421 | else | |
422 | sprintf(tmp, "'%c", type.fOrigin[i]); | |
423 | out+=tmp; | |
424 | } | |
425 | out+="':'"; | |
426 | for (i=0; i<kAliHLTComponentDataTypefIDsize; i++) { | |
427 | unsigned char* puc=(unsigned char*)type.fID; | |
428 | if (puc[i]<32) | |
429 | sprintf(tmp, "\\%x'", type.fID[i]); | |
430 | else | |
431 | sprintf(tmp, "%c'", type.fID[i]); | |
432 | out+=tmp; | |
433 | } | |
434 | return out; | |
435 | } | |
436 | ||
9ce4bf4a | 437 | if (type==kAliHLTVoidDataType) { |
438 | out="VOID:VOID"; | |
439 | } else { | |
3cde846d | 440 | // some gymnastics in order to avoid a '0' which is part of either or both |
441 | // ID and origin terminating the whole string. Unfortunately, string doesn't | |
442 | // stop appending at the '0' if the number of elements to append was | |
443 | // explicitely specified | |
444 | string tmp(""); | |
445 | tmp.append(type.fOrigin, kAliHLTComponentDataTypefOriginSize); | |
446 | out.append(tmp.c_str()); | |
9ce4bf4a | 447 | out.append(":"); |
3cde846d | 448 | tmp=""; |
449 | tmp.append(type.fID, kAliHLTComponentDataTypefIDsize); | |
450 | out.append(tmp.c_str()); | |
9ce4bf4a | 451 | } |
452 | return out; | |
453 | } | |
454 | ||
455 | ||
70ed7d01 | 456 | void* AliHLTComponent::AllocMemory( unsigned long size ) |
457 | { | |
458 | // see header file for function documentation | |
85869391 | 459 | if (fEnvironment.fAllocMemoryFunc) |
460 | return (*fEnvironment.fAllocMemoryFunc)(fEnvironment.fParam, size ); | |
9ce4bf4a | 461 | HLTFatal("no memory allocation handler registered"); |
85869391 | 462 | return NULL; |
463 | } | |
464 | ||
2be3f004 | 465 | int AliHLTComponent::MakeOutputDataBlockList( const AliHLTComponentBlockDataList& blocks, AliHLTUInt32_t* blockCount, |
70ed7d01 | 466 | AliHLTComponentBlockData** outputBlocks ) |
467 | { | |
468 | // see header file for function documentation | |
9ce4bf4a | 469 | if ( blockCount==NULL || outputBlocks==NULL ) |
2d7ff710 | 470 | return -EFAULT; |
fa2e9b7c | 471 | AliHLTUInt32_t count = blocks.size(); |
472 | if ( !count ) | |
473 | { | |
474 | *blockCount = 0; | |
475 | *outputBlocks = NULL; | |
476 | return 0; | |
477 | } | |
8ede8717 | 478 | *outputBlocks = reinterpret_cast<AliHLTComponentBlockData*>( AllocMemory( sizeof(AliHLTComponentBlockData)*count ) ); |
fa2e9b7c | 479 | if ( !*outputBlocks ) |
2d7ff710 | 480 | return -ENOMEM; |
ca8524df | 481 | for ( unsigned long i = 0; i < count; i++ ) { |
fa2e9b7c | 482 | (*outputBlocks)[i] = blocks[i]; |
732e8f50 | 483 | if (MatchExactly(blocks[i].fDataType, kAliHLTAnyDataType)) { |
5f5b708b | 484 | (*outputBlocks)[i].fDataType=GetOutputDataType(); |
485 | /* data type was set to the output data type by the PubSub AliRoot | |
486 | Wrapper component, if data type of the block was ********:****. | |
487 | Now handled by the component base class in order to have same | |
488 | behavior when running embedded in AliRoot | |
ca8524df | 489 | memset((*outputBlocks)[i].fDataType.fID, '*', kAliHLTComponentDataTypefIDsize); |
490 | memset((*outputBlocks)[i].fDataType.fOrigin, '*', kAliHLTComponentDataTypefOriginSize); | |
5f5b708b | 491 | */ |
ca8524df | 492 | } |
493 | } | |
fa2e9b7c | 494 | *blockCount = count; |
495 | return 0; | |
496 | ||
497 | } | |
0c0c9d99 | 498 | |
70ed7d01 | 499 | int AliHLTComponent::GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd ) |
500 | { | |
501 | // see header file for function documentation | |
85869391 | 502 | if (fEnvironment.fGetEventDoneDataFunc) |
503 | return (*fEnvironment.fGetEventDoneDataFunc)(fEnvironment.fParam, fCurrentEvent, size, edd ); | |
504 | return -ENOSYS; | |
505 | } | |
506 | ||
2be3f004 | 507 | int AliHLTComponent::FindMatchingDataTypes(AliHLTComponent* pConsumer, AliHLTComponentDataTypeList* tgtList) |
0c0c9d99 | 508 | { |
70ed7d01 | 509 | // see header file for function documentation |
0c0c9d99 | 510 | int iResult=0; |
511 | if (pConsumer) { | |
8a106878 | 512 | AliHLTComponentDataTypeList itypes; |
513 | AliHLTComponentDataTypeList otypes; | |
514 | otypes.push_back(GetOutputDataType()); | |
515 | if (otypes[0]==kAliHLTMultipleDataType) { | |
516 | otypes.clear(); | |
517 | int count=0; | |
518 | if ((count=GetOutputDataTypes(otypes))>0) { | |
519 | } else if (GetComponentType()!=kSink) { | |
520 | HLTWarning("component %s indicates multiple output data types but GetOutputDataTypes returns %d", GetComponentID(), count); | |
521 | } | |
522 | } | |
523 | ((AliHLTComponent*)pConsumer)->GetInputDataTypes(itypes); | |
524 | AliHLTComponentDataTypeList::iterator itype=itypes.begin(); | |
525 | while (itype!=itypes.end()) { | |
526 | //PrintDataTypeContent((*itype), "consumer \'%s\'"); | |
527 | AliHLTComponentDataTypeList::iterator otype=otypes.begin(); | |
528 | while (otype!=otypes.end() && (*itype)!=(*otype)) otype++; | |
529 | //if (otype!=otypes.end()) PrintDataTypeContent(*otype, "publisher \'%s\'"); | |
d8f5c9fe | 530 | if (otype!=otypes.end()) { |
8a106878 | 531 | if (tgtList) tgtList->push_back(*itype); |
0c0c9d99 | 532 | iResult++; |
0c0c9d99 | 533 | } |
8a106878 | 534 | itype++; |
0c0c9d99 | 535 | } |
536 | } else { | |
537 | iResult=-EINVAL; | |
538 | } | |
539 | return iResult; | |
540 | } | |
2d7ff710 | 541 | |
8b97f4f1 | 542 | void AliHLTComponent::PrintDataTypeContent(AliHLTComponentDataType& dt, const char* format) |
5f5b708b | 543 | { |
66043029 | 544 | // see header file for function documentation |
8b97f4f1 | 545 | const char* fmt="\'%s\'"; |
5f5b708b | 546 | if (format) fmt=format; |
8b97f4f1 | 547 | AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, Form(fmt, (DataType2Text(dt)).c_str())); |
548 | AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, | |
549 | Form("%x %x %x %x %x %x %x %x : %x %x %x %x", | |
550 | dt.fID[0], | |
551 | dt.fID[1], | |
552 | dt.fID[2], | |
553 | dt.fID[3], | |
554 | dt.fID[4], | |
555 | dt.fID[5], | |
556 | dt.fID[6], | |
557 | dt.fID[7], | |
558 | dt.fOrigin[0], | |
559 | dt.fOrigin[1], | |
560 | dt.fOrigin[2], | |
561 | dt.fOrigin[3])); | |
5f5b708b | 562 | } |
563 | ||
fbdb63fd | 564 | void AliHLTComponent::FillBlockData( AliHLTComponentBlockData& blockData ) |
70ed7d01 | 565 | { |
566 | // see header file for function documentation | |
2d7ff710 | 567 | blockData.fStructSize = sizeof(blockData); |
568 | FillShmData( blockData.fShmKey ); | |
569 | blockData.fOffset = ~(AliHLTUInt32_t)0; | |
570 | blockData.fPtr = NULL; | |
571 | blockData.fSize = 0; | |
572 | FillDataType( blockData.fDataType ); | |
a655eae3 | 573 | blockData.fSpecification = kAliHLTVoidDataSpec; |
2d7ff710 | 574 | } |
575 | ||
fbdb63fd | 576 | void AliHLTComponent::FillShmData( AliHLTComponentShmData& shmData ) |
70ed7d01 | 577 | { |
578 | // see header file for function documentation | |
2d7ff710 | 579 | shmData.fStructSize = sizeof(shmData); |
580 | shmData.fShmType = gkAliHLTComponentInvalidShmType; | |
581 | shmData.fShmID = gkAliHLTComponentInvalidShmID; | |
582 | } | |
583 | ||
fbdb63fd | 584 | void AliHLTComponent::FillDataType( AliHLTComponentDataType& dataType ) |
70ed7d01 | 585 | { |
586 | // see header file for function documentation | |
ca8524df | 587 | dataType=kAliHLTAnyDataType; |
2d7ff710 | 588 | } |
589 | ||
70ed7d01 | 590 | void AliHLTComponent::CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt) |
591 | { | |
592 | // see header file for function documentation | |
2d7ff710 | 593 | memcpy(&tgtdt.fID[0], &srcdt.fID[0], kAliHLTComponentDataTypefIDsize); |
594 | memcpy(&tgtdt.fOrigin[0], &srcdt.fOrigin[0], kAliHLTComponentDataTypefOriginSize); | |
595 | } | |
596 | ||
70ed7d01 | 597 | void AliHLTComponent::SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin) |
598 | { | |
599 | // see header file for function documentation | |
7e3efc8f | 600 | tgtdt.fStructSize=sizeof(AliHLTComponentDataType); |
601 | if (id) { | |
602 | memset(&tgtdt.fID[0], 0, kAliHLTComponentDataTypefIDsize); | |
d76bc02a | 603 | strncpy(&tgtdt.fID[0], id, strlen(id)<(size_t)kAliHLTComponentDataTypefIDsize?strlen(id):kAliHLTComponentDataTypefIDsize); |
7e3efc8f | 604 | } |
605 | if (origin) { | |
606 | memset(&tgtdt.fOrigin[0], 0, kAliHLTComponentDataTypefOriginSize); | |
d76bc02a | 607 | strncpy(&tgtdt.fOrigin[0], origin, strlen(origin)<(size_t)kAliHLTComponentDataTypefOriginSize?strlen(origin):kAliHLTComponentDataTypefOriginSize); |
7e3efc8f | 608 | } |
2d7ff710 | 609 | } |
9ce4bf4a | 610 | |
18b56222 | 611 | void AliHLTComponent::SetDataType(AliHLTComponentDataType& dt, AliHLTUInt64_t id, AliHLTUInt32_t origin) |
612 | { | |
613 | // see header file for function documentation | |
614 | dt.fStructSize=sizeof(AliHLTComponentDataType); | |
615 | assert(kAliHLTComponentDataTypefIDsize==sizeof(id)); | |
616 | assert(kAliHLTComponentDataTypefOriginSize==sizeof(origin)); | |
617 | memcpy(&dt.fID, &id, kAliHLTComponentDataTypefIDsize); | |
618 | memcpy(&dt.fOrigin, &origin, kAliHLTComponentDataTypefOriginSize); | |
619 | } | |
620 | ||
9ce4bf4a | 621 | void AliHLTComponent::FillEventData(AliHLTComponentEventData& evtData) |
622 | { | |
70ed7d01 | 623 | // see header file for function documentation |
9ce4bf4a | 624 | memset(&evtData, 0, sizeof(AliHLTComponentEventData)); |
625 | evtData.fStructSize=sizeof(AliHLTComponentEventData); | |
626 | } | |
627 | ||
70ed7d01 | 628 | void AliHLTComponent::PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt) |
629 | { | |
630 | // see header file for function documentation | |
9ce4bf4a | 631 | TString msg; |
632 | msg.Form("AliHLTComponentDataType(%d): ID=\"", dt.fStructSize); | |
633 | for ( int i = 0; i < kAliHLTComponentDataTypefIDsize; i++ ) { | |
634 | if (dt.fID[i]!=0) msg+=dt.fID[i]; | |
635 | else msg+="\\0"; | |
636 | } | |
637 | msg+="\" Origin=\""; | |
638 | for ( int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++ ) { | |
639 | if (dt.fOrigin[i]!=0) msg+=dt.fOrigin[i]; | |
640 | else msg+="\\0"; | |
641 | } | |
642 | msg+="\""; | |
3cde846d | 643 | AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, msg.Data()); |
9ce4bf4a | 644 | } |
645 | ||
70ed7d01 | 646 | int AliHLTComponent::GetEventCount() const |
3cde846d | 647 | { |
70ed7d01 | 648 | // see header file for function documentation |
3cde846d | 649 | return fEventCount; |
650 | } | |
651 | ||
652 | int AliHLTComponent::IncrementEventCounter() | |
653 | { | |
70ed7d01 | 654 | // see header file for function documentation |
3cde846d | 655 | if (fEventCount>=0) fEventCount++; |
656 | return fEventCount; | |
657 | } | |
658 | ||
66043029 | 659 | int AliHLTComponent::GetNumberOfInputBlocks() const |
a655eae3 | 660 | { |
661 | // see header file for function documentation | |
662 | if (fpInputBlocks!=NULL) { | |
663 | return fCurrentEventData.fBlockCnt; | |
664 | } | |
665 | return 0; | |
666 | } | |
667 | ||
668 | const TObject* AliHLTComponent::GetFirstInputObject(const AliHLTComponentDataType& dt, | |
669 | const char* classname, | |
670 | int bForce) | |
671 | { | |
672 | // see header file for function documentation | |
90ebac25 | 673 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
a655eae3 | 674 | fSearchDataType=dt; |
675 | if (classname) fClassName=classname; | |
676 | else fClassName.clear(); | |
1edbbe49 | 677 | int idx=FindInputBlock(fSearchDataType, 0, 1); |
a655eae3 | 678 | TObject* pObj=NULL; |
679 | if (idx>=0) { | |
79c114b5 | 680 | HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(dt).c_str()); |
a655eae3 | 681 | if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) { |
682 | fCurrentInputBlock=idx; | |
683 | } else { | |
684 | } | |
685 | } | |
686 | return pObj; | |
687 | } | |
688 | ||
689 | const TObject* AliHLTComponent::GetFirstInputObject(const char* dtID, | |
690 | const char* dtOrigin, | |
691 | const char* classname, | |
692 | int bForce) | |
693 | { | |
694 | // see header file for function documentation | |
90ebac25 | 695 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
a655eae3 | 696 | AliHLTComponentDataType dt; |
697 | SetDataType(dt, dtID, dtOrigin); | |
698 | return GetFirstInputObject(dt, classname, bForce); | |
699 | } | |
700 | ||
701 | const TObject* AliHLTComponent::GetNextInputObject(int bForce) | |
702 | { | |
703 | // see header file for function documentation | |
90ebac25 | 704 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
1edbbe49 | 705 | int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1, 1); |
a655eae3 | 706 | //HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(fSearchDataType).c_str()); |
707 | TObject* pObj=NULL; | |
708 | if (idx>=0) { | |
709 | if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) { | |
710 | fCurrentInputBlock=idx; | |
711 | } | |
712 | } | |
713 | return pObj; | |
714 | } | |
715 | ||
1edbbe49 | 716 | int AliHLTComponent::FindInputBlock(const AliHLTComponentDataType& dt, int startIdx, int bObject) const |
a655eae3 | 717 | { |
718 | // see header file for function documentation | |
719 | int iResult=-ENOENT; | |
720 | if (fpInputBlocks!=NULL) { | |
721 | int idx=startIdx<0?0:startIdx; | |
4b98eadb | 722 | for ( ; (UInt_t)idx<fCurrentEventData.fBlockCnt && iResult==-ENOENT; idx++) { |
3dd8541e | 723 | if (dt!=fpInputBlocks[idx].fDataType) continue; |
724 | ||
1edbbe49 | 725 | if (bObject!=0) { |
726 | if (fpInputBlocks[idx].fPtr==NULL) continue; | |
3294f81a | 727 | AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr); |
728 | if (firstWord!=fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) continue; | |
1edbbe49 | 729 | } |
3dd8541e | 730 | iResult=idx; |
a655eae3 | 731 | } |
732 | } | |
733 | return iResult; | |
734 | } | |
735 | ||
736 | TObject* AliHLTComponent::CreateInputObject(int idx, int bForce) | |
737 | { | |
738 | // see header file for function documentation | |
739 | TObject* pObj=NULL; | |
740 | if (fpInputBlocks!=NULL) { | |
4b98eadb | 741 | if ((UInt_t)idx<fCurrentEventData.fBlockCnt) { |
a655eae3 | 742 | if (fpInputBlocks[idx].fPtr) { |
3294f81a | 743 | AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr); |
a655eae3 | 744 | if (firstWord==fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) { |
8451168b | 745 | HLTDebug("create object from block %d size %d", idx, fpInputBlocks[idx].fSize); |
3294f81a | 746 | AliHLTMessage msg(fpInputBlocks[idx].fPtr, fpInputBlocks[idx].fSize); |
66043029 | 747 | TClass* objclass=msg.GetClass(); |
748 | pObj=msg.ReadObject(objclass); | |
749 | if (pObj && objclass) { | |
750 | HLTDebug("object %p type %s created", pObj, objclass->GetName()); | |
a655eae3 | 751 | } else { |
752 | } | |
1edbbe49 | 753 | //} else { |
754 | } else if (bForce!=0) { | |
c5123824 | 755 | HLTError("size mismatch: block size %d, indicated %d", fpInputBlocks[idx].fSize, firstWord+sizeof(AliHLTUInt32_t)); |
a655eae3 | 756 | } |
757 | } else { | |
758 | HLTFatal("block descriptor empty"); | |
759 | } | |
760 | } else { | |
761 | HLTError("index %d out of range %d", idx, fCurrentEventData.fBlockCnt); | |
762 | } | |
763 | } else { | |
764 | HLTError("no input blocks available"); | |
765 | } | |
766 | ||
767 | return pObj; | |
768 | } | |
769 | ||
298ef463 | 770 | TObject* AliHLTComponent::GetInputObject(int idx, const char* /*classname*/, int bForce) |
a655eae3 | 771 | { |
772 | // see header file for function documentation | |
773 | if (fpInputObjects==NULL) { | |
774 | fpInputObjects=new TObjArray(fCurrentEventData.fBlockCnt); | |
775 | } | |
776 | TObject* pObj=NULL; | |
777 | if (fpInputObjects) { | |
778 | pObj=fpInputObjects->At(idx); | |
779 | if (pObj==NULL) { | |
780 | pObj=CreateInputObject(idx, bForce); | |
781 | if (pObj) { | |
782 | fpInputObjects->AddAt(pObj, idx); | |
783 | } | |
784 | } | |
785 | } else { | |
786 | HLTFatal("memory allocation failed: TObjArray of size %d", fCurrentEventData.fBlockCnt); | |
787 | } | |
788 | return pObj; | |
789 | } | |
790 | ||
8451168b | 791 | int AliHLTComponent::CleanupInputObjects() |
792 | { | |
66043029 | 793 | // see header file for function documentation |
8451168b | 794 | if (!fpInputObjects) return 0; |
795 | TObjArray* array=fpInputObjects; | |
796 | fpInputObjects=NULL; | |
797 | for (int i=0; i<array->GetEntries(); i++) { | |
798 | TObject* pObj=array->At(i); | |
79c114b5 | 799 | // grrr, garbage collection strikes back: When read via AliHLTMessage |
800 | // (CreateInputObject), and written to a TFile afterwards, the | |
801 | // TFile::Close calls ROOOT's garbage collection. No clue why the | |
802 | // object ended up in the key list and needs to be deleted | |
803 | if (pObj && gObjectTable->PtrIsValid(pObj)) delete pObj; | |
8451168b | 804 | } |
805 | delete array; | |
90ebac25 | 806 | return 0; |
8451168b | 807 | } |
808 | ||
a655eae3 | 809 | AliHLTComponentDataType AliHLTComponent::GetDataType(const TObject* pObject) |
810 | { | |
811 | // see header file for function documentation | |
90ebac25 | 812 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
a655eae3 | 813 | AliHLTComponentDataType dt=kAliHLTVoidDataType; |
814 | int idx=fCurrentInputBlock; | |
815 | if (pObject) { | |
816 | if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) { | |
817 | } else { | |
818 | HLTError("unknown object %p", pObject); | |
819 | } | |
820 | } | |
821 | if (idx>=0) { | |
4b98eadb | 822 | if ((UInt_t)idx<fCurrentEventData.fBlockCnt) { |
a655eae3 | 823 | dt=fpInputBlocks[idx].fDataType; |
824 | } else { | |
825 | HLTFatal("severe internal error, index out of range"); | |
826 | } | |
827 | } | |
828 | return dt; | |
829 | } | |
830 | ||
831 | AliHLTUInt32_t AliHLTComponent::GetSpecification(const TObject* pObject) | |
832 | { | |
833 | // see header file for function documentation | |
90ebac25 | 834 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
a655eae3 | 835 | AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec; |
836 | int idx=fCurrentInputBlock; | |
837 | if (pObject) { | |
838 | if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) { | |
839 | } else { | |
840 | HLTError("unknown object %p", pObject); | |
841 | } | |
842 | } | |
843 | if (idx>=0) { | |
4b98eadb | 844 | if ((UInt_t)idx<fCurrentEventData.fBlockCnt) { |
a655eae3 | 845 | iSpec=fpInputBlocks[idx].fSpecification; |
846 | } else { | |
847 | HLTFatal("severe internal error, index out of range"); | |
848 | } | |
849 | } | |
850 | return iSpec; | |
851 | } | |
852 | ||
c7e9e2f2 | 853 | int AliHLTComponent::Forward(const TObject* pObject) |
854 | { | |
855 | // see header file for function documentation | |
856 | int iResult=0; | |
857 | int idx=fCurrentInputBlock; | |
858 | if (pObject) { | |
859 | if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) { | |
860 | } else { | |
861 | HLTError("unknown object %p", pObject); | |
862 | iResult=-ENOENT; | |
863 | } | |
864 | } | |
865 | if (idx>=0) { | |
866 | fOutputBlocks.push_back(fpInputBlocks[idx]); | |
867 | } | |
868 | return iResult; | |
869 | } | |
870 | ||
871 | int AliHLTComponent::Forward(const AliHLTComponentBlockData* pBlock) | |
872 | { | |
873 | // see header file for function documentation | |
874 | int iResult=0; | |
875 | int idx=fCurrentInputBlock; | |
876 | if (pBlock) { | |
877 | if (fpInputObjects==NULL || (idx=FindInputBlock(pBlock))>=0) { | |
878 | } else { | |
879 | HLTError("unknown Block %p", pBlock); | |
880 | iResult=-ENOENT; | |
881 | } | |
882 | } | |
883 | if (idx>=0) { | |
884 | // check for fpInputBlocks pointer done in FindInputBlock | |
885 | fOutputBlocks.push_back(fpInputBlocks[idx]); | |
886 | } | |
887 | return iResult; | |
888 | } | |
889 | ||
a655eae3 | 890 | const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const AliHLTComponentDataType& dt) |
891 | { | |
892 | // see header file for function documentation | |
90ebac25 | 893 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
a655eae3 | 894 | fSearchDataType=dt; |
895 | fClassName.clear(); | |
896 | int idx=FindInputBlock(fSearchDataType, 0); | |
897 | const AliHLTComponentBlockData* pBlock=NULL; | |
898 | if (idx>=0) { | |
899 | // check for fpInputBlocks pointer done in FindInputBlock | |
900 | pBlock=&fpInputBlocks[idx]; | |
1edbbe49 | 901 | fCurrentInputBlock=idx; |
a655eae3 | 902 | } |
903 | return pBlock; | |
904 | } | |
905 | ||
906 | const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const char* dtID, | |
907 | const char* dtOrigin) | |
908 | { | |
909 | // see header file for function documentation | |
90ebac25 | 910 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
a655eae3 | 911 | AliHLTComponentDataType dt; |
912 | SetDataType(dt, dtID, dtOrigin); | |
913 | return GetFirstInputBlock(dt); | |
914 | } | |
915 | ||
ec25e4ca | 916 | const AliHLTComponentBlockData* AliHLTComponent::GetInputBlock(int index) |
917 | { | |
918 | // see header file for function documentation | |
919 | ALIHLTCOMPONENT_BASE_STOPWATCH(); | |
13398559 | 920 | assert( 0 <= index and index < (int)fCurrentEventData.fBlockCnt ); |
ec25e4ca | 921 | return &fpInputBlocks[index]; |
922 | } | |
923 | ||
a655eae3 | 924 | const AliHLTComponentBlockData* AliHLTComponent::GetNextInputBlock() |
925 | { | |
926 | // see header file for function documentation | |
90ebac25 | 927 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
a655eae3 | 928 | int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1); |
929 | const AliHLTComponentBlockData* pBlock=NULL; | |
930 | if (idx>=0) { | |
931 | // check for fpInputBlocks pointer done in FindInputBlock | |
932 | pBlock=&fpInputBlocks[idx]; | |
1edbbe49 | 933 | fCurrentInputBlock=idx; |
a655eae3 | 934 | } |
935 | return pBlock; | |
936 | } | |
937 | ||
66043029 | 938 | int AliHLTComponent::FindInputBlock(const AliHLTComponentBlockData* pBlock) const |
a655eae3 | 939 | { |
940 | // see header file for function documentation | |
941 | int iResult=-ENOENT; | |
942 | if (fpInputBlocks!=NULL) { | |
943 | if (pBlock) { | |
944 | if (pBlock>=fpInputBlocks && pBlock<fpInputBlocks+fCurrentEventData.fBlockCnt) { | |
132ca004 | 945 | iResult=(int)(pBlock-fpInputBlocks); |
a655eae3 | 946 | } |
947 | } else { | |
948 | iResult=-EINVAL; | |
949 | } | |
950 | } | |
951 | return iResult; | |
952 | } | |
953 | ||
954 | AliHLTUInt32_t AliHLTComponent::GetSpecification(const AliHLTComponentBlockData* pBlock) | |
955 | { | |
956 | // see header file for function documentation | |
90ebac25 | 957 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
a655eae3 | 958 | AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec; |
959 | int idx=fCurrentInputBlock; | |
960 | if (pBlock) { | |
961 | if (fpInputObjects==NULL || (idx=FindInputBlock(pBlock))>=0) { | |
962 | } else { | |
963 | HLTError("unknown Block %p", pBlock); | |
964 | } | |
965 | } | |
966 | if (idx>=0) { | |
967 | // check for fpInputBlocks pointer done in FindInputBlock | |
968 | iSpec=fpInputBlocks[idx].fSpecification; | |
969 | } | |
970 | return iSpec; | |
971 | } | |
972 | ||
79c114b5 | 973 | int AliHLTComponent::PushBack(TObject* pObject, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec, |
974 | void* pHeader, int headerSize) | |
a655eae3 | 975 | { |
976 | // see header file for function documentation | |
90ebac25 | 977 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
a655eae3 | 978 | int iResult=0; |
979 | if (pObject) { | |
980 | AliHLTMessage msg(kMESS_OBJECT); | |
981 | msg.WriteObject(pObject); | |
982 | Int_t iMsgLength=msg.Length(); | |
983 | if (iMsgLength>0) { | |
984 | msg.SetLength(); // sets the length to the first (reserved) word | |
79c114b5 | 985 | iResult=InsertOutputBlock(msg.Buffer(), iMsgLength, dt, spec, pHeader, headerSize); |
a655eae3 | 986 | if (iResult>=0) { |
8451168b | 987 | HLTDebug("object %s (%p) size %d inserted to output", pObject->ClassName(), pObject, iMsgLength); |
a655eae3 | 988 | } |
989 | } else { | |
990 | HLTError("object serialization failed for object %p", pObject); | |
991 | iResult=-ENOMSG; | |
992 | } | |
993 | } else { | |
994 | iResult=-EINVAL; | |
995 | } | |
996 | return iResult; | |
997 | } | |
998 | ||
79c114b5 | 999 | int AliHLTComponent::PushBack(TObject* pObject, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec, |
1000 | void* pHeader, int headerSize) | |
a655eae3 | 1001 | { |
1002 | // see header file for function documentation | |
90ebac25 | 1003 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
a655eae3 | 1004 | AliHLTComponentDataType dt; |
1005 | SetDataType(dt, dtID, dtOrigin); | |
79c114b5 | 1006 | return PushBack(pObject, dt, spec, pHeader, headerSize); |
a655eae3 | 1007 | } |
1008 | ||
9d9ffd37 | 1009 | int AliHLTComponent::PushBack(void* pBuffer, int iSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec, |
1010 | void* pHeader, int headerSize) | |
a655eae3 | 1011 | { |
1012 | // see header file for function documentation | |
90ebac25 | 1013 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
9d9ffd37 | 1014 | return InsertOutputBlock(pBuffer, iSize, dt, spec, pHeader, headerSize); |
a655eae3 | 1015 | } |
1016 | ||
9d9ffd37 | 1017 | int AliHLTComponent::PushBack(void* pBuffer, int iSize, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec, |
1018 | void* pHeader, int headerSize) | |
a655eae3 | 1019 | { |
1020 | // see header file for function documentation | |
90ebac25 | 1021 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
a655eae3 | 1022 | AliHLTComponentDataType dt; |
1023 | SetDataType(dt, dtID, dtOrigin); | |
9d9ffd37 | 1024 | return PushBack(pBuffer, iSize, dt, spec, pHeader, headerSize); |
a655eae3 | 1025 | } |
1026 | ||
79c114b5 | 1027 | int AliHLTComponent::InsertOutputBlock(void* pBuffer, int iBufferSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec, |
1028 | void* pHeader, int iHeaderSize) | |
a655eae3 | 1029 | { |
1030 | // see header file for function documentation | |
1031 | int iResult=0; | |
79c114b5 | 1032 | int iBlkSize = iBufferSize + iHeaderSize; |
a655eae3 | 1033 | if (pBuffer) { |
79c114b5 | 1034 | if (fpOutputBuffer && iBlkSize<=(int)(fOutputBufferSize-fOutputBufferFilled)) { |
a655eae3 | 1035 | AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled; |
1036 | AliHLTComponentBlockData bd; | |
1037 | FillBlockData( bd ); | |
1038 | bd.fOffset = fOutputBufferFilled; | |
79c114b5 | 1039 | bd.fSize = iBlkSize; |
a655eae3 | 1040 | bd.fDataType = dt; |
1041 | bd.fSpecification = spec; | |
79c114b5 | 1042 | if (pHeader!=NULL && pHeader!=pTgt) { |
1043 | memcpy(pTgt, pHeader, iHeaderSize); | |
1044 | } | |
1045 | ||
1046 | pTgt += (AliHLTUInt8_t) iHeaderSize; | |
1047 | ||
a655eae3 | 1048 | if (pBuffer!=NULL && pBuffer!=pTgt) { |
79c114b5 | 1049 | memcpy(pTgt, pBuffer, iBufferSize); |
1050 | ||
4b98eadb | 1051 | //AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)pBuffer); |
79c114b5 | 1052 | //HLTDebug("copy %d bytes from %p to output buffer %p, first word %#x", iBufferSize, pBuffer, pTgt, firstWord); |
a655eae3 | 1053 | } |
1054 | fOutputBufferFilled+=bd.fSize; | |
1055 | fOutputBlocks.push_back( bd ); | |
79c114b5 | 1056 | //HLTDebug("buffer inserted to output: size %d data type %s spec %#x", iBlkSize, DataType2Text(dt).c_str(), spec); |
a655eae3 | 1057 | } else { |
1058 | if (fpOutputBuffer) { | |
79c114b5 | 1059 | HLTError("too little space in output buffer: %d, required %d", fOutputBufferSize-fOutputBufferFilled, iBlkSize); |
a655eae3 | 1060 | } else { |
1061 | HLTError("output buffer not available"); | |
1062 | } | |
1063 | iResult=-ENOSPC; | |
1064 | } | |
1065 | } else { | |
1066 | iResult=-EINVAL; | |
1067 | } | |
1068 | return iResult; | |
1069 | } | |
1070 | ||
8451168b | 1071 | int AliHLTComponent::EstimateObjectSize(TObject* pObject) const |
1072 | { | |
66043029 | 1073 | // see header file for function documentation |
8451168b | 1074 | if (!pObject) return -EINVAL; |
1075 | AliHLTMessage msg(kMESS_OBJECT); | |
1076 | msg.WriteObject(pObject); | |
1077 | return msg.Length(); | |
1078 | } | |
1079 | ||
79c114b5 | 1080 | AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(int capacity, const char* dtID, |
1081 | const char* dtOrigin, | |
1082 | AliHLTUInt32_t spec) | |
1083 | { | |
1084 | // see header file for function documentation | |
1085 | ALIHLTCOMPONENT_BASE_STOPWATCH(); | |
1086 | AliHLTComponentDataType dt; | |
1087 | SetDataType(dt, dtID, dtOrigin); | |
1088 | return CreateMemoryFile(capacity, dt, spec); | |
1089 | } | |
1090 | ||
1091 | AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(int capacity, | |
1092 | const AliHLTComponentDataType& dt, | |
1093 | AliHLTUInt32_t spec) | |
1094 | { | |
1095 | // see header file for function documentation | |
1096 | ALIHLTCOMPONENT_BASE_STOPWATCH(); | |
1097 | AliHLTMemoryFile* pFile=NULL; | |
83fec083 | 1098 | if (capacity>=0 && static_cast<unsigned int>(capacity)<=fOutputBufferSize-fOutputBufferFilled){ |
79c114b5 | 1099 | AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled; |
1100 | pFile=new AliHLTMemoryFile((char*)pTgt, capacity); | |
1101 | if (pFile) { | |
83fec083 | 1102 | unsigned int nofBlocks=fOutputBlocks.size(); |
79c114b5 | 1103 | if (nofBlocks+1>fMemFiles.size()) { |
1104 | fMemFiles.resize(nofBlocks+1, NULL); | |
1105 | } | |
1106 | if (nofBlocks<fMemFiles.size()) { | |
1107 | fMemFiles[nofBlocks]=pFile; | |
1108 | AliHLTComponentBlockData bd; | |
1109 | FillBlockData( bd ); | |
1110 | bd.fOffset = fOutputBufferFilled; | |
79c114b5 | 1111 | bd.fSize = capacity; |
1112 | bd.fDataType = dt; | |
1113 | bd.fSpecification = spec; | |
1114 | fOutputBufferFilled+=bd.fSize; | |
1115 | fOutputBlocks.push_back( bd ); | |
1116 | } else { | |
1117 | HLTError("can not allocate/grow object array"); | |
29312178 | 1118 | pFile->CloseMemoryFile(0); |
79c114b5 | 1119 | delete pFile; |
1120 | pFile=NULL; | |
1121 | } | |
1122 | } | |
1123 | } else { | |
1124 | HLTError("can not create memory file of size %d (%d available)", capacity, fOutputBufferSize-fOutputBufferFilled); | |
1125 | } | |
1126 | return pFile; | |
1127 | } | |
1128 | ||
1129 | AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(const char* dtID, | |
1130 | const char* dtOrigin, | |
1131 | AliHLTUInt32_t spec, | |
1132 | float capacity) | |
1133 | { | |
1134 | // see header file for function documentation | |
1135 | ALIHLTCOMPONENT_BASE_STOPWATCH(); | |
1136 | AliHLTComponentDataType dt; | |
1137 | SetDataType(dt, dtID, dtOrigin); | |
1138 | int size=fOutputBufferSize-fOutputBufferFilled; | |
1139 | if (capacity<0 || capacity>1.0) { | |
1140 | HLTError("invalid parameter: capacity %f", capacity); | |
1141 | return NULL; | |
1142 | } | |
1143 | size=(int)(size*capacity); | |
1144 | return CreateMemoryFile(size, dt, spec); | |
1145 | } | |
1146 | ||
1147 | AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(const AliHLTComponentDataType& dt, | |
1148 | AliHLTUInt32_t spec, | |
1149 | float capacity) | |
1150 | { | |
1151 | // see header file for function documentation | |
1152 | ALIHLTCOMPONENT_BASE_STOPWATCH(); | |
1153 | int size=fOutputBufferSize-fOutputBufferFilled; | |
1154 | if (capacity<0 || capacity>1.0) { | |
1155 | HLTError("invalid parameter: capacity %f", capacity); | |
1156 | return NULL; | |
1157 | } | |
1158 | size=(int)(size*capacity); | |
1159 | return CreateMemoryFile(size, dt, spec); | |
1160 | } | |
1161 | ||
1162 | int AliHLTComponent::Write(AliHLTMemoryFile* pFile, const TObject* pObject, | |
1163 | const char* key, int option) | |
1164 | { | |
3a7c0444 | 1165 | // see header file for function documentation |
79c114b5 | 1166 | int iResult=0; |
1167 | if (pFile && pObject) { | |
1168 | pFile->cd(); | |
1169 | iResult=pObject->Write(key, option); | |
1170 | if (iResult>0) { | |
1171 | // success | |
1172 | } else { | |
1173 | iResult=-pFile->GetErrno(); | |
1174 | if (iResult==-ENOSPC) { | |
1175 | HLTError("error writing memory file, buffer too small"); | |
1176 | } | |
1177 | } | |
1178 | } else { | |
1179 | iResult=-EINVAL; | |
1180 | } | |
1181 | return iResult; | |
1182 | } | |
1183 | ||
1184 | int AliHLTComponent::CloseMemoryFile(AliHLTMemoryFile* pFile) | |
1185 | { | |
3a7c0444 | 1186 | // see header file for function documentation |
79c114b5 | 1187 | int iResult=0; |
1188 | if (pFile) { | |
2be3f004 | 1189 | AliHLTMemoryFilePList::iterator element=fMemFiles.begin(); |
79c114b5 | 1190 | int i=0; |
1191 | while (element!=fMemFiles.end() && iResult>=0) { | |
1192 | if (*element && *element==pFile) { | |
29312178 | 1193 | iResult=pFile->CloseMemoryFile(); |
79c114b5 | 1194 | |
1195 | // sync memory files and descriptors | |
1196 | if (iResult>=0) { | |
1197 | fOutputBlocks[i].fSize=(*element)->GetSize()+(*element)->GetHeaderSize(); | |
1198 | } | |
1199 | delete *element; | |
1200 | *element=NULL; | |
1201 | return iResult; | |
1202 | } | |
1203 | element++; i++; | |
1204 | } | |
1205 | HLTError("can not find memory file %p", pFile); | |
1206 | iResult=-ENOENT; | |
1207 | } else { | |
1208 | iResult=-EINVAL; | |
1209 | } | |
1210 | return iResult; | |
1211 | } | |
1212 | ||
29312178 | 1213 | int AliHLTComponent::CreateEventDoneData(AliHLTComponentEventDoneData /*edd*/) |
a655eae3 | 1214 | { |
1215 | // see header file for function documentation | |
1216 | int iResult=-ENOSYS; | |
1217 | //#warning function not yet implemented | |
1218 | HLTWarning("function not yet implemented"); | |
1219 | return iResult; | |
1220 | } | |
1221 | ||
3cde846d | 1222 | int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData, |
1223 | const AliHLTComponentBlockData* blocks, | |
1224 | AliHLTComponentTriggerData& trigData, | |
1225 | AliHLTUInt8_t* outputPtr, | |
1226 | AliHLTUInt32_t& size, | |
1227 | AliHLTUInt32_t& outputBlockCnt, | |
1228 | AliHLTComponentBlockData*& outputBlocks, | |
1229 | AliHLTComponentEventDoneData*& edd ) | |
1230 | { | |
70ed7d01 | 1231 | // see header file for function documentation |
b2065764 | 1232 | HLTLogKeyword(GetComponentID()); |
90ebac25 | 1233 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
3cde846d | 1234 | int iResult=0; |
1235 | fCurrentEvent=evtData.fEventID; | |
a655eae3 | 1236 | fCurrentEventData=evtData; |
1237 | fpInputBlocks=blocks; | |
1238 | fCurrentInputBlock=-1; | |
1239 | fSearchDataType=kAliHLTAnyDataType; | |
1240 | fpOutputBuffer=outputPtr; | |
1241 | fOutputBufferSize=size; | |
1242 | fOutputBufferFilled=0; | |
1243 | fOutputBlocks.clear(); | |
96f9673a | 1244 | outputBlockCnt=0; |
1245 | outputBlocks=NULL; | |
a0aeb701 | 1246 | AliHLTComponentStatisticsList compStats; |
1247 | #if defined(__DEBUG) || defined(HLT_COMPONENT_STATISTICS) | |
1248 | AliHLTComponentStatistics outputStat; | |
1249 | memset(&outputStat, 0, sizeof(AliHLTComponentStatistics)); | |
1250 | compStats.push_back(outputStat); | |
1251 | if (fpBenchmark) { | |
1252 | fpBenchmark->Reset(); | |
1253 | fpBenchmark->Start(); | |
1254 | } | |
1255 | #endif | |
559631d5 | 1256 | |
45c0a780 | 1257 | // data processing is skipped if there are only steering events |
1258 | // in the block list. It is not skipped if there is no block list | |
1259 | // at all for the sake of data source components. Data processing | |
1260 | // is always skipped if the event is of type | |
1261 | // - gkAliEventTypeConfiguration | |
1262 | // - gkAliEventTypeReadPreprocessor | |
1263 | const unsigned int skipModeDefault=0x1; | |
1264 | const unsigned int skipModeForce=0x2; | |
1265 | unsigned int bSkipDataProcessing=skipModeDefault; | |
1266 | ||
559631d5 | 1267 | // find special events |
45c0a780 | 1268 | if (fpInputBlocks && evtData.fBlockCnt>0) { |
579d9eb7 | 1269 | // first look for all special events and execute in the appropriate |
1270 | // sequence afterwords | |
b543e186 | 1271 | AliHLTUInt32_t eventType=gkAliEventTypeUnknown; |
579d9eb7 | 1272 | int indexComConfEvent=-1; |
b543e186 | 1273 | int indexUpdtDCSEvent=-1; |
579d9eb7 | 1274 | int indexSOREvent=-1; |
1275 | int indexEOREvent=-1; | |
83fec083 | 1276 | for (unsigned int i=0; i<evtData.fBlockCnt && iResult>=0; i++) { |
559631d5 | 1277 | if (fpInputBlocks[i].fDataType==kAliHLTDataTypeSOR) { |
579d9eb7 | 1278 | indexSOREvent=i; |
45c0a780 | 1279 | // the AliHLTCalibrationProcessor relies on the SOR and EOR events |
1280 | bSkipDataProcessing&=~skipModeDefault; | |
1281 | } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeRunType) { | |
1282 | // run type string | |
1283 | // handling is not clear yet | |
1284 | if (fpInputBlocks[i].fPtr) { | |
1285 | HLTDebug("got run type \"%s\"\n", fpInputBlocks[i].fPtr); | |
1286 | } | |
579d9eb7 | 1287 | } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeEOR) { |
1288 | indexEOREvent=i; | |
45c0a780 | 1289 | // the calibration processor relies on the SOR and EOR events |
1290 | bSkipDataProcessing&=~skipModeDefault; | |
579d9eb7 | 1291 | } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeDDL) { |
1292 | // DDL list | |
1293 | // this event is most likely deprecated | |
1294 | } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComConf) { | |
1295 | indexComConfEvent=i; | |
b543e186 | 1296 | } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeUpdtDCS) { |
1297 | indexUpdtDCSEvent=i; | |
1298 | } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeEvent) { | |
1299 | eventType=fpInputBlocks[i].fSpecification; | |
45c0a780 | 1300 | if (fpInputBlocks[i].fSpecification==gkAliEventTypeConfiguration) bSkipDataProcessing|=skipModeForce; |
1301 | if (fpInputBlocks[i].fSpecification==gkAliEventTypeReadPreprocessor) bSkipDataProcessing|=skipModeForce; | |
a0aeb701 | 1302 | } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComponentStatistics) { |
1303 | if (compStats.size()>0) { | |
1304 | AliHLTUInt8_t* pData=reinterpret_cast<AliHLTUInt8_t*>(fpInputBlocks[i].fPtr); | |
1305 | for (AliHLTUInt32_t offset=0; | |
1306 | offset+sizeof(AliHLTComponentStatistics)<=fpInputBlocks[i].fSize; | |
1307 | offset+=sizeof(AliHLTComponentStatistics)) { | |
1308 | AliHLTComponentStatistics* pStat=reinterpret_cast<AliHLTComponentStatistics*>(pData+offset); | |
1309 | if (pStat && compStats[0].fLevel<=pStat->fLevel) { | |
1310 | compStats[0].fLevel=pStat->fLevel+1; | |
1311 | } | |
1312 | compStats.push_back(*pStat); | |
1313 | } | |
1314 | } | |
45c0a780 | 1315 | } else { |
1316 | // the processing function is called if there is at least one | |
1317 | // non-steering data block. Steering blocks are not filtered out | |
1318 | // for sake of performance | |
1319 | bSkipDataProcessing&=~skipModeDefault; | |
a0aeb701 | 1320 | if (compStats.size()>0) { |
1321 | compStats[0].fInputBlockCount++; | |
1322 | compStats[0].fTotalInputSize+=fpInputBlocks[i].fSize; | |
1323 | } | |
579d9eb7 | 1324 | } |
1325 | } | |
45c0a780 | 1326 | |
579d9eb7 | 1327 | if (indexSOREvent>=0) { |
1328 | // start of run | |
1329 | if (fpRunDesc==NULL) { | |
1330 | fpRunDesc=new AliHLTRunDesc; | |
45c0a780 | 1331 | } |
1332 | if (fpRunDesc) { | |
1333 | AliHLTRunDesc rundesc; | |
1334 | if ((iResult=CopyStruct(&rundesc, sizeof(AliHLTRunDesc), indexSOREvent, "AliHLTRunDesc", "SOR"))>0) { | |
1335 | if (fpRunDesc->fRunNo==kAliHLTVoidRunNo) { | |
1336 | *fpRunDesc=rundesc; | |
579d9eb7 | 1337 | HLTDebug("set run decriptor, run no %d", fpRunDesc->fRunNo); |
1338 | SetCDBRunNo(fpRunDesc->fRunNo); | |
45c0a780 | 1339 | } else if (fpRunDesc->fRunNo!=rundesc.fRunNo) { |
1340 | HLTWarning("already set run properties run no %d, ignoring SOR with run no %d", fpRunDesc->fRunNo, rundesc.fRunNo); | |
559631d5 | 1341 | } |
559631d5 | 1342 | } |
579d9eb7 | 1343 | } else { |
45c0a780 | 1344 | iResult=-ENOMEM; |
579d9eb7 | 1345 | } |
1346 | } | |
1347 | if (indexEOREvent>=0) { | |
1348 | if (fpRunDesc!=NULL) { | |
1349 | if (fpRunDesc) { | |
1350 | AliHLTRunDesc rundesc; | |
1351 | if ((iResult=CopyStruct(&rundesc, sizeof(AliHLTRunDesc), indexEOREvent, "AliHLTRunDesc", "SOR"))>0) { | |
1352 | if (fpRunDesc->fRunNo!=rundesc.fRunNo) { | |
c5123824 | 1353 | HLTWarning("run no mismatch: SOR %d, EOR %d", fpRunDesc->fRunNo, rundesc.fRunNo); |
579d9eb7 | 1354 | } else { |
1355 | HLTDebug("EOR run no %d", fpRunDesc->fRunNo); | |
559631d5 | 1356 | } |
559631d5 | 1357 | } |
579d9eb7 | 1358 | AliHLTRunDesc* pRunDesc=fpRunDesc; |
1359 | fpRunDesc=NULL; | |
1360 | delete pRunDesc; | |
559631d5 | 1361 | } |
579d9eb7 | 1362 | } else { |
1363 | HLTWarning("did not receive SOR, ignoring EOR"); | |
1364 | } | |
1365 | } | |
b543e186 | 1366 | if (indexComConfEvent>=0 || eventType==gkAliEventTypeConfiguration) { |
579d9eb7 | 1367 | TString cdbEntry; |
b543e186 | 1368 | if (indexComConfEvent>=0 && fpInputBlocks[indexComConfEvent].fPtr!=NULL && fpInputBlocks[indexComConfEvent].fSize>0) { |
579d9eb7 | 1369 | cdbEntry.Append(reinterpret_cast<const char*>(fpInputBlocks[indexComConfEvent].fPtr), fpInputBlocks[indexComConfEvent].fSize); |
1370 | } | |
1371 | HLTDebug("received component configuration command: entry %s", cdbEntry.IsNull()?"none":cdbEntry.Data()); | |
1372 | int tmpResult=Reconfigure(cdbEntry[0]==0?NULL:cdbEntry.Data(), fChainId.c_str()); | |
1373 | if (tmpResult<0) { | |
1374 | HLTWarning("reconfiguration of component %p (%s) failed with error code %d", this, GetComponentID(), tmpResult); | |
559631d5 | 1375 | } |
1376 | } | |
d6b69874 | 1377 | if (indexUpdtDCSEvent>=0 || eventType==gkAliEventTypeReadPreprocessor) { |
b543e186 | 1378 | TString modules; |
1379 | if (fpInputBlocks[indexUpdtDCSEvent].fPtr!=NULL && fpInputBlocks[indexUpdtDCSEvent].fSize>0) { | |
1380 | modules.Append(reinterpret_cast<const char*>(fpInputBlocks[indexUpdtDCSEvent].fPtr), fpInputBlocks[indexUpdtDCSEvent].fSize); | |
1381 | } | |
d6b69874 | 1382 | HLTDebug("received preprocessor update command: detectors %s", modules.IsNull()?"ALL":modules.Data()); |
1383 | int tmpResult=ReadPreprocessorValues(modules[0]==0?"ALL":modules.Data()); | |
b543e186 | 1384 | if (tmpResult<0) { |
1385 | HLTWarning("preprocessor update of component %p (%s) failed with error code %d", this, GetComponentID(), tmpResult); | |
1386 | } | |
1387 | } | |
45c0a780 | 1388 | } else { |
1389 | // processing function needs to be called if there are no input data | |
1390 | // blocks in order to make data source components working. | |
1391 | bSkipDataProcessing&=~skipModeDefault; | |
559631d5 | 1392 | } |
a0aeb701 | 1393 | |
1394 | // data processing is not skipped if the component explicitly asks | |
1395 | // for the private blocks | |
1396 | if (fRequireSteeringBlocks) bSkipDataProcessing=0; | |
1397 | ||
2be3f004 | 1398 | AliHLTComponentBlockDataList blockData; |
45c0a780 | 1399 | if (iResult>=0 && !bSkipDataProcessing) |
90ebac25 | 1400 | { // dont delete, sets the scope for the stopwatch guard |
f7561f8d | 1401 | // do not use ALIHLTCOMPONENT_DA_STOPWATCH(); macro |
1402 | // in order to avoid 'shadowed variable' warning | |
1403 | AliHLTStopwatchGuard swguard2(fpStopwatches!=NULL?reinterpret_cast<TStopwatch*>(fpStopwatches->At((int)kSWDA)):NULL); | |
90ebac25 | 1404 | iResult=DoProcessing(evtData, blocks, trigData, outputPtr, size, blockData, edd); |
1405 | } // end of the scope of the stopwatch guard | |
b543e186 | 1406 | if (iResult>=0 && !bSkipDataProcessing) { |
a655eae3 | 1407 | if (fOutputBlocks.size()>0) { |
df61f928 | 1408 | // High Level interface |
1409 | ||
1410 | //HLTDebug("got %d block(s) via high level interface", fOutputBlocks.size()); | |
79c114b5 | 1411 | // sync memory files and descriptors |
2be3f004 | 1412 | AliHLTMemoryFilePList::iterator element=fMemFiles.begin(); |
79c114b5 | 1413 | int i=0; |
1414 | while (element!=fMemFiles.end() && iResult>=0) { | |
1415 | if (*element) { | |
1416 | if ((*element)->IsClosed()==0) { | |
1417 | HLTWarning("memory file has not been closed, force flush"); | |
1418 | iResult=CloseMemoryFile(*element); | |
1419 | } | |
1420 | } | |
1421 | element++; i++; | |
1422 | } | |
1423 | ||
1424 | if (iResult>=0) { | |
1425 | // create the descriptor list | |
1426 | if (blockData.size()>0) { | |
1427 | HLTError("low level and high interface must not be mixed; use PushBack methods to insert data blocks"); | |
1428 | iResult=-EFAULT; | |
1429 | } else { | |
a0aeb701 | 1430 | if (compStats.size()>0) { |
1431 | int offset=AddComponentStatistics(fOutputBlocks, fpOutputBuffer, fOutputBufferSize, fOutputBufferFilled, compStats); | |
1432 | if (offset>0) fOutputBufferFilled+=offset; | |
1433 | } | |
79c114b5 | 1434 | iResult=MakeOutputDataBlockList(fOutputBlocks, &outputBlockCnt, &outputBlocks); |
1435 | size=fOutputBufferFilled; | |
1436 | } | |
a655eae3 | 1437 | } |
1438 | } else { | |
df61f928 | 1439 | // Low Level interface |
a0aeb701 | 1440 | if (compStats.size()>0) { |
1441 | int offset=AddComponentStatistics(blockData, fpOutputBuffer, fOutputBufferSize, size, compStats); | |
1442 | if (offset>0) size+=offset; | |
1443 | } | |
a655eae3 | 1444 | iResult=MakeOutputDataBlockList(blockData, &outputBlockCnt, &outputBlocks); |
1445 | } | |
1446 | if (iResult<0) { | |
1447 | HLTFatal("component %s (%p): can not convert output block descriptor list", GetComponentID(), this); | |
1448 | } | |
1449 | } | |
b543e186 | 1450 | if (iResult<0 || bSkipDataProcessing) { |
a655eae3 | 1451 | outputBlockCnt=0; |
1452 | outputBlocks=NULL; | |
1453 | } | |
8451168b | 1454 | CleanupInputObjects(); |
b543e186 | 1455 | if (iResult>=0 && !bSkipDataProcessing) { |
f8bc6d99 | 1456 | IncrementEventCounter(); |
1457 | } | |
96f9673a | 1458 | if (outputBlockCnt==0) { |
1459 | // no output blocks, set size to 0 | |
1460 | size=0; | |
1461 | } | |
3cde846d | 1462 | return iResult; |
1463 | } | |
a655eae3 | 1464 | |
a0aeb701 | 1465 | int AliHLTComponent::AddComponentStatistics(AliHLTComponentBlockDataList& blocks, |
1466 | AliHLTUInt8_t* buffer, | |
1467 | AliHLTUInt32_t bufferSize, | |
1468 | AliHLTUInt32_t offset, | |
1469 | AliHLTComponentStatisticsList& stats) const | |
1470 | { | |
1471 | // see header file for function documentation | |
1472 | int iResult=0; | |
1473 | if (stats.size()==0) return -ENOENT; | |
1474 | stats[0].fTotalOutputSize=offset; | |
1475 | stats[0].fOutputBlockCount=blocks.size(); | |
1476 | if (fpBenchmark) { | |
1477 | stats[0].fTime=(AliHLTUInt32_t)(fpBenchmark->RealTime()*1000000); | |
1478 | stats[0].fCTime=(AliHLTUInt32_t)(fpBenchmark->CpuTime()*1000000); | |
1479 | } | |
1480 | if (offset+stats.size()*sizeof(AliHLTComponentStatistics)<=bufferSize) { | |
1481 | AliHLTComponentBlockData bd; | |
1482 | FillBlockData( bd ); | |
1483 | bd.fOffset = offset; | |
1484 | bd.fSize = stats.size()*sizeof(AliHLTComponentStatistics); | |
1485 | bd.fDataType = kAliHLTDataTypeComponentStatistics; | |
1486 | bd.fSpecification = kAliHLTVoidDataSpec; | |
1487 | unsigned int master=0; | |
1488 | for (unsigned int i=1; i<blocks.size(); i++) { | |
1489 | if (blocks[i].fSize>blocks[master].fSize && | |
1490 | !MatchExactly(blocks[i].fDataType, kAliHLTVoidDataType|kAliHLTDataOriginPrivate)) | |
1491 | master=i; | |
1492 | } | |
1493 | if (blocks.size()>0 && !MatchExactly(blocks[master].fDataType, kAliHLTVoidDataType|kAliHLTDataOriginPrivate)) { | |
1494 | // take the data origin of the biggest block as specification | |
1495 | // this is similar to the treatment in the HOMER interface. For traditional | |
1496 | // reasons, the bytes are swapped there on a little endian architecture, so | |
1497 | // we do it as well. | |
1498 | memcpy(&bd.fSpecification, &blocks[master].fDataType.fOrigin, sizeof(bd.fSpecification)); | |
1499 | #ifdef R__BYTESWAP // set on little endian architectures | |
1500 | bd.fSpecification=((bd.fSpecification & 0xFFULL) << 24) | | |
1501 | ((bd.fSpecification & 0xFF00ULL) << 8) | | |
1502 | ((bd.fSpecification & 0xFF0000ULL) >> 8) | | |
1503 | ((bd.fSpecification & 0xFF000000ULL) >> 24); | |
1504 | #endif | |
1505 | } | |
1506 | memcpy(buffer+offset, &(stats[0]), bd.fSize); | |
1507 | blocks.push_back(bd); | |
1508 | iResult=bd.fSize; | |
1509 | } | |
1510 | return iResult; | |
1511 | } | |
1512 | ||
90ebac25 | 1513 | AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard() |
1514 | : | |
1515 | fpStopwatch(NULL), | |
1516 | fpPrec(NULL) | |
1517 | { | |
1518 | // standard constructor (not for use) | |
1519 | } | |
1520 | ||
1521 | AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(TStopwatch* pStopwatch) | |
1522 | : | |
1523 | fpStopwatch(pStopwatch), | |
1524 | fpPrec(NULL) | |
1525 | { | |
1526 | // constructor | |
1527 | ||
1528 | // check for already existing guard | |
1529 | if (fgpCurrent) fpPrec=fgpCurrent; | |
1530 | fgpCurrent=this; | |
1531 | ||
1532 | // stop the preceeding guard if it controls a different stopwatch | |
1533 | int bStart=1; | |
1534 | if (fpPrec && fpPrec!=this) bStart=fpPrec->Hold(fpStopwatch); | |
1535 | ||
1536 | // start the stopwatch if the current guard controls a different one | |
1537 | if (fpStopwatch && bStart==1) fpStopwatch->Start(kFALSE); | |
1538 | } | |
1539 | ||
e419b223 | 1540 | AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(const AliHLTStopwatchGuard&) |
90ebac25 | 1541 | : |
1542 | fpStopwatch(NULL), | |
1543 | fpPrec(NULL) | |
1544 | { | |
e419b223 | 1545 | // |
1546 | // copy constructor not for use | |
1547 | // | |
1548 | } | |
1549 | ||
1550 | AliHLTComponent::AliHLTStopwatchGuard& AliHLTComponent::AliHLTStopwatchGuard::operator=(const AliHLTStopwatchGuard&) | |
1551 | { | |
1552 | // | |
1553 | // assignment operator not for use | |
1554 | // | |
1555 | fpStopwatch=NULL; | |
1556 | fpPrec=NULL; | |
1557 | return *this; | |
90ebac25 | 1558 | } |
1559 | ||
1560 | AliHLTComponent::AliHLTStopwatchGuard* AliHLTComponent::AliHLTStopwatchGuard::fgpCurrent=NULL; | |
1561 | ||
1562 | AliHLTComponent::AliHLTStopwatchGuard::~AliHLTStopwatchGuard() | |
1563 | { | |
1564 | // destructor | |
1565 | ||
1566 | // resume the preceeding guard if it controls a different stopwatch | |
1567 | int bStop=1; | |
1568 | if (fpPrec && fpPrec!=this) bStop=fpPrec->Resume(fpStopwatch); | |
1569 | ||
1570 | // stop the stopwatch if the current guard controls a different one | |
1571 | if (fpStopwatch && bStop==1) fpStopwatch->Stop(); | |
1572 | ||
1573 | // resume to the preceeding guard | |
1574 | fgpCurrent=fpPrec; | |
1575 | } | |
1576 | ||
1577 | int AliHLTComponent::AliHLTStopwatchGuard::Hold(TStopwatch* pSucc) | |
1578 | { | |
1579 | // see header file for function documentation | |
1580 | if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Stop(); | |
1581 | return fpStopwatch!=pSucc?1:0; | |
1582 | } | |
1583 | ||
1584 | int AliHLTComponent::AliHLTStopwatchGuard::Resume(TStopwatch* pSucc) | |
1585 | { | |
1586 | // see header file for function documentation | |
1587 | if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Start(kFALSE); | |
1588 | return fpStopwatch!=pSucc?1:0; | |
1589 | } | |
1590 | ||
1591 | int AliHLTComponent::SetStopwatch(TObject* pSW, AliHLTStopwatchType type) | |
1592 | { | |
1593 | // see header file for function documentation | |
1594 | int iResult=0; | |
1595 | if (pSW!=NULL && type<kSWTypeCount) { | |
1596 | if (fpStopwatches) { | |
1597 | TObject* pObj=fpStopwatches->At((int)type); | |
1598 | if (pSW==NULL // explicit reset | |
1599 | || pObj==NULL) { // explicit set | |
1600 | fpStopwatches->AddAt(pSW, (int)type); | |
1601 | } else if (pObj!=pSW) { | |
1602 | HLTWarning("stopwatch %d already set, reset first", (int)type); | |
1603 | iResult=-EBUSY; | |
1604 | } | |
1605 | } | |
1606 | } else { | |
1607 | iResult=-EINVAL; | |
1608 | } | |
1609 | return iResult; | |
1610 | } | |
1611 | ||
1612 | int AliHLTComponent::SetStopwatches(TObjArray* pStopwatches) | |
1613 | { | |
1614 | // see header file for function documentation | |
1615 | if (pStopwatches==NULL) return -EINVAL; | |
1616 | ||
1617 | int iResult=0; | |
1618 | for (int i=0 ; i<(int)kSWTypeCount && pStopwatches->GetEntries(); i++) | |
1619 | SetStopwatch(pStopwatches->At(i), (AliHLTStopwatchType)i); | |
1620 | return iResult; | |
1621 | } | |
559631d5 | 1622 | |
1623 | AliHLTUInt32_t AliHLTComponent::GetRunNo() const | |
1624 | { | |
29312178 | 1625 | // see header file for function documentation |
45c0a780 | 1626 | if (fpRunDesc==NULL) return kAliHLTVoidRunNo; |
559631d5 | 1627 | return fpRunDesc->fRunNo; |
1628 | } | |
1629 | ||
1630 | AliHLTUInt32_t AliHLTComponent::GetRunType() const | |
1631 | { | |
29312178 | 1632 | // see header file for function documentation |
45c0a780 | 1633 | if (fpRunDesc==NULL) return kAliHLTVoidRunType; |
559631d5 | 1634 | return fpRunDesc->fRunType; |
1635 | } | |
1636 | ||
83fec083 | 1637 | int AliHLTComponent::CopyStruct(void* pStruct, unsigned int iStructSize, unsigned int iBlockNo, |
559631d5 | 1638 | const char* structname, const char* eventname) |
1639 | { | |
29312178 | 1640 | // see header file for function documentation |
559631d5 | 1641 | int iResult=0; |
1642 | if (pStruct!=NULL && iStructSize>sizeof(AliHLTUInt32_t)) { | |
1643 | if (fpInputBlocks!=NULL && iBlockNo<fCurrentEventData.fBlockCnt) { | |
1644 | AliHLTUInt32_t* pTgt=(AliHLTUInt32_t*)pStruct; | |
1645 | if (fpInputBlocks[iBlockNo].fPtr && fpInputBlocks[iBlockNo].fSize) { | |
3294f81a | 1646 | AliHLTUInt32_t copy=*((AliHLTUInt32_t*)fpInputBlocks[iBlockNo].fPtr); |
559631d5 | 1647 | if (fpInputBlocks[iBlockNo].fSize!=copy) { |
c5123824 | 1648 | HLTWarning("%s event: mismatch of block size (%d) and structure size (%d)", eventname, fpInputBlocks[iBlockNo].fSize, copy); |
559631d5 | 1649 | if (copy>fpInputBlocks[iBlockNo].fSize) copy=fpInputBlocks[iBlockNo].fSize; |
1650 | } | |
1651 | if (copy!=iStructSize) { | |
c5123824 | 1652 | HLTWarning("%s event: mismatch in %s version (data type version %d)", eventname, structname, ALIHLT_DATA_TYPES_VERSION); |
559631d5 | 1653 | if (copy>iStructSize) { |
1654 | copy=iStructSize; | |
1655 | } else { | |
1656 | memset(pTgt, 0, iStructSize); | |
1657 | } | |
1658 | } | |
3294f81a | 1659 | memcpy(pTgt, fpInputBlocks[iBlockNo].fPtr, copy); |
559631d5 | 1660 | *pTgt=iStructSize; |
1661 | iResult=copy; | |
1662 | } else { | |
1663 | HLTWarning("%s event: missing data block", eventname); | |
1664 | } | |
1665 | } else { | |
1666 | iResult=-ENODATA; | |
1667 | } | |
1668 | } else { | |
1669 | HLTError("invalid struct"); | |
1670 | iResult=-EINVAL; | |
1671 | } | |
1672 | return iResult; | |
1673 | } | |
ed504011 | 1674 | |
1675 | void AliHLTComponent::SetDDLBit(AliHLTEventDDL &list, Int_t ddlId, Bool_t state ) const | |
1676 | { | |
1677 | // see header file for function documentation | |
1678 | ||
1679 | // -- Detector offset | |
1680 | Int_t ddlIdBase = TMath::FloorNint( (Double_t) ddlId / 256.0 ); | |
1681 | ||
1682 | // -- Word Base = 1. word of detector ( TPC has 8 words, TOF 3 ) | |
1683 | Int_t wordBase = 0; | |
1684 | ||
1685 | if ( ddlIdBase <= 3 ) | |
1686 | wordBase = ddlIdBase; | |
1687 | else if ( ddlIdBase > 3 && ddlIdBase < 5 ) | |
1688 | wordBase = ddlIdBase + 7; | |
1689 | else | |
1690 | wordBase = ddlIdBase + 9; | |
1691 | ||
1692 | // -- Bit index in Word | |
1693 | Int_t bitIdx = ddlId % 32; | |
1694 | ||
1695 | // -- Index of word | |
1696 | Int_t wordIdx = wordBase; | |
1697 | ||
1698 | // -- if TPC (3) or TOD (5) add word idx | |
1699 | if ( ( ddlIdBase == 3 ) || ( ddlIdBase == 5 ) ) { | |
1700 | wordIdx += TMath::FloorNint( (Double_t) ( ddlId - ( ddlIdBase * 256 ) ) / 32.0 ); | |
1701 | } | |
1702 | ||
1703 | // -- Set -- 'OR' word with bit mask; | |
1704 | if ( state ) | |
1705 | list.fList[wordIdx] |= ( 0x00000001 << bitIdx ); | |
1706 | // -- Unset -- 'AND' word with bit mask; | |
1707 | else | |
1708 | list.fList[wordIdx] &= ( 0xFFFFFFFF ^ ( 0x00000001 << bitIdx ) ); | |
1709 | } | |
1710 | ||
1711 | Int_t AliHLTComponent::GetFirstUsedDDLWord(AliHLTEventDDL &list) const | |
1712 | { | |
1713 | // see header file for function documentation | |
1714 | ||
1715 | Int_t iResult = -1; | |
1716 | ||
1717 | for ( Int_t wordNdx = 0 ; wordNdx < gkAliHLTDDLListSize ; wordNdx++ ) { | |
1718 | ||
1719 | if ( list.fList[wordNdx] != 0 && iResult == -1 ) { | |
1720 | // check for special cases TPC and TOF | |
1721 | if ( wordNdx > 3 && wordNdx <= 10 ) { | |
1722 | wordNdx = 10; | |
1723 | iResult = 3; | |
1724 | } | |
1725 | else if ( wordNdx > 12 && wordNdx <= 14 ) { | |
1726 | wordNdx = 14; | |
1727 | iResult = 12; | |
1728 | } | |
1729 | else | |
1730 | iResult = wordNdx; | |
1731 | } | |
1732 | else if ( list.fList[wordNdx] != 0 && iResult >= 0 ) { | |
1733 | HLTError( "DDLIDs for minimum of TWO detectors ( %d, %d ) set, this function works only for ONE detector.", iResult, wordNdx ); | |
1734 | iResult = -1; | |
1735 | break; | |
1736 | } | |
1737 | } | |
1738 | ||
1739 | return iResult; | |
1740 | } |