3 /**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
7 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
9 * for The ALICE HLT Project. *
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 **************************************************************************/
20 /** @file AliHLTComponent.cxx
21 @author Matthias Richter, Timm Steinbeck
23 @brief Base class implementation for HLT components. */
29 //#include "AliHLTStdIncludes.h"
30 #include "AliHLTComponent.h"
31 #include "AliHLTComponentHandler.h"
32 #include "AliHLTMessage.h"
34 #include "TObjArray.h"
36 #include "TStopwatch.h"
38 /** ROOT macro for the implementation of ROOT specific class methods */
39 ClassImp(AliHLTComponent);
41 /** stopwatch macro using the stopwatch guard */
42 #define ALIHLTCOMPONENT_STOPWATCH(type) AliHLTStopwatchGuard swguard(fpStopwatches!=NULL?reinterpret_cast<TStopwatch*>(fpStopwatches->At((int)type)):NULL)
43 //#define ALIHLTCOMPONENT_STOPWATCH(type)
45 /** stopwatch macro for operations of the base class */
46 #define ALIHLTCOMPONENT_BASE_STOPWATCH() ALIHLTCOMPONENT_STOPWATCH(kSWBase)
47 /** stopwatch macro for operations of the detector algorithm (DA) */
48 #define ALIHLTCOMPONENT_DA_STOPWATCH() ALIHLTCOMPONENT_STOPWATCH(kSWDA)
50 AliHLTComponent::AliHLTComponent()
58 fCurrentInputBlock(-1),
59 fSearchDataType(kAliHLTVoidDataType),
64 fOutputBufferFilled(0),
66 fpStopwatches(new TObjArray(kSWTypeCount))
68 // see header file for class documentation
70 // refer to README to build package
72 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
73 memset(&fEnvironment, 0, sizeof(AliHLTComponentEnvironment));
74 if (fgpComponentHandler)
75 fgpComponentHandler->ScheduleRegister(this);
76 //SetLocalLoggingLevel(kHLTLogDefault);
79 AliHLTComponent::AliHLTComponent(const AliHLTComponent&)
88 fCurrentInputBlock(-1),
89 fSearchDataType(kAliHLTVoidDataType),
94 fOutputBufferFilled(0),
98 // see header file for class documentation
99 HLTFatal("copy constructor untested");
102 AliHLTComponent& AliHLTComponent::operator=(const AliHLTComponent&)
104 // see header file for class documentation
105 HLTFatal("assignment operator untested");
109 AliHLTComponent::~AliHLTComponent()
111 // see header file for function documentation
112 CleanupInputObjects();
113 if (fpStopwatches!=NULL) delete fpStopwatches;
117 AliHLTComponentHandler* AliHLTComponent::fgpComponentHandler=NULL;
119 int AliHLTComponent::SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite)
121 // see header file for function documentation
123 if (fgpComponentHandler==NULL || bOverwrite!=0)
124 fgpComponentHandler=pCH;
130 int AliHLTComponent::UnsetGlobalComponentHandler()
132 // see header file for function documentation
133 return SetGlobalComponentHandler(NULL,1);
136 int AliHLTComponent::Init( AliHLTComponentEnvironment* environ, void* environParam, int argc, const char** argv )
138 // see header file for function documentation
141 memcpy(&fEnvironment, environ, sizeof(AliHLTComponentEnvironment));
142 fEnvironment.fParam=environParam;
144 const char** pArguments=NULL;
149 pArguments=new const char*[argc];
151 for (int i=0; i<argc && iResult>=0; i++) {
153 if (argument.IsNull()) continue;
156 if (argument.CompareTo("benchmark")==0) {
159 } else if (argument.CompareTo("loglevel")==0) {
160 if ((bMissingParam=(++i>=argc))) break;
161 TString parameter(argv[i]);
162 parameter.Remove(TString::kLeading, ' '); // remove all blanks
163 if (parameter.BeginsWith("0x") &&
164 parameter.Replace(0,2,"",0).IsHex()) {
165 AliHLTComponentLogSeverity loglevel=kHLTLogNone;
166 sscanf(parameter.Data(),"%x", (unsigned int*)&loglevel);
167 SetLocalLoggingLevel(loglevel);
169 HLTError("wrong parameter for argument %s, hex number expected", argument.Data());
173 pArguments[iNofChildArgs++]=argv[i];
181 HLTError("missing parameter for argument %s", argument.Data());
185 iResult=DoInit(iNofChildArgs, pArguments);
187 if (iResult>=0) fEventCount=0;
188 if (pArguments) delete [] pArguments;
192 int AliHLTComponent::Deinit()
194 // see header file for function documentation
200 int AliHLTComponent::DoInit( int argc, const char** argv )
202 // see header file for function documentation
203 if (argc==0 && argv==NULL) {
204 // this is currently just to get rid of the warning "unused parameter"
210 int AliHLTComponent::DoDeinit()
212 // see header file for function documentation
217 void AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2] ) const
219 // see header file for function documentation
220 memset( output, 0, kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2 );
221 strncat( output, type.fOrigin, kAliHLTComponentDataTypefOriginSize );
222 strcat( output, ":" );
223 strncat( output, type.fID, kAliHLTComponentDataTypefIDsize );
226 string AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type )
228 // see header file for function documentation
231 if (type==kAliHLTVoidDataType) {
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
239 tmp.append(type.fOrigin, kAliHLTComponentDataTypefOriginSize);
240 out.append(tmp.c_str());
243 tmp.append(type.fID, kAliHLTComponentDataTypefIDsize);
244 out.append(tmp.c_str());
250 void* AliHLTComponent::AllocMemory( unsigned long size )
252 // see header file for function documentation
253 if (fEnvironment.fAllocMemoryFunc)
254 return (*fEnvironment.fAllocMemoryFunc)(fEnvironment.fParam, size );
255 HLTFatal("no memory allocation handler registered");
259 int AliHLTComponent::MakeOutputDataBlockList( const vector<AliHLTComponentBlockData>& blocks, AliHLTUInt32_t* blockCount,
260 AliHLTComponentBlockData** outputBlocks )
262 // see header file for function documentation
263 if ( blockCount==NULL || outputBlocks==NULL )
265 AliHLTUInt32_t count = blocks.size();
269 *outputBlocks = NULL;
272 *outputBlocks = reinterpret_cast<AliHLTComponentBlockData*>( AllocMemory( sizeof(AliHLTComponentBlockData)*count ) );
273 if ( !*outputBlocks )
275 for ( unsigned long i = 0; i < count; i++ ) {
276 (*outputBlocks)[i] = blocks[i];
277 if (blocks[i].fDataType==kAliHLTAnyDataType) {
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
283 memset((*outputBlocks)[i].fDataType.fID, '*', kAliHLTComponentDataTypefIDsize);
284 memset((*outputBlocks)[i].fDataType.fOrigin, '*', kAliHLTComponentDataTypefOriginSize);
293 int AliHLTComponent::GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd )
295 // see header file for function documentation
296 if (fEnvironment.fGetEventDoneDataFunc)
297 return (*fEnvironment.fGetEventDoneDataFunc)(fEnvironment.fParam, fCurrentEvent, size, edd );
301 int AliHLTComponent::FindMatchingDataTypes(AliHLTComponent* pConsumer, vector<AliHLTComponentDataType>* tgtList)
303 // see header file for function documentation
306 vector<AliHLTComponentDataType> ctlist;
307 ((AliHLTComponent*)pConsumer)->GetInputDataTypes(ctlist);
308 vector<AliHLTComponentDataType>::iterator type=ctlist.begin();
309 //AliHLTComponentDataType ouptdt=GetOutputDataType();
310 //PrintDataTypeContent(ouptdt, "publisher \'%s\'");
311 while (type!=ctlist.end() && iResult==0) {
312 //PrintDataTypeContent((*type), "consumer \'%s\'");
313 if ((*type)==GetOutputDataType() ||
314 (*type)==kAliHLTAnyDataType) {
315 if (tgtList) tgtList->push_back(*type);
317 // this loop has to be changed in case of multiple output types
328 void AliHLTComponent::PrintDataTypeContent(AliHLTComponentDataType& dt, const char* format) const
330 // see header file for function documentation
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",
349 void AliHLTComponent::FillBlockData( AliHLTComponentBlockData& blockData ) const
351 // see header file for function documentation
352 blockData.fStructSize = sizeof(blockData);
353 FillShmData( blockData.fShmKey );
354 blockData.fOffset = ~(AliHLTUInt32_t)0;
355 blockData.fPtr = NULL;
357 FillDataType( blockData.fDataType );
358 blockData.fSpecification = kAliHLTVoidDataSpec;
361 void AliHLTComponent::FillShmData( AliHLTComponentShmData& shmData ) const
363 // see header file for function documentation
364 shmData.fStructSize = sizeof(shmData);
365 shmData.fShmType = gkAliHLTComponentInvalidShmType;
366 shmData.fShmID = gkAliHLTComponentInvalidShmID;
369 void AliHLTComponent::FillDataType( AliHLTComponentDataType& dataType ) const
371 // see header file for function documentation
372 dataType=kAliHLTAnyDataType;
375 void AliHLTComponent::CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt)
377 // see header file for function documentation
378 memcpy(&tgtdt.fID[0], &srcdt.fID[0], kAliHLTComponentDataTypefIDsize);
379 memcpy(&tgtdt.fOrigin[0], &srcdt.fOrigin[0], kAliHLTComponentDataTypefOriginSize);
382 void AliHLTComponent::SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin)
384 // see header file for function documentation
385 tgtdt.fStructSize = sizeof(AliHLTComponentDataType);
386 memset(&tgtdt.fID[0], 0, kAliHLTComponentDataTypefIDsize);
387 memset(&tgtdt.fOrigin[0], 0, kAliHLTComponentDataTypefOriginSize);
389 if ((int)strlen(id)>kAliHLTComponentDataTypefIDsize) {
390 HLTWarning("data type id %s is too long, truncated to %d", id, kAliHLTComponentDataTypefIDsize);
392 strncpy(&tgtdt.fID[0], id, kAliHLTComponentDataTypefIDsize);
394 if ((int)strlen(origin)>kAliHLTComponentDataTypefOriginSize) {
395 HLTWarning("data type origin %s is too long, truncated to %d", origin, kAliHLTComponentDataTypefOriginSize);
397 strncpy(&tgtdt.fOrigin[0], origin, kAliHLTComponentDataTypefOriginSize);
400 void AliHLTComponent::FillEventData(AliHLTComponentEventData& evtData)
402 // see header file for function documentation
403 memset(&evtData, 0, sizeof(AliHLTComponentEventData));
404 evtData.fStructSize=sizeof(AliHLTComponentEventData);
407 void AliHLTComponent::PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt)
409 // see header file for function documentation
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];
417 for ( int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++ ) {
418 if (dt.fOrigin[i]!=0) msg+=dt.fOrigin[i];
422 AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, msg.Data());
425 int AliHLTComponent::GetEventCount() const
427 // see header file for function documentation
431 int AliHLTComponent::IncrementEventCounter()
433 // see header file for function documentation
434 if (fEventCount>=0) fEventCount++;
438 int AliHLTComponent::GetNumberOfInputBlocks() const
440 // see header file for function documentation
441 if (fpInputBlocks!=NULL) {
442 return fCurrentEventData.fBlockCnt;
447 const TObject* AliHLTComponent::GetFirstInputObject(const AliHLTComponentDataType& dt,
448 const char* classname,
451 // see header file for function documentation
452 ALIHLTCOMPONENT_BASE_STOPWATCH();
454 if (classname) fClassName=classname;
455 else fClassName.clear();
456 int idx=FindInputBlock(fSearchDataType, 0, 1);
457 HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(dt).c_str());
460 if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) {
461 fCurrentInputBlock=idx;
468 const TObject* AliHLTComponent::GetFirstInputObject(const char* dtID,
469 const char* dtOrigin,
470 const char* classname,
473 // see header file for function documentation
474 ALIHLTCOMPONENT_BASE_STOPWATCH();
475 AliHLTComponentDataType dt;
476 SetDataType(dt, dtID, dtOrigin);
477 return GetFirstInputObject(dt, classname, bForce);
480 const TObject* AliHLTComponent::GetNextInputObject(int bForce)
482 // see header file for function documentation
483 ALIHLTCOMPONENT_BASE_STOPWATCH();
484 int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1, 1);
485 //HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(fSearchDataType).c_str());
488 if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) {
489 fCurrentInputBlock=idx;
495 int AliHLTComponent::FindInputBlock(const AliHLTComponentDataType& dt, int startIdx, int bObject) const
497 // see header file for function documentation
499 if (fpInputBlocks!=NULL) {
500 int idx=startIdx<0?0:startIdx;
501 for ( ; (UInt_t)idx<fCurrentEventData.fBlockCnt && iResult==-ENOENT; idx++) {
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;
507 if (dt == kAliHLTAnyDataType || fpInputBlocks[idx].fDataType == dt) {
515 TObject* AliHLTComponent::CreateInputObject(int idx, int bForce)
517 // see header file for function documentation
519 if (fpInputBlocks!=NULL) {
520 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
521 if (fpInputBlocks[idx].fPtr) {
522 AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr);
523 if (firstWord==fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) {
524 HLTDebug("create object from block %d size %d", idx, fpInputBlocks[idx].fSize);
525 AliHLTMessage msg(fpInputBlocks[idx].fPtr, fpInputBlocks[idx].fSize);
526 TClass* objclass=msg.GetClass();
527 pObj=msg.ReadObject(objclass);
528 if (pObj && objclass) {
529 HLTDebug("object %p type %s created", pObj, objclass->GetName());
533 } else if (bForce!=0) {
534 HLTError("size missmatch: block size %d, indicated %d", fpInputBlocks[idx].fSize, firstWord+sizeof(AliHLTUInt32_t));
537 HLTFatal("block descriptor empty");
540 HLTError("index %d out of range %d", idx, fCurrentEventData.fBlockCnt);
543 HLTError("no input blocks available");
549 TObject* AliHLTComponent::GetInputObject(int idx, const char* classname, int bForce)
551 // see header file for function documentation
552 if (fpInputObjects==NULL) {
553 fpInputObjects=new TObjArray(fCurrentEventData.fBlockCnt);
556 if (fpInputObjects) {
557 pObj=fpInputObjects->At(idx);
559 pObj=CreateInputObject(idx, bForce);
561 fpInputObjects->AddAt(pObj, idx);
565 HLTFatal("memory allocation failed: TObjArray of size %d", fCurrentEventData.fBlockCnt);
570 int AliHLTComponent::CleanupInputObjects()
572 // see header file for function documentation
573 if (!fpInputObjects) return 0;
574 TObjArray* array=fpInputObjects;
576 for (int i=0; i<array->GetEntries(); i++) {
577 TObject* pObj=array->At(i);
578 if (pObj) delete pObj;
584 AliHLTComponentDataType AliHLTComponent::GetDataType(const TObject* pObject)
586 // see header file for function documentation
587 ALIHLTCOMPONENT_BASE_STOPWATCH();
588 AliHLTComponentDataType dt=kAliHLTVoidDataType;
589 int idx=fCurrentInputBlock;
591 if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
593 HLTError("unknown object %p", pObject);
597 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
598 dt=fpInputBlocks[idx].fDataType;
600 HLTFatal("severe internal error, index out of range");
606 AliHLTUInt32_t AliHLTComponent::GetSpecification(const TObject* pObject)
608 // see header file for function documentation
609 ALIHLTCOMPONENT_BASE_STOPWATCH();
610 AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec;
611 int idx=fCurrentInputBlock;
613 if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
615 HLTError("unknown object %p", pObject);
619 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
620 iSpec=fpInputBlocks[idx].fSpecification;
622 HLTFatal("severe internal error, index out of range");
628 const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const AliHLTComponentDataType& dt)
630 // see header file for function documentation
631 ALIHLTCOMPONENT_BASE_STOPWATCH();
634 int idx=FindInputBlock(fSearchDataType, 0);
635 const AliHLTComponentBlockData* pBlock=NULL;
637 // check for fpInputBlocks pointer done in FindInputBlock
638 pBlock=&fpInputBlocks[idx];
639 fCurrentInputBlock=idx;
644 const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const char* dtID,
645 const char* dtOrigin)
647 // see header file for function documentation
648 ALIHLTCOMPONENT_BASE_STOPWATCH();
649 AliHLTComponentDataType dt;
650 SetDataType(dt, dtID, dtOrigin);
651 return GetFirstInputBlock(dt);
654 const AliHLTComponentBlockData* AliHLTComponent::GetNextInputBlock()
656 // see header file for function documentation
657 ALIHLTCOMPONENT_BASE_STOPWATCH();
658 int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1);
659 const AliHLTComponentBlockData* pBlock=NULL;
661 // check for fpInputBlocks pointer done in FindInputBlock
662 pBlock=&fpInputBlocks[idx];
663 fCurrentInputBlock=idx;
668 int AliHLTComponent::FindInputBlock(const AliHLTComponentBlockData* pBlock) const
670 // see header file for function documentation
672 if (fpInputBlocks!=NULL) {
674 if (pBlock>=fpInputBlocks && pBlock<fpInputBlocks+fCurrentEventData.fBlockCnt) {
675 iResult=(int)(pBlock-fpInputBlocks);
684 AliHLTUInt32_t AliHLTComponent::GetSpecification(const AliHLTComponentBlockData* pBlock)
686 // see header file for function documentation
687 ALIHLTCOMPONENT_BASE_STOPWATCH();
688 AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec;
689 int idx=fCurrentInputBlock;
691 if (fpInputObjects==NULL || (idx=FindInputBlock(pBlock))>=0) {
693 HLTError("unknown Block %p", pBlock);
697 // check for fpInputBlocks pointer done in FindInputBlock
698 iSpec=fpInputBlocks[idx].fSpecification;
703 int AliHLTComponent::PushBack(TObject* pObject, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec)
705 // see header file for function documentation
706 ALIHLTCOMPONENT_BASE_STOPWATCH();
709 AliHLTMessage msg(kMESS_OBJECT);
710 msg.WriteObject(pObject);
711 Int_t iMsgLength=msg.Length();
713 msg.SetLength(); // sets the length to the first (reserved) word
714 iResult=InsertOutputBlock(msg.Buffer(), iMsgLength, dt, spec);
716 HLTDebug("object %s (%p) size %d inserted to output", pObject->ClassName(), pObject, iMsgLength);
719 HLTError("object serialization failed for object %p", pObject);
728 int AliHLTComponent::PushBack(TObject* pObject, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec)
730 // see header file for function documentation
731 ALIHLTCOMPONENT_BASE_STOPWATCH();
732 AliHLTComponentDataType dt;
733 SetDataType(dt, dtID, dtOrigin);
734 return PushBack(pObject, dt, spec);
737 int AliHLTComponent::PushBack(void* pBuffer, int iSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec)
739 // see header file for function documentation
740 ALIHLTCOMPONENT_BASE_STOPWATCH();
741 return InsertOutputBlock(pBuffer, iSize, dt, spec);
744 int AliHLTComponent::PushBack(void* pBuffer, int iSize, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec)
746 // see header file for function documentation
747 ALIHLTCOMPONENT_BASE_STOPWATCH();
748 AliHLTComponentDataType dt;
749 SetDataType(dt, dtID, dtOrigin);
750 return PushBack(pBuffer, iSize, dt, spec);
753 int AliHLTComponent::InsertOutputBlock(void* pBuffer, int iSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec)
755 // see header file for function documentation
758 if (fpOutputBuffer && iSize<=(int)(fOutputBufferSize-fOutputBufferFilled)) {
759 AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled;
760 AliHLTComponentBlockData bd;
762 bd.fOffset = fOutputBufferFilled;
766 bd.fSpecification = spec;
767 if (pBuffer!=NULL && pBuffer!=pTgt) {
768 memcpy(pTgt, pBuffer, iSize);
769 //AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)pBuffer);
770 //HLTDebug("copy %d bytes from %p to output buffer %p, first word %#x", iSize, pBuffer, pTgt, firstWord);
772 fOutputBufferFilled+=bd.fSize;
773 fOutputBlocks.push_back( bd );
774 //HLTDebug("buffer inserted to output: size %d data type %s spec %#x", iSize, DataType2Text(dt).c_str(), spec);
776 if (fpOutputBuffer) {
777 HLTError("too little space in output buffer: %d, required %d", fOutputBufferSize-fOutputBufferFilled, iSize);
779 HLTError("output buffer not available");
789 int AliHLTComponent::EstimateObjectSize(TObject* pObject) const
791 // see header file for function documentation
792 if (!pObject) return -EINVAL;
793 AliHLTMessage msg(kMESS_OBJECT);
794 msg.WriteObject(pObject);
798 int AliHLTComponent::CreateEventDoneData(AliHLTComponentEventDoneData edd)
800 // see header file for function documentation
802 //#warning function not yet implemented
803 HLTWarning("function not yet implemented");
807 int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
808 const AliHLTComponentBlockData* blocks,
809 AliHLTComponentTriggerData& trigData,
810 AliHLTUInt8_t* outputPtr,
811 AliHLTUInt32_t& size,
812 AliHLTUInt32_t& outputBlockCnt,
813 AliHLTComponentBlockData*& outputBlocks,
814 AliHLTComponentEventDoneData*& edd )
816 // see header file for function documentation
817 ALIHLTCOMPONENT_BASE_STOPWATCH();
819 fCurrentEvent=evtData.fEventID;
820 fCurrentEventData=evtData;
821 fpInputBlocks=blocks;
822 fCurrentInputBlock=-1;
823 fSearchDataType=kAliHLTAnyDataType;
824 fpOutputBuffer=outputPtr;
825 fOutputBufferSize=size;
826 fOutputBufferFilled=0;
827 fOutputBlocks.clear();
829 vector<AliHLTComponentBlockData> blockData;
830 { // dont delete, sets the scope for the stopwatch guard
831 ALIHLTCOMPONENT_DA_STOPWATCH();
832 iResult=DoProcessing(evtData, blocks, trigData, outputPtr, size, blockData, edd);
833 } // end of the scope of the stopwatch guard
835 if (fOutputBlocks.size()>0) {
836 //HLTDebug("got %d block(s) via high level interface", fOutputBlocks.size());
837 if (blockData.size()>0) {
838 HLTError("low level and high interface must not be mixed; use PushBack methods to insert data blocks");
841 iResult=MakeOutputDataBlockList(fOutputBlocks, &outputBlockCnt, &outputBlocks);
842 size=fOutputBufferFilled;
845 iResult=MakeOutputDataBlockList(blockData, &outputBlockCnt, &outputBlocks);
848 HLTFatal("component %s (%p): can not convert output block descriptor list", GetComponentID(), this);
855 CleanupInputObjects();
856 IncrementEventCounter();
860 AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard()
865 // standard constructor (not for use)
868 AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(TStopwatch* pStopwatch)
870 fpStopwatch(pStopwatch),
875 // check for already existing guard
876 if (fgpCurrent) fpPrec=fgpCurrent;
879 // stop the preceeding guard if it controls a different stopwatch
881 if (fpPrec && fpPrec!=this) bStart=fpPrec->Hold(fpStopwatch);
883 // start the stopwatch if the current guard controls a different one
884 if (fpStopwatch && bStart==1) fpStopwatch->Start(kFALSE);
887 AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(AliHLTStopwatchGuard&)
892 // copy constructor (not for use)
895 AliHLTComponent::AliHLTStopwatchGuard* AliHLTComponent::AliHLTStopwatchGuard::fgpCurrent=NULL;
897 AliHLTComponent::AliHLTStopwatchGuard::~AliHLTStopwatchGuard()
901 // resume the preceeding guard if it controls a different stopwatch
903 if (fpPrec && fpPrec!=this) bStop=fpPrec->Resume(fpStopwatch);
905 // stop the stopwatch if the current guard controls a different one
906 if (fpStopwatch && bStop==1) fpStopwatch->Stop();
908 // resume to the preceeding guard
912 int AliHLTComponent::AliHLTStopwatchGuard::Hold(TStopwatch* pSucc)
914 // see header file for function documentation
915 if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Stop();
916 return fpStopwatch!=pSucc?1:0;
919 int AliHLTComponent::AliHLTStopwatchGuard::Resume(TStopwatch* pSucc)
921 // see header file for function documentation
922 if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Start(kFALSE);
923 return fpStopwatch!=pSucc?1:0;
926 int AliHLTComponent::SetStopwatch(TObject* pSW, AliHLTStopwatchType type)
928 // see header file for function documentation
930 if (pSW!=NULL && type<kSWTypeCount) {
932 TObject* pObj=fpStopwatches->At((int)type);
933 if (pSW==NULL // explicit reset
934 || pObj==NULL) { // explicit set
935 fpStopwatches->AddAt(pSW, (int)type);
936 } else if (pObj!=pSW) {
937 HLTWarning("stopwatch %d already set, reset first", (int)type);
947 int AliHLTComponent::SetStopwatches(TObjArray* pStopwatches)
949 // see header file for function documentation
950 if (pStopwatches==NULL) return -EINVAL;
953 for (int i=0 ; i<(int)kSWTypeCount && pStopwatches->GetEntries(); i++)
954 SetStopwatch(pStopwatches->At(i), (AliHLTStopwatchType)i);