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"
35 #include "TObjArray.h"
36 #include "TObjectTable.h"
38 #include "TStopwatch.h"
39 #include "AliHLTMemoryFile.h"
40 #include "AliHLTMisc.h"
43 /** ROOT macro for the implementation of ROOT specific class methods */
44 ClassImp(AliHLTComponent);
46 /** stopwatch macro using the stopwatch guard */
47 #define ALIHLTCOMPONENT_STOPWATCH(type) AliHLTStopwatchGuard swguard(fpStopwatches!=NULL?reinterpret_cast<TStopwatch*>(fpStopwatches->At((int)type)):NULL)
48 //#define ALIHLTCOMPONENT_STOPWATCH(type)
50 /** stopwatch macro for operations of the base class */
51 #define ALIHLTCOMPONENT_BASE_STOPWATCH() ALIHLTCOMPONENT_STOPWATCH(kSWBase)
52 /** stopwatch macro for operations of the detector algorithm (DA) */
53 #define ALIHLTCOMPONENT_DA_STOPWATCH() ALIHLTCOMPONENT_STOPWATCH(kSWDA)
55 AliHLTComponent::AliHLTComponent()
63 fCurrentInputBlock(-1),
64 fSearchDataType(kAliHLTVoidDataType),
69 fOutputBufferFilled(0),
71 fpStopwatches(new TObjArray(kSWTypeCount)),
75 fCDBSetRunNoFunc(false),
78 fRequireSteeringBlocks(false)
80 // see header file for class documentation
82 // refer to README to build package
84 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
85 memset(&fEnvironment, 0, sizeof(AliHLTComponentEnvironment));
86 if (fgpComponentHandler)
87 fgpComponentHandler->ScheduleRegister(this);
88 //SetLocalLoggingLevel(kHLTLogDefault);
91 AliHLTComponent::~AliHLTComponent()
93 // see header file for function documentation
94 if (fpBenchmark) delete fpBenchmark;
97 CleanupInputObjects();
98 if (fpStopwatches!=NULL) delete fpStopwatches;
100 AliHLTMemoryFilePList::iterator element=fMemFiles.begin();
101 while (element!=fMemFiles.end()) {
103 if ((*element)->IsClosed()==0) {
104 HLTWarning("memory file has not been closed, possible data loss or incomplete buffer");
105 // close but do not flush as we dont know whether the buffer is still valid
106 (*element)->CloseMemoryFile(0);
119 AliHLTComponentHandler* AliHLTComponent::fgpComponentHandler=NULL;
121 int AliHLTComponent::SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite)
123 // see header file for function documentation
125 if (fgpComponentHandler==NULL || bOverwrite!=0)
126 fgpComponentHandler=pCH;
132 int AliHLTComponent::UnsetGlobalComponentHandler()
134 // see header file for function documentation
135 return SetGlobalComponentHandler(NULL,1);
138 int AliHLTComponent::Init(const AliHLTComponentEnvironment* comenv, void* environParam, int argc, const char** argv )
140 // see header file for function documentation
141 HLTLogKeyword(GetComponentID());
144 memcpy(&fEnvironment, comenv, sizeof(AliHLTComponentEnvironment));
145 fEnvironment.fParam=environParam;
147 const char** pArguments=NULL;
152 pArguments=new const char*[argc];
154 for (int i=0; i<argc && iResult>=0; i++) {
156 if (argument.IsNull()) continue;
159 if (argument.CompareTo("benchmark")==0) {
162 } else if (argument.CompareTo("loglevel")==0) {
163 if ((bMissingParam=(++i>=argc))) break;
164 TString parameter(argv[i]);
165 parameter.Remove(TString::kLeading, ' '); // remove all blanks
166 if (parameter.BeginsWith("0x") &&
167 parameter.Replace(0,2,"",0).IsHex()) {
168 AliHLTComponentLogSeverity loglevel=kHLTLogNone;
169 sscanf(parameter.Data(),"%x", (unsigned int*)&loglevel);
170 SetLocalLoggingLevel(loglevel);
172 HLTError("wrong parameter for argument %s, hex number expected", argument.Data());
176 pArguments[iNofChildArgs++]=argv[i];
184 HLTError("missing parameter for argument %s", argument.Data());
188 iResult=DoInit(iNofChildArgs, pArguments);
193 // find out if the component wants to get the steering events
195 AliHLTComponentDataTypeList inputDt;
196 GetInputDataTypes(inputDt);
197 for (AliHLTComponentDataTypeList::iterator dt=inputDt.begin();
198 dt!=inputDt.end() && !fRequireSteeringBlocks;
200 fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeSOR);
201 fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeRunType);
202 fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeEOR);
203 fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeDDL);
204 fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeComponentStatistics);
207 if (pArguments) delete [] pArguments;
209 #if defined(__DEBUG) || defined(HLT_COMPONENT_STATISTICS)
210 // benchmarking stopwatch for the component statistics
211 fpBenchmark=new TStopwatch;
213 fpBenchmark->Start();
220 int AliHLTComponent::Deinit()
222 // see header file for function documentation
223 HLTLogKeyword(GetComponentID());
227 HLTWarning("did not receive EOR for run %d", fpRunDesc->fRunNo);
228 AliHLTRunDesc* pRunDesc=fpRunDesc;
236 int AliHLTComponent::InitCDB(const char* cdbPath, AliHLTComponentHandler* pHandler)
238 // see header file for function documentation
241 // I have to think about separating the library handling from the
242 // component handler. Requiring the component hanlder here is not
243 // the cleanest solution.
244 // We presume the library already to be loaded
246 AliHLTMiscInitCDB_t pFunc=(AliHLTMiscInitCDB_t)pHandler->FindSymbol(ALIHLTMISC_LIBRARY, ALIHLTMISC_INIT_CDB);
249 if (cdbPath && cdbPath[0]!=0) {
251 // very temporary fix, have to check for other formats
252 if (!path.BeginsWith("local://")) {
257 if ((iResult=(*pFunc)(path.Data()))>=0) {
258 if (!(fCDBSetRunNoFunc=pHandler->FindSymbol(ALIHLTMISC_LIBRARY, ALIHLTMISC_SET_CDB_RUNNO))) {
259 Message(NULL, kHLTLogWarning, "AliHLTComponent::InitCDB", "init CDB",
260 "can not find function to set CDB run no");
264 Message(NULL, kHLTLogError, "AliHLTComponent::InitCDB", "init CDB",
265 "can not find initialization function");
274 int AliHLTComponent::SetCDBRunNo(int runNo)
276 // see header file for function documentation
277 if (!fCDBSetRunNoFunc) return 0;
278 return (*((AliHLTMiscSetCDBRunNo_t)fCDBSetRunNoFunc))(runNo);
281 int AliHLTComponent::SetRunDescription(const AliHLTRunDesc* desc, const char* /*runType*/)
283 // see header file for function documentation
284 if (!desc) return -EINVAL;
285 if (desc->fStructSize!=sizeof(AliHLTRunDesc)) {
286 HLTError("invalid size of RunDesc struct (%ul)", desc->fStructSize);
291 fpRunDesc=new AliHLTRunDesc;
292 if (!fpRunDesc) return -ENOMEM;
293 *fpRunDesc=kAliHLTVoidRunDesc;
296 if (fpRunDesc->fRunNo!=kAliHLTVoidRunNo && fpRunDesc->fRunNo!=desc->fRunNo) {
297 HLTWarning("Run description has already been set");
300 SetCDBRunNo(fpRunDesc->fRunNo);
301 // TODO: we have to decide about the runType
305 int AliHLTComponent::SetComponentDescription(const char* desc)
307 // default implementation, childs can overload
311 TString descriptor=desc;
312 TObjArray* pTokens=descriptor.Tokenize(" ");
314 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
315 TString argument=((TObjString*)pTokens->At(i++))->GetString();
316 if (!argument || argument.IsNull()) continue;
319 if (argument.BeginsWith("-chainid")) {
320 argument.ReplaceAll("-chainid", "");
321 if (argument.BeginsWith("=")) {
322 fChainId=argument.Replace(0,1,"");
327 HLTWarning("unknown argument %s", argument.Data());
335 int AliHLTComponent::DoInit( int /*argc*/, const char** /*argv*/)
337 // default implementation, childs can overload
338 HLTLogKeyword("dummy");
342 int AliHLTComponent::DoDeinit()
344 // default implementation, childs can overload
345 HLTLogKeyword("dummy");
349 int AliHLTComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/)
351 // default implementation, childs can overload
352 HLTLogKeyword("dummy");
356 int AliHLTComponent::ReadPreprocessorValues(const char* /*modules*/)
358 // default implementation, childs can overload
359 HLTLogKeyword("dummy");
363 int AliHLTComponent::StartOfRun()
365 // default implementation, childs can overload
366 HLTLogKeyword("dummy");
370 int AliHLTComponent::EndOfRun()
372 // default implementation, childs can overload
373 HLTLogKeyword("dummy");
378 int AliHLTComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& /*tgtList*/)
380 // default implementation, childs can overload
381 HLTLogKeyword("dummy");
385 void AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2] ) const
387 // see header file for function documentation
388 memset( output, 0, kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2 );
389 strncat( output, type.fOrigin, kAliHLTComponentDataTypefOriginSize );
390 strcat( output, ":" );
391 strncat( output, type.fID, kAliHLTComponentDataTypefIDsize );
394 string AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, int mode)
396 // see header file for function documentation
402 for (i=0; i<kAliHLTComponentDataTypefOriginSize; i++) {
403 sprintf(tmp, "'%d", type.fOrigin[i]);
407 for (i=0; i<kAliHLTComponentDataTypefIDsize; i++) {
408 sprintf(tmp, "%d'", type.fID[i]);
417 for (i=0; i<kAliHLTComponentDataTypefOriginSize; i++) {
418 unsigned char* puc=(unsigned char*)type.fOrigin;
420 sprintf(tmp, "'\\%x", type.fOrigin[i]);
422 sprintf(tmp, "'%c", type.fOrigin[i]);
426 for (i=0; i<kAliHLTComponentDataTypefIDsize; i++) {
427 unsigned char* puc=(unsigned char*)type.fID;
429 sprintf(tmp, "\\%x'", type.fID[i]);
431 sprintf(tmp, "%c'", type.fID[i]);
437 if (type==kAliHLTVoidDataType) {
440 // some gymnastics in order to avoid a '0' which is part of either or both
441 // ID and origin terminating the whole string. Unfortunately, string doesn't
442 // stop appending at the '0' if the number of elements to append was
443 // explicitely specified
445 tmp.append(type.fOrigin, kAliHLTComponentDataTypefOriginSize);
446 out.append(tmp.c_str());
449 tmp.append(type.fID, kAliHLTComponentDataTypefIDsize);
450 out.append(tmp.c_str());
456 void* AliHLTComponent::AllocMemory( unsigned long size )
458 // see header file for function documentation
459 if (fEnvironment.fAllocMemoryFunc)
460 return (*fEnvironment.fAllocMemoryFunc)(fEnvironment.fParam, size );
461 HLTFatal("no memory allocation handler registered");
465 int AliHLTComponent::MakeOutputDataBlockList( const AliHLTComponentBlockDataList& blocks, AliHLTUInt32_t* blockCount,
466 AliHLTComponentBlockData** outputBlocks )
468 // see header file for function documentation
469 if ( blockCount==NULL || outputBlocks==NULL )
471 AliHLTUInt32_t count = blocks.size();
475 *outputBlocks = NULL;
478 *outputBlocks = reinterpret_cast<AliHLTComponentBlockData*>( AllocMemory( sizeof(AliHLTComponentBlockData)*count ) );
479 if ( !*outputBlocks )
481 for ( unsigned long i = 0; i < count; i++ ) {
482 (*outputBlocks)[i] = blocks[i];
483 if (MatchExactly(blocks[i].fDataType, kAliHLTAnyDataType)) {
484 (*outputBlocks)[i].fDataType=GetOutputDataType();
485 /* data type was set to the output data type by the PubSub AliRoot
486 Wrapper component, if data type of the block was ********:****.
487 Now handled by the component base class in order to have same
488 behavior when running embedded in AliRoot
489 memset((*outputBlocks)[i].fDataType.fID, '*', kAliHLTComponentDataTypefIDsize);
490 memset((*outputBlocks)[i].fDataType.fOrigin, '*', kAliHLTComponentDataTypefOriginSize);
499 int AliHLTComponent::GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd )
501 // see header file for function documentation
502 if (fEnvironment.fGetEventDoneDataFunc)
503 return (*fEnvironment.fGetEventDoneDataFunc)(fEnvironment.fParam, fCurrentEvent, size, edd );
507 int AliHLTComponent::FindMatchingDataTypes(AliHLTComponent* pConsumer, AliHLTComponentDataTypeList* tgtList)
509 // see header file for function documentation
512 AliHLTComponentDataTypeList itypes;
513 AliHLTComponentDataTypeList otypes;
514 otypes.push_back(GetOutputDataType());
515 if (otypes[0]==kAliHLTMultipleDataType) {
518 if ((count=GetOutputDataTypes(otypes))>0) {
519 } else if (GetComponentType()!=kSink) {
520 HLTWarning("component %s indicates multiple output data types but GetOutputDataTypes returns %d", GetComponentID(), count);
523 ((AliHLTComponent*)pConsumer)->GetInputDataTypes(itypes);
524 AliHLTComponentDataTypeList::iterator itype=itypes.begin();
525 while (itype!=itypes.end()) {
526 //PrintDataTypeContent((*itype), "consumer \'%s\'");
527 AliHLTComponentDataTypeList::iterator otype=otypes.begin();
528 while (otype!=otypes.end() && (*itype)!=(*otype)) otype++;
529 //if (otype!=otypes.end()) PrintDataTypeContent(*otype, "publisher \'%s\'");
530 if (otype!=otypes.end()) {
531 if (tgtList) tgtList->push_back(*itype);
542 void AliHLTComponent::PrintDataTypeContent(AliHLTComponentDataType& dt, const char* format)
544 // see header file for function documentation
545 const char* fmt="\'%s\'";
546 if (format) fmt=format;
547 AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, Form(fmt, (DataType2Text(dt)).c_str()));
548 AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL,
549 Form("%x %x %x %x %x %x %x %x : %x %x %x %x",
564 void AliHLTComponent::FillBlockData( AliHLTComponentBlockData& blockData )
566 // see header file for function documentation
567 blockData.fStructSize = sizeof(blockData);
568 FillShmData( blockData.fShmKey );
569 blockData.fOffset = ~(AliHLTUInt32_t)0;
570 blockData.fPtr = NULL;
572 FillDataType( blockData.fDataType );
573 blockData.fSpecification = kAliHLTVoidDataSpec;
576 void AliHLTComponent::FillShmData( AliHLTComponentShmData& shmData )
578 // see header file for function documentation
579 shmData.fStructSize = sizeof(shmData);
580 shmData.fShmType = gkAliHLTComponentInvalidShmType;
581 shmData.fShmID = gkAliHLTComponentInvalidShmID;
584 void AliHLTComponent::FillDataType( AliHLTComponentDataType& dataType )
586 // see header file for function documentation
587 dataType=kAliHLTAnyDataType;
590 void AliHLTComponent::CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt)
592 // see header file for function documentation
593 memcpy(&tgtdt.fID[0], &srcdt.fID[0], kAliHLTComponentDataTypefIDsize);
594 memcpy(&tgtdt.fOrigin[0], &srcdt.fOrigin[0], kAliHLTComponentDataTypefOriginSize);
597 void AliHLTComponent::SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin)
599 // see header file for function documentation
600 tgtdt.fStructSize=sizeof(AliHLTComponentDataType);
602 memset(&tgtdt.fID[0], 0, kAliHLTComponentDataTypefIDsize);
603 strncpy(&tgtdt.fID[0], id, strlen(id)<(size_t)kAliHLTComponentDataTypefIDsize?strlen(id):kAliHLTComponentDataTypefIDsize);
606 memset(&tgtdt.fOrigin[0], 0, kAliHLTComponentDataTypefOriginSize);
607 strncpy(&tgtdt.fOrigin[0], origin, strlen(origin)<(size_t)kAliHLTComponentDataTypefOriginSize?strlen(origin):kAliHLTComponentDataTypefOriginSize);
611 void AliHLTComponent::SetDataType(AliHLTComponentDataType& dt, AliHLTUInt64_t id, AliHLTUInt32_t origin)
613 // see header file for function documentation
614 dt.fStructSize=sizeof(AliHLTComponentDataType);
615 assert(kAliHLTComponentDataTypefIDsize==sizeof(id));
616 assert(kAliHLTComponentDataTypefOriginSize==sizeof(origin));
617 memcpy(&dt.fID, &id, kAliHLTComponentDataTypefIDsize);
618 memcpy(&dt.fOrigin, &origin, kAliHLTComponentDataTypefOriginSize);
621 void AliHLTComponent::FillEventData(AliHLTComponentEventData& evtData)
623 // see header file for function documentation
624 memset(&evtData, 0, sizeof(AliHLTComponentEventData));
625 evtData.fStructSize=sizeof(AliHLTComponentEventData);
628 void AliHLTComponent::PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt)
630 // see header file for function documentation
632 msg.Form("AliHLTComponentDataType(%d): ID=\"", dt.fStructSize);
633 for ( int i = 0; i < kAliHLTComponentDataTypefIDsize; i++ ) {
634 if (dt.fID[i]!=0) msg+=dt.fID[i];
638 for ( int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++ ) {
639 if (dt.fOrigin[i]!=0) msg+=dt.fOrigin[i];
643 AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, msg.Data());
646 int AliHLTComponent::GetEventCount() const
648 // see header file for function documentation
652 int AliHLTComponent::IncrementEventCounter()
654 // see header file for function documentation
655 if (fEventCount>=0) fEventCount++;
659 int AliHLTComponent::GetNumberOfInputBlocks() const
661 // see header file for function documentation
662 if (fpInputBlocks!=NULL) {
663 return fCurrentEventData.fBlockCnt;
668 const TObject* AliHLTComponent::GetFirstInputObject(const AliHLTComponentDataType& dt,
669 const char* classname,
672 // see header file for function documentation
673 ALIHLTCOMPONENT_BASE_STOPWATCH();
675 if (classname) fClassName=classname;
676 else fClassName.clear();
677 int idx=FindInputBlock(fSearchDataType, 0, 1);
680 HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(dt).c_str());
681 if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) {
682 fCurrentInputBlock=idx;
689 const TObject* AliHLTComponent::GetFirstInputObject(const char* dtID,
690 const char* dtOrigin,
691 const char* classname,
694 // see header file for function documentation
695 ALIHLTCOMPONENT_BASE_STOPWATCH();
696 AliHLTComponentDataType dt;
697 SetDataType(dt, dtID, dtOrigin);
698 return GetFirstInputObject(dt, classname, bForce);
701 const TObject* AliHLTComponent::GetNextInputObject(int bForce)
703 // see header file for function documentation
704 ALIHLTCOMPONENT_BASE_STOPWATCH();
705 int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1, 1);
706 //HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(fSearchDataType).c_str());
709 if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) {
710 fCurrentInputBlock=idx;
716 int AliHLTComponent::FindInputBlock(const AliHLTComponentDataType& dt, int startIdx, int bObject) const
718 // see header file for function documentation
720 if (fpInputBlocks!=NULL) {
721 int idx=startIdx<0?0:startIdx;
722 for ( ; (UInt_t)idx<fCurrentEventData.fBlockCnt && iResult==-ENOENT; idx++) {
723 if (dt!=fpInputBlocks[idx].fDataType) continue;
726 if (fpInputBlocks[idx].fPtr==NULL) continue;
727 AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr);
728 if (firstWord!=fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) continue;
736 TObject* AliHLTComponent::CreateInputObject(int idx, int bForce)
738 // see header file for function documentation
740 if (fpInputBlocks!=NULL) {
741 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
742 if (fpInputBlocks[idx].fPtr) {
743 AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr);
744 if (firstWord==fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) {
745 HLTDebug("create object from block %d size %d", idx, fpInputBlocks[idx].fSize);
746 AliHLTMessage msg(fpInputBlocks[idx].fPtr, fpInputBlocks[idx].fSize);
747 TClass* objclass=msg.GetClass();
748 pObj=msg.ReadObject(objclass);
749 if (pObj && objclass) {
750 HLTDebug("object %p type %s created", pObj, objclass->GetName());
754 } else if (bForce!=0) {
755 HLTError("size mismatch: block size %d, indicated %d", fpInputBlocks[idx].fSize, firstWord+sizeof(AliHLTUInt32_t));
758 HLTFatal("block descriptor empty");
761 HLTError("index %d out of range %d", idx, fCurrentEventData.fBlockCnt);
764 HLTError("no input blocks available");
770 TObject* AliHLTComponent::GetInputObject(int idx, const char* /*classname*/, int bForce)
772 // see header file for function documentation
773 if (fpInputObjects==NULL) {
774 fpInputObjects=new TObjArray(fCurrentEventData.fBlockCnt);
777 if (fpInputObjects) {
778 pObj=fpInputObjects->At(idx);
780 pObj=CreateInputObject(idx, bForce);
782 fpInputObjects->AddAt(pObj, idx);
786 HLTFatal("memory allocation failed: TObjArray of size %d", fCurrentEventData.fBlockCnt);
791 int AliHLTComponent::CleanupInputObjects()
793 // see header file for function documentation
794 if (!fpInputObjects) return 0;
795 TObjArray* array=fpInputObjects;
797 for (int i=0; i<array->GetEntries(); i++) {
798 TObject* pObj=array->At(i);
799 // grrr, garbage collection strikes back: When read via AliHLTMessage
800 // (CreateInputObject), and written to a TFile afterwards, the
801 // TFile::Close calls ROOOT's garbage collection. No clue why the
802 // object ended up in the key list and needs to be deleted
803 if (pObj && gObjectTable->PtrIsValid(pObj)) delete pObj;
809 AliHLTComponentDataType AliHLTComponent::GetDataType(const TObject* pObject)
811 // see header file for function documentation
812 ALIHLTCOMPONENT_BASE_STOPWATCH();
813 AliHLTComponentDataType dt=kAliHLTVoidDataType;
814 int idx=fCurrentInputBlock;
816 if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
818 HLTError("unknown object %p", pObject);
822 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
823 dt=fpInputBlocks[idx].fDataType;
825 HLTFatal("severe internal error, index out of range");
831 AliHLTUInt32_t AliHLTComponent::GetSpecification(const TObject* pObject)
833 // see header file for function documentation
834 ALIHLTCOMPONENT_BASE_STOPWATCH();
835 AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec;
836 int idx=fCurrentInputBlock;
838 if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
840 HLTError("unknown object %p", pObject);
844 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
845 iSpec=fpInputBlocks[idx].fSpecification;
847 HLTFatal("severe internal error, index out of range");
853 int AliHLTComponent::Forward(const TObject* pObject)
855 // see header file for function documentation
857 int idx=fCurrentInputBlock;
859 if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
861 HLTError("unknown object %p", pObject);
866 fOutputBlocks.push_back(fpInputBlocks[idx]);
871 int AliHLTComponent::Forward(const AliHLTComponentBlockData* pBlock)
873 // see header file for function documentation
875 int idx=fCurrentInputBlock;
877 if (fpInputObjects==NULL || (idx=FindInputBlock(pBlock))>=0) {
879 HLTError("unknown Block %p", pBlock);
884 // check for fpInputBlocks pointer done in FindInputBlock
885 fOutputBlocks.push_back(fpInputBlocks[idx]);
890 const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const AliHLTComponentDataType& dt)
892 // see header file for function documentation
893 ALIHLTCOMPONENT_BASE_STOPWATCH();
896 int idx=FindInputBlock(fSearchDataType, 0);
897 const AliHLTComponentBlockData* pBlock=NULL;
899 // check for fpInputBlocks pointer done in FindInputBlock
900 pBlock=&fpInputBlocks[idx];
901 fCurrentInputBlock=idx;
906 const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const char* dtID,
907 const char* dtOrigin)
909 // see header file for function documentation
910 ALIHLTCOMPONENT_BASE_STOPWATCH();
911 AliHLTComponentDataType dt;
912 SetDataType(dt, dtID, dtOrigin);
913 return GetFirstInputBlock(dt);
916 const AliHLTComponentBlockData* AliHLTComponent::GetInputBlock(int index)
918 // see header file for function documentation
919 ALIHLTCOMPONENT_BASE_STOPWATCH();
920 assert( 0 <= index and index < (int)fCurrentEventData.fBlockCnt );
921 return &fpInputBlocks[index];
924 const AliHLTComponentBlockData* AliHLTComponent::GetNextInputBlock()
926 // see header file for function documentation
927 ALIHLTCOMPONENT_BASE_STOPWATCH();
928 int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1);
929 const AliHLTComponentBlockData* pBlock=NULL;
931 // check for fpInputBlocks pointer done in FindInputBlock
932 pBlock=&fpInputBlocks[idx];
933 fCurrentInputBlock=idx;
938 int AliHLTComponent::FindInputBlock(const AliHLTComponentBlockData* pBlock) const
940 // see header file for function documentation
942 if (fpInputBlocks!=NULL) {
944 if (pBlock>=fpInputBlocks && pBlock<fpInputBlocks+fCurrentEventData.fBlockCnt) {
945 iResult=(int)(pBlock-fpInputBlocks);
954 AliHLTUInt32_t AliHLTComponent::GetSpecification(const AliHLTComponentBlockData* pBlock)
956 // see header file for function documentation
957 ALIHLTCOMPONENT_BASE_STOPWATCH();
958 AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec;
959 int idx=fCurrentInputBlock;
961 if (fpInputObjects==NULL || (idx=FindInputBlock(pBlock))>=0) {
963 HLTError("unknown Block %p", pBlock);
967 // check for fpInputBlocks pointer done in FindInputBlock
968 iSpec=fpInputBlocks[idx].fSpecification;
973 int AliHLTComponent::PushBack(TObject* pObject, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
974 void* pHeader, int headerSize)
976 // see header file for function documentation
977 ALIHLTCOMPONENT_BASE_STOPWATCH();
980 AliHLTMessage msg(kMESS_OBJECT);
981 msg.WriteObject(pObject);
982 Int_t iMsgLength=msg.Length();
984 msg.SetLength(); // sets the length to the first (reserved) word
985 iResult=InsertOutputBlock(msg.Buffer(), iMsgLength, dt, spec, pHeader, headerSize);
987 HLTDebug("object %s (%p) size %d inserted to output", pObject->ClassName(), pObject, iMsgLength);
990 HLTError("object serialization failed for object %p", pObject);
999 int AliHLTComponent::PushBack(TObject* pObject, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec,
1000 void* pHeader, int headerSize)
1002 // see header file for function documentation
1003 ALIHLTCOMPONENT_BASE_STOPWATCH();
1004 AliHLTComponentDataType dt;
1005 SetDataType(dt, dtID, dtOrigin);
1006 return PushBack(pObject, dt, spec, pHeader, headerSize);
1009 int AliHLTComponent::PushBack(void* pBuffer, int iSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
1010 void* pHeader, int headerSize)
1012 // see header file for function documentation
1013 ALIHLTCOMPONENT_BASE_STOPWATCH();
1014 return InsertOutputBlock(pBuffer, iSize, dt, spec, pHeader, headerSize);
1017 int AliHLTComponent::PushBack(void* pBuffer, int iSize, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec,
1018 void* pHeader, int headerSize)
1020 // see header file for function documentation
1021 ALIHLTCOMPONENT_BASE_STOPWATCH();
1022 AliHLTComponentDataType dt;
1023 SetDataType(dt, dtID, dtOrigin);
1024 return PushBack(pBuffer, iSize, dt, spec, pHeader, headerSize);
1027 int AliHLTComponent::InsertOutputBlock(void* pBuffer, int iBufferSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
1028 void* pHeader, int iHeaderSize)
1030 // see header file for function documentation
1032 int iBlkSize = iBufferSize + iHeaderSize;
1034 if (fpOutputBuffer && iBlkSize<=(int)(fOutputBufferSize-fOutputBufferFilled)) {
1035 AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled;
1036 AliHLTComponentBlockData bd;
1037 FillBlockData( bd );
1038 bd.fOffset = fOutputBufferFilled;
1039 bd.fSize = iBlkSize;
1041 bd.fSpecification = spec;
1042 if (pHeader!=NULL && pHeader!=pTgt) {
1043 memcpy(pTgt, pHeader, iHeaderSize);
1046 pTgt += (AliHLTUInt8_t) iHeaderSize;
1048 if (pBuffer!=NULL && pBuffer!=pTgt) {
1049 memcpy(pTgt, pBuffer, iBufferSize);
1051 //AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)pBuffer);
1052 //HLTDebug("copy %d bytes from %p to output buffer %p, first word %#x", iBufferSize, pBuffer, pTgt, firstWord);
1054 fOutputBufferFilled+=bd.fSize;
1055 fOutputBlocks.push_back( bd );
1056 //HLTDebug("buffer inserted to output: size %d data type %s spec %#x", iBlkSize, DataType2Text(dt).c_str(), spec);
1058 if (fpOutputBuffer) {
1059 HLTError("too little space in output buffer: %d, required %d", fOutputBufferSize-fOutputBufferFilled, iBlkSize);
1061 HLTError("output buffer not available");
1071 int AliHLTComponent::EstimateObjectSize(TObject* pObject) const
1073 // see header file for function documentation
1074 if (!pObject) return -EINVAL;
1075 AliHLTMessage msg(kMESS_OBJECT);
1076 msg.WriteObject(pObject);
1077 return msg.Length();
1080 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(int capacity, const char* dtID,
1081 const char* dtOrigin,
1082 AliHLTUInt32_t spec)
1084 // see header file for function documentation
1085 ALIHLTCOMPONENT_BASE_STOPWATCH();
1086 AliHLTComponentDataType dt;
1087 SetDataType(dt, dtID, dtOrigin);
1088 return CreateMemoryFile(capacity, dt, spec);
1091 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(int capacity,
1092 const AliHLTComponentDataType& dt,
1093 AliHLTUInt32_t spec)
1095 // see header file for function documentation
1096 ALIHLTCOMPONENT_BASE_STOPWATCH();
1097 AliHLTMemoryFile* pFile=NULL;
1098 if (capacity>=0 && static_cast<unsigned int>(capacity)<=fOutputBufferSize-fOutputBufferFilled){
1099 AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled;
1100 pFile=new AliHLTMemoryFile((char*)pTgt, capacity);
1102 unsigned int nofBlocks=fOutputBlocks.size();
1103 if (nofBlocks+1>fMemFiles.size()) {
1104 fMemFiles.resize(nofBlocks+1, NULL);
1106 if (nofBlocks<fMemFiles.size()) {
1107 fMemFiles[nofBlocks]=pFile;
1108 AliHLTComponentBlockData bd;
1109 FillBlockData( bd );
1110 bd.fOffset = fOutputBufferFilled;
1111 bd.fSize = capacity;
1113 bd.fSpecification = spec;
1114 fOutputBufferFilled+=bd.fSize;
1115 fOutputBlocks.push_back( bd );
1117 HLTError("can not allocate/grow object array");
1118 pFile->CloseMemoryFile(0);
1124 HLTError("can not create memory file of size %d (%d available)", capacity, fOutputBufferSize-fOutputBufferFilled);
1129 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(const char* dtID,
1130 const char* dtOrigin,
1131 AliHLTUInt32_t spec,
1134 // see header file for function documentation
1135 ALIHLTCOMPONENT_BASE_STOPWATCH();
1136 AliHLTComponentDataType dt;
1137 SetDataType(dt, dtID, dtOrigin);
1138 int size=fOutputBufferSize-fOutputBufferFilled;
1139 if (capacity<0 || capacity>1.0) {
1140 HLTError("invalid parameter: capacity %f", capacity);
1143 size=(int)(size*capacity);
1144 return CreateMemoryFile(size, dt, spec);
1147 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(const AliHLTComponentDataType& dt,
1148 AliHLTUInt32_t spec,
1151 // see header file for function documentation
1152 ALIHLTCOMPONENT_BASE_STOPWATCH();
1153 int size=fOutputBufferSize-fOutputBufferFilled;
1154 if (capacity<0 || capacity>1.0) {
1155 HLTError("invalid parameter: capacity %f", capacity);
1158 size=(int)(size*capacity);
1159 return CreateMemoryFile(size, dt, spec);
1162 int AliHLTComponent::Write(AliHLTMemoryFile* pFile, const TObject* pObject,
1163 const char* key, int option)
1165 // see header file for function documentation
1167 if (pFile && pObject) {
1169 iResult=pObject->Write(key, option);
1173 iResult=-pFile->GetErrno();
1174 if (iResult==-ENOSPC) {
1175 HLTError("error writing memory file, buffer too small");
1184 int AliHLTComponent::CloseMemoryFile(AliHLTMemoryFile* pFile)
1186 // see header file for function documentation
1189 AliHLTMemoryFilePList::iterator element=fMemFiles.begin();
1191 while (element!=fMemFiles.end() && iResult>=0) {
1192 if (*element && *element==pFile) {
1193 iResult=pFile->CloseMemoryFile();
1195 // sync memory files and descriptors
1197 fOutputBlocks[i].fSize=(*element)->GetSize()+(*element)->GetHeaderSize();
1205 HLTError("can not find memory file %p", pFile);
1213 int AliHLTComponent::CreateEventDoneData(AliHLTComponentEventDoneData /*edd*/)
1215 // see header file for function documentation
1216 int iResult=-ENOSYS;
1217 //#warning function not yet implemented
1218 HLTWarning("function not yet implemented");
1222 int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
1223 const AliHLTComponentBlockData* blocks,
1224 AliHLTComponentTriggerData& trigData,
1225 AliHLTUInt8_t* outputPtr,
1226 AliHLTUInt32_t& size,
1227 AliHLTUInt32_t& outputBlockCnt,
1228 AliHLTComponentBlockData*& outputBlocks,
1229 AliHLTComponentEventDoneData*& edd )
1231 // see header file for function documentation
1232 HLTLogKeyword(GetComponentID());
1233 ALIHLTCOMPONENT_BASE_STOPWATCH();
1235 fCurrentEvent=evtData.fEventID;
1236 fCurrentEventData=evtData;
1237 fpInputBlocks=blocks;
1238 fCurrentInputBlock=-1;
1239 fSearchDataType=kAliHLTAnyDataType;
1240 fpOutputBuffer=outputPtr;
1241 fOutputBufferSize=size;
1242 fOutputBufferFilled=0;
1243 fOutputBlocks.clear();
1246 AliHLTComponentStatisticsList compStats;
1247 #if defined(__DEBUG) || defined(HLT_COMPONENT_STATISTICS)
1248 AliHLTComponentStatistics outputStat;
1249 memset(&outputStat, 0, sizeof(AliHLTComponentStatistics));
1250 compStats.push_back(outputStat);
1252 fpBenchmark->Reset();
1253 fpBenchmark->Start();
1257 // data processing is skipped if there are only steering events
1258 // in the block list. It is not skipped if there is no block list
1259 // at all for the sake of data source components. Data processing
1260 // is always skipped if the event is of type
1261 // - gkAliEventTypeConfiguration
1262 // - gkAliEventTypeReadPreprocessor
1263 const unsigned int skipModeDefault=0x1;
1264 const unsigned int skipModeForce=0x2;
1265 unsigned int bSkipDataProcessing=skipModeDefault;
1267 // find special events
1268 if (fpInputBlocks && evtData.fBlockCnt>0) {
1269 // first look for all special events and execute in the appropriate
1270 // sequence afterwords
1271 AliHLTUInt32_t eventType=gkAliEventTypeUnknown;
1272 int indexComConfEvent=-1;
1273 int indexUpdtDCSEvent=-1;
1274 int indexSOREvent=-1;
1275 int indexEOREvent=-1;
1276 for (unsigned int i=0; i<evtData.fBlockCnt && iResult>=0; i++) {
1277 if (fpInputBlocks[i].fDataType==kAliHLTDataTypeSOR) {
1279 // the AliHLTCalibrationProcessor relies on the SOR and EOR events
1280 bSkipDataProcessing&=~skipModeDefault;
1281 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeRunType) {
1283 // handling is not clear yet
1284 if (fpInputBlocks[i].fPtr) {
1285 HLTDebug("got run type \"%s\"\n", fpInputBlocks[i].fPtr);
1287 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeEOR) {
1289 // the calibration processor relies on the SOR and EOR events
1290 bSkipDataProcessing&=~skipModeDefault;
1291 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeDDL) {
1293 // this event is most likely deprecated
1294 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComConf) {
1295 indexComConfEvent=i;
1296 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeUpdtDCS) {
1297 indexUpdtDCSEvent=i;
1298 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeEvent) {
1299 eventType=fpInputBlocks[i].fSpecification;
1300 if (fpInputBlocks[i].fSpecification==gkAliEventTypeConfiguration) bSkipDataProcessing|=skipModeForce;
1301 if (fpInputBlocks[i].fSpecification==gkAliEventTypeReadPreprocessor) bSkipDataProcessing|=skipModeForce;
1302 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComponentStatistics) {
1303 if (compStats.size()>0) {
1304 AliHLTUInt8_t* pData=reinterpret_cast<AliHLTUInt8_t*>(fpInputBlocks[i].fPtr);
1305 for (AliHLTUInt32_t offset=0;
1306 offset+sizeof(AliHLTComponentStatistics)<=fpInputBlocks[i].fSize;
1307 offset+=sizeof(AliHLTComponentStatistics)) {
1308 AliHLTComponentStatistics* pStat=reinterpret_cast<AliHLTComponentStatistics*>(pData+offset);
1309 if (pStat && compStats[0].fLevel<=pStat->fLevel) {
1310 compStats[0].fLevel=pStat->fLevel+1;
1312 compStats.push_back(*pStat);
1316 // the processing function is called if there is at least one
1317 // non-steering data block. Steering blocks are not filtered out
1318 // for sake of performance
1319 bSkipDataProcessing&=~skipModeDefault;
1320 if (compStats.size()>0) {
1321 compStats[0].fInputBlockCount++;
1322 compStats[0].fTotalInputSize+=fpInputBlocks[i].fSize;
1327 if (indexSOREvent>=0) {
1329 if (fpRunDesc==NULL) {
1330 fpRunDesc=new AliHLTRunDesc;
1333 AliHLTRunDesc rundesc;
1334 if ((iResult=CopyStruct(&rundesc, sizeof(AliHLTRunDesc), indexSOREvent, "AliHLTRunDesc", "SOR"))>0) {
1335 if (fpRunDesc->fRunNo==kAliHLTVoidRunNo) {
1337 HLTDebug("set run decriptor, run no %d", fpRunDesc->fRunNo);
1338 SetCDBRunNo(fpRunDesc->fRunNo);
1339 } else if (fpRunDesc->fRunNo!=rundesc.fRunNo) {
1340 HLTWarning("already set run properties run no %d, ignoring SOR with run no %d", fpRunDesc->fRunNo, rundesc.fRunNo);
1347 if (indexEOREvent>=0) {
1348 if (fpRunDesc!=NULL) {
1350 AliHLTRunDesc rundesc;
1351 if ((iResult=CopyStruct(&rundesc, sizeof(AliHLTRunDesc), indexEOREvent, "AliHLTRunDesc", "SOR"))>0) {
1352 if (fpRunDesc->fRunNo!=rundesc.fRunNo) {
1353 HLTWarning("run no mismatch: SOR %d, EOR %d", fpRunDesc->fRunNo, rundesc.fRunNo);
1355 HLTDebug("EOR run no %d", fpRunDesc->fRunNo);
1358 AliHLTRunDesc* pRunDesc=fpRunDesc;
1363 HLTWarning("did not receive SOR, ignoring EOR");
1366 if (indexComConfEvent>=0 || eventType==gkAliEventTypeConfiguration) {
1368 if (indexComConfEvent>=0 && fpInputBlocks[indexComConfEvent].fPtr!=NULL && fpInputBlocks[indexComConfEvent].fSize>0) {
1369 cdbEntry.Append(reinterpret_cast<const char*>(fpInputBlocks[indexComConfEvent].fPtr), fpInputBlocks[indexComConfEvent].fSize);
1371 HLTDebug("received component configuration command: entry %s", cdbEntry.IsNull()?"none":cdbEntry.Data());
1372 int tmpResult=Reconfigure(cdbEntry[0]==0?NULL:cdbEntry.Data(), fChainId.c_str());
1374 HLTWarning("reconfiguration of component %p (%s) failed with error code %d", this, GetComponentID(), tmpResult);
1377 if (indexUpdtDCSEvent>=0 || eventType==gkAliEventTypeReadPreprocessor) {
1379 if (fpInputBlocks[indexUpdtDCSEvent].fPtr!=NULL && fpInputBlocks[indexUpdtDCSEvent].fSize>0) {
1380 modules.Append(reinterpret_cast<const char*>(fpInputBlocks[indexUpdtDCSEvent].fPtr), fpInputBlocks[indexUpdtDCSEvent].fSize);
1382 HLTDebug("received preprocessor update command: detectors %s", modules.IsNull()?"ALL":modules.Data());
1383 int tmpResult=ReadPreprocessorValues(modules[0]==0?"ALL":modules.Data());
1385 HLTWarning("preprocessor update of component %p (%s) failed with error code %d", this, GetComponentID(), tmpResult);
1389 // processing function needs to be called if there are no input data
1390 // blocks in order to make data source components working.
1391 bSkipDataProcessing&=~skipModeDefault;
1394 // data processing is not skipped if the component explicitly asks
1395 // for the private blocks
1396 if (fRequireSteeringBlocks) bSkipDataProcessing=0;
1398 AliHLTComponentBlockDataList blockData;
1399 if (iResult>=0 && !bSkipDataProcessing)
1400 { // dont delete, sets the scope for the stopwatch guard
1401 // do not use ALIHLTCOMPONENT_DA_STOPWATCH(); macro
1402 // in order to avoid 'shadowed variable' warning
1403 AliHLTStopwatchGuard swguard2(fpStopwatches!=NULL?reinterpret_cast<TStopwatch*>(fpStopwatches->At((int)kSWDA)):NULL);
1404 iResult=DoProcessing(evtData, blocks, trigData, outputPtr, size, blockData, edd);
1405 } // end of the scope of the stopwatch guard
1406 if (iResult>=0 && !bSkipDataProcessing) {
1407 if (fOutputBlocks.size()>0) {
1408 // High Level interface
1410 //HLTDebug("got %d block(s) via high level interface", fOutputBlocks.size());
1411 // sync memory files and descriptors
1412 AliHLTMemoryFilePList::iterator element=fMemFiles.begin();
1414 while (element!=fMemFiles.end() && iResult>=0) {
1416 if ((*element)->IsClosed()==0) {
1417 HLTWarning("memory file has not been closed, force flush");
1418 iResult=CloseMemoryFile(*element);
1425 // create the descriptor list
1426 if (blockData.size()>0) {
1427 HLTError("low level and high interface must not be mixed; use PushBack methods to insert data blocks");
1430 if (compStats.size()>0) {
1431 int offset=AddComponentStatistics(fOutputBlocks, fpOutputBuffer, fOutputBufferSize, fOutputBufferFilled, compStats);
1432 if (offset>0) fOutputBufferFilled+=offset;
1434 iResult=MakeOutputDataBlockList(fOutputBlocks, &outputBlockCnt, &outputBlocks);
1435 size=fOutputBufferFilled;
1439 // Low Level interface
1440 if (compStats.size()>0) {
1441 int offset=AddComponentStatistics(blockData, fpOutputBuffer, fOutputBufferSize, size, compStats);
1442 if (offset>0) size+=offset;
1444 iResult=MakeOutputDataBlockList(blockData, &outputBlockCnt, &outputBlocks);
1447 HLTFatal("component %s (%p): can not convert output block descriptor list", GetComponentID(), this);
1450 if (iResult<0 || bSkipDataProcessing) {
1454 CleanupInputObjects();
1455 if (iResult>=0 && !bSkipDataProcessing) {
1456 IncrementEventCounter();
1458 if (outputBlockCnt==0) {
1459 // no output blocks, set size to 0
1465 int AliHLTComponent::AddComponentStatistics(AliHLTComponentBlockDataList& blocks,
1466 AliHLTUInt8_t* buffer,
1467 AliHLTUInt32_t bufferSize,
1468 AliHLTUInt32_t offset,
1469 AliHLTComponentStatisticsList& stats) const
1471 // see header file for function documentation
1473 if (stats.size()==0) return -ENOENT;
1474 stats[0].fTotalOutputSize=offset;
1475 stats[0].fOutputBlockCount=blocks.size();
1477 stats[0].fTime=(AliHLTUInt32_t)(fpBenchmark->RealTime()*1000000);
1478 stats[0].fCTime=(AliHLTUInt32_t)(fpBenchmark->CpuTime()*1000000);
1480 if (offset+stats.size()*sizeof(AliHLTComponentStatistics)<=bufferSize) {
1481 AliHLTComponentBlockData bd;
1482 FillBlockData( bd );
1483 bd.fOffset = offset;
1484 bd.fSize = stats.size()*sizeof(AliHLTComponentStatistics);
1485 bd.fDataType = kAliHLTDataTypeComponentStatistics;
1486 bd.fSpecification = kAliHLTVoidDataSpec;
1487 unsigned int master=0;
1488 for (unsigned int i=1; i<blocks.size(); i++) {
1489 if (blocks[i].fSize>blocks[master].fSize &&
1490 !MatchExactly(blocks[i].fDataType, kAliHLTVoidDataType|kAliHLTDataOriginPrivate))
1493 if (blocks.size()>0 && !MatchExactly(blocks[master].fDataType, kAliHLTVoidDataType|kAliHLTDataOriginPrivate)) {
1494 // take the data origin of the biggest block as specification
1495 // this is similar to the treatment in the HOMER interface. For traditional
1496 // reasons, the bytes are swapped there on a little endian architecture, so
1497 // we do it as well.
1498 memcpy(&bd.fSpecification, &blocks[master].fDataType.fOrigin, sizeof(bd.fSpecification));
1499 #ifdef R__BYTESWAP // set on little endian architectures
1500 bd.fSpecification=((bd.fSpecification & 0xFFULL) << 24) |
1501 ((bd.fSpecification & 0xFF00ULL) << 8) |
1502 ((bd.fSpecification & 0xFF0000ULL) >> 8) |
1503 ((bd.fSpecification & 0xFF000000ULL) >> 24);
1506 memcpy(buffer+offset, &(stats[0]), bd.fSize);
1507 blocks.push_back(bd);
1513 AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard()
1518 // standard constructor (not for use)
1521 AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(TStopwatch* pStopwatch)
1523 fpStopwatch(pStopwatch),
1528 // check for already existing guard
1529 if (fgpCurrent) fpPrec=fgpCurrent;
1532 // stop the preceeding guard if it controls a different stopwatch
1534 if (fpPrec && fpPrec!=this) bStart=fpPrec->Hold(fpStopwatch);
1536 // start the stopwatch if the current guard controls a different one
1537 if (fpStopwatch && bStart==1) fpStopwatch->Start(kFALSE);
1540 AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(const AliHLTStopwatchGuard&)
1546 // copy constructor not for use
1550 AliHLTComponent::AliHLTStopwatchGuard& AliHLTComponent::AliHLTStopwatchGuard::operator=(const AliHLTStopwatchGuard&)
1553 // assignment operator not for use
1560 AliHLTComponent::AliHLTStopwatchGuard* AliHLTComponent::AliHLTStopwatchGuard::fgpCurrent=NULL;
1562 AliHLTComponent::AliHLTStopwatchGuard::~AliHLTStopwatchGuard()
1566 // resume the preceeding guard if it controls a different stopwatch
1568 if (fpPrec && fpPrec!=this) bStop=fpPrec->Resume(fpStopwatch);
1570 // stop the stopwatch if the current guard controls a different one
1571 if (fpStopwatch && bStop==1) fpStopwatch->Stop();
1573 // resume to the preceeding guard
1577 int AliHLTComponent::AliHLTStopwatchGuard::Hold(TStopwatch* pSucc)
1579 // see header file for function documentation
1580 if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Stop();
1581 return fpStopwatch!=pSucc?1:0;
1584 int AliHLTComponent::AliHLTStopwatchGuard::Resume(TStopwatch* pSucc)
1586 // see header file for function documentation
1587 if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Start(kFALSE);
1588 return fpStopwatch!=pSucc?1:0;
1591 int AliHLTComponent::SetStopwatch(TObject* pSW, AliHLTStopwatchType type)
1593 // see header file for function documentation
1595 if (pSW!=NULL && type<kSWTypeCount) {
1596 if (fpStopwatches) {
1597 TObject* pObj=fpStopwatches->At((int)type);
1598 if (pSW==NULL // explicit reset
1599 || pObj==NULL) { // explicit set
1600 fpStopwatches->AddAt(pSW, (int)type);
1601 } else if (pObj!=pSW) {
1602 HLTWarning("stopwatch %d already set, reset first", (int)type);
1612 int AliHLTComponent::SetStopwatches(TObjArray* pStopwatches)
1614 // see header file for function documentation
1615 if (pStopwatches==NULL) return -EINVAL;
1618 for (int i=0 ; i<(int)kSWTypeCount && pStopwatches->GetEntries(); i++)
1619 SetStopwatch(pStopwatches->At(i), (AliHLTStopwatchType)i);
1623 AliHLTUInt32_t AliHLTComponent::GetRunNo() const
1625 // see header file for function documentation
1626 if (fpRunDesc==NULL) return kAliHLTVoidRunNo;
1627 return fpRunDesc->fRunNo;
1630 AliHLTUInt32_t AliHLTComponent::GetRunType() const
1632 // see header file for function documentation
1633 if (fpRunDesc==NULL) return kAliHLTVoidRunType;
1634 return fpRunDesc->fRunType;
1637 int AliHLTComponent::CopyStruct(void* pStruct, unsigned int iStructSize, unsigned int iBlockNo,
1638 const char* structname, const char* eventname)
1640 // see header file for function documentation
1642 if (pStruct!=NULL && iStructSize>sizeof(AliHLTUInt32_t)) {
1643 if (fpInputBlocks!=NULL && iBlockNo<fCurrentEventData.fBlockCnt) {
1644 AliHLTUInt32_t* pTgt=(AliHLTUInt32_t*)pStruct;
1645 if (fpInputBlocks[iBlockNo].fPtr && fpInputBlocks[iBlockNo].fSize) {
1646 AliHLTUInt32_t copy=*((AliHLTUInt32_t*)fpInputBlocks[iBlockNo].fPtr);
1647 if (fpInputBlocks[iBlockNo].fSize!=copy) {
1648 HLTWarning("%s event: mismatch of block size (%d) and structure size (%d)", eventname, fpInputBlocks[iBlockNo].fSize, copy);
1649 if (copy>fpInputBlocks[iBlockNo].fSize) copy=fpInputBlocks[iBlockNo].fSize;
1651 if (copy!=iStructSize) {
1652 HLTWarning("%s event: mismatch in %s version (data type version %d)", eventname, structname, ALIHLT_DATA_TYPES_VERSION);
1653 if (copy>iStructSize) {
1656 memset(pTgt, 0, iStructSize);
1659 memcpy(pTgt, fpInputBlocks[iBlockNo].fPtr, copy);
1663 HLTWarning("%s event: missing data block", eventname);
1669 HLTError("invalid struct");
1675 void AliHLTComponent::SetDDLBit(AliHLTEventDDL &list, Int_t ddlId, Bool_t state ) const
1677 // see header file for function documentation
1679 // -- Detector offset
1680 Int_t ddlIdBase = TMath::FloorNint( (Double_t) ddlId / 256.0 );
1682 // -- Word Base = 1. word of detector ( TPC has 8 words, TOF 3 )
1685 if ( ddlIdBase <= 3 )
1686 wordBase = ddlIdBase;
1687 else if ( ddlIdBase > 3 && ddlIdBase < 5 )
1688 wordBase = ddlIdBase + 7;
1690 wordBase = ddlIdBase + 9;
1692 // -- Bit index in Word
1693 Int_t bitIdx = ddlId % 32;
1696 Int_t wordIdx = wordBase;
1698 // -- if TPC (3) or TOD (5) add word idx
1699 if ( ( ddlIdBase == 3 ) || ( ddlIdBase == 5 ) ) {
1700 wordIdx += TMath::FloorNint( (Double_t) ( ddlId - ( ddlIdBase * 256 ) ) / 32.0 );
1703 // -- Set -- 'OR' word with bit mask;
1705 list.fList[wordIdx] |= ( 0x00000001 << bitIdx );
1706 // -- Unset -- 'AND' word with bit mask;
1708 list.fList[wordIdx] &= ( 0xFFFFFFFF ^ ( 0x00000001 << bitIdx ) );
1711 Int_t AliHLTComponent::GetFirstUsedDDLWord(AliHLTEventDDL &list) const
1713 // see header file for function documentation
1717 for ( Int_t wordNdx = 0 ; wordNdx < gkAliHLTDDLListSize ; wordNdx++ ) {
1719 if ( list.fList[wordNdx] != 0 && iResult == -1 ) {
1720 // check for special cases TPC and TOF
1721 if ( wordNdx > 3 && wordNdx <= 10 ) {
1725 else if ( wordNdx > 12 && wordNdx <= 14 ) {
1732 else if ( list.fList[wordNdx] != 0 && iResult >= 0 ) {
1733 HLTError( "DDLIDs for minimum of TWO detectors ( %d, %d ) set, this function works only for ONE detector.", iResult, wordNdx );