]>
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 "TObjArray.h" | |
35 | #include "TObjectTable.h" | |
36 | #include "TClass.h" | |
37 | #include "TStopwatch.h" | |
38 | #include "AliHLTMemoryFile.h" | |
39 | ||
40 | /** ROOT macro for the implementation of ROOT specific class methods */ | |
41 | ClassImp(AliHLTComponent); | |
42 | ||
43 | /** stopwatch macro using the stopwatch guard */ | |
44 | #define ALIHLTCOMPONENT_STOPWATCH(type) AliHLTStopwatchGuard swguard(fpStopwatches!=NULL?reinterpret_cast<TStopwatch*>(fpStopwatches->At((int)type)):NULL) | |
45 | //#define ALIHLTCOMPONENT_STOPWATCH(type) | |
46 | ||
47 | /** stopwatch macro for operations of the base class */ | |
48 | #define ALIHLTCOMPONENT_BASE_STOPWATCH() ALIHLTCOMPONENT_STOPWATCH(kSWBase) | |
49 | /** stopwatch macro for operations of the detector algorithm (DA) */ | |
50 | #define ALIHLTCOMPONENT_DA_STOPWATCH() ALIHLTCOMPONENT_STOPWATCH(kSWDA) | |
51 | ||
52 | AliHLTComponent::AliHLTComponent() | |
53 | : | |
54 | fEnvironment(), | |
55 | fCurrentEvent(0), | |
56 | fEventCount(-1), | |
57 | fFailedEvents(0), | |
58 | fCurrentEventData(), | |
59 | fpInputBlocks(NULL), | |
60 | fCurrentInputBlock(-1), | |
61 | fSearchDataType(kAliHLTVoidDataType), | |
62 | fClassName(), | |
63 | fpInputObjects(NULL), | |
64 | fpOutputBuffer(NULL), | |
65 | fOutputBufferSize(0), | |
66 | fOutputBufferFilled(0), | |
67 | fOutputBlocks(), | |
68 | fpStopwatches(new TObjArray(kSWTypeCount)), | |
69 | fMemFiles(), | |
70 | fpRunDesc(NULL), | |
71 | fpDDLList(NULL) | |
72 | ||
73 | { | |
74 | // see header file for class documentation | |
75 | // or | |
76 | // refer to README to build package | |
77 | // or | |
78 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
79 | memset(&fEnvironment, 0, sizeof(AliHLTComponentEnvironment)); | |
80 | if (fgpComponentHandler) | |
81 | fgpComponentHandler->ScheduleRegister(this); | |
82 | //SetLocalLoggingLevel(kHLTLogDefault); | |
83 | } | |
84 | ||
85 | AliHLTComponent::AliHLTComponent(const AliHLTComponent&) | |
86 | : | |
87 | AliHLTLogging(), | |
88 | fEnvironment(), | |
89 | fCurrentEvent(0), | |
90 | fEventCount(-1), | |
91 | fFailedEvents(0), | |
92 | fCurrentEventData(), | |
93 | fpInputBlocks(NULL), | |
94 | fCurrentInputBlock(-1), | |
95 | fSearchDataType(kAliHLTVoidDataType), | |
96 | fClassName(), | |
97 | fpInputObjects(NULL), | |
98 | fpOutputBuffer(NULL), | |
99 | fOutputBufferSize(0), | |
100 | fOutputBufferFilled(0), | |
101 | fOutputBlocks(), | |
102 | fpStopwatches(NULL), | |
103 | fMemFiles(), | |
104 | fpRunDesc(NULL), | |
105 | fpDDLList(NULL) | |
106 | { | |
107 | // see header file for class documentation | |
108 | } | |
109 | ||
110 | AliHLTComponent& AliHLTComponent::operator=(const AliHLTComponent&) | |
111 | { | |
112 | // see header file for class documentation | |
113 | return *this; | |
114 | } | |
115 | ||
116 | AliHLTComponent::~AliHLTComponent() | |
117 | { | |
118 | // see header file for function documentation | |
119 | CleanupInputObjects(); | |
120 | if (fpStopwatches!=NULL) delete fpStopwatches; | |
121 | fpStopwatches=NULL; | |
122 | vector<AliHLTMemoryFile*>::iterator element=fMemFiles.begin(); | |
123 | while (element!=fMemFiles.end()) { | |
124 | if (*element) { | |
125 | if ((*element)->IsClosed()==0) { | |
126 | HLTWarning("memory file has not been closed, possible data loss or incomplete buffer"); | |
127 | // close but do not flush as we dont know whether the buffer is still valid | |
128 | (*element)->Close(0); | |
129 | } | |
130 | delete *element; | |
131 | *element=NULL; | |
132 | } | |
133 | element++; | |
134 | } | |
135 | } | |
136 | ||
137 | AliHLTComponentHandler* AliHLTComponent::fgpComponentHandler=NULL; | |
138 | ||
139 | int AliHLTComponent::SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite) | |
140 | { | |
141 | // see header file for function documentation | |
142 | int iResult=0; | |
143 | if (fgpComponentHandler==NULL || bOverwrite!=0) | |
144 | fgpComponentHandler=pCH; | |
145 | else | |
146 | iResult=-EPERM; | |
147 | return iResult; | |
148 | } | |
149 | ||
150 | int AliHLTComponent::UnsetGlobalComponentHandler() | |
151 | { | |
152 | // see header file for function documentation | |
153 | return SetGlobalComponentHandler(NULL,1); | |
154 | } | |
155 | ||
156 | int AliHLTComponent::Init( AliHLTComponentEnvironment* environ, void* environParam, int argc, const char** argv ) | |
157 | { | |
158 | // see header file for function documentation | |
159 | int iResult=0; | |
160 | if (environ) { | |
161 | memcpy(&fEnvironment, environ, sizeof(AliHLTComponentEnvironment)); | |
162 | fEnvironment.fParam=environParam; | |
163 | } | |
164 | const char** pArguments=NULL; | |
165 | int iNofChildArgs=0; | |
166 | TString argument=""; | |
167 | int bMissingParam=0; | |
168 | if (argc>0) { | |
169 | pArguments=new const char*[argc]; | |
170 | if (pArguments) { | |
171 | for (int i=0; i<argc && iResult>=0; i++) { | |
172 | argument=argv[i]; | |
173 | if (argument.IsNull()) continue; | |
174 | ||
175 | // benchmark | |
176 | if (argument.CompareTo("benchmark")==0) { | |
177 | ||
178 | // loglevel | |
179 | } else if (argument.CompareTo("loglevel")==0) { | |
180 | if ((bMissingParam=(++i>=argc))) break; | |
181 | TString parameter(argv[i]); | |
182 | parameter.Remove(TString::kLeading, ' '); // remove all blanks | |
183 | if (parameter.BeginsWith("0x") && | |
184 | parameter.Replace(0,2,"",0).IsHex()) { | |
185 | AliHLTComponentLogSeverity loglevel=kHLTLogNone; | |
186 | sscanf(parameter.Data(),"%x", (unsigned int*)&loglevel); | |
187 | SetLocalLoggingLevel(loglevel); | |
188 | } else { | |
189 | HLTError("wrong parameter for argument %s, hex number expected", argument.Data()); | |
190 | iResult=-EINVAL; | |
191 | } | |
192 | } else { | |
193 | pArguments[iNofChildArgs++]=argv[i]; | |
194 | } | |
195 | } | |
196 | } else { | |
197 | iResult=-ENOMEM; | |
198 | } | |
199 | } | |
200 | if (bMissingParam) { | |
201 | HLTError("missing parameter for argument %s", argument.Data()); | |
202 | iResult=-EINVAL; | |
203 | } | |
204 | if (iResult>=0) { | |
205 | iResult=DoInit(iNofChildArgs, pArguments); | |
206 | } | |
207 | if (iResult>=0) fEventCount=0; | |
208 | if (pArguments) delete [] pArguments; | |
209 | return iResult; | |
210 | } | |
211 | ||
212 | int AliHLTComponent::Deinit() | |
213 | { | |
214 | // see header file for function documentation | |
215 | int iResult=0; | |
216 | iResult=DoDeinit(); | |
217 | if (fpRunDesc) { | |
218 | HLTWarning("did not receive EOR for run %d", fpRunDesc->fRunNo); | |
219 | AliHLTRunDesc* pRunDesc=fpRunDesc; | |
220 | fpRunDesc=NULL; | |
221 | delete pRunDesc; | |
222 | } | |
223 | return iResult; | |
224 | } | |
225 | ||
226 | int AliHLTComponent::DoInit( int argc, const char** argv ) | |
227 | { | |
228 | // see header file for function documentation | |
229 | if (argc==0 && argv==NULL) { | |
230 | // this is currently just to get rid of the warning "unused parameter" | |
231 | } | |
232 | fEventCount=0; | |
233 | return 0; | |
234 | } | |
235 | ||
236 | int AliHLTComponent::DoDeinit() | |
237 | { | |
238 | // see header file for function documentation | |
239 | fEventCount=0; | |
240 | return 0; | |
241 | } | |
242 | ||
243 | int AliHLTComponent::GetOutputDataTypes(vector<AliHLTComponentDataType>& /*tgtList*/) | |
244 | { | |
245 | return 0; | |
246 | } | |
247 | ||
248 | void AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2] ) const | |
249 | { | |
250 | // see header file for function documentation | |
251 | memset( output, 0, kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2 ); | |
252 | strncat( output, type.fOrigin, kAliHLTComponentDataTypefOriginSize ); | |
253 | strcat( output, ":" ); | |
254 | strncat( output, type.fID, kAliHLTComponentDataTypefIDsize ); | |
255 | } | |
256 | ||
257 | string AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type ) | |
258 | { | |
259 | // see header file for function documentation | |
260 | string out(""); | |
261 | ||
262 | if (type==kAliHLTVoidDataType) { | |
263 | out="VOID:VOID"; | |
264 | } else { | |
265 | // some gymnastics in order to avoid a '0' which is part of either or both | |
266 | // ID and origin terminating the whole string. Unfortunately, string doesn't | |
267 | // stop appending at the '0' if the number of elements to append was | |
268 | // explicitely specified | |
269 | string tmp(""); | |
270 | tmp.append(type.fOrigin, kAliHLTComponentDataTypefOriginSize); | |
271 | out.append(tmp.c_str()); | |
272 | out.append(":"); | |
273 | tmp=""; | |
274 | tmp.append(type.fID, kAliHLTComponentDataTypefIDsize); | |
275 | out.append(tmp.c_str()); | |
276 | } | |
277 | return out; | |
278 | } | |
279 | ||
280 | ||
281 | void* AliHLTComponent::AllocMemory( unsigned long size ) | |
282 | { | |
283 | // see header file for function documentation | |
284 | if (fEnvironment.fAllocMemoryFunc) | |
285 | return (*fEnvironment.fAllocMemoryFunc)(fEnvironment.fParam, size ); | |
286 | HLTFatal("no memory allocation handler registered"); | |
287 | return NULL; | |
288 | } | |
289 | ||
290 | int AliHLTComponent::MakeOutputDataBlockList( const vector<AliHLTComponentBlockData>& blocks, AliHLTUInt32_t* blockCount, | |
291 | AliHLTComponentBlockData** outputBlocks ) | |
292 | { | |
293 | // see header file for function documentation | |
294 | if ( blockCount==NULL || outputBlocks==NULL ) | |
295 | return -EFAULT; | |
296 | AliHLTUInt32_t count = blocks.size(); | |
297 | if ( !count ) | |
298 | { | |
299 | *blockCount = 0; | |
300 | *outputBlocks = NULL; | |
301 | return 0; | |
302 | } | |
303 | *outputBlocks = reinterpret_cast<AliHLTComponentBlockData*>( AllocMemory( sizeof(AliHLTComponentBlockData)*count ) ); | |
304 | if ( !*outputBlocks ) | |
305 | return -ENOMEM; | |
306 | for ( unsigned long i = 0; i < count; i++ ) { | |
307 | (*outputBlocks)[i] = blocks[i]; | |
308 | if (blocks[i].fDataType==kAliHLTAnyDataType) { | |
309 | (*outputBlocks)[i].fDataType=GetOutputDataType(); | |
310 | /* data type was set to the output data type by the PubSub AliRoot | |
311 | Wrapper component, if data type of the block was ********:****. | |
312 | Now handled by the component base class in order to have same | |
313 | behavior when running embedded in AliRoot | |
314 | memset((*outputBlocks)[i].fDataType.fID, '*', kAliHLTComponentDataTypefIDsize); | |
315 | memset((*outputBlocks)[i].fDataType.fOrigin, '*', kAliHLTComponentDataTypefOriginSize); | |
316 | */ | |
317 | } | |
318 | } | |
319 | *blockCount = count; | |
320 | return 0; | |
321 | ||
322 | } | |
323 | ||
324 | int AliHLTComponent::GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd ) | |
325 | { | |
326 | // see header file for function documentation | |
327 | if (fEnvironment.fGetEventDoneDataFunc) | |
328 | return (*fEnvironment.fGetEventDoneDataFunc)(fEnvironment.fParam, fCurrentEvent, size, edd ); | |
329 | return -ENOSYS; | |
330 | } | |
331 | ||
332 | int AliHLTComponent::FindMatchingDataTypes(AliHLTComponent* pConsumer, vector<AliHLTComponentDataType>* tgtList) | |
333 | { | |
334 | // see header file for function documentation | |
335 | int iResult=0; | |
336 | if (pConsumer) { | |
337 | vector<AliHLTComponentDataType> ctlist; | |
338 | ((AliHLTComponent*)pConsumer)->GetInputDataTypes(ctlist); | |
339 | vector<AliHLTComponentDataType>::iterator type=ctlist.begin(); | |
340 | //AliHLTComponentDataType ouptdt=GetOutputDataType(); | |
341 | //PrintDataTypeContent(ouptdt, "publisher \'%s\'"); | |
342 | while (type!=ctlist.end() && iResult==0) { | |
343 | //PrintDataTypeContent((*type), "consumer \'%s\'"); | |
344 | if ((*type)==GetOutputDataType() || | |
345 | (*type)==kAliHLTAnyDataType) { | |
346 | if (tgtList) tgtList->push_back(*type); | |
347 | iResult++; | |
348 | // this loop has to be changed in case of multiple output types | |
349 | break; | |
350 | } | |
351 | type++; | |
352 | } | |
353 | } else { | |
354 | iResult=-EINVAL; | |
355 | } | |
356 | return iResult; | |
357 | } | |
358 | ||
359 | void AliHLTComponent::PrintDataTypeContent(AliHLTComponentDataType& dt, const char* format) const | |
360 | { | |
361 | // see header file for function documentation | |
362 | const char* fmt="publisher \'%s\'"; | |
363 | if (format) fmt=format; | |
364 | HLTMessage(fmt, (DataType2Text(dt)).c_str()); | |
365 | HLTMessage("%x %x %x %x %x %x %x %x : %x %x %x %x", | |
366 | dt.fID[0], | |
367 | dt.fID[1], | |
368 | dt.fID[2], | |
369 | dt.fID[3], | |
370 | dt.fID[4], | |
371 | dt.fID[5], | |
372 | dt.fID[6], | |
373 | dt.fID[7], | |
374 | dt.fOrigin[0], | |
375 | dt.fOrigin[1], | |
376 | dt.fOrigin[2], | |
377 | dt.fOrigin[3]); | |
378 | } | |
379 | ||
380 | void AliHLTComponent::FillBlockData( AliHLTComponentBlockData& blockData ) const | |
381 | { | |
382 | // see header file for function documentation | |
383 | blockData.fStructSize = sizeof(blockData); | |
384 | FillShmData( blockData.fShmKey ); | |
385 | blockData.fOffset = ~(AliHLTUInt32_t)0; | |
386 | blockData.fPtr = NULL; | |
387 | blockData.fSize = 0; | |
388 | FillDataType( blockData.fDataType ); | |
389 | blockData.fSpecification = kAliHLTVoidDataSpec; | |
390 | } | |
391 | ||
392 | void AliHLTComponent::FillShmData( AliHLTComponentShmData& shmData ) const | |
393 | { | |
394 | // see header file for function documentation | |
395 | shmData.fStructSize = sizeof(shmData); | |
396 | shmData.fShmType = gkAliHLTComponentInvalidShmType; | |
397 | shmData.fShmID = gkAliHLTComponentInvalidShmID; | |
398 | } | |
399 | ||
400 | void AliHLTComponent::FillDataType( AliHLTComponentDataType& dataType ) const | |
401 | { | |
402 | // see header file for function documentation | |
403 | dataType=kAliHLTAnyDataType; | |
404 | } | |
405 | ||
406 | void AliHLTComponent::CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt) | |
407 | { | |
408 | // see header file for function documentation | |
409 | memcpy(&tgtdt.fID[0], &srcdt.fID[0], kAliHLTComponentDataTypefIDsize); | |
410 | memcpy(&tgtdt.fOrigin[0], &srcdt.fOrigin[0], kAliHLTComponentDataTypefOriginSize); | |
411 | } | |
412 | ||
413 | void AliHLTComponent::SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin) | |
414 | { | |
415 | // see header file for function documentation | |
416 | tgtdt.fStructSize = sizeof(AliHLTComponentDataType); | |
417 | memset(&tgtdt.fID[0], 0, kAliHLTComponentDataTypefIDsize); | |
418 | memset(&tgtdt.fOrigin[0], 0, kAliHLTComponentDataTypefOriginSize); | |
419 | ||
420 | if ((int)strlen(id)>kAliHLTComponentDataTypefIDsize) { | |
421 | HLTWarning("data type id %s is too long, truncated to %d", id, kAliHLTComponentDataTypefIDsize); | |
422 | } | |
423 | strncpy(&tgtdt.fID[0], id, kAliHLTComponentDataTypefIDsize); | |
424 | ||
425 | if ((int)strlen(origin)>kAliHLTComponentDataTypefOriginSize) { | |
426 | HLTWarning("data type origin %s is too long, truncated to %d", origin, kAliHLTComponentDataTypefOriginSize); | |
427 | } | |
428 | strncpy(&tgtdt.fOrigin[0], origin, kAliHLTComponentDataTypefOriginSize); | |
429 | } | |
430 | ||
431 | void AliHLTComponent::FillEventData(AliHLTComponentEventData& evtData) | |
432 | { | |
433 | // see header file for function documentation | |
434 | memset(&evtData, 0, sizeof(AliHLTComponentEventData)); | |
435 | evtData.fStructSize=sizeof(AliHLTComponentEventData); | |
436 | } | |
437 | ||
438 | void AliHLTComponent::PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt) | |
439 | { | |
440 | // see header file for function documentation | |
441 | TString msg; | |
442 | msg.Form("AliHLTComponentDataType(%d): ID=\"", dt.fStructSize); | |
443 | for ( int i = 0; i < kAliHLTComponentDataTypefIDsize; i++ ) { | |
444 | if (dt.fID[i]!=0) msg+=dt.fID[i]; | |
445 | else msg+="\\0"; | |
446 | } | |
447 | msg+="\" Origin=\""; | |
448 | for ( int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++ ) { | |
449 | if (dt.fOrigin[i]!=0) msg+=dt.fOrigin[i]; | |
450 | else msg+="\\0"; | |
451 | } | |
452 | msg+="\""; | |
453 | AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, msg.Data()); | |
454 | } | |
455 | ||
456 | int AliHLTComponent::GetEventCount() const | |
457 | { | |
458 | // see header file for function documentation | |
459 | return fEventCount; | |
460 | } | |
461 | ||
462 | int AliHLTComponent::IncrementEventCounter() | |
463 | { | |
464 | // see header file for function documentation | |
465 | if (fEventCount>=0) fEventCount++; | |
466 | return fEventCount; | |
467 | } | |
468 | ||
469 | int AliHLTComponent::GetNumberOfInputBlocks() const | |
470 | { | |
471 | // see header file for function documentation | |
472 | if (fpInputBlocks!=NULL) { | |
473 | return fCurrentEventData.fBlockCnt; | |
474 | } | |
475 | return 0; | |
476 | } | |
477 | ||
478 | const TObject* AliHLTComponent::GetFirstInputObject(const AliHLTComponentDataType& dt, | |
479 | const char* classname, | |
480 | int bForce) | |
481 | { | |
482 | // see header file for function documentation | |
483 | ALIHLTCOMPONENT_BASE_STOPWATCH(); | |
484 | fSearchDataType=dt; | |
485 | if (classname) fClassName=classname; | |
486 | else fClassName.clear(); | |
487 | int idx=FindInputBlock(fSearchDataType, 0, 1); | |
488 | TObject* pObj=NULL; | |
489 | if (idx>=0) { | |
490 | HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(dt).c_str()); | |
491 | if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) { | |
492 | fCurrentInputBlock=idx; | |
493 | } else { | |
494 | } | |
495 | } | |
496 | return pObj; | |
497 | } | |
498 | ||
499 | const TObject* AliHLTComponent::GetFirstInputObject(const char* dtID, | |
500 | const char* dtOrigin, | |
501 | const char* classname, | |
502 | int bForce) | |
503 | { | |
504 | // see header file for function documentation | |
505 | ALIHLTCOMPONENT_BASE_STOPWATCH(); | |
506 | AliHLTComponentDataType dt; | |
507 | SetDataType(dt, dtID, dtOrigin); | |
508 | return GetFirstInputObject(dt, classname, bForce); | |
509 | } | |
510 | ||
511 | const TObject* AliHLTComponent::GetNextInputObject(int bForce) | |
512 | { | |
513 | // see header file for function documentation | |
514 | ALIHLTCOMPONENT_BASE_STOPWATCH(); | |
515 | int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1, 1); | |
516 | //HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(fSearchDataType).c_str()); | |
517 | TObject* pObj=NULL; | |
518 | if (idx>=0) { | |
519 | if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) { | |
520 | fCurrentInputBlock=idx; | |
521 | } | |
522 | } | |
523 | return pObj; | |
524 | } | |
525 | ||
526 | int AliHLTComponent::FindInputBlock(const AliHLTComponentDataType& dt, int startIdx, int bObject) const | |
527 | { | |
528 | // see header file for function documentation | |
529 | int iResult=-ENOENT; | |
530 | if (fpInputBlocks!=NULL) { | |
531 | int idx=startIdx<0?0:startIdx; | |
532 | for ( ; (UInt_t)idx<fCurrentEventData.fBlockCnt && iResult==-ENOENT; idx++) { | |
533 | if (bObject!=0) { | |
534 | if (fpInputBlocks[idx].fPtr==NULL) continue; | |
535 | AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr); | |
536 | if (firstWord!=fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) continue; | |
537 | } | |
538 | if (dt == kAliHLTAnyDataType || fpInputBlocks[idx].fDataType == dt) { | |
539 | iResult=idx; | |
540 | } | |
541 | } | |
542 | } | |
543 | return iResult; | |
544 | } | |
545 | ||
546 | TObject* AliHLTComponent::CreateInputObject(int idx, int bForce) | |
547 | { | |
548 | // see header file for function documentation | |
549 | TObject* pObj=NULL; | |
550 | if (fpInputBlocks!=NULL) { | |
551 | if ((UInt_t)idx<fCurrentEventData.fBlockCnt) { | |
552 | if (fpInputBlocks[idx].fPtr) { | |
553 | AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr); | |
554 | if (firstWord==fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) { | |
555 | HLTDebug("create object from block %d size %d", idx, fpInputBlocks[idx].fSize); | |
556 | AliHLTMessage msg(fpInputBlocks[idx].fPtr, fpInputBlocks[idx].fSize); | |
557 | TClass* objclass=msg.GetClass(); | |
558 | pObj=msg.ReadObject(objclass); | |
559 | if (pObj && objclass) { | |
560 | HLTDebug("object %p type %s created", pObj, objclass->GetName()); | |
561 | } else { | |
562 | } | |
563 | //} else { | |
564 | } else if (bForce!=0) { | |
565 | HLTError("size missmatch: block size %d, indicated %d", fpInputBlocks[idx].fSize, firstWord+sizeof(AliHLTUInt32_t)); | |
566 | } | |
567 | } else { | |
568 | HLTFatal("block descriptor empty"); | |
569 | } | |
570 | } else { | |
571 | HLTError("index %d out of range %d", idx, fCurrentEventData.fBlockCnt); | |
572 | } | |
573 | } else { | |
574 | HLTError("no input blocks available"); | |
575 | } | |
576 | ||
577 | return pObj; | |
578 | } | |
579 | ||
580 | TObject* AliHLTComponent::GetInputObject(int idx, const char* classname, int bForce) | |
581 | { | |
582 | // see header file for function documentation | |
583 | if (fpInputObjects==NULL) { | |
584 | fpInputObjects=new TObjArray(fCurrentEventData.fBlockCnt); | |
585 | } | |
586 | TObject* pObj=NULL; | |
587 | if (fpInputObjects) { | |
588 | pObj=fpInputObjects->At(idx); | |
589 | if (pObj==NULL) { | |
590 | pObj=CreateInputObject(idx, bForce); | |
591 | if (pObj) { | |
592 | fpInputObjects->AddAt(pObj, idx); | |
593 | } | |
594 | } | |
595 | } else { | |
596 | HLTFatal("memory allocation failed: TObjArray of size %d", fCurrentEventData.fBlockCnt); | |
597 | } | |
598 | return pObj; | |
599 | } | |
600 | ||
601 | int AliHLTComponent::CleanupInputObjects() | |
602 | { | |
603 | // see header file for function documentation | |
604 | if (!fpInputObjects) return 0; | |
605 | TObjArray* array=fpInputObjects; | |
606 | fpInputObjects=NULL; | |
607 | for (int i=0; i<array->GetEntries(); i++) { | |
608 | TObject* pObj=array->At(i); | |
609 | // grrr, garbage collection strikes back: When read via AliHLTMessage | |
610 | // (CreateInputObject), and written to a TFile afterwards, the | |
611 | // TFile::Close calls ROOOT's garbage collection. No clue why the | |
612 | // object ended up in the key list and needs to be deleted | |
613 | if (pObj && gObjectTable->PtrIsValid(pObj)) delete pObj; | |
614 | } | |
615 | delete array; | |
616 | return 0; | |
617 | } | |
618 | ||
619 | AliHLTComponentDataType AliHLTComponent::GetDataType(const TObject* pObject) | |
620 | { | |
621 | // see header file for function documentation | |
622 | ALIHLTCOMPONENT_BASE_STOPWATCH(); | |
623 | AliHLTComponentDataType dt=kAliHLTVoidDataType; | |
624 | int idx=fCurrentInputBlock; | |
625 | if (pObject) { | |
626 | if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) { | |
627 | } else { | |
628 | HLTError("unknown object %p", pObject); | |
629 | } | |
630 | } | |
631 | if (idx>=0) { | |
632 | if ((UInt_t)idx<fCurrentEventData.fBlockCnt) { | |
633 | dt=fpInputBlocks[idx].fDataType; | |
634 | } else { | |
635 | HLTFatal("severe internal error, index out of range"); | |
636 | } | |
637 | } | |
638 | return dt; | |
639 | } | |
640 | ||
641 | AliHLTUInt32_t AliHLTComponent::GetSpecification(const TObject* pObject) | |
642 | { | |
643 | // see header file for function documentation | |
644 | ALIHLTCOMPONENT_BASE_STOPWATCH(); | |
645 | AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec; | |
646 | int idx=fCurrentInputBlock; | |
647 | if (pObject) { | |
648 | if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) { | |
649 | } else { | |
650 | HLTError("unknown object %p", pObject); | |
651 | } | |
652 | } | |
653 | if (idx>=0) { | |
654 | if ((UInt_t)idx<fCurrentEventData.fBlockCnt) { | |
655 | iSpec=fpInputBlocks[idx].fSpecification; | |
656 | } else { | |
657 | HLTFatal("severe internal error, index out of range"); | |
658 | } | |
659 | } | |
660 | return iSpec; | |
661 | } | |
662 | ||
663 | const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const AliHLTComponentDataType& dt) | |
664 | { | |
665 | // see header file for function documentation | |
666 | ALIHLTCOMPONENT_BASE_STOPWATCH(); | |
667 | fSearchDataType=dt; | |
668 | fClassName.clear(); | |
669 | int idx=FindInputBlock(fSearchDataType, 0); | |
670 | const AliHLTComponentBlockData* pBlock=NULL; | |
671 | if (idx>=0) { | |
672 | // check for fpInputBlocks pointer done in FindInputBlock | |
673 | pBlock=&fpInputBlocks[idx]; | |
674 | fCurrentInputBlock=idx; | |
675 | } | |
676 | return pBlock; | |
677 | } | |
678 | ||
679 | const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const char* dtID, | |
680 | const char* dtOrigin) | |
681 | { | |
682 | // see header file for function documentation | |
683 | ALIHLTCOMPONENT_BASE_STOPWATCH(); | |
684 | AliHLTComponentDataType dt; | |
685 | SetDataType(dt, dtID, dtOrigin); | |
686 | return GetFirstInputBlock(dt); | |
687 | } | |
688 | ||
689 | const AliHLTComponentBlockData* AliHLTComponent::GetNextInputBlock() | |
690 | { | |
691 | // see header file for function documentation | |
692 | ALIHLTCOMPONENT_BASE_STOPWATCH(); | |
693 | int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1); | |
694 | const AliHLTComponentBlockData* pBlock=NULL; | |
695 | if (idx>=0) { | |
696 | // check for fpInputBlocks pointer done in FindInputBlock | |
697 | pBlock=&fpInputBlocks[idx]; | |
698 | fCurrentInputBlock=idx; | |
699 | } | |
700 | return pBlock; | |
701 | } | |
702 | ||
703 | int AliHLTComponent::FindInputBlock(const AliHLTComponentBlockData* pBlock) const | |
704 | { | |
705 | // see header file for function documentation | |
706 | int iResult=-ENOENT; | |
707 | if (fpInputBlocks!=NULL) { | |
708 | if (pBlock) { | |
709 | if (pBlock>=fpInputBlocks && pBlock<fpInputBlocks+fCurrentEventData.fBlockCnt) { | |
710 | iResult=(int)(pBlock-fpInputBlocks); | |
711 | } | |
712 | } else { | |
713 | iResult=-EINVAL; | |
714 | } | |
715 | } | |
716 | return iResult; | |
717 | } | |
718 | ||
719 | AliHLTUInt32_t AliHLTComponent::GetSpecification(const AliHLTComponentBlockData* pBlock) | |
720 | { | |
721 | // see header file for function documentation | |
722 | ALIHLTCOMPONENT_BASE_STOPWATCH(); | |
723 | AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec; | |
724 | int idx=fCurrentInputBlock; | |
725 | if (pBlock) { | |
726 | if (fpInputObjects==NULL || (idx=FindInputBlock(pBlock))>=0) { | |
727 | } else { | |
728 | HLTError("unknown Block %p", pBlock); | |
729 | } | |
730 | } | |
731 | if (idx>=0) { | |
732 | // check for fpInputBlocks pointer done in FindInputBlock | |
733 | iSpec=fpInputBlocks[idx].fSpecification; | |
734 | } | |
735 | return iSpec; | |
736 | } | |
737 | ||
738 | int AliHLTComponent::PushBack(TObject* pObject, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec, | |
739 | void* pHeader, int headerSize) | |
740 | { | |
741 | // see header file for function documentation | |
742 | ALIHLTCOMPONENT_BASE_STOPWATCH(); | |
743 | int iResult=0; | |
744 | if (pObject) { | |
745 | AliHLTMessage msg(kMESS_OBJECT); | |
746 | msg.WriteObject(pObject); | |
747 | Int_t iMsgLength=msg.Length(); | |
748 | if (iMsgLength>0) { | |
749 | msg.SetLength(); // sets the length to the first (reserved) word | |
750 | iResult=InsertOutputBlock(msg.Buffer(), iMsgLength, dt, spec, pHeader, headerSize); | |
751 | if (iResult>=0) { | |
752 | HLTDebug("object %s (%p) size %d inserted to output", pObject->ClassName(), pObject, iMsgLength); | |
753 | } | |
754 | } else { | |
755 | HLTError("object serialization failed for object %p", pObject); | |
756 | iResult=-ENOMSG; | |
757 | } | |
758 | } else { | |
759 | iResult=-EINVAL; | |
760 | } | |
761 | return iResult; | |
762 | } | |
763 | ||
764 | int AliHLTComponent::PushBack(TObject* pObject, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec, | |
765 | void* pHeader, int headerSize) | |
766 | { | |
767 | // see header file for function documentation | |
768 | ALIHLTCOMPONENT_BASE_STOPWATCH(); | |
769 | AliHLTComponentDataType dt; | |
770 | SetDataType(dt, dtID, dtOrigin); | |
771 | return PushBack(pObject, dt, spec, pHeader, headerSize); | |
772 | } | |
773 | ||
774 | int AliHLTComponent::PushBack(void* pBuffer, int iSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec, | |
775 | void* pHeader, int headerSize) | |
776 | { | |
777 | // see header file for function documentation | |
778 | ALIHLTCOMPONENT_BASE_STOPWATCH(); | |
779 | return InsertOutputBlock(pBuffer, iSize, dt, spec, pHeader, headerSize); | |
780 | } | |
781 | ||
782 | int AliHLTComponent::PushBack(void* pBuffer, int iSize, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec, | |
783 | void* pHeader, int headerSize) | |
784 | { | |
785 | // see header file for function documentation | |
786 | ALIHLTCOMPONENT_BASE_STOPWATCH(); | |
787 | AliHLTComponentDataType dt; | |
788 | SetDataType(dt, dtID, dtOrigin); | |
789 | return PushBack(pBuffer, iSize, dt, spec, pHeader, headerSize); | |
790 | } | |
791 | ||
792 | int AliHLTComponent::InsertOutputBlock(void* pBuffer, int iBufferSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec, | |
793 | void* pHeader, int iHeaderSize) | |
794 | { | |
795 | // see header file for function documentation | |
796 | int iResult=0; | |
797 | int iBlkSize = iBufferSize + iHeaderSize; | |
798 | if (pBuffer) { | |
799 | if (fpOutputBuffer && iBlkSize<=(int)(fOutputBufferSize-fOutputBufferFilled)) { | |
800 | AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled; | |
801 | AliHLTComponentBlockData bd; | |
802 | FillBlockData( bd ); | |
803 | bd.fOffset = fOutputBufferFilled; | |
804 | bd.fPtr = pTgt; | |
805 | bd.fSize = iBlkSize; | |
806 | bd.fDataType = dt; | |
807 | bd.fSpecification = spec; | |
808 | if (pHeader!=NULL && pHeader!=pTgt) { | |
809 | memcpy(pTgt, pHeader, iHeaderSize); | |
810 | } | |
811 | ||
812 | pTgt += (AliHLTUInt8_t) iHeaderSize; | |
813 | ||
814 | if (pBuffer!=NULL && pBuffer!=pTgt) { | |
815 | memcpy(pTgt, pBuffer, iBufferSize); | |
816 | ||
817 | //AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)pBuffer); | |
818 | //HLTDebug("copy %d bytes from %p to output buffer %p, first word %#x", iBufferSize, pBuffer, pTgt, firstWord); | |
819 | } | |
820 | fOutputBufferFilled+=bd.fSize; | |
821 | fOutputBlocks.push_back( bd ); | |
822 | //HLTDebug("buffer inserted to output: size %d data type %s spec %#x", iBlkSize, DataType2Text(dt).c_str(), spec); | |
823 | } else { | |
824 | if (fpOutputBuffer) { | |
825 | HLTError("too little space in output buffer: %d, required %d", fOutputBufferSize-fOutputBufferFilled, iBlkSize); | |
826 | } else { | |
827 | HLTError("output buffer not available"); | |
828 | } | |
829 | iResult=-ENOSPC; | |
830 | } | |
831 | } else { | |
832 | iResult=-EINVAL; | |
833 | } | |
834 | return iResult; | |
835 | } | |
836 | ||
837 | int AliHLTComponent::EstimateObjectSize(TObject* pObject) const | |
838 | { | |
839 | // see header file for function documentation | |
840 | if (!pObject) return -EINVAL; | |
841 | AliHLTMessage msg(kMESS_OBJECT); | |
842 | msg.WriteObject(pObject); | |
843 | return msg.Length(); | |
844 | } | |
845 | ||
846 | AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(int capacity, const char* dtID, | |
847 | const char* dtOrigin, | |
848 | AliHLTUInt32_t spec) | |
849 | { | |
850 | // see header file for function documentation | |
851 | ALIHLTCOMPONENT_BASE_STOPWATCH(); | |
852 | AliHLTComponentDataType dt; | |
853 | SetDataType(dt, dtID, dtOrigin); | |
854 | return CreateMemoryFile(capacity, dt, spec); | |
855 | } | |
856 | ||
857 | AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(int capacity, | |
858 | const AliHLTComponentDataType& dt, | |
859 | AliHLTUInt32_t spec) | |
860 | { | |
861 | // see header file for function documentation | |
862 | ALIHLTCOMPONENT_BASE_STOPWATCH(); | |
863 | AliHLTMemoryFile* pFile=NULL; | |
864 | if (capacity>=0 && capacity<=fOutputBufferSize-fOutputBufferFilled){ | |
865 | AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled; | |
866 | pFile=new AliHLTMemoryFile((char*)pTgt, capacity); | |
867 | if (pFile) { | |
868 | int nofBlocks=fOutputBlocks.size(); | |
869 | if (nofBlocks+1>fMemFiles.size()) { | |
870 | fMemFiles.resize(nofBlocks+1, NULL); | |
871 | } | |
872 | if (nofBlocks<fMemFiles.size()) { | |
873 | fMemFiles[nofBlocks]=pFile; | |
874 | AliHLTComponentBlockData bd; | |
875 | FillBlockData( bd ); | |
876 | bd.fOffset = fOutputBufferFilled; | |
877 | bd.fPtr = pTgt; | |
878 | bd.fSize = capacity; | |
879 | bd.fDataType = dt; | |
880 | bd.fSpecification = spec; | |
881 | fOutputBufferFilled+=bd.fSize; | |
882 | fOutputBlocks.push_back( bd ); | |
883 | } else { | |
884 | HLTError("can not allocate/grow object array"); | |
885 | pFile->Close(0); | |
886 | delete pFile; | |
887 | pFile=NULL; | |
888 | } | |
889 | } | |
890 | } else { | |
891 | HLTError("can not create memory file of size %d (%d available)", capacity, fOutputBufferSize-fOutputBufferFilled); | |
892 | } | |
893 | return pFile; | |
894 | } | |
895 | ||
896 | AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(const char* dtID, | |
897 | const char* dtOrigin, | |
898 | AliHLTUInt32_t spec, | |
899 | float capacity) | |
900 | { | |
901 | // see header file for function documentation | |
902 | ALIHLTCOMPONENT_BASE_STOPWATCH(); | |
903 | AliHLTComponentDataType dt; | |
904 | SetDataType(dt, dtID, dtOrigin); | |
905 | int size=fOutputBufferSize-fOutputBufferFilled; | |
906 | if (capacity<0 || capacity>1.0) { | |
907 | HLTError("invalid parameter: capacity %f", capacity); | |
908 | return NULL; | |
909 | } | |
910 | size=(int)(size*capacity); | |
911 | return CreateMemoryFile(size, dt, spec); | |
912 | } | |
913 | ||
914 | AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(const AliHLTComponentDataType& dt, | |
915 | AliHLTUInt32_t spec, | |
916 | float capacity) | |
917 | { | |
918 | // see header file for function documentation | |
919 | ALIHLTCOMPONENT_BASE_STOPWATCH(); | |
920 | int size=fOutputBufferSize-fOutputBufferFilled; | |
921 | if (capacity<0 || capacity>1.0) { | |
922 | HLTError("invalid parameter: capacity %f", capacity); | |
923 | return NULL; | |
924 | } | |
925 | size=(int)(size*capacity); | |
926 | return CreateMemoryFile(size, dt, spec); | |
927 | } | |
928 | ||
929 | int AliHLTComponent::Write(AliHLTMemoryFile* pFile, const TObject* pObject, | |
930 | const char* key, int option) | |
931 | { | |
932 | int iResult=0; | |
933 | if (pFile && pObject) { | |
934 | pFile->cd(); | |
935 | iResult=pObject->Write(key, option); | |
936 | if (iResult>0) { | |
937 | // success | |
938 | } else { | |
939 | iResult=-pFile->GetErrno(); | |
940 | if (iResult==-ENOSPC) { | |
941 | HLTError("error writing memory file, buffer too small"); | |
942 | } | |
943 | } | |
944 | } else { | |
945 | iResult=-EINVAL; | |
946 | } | |
947 | return iResult; | |
948 | } | |
949 | ||
950 | int AliHLTComponent::CloseMemoryFile(AliHLTMemoryFile* pFile) | |
951 | { | |
952 | int iResult=0; | |
953 | if (pFile) { | |
954 | vector<AliHLTMemoryFile*>::iterator element=fMemFiles.begin(); | |
955 | int i=0; | |
956 | while (element!=fMemFiles.end() && iResult>=0) { | |
957 | if (*element && *element==pFile) { | |
958 | iResult=pFile->Close(); | |
959 | ||
960 | // sync memory files and descriptors | |
961 | if (iResult>=0) { | |
962 | fOutputBlocks[i].fSize=(*element)->GetSize()+(*element)->GetHeaderSize(); | |
963 | } | |
964 | delete *element; | |
965 | *element=NULL; | |
966 | return iResult; | |
967 | } | |
968 | element++; i++; | |
969 | } | |
970 | HLTError("can not find memory file %p", pFile); | |
971 | iResult=-ENOENT; | |
972 | } else { | |
973 | iResult=-EINVAL; | |
974 | } | |
975 | return iResult; | |
976 | } | |
977 | ||
978 | int AliHLTComponent::CreateEventDoneData(AliHLTComponentEventDoneData edd) | |
979 | { | |
980 | // see header file for function documentation | |
981 | int iResult=-ENOSYS; | |
982 | //#warning function not yet implemented | |
983 | HLTWarning("function not yet implemented"); | |
984 | return iResult; | |
985 | } | |
986 | ||
987 | int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData, | |
988 | const AliHLTComponentBlockData* blocks, | |
989 | AliHLTComponentTriggerData& trigData, | |
990 | AliHLTUInt8_t* outputPtr, | |
991 | AliHLTUInt32_t& size, | |
992 | AliHLTUInt32_t& outputBlockCnt, | |
993 | AliHLTComponentBlockData*& outputBlocks, | |
994 | AliHLTComponentEventDoneData*& edd ) | |
995 | { | |
996 | // see header file for function documentation | |
997 | ALIHLTCOMPONENT_BASE_STOPWATCH(); | |
998 | int iResult=0; | |
999 | fCurrentEvent=evtData.fEventID; | |
1000 | fCurrentEventData=evtData; | |
1001 | fpInputBlocks=blocks; | |
1002 | fCurrentInputBlock=-1; | |
1003 | fSearchDataType=kAliHLTAnyDataType; | |
1004 | fpOutputBuffer=outputPtr; | |
1005 | fOutputBufferSize=size; | |
1006 | fOutputBufferFilled=0; | |
1007 | fOutputBlocks.clear(); | |
1008 | ||
1009 | // find special events | |
1010 | if (fpInputBlocks) { | |
1011 | for (int i=0; i<evtData.fBlockCnt && iResult>=0; i++) { | |
1012 | if (fpInputBlocks[i].fDataType==kAliHLTDataTypeSOR) { | |
1013 | // start of run | |
1014 | if (fpRunDesc==NULL) { | |
1015 | fpRunDesc=new AliHLTRunDesc; | |
1016 | if (fpRunDesc) { | |
1017 | if ((iResult=CopyStruct(fpRunDesc, sizeof(AliHLTRunDesc), i, "AliHLTRunDesc", "SOR"))>0) { | |
1018 | HLTDebug("set run decriptor, run no %d", fpRunDesc->fRunNo); | |
1019 | } | |
1020 | } else { | |
1021 | iResult=-ENOMEM; | |
1022 | } | |
1023 | } else { | |
1024 | HLTWarning("already received SOR event run no %d, ignoring SOR", fpRunDesc->fRunNo); | |
1025 | } | |
1026 | } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeEOR) { | |
1027 | if (fpRunDesc!=NULL) { | |
1028 | if (fpRunDesc) { | |
1029 | AliHLTRunDesc rundesc; | |
1030 | if ((iResult=CopyStruct(&rundesc, sizeof(AliHLTRunDesc), i, "AliHLTRunDesc", "SOR"))>0) { | |
1031 | if (fpRunDesc->fRunNo!=rundesc.fRunNo) { | |
1032 | HLTWarning("run no missmatch: SOR %d, EOR %d", fpRunDesc->fRunNo, rundesc.fRunNo); | |
1033 | } else { | |
1034 | HLTDebug("EOR run no %d", fpRunDesc->fRunNo); | |
1035 | } | |
1036 | } | |
1037 | AliHLTRunDesc* pRunDesc=fpRunDesc; | |
1038 | fpRunDesc=NULL; | |
1039 | delete pRunDesc; | |
1040 | } | |
1041 | } else { | |
1042 | HLTWarning("did not receive SOR, ignoring EOR"); | |
1043 | } | |
1044 | // end of run | |
1045 | } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeDDL) { | |
1046 | // DDL list | |
1047 | } | |
1048 | } | |
1049 | } | |
1050 | ||
1051 | vector<AliHLTComponentBlockData> blockData; | |
1052 | { // dont delete, sets the scope for the stopwatch guard | |
1053 | ALIHLTCOMPONENT_DA_STOPWATCH(); | |
1054 | iResult=DoProcessing(evtData, blocks, trigData, outputPtr, size, blockData, edd); | |
1055 | } // end of the scope of the stopwatch guard | |
1056 | if (iResult>=0) { | |
1057 | if (fOutputBlocks.size()>0) { | |
1058 | //HLTDebug("got %d block(s) via high level interface", fOutputBlocks.size()); | |
1059 | ||
1060 | // sync memory files and descriptors | |
1061 | vector<AliHLTMemoryFile*>::iterator element=fMemFiles.begin(); | |
1062 | int i=0; | |
1063 | while (element!=fMemFiles.end() && iResult>=0) { | |
1064 | if (*element) { | |
1065 | if ((*element)->IsClosed()==0) { | |
1066 | HLTWarning("memory file has not been closed, force flush"); | |
1067 | iResult=CloseMemoryFile(*element); | |
1068 | } | |
1069 | } | |
1070 | element++; i++; | |
1071 | } | |
1072 | ||
1073 | if (iResult>=0) { | |
1074 | // create the descriptor list | |
1075 | if (blockData.size()>0) { | |
1076 | HLTError("low level and high interface must not be mixed; use PushBack methods to insert data blocks"); | |
1077 | iResult=-EFAULT; | |
1078 | } else { | |
1079 | iResult=MakeOutputDataBlockList(fOutputBlocks, &outputBlockCnt, &outputBlocks); | |
1080 | size=fOutputBufferFilled; | |
1081 | } | |
1082 | } | |
1083 | } else { | |
1084 | iResult=MakeOutputDataBlockList(blockData, &outputBlockCnt, &outputBlocks); | |
1085 | } | |
1086 | if (iResult<0) { | |
1087 | HLTFatal("component %s (%p): can not convert output block descriptor list", GetComponentID(), this); | |
1088 | } | |
1089 | } | |
1090 | if (iResult<0) { | |
1091 | outputBlockCnt=0; | |
1092 | outputBlocks=NULL; | |
1093 | } | |
1094 | CleanupInputObjects(); | |
1095 | IncrementEventCounter(); | |
1096 | return iResult; | |
1097 | } | |
1098 | ||
1099 | AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard() | |
1100 | : | |
1101 | fpStopwatch(NULL), | |
1102 | fpPrec(NULL) | |
1103 | { | |
1104 | // standard constructor (not for use) | |
1105 | } | |
1106 | ||
1107 | AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(TStopwatch* pStopwatch) | |
1108 | : | |
1109 | fpStopwatch(pStopwatch), | |
1110 | fpPrec(NULL) | |
1111 | { | |
1112 | // constructor | |
1113 | ||
1114 | // check for already existing guard | |
1115 | if (fgpCurrent) fpPrec=fgpCurrent; | |
1116 | fgpCurrent=this; | |
1117 | ||
1118 | // stop the preceeding guard if it controls a different stopwatch | |
1119 | int bStart=1; | |
1120 | if (fpPrec && fpPrec!=this) bStart=fpPrec->Hold(fpStopwatch); | |
1121 | ||
1122 | // start the stopwatch if the current guard controls a different one | |
1123 | if (fpStopwatch && bStart==1) fpStopwatch->Start(kFALSE); | |
1124 | } | |
1125 | ||
1126 | AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(const AliHLTStopwatchGuard&) | |
1127 | : | |
1128 | fpStopwatch(NULL), | |
1129 | fpPrec(NULL) | |
1130 | { | |
1131 | // | |
1132 | // copy constructor not for use | |
1133 | // | |
1134 | } | |
1135 | ||
1136 | AliHLTComponent::AliHLTStopwatchGuard& AliHLTComponent::AliHLTStopwatchGuard::operator=(const AliHLTStopwatchGuard&) | |
1137 | { | |
1138 | // | |
1139 | // assignment operator not for use | |
1140 | // | |
1141 | fpStopwatch=NULL; | |
1142 | fpPrec=NULL; | |
1143 | return *this; | |
1144 | } | |
1145 | ||
1146 | AliHLTComponent::AliHLTStopwatchGuard* AliHLTComponent::AliHLTStopwatchGuard::fgpCurrent=NULL; | |
1147 | ||
1148 | AliHLTComponent::AliHLTStopwatchGuard::~AliHLTStopwatchGuard() | |
1149 | { | |
1150 | // destructor | |
1151 | ||
1152 | // resume the preceeding guard if it controls a different stopwatch | |
1153 | int bStop=1; | |
1154 | if (fpPrec && fpPrec!=this) bStop=fpPrec->Resume(fpStopwatch); | |
1155 | ||
1156 | // stop the stopwatch if the current guard controls a different one | |
1157 | if (fpStopwatch && bStop==1) fpStopwatch->Stop(); | |
1158 | ||
1159 | // resume to the preceeding guard | |
1160 | fgpCurrent=fpPrec; | |
1161 | } | |
1162 | ||
1163 | int AliHLTComponent::AliHLTStopwatchGuard::Hold(TStopwatch* pSucc) | |
1164 | { | |
1165 | // see header file for function documentation | |
1166 | if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Stop(); | |
1167 | return fpStopwatch!=pSucc?1:0; | |
1168 | } | |
1169 | ||
1170 | int AliHLTComponent::AliHLTStopwatchGuard::Resume(TStopwatch* pSucc) | |
1171 | { | |
1172 | // see header file for function documentation | |
1173 | if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Start(kFALSE); | |
1174 | return fpStopwatch!=pSucc?1:0; | |
1175 | } | |
1176 | ||
1177 | int AliHLTComponent::SetStopwatch(TObject* pSW, AliHLTStopwatchType type) | |
1178 | { | |
1179 | // see header file for function documentation | |
1180 | int iResult=0; | |
1181 | if (pSW!=NULL && type<kSWTypeCount) { | |
1182 | if (fpStopwatches) { | |
1183 | TObject* pObj=fpStopwatches->At((int)type); | |
1184 | if (pSW==NULL // explicit reset | |
1185 | || pObj==NULL) { // explicit set | |
1186 | fpStopwatches->AddAt(pSW, (int)type); | |
1187 | } else if (pObj!=pSW) { | |
1188 | HLTWarning("stopwatch %d already set, reset first", (int)type); | |
1189 | iResult=-EBUSY; | |
1190 | } | |
1191 | } | |
1192 | } else { | |
1193 | iResult=-EINVAL; | |
1194 | } | |
1195 | return iResult; | |
1196 | } | |
1197 | ||
1198 | int AliHLTComponent::SetStopwatches(TObjArray* pStopwatches) | |
1199 | { | |
1200 | // see header file for function documentation | |
1201 | if (pStopwatches==NULL) return -EINVAL; | |
1202 | ||
1203 | int iResult=0; | |
1204 | for (int i=0 ; i<(int)kSWTypeCount && pStopwatches->GetEntries(); i++) | |
1205 | SetStopwatch(pStopwatches->At(i), (AliHLTStopwatchType)i); | |
1206 | return iResult; | |
1207 | } | |
1208 | ||
1209 | AliHLTUInt32_t AliHLTComponent::GetRunNo() const | |
1210 | { | |
1211 | if (fpRunDesc==NULL) return 0; | |
1212 | return fpRunDesc->fRunNo; | |
1213 | } | |
1214 | ||
1215 | AliHLTUInt32_t AliHLTComponent::GetRunType() const | |
1216 | { | |
1217 | if (fpRunDesc==NULL) return 0; | |
1218 | return fpRunDesc->fRunType; | |
1219 | } | |
1220 | ||
1221 | int AliHLTComponent::CopyStruct(void* pStruct, int iStructSize, int iBlockNo, | |
1222 | const char* structname, const char* eventname) | |
1223 | { | |
1224 | int iResult=0; | |
1225 | if (pStruct!=NULL && iStructSize>sizeof(AliHLTUInt32_t)) { | |
1226 | if (fpInputBlocks!=NULL && iBlockNo<fCurrentEventData.fBlockCnt) { | |
1227 | AliHLTUInt32_t* pTgt=(AliHLTUInt32_t*)pStruct; | |
1228 | if (fpInputBlocks[iBlockNo].fPtr && fpInputBlocks[iBlockNo].fSize) { | |
1229 | AliHLTUInt8_t* pSrc=((AliHLTUInt8_t*)fpInputBlocks[iBlockNo].fPtr)+fpInputBlocks[iBlockNo].fOffset; | |
1230 | AliHLTUInt32_t copy=*((AliHLTUInt32_t*)pSrc); | |
1231 | if (fpInputBlocks[iBlockNo].fSize!=copy) { | |
1232 | HLTWarning("%s event: missmatch of block size (%d) and structure size (%d)", eventname, fpInputBlocks[iBlockNo].fSize, copy); | |
1233 | if (copy>fpInputBlocks[iBlockNo].fSize) copy=fpInputBlocks[iBlockNo].fSize; | |
1234 | } | |
1235 | if (copy!=iStructSize) { | |
1236 | HLTWarning("%s event: missmatch in %s version (data type version %d)", eventname, structname, ALIHLT_DATA_TYPES_VERSION); | |
1237 | if (copy>iStructSize) { | |
1238 | copy=iStructSize; | |
1239 | } else { | |
1240 | memset(pTgt, 0, iStructSize); | |
1241 | } | |
1242 | } | |
1243 | memcpy(pTgt, pSrc, copy); | |
1244 | *pTgt=iStructSize; | |
1245 | iResult=copy; | |
1246 | } else { | |
1247 | HLTWarning("%s event: missing data block", eventname); | |
1248 | } | |
1249 | } else { | |
1250 | iResult=-ENODATA; | |
1251 | } | |
1252 | } else { | |
1253 | HLTError("invalid struct"); | |
1254 | iResult=-EINVAL; | |
1255 | } | |
1256 | return iResult; | |
1257 | } |