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