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