]>
Commit | Line | Data |
---|---|---|
f23a6e1a | 1 | // $Id$ |
2 | ||
3 | /************************************************************************** | |
4 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
5 | * * | |
6 | * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> * | |
7 | * Timm Steinbeck <timm@kip.uni-heidelberg.de> * | |
f23a6e1a | 8 | * for The ALICE Off-line Project. * |
9 | * * | |
10 | * Permission to use, copy, modify and distribute this software and its * | |
11 | * documentation strictly for non-commercial purposes is hereby granted * | |
12 | * without fee, provided that the above copyright notice appears in all * | |
13 | * copies and that both the copyright notice and this permission notice * | |
14 | * appear in the supporting documentation. The authors make no claims * | |
15 | * about the suitability of this software for any purpose. It is * | |
16 | * provided "as is" without express or implied warranty. * | |
17 | **************************************************************************/ | |
18 | ||
bfccbf68 | 19 | /** @file AliHLTComponent.cxx |
20 | @author Matthias Richter, Timm Steinbeck | |
21 | @date | |
22 | @brief Base class implementation for HLT components. */ | |
f23a6e1a | 23 | |
0c0c9d99 | 24 | #if __GNUC__>= 3 |
f23a6e1a | 25 | using namespace std; |
26 | #endif | |
27 | ||
66043029 | 28 | //#include "AliHLTStdIncludes.h" |
f23a6e1a | 29 | #include "AliHLTComponent.h" |
30 | #include "AliHLTComponentHandler.h" | |
a655eae3 | 31 | #include "AliHLTMessage.h" |
70ed7d01 | 32 | #include "TString.h" |
a655eae3 | 33 | #include "TObjArray.h" |
34 | #include "TClass.h" | |
90ebac25 | 35 | #include "TStopwatch.h" |
f23a6e1a | 36 | |
b22e91eb | 37 | /** ROOT macro for the implementation of ROOT specific class methods */ |
90ebac25 | 38 | ClassImp(AliHLTComponent); |
39 | ||
40 | /** stopwatch macro using the stopwatch guard */ | |
41 | #define ALIHLTCOMPONENT_STOPWATCH(type) AliHLTStopwatchGuard swguard(fpStopwatches!=NULL?reinterpret_cast<TStopwatch*>(fpStopwatches->At((int)type)):NULL) | |
42 | //#define ALIHLTCOMPONENT_STOPWATCH(type) | |
43 | ||
44 | /** stopwatch macro for operations of the base class */ | |
45 | #define ALIHLTCOMPONENT_BASE_STOPWATCH() ALIHLTCOMPONENT_STOPWATCH(kSWBase) | |
46 | /** stopwatch macro for operations of the detector algorithm (DA) */ | |
47 | #define ALIHLTCOMPONENT_DA_STOPWATCH() ALIHLTCOMPONENT_STOPWATCH(kSWDA) | |
f23a6e1a | 48 | |
f23a6e1a | 49 | AliHLTComponent::AliHLTComponent() |
85869391 | 50 | : |
53feaef5 | 51 | fEnvironment(), |
3cde846d | 52 | fCurrentEvent(0), |
a655eae3 | 53 | fEventCount(-1), |
54 | fFailedEvents(0), | |
55 | fCurrentEventData(), | |
56 | fpInputBlocks(NULL), | |
57 | fCurrentInputBlock(-1), | |
58 | fSearchDataType(kAliHLTVoidDataType), | |
59 | fClassName(), | |
60 | fpInputObjects(NULL), | |
61 | fpOutputBuffer(NULL), | |
62 | fOutputBufferSize(0), | |
63 | fOutputBufferFilled(0), | |
90ebac25 | 64 | fOutputBlocks(), |
65 | fpStopwatches(new TObjArray(kSWTypeCount)) | |
70ed7d01 | 66 | { |
67 | // see header file for class documentation | |
68 | // or | |
69 | // refer to README to build package | |
70 | // or | |
71 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
f23a6e1a | 72 | memset(&fEnvironment, 0, sizeof(AliHLTComponentEnvironment)); |
70ed7d01 | 73 | if (fgpComponentHandler) |
74 | fgpComponentHandler->ScheduleRegister(this); | |
8451168b | 75 | SetLocalLoggingLevel(kHLTLogDefault); |
70ed7d01 | 76 | } |
77 | ||
78 | AliHLTComponent::AliHLTComponent(const AliHLTComponent&) | |
79 | : | |
9253e11b | 80 | AliHLTLogging(), |
70ed7d01 | 81 | fEnvironment(), |
82 | fCurrentEvent(0), | |
a655eae3 | 83 | fEventCount(-1), |
84 | fFailedEvents(0), | |
85 | fCurrentEventData(), | |
86 | fpInputBlocks(NULL), | |
87 | fCurrentInputBlock(-1), | |
88 | fSearchDataType(kAliHLTVoidDataType), | |
89 | fClassName(), | |
90 | fpInputObjects(NULL), | |
91 | fpOutputBuffer(NULL), | |
92 | fOutputBufferSize(0), | |
93 | fOutputBufferFilled(0), | |
90ebac25 | 94 | fOutputBlocks(), |
95 | fpStopwatches(NULL) | |
70ed7d01 | 96 | { |
97 | // see header file for class documentation | |
98 | HLTFatal("copy constructor untested"); | |
99 | } | |
100 | ||
101 | AliHLTComponent& AliHLTComponent::operator=(const AliHLTComponent&) | |
102 | { | |
103 | // see header file for class documentation | |
104 | HLTFatal("assignment operator untested"); | |
105 | return *this; | |
f23a6e1a | 106 | } |
107 | ||
108 | AliHLTComponent::~AliHLTComponent() | |
109 | { | |
70ed7d01 | 110 | // see header file for function documentation |
8451168b | 111 | CleanupInputObjects(); |
f23a6e1a | 112 | } |
113 | ||
70ed7d01 | 114 | AliHLTComponentHandler* AliHLTComponent::fgpComponentHandler=NULL; |
b22e91eb | 115 | |
85869391 | 116 | int AliHLTComponent::SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite) |
117 | { | |
70ed7d01 | 118 | // see header file for function documentation |
85869391 | 119 | int iResult=0; |
70ed7d01 | 120 | if (fgpComponentHandler==NULL || bOverwrite!=0) |
121 | fgpComponentHandler=pCH; | |
85869391 | 122 | else |
123 | iResult=-EPERM; | |
124 | return iResult; | |
125 | } | |
126 | ||
70ed7d01 | 127 | int AliHLTComponent::UnsetGlobalComponentHandler() |
128 | { | |
129 | // see header file for function documentation | |
85869391 | 130 | return SetGlobalComponentHandler(NULL,1); |
131 | } | |
132 | ||
70ed7d01 | 133 | int AliHLTComponent::Init( AliHLTComponentEnvironment* environ, void* environParam, int argc, const char** argv ) |
f23a6e1a | 134 | { |
70ed7d01 | 135 | // see header file for function documentation |
f23a6e1a | 136 | int iResult=0; |
137 | if (environ) { | |
138 | memcpy(&fEnvironment, environ, sizeof(AliHLTComponentEnvironment)); | |
70ed7d01 | 139 | fEnvironment.fParam=environParam; |
f23a6e1a | 140 | } |
8451168b | 141 | const char** pArguments=NULL; |
142 | int iNofChildArgs=0; | |
143 | TString argument=""; | |
144 | int bMissingParam=0; | |
145 | if (argc>0) { | |
146 | pArguments=new const char*[argc]; | |
147 | if (pArguments) { | |
148 | for (int i=0; i<argc && iResult>=0; i++) { | |
149 | argument=argv[i]; | |
150 | if (argument.IsNull()) continue; | |
151 | ||
152 | // benchmark | |
153 | if (argument.CompareTo("benchmark")==0) { | |
154 | ||
155 | // loglevel | |
156 | } else if (argument.CompareTo("loglevel")==0) { | |
157 | if ((bMissingParam=(++i>=argc))) break; | |
158 | TString parameter(argv[i]); | |
159 | parameter.Remove(TString::kLeading, ' '); // remove all blanks | |
160 | if (parameter.BeginsWith("0x") && | |
161 | parameter.Replace(0,2,"",0).IsHex()) { | |
162 | AliHLTComponentLogSeverity loglevel=kHLTLogNone; | |
7a5ccd96 | 163 | sscanf(parameter.Data(),"%x", (unsigned int*)&loglevel); |
8451168b | 164 | SetLocalLoggingLevel(loglevel); |
165 | } else { | |
166 | HLTError("wrong parameter for argument %s, hex number expected", argument.Data()); | |
167 | iResult=-EINVAL; | |
168 | } | |
169 | } else { | |
170 | pArguments[iNofChildArgs++]=argv[i]; | |
171 | } | |
172 | } | |
173 | } else { | |
174 | iResult=-ENOMEM; | |
175 | } | |
176 | } | |
177 | if (bMissingParam) { | |
178 | HLTError("missing parameter for argument %s", argument.Data()); | |
179 | iResult=-EINVAL; | |
180 | } | |
181 | if (iResult>=0) { | |
182 | iResult=DoInit(iNofChildArgs, pArguments); | |
183 | } | |
3cde846d | 184 | if (iResult>=0) fEventCount=0; |
8451168b | 185 | if (pArguments) delete [] pArguments; |
f23a6e1a | 186 | return iResult; |
187 | } | |
188 | ||
189 | int AliHLTComponent::Deinit() | |
190 | { | |
70ed7d01 | 191 | // see header file for function documentation |
f23a6e1a | 192 | int iResult=0; |
193 | iResult=DoDeinit(); | |
194 | return iResult; | |
195 | } | |
fa2e9b7c | 196 | |
53feaef5 | 197 | int AliHLTComponent::DoInit( int argc, const char** argv ) |
198 | { | |
70ed7d01 | 199 | // see header file for function documentation |
53feaef5 | 200 | if (argc==0 && argv==NULL) { |
201 | // this is currently just to get rid of the warning "unused parameter" | |
202 | } | |
66043029 | 203 | fEventCount=0; |
53feaef5 | 204 | return 0; |
205 | } | |
206 | ||
207 | int AliHLTComponent::DoDeinit() | |
208 | { | |
70ed7d01 | 209 | // see header file for function documentation |
66043029 | 210 | fEventCount=0; |
53feaef5 | 211 | return 0; |
212 | } | |
213 | ||
70ed7d01 | 214 | void AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2] ) const |
215 | { | |
216 | // see header file for function documentation | |
9ce4bf4a | 217 | memset( output, 0, kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2 ); |
218 | strncat( output, type.fOrigin, kAliHLTComponentDataTypefOriginSize ); | |
219 | strcat( output, ":" ); | |
220 | strncat( output, type.fID, kAliHLTComponentDataTypefIDsize ); | |
fa2e9b7c | 221 | } |
222 | ||
9ce4bf4a | 223 | string AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type ) |
224 | { | |
70ed7d01 | 225 | // see header file for function documentation |
9ce4bf4a | 226 | string out(""); |
3cde846d | 227 | |
9ce4bf4a | 228 | if (type==kAliHLTVoidDataType) { |
229 | out="VOID:VOID"; | |
230 | } else { | |
3cde846d | 231 | // some gymnastics in order to avoid a '0' which is part of either or both |
232 | // ID and origin terminating the whole string. Unfortunately, string doesn't | |
233 | // stop appending at the '0' if the number of elements to append was | |
234 | // explicitely specified | |
235 | string tmp(""); | |
236 | tmp.append(type.fOrigin, kAliHLTComponentDataTypefOriginSize); | |
237 | out.append(tmp.c_str()); | |
9ce4bf4a | 238 | out.append(":"); |
3cde846d | 239 | tmp=""; |
240 | tmp.append(type.fID, kAliHLTComponentDataTypefIDsize); | |
241 | out.append(tmp.c_str()); | |
9ce4bf4a | 242 | } |
243 | return out; | |
244 | } | |
245 | ||
246 | ||
70ed7d01 | 247 | void* AliHLTComponent::AllocMemory( unsigned long size ) |
248 | { | |
249 | // see header file for function documentation | |
85869391 | 250 | if (fEnvironment.fAllocMemoryFunc) |
251 | return (*fEnvironment.fAllocMemoryFunc)(fEnvironment.fParam, size ); | |
9ce4bf4a | 252 | HLTFatal("no memory allocation handler registered"); |
85869391 | 253 | return NULL; |
254 | } | |
255 | ||
8ede8717 | 256 | int AliHLTComponent::MakeOutputDataBlockList( const vector<AliHLTComponentBlockData>& blocks, AliHLTUInt32_t* blockCount, |
70ed7d01 | 257 | AliHLTComponentBlockData** outputBlocks ) |
258 | { | |
259 | // see header file for function documentation | |
9ce4bf4a | 260 | if ( blockCount==NULL || outputBlocks==NULL ) |
2d7ff710 | 261 | return -EFAULT; |
fa2e9b7c | 262 | AliHLTUInt32_t count = blocks.size(); |
263 | if ( !count ) | |
264 | { | |
265 | *blockCount = 0; | |
266 | *outputBlocks = NULL; | |
267 | return 0; | |
268 | } | |
8ede8717 | 269 | *outputBlocks = reinterpret_cast<AliHLTComponentBlockData*>( AllocMemory( sizeof(AliHLTComponentBlockData)*count ) ); |
fa2e9b7c | 270 | if ( !*outputBlocks ) |
2d7ff710 | 271 | return -ENOMEM; |
ca8524df | 272 | for ( unsigned long i = 0; i < count; i++ ) { |
fa2e9b7c | 273 | (*outputBlocks)[i] = blocks[i]; |
ca8524df | 274 | if (blocks[i].fDataType==kAliHLTAnyDataType) { |
5f5b708b | 275 | (*outputBlocks)[i].fDataType=GetOutputDataType(); |
276 | /* data type was set to the output data type by the PubSub AliRoot | |
277 | Wrapper component, if data type of the block was ********:****. | |
278 | Now handled by the component base class in order to have same | |
279 | behavior when running embedded in AliRoot | |
ca8524df | 280 | memset((*outputBlocks)[i].fDataType.fID, '*', kAliHLTComponentDataTypefIDsize); |
281 | memset((*outputBlocks)[i].fDataType.fOrigin, '*', kAliHLTComponentDataTypefOriginSize); | |
5f5b708b | 282 | */ |
ca8524df | 283 | } |
284 | } | |
fa2e9b7c | 285 | *blockCount = count; |
286 | return 0; | |
287 | ||
288 | } | |
0c0c9d99 | 289 | |
70ed7d01 | 290 | int AliHLTComponent::GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd ) |
291 | { | |
292 | // see header file for function documentation | |
85869391 | 293 | if (fEnvironment.fGetEventDoneDataFunc) |
294 | return (*fEnvironment.fGetEventDoneDataFunc)(fEnvironment.fParam, fCurrentEvent, size, edd ); | |
295 | return -ENOSYS; | |
296 | } | |
297 | ||
8ede8717 | 298 | int AliHLTComponent::FindMatchingDataTypes(AliHLTComponent* pConsumer, vector<AliHLTComponentDataType>* tgtList) |
0c0c9d99 | 299 | { |
70ed7d01 | 300 | // see header file for function documentation |
0c0c9d99 | 301 | int iResult=0; |
302 | if (pConsumer) { | |
8ede8717 | 303 | vector<AliHLTComponentDataType> ctlist; |
0c0c9d99 | 304 | ((AliHLTComponent*)pConsumer)->GetInputDataTypes(ctlist); |
8ede8717 | 305 | vector<AliHLTComponentDataType>::iterator type=ctlist.begin(); |
5f5b708b | 306 | //AliHLTComponentDataType ouptdt=GetOutputDataType(); |
307 | //PrintDataTypeContent(ouptdt, "publisher \'%s\'"); | |
0c0c9d99 | 308 | while (type!=ctlist.end() && iResult==0) { |
5f5b708b | 309 | //PrintDataTypeContent((*type), "consumer \'%s\'"); |
9ce4bf4a | 310 | if ((*type)==GetOutputDataType() || |
311 | (*type)==kAliHLTAnyDataType) { | |
0c0c9d99 | 312 | if (tgtList) tgtList->push_back(*type); |
313 | iResult++; | |
9ce4bf4a | 314 | // this loop has to be changed in case of multiple output types |
0c0c9d99 | 315 | break; |
316 | } | |
317 | type++; | |
318 | } | |
319 | } else { | |
320 | iResult=-EINVAL; | |
321 | } | |
322 | return iResult; | |
323 | } | |
2d7ff710 | 324 | |
5f5b708b | 325 | void AliHLTComponent::PrintDataTypeContent(AliHLTComponentDataType& dt, const char* format) const |
326 | { | |
66043029 | 327 | // see header file for function documentation |
5f5b708b | 328 | const char* fmt="publisher \'%s\'"; |
329 | if (format) fmt=format; | |
330 | HLTMessage(fmt, (DataType2Text(dt)).c_str()); | |
331 | HLTMessage("%x %x %x %x %x %x %x %x : %x %x %x %x", | |
332 | dt.fID[0], | |
333 | dt.fID[1], | |
334 | dt.fID[2], | |
335 | dt.fID[3], | |
336 | dt.fID[4], | |
337 | dt.fID[5], | |
338 | dt.fID[6], | |
339 | dt.fID[7], | |
340 | dt.fOrigin[0], | |
341 | dt.fOrigin[1], | |
342 | dt.fOrigin[2], | |
343 | dt.fOrigin[3]); | |
344 | } | |
345 | ||
70ed7d01 | 346 | void AliHLTComponent::FillBlockData( AliHLTComponentBlockData& blockData ) const |
347 | { | |
348 | // see header file for function documentation | |
2d7ff710 | 349 | blockData.fStructSize = sizeof(blockData); |
350 | FillShmData( blockData.fShmKey ); | |
351 | blockData.fOffset = ~(AliHLTUInt32_t)0; | |
352 | blockData.fPtr = NULL; | |
353 | blockData.fSize = 0; | |
354 | FillDataType( blockData.fDataType ); | |
a655eae3 | 355 | blockData.fSpecification = kAliHLTVoidDataSpec; |
2d7ff710 | 356 | } |
357 | ||
70ed7d01 | 358 | void AliHLTComponent::FillShmData( AliHLTComponentShmData& shmData ) const |
359 | { | |
360 | // see header file for function documentation | |
2d7ff710 | 361 | shmData.fStructSize = sizeof(shmData); |
362 | shmData.fShmType = gkAliHLTComponentInvalidShmType; | |
363 | shmData.fShmID = gkAliHLTComponentInvalidShmID; | |
364 | } | |
365 | ||
70ed7d01 | 366 | void AliHLTComponent::FillDataType( AliHLTComponentDataType& dataType ) const |
367 | { | |
368 | // see header file for function documentation | |
ca8524df | 369 | dataType=kAliHLTAnyDataType; |
2d7ff710 | 370 | } |
371 | ||
70ed7d01 | 372 | void AliHLTComponent::CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt) |
373 | { | |
374 | // see header file for function documentation | |
2d7ff710 | 375 | memcpy(&tgtdt.fID[0], &srcdt.fID[0], kAliHLTComponentDataTypefIDsize); |
376 | memcpy(&tgtdt.fOrigin[0], &srcdt.fOrigin[0], kAliHLTComponentDataTypefOriginSize); | |
377 | } | |
378 | ||
70ed7d01 | 379 | void AliHLTComponent::SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin) |
380 | { | |
381 | // see header file for function documentation | |
2d7ff710 | 382 | tgtdt.fStructSize = sizeof(AliHLTComponentDataType); |
383 | memset(&tgtdt.fID[0], 0, kAliHLTComponentDataTypefIDsize); | |
384 | memset(&tgtdt.fOrigin[0], 0, kAliHLTComponentDataTypefOriginSize); | |
385 | ||
9ce4bf4a | 386 | if ((int)strlen(id)>kAliHLTComponentDataTypefIDsize) { |
2d7ff710 | 387 | HLTWarning("data type id %s is too long, truncated to %d", id, kAliHLTComponentDataTypefIDsize); |
388 | } | |
389 | strncpy(&tgtdt.fID[0], id, kAliHLTComponentDataTypefIDsize); | |
390 | ||
9ce4bf4a | 391 | if ((int)strlen(origin)>kAliHLTComponentDataTypefOriginSize) { |
2d7ff710 | 392 | HLTWarning("data type origin %s is too long, truncated to %d", origin, kAliHLTComponentDataTypefOriginSize); |
393 | } | |
394 | strncpy(&tgtdt.fOrigin[0], origin, kAliHLTComponentDataTypefOriginSize); | |
395 | } | |
9ce4bf4a | 396 | |
397 | void AliHLTComponent::FillEventData(AliHLTComponentEventData& evtData) | |
398 | { | |
70ed7d01 | 399 | // see header file for function documentation |
9ce4bf4a | 400 | memset(&evtData, 0, sizeof(AliHLTComponentEventData)); |
401 | evtData.fStructSize=sizeof(AliHLTComponentEventData); | |
402 | } | |
403 | ||
70ed7d01 | 404 | void AliHLTComponent::PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt) |
405 | { | |
406 | // see header file for function documentation | |
9ce4bf4a | 407 | TString msg; |
408 | msg.Form("AliHLTComponentDataType(%d): ID=\"", dt.fStructSize); | |
409 | for ( int i = 0; i < kAliHLTComponentDataTypefIDsize; i++ ) { | |
410 | if (dt.fID[i]!=0) msg+=dt.fID[i]; | |
411 | else msg+="\\0"; | |
412 | } | |
413 | msg+="\" Origin=\""; | |
414 | for ( int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++ ) { | |
415 | if (dt.fOrigin[i]!=0) msg+=dt.fOrigin[i]; | |
416 | else msg+="\\0"; | |
417 | } | |
418 | msg+="\""; | |
3cde846d | 419 | AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, msg.Data()); |
9ce4bf4a | 420 | } |
421 | ||
70ed7d01 | 422 | int AliHLTComponent::GetEventCount() const |
3cde846d | 423 | { |
70ed7d01 | 424 | // see header file for function documentation |
3cde846d | 425 | return fEventCount; |
426 | } | |
427 | ||
428 | int AliHLTComponent::IncrementEventCounter() | |
429 | { | |
70ed7d01 | 430 | // see header file for function documentation |
3cde846d | 431 | if (fEventCount>=0) fEventCount++; |
432 | return fEventCount; | |
433 | } | |
434 | ||
66043029 | 435 | int AliHLTComponent::GetNumberOfInputBlocks() const |
a655eae3 | 436 | { |
437 | // see header file for function documentation | |
438 | if (fpInputBlocks!=NULL) { | |
439 | return fCurrentEventData.fBlockCnt; | |
440 | } | |
441 | return 0; | |
442 | } | |
443 | ||
444 | const TObject* AliHLTComponent::GetFirstInputObject(const AliHLTComponentDataType& dt, | |
445 | const char* classname, | |
446 | int bForce) | |
447 | { | |
448 | // see header file for function documentation | |
90ebac25 | 449 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
a655eae3 | 450 | fSearchDataType=dt; |
451 | if (classname) fClassName=classname; | |
452 | else fClassName.clear(); | |
453 | int idx=FindInputBlock(fSearchDataType, 0); | |
8451168b | 454 | HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(dt).c_str()); |
a655eae3 | 455 | TObject* pObj=NULL; |
456 | if (idx>=0) { | |
457 | if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) { | |
458 | fCurrentInputBlock=idx; | |
459 | } else { | |
460 | } | |
461 | } | |
462 | return pObj; | |
463 | } | |
464 | ||
465 | const TObject* AliHLTComponent::GetFirstInputObject(const char* dtID, | |
466 | const char* dtOrigin, | |
467 | const char* classname, | |
468 | int bForce) | |
469 | { | |
470 | // see header file for function documentation | |
90ebac25 | 471 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
a655eae3 | 472 | AliHLTComponentDataType dt; |
473 | SetDataType(dt, dtID, dtOrigin); | |
474 | return GetFirstInputObject(dt, classname, bForce); | |
475 | } | |
476 | ||
477 | const TObject* AliHLTComponent::GetNextInputObject(int bForce) | |
478 | { | |
479 | // see header file for function documentation | |
90ebac25 | 480 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
a655eae3 | 481 | int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1); |
482 | //HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(fSearchDataType).c_str()); | |
483 | TObject* pObj=NULL; | |
484 | if (idx>=0) { | |
485 | if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) { | |
486 | fCurrentInputBlock=idx; | |
487 | } | |
488 | } | |
489 | return pObj; | |
490 | } | |
491 | ||
66043029 | 492 | int AliHLTComponent::FindInputBlock(const AliHLTComponentDataType& dt, int startIdx) const |
a655eae3 | 493 | { |
494 | // see header file for function documentation | |
495 | int iResult=-ENOENT; | |
496 | if (fpInputBlocks!=NULL) { | |
497 | int idx=startIdx<0?0:startIdx; | |
4b98eadb | 498 | for ( ; (UInt_t)idx<fCurrentEventData.fBlockCnt && iResult==-ENOENT; idx++) { |
a655eae3 | 499 | if (dt == kAliHLTAnyDataType || fpInputBlocks[idx].fDataType == dt) { |
500 | iResult=idx; | |
501 | } | |
502 | } | |
503 | } | |
504 | return iResult; | |
505 | } | |
506 | ||
507 | TObject* AliHLTComponent::CreateInputObject(int idx, int bForce) | |
508 | { | |
509 | // see header file for function documentation | |
510 | TObject* pObj=NULL; | |
511 | if (fpInputBlocks!=NULL) { | |
4b98eadb | 512 | if ((UInt_t)idx<fCurrentEventData.fBlockCnt) { |
a655eae3 | 513 | if (fpInputBlocks[idx].fPtr) { |
514 | AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr); | |
515 | if (firstWord==fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) { | |
8451168b | 516 | HLTDebug("create object from block %d size %d", idx, fpInputBlocks[idx].fSize); |
a655eae3 | 517 | AliHLTMessage msg(fpInputBlocks[idx].fPtr, fpInputBlocks[idx].fSize); |
66043029 | 518 | TClass* objclass=msg.GetClass(); |
519 | pObj=msg.ReadObject(objclass); | |
520 | if (pObj && objclass) { | |
521 | HLTDebug("object %p type %s created", pObj, objclass->GetName()); | |
a655eae3 | 522 | } else { |
523 | } | |
524 | } else { | |
525 | // } else if (bForce!=0) { | |
526 | HLTError("size missmatch: block size %d, indicated %d", fpInputBlocks[idx].fSize, firstWord+sizeof(AliHLTUInt32_t)); | |
527 | } | |
528 | } else { | |
529 | HLTFatal("block descriptor empty"); | |
530 | } | |
531 | } else { | |
532 | HLTError("index %d out of range %d", idx, fCurrentEventData.fBlockCnt); | |
533 | } | |
534 | } else { | |
535 | HLTError("no input blocks available"); | |
536 | } | |
537 | ||
538 | return pObj; | |
539 | } | |
540 | ||
541 | TObject* AliHLTComponent::GetInputObject(int idx, const char* classname, int bForce) | |
542 | { | |
543 | // see header file for function documentation | |
544 | if (fpInputObjects==NULL) { | |
545 | fpInputObjects=new TObjArray(fCurrentEventData.fBlockCnt); | |
546 | } | |
547 | TObject* pObj=NULL; | |
548 | if (fpInputObjects) { | |
549 | pObj=fpInputObjects->At(idx); | |
550 | if (pObj==NULL) { | |
551 | pObj=CreateInputObject(idx, bForce); | |
552 | if (pObj) { | |
553 | fpInputObjects->AddAt(pObj, idx); | |
554 | } | |
555 | } | |
556 | } else { | |
557 | HLTFatal("memory allocation failed: TObjArray of size %d", fCurrentEventData.fBlockCnt); | |
558 | } | |
559 | return pObj; | |
560 | } | |
561 | ||
8451168b | 562 | int AliHLTComponent::CleanupInputObjects() |
563 | { | |
66043029 | 564 | // see header file for function documentation |
8451168b | 565 | if (!fpInputObjects) return 0; |
566 | TObjArray* array=fpInputObjects; | |
567 | fpInputObjects=NULL; | |
568 | for (int i=0; i<array->GetEntries(); i++) { | |
569 | TObject* pObj=array->At(i); | |
570 | if (pObj) delete pObj; | |
571 | } | |
572 | delete array; | |
90ebac25 | 573 | return 0; |
8451168b | 574 | } |
575 | ||
a655eae3 | 576 | AliHLTComponentDataType AliHLTComponent::GetDataType(const TObject* pObject) |
577 | { | |
578 | // see header file for function documentation | |
90ebac25 | 579 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
a655eae3 | 580 | AliHLTComponentDataType dt=kAliHLTVoidDataType; |
581 | int idx=fCurrentInputBlock; | |
582 | if (pObject) { | |
583 | if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) { | |
584 | } else { | |
585 | HLTError("unknown object %p", pObject); | |
586 | } | |
587 | } | |
588 | if (idx>=0) { | |
4b98eadb | 589 | if ((UInt_t)idx<fCurrentEventData.fBlockCnt) { |
a655eae3 | 590 | dt=fpInputBlocks[idx].fDataType; |
591 | } else { | |
592 | HLTFatal("severe internal error, index out of range"); | |
593 | } | |
594 | } | |
595 | return dt; | |
596 | } | |
597 | ||
598 | AliHLTUInt32_t AliHLTComponent::GetSpecification(const TObject* pObject) | |
599 | { | |
600 | // see header file for function documentation | |
90ebac25 | 601 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
a655eae3 | 602 | AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec; |
603 | int idx=fCurrentInputBlock; | |
604 | if (pObject) { | |
605 | if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) { | |
606 | } else { | |
607 | HLTError("unknown object %p", pObject); | |
608 | } | |
609 | } | |
610 | if (idx>=0) { | |
4b98eadb | 611 | if ((UInt_t)idx<fCurrentEventData.fBlockCnt) { |
a655eae3 | 612 | iSpec=fpInputBlocks[idx].fSpecification; |
613 | } else { | |
614 | HLTFatal("severe internal error, index out of range"); | |
615 | } | |
616 | } | |
617 | return iSpec; | |
618 | } | |
619 | ||
620 | const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const AliHLTComponentDataType& dt) | |
621 | { | |
622 | // see header file for function documentation | |
90ebac25 | 623 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
a655eae3 | 624 | fSearchDataType=dt; |
625 | fClassName.clear(); | |
626 | int idx=FindInputBlock(fSearchDataType, 0); | |
627 | const AliHLTComponentBlockData* pBlock=NULL; | |
628 | if (idx>=0) { | |
629 | // check for fpInputBlocks pointer done in FindInputBlock | |
630 | pBlock=&fpInputBlocks[idx]; | |
631 | } | |
632 | return pBlock; | |
633 | } | |
634 | ||
635 | const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const char* dtID, | |
636 | const char* dtOrigin) | |
637 | { | |
638 | // see header file for function documentation | |
90ebac25 | 639 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
a655eae3 | 640 | AliHLTComponentDataType dt; |
641 | SetDataType(dt, dtID, dtOrigin); | |
642 | return GetFirstInputBlock(dt); | |
643 | } | |
644 | ||
645 | const AliHLTComponentBlockData* AliHLTComponent::GetNextInputBlock() | |
646 | { | |
647 | // see header file for function documentation | |
90ebac25 | 648 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
a655eae3 | 649 | int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1); |
650 | const AliHLTComponentBlockData* pBlock=NULL; | |
651 | if (idx>=0) { | |
652 | // check for fpInputBlocks pointer done in FindInputBlock | |
653 | pBlock=&fpInputBlocks[idx]; | |
654 | } | |
655 | return pBlock; | |
656 | } | |
657 | ||
66043029 | 658 | int AliHLTComponent::FindInputBlock(const AliHLTComponentBlockData* pBlock) const |
a655eae3 | 659 | { |
660 | // see header file for function documentation | |
661 | int iResult=-ENOENT; | |
662 | if (fpInputBlocks!=NULL) { | |
663 | if (pBlock) { | |
664 | if (pBlock>=fpInputBlocks && pBlock<fpInputBlocks+fCurrentEventData.fBlockCnt) { | |
132ca004 | 665 | iResult=(int)(pBlock-fpInputBlocks); |
a655eae3 | 666 | } |
667 | } else { | |
668 | iResult=-EINVAL; | |
669 | } | |
670 | } | |
671 | return iResult; | |
672 | } | |
673 | ||
674 | AliHLTUInt32_t AliHLTComponent::GetSpecification(const AliHLTComponentBlockData* pBlock) | |
675 | { | |
676 | // see header file for function documentation | |
90ebac25 | 677 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
a655eae3 | 678 | AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec; |
679 | int idx=fCurrentInputBlock; | |
680 | if (pBlock) { | |
681 | if (fpInputObjects==NULL || (idx=FindInputBlock(pBlock))>=0) { | |
682 | } else { | |
683 | HLTError("unknown Block %p", pBlock); | |
684 | } | |
685 | } | |
686 | if (idx>=0) { | |
687 | // check for fpInputBlocks pointer done in FindInputBlock | |
688 | iSpec=fpInputBlocks[idx].fSpecification; | |
689 | } | |
690 | return iSpec; | |
691 | } | |
692 | ||
693 | int AliHLTComponent::PushBack(TObject* pObject, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec) | |
694 | { | |
695 | // see header file for function documentation | |
90ebac25 | 696 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
a655eae3 | 697 | int iResult=0; |
698 | if (pObject) { | |
699 | AliHLTMessage msg(kMESS_OBJECT); | |
700 | msg.WriteObject(pObject); | |
701 | Int_t iMsgLength=msg.Length(); | |
702 | if (iMsgLength>0) { | |
703 | msg.SetLength(); // sets the length to the first (reserved) word | |
704 | iResult=InsertOutputBlock(msg.Buffer(), iMsgLength, dt, spec); | |
705 | if (iResult>=0) { | |
8451168b | 706 | HLTDebug("object %s (%p) size %d inserted to output", pObject->ClassName(), pObject, iMsgLength); |
a655eae3 | 707 | } |
708 | } else { | |
709 | HLTError("object serialization failed for object %p", pObject); | |
710 | iResult=-ENOMSG; | |
711 | } | |
712 | } else { | |
713 | iResult=-EINVAL; | |
714 | } | |
715 | return iResult; | |
716 | } | |
717 | ||
718 | int AliHLTComponent::PushBack(TObject* pObject, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec) | |
719 | { | |
720 | // see header file for function documentation | |
90ebac25 | 721 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
a655eae3 | 722 | AliHLTComponentDataType dt; |
723 | SetDataType(dt, dtID, dtOrigin); | |
724 | return PushBack(pObject, dt, spec); | |
725 | } | |
726 | ||
727 | int AliHLTComponent::PushBack(void* pBuffer, int iSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec) | |
728 | { | |
729 | // see header file for function documentation | |
90ebac25 | 730 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
a655eae3 | 731 | return InsertOutputBlock(pBuffer, iSize, dt, spec); |
732 | } | |
733 | ||
734 | int AliHLTComponent::PushBack(void* pBuffer, int iSize, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec) | |
735 | { | |
736 | // see header file for function documentation | |
90ebac25 | 737 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
a655eae3 | 738 | AliHLTComponentDataType dt; |
739 | SetDataType(dt, dtID, dtOrigin); | |
740 | return PushBack(pBuffer, iSize, dt, spec); | |
741 | } | |
742 | ||
743 | int AliHLTComponent::InsertOutputBlock(void* pBuffer, int iSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec) | |
744 | { | |
745 | // see header file for function documentation | |
746 | int iResult=0; | |
747 | if (pBuffer) { | |
7a5ccd96 | 748 | if (fpOutputBuffer && iSize<=(int)(fOutputBufferSize-fOutputBufferFilled)) { |
a655eae3 | 749 | AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled; |
750 | AliHLTComponentBlockData bd; | |
751 | FillBlockData( bd ); | |
752 | bd.fOffset = fOutputBufferFilled; | |
753 | bd.fPtr = pTgt; | |
754 | bd.fSize = iSize; | |
755 | bd.fDataType = dt; | |
756 | bd.fSpecification = spec; | |
757 | if (pBuffer!=NULL && pBuffer!=pTgt) { | |
758 | memcpy(pTgt, pBuffer, iSize); | |
4b98eadb | 759 | //AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)pBuffer); |
a655eae3 | 760 | //HLTDebug("copy %d bytes from %p to output buffer %p, first word %#x", iSize, pBuffer, pTgt, firstWord); |
761 | } | |
762 | fOutputBufferFilled+=bd.fSize; | |
763 | fOutputBlocks.push_back( bd ); | |
764 | //HLTDebug("buffer inserted to output: size %d data type %s spec %#x", iSize, DataType2Text(dt).c_str(), spec); | |
765 | } else { | |
766 | if (fpOutputBuffer) { | |
767 | HLTError("too little space in output buffer: %d, required %d", fOutputBufferSize-fOutputBufferFilled, iSize); | |
768 | } else { | |
769 | HLTError("output buffer not available"); | |
770 | } | |
771 | iResult=-ENOSPC; | |
772 | } | |
773 | } else { | |
774 | iResult=-EINVAL; | |
775 | } | |
776 | return iResult; | |
777 | } | |
778 | ||
8451168b | 779 | int AliHLTComponent::EstimateObjectSize(TObject* pObject) const |
780 | { | |
66043029 | 781 | // see header file for function documentation |
8451168b | 782 | if (!pObject) return -EINVAL; |
783 | AliHLTMessage msg(kMESS_OBJECT); | |
784 | msg.WriteObject(pObject); | |
785 | return msg.Length(); | |
786 | } | |
787 | ||
a655eae3 | 788 | int AliHLTComponent::CreateEventDoneData(AliHLTComponentEventDoneData edd) |
789 | { | |
790 | // see header file for function documentation | |
791 | int iResult=-ENOSYS; | |
792 | //#warning function not yet implemented | |
793 | HLTWarning("function not yet implemented"); | |
794 | return iResult; | |
795 | } | |
796 | ||
3cde846d | 797 | int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData, |
798 | const AliHLTComponentBlockData* blocks, | |
799 | AliHLTComponentTriggerData& trigData, | |
800 | AliHLTUInt8_t* outputPtr, | |
801 | AliHLTUInt32_t& size, | |
802 | AliHLTUInt32_t& outputBlockCnt, | |
803 | AliHLTComponentBlockData*& outputBlocks, | |
804 | AliHLTComponentEventDoneData*& edd ) | |
805 | { | |
70ed7d01 | 806 | // see header file for function documentation |
90ebac25 | 807 | ALIHLTCOMPONENT_BASE_STOPWATCH(); |
3cde846d | 808 | int iResult=0; |
809 | fCurrentEvent=evtData.fEventID; | |
a655eae3 | 810 | fCurrentEventData=evtData; |
811 | fpInputBlocks=blocks; | |
812 | fCurrentInputBlock=-1; | |
813 | fSearchDataType=kAliHLTAnyDataType; | |
814 | fpOutputBuffer=outputPtr; | |
815 | fOutputBufferSize=size; | |
816 | fOutputBufferFilled=0; | |
817 | fOutputBlocks.clear(); | |
818 | ||
819 | vector<AliHLTComponentBlockData> blockData; | |
90ebac25 | 820 | { // dont delete, sets the scope for the stopwatch guard |
821 | ALIHLTCOMPONENT_DA_STOPWATCH(); | |
822 | iResult=DoProcessing(evtData, blocks, trigData, outputPtr, size, blockData, edd); | |
823 | } // end of the scope of the stopwatch guard | |
a655eae3 | 824 | if (iResult>=0) { |
825 | if (fOutputBlocks.size()>0) { | |
826 | //HLTDebug("got %d block(s) via high level interface", fOutputBlocks.size()); | |
827 | if (blockData.size()>0) { | |
828 | HLTError("low level and high interface must not be mixed; use PushBack methods to insert data blocks"); | |
829 | iResult=-EFAULT; | |
830 | } else { | |
831 | iResult=MakeOutputDataBlockList(fOutputBlocks, &outputBlockCnt, &outputBlocks); | |
832 | size=fOutputBufferFilled; | |
833 | } | |
834 | } else { | |
835 | iResult=MakeOutputDataBlockList(blockData, &outputBlockCnt, &outputBlocks); | |
836 | } | |
837 | if (iResult<0) { | |
838 | HLTFatal("component %s (%p): can not convert output block descriptor list", GetComponentID(), this); | |
839 | } | |
840 | } | |
841 | if (iResult<0) { | |
842 | outputBlockCnt=0; | |
843 | outputBlocks=NULL; | |
844 | } | |
8451168b | 845 | CleanupInputObjects(); |
3cde846d | 846 | IncrementEventCounter(); |
847 | return iResult; | |
848 | } | |
a655eae3 | 849 | |
90ebac25 | 850 | AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard() |
851 | : | |
852 | fpStopwatch(NULL), | |
853 | fpPrec(NULL) | |
854 | { | |
855 | // standard constructor (not for use) | |
856 | } | |
857 | ||
858 | AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(TStopwatch* pStopwatch) | |
859 | : | |
860 | fpStopwatch(pStopwatch), | |
861 | fpPrec(NULL) | |
862 | { | |
863 | // constructor | |
864 | ||
865 | // check for already existing guard | |
866 | if (fgpCurrent) fpPrec=fgpCurrent; | |
867 | fgpCurrent=this; | |
868 | ||
869 | // stop the preceeding guard if it controls a different stopwatch | |
870 | int bStart=1; | |
871 | if (fpPrec && fpPrec!=this) bStart=fpPrec->Hold(fpStopwatch); | |
872 | ||
873 | // start the stopwatch if the current guard controls a different one | |
874 | if (fpStopwatch && bStart==1) fpStopwatch->Start(kFALSE); | |
875 | } | |
876 | ||
877 | AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(AliHLTStopwatchGuard&) | |
878 | : | |
879 | fpStopwatch(NULL), | |
880 | fpPrec(NULL) | |
881 | { | |
882 | // copy constructor (not for use) | |
883 | } | |
884 | ||
885 | AliHLTComponent::AliHLTStopwatchGuard* AliHLTComponent::AliHLTStopwatchGuard::fgpCurrent=NULL; | |
886 | ||
887 | AliHLTComponent::AliHLTStopwatchGuard::~AliHLTStopwatchGuard() | |
888 | { | |
889 | // destructor | |
890 | ||
891 | // resume the preceeding guard if it controls a different stopwatch | |
892 | int bStop=1; | |
893 | if (fpPrec && fpPrec!=this) bStop=fpPrec->Resume(fpStopwatch); | |
894 | ||
895 | // stop the stopwatch if the current guard controls a different one | |
896 | if (fpStopwatch && bStop==1) fpStopwatch->Stop(); | |
897 | ||
898 | // resume to the preceeding guard | |
899 | fgpCurrent=fpPrec; | |
900 | } | |
901 | ||
902 | int AliHLTComponent::AliHLTStopwatchGuard::Hold(TStopwatch* pSucc) | |
903 | { | |
904 | // see header file for function documentation | |
905 | if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Stop(); | |
906 | return fpStopwatch!=pSucc?1:0; | |
907 | } | |
908 | ||
909 | int AliHLTComponent::AliHLTStopwatchGuard::Resume(TStopwatch* pSucc) | |
910 | { | |
911 | // see header file for function documentation | |
912 | if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Start(kFALSE); | |
913 | return fpStopwatch!=pSucc?1:0; | |
914 | } | |
915 | ||
916 | int AliHLTComponent::SetStopwatch(TObject* pSW, AliHLTStopwatchType type) | |
917 | { | |
918 | // see header file for function documentation | |
919 | int iResult=0; | |
920 | if (pSW!=NULL && type<kSWTypeCount) { | |
921 | if (fpStopwatches) { | |
922 | TObject* pObj=fpStopwatches->At((int)type); | |
923 | if (pSW==NULL // explicit reset | |
924 | || pObj==NULL) { // explicit set | |
925 | fpStopwatches->AddAt(pSW, (int)type); | |
926 | } else if (pObj!=pSW) { | |
927 | HLTWarning("stopwatch %d already set, reset first", (int)type); | |
928 | iResult=-EBUSY; | |
929 | } | |
930 | } | |
931 | } else { | |
932 | iResult=-EINVAL; | |
933 | } | |
934 | return iResult; | |
935 | } | |
936 | ||
937 | int AliHLTComponent::SetStopwatches(TObjArray* pStopwatches) | |
938 | { | |
939 | // see header file for function documentation | |
940 | if (pStopwatches==NULL) return -EINVAL; | |
941 | ||
942 | int iResult=0; | |
943 | for (int i=0 ; i<(int)kSWTypeCount && pStopwatches->GetEntries(); i++) | |
944 | SetStopwatch(pStopwatches->At(i), (AliHLTStopwatchType)i); | |
945 | return iResult; | |
946 | } |