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