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"
45 * default compression level for ROOT objects
47 #define ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION 5
48 #define ALIHLTCOMPONENT_STATTIME_SCALER 1000000
50 /** ROOT macro for the implementation of ROOT specific class methods */
51 ClassImp(AliHLTComponent);
53 /** stopwatch macro using the stopwatch guard */
54 #define ALIHLTCOMPONENT_STOPWATCH(type) AliHLTStopwatchGuard swguard(fpStopwatches!=NULL?reinterpret_cast<TStopwatch*>(fpStopwatches->At((int)type)):NULL)
55 //#define ALIHLTCOMPONENT_STOPWATCH(type)
57 /** stopwatch macro for operations of the base class */
58 #define ALIHLTCOMPONENT_BASE_STOPWATCH() ALIHLTCOMPONENT_STOPWATCH(kSWBase)
59 /** stopwatch macro for operations of the detector algorithm (DA) */
60 #define ALIHLTCOMPONENT_DA_STOPWATCH() ALIHLTCOMPONENT_STOPWATCH(kSWDA)
62 AliHLTComponent::AliHLTComponent()
70 fCurrentInputBlock(-1),
71 fSearchDataType(kAliHLTVoidDataType),
76 fOutputBufferFilled(0),
78 fpStopwatches(new TObjArray(kSWTypeCount)),
82 fCDBSetRunNoFunc(false),
86 fRequireSteeringBlocks(false),
87 fEventType(gkAliEventTypeUnknown),
90 fEventDoneDataSize(0),
91 fCompressionLevel(ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION)
94 // see header file for class documentation
96 // refer to README to build package
98 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
99 memset(&fEnvironment, 0, sizeof(AliHLTAnalysisEnvironment));
100 if (fgpComponentHandler)
101 fgpComponentHandler->ScheduleRegister(this);
102 //SetLocalLoggingLevel(kHLTLogDefault);
105 AliHLTComponent::~AliHLTComponent()
107 // see header file for function documentation
108 if (fpBenchmark) delete fpBenchmark;
111 CleanupInputObjects();
112 if (fpStopwatches!=NULL) delete fpStopwatches;
114 AliHLTMemoryFilePList::iterator element=fMemFiles.begin();
115 while (element!=fMemFiles.end()) {
117 if ((*element)->IsClosed()==0) {
118 HLTWarning("memory file has not been closed, possible data loss or incomplete buffer");
119 // close but do not flush as we dont know whether the buffer is still valid
120 (*element)->CloseMemoryFile(0);
132 delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
135 AliHLTComponentHandler* AliHLTComponent::fgpComponentHandler=NULL;
137 int AliHLTComponent::SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite)
139 // see header file for function documentation
141 if (fgpComponentHandler==NULL || bOverwrite!=0)
142 fgpComponentHandler=pCH;
148 int AliHLTComponent::UnsetGlobalComponentHandler()
150 // see header file for function documentation
151 return SetGlobalComponentHandler(NULL,1);
154 int AliHLTComponent::SetComponentEnvironment(const AliHLTAnalysisEnvironment* comenv, void* environParam)
156 // see header file for function documentation
157 HLTLogKeyword(fChainId.c_str());
160 memset(&fEnvironment, 0, sizeof(AliHLTAnalysisEnvironment));
161 memcpy(&fEnvironment, comenv, comenv->fStructSize<sizeof(AliHLTAnalysisEnvironment)?comenv->fStructSize:sizeof(AliHLTAnalysisEnvironment));
162 fEnvironment.fStructSize=sizeof(AliHLTAnalysisEnvironment);
163 fEnvironment.fParam=environParam;
168 int AliHLTComponent::Init(const AliHLTAnalysisEnvironment* comenv, void* environParam, int argc, const char** argv )
170 // see header file for function documentation
171 HLTLogKeyword(fChainId.c_str());
174 SetComponentEnvironment(comenv, environParam);
177 const char** pArguments=NULL;
182 pArguments=new const char*[argc];
184 for (int i=0; i<argc && iResult>=0; i++) {
185 if (fComponentArgs.size()>0) fComponentArgs+=" ";
186 fComponentArgs+=argv[i];
188 if (argument.IsNull()) continue;
191 if (argument.CompareTo("-benchmark")==0) {
194 } else if (argument.BeginsWith("-loglevel=")) {
195 TString parameter=argument.ReplaceAll("-loglevel=", "");
196 parameter.Remove(TString::kLeading, ' '); // remove all blanks
197 if (parameter.BeginsWith("0x") &&
198 parameter.Replace(0,2,"",0).IsHex()) {
199 unsigned int loglevel=kHLTLogNone;
200 sscanf(parameter.Data(),"%x", &loglevel);
201 SetLocalLoggingLevel((AliHLTComponentLogSeverity)loglevel);
203 HLTError("wrong parameter for argument %s, hex number expected", argument.Data());
206 // -object-compression=
207 } else if (argument.BeginsWith("-object-compression=")) {
208 argument.ReplaceAll("-object-compression=", "");
209 if (argument.IsDigit()) {
210 fCompressionLevel=argument.Atoi();
211 if (fCompressionLevel<0 || fCompressionLevel>9) {
212 HLTWarning("invalid compression level %d, setting to default %d", fCompressionLevel, ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION);
213 fCompressionLevel=ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION;
216 HLTError("wrong parameter for argument -object-compression, number expected");
219 pArguments[iNofChildArgs++]=argv[i];
227 HLTError("missing parameter for argument %s", argument.Data());
231 iResult=DoInit(iNofChildArgs, pArguments);
236 // find out if the component wants to get the steering events
238 AliHLTComponentDataTypeList inputDt;
239 GetInputDataTypes(inputDt);
240 for (AliHLTComponentDataTypeList::iterator dt=inputDt.begin();
241 dt!=inputDt.end() && !fRequireSteeringBlocks;
243 fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeSOR);
244 fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeRunType);
245 fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeEOR);
246 fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeDDL);
247 fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeComponentStatistics);
250 if (pArguments) delete [] pArguments;
252 #if defined(__DEBUG) || defined(HLT_COMPONENT_STATISTICS)
253 // benchmarking stopwatch for the component statistics
254 fpBenchmark=new TStopwatch;
260 int AliHLTComponent::Deinit()
262 // see header file for function documentation
263 HLTLogKeyword(fChainId.c_str());
267 HLTWarning("did not receive EOR for run %d", fpRunDesc->fRunNo);
268 AliHLTRunDesc* pRunDesc=fpRunDesc;
276 int AliHLTComponent::InitCDB(const char* cdbPath, AliHLTComponentHandler* pHandler)
278 // see header file for function documentation
280 HLTInfo("Using CDB: %s", cdbPath);
282 // I have to think about separating the library handling from the
283 // component handler. Requiring the component handler here is not
284 // the cleanest solution.
285 // We presume the library already to be loaded, which is the case
286 // because it is loaded in the initialization of the logging functionality
289 AliHLTMiscInitCDB_t pFunc=(AliHLTMiscInitCDB_t)pHandler->FindSymbol(ALIHLTMISC_LIBRARY, ALIHLTMISC_INIT_CDB);
292 if (cdbPath && cdbPath[0]!=0) {
294 // very temporary fix, have to check for other formats
295 if (!path.BeginsWith("local://")) {
300 if ((iResult=(*pFunc)(path.Data()))>=0) {
301 if (!(fCDBSetRunNoFunc=pHandler->FindSymbol(ALIHLTMISC_LIBRARY, ALIHLTMISC_SET_CDB_RUNNO))) {
302 Message(NULL, kHLTLogWarning, "AliHLTComponent::InitCDB", "init CDB",
303 "can not find function to set CDB run no");
307 Message(NULL, kHLTLogError, "AliHLTComponent::InitCDB", "init CDB",
308 "can not find initialization function");
317 int AliHLTComponent::SetCDBRunNo(int runNo)
319 // see header file for function documentation
320 if (!fCDBSetRunNoFunc) return 0;
321 return (*((AliHLTMiscSetCDBRunNo_t)fCDBSetRunNoFunc))(runNo);
324 int AliHLTComponent::SetRunDescription(const AliHLTRunDesc* desc, const char* /*runType*/)
326 // see header file for function documentation
327 if (!desc) return -EINVAL;
328 if (desc->fStructSize!=sizeof(AliHLTRunDesc)) {
329 HLTError("invalid size of RunDesc struct (%ul)", desc->fStructSize);
334 fpRunDesc=new AliHLTRunDesc;
335 if (!fpRunDesc) return -ENOMEM;
336 *fpRunDesc=kAliHLTVoidRunDesc;
339 if (fpRunDesc->fRunNo!=kAliHLTVoidRunNo && fpRunDesc->fRunNo!=desc->fRunNo) {
340 HLTWarning("Run description has already been set");
343 SetCDBRunNo(fpRunDesc->fRunNo);
344 // TODO: we have to decide about the runType
348 int AliHLTComponent::SetComponentDescription(const char* desc)
350 // see header file for function documentation
354 TString descriptor=desc;
355 TObjArray* pTokens=descriptor.Tokenize(" ");
357 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
358 TString argument=((TObjString*)pTokens->At(i++))->GetString();
359 if (!argument || argument.IsNull()) continue;
362 if (argument.BeginsWith("chainid")) {
363 argument.ReplaceAll("chainid", "");
364 if (argument.BeginsWith("=")) {
365 fChainId=argument.Replace(0,1,"");
366 fChainIdCrc=CalculateChecksum((const AliHLTUInt8_t*)fChainId.c_str(), fChainId.length());
367 HLTDebug("setting component description: chain id %s crc 0x%8x", fChainId.c_str(), fChainIdCrc);
372 HLTWarning("unknown component description %s", argument.Data());
380 int AliHLTComponent::DoInit( int /*argc*/, const char** /*argv*/)
382 // default implementation, childs can overload
383 HLTLogKeyword("dummy");
387 int AliHLTComponent::DoDeinit()
389 // default implementation, childs can overload
390 HLTLogKeyword("dummy");
394 int AliHLTComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/)
396 // default implementation, childs can overload
397 HLTLogKeyword("dummy");
401 int AliHLTComponent::ReadPreprocessorValues(const char* /*modules*/)
403 // default implementation, childs can overload
404 HLTLogKeyword("dummy");
408 int AliHLTComponent::StartOfRun()
410 // default implementation, childs can overload
411 HLTLogKeyword("dummy");
415 int AliHLTComponent::EndOfRun()
417 // default implementation, childs can overload
418 HLTLogKeyword("dummy");
423 int AliHLTComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& /*tgtList*/)
425 // default implementation, childs can overload
426 HLTLogKeyword("dummy");
430 void AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2] ) const
432 // see header file for function documentation
433 memset( output, 0, kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2 );
434 strncat( output, type.fOrigin, kAliHLTComponentDataTypefOriginSize );
435 strcat( output, ":" );
436 strncat( output, type.fID, kAliHLTComponentDataTypefIDsize );
439 string AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, int mode)
441 // see header file for function documentation
447 for (i=0; i<kAliHLTComponentDataTypefOriginSize; i++) {
448 sprintf(tmp, "'%d", type.fOrigin[i]);
452 for (i=0; i<kAliHLTComponentDataTypefIDsize; i++) {
453 sprintf(tmp, "%d'", type.fID[i]);
462 for (i=0; i<kAliHLTComponentDataTypefOriginSize; i++) {
463 unsigned char* puc=(unsigned char*)type.fOrigin;
465 sprintf(tmp, "'\\%x", type.fOrigin[i]);
467 sprintf(tmp, "'%c", type.fOrigin[i]);
471 for (i=0; i<kAliHLTComponentDataTypefIDsize; i++) {
472 unsigned char* puc=(unsigned char*)type.fID;
474 sprintf(tmp, "\\%x'", type.fID[i]);
476 sprintf(tmp, "%c'", type.fID[i]);
482 if (type==kAliHLTVoidDataType) {
485 // some gymnastics in order to avoid a '0' which is part of either or both
486 // ID and origin terminating the whole string. Unfortunately, string doesn't
487 // stop appending at the '0' if the number of elements to append was
488 // explicitely specified
490 tmp.append(type.fOrigin, kAliHLTComponentDataTypefOriginSize);
491 out.append(tmp.c_str());
494 tmp.append(type.fID, kAliHLTComponentDataTypefIDsize);
495 out.append(tmp.c_str());
501 void* AliHLTComponent::AllocMemory( unsigned long size )
503 // see header file for function documentation
504 if (fEnvironment.fAllocMemoryFunc)
505 return (*fEnvironment.fAllocMemoryFunc)(fEnvironment.fParam, size );
506 HLTFatal("no memory allocation handler registered");
510 int AliHLTComponent::MakeOutputDataBlockList( const AliHLTComponentBlockDataList& blocks, AliHLTUInt32_t* blockCount,
511 AliHLTComponentBlockData** outputBlocks )
513 // see header file for function documentation
514 if ( blockCount==NULL || outputBlocks==NULL )
516 AliHLTUInt32_t count = blocks.size();
520 *outputBlocks = NULL;
523 *outputBlocks = reinterpret_cast<AliHLTComponentBlockData*>( AllocMemory( sizeof(AliHLTComponentBlockData)*count ) );
524 if ( !*outputBlocks )
526 for ( unsigned long i = 0; i < count; i++ ) {
527 (*outputBlocks)[i] = blocks[i];
528 if (MatchExactly(blocks[i].fDataType, kAliHLTAnyDataType)) {
529 (*outputBlocks)[i].fDataType=GetOutputDataType();
530 /* data type was set to the output data type by the PubSub AliRoot
531 Wrapper component, if data type of the block was ********:****.
532 Now handled by the component base class in order to have same
533 behavior when running embedded in AliRoot
534 memset((*outputBlocks)[i].fDataType.fID, '*', kAliHLTComponentDataTypefIDsize);
535 memset((*outputBlocks)[i].fDataType.fOrigin, '*', kAliHLTComponentDataTypefOriginSize);
544 int AliHLTComponent::GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd )
546 // see header file for function documentation
547 if (fEnvironment.fGetEventDoneDataFunc)
548 return (*fEnvironment.fGetEventDoneDataFunc)(fEnvironment.fParam, fCurrentEvent, size, edd );
552 int AliHLTComponent::ReserveEventDoneData( unsigned long size )
554 // see header file for function documentation
558 if (size>fEventDoneDataSize) {
559 AliHLTComponentEventDoneData* newEDD = reinterpret_cast<AliHLTComponentEventDoneData*>( new AliHLTUInt8_t[ sizeof(AliHLTComponentEventDoneData)+size ] );
562 newEDD->fStructSize = sizeof(AliHLTComponentEventDoneData);
563 newEDD->fDataSize = 0;
564 newEDD->fData = reinterpret_cast<AliHLTUInt8_t*>(newEDD)+newEDD->fStructSize;
565 if (fEventDoneData) {
566 memcpy( newEDD->fData, fEventDoneData->fData, fEventDoneData->fDataSize );
567 newEDD->fDataSize = fEventDoneData->fDataSize;
568 delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
570 fEventDoneData = newEDD;
571 fEventDoneDataSize = size;
577 int AliHLTComponent::PushEventDoneData( AliHLTUInt32_t eddDataWord )
581 if (fEventDoneData->fDataSize+sizeof(AliHLTUInt32_t)>fEventDoneDataSize)
583 *reinterpret_cast<AliHLTUInt32_t*>((reinterpret_cast<AliHLTUInt8_t*>(fEventDoneData->fData)+fEventDoneData->fDataSize)) = eddDataWord;
584 fEventDoneData->fDataSize += sizeof(AliHLTUInt32_t);
588 void AliHLTComponent::ReleaseEventDoneData()
591 delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
592 fEventDoneData = NULL;
593 fEventDoneDataSize = 0;
597 int AliHLTComponent::FindMatchingDataTypes(AliHLTComponent* pConsumer, AliHLTComponentDataTypeList* tgtList)
599 // see header file for function documentation
602 AliHLTComponentDataTypeList itypes;
603 AliHLTComponentDataTypeList otypes;
604 otypes.push_back(GetOutputDataType());
605 if (MatchExactly(otypes[0],kAliHLTMultipleDataType)) {
608 if ((count=GetOutputDataTypes(otypes))>0) {
609 } else if (GetComponentType()!=kSink) {
610 HLTWarning("component %s indicates multiple output data types but GetOutputDataTypes returns %d", GetComponentID(), count);
613 ((AliHLTComponent*)pConsumer)->GetInputDataTypes(itypes);
614 AliHLTComponentDataTypeList::iterator otype=otypes.begin();
615 for (;otype!=otypes.end();otype++) {
616 //PrintDataTypeContent((*otype), "publisher \'%s\'");
617 if ((*otype)==(kAliHLTAnyDataType|kAliHLTDataOriginPrivate)) {
618 if (tgtList) tgtList->push_back(*otype);
623 AliHLTComponentDataTypeList::iterator itype=itypes.begin();
624 for ( ; itype!=itypes.end() && (*itype)!=(*otype) ; itype++) {/* empty body */};
625 //if (itype!=itypes.end()) PrintDataTypeContent(*itype, "consumer \'%s\'");
626 if (itype!=itypes.end()) {
627 if (tgtList) tgtList->push_back(*otype);
637 void AliHLTComponent::PrintDataTypeContent(AliHLTComponentDataType& dt, const char* format)
639 // see header file for function documentation
640 const char* fmt="\'%s\'";
641 if (format) fmt=format;
642 AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, Form(fmt, (DataType2Text(dt)).c_str()));
643 AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL,
644 Form("%x %x %x %x %x %x %x %x : %x %x %x %x",
659 void AliHLTComponent::FillBlockData( AliHLTComponentBlockData& blockData )
661 // see header file for function documentation
662 blockData.fStructSize = sizeof(blockData);
663 FillShmData( blockData.fShmKey );
664 blockData.fOffset = ~(AliHLTUInt32_t)0;
665 blockData.fPtr = NULL;
667 FillDataType( blockData.fDataType );
668 blockData.fSpecification = kAliHLTVoidDataSpec;
671 void AliHLTComponent::FillShmData( AliHLTComponentShmData& shmData )
673 // see header file for function documentation
674 shmData.fStructSize = sizeof(shmData);
675 shmData.fShmType = gkAliHLTComponentInvalidShmType;
676 shmData.fShmID = gkAliHLTComponentInvalidShmID;
679 void AliHLTComponent::FillDataType( AliHLTComponentDataType& dataType )
681 // see header file for function documentation
682 dataType=kAliHLTAnyDataType;
685 void AliHLTComponent::CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt)
687 // see header file for function documentation
688 memcpy(&tgtdt.fID[0], &srcdt.fID[0], kAliHLTComponentDataTypefIDsize);
689 memcpy(&tgtdt.fOrigin[0], &srcdt.fOrigin[0], kAliHLTComponentDataTypefOriginSize);
692 void AliHLTComponent::SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin)
694 // see header file for function documentation
695 tgtdt.fStructSize=sizeof(AliHLTComponentDataType);
697 memset(&tgtdt.fID[0], 0, kAliHLTComponentDataTypefIDsize);
698 strncpy(&tgtdt.fID[0], id, strlen(id)<(size_t)kAliHLTComponentDataTypefIDsize?strlen(id):kAliHLTComponentDataTypefIDsize);
701 memset(&tgtdt.fOrigin[0], 0, kAliHLTComponentDataTypefOriginSize);
702 strncpy(&tgtdt.fOrigin[0], origin, strlen(origin)<(size_t)kAliHLTComponentDataTypefOriginSize?strlen(origin):kAliHLTComponentDataTypefOriginSize);
706 void AliHLTComponent::SetDataType(AliHLTComponentDataType& dt, AliHLTUInt64_t id, AliHLTUInt32_t origin)
708 // see header file for function documentation
709 dt.fStructSize=sizeof(AliHLTComponentDataType);
710 assert(kAliHLTComponentDataTypefIDsize==sizeof(id));
711 assert(kAliHLTComponentDataTypefOriginSize==sizeof(origin));
712 memcpy(&dt.fID, &id, kAliHLTComponentDataTypefIDsize);
713 memcpy(&dt.fOrigin, &origin, kAliHLTComponentDataTypefOriginSize);
716 void AliHLTComponent::FillEventData(AliHLTComponentEventData& evtData)
718 // see header file for function documentation
719 memset(&evtData, 0, sizeof(AliHLTComponentEventData));
720 evtData.fStructSize=sizeof(AliHLTComponentEventData);
721 evtData.fEventID=kAliHLTVoidEventID;
724 void AliHLTComponent::PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt)
726 // see header file for function documentation
728 msg.Form("AliHLTComponentDataType(%d): ID=\"", dt.fStructSize);
729 for ( int i = 0; i < kAliHLTComponentDataTypefIDsize; i++ ) {
730 if (dt.fID[i]!=0) msg+=dt.fID[i];
734 for ( int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++ ) {
735 if (dt.fOrigin[i]!=0) msg+=dt.fOrigin[i];
739 AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, msg.Data());
742 int AliHLTComponent::GetEventCount() const
744 // see header file for function documentation
748 int AliHLTComponent::IncrementEventCounter()
750 // see header file for function documentation
751 if (fEventCount>=0) fEventCount++;
755 int AliHLTComponent::GetNumberOfInputBlocks() const
757 // see header file for function documentation
758 if (fpInputBlocks!=NULL) {
759 return fCurrentEventData.fBlockCnt;
764 AliHLTEventID_t AliHLTComponent::GetEventId() const
766 // see header file for function documentation
767 if (fpInputBlocks!=NULL) {
768 return fCurrentEventData.fEventID;
773 const TObject* AliHLTComponent::GetFirstInputObject(const AliHLTComponentDataType& dt,
774 const char* classname,
777 // see header file for function documentation
778 ALIHLTCOMPONENT_BASE_STOPWATCH();
780 if (classname) fClassName=classname;
781 else fClassName.clear();
782 int idx=FindInputBlock(fSearchDataType, 0, 1);
785 HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(dt).c_str());
786 if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) {
787 fCurrentInputBlock=idx;
794 const TObject* AliHLTComponent::GetFirstInputObject(const char* dtID,
795 const char* dtOrigin,
796 const char* classname,
799 // see header file for function documentation
800 ALIHLTCOMPONENT_BASE_STOPWATCH();
801 AliHLTComponentDataType dt;
802 SetDataType(dt, dtID, dtOrigin);
803 return GetFirstInputObject(dt, classname, bForce);
806 const TObject* AliHLTComponent::GetNextInputObject(int bForce)
808 // see header file for function documentation
809 ALIHLTCOMPONENT_BASE_STOPWATCH();
810 int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1, 1);
811 //HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(fSearchDataType).c_str());
814 if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) {
815 fCurrentInputBlock=idx;
821 int AliHLTComponent::FindInputBlock(const AliHLTComponentDataType& dt, int startIdx, int bObject) const
823 // see header file for function documentation
825 if (fpInputBlocks!=NULL) {
826 int idx=startIdx<0?0:startIdx;
827 for ( ; (UInt_t)idx<fCurrentEventData.fBlockCnt && iResult==-ENOENT; idx++) {
828 if (dt!=fpInputBlocks[idx].fDataType) continue;
831 if (fpInputBlocks[idx].fPtr==NULL) continue;
832 AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr);
833 if (firstWord!=fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) continue;
841 TObject* AliHLTComponent::CreateInputObject(int idx, int bForce)
843 // see header file for function documentation
845 if (fpInputBlocks!=NULL) {
846 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
847 if (fpInputBlocks[idx].fPtr) {
848 AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr);
849 if (firstWord==fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) {
850 HLTDebug("create object from block %d size %d", idx, fpInputBlocks[idx].fSize);
851 AliHLTMessage msg(fpInputBlocks[idx].fPtr, fpInputBlocks[idx].fSize);
852 TClass* objclass=msg.GetClass();
853 pObj=msg.ReadObject(objclass);
854 if (pObj && objclass) {
855 HLTDebug("object %p type %s created", pObj, objclass->GetName());
859 } else if (bForce!=0) {
860 HLTError("size mismatch: block size %d, indicated %d", fpInputBlocks[idx].fSize, firstWord+sizeof(AliHLTUInt32_t));
863 HLTFatal("block descriptor empty");
866 HLTError("index %d out of range %d", idx, fCurrentEventData.fBlockCnt);
869 HLTError("no input blocks available");
875 TObject* AliHLTComponent::GetInputObject(int idx, const char* /*classname*/, int bForce)
877 // see header file for function documentation
878 if (fpInputObjects==NULL) {
879 fpInputObjects=new TObjArray(fCurrentEventData.fBlockCnt);
882 if (fpInputObjects) {
883 pObj=fpInputObjects->At(idx);
885 pObj=CreateInputObject(idx, bForce);
887 fpInputObjects->AddAt(pObj, idx);
891 HLTFatal("memory allocation failed: TObjArray of size %d", fCurrentEventData.fBlockCnt);
896 int AliHLTComponent::CleanupInputObjects()
898 // see header file for function documentation
899 if (!fpInputObjects) return 0;
900 TObjArray* array=fpInputObjects;
902 for (int i=0; i<array->GetEntries(); i++) {
903 TObject* pObj=array->At(i);
904 // grrr, garbage collection strikes back: When read via AliHLTMessage
905 // (CreateInputObject), and written to a TFile afterwards, the
906 // TFile::Close calls ROOOT's garbage collection. No clue why the
907 // object ended up in the key list and needs to be deleted
909 // Matthias 09.11.2008 follow up
910 // This approach doesn't actually work in all cases: the object table
911 // can be switched off globally, the flag needs to be checked here as
912 // well in order to avoid memory leaks.
913 // This means we have to find another solution for the problem if it
916 (!TObject::GetObjectStat() || gObjectTable->PtrIsValid(pObj))) {
924 AliHLTComponentDataType AliHLTComponent::GetDataType(const TObject* pObject)
926 // see header file for function documentation
927 ALIHLTCOMPONENT_BASE_STOPWATCH();
928 AliHLTComponentDataType dt=kAliHLTVoidDataType;
929 int idx=fCurrentInputBlock;
931 if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
933 HLTError("unknown object %p", pObject);
937 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
938 dt=fpInputBlocks[idx].fDataType;
940 HLTFatal("severe internal error, index out of range");
946 AliHLTUInt32_t AliHLTComponent::GetSpecification(const TObject* pObject)
948 // see header file for function documentation
949 ALIHLTCOMPONENT_BASE_STOPWATCH();
950 AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec;
951 int idx=fCurrentInputBlock;
953 if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
955 HLTError("unknown object %p", pObject);
959 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
960 iSpec=fpInputBlocks[idx].fSpecification;
962 HLTFatal("severe internal error, index out of range");
968 int AliHLTComponent::Forward(const TObject* pObject)
970 // see header file for function documentation
972 int idx=fCurrentInputBlock;
974 if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
976 HLTError("unknown object %p", pObject);
981 fOutputBlocks.push_back(fpInputBlocks[idx]);
986 int AliHLTComponent::Forward(const AliHLTComponentBlockData* pBlock)
988 // see header file for function documentation
990 int idx=fCurrentInputBlock;
992 if (fpInputObjects==NULL || (idx=FindInputBlock(pBlock))>=0) {
994 HLTError("unknown Block %p", pBlock);
999 // check for fpInputBlocks pointer done in FindInputBlock
1000 fOutputBlocks.push_back(fpInputBlocks[idx]);
1005 const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const AliHLTComponentDataType& dt)
1007 // see header file for function documentation
1008 ALIHLTCOMPONENT_BASE_STOPWATCH();
1011 int idx=FindInputBlock(fSearchDataType, 0);
1012 const AliHLTComponentBlockData* pBlock=NULL;
1014 // check for fpInputBlocks pointer done in FindInputBlock
1015 pBlock=&fpInputBlocks[idx];
1016 fCurrentInputBlock=idx;
1021 const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const char* dtID,
1022 const char* dtOrigin)
1024 // see header file for function documentation
1025 ALIHLTCOMPONENT_BASE_STOPWATCH();
1026 AliHLTComponentDataType dt;
1027 SetDataType(dt, dtID, dtOrigin);
1028 return GetFirstInputBlock(dt);
1031 const AliHLTComponentBlockData* AliHLTComponent::GetInputBlock(int index) const
1033 // see header file for function documentation
1034 ALIHLTCOMPONENT_BASE_STOPWATCH();
1035 assert( 0 <= index and index < (int)fCurrentEventData.fBlockCnt );
1036 return &fpInputBlocks[index];
1039 const AliHLTComponentBlockData* AliHLTComponent::GetNextInputBlock()
1041 // see header file for function documentation
1042 ALIHLTCOMPONENT_BASE_STOPWATCH();
1043 int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1);
1044 const AliHLTComponentBlockData* pBlock=NULL;
1046 // check for fpInputBlocks pointer done in FindInputBlock
1047 pBlock=&fpInputBlocks[idx];
1048 fCurrentInputBlock=idx;
1053 int AliHLTComponent::FindInputBlock(const AliHLTComponentBlockData* pBlock) const
1055 // see header file for function documentation
1056 int iResult=-ENOENT;
1057 if (fpInputBlocks!=NULL) {
1059 if (pBlock>=fpInputBlocks && pBlock<fpInputBlocks+fCurrentEventData.fBlockCnt) {
1060 iResult=(int)(pBlock-fpInputBlocks);
1069 AliHLTUInt32_t AliHLTComponent::GetSpecification(const AliHLTComponentBlockData* pBlock)
1071 // see header file for function documentation
1072 ALIHLTCOMPONENT_BASE_STOPWATCH();
1073 AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec;
1074 int idx=fCurrentInputBlock;
1076 if (fpInputObjects==NULL || (idx=FindInputBlock(pBlock))>=0) {
1078 HLTError("unknown Block %p", pBlock);
1082 // check for fpInputBlocks pointer done in FindInputBlock
1083 iSpec=fpInputBlocks[idx].fSpecification;
1088 int AliHLTComponent::PushBack(TObject* pObject, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
1089 void* pHeader, int headerSize)
1091 // see header file for function documentation
1092 ALIHLTCOMPONENT_BASE_STOPWATCH();
1096 AliHLTMessage msg(kMESS_OBJECT);
1097 msg.SetCompressionLevel(fCompressionLevel);
1098 msg.WriteObject(pObject);
1099 Int_t iMsgLength=msg.Length();
1101 // Matthias Sep 2008
1102 // NOTE: AliHLTMessage does implement it's own SetLength method
1103 // which is not architecture independent. The original SetLength
1104 // stores the size always in network byte order.
1105 // I'm trying to remember the rational for that, might be that
1106 // it was just some lack of knowledge. Want to change this, but
1107 // has to be done carefullt to be backward compatible.
1108 msg.SetLength(); // sets the length to the first (reserved) word
1110 // does nothing if the level is 0
1113 char *mbuf = msg.Buffer();
1114 if (msg.CompBuffer()) {
1115 msg.SetLength(); // set once more to have to byte order
1116 mbuf = msg.CompBuffer();
1117 iMsgLength = msg.CompLength();
1120 iResult=InsertOutputBlock(mbuf, iMsgLength, dt, spec, pHeader, headerSize);
1122 HLTDebug("object %s (%p) size %d compression %d inserted to output", pObject->ClassName(), pObject, iMsgLength, msg.GetCompressionLevel());
1124 fLastObjectSize=iMsgLength;
1126 HLTError("object serialization failed for object %p", pObject);
1135 int AliHLTComponent::PushBack(TObject* pObject, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec,
1136 void* pHeader, int headerSize)
1138 // see header file for function documentation
1139 ALIHLTCOMPONENT_BASE_STOPWATCH();
1140 AliHLTComponentDataType dt;
1141 SetDataType(dt, dtID, dtOrigin);
1142 return PushBack(pObject, dt, spec, pHeader, headerSize);
1145 int AliHLTComponent::PushBack(const void* pBuffer, int iSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
1146 const void* pHeader, int headerSize)
1148 // see header file for function documentation
1149 ALIHLTCOMPONENT_BASE_STOPWATCH();
1150 return InsertOutputBlock(pBuffer, iSize, dt, spec, pHeader, headerSize);
1153 int AliHLTComponent::PushBack(const void* pBuffer, int iSize, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec,
1154 const void* pHeader, int headerSize)
1156 // see header file for function documentation
1157 ALIHLTCOMPONENT_BASE_STOPWATCH();
1158 AliHLTComponentDataType dt;
1159 SetDataType(dt, dtID, dtOrigin);
1160 return PushBack(pBuffer, iSize, dt, spec, pHeader, headerSize);
1163 int AliHLTComponent::InsertOutputBlock(const void* pBuffer, int iBufferSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
1164 const void* pHeader, int iHeaderSize)
1166 // see header file for function documentation
1168 int iBlkSize = iBufferSize + iHeaderSize;
1170 if ((pBuffer!=NULL && iBufferSize>0) || (pHeader!=NULL && iHeaderSize>0)) {
1171 if (fpOutputBuffer && iBlkSize<=(int)(fOutputBufferSize-fOutputBufferFilled)) {
1172 AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled;
1174 // copy header if provided but skip if the header is the target location
1175 // in that case it has already been copied
1176 if (pHeader!=NULL && pHeader!=pTgt) {
1177 memcpy(pTgt, pHeader, iHeaderSize);
1180 pTgt += (AliHLTUInt8_t) iHeaderSize;
1182 // copy buffer if provided but skip if buffer is the target location
1183 // in that case it has already been copied
1184 if (pBuffer!=NULL && pBuffer!=pTgt) {
1185 memcpy(pTgt, pBuffer, iBufferSize);
1187 //AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)pBuffer);
1188 //HLTDebug("copy %d bytes from %p to output buffer %p, first word %#x", iBufferSize, pBuffer, pTgt, firstWord);
1190 //HLTDebug("buffer inserted to output: size %d data type %s spec %#x", iBlkSize, DataType2Text(dt).c_str(), spec);
1192 if (fpOutputBuffer) {
1193 HLTError("too little space in output buffer: %d of %d, required %d", fOutputBufferSize-fOutputBufferFilled, fOutputBufferSize, iBlkSize);
1195 HLTError("output buffer not available");
1201 AliHLTComponentBlockData bd;
1202 FillBlockData( bd );
1203 bd.fOffset = fOutputBufferFilled;
1204 bd.fSize = iBlkSize;
1206 bd.fSpecification = spec;
1207 fOutputBlocks.push_back( bd );
1208 fOutputBufferFilled+=bd.fSize;
1214 int AliHLTComponent::EstimateObjectSize(TObject* pObject) const
1216 // see header file for function documentation
1217 if (!pObject) return -EINVAL;
1218 AliHLTMessage msg(kMESS_OBJECT);
1219 msg.WriteObject(pObject);
1220 return msg.Length();
1223 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(int capacity, const char* dtID,
1224 const char* dtOrigin,
1225 AliHLTUInt32_t spec)
1227 // see header file for function documentation
1228 ALIHLTCOMPONENT_BASE_STOPWATCH();
1229 AliHLTComponentDataType dt;
1230 SetDataType(dt, dtID, dtOrigin);
1231 return CreateMemoryFile(capacity, dt, spec);
1234 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(int capacity,
1235 const AliHLTComponentDataType& dt,
1236 AliHLTUInt32_t spec)
1238 // see header file for function documentation
1239 ALIHLTCOMPONENT_BASE_STOPWATCH();
1240 AliHLTMemoryFile* pFile=NULL;
1241 if (capacity>=0 && static_cast<unsigned int>(capacity)<=fOutputBufferSize-fOutputBufferFilled){
1242 AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled;
1243 pFile=new AliHLTMemoryFile((char*)pTgt, capacity);
1245 unsigned int nofBlocks=fOutputBlocks.size();
1246 if (nofBlocks+1>fMemFiles.size()) {
1247 fMemFiles.resize(nofBlocks+1, NULL);
1249 if (nofBlocks<fMemFiles.size()) {
1250 fMemFiles[nofBlocks]=pFile;
1251 AliHLTComponentBlockData bd;
1252 FillBlockData( bd );
1253 bd.fOffset = fOutputBufferFilled;
1254 bd.fSize = capacity;
1256 bd.fSpecification = spec;
1257 fOutputBufferFilled+=bd.fSize;
1258 fOutputBlocks.push_back( bd );
1260 HLTError("can not allocate/grow object array");
1261 pFile->CloseMemoryFile(0);
1267 HLTError("can not create memory file of size %d (%d available)", capacity, fOutputBufferSize-fOutputBufferFilled);
1272 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(const char* dtID,
1273 const char* dtOrigin,
1274 AliHLTUInt32_t spec,
1277 // see header file for function documentation
1278 ALIHLTCOMPONENT_BASE_STOPWATCH();
1279 AliHLTComponentDataType dt;
1280 SetDataType(dt, dtID, dtOrigin);
1281 int size=fOutputBufferSize-fOutputBufferFilled;
1282 if (capacity<0 || capacity>1.0) {
1283 HLTError("invalid parameter: capacity %f", capacity);
1286 size=(int)(size*capacity);
1287 return CreateMemoryFile(size, dt, spec);
1290 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(const AliHLTComponentDataType& dt,
1291 AliHLTUInt32_t spec,
1294 // see header file for function documentation
1295 ALIHLTCOMPONENT_BASE_STOPWATCH();
1296 int size=fOutputBufferSize-fOutputBufferFilled;
1297 if (capacity<0 || capacity>1.0) {
1298 HLTError("invalid parameter: capacity %f", capacity);
1301 size=(int)(size*capacity);
1302 return CreateMemoryFile(size, dt, spec);
1305 int AliHLTComponent::Write(AliHLTMemoryFile* pFile, const TObject* pObject,
1306 const char* key, int option)
1308 // see header file for function documentation
1310 if (pFile && pObject) {
1312 iResult=pObject->Write(key, option);
1316 iResult=-pFile->GetErrno();
1317 if (iResult==-ENOSPC) {
1318 HLTError("error writing memory file, buffer too small");
1327 int AliHLTComponent::CloseMemoryFile(AliHLTMemoryFile* pFile)
1329 // see header file for function documentation
1332 AliHLTMemoryFilePList::iterator element=fMemFiles.begin();
1334 while (element!=fMemFiles.end() && iResult>=0) {
1335 if (*element && *element==pFile) {
1336 iResult=pFile->CloseMemoryFile();
1338 // sync memory files and descriptors
1340 fOutputBlocks[i].fSize=(*element)->GetSize()+(*element)->GetHeaderSize();
1348 HLTError("can not find memory file %p", pFile);
1356 int AliHLTComponent::CreateEventDoneData(AliHLTComponentEventDoneData edd)
1358 // see header file for function documentation
1361 AliHLTComponentEventDoneData* newEDD = NULL;
1363 unsigned long newSize=edd.fDataSize;
1365 newSize += fEventDoneData->fDataSize;
1367 if (newSize>fEventDoneDataSize) {
1368 newEDD = reinterpret_cast<AliHLTComponentEventDoneData*>( new AliHLTUInt8_t[ sizeof(AliHLTComponentEventDoneData)+newSize ] );
1371 newEDD->fStructSize = sizeof(AliHLTComponentEventDoneData);
1372 newEDD->fDataSize = newSize;
1373 newEDD->fData = reinterpret_cast<AliHLTUInt8_t*>(newEDD)+newEDD->fStructSize;
1374 unsigned long long offset = 0;
1375 if (fEventDoneData) {
1376 memcpy( newEDD->fData, fEventDoneData->fData, fEventDoneData->fDataSize );
1377 offset += fEventDoneData->fDataSize;
1379 memcpy( reinterpret_cast<AliHLTUInt8_t*>(newEDD->fData)+offset, edd.fData, edd.fDataSize );
1381 delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
1382 fEventDoneData = newEDD;
1383 fEventDoneDataSize = newSize;
1386 memcpy( reinterpret_cast<AliHLTUInt8_t*>(fEventDoneData->fData)+fEventDoneData->fDataSize, edd.fData, edd.fDataSize );
1387 fEventDoneData->fDataSize += edd.fDataSize;
1392 int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
1393 const AliHLTComponentBlockData* blocks,
1394 AliHLTComponentTriggerData& trigData,
1395 AliHLTUInt8_t* outputPtr,
1396 AliHLTUInt32_t& size,
1397 AliHLTUInt32_t& outputBlockCnt,
1398 AliHLTComponentBlockData*& outputBlocks,
1399 AliHLTComponentEventDoneData*& edd )
1401 // see header file for function documentation
1402 HLTLogKeyword(fChainId.c_str());
1403 ALIHLTCOMPONENT_BASE_STOPWATCH();
1405 fCurrentEvent=evtData.fEventID;
1406 fCurrentEventData=evtData;
1407 fpInputBlocks=blocks;
1408 fCurrentInputBlock=-1;
1409 fSearchDataType=kAliHLTAnyDataType;
1410 fpOutputBuffer=outputPtr;
1411 fOutputBufferSize=size;
1412 fOutputBufferFilled=0;
1413 fOutputBlocks.clear();
1417 AliHLTComponentBlockDataList forwardedBlocks;
1419 // optional component statistics
1420 AliHLTComponentStatisticsList compStats;
1421 bool bAddComponentTableEntry=false;
1422 vector<AliHLTUInt32_t> parentComponentTables;
1423 #if defined(__DEBUG) || defined(HLT_COMPONENT_STATISTICS)
1424 AliHLTComponentStatistics outputStat;
1425 memset(&outputStat, 0, sizeof(AliHLTComponentStatistics));
1426 outputStat.fStructSize=sizeof(AliHLTComponentStatistics);
1427 outputStat.fId=fChainIdCrc;
1429 fpBenchmark->Stop();
1430 outputStat.fComponentCycleTime=(AliHLTUInt32_t)(fpBenchmark->RealTime()*ALIHLTCOMPONENT_STATTIME_SCALER);
1431 fpBenchmark->Reset();
1432 fpBenchmark->Start();
1434 compStats.push_back(outputStat);
1437 // data processing is skipped
1438 // - if there are only steering events in the block list.
1439 // For the sake of data source components data processing
1440 // is not skipped if there is no block list at all or if it
1441 // just contains the eventType block
1442 // - always skipped if the event is of type
1443 // - gkAliEventTypeConfiguration
1444 // - gkAliEventTypeReadPreprocessor
1445 const unsigned int skipModeDefault=0x1;
1446 const unsigned int skipModeForce=0x2;
1447 unsigned int bSkipDataProcessing=skipModeDefault;
1449 // find special events
1450 if (fpInputBlocks && evtData.fBlockCnt>0) {
1451 // first look for all special events and execute in the appropriate
1452 // sequence afterwords
1453 int indexComConfEvent=-1;
1454 int indexUpdtDCSEvent=-1;
1455 int indexSOREvent=-1;
1456 int indexEOREvent=-1;
1457 for (unsigned int i=0; i<evtData.fBlockCnt && iResult>=0; i++) {
1458 if (fpInputBlocks[i].fDataType==kAliHLTDataTypeSOR) {
1460 // the AliHLTCalibrationProcessor relies on the SOR and EOR events
1461 bSkipDataProcessing&=~skipModeDefault;
1462 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeRunType) {
1464 // handling is not clear yet
1465 if (fpInputBlocks[i].fPtr) {
1466 HLTDebug("got run type \"%s\"\n", fpInputBlocks[i].fPtr);
1468 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeEOR) {
1470 // the calibration processor relies on the SOR and EOR events
1471 bSkipDataProcessing&=~skipModeDefault;
1472 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeDDL) {
1474 // this event is most likely deprecated
1475 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComConf) {
1476 indexComConfEvent=i;
1477 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeUpdtDCS) {
1478 indexUpdtDCSEvent=i;
1479 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeEvent) {
1480 fEventType=fpInputBlocks[i].fSpecification;
1482 // skip always in case of gkAliEventTypeConfiguration
1483 if (fpInputBlocks[i].fSpecification==gkAliEventTypeConfiguration) bSkipDataProcessing|=skipModeForce;
1485 // skip always in case of gkAliEventTypeReadPreprocessor
1486 if (fpInputBlocks[i].fSpecification==gkAliEventTypeReadPreprocessor) bSkipDataProcessing|=skipModeForce;
1488 // never skip if the event type block is the only block
1489 if (evtData.fBlockCnt==1) bSkipDataProcessing&=~skipModeDefault;
1491 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComponentStatistics) {
1492 if (compStats.size()>0) {
1493 AliHLTUInt8_t* pData=reinterpret_cast<AliHLTUInt8_t*>(fpInputBlocks[i].fPtr);
1494 for (AliHLTUInt32_t offset=0;
1495 offset+sizeof(AliHLTComponentStatistics)<=fpInputBlocks[i].fSize;
1496 offset+=sizeof(AliHLTComponentStatistics)) {
1497 AliHLTComponentStatistics* pStat=reinterpret_cast<AliHLTComponentStatistics*>(pData+offset);
1498 if (pStat && compStats[0].fLevel<=pStat->fLevel) {
1499 compStats[0].fLevel=pStat->fLevel+1;
1501 compStats.push_back(*pStat);
1504 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComponentTable) {
1505 forwardedBlocks.push_back(fpInputBlocks[i]);
1506 parentComponentTables.push_back(fpInputBlocks[i].fSpecification);
1508 // the processing function is called if there is at least one
1509 // non-steering data block. Steering blocks are not filtered out
1510 // for sake of performance
1511 bSkipDataProcessing&=~skipModeDefault;
1512 if (compStats.size()>0) {
1513 compStats[0].fInputBlockCount++;
1514 compStats[0].fTotalInputSize+=fpInputBlocks[i].fSize;
1519 if (indexSOREvent>=0) {
1521 bAddComponentTableEntry=true;
1522 if (fpRunDesc==NULL) {
1523 fpRunDesc=new AliHLTRunDesc;
1524 if (fpRunDesc) *fpRunDesc=kAliHLTVoidRunDesc;
1527 AliHLTRunDesc rundesc;
1528 if ((iResult=CopyStruct(&rundesc, sizeof(AliHLTRunDesc), indexSOREvent, "AliHLTRunDesc", "SOR"))>0) {
1529 if (fpRunDesc->fRunNo==kAliHLTVoidRunNo) {
1531 HLTDebug("set run decriptor, run no %d", fpRunDesc->fRunNo);
1532 SetCDBRunNo(fpRunDesc->fRunNo);
1533 } else if (fpRunDesc->fRunNo!=rundesc.fRunNo) {
1534 HLTWarning("already set run properties run no %d, ignoring SOR with run no %d", fpRunDesc->fRunNo, rundesc.fRunNo);
1541 if (indexEOREvent>=0) {
1542 bAddComponentTableEntry=true;
1543 if (fpRunDesc!=NULL) {
1545 AliHLTRunDesc rundesc;
1546 if ((iResult=CopyStruct(&rundesc, sizeof(AliHLTRunDesc), indexEOREvent, "AliHLTRunDesc", "SOR"))>0) {
1547 if (fpRunDesc->fRunNo!=rundesc.fRunNo) {
1548 HLTWarning("run no mismatch: SOR %d, EOR %d", fpRunDesc->fRunNo, rundesc.fRunNo);
1550 HLTDebug("EOR run no %d", fpRunDesc->fRunNo);
1553 AliHLTRunDesc* pRunDesc=fpRunDesc;
1558 HLTWarning("did not receive SOR, ignoring EOR");
1561 if (indexComConfEvent>=0 || fEventType==gkAliEventTypeConfiguration) {
1563 if (indexComConfEvent>=0 && fpInputBlocks[indexComConfEvent].fPtr!=NULL && fpInputBlocks[indexComConfEvent].fSize>0) {
1564 cdbEntry.Append(reinterpret_cast<const char*>(fpInputBlocks[indexComConfEvent].fPtr), fpInputBlocks[indexComConfEvent].fSize);
1566 HLTDebug("received component configuration command: entry %s", cdbEntry.IsNull()?"none":cdbEntry.Data());
1567 int tmpResult=Reconfigure(cdbEntry[0]==0?NULL:cdbEntry.Data(), fChainId.c_str());
1569 HLTWarning("reconfiguration of component %p (%s) failed with error code %d", this, GetComponentID(), tmpResult);
1572 if (indexUpdtDCSEvent>=0 || fEventType==gkAliEventTypeReadPreprocessor) {
1574 if (fpInputBlocks[indexUpdtDCSEvent].fPtr!=NULL && fpInputBlocks[indexUpdtDCSEvent].fSize>0) {
1575 modules.Append(reinterpret_cast<const char*>(fpInputBlocks[indexUpdtDCSEvent].fPtr), fpInputBlocks[indexUpdtDCSEvent].fSize);
1577 HLTDebug("received preprocessor update command: detectors %s", modules.IsNull()?"ALL":modules.Data());
1578 int tmpResult=ReadPreprocessorValues(modules[0]==0?"ALL":modules.Data());
1580 HLTWarning("preprocessor update of component %p (%s) failed with error code %d", this, GetComponentID(), tmpResult);
1584 // processing function needs to be called if there are no input data
1585 // blocks in order to make data source components working.
1586 bSkipDataProcessing&=~skipModeDefault;
1589 // data processing is not skipped if the component explicitly asks
1590 // for the private blocks
1591 if (fRequireSteeringBlocks) bSkipDataProcessing=0;
1593 AliHLTComponentBlockDataList blockData;
1594 if (iResult>=0 && !bSkipDataProcessing)
1595 { // dont delete, sets the scope for the stopwatch guard
1596 // do not use ALIHLTCOMPONENT_DA_STOPWATCH(); macro
1597 // in order to avoid 'shadowed variable' warning
1598 AliHLTStopwatchGuard swguard2(fpStopwatches!=NULL?reinterpret_cast<TStopwatch*>(fpStopwatches->At((int)kSWDA)):NULL);
1599 iResult=DoProcessing(evtData, blocks, trigData, outputPtr, size, blockData, edd);
1600 } // end of the scope of the stopwatch guard
1601 if (iResult>=0 && !bSkipDataProcessing) {
1602 if (fOutputBlocks.size()>0) {
1603 // High Level interface
1605 //HLTDebug("got %d block(s) via high level interface", fOutputBlocks.size());
1606 // sync memory files and descriptors
1607 AliHLTMemoryFilePList::iterator element=fMemFiles.begin();
1609 while (element!=fMemFiles.end() && iResult>=0) {
1611 if ((*element)->IsClosed()==0) {
1612 HLTWarning("memory file has not been closed, force flush");
1613 iResult=CloseMemoryFile(*element);
1620 // create the descriptor list
1621 if (blockData.size()>0) {
1622 HLTError("low level and high interface must not be mixed; use PushBack methods to insert data blocks");
1625 if (compStats.size()>0 && IsDataEvent()) {
1626 int offset=AddComponentStatistics(fOutputBlocks, fpOutputBuffer, fOutputBufferSize, fOutputBufferFilled, compStats);
1627 if (offset>0) fOutputBufferFilled+=offset;
1629 if (bAddComponentTableEntry) {
1630 int offset=AddComponentTableEntry(fOutputBlocks, fpOutputBuffer, fOutputBufferSize, fOutputBufferFilled, parentComponentTables);
1631 if (offset>0) size+=offset;
1633 if (forwardedBlocks.size()>0) {
1634 fOutputBlocks.insert(fOutputBlocks.end(), forwardedBlocks.begin(), forwardedBlocks.end());
1636 iResult=MakeOutputDataBlockList(fOutputBlocks, &outputBlockCnt, &outputBlocks);
1637 size=fOutputBufferFilled;
1641 // Low Level interface
1642 if (compStats.size()>0) {
1643 int offset=AddComponentStatistics(blockData, fpOutputBuffer, fOutputBufferSize, size, compStats);
1644 if (offset>0) size+=offset;
1646 if (bAddComponentTableEntry) {
1647 int offset=AddComponentTableEntry(blockData, fpOutputBuffer, fOutputBufferSize, size, parentComponentTables);
1648 if (offset>0) size+=offset;
1650 if (forwardedBlocks.size()>0) {
1651 blockData.insert(blockData.end(), forwardedBlocks.begin(), forwardedBlocks.end());
1653 iResult=MakeOutputDataBlockList(blockData, &outputBlockCnt, &outputBlocks);
1656 HLTFatal("component %s (%p): can not convert output block descriptor list", GetComponentID(), this);
1659 if (iResult<0 || bSkipDataProcessing) {
1663 CleanupInputObjects();
1664 if (iResult>=0 && IsDataEvent()) {
1665 IncrementEventCounter();
1667 if (outputBlockCnt==0) {
1668 // no output blocks, set size to 0
1671 FillEventData(fCurrentEventData);
1675 int AliHLTComponent::AddComponentStatistics(AliHLTComponentBlockDataList& blocks,
1676 AliHLTUInt8_t* buffer,
1677 AliHLTUInt32_t bufferSize,
1678 AliHLTUInt32_t offset,
1679 AliHLTComponentStatisticsList& stats) const
1681 // see header file for function documentation
1683 #if defined(__DEBUG) || defined(HLT_COMPONENT_STATISTICS)
1684 if (stats.size()==0) return -ENOENT;
1685 // check if there is space for at least one entry
1686 if (offset+sizeof(AliHLTComponentStatistics)>bufferSize) return 0;
1687 stats[0].fTotalOutputSize=offset;
1688 stats[0].fOutputBlockCount=blocks.size();
1690 fpBenchmark->Stop();
1691 stats[0].fTime=(AliHLTUInt32_t)(fpBenchmark->RealTime()*ALIHLTCOMPONENT_STATTIME_SCALER);
1692 stats[0].fCTime=(AliHLTUInt32_t)(fpBenchmark->CpuTime()*ALIHLTCOMPONENT_STATTIME_SCALER);
1693 fpBenchmark->Continue();
1695 if (offset+stats.size()*sizeof(AliHLTComponentStatistics)>bufferSize) {
1696 AliHLTUInt32_t removedLevel=0;
1698 // remove all entries of the level of the last entry
1699 removedLevel=stats.back().fLevel;
1700 AliHLTComponentStatisticsList::iterator element=stats.begin();
1702 while (element!=stats.end()) {
1703 if (element->fLevel<=removedLevel) {
1704 element=stats.erase(element);
1709 } while (stats.size()>1 &&
1710 (offset+stats.size()*sizeof(AliHLTComponentStatistics)>bufferSize));
1712 assert(stats.size()>0);
1713 if (stats.size()==0) return 0;
1715 if (offset+stats.size()*sizeof(AliHLTComponentStatistics)<=bufferSize) {
1716 AliHLTComponentBlockData bd;
1717 FillBlockData( bd );
1718 bd.fOffset = offset;
1719 bd.fSize = stats.size()*sizeof(AliHLTComponentStatistics);
1720 bd.fDataType = kAliHLTDataTypeComponentStatistics;
1721 bd.fSpecification = kAliHLTVoidDataSpec;
1722 unsigned int master=0;
1723 for (unsigned int i=1; i<blocks.size(); i++) {
1724 if (blocks[i].fSize>blocks[master].fSize &&
1725 !MatchExactly(blocks[i].fDataType, kAliHLTVoidDataType|kAliHLTDataOriginPrivate))
1728 if (blocks.size()>0 && !MatchExactly(blocks[master].fDataType, kAliHLTVoidDataType|kAliHLTDataOriginPrivate)) {
1729 // take the data origin of the biggest block as specification
1730 // this is similar to the treatment in the HOMER interface. For traditional
1731 // reasons, the bytes are swapped there on a little endian architecture, so
1732 // we do it as well.
1733 memcpy(&bd.fSpecification, &blocks[master].fDataType.fOrigin, sizeof(bd.fSpecification));
1734 #ifdef R__BYTESWAP // set on little endian architectures
1735 bd.fSpecification=((bd.fSpecification & 0xFFULL) << 24) |
1736 ((bd.fSpecification & 0xFF00ULL) << 8) |
1737 ((bd.fSpecification & 0xFF0000ULL) >> 8) |
1738 ((bd.fSpecification & 0xFF000000ULL) >> 24);
1741 memcpy(buffer+offset, &(stats[0]), bd.fSize);
1742 blocks.push_back(bd);
1746 if (blocks.size() && buffer && bufferSize && offset && stats.size()) {
1747 // get rid of warning
1753 int AliHLTComponent::AddComponentTableEntry(AliHLTComponentBlockDataList& blocks,
1754 AliHLTUInt8_t* buffer,
1755 AliHLTUInt32_t bufferSize,
1756 AliHLTUInt32_t offset,
1757 const vector<AliHLTUInt32_t>& parents) const
1759 // see header file for function documentation
1761 #if defined(__DEBUG) || defined(HLT_COMPONENT_STATISTICS)
1762 // the payload consists of the AliHLTComponentTableEntry struct,
1763 // followed by a an array of 32bit crc chain ids and the component
1764 // description string
1765 unsigned int payloadSize=sizeof(AliHLTComponentTableEntry);
1766 payloadSize+=parents.size()*sizeof(AliHLTUInt32_t);
1768 // the component description has the following format:
1769 // chain-id{component-id:arguments}
1770 const char* componentId=const_cast<AliHLTComponent*>(this)->GetComponentID();
1771 unsigned int descriptionSize=fChainId.size()+1;
1772 descriptionSize+=2; // the '{}' around the component id
1773 descriptionSize+=strlen(componentId);
1774 descriptionSize+=1; // the ':' between component id and arguments
1775 descriptionSize+=fComponentArgs.size();
1777 payloadSize+=descriptionSize;
1778 if (buffer && (offset+payloadSize<=bufferSize)) {
1779 AliHLTUInt8_t* pTgt=buffer+offset;
1780 memset(pTgt, 0, payloadSize);
1783 AliHLTComponentTableEntry* pEntry=reinterpret_cast<AliHLTComponentTableEntry*>(pTgt);
1784 pEntry->fStructSize=sizeof(AliHLTComponentTableEntry);
1785 pEntry->fNofParents=parents.size();
1786 pEntry->fSizeDescription=descriptionSize;
1787 pTgt=pEntry->fBuffer;
1789 // write array of parents
1790 if (parents.size()>0) {
1791 unsigned int copy=parents.size()*sizeof(vector<AliHLTUInt32_t>::value_type);
1792 memcpy(pTgt, &parents[0], parents.size()*sizeof(vector<AliHLTUInt32_t>::value_type));
1796 // write component description
1797 memcpy(pTgt, fChainId.c_str(), fChainId.size());
1798 pTgt+=fChainId.size();
1800 memcpy(pTgt, componentId, strlen(componentId));
1801 pTgt+=strlen(componentId);
1803 memcpy(pTgt, fComponentArgs.c_str(), fComponentArgs.size());
1804 pTgt+=fComponentArgs.size();
1808 AliHLTComponentBlockData bd;
1809 FillBlockData( bd );
1810 bd.fOffset = offset;
1811 bd.fSize = payloadSize;
1812 bd.fDataType = kAliHLTDataTypeComponentTable;
1813 bd.fSpecification = fChainIdCrc;
1814 blocks.push_back(bd);
1818 if (blocks.size() && buffer && bufferSize && offset && parents.size()) {
1819 // get rid of warning
1825 AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard()
1830 // standard constructor (not for use)
1833 AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(TStopwatch* pStopwatch)
1835 fpStopwatch(pStopwatch),
1840 // check for already existing guard
1841 if (fgpCurrent) fpPrec=fgpCurrent;
1844 // stop the preceeding guard if it controls a different stopwatch
1846 if (fpPrec && fpPrec!=this) bStart=fpPrec->Hold(fpStopwatch);
1848 // start the stopwatch if the current guard controls a different one
1849 if (fpStopwatch && bStart==1) fpStopwatch->Start(kFALSE);
1852 AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(const AliHLTStopwatchGuard&)
1858 // copy constructor not for use
1862 AliHLTComponent::AliHLTStopwatchGuard& AliHLTComponent::AliHLTStopwatchGuard::operator=(const AliHLTStopwatchGuard&)
1865 // assignment operator not for use
1872 AliHLTComponent::AliHLTStopwatchGuard* AliHLTComponent::AliHLTStopwatchGuard::fgpCurrent=NULL;
1874 AliHLTComponent::AliHLTStopwatchGuard::~AliHLTStopwatchGuard()
1878 // resume the preceeding guard if it controls a different stopwatch
1880 if (fpPrec && fpPrec!=this) bStop=fpPrec->Resume(fpStopwatch);
1882 // stop the stopwatch if the current guard controls a different one
1883 if (fpStopwatch && bStop==1) fpStopwatch->Stop();
1885 // resume to the preceeding guard
1889 int AliHLTComponent::AliHLTStopwatchGuard::Hold(TStopwatch* pSucc)
1891 // see header file for function documentation
1892 if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Stop();
1893 return fpStopwatch!=pSucc?1:0;
1896 int AliHLTComponent::AliHLTStopwatchGuard::Resume(TStopwatch* pSucc)
1898 // see header file for function documentation
1899 if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Start(kFALSE);
1900 return fpStopwatch!=pSucc?1:0;
1903 int AliHLTComponent::SetStopwatch(TObject* pSW, AliHLTStopwatchType type)
1905 // see header file for function documentation
1907 if (pSW!=NULL && type<kSWTypeCount) {
1908 if (fpStopwatches) {
1909 TObject* pObj=fpStopwatches->At((int)type);
1910 if (pSW==NULL // explicit reset
1911 || pObj==NULL) { // explicit set
1912 fpStopwatches->AddAt(pSW, (int)type);
1913 } else if (pObj!=pSW) {
1914 HLTWarning("stopwatch %d already set, reset first", (int)type);
1924 int AliHLTComponent::SetStopwatches(TObjArray* pStopwatches)
1926 // see header file for function documentation
1927 if (pStopwatches==NULL) return -EINVAL;
1930 for (int i=0 ; i<(int)kSWTypeCount && pStopwatches->GetEntries(); i++)
1931 SetStopwatch(pStopwatches->At(i), (AliHLTStopwatchType)i);
1935 AliHLTUInt32_t AliHLTComponent::GetRunNo() const
1937 // see header file for function documentation
1938 if (fpRunDesc==NULL) return kAliHLTVoidRunNo;
1939 return fpRunDesc->fRunNo;
1942 AliHLTUInt32_t AliHLTComponent::GetRunType() const
1944 // see header file for function documentation
1945 if (fpRunDesc==NULL) return kAliHLTVoidRunType;
1946 return fpRunDesc->fRunType;
1949 bool AliHLTComponent::IsDataEvent(AliHLTUInt32_t* pTgt)
1951 // see header file for function documentation
1952 if (pTgt) *pTgt=fEventType;
1953 return (fEventType==gkAliEventTypeData ||
1954 fEventType==gkAliEventTypeDataReplay ||
1955 fEventType==gkAliEventTypeCalibration);
1958 int AliHLTComponent::CopyStruct(void* pStruct, unsigned int iStructSize, unsigned int iBlockNo,
1959 const char* structname, const char* eventname)
1961 // see header file for function documentation
1963 if (pStruct!=NULL && iStructSize>sizeof(AliHLTUInt32_t)) {
1964 if (fpInputBlocks!=NULL && iBlockNo<fCurrentEventData.fBlockCnt) {
1965 AliHLTUInt32_t* pTgt=(AliHLTUInt32_t*)pStruct;
1966 if (fpInputBlocks[iBlockNo].fPtr && fpInputBlocks[iBlockNo].fSize) {
1967 AliHLTUInt32_t copy=*((AliHLTUInt32_t*)fpInputBlocks[iBlockNo].fPtr);
1968 if (fpInputBlocks[iBlockNo].fSize!=copy) {
1969 HLTWarning("%s event: mismatch of block size (%d) and structure size (%d)", eventname, fpInputBlocks[iBlockNo].fSize, copy);
1970 if (copy>fpInputBlocks[iBlockNo].fSize) copy=fpInputBlocks[iBlockNo].fSize;
1972 if (copy!=iStructSize) {
1973 HLTWarning("%s event: mismatch in %s version (data type version %d)", eventname, structname, ALIHLT_DATA_TYPES_VERSION);
1974 if (copy>iStructSize) {
1977 memset(pTgt, 0, iStructSize);
1980 memcpy(pTgt, fpInputBlocks[iBlockNo].fPtr, copy);
1984 HLTWarning("%s event: missing data block", eventname);
1990 HLTError("invalid struct");
1996 void AliHLTComponent::SetDDLBit(AliHLTEventDDL &list, Int_t ddlId, Bool_t state ) const
1998 // see header file for function documentation
2000 // -- Detector offset
2001 Int_t ddlIdBase = TMath::FloorNint( (Double_t) ddlId / 256.0 );
2003 // -- Word Base = 1. word of detector ( TPC has 8 words, TOF 3 )
2006 if ( ddlIdBase <= 3 )
2007 wordBase = ddlIdBase;
2008 else if ( ddlIdBase > 3 && ddlIdBase < 5 )
2009 wordBase = ddlIdBase + 7;
2011 wordBase = ddlIdBase + 9;
2013 // -- Bit index in Word
2014 Int_t bitIdx = ddlId % 32;
2017 Int_t wordIdx = wordBase;
2019 // -- if TPC (3) or TOD (5) add word idx
2020 if ( ( ddlIdBase == 3 ) || ( ddlIdBase == 5 ) ) {
2021 wordIdx += TMath::FloorNint( (Double_t) ( ddlId - ( ddlIdBase * 256 ) ) / 32.0 );
2024 // -- Set -- 'OR' word with bit mask;
2026 list.fList[wordIdx] |= ( 0x00000001 << bitIdx );
2027 // -- Unset -- 'AND' word with bit mask;
2029 list.fList[wordIdx] &= ( 0xFFFFFFFF ^ ( 0x00000001 << bitIdx ) );
2032 Int_t AliHLTComponent::GetFirstUsedDDLWord(AliHLTEventDDL &list) const
2034 // see header file for function documentation
2038 for ( Int_t wordNdx = 0 ; wordNdx < gkAliHLTDDLListSize ; wordNdx++ ) {
2040 if ( list.fList[wordNdx] != 0 && iResult == -1 ) {
2041 // check for special cases TPC and TOF
2042 if ( wordNdx > 3 && wordNdx <= 10 ) {
2046 else if ( wordNdx > 12 && wordNdx <= 14 ) {
2053 else if ( list.fList[wordNdx] != 0 && iResult >= 0 ) {
2054 HLTError( "DDLIDs for minimum of TWO detectors ( %d, %d ) set, this function works only for ONE detector.", iResult, wordNdx );
2063 AliHLTUInt32_t AliHLTComponent::CalculateChecksum(const AliHLTUInt8_t* buffer, int size)
2065 // see header file for function documentation
2066 AliHLTUInt32_t remainder = 0;
2067 const AliHLTUInt8_t crcwidth=(8*sizeof(AliHLTUInt32_t));
2068 const AliHLTUInt32_t topbit=1 << (crcwidth-1);
2069 const AliHLTUInt32_t polynomial=0xD8; /* 11011 followed by 0's */
2072 // http://www.netrino.com/Embedded-Systems/How-To/CRC-Calculation-C-Code
2075 * Perform modulo-2 division, a byte at a time.
2077 for (int byte = 0; byte < size; ++byte)
2080 * Bring the next byte into the remainder.
2082 remainder ^= (buffer[byte] << (crcwidth - 8));
2085 * Perform modulo-2 division, a bit at a time.
2087 for (uint8_t bit = 8; bit > 0; --bit)
2090 * Try to divide the current data bit.
2092 if (remainder & topbit)
2094 remainder = (remainder << 1) ^ polynomial;
2098 remainder = (remainder << 1);
2104 * The final remainder is the CRC result.
2109 int AliHLTComponent::ExtractComponentTableEntry(const AliHLTUInt8_t* pBuffer, AliHLTUInt32_t size,
2110 string& retChainId, string& retCompId, string& retCompArgs,
2111 vector<AliHLTUInt32_t>& parents)
2113 // see header file for function documentation
2116 retCompArgs.clear();
2118 if (!pBuffer || size==0) return 0;
2120 const AliHLTComponentTableEntry* pEntry=reinterpret_cast<const AliHLTComponentTableEntry*>(pBuffer);
2121 if (size<8/* the initial size of the structure*/ ||
2122 pEntry==NULL || pEntry->fStructSize<8) return -ENOMSG;
2123 const AliHLTUInt32_t* pParents=reinterpret_cast<const AliHLTUInt32_t*>(pEntry->fBuffer);
2124 const AliHLTUInt8_t* pEnd=pBuffer+size;
2126 if (pParents+pEntry->fNofParents>=reinterpret_cast<const AliHLTUInt32_t*>(pEnd)) return -ENODEV;
2127 for (unsigned int i=0; i<pEntry->fNofParents; i++, pParents++) {
2128 parents.push_back(*pParents);
2131 const char* pDescription=reinterpret_cast<const char*>(pParents);
2132 if (pDescription+pEntry->fSizeDescription>=reinterpret_cast<const char*>(pEnd) ||
2133 *(pDescription+pEntry->fSizeDescription)!=0) {
2137 TString descriptor=reinterpret_cast<const char*>(pDescription);
2141 TObjArray* pTokens=descriptor.Tokenize("{");
2144 if (pTokens->GetEntries()>n) {
2145 retChainId=((TObjString*)pTokens->At(n++))->GetString();
2147 if (pTokens->GetEntries()>n) {
2148 compId=((TObjString*)pTokens->At(n++))->GetString();
2152 if (!compId.IsNull() && (pTokens=compId.Tokenize(":"))!=NULL) {
2154 if (pTokens->GetEntries()>n) {
2155 compId=((TObjString*)pTokens->At(n++))->GetString();
2157 if (pTokens->GetEntries()>n) {
2158 compArgs=((TObjString*)pTokens->At(n++))->GetString();
2162 compId.ReplaceAll("}", "");
2163 compArgs.ReplaceAll("}", "");
2166 retCompArgs=compArgs;
2168 if (retChainId.size()==0) return -ENODATA;
2173 int AliHLTComponent::LoggingVarargs(AliHLTComponentLogSeverity severity,
2174 const char* originClass, const char* originFunc,
2175 const char* file, int line, ... ) const
2177 // see header file for function documentation
2181 va_start(args, line);
2183 // logging function needs to be const in order to be called from const member functions
2184 // without problems. But at this point we face the problem with virtual members which
2185 // are not necessarily const.
2186 AliHLTComponent* nonconst=const_cast<AliHLTComponent*>(this);
2187 AliHLTLogging::SetLogString("%s (%s, %p): ",
2188 fChainId[0]!=0?fChainId.c_str():nonconst->GetComponentID(),
2189 nonconst->GetComponentID(), this);
2190 iResult=SendMessage(severity, originClass, originFunc, file, line, AliHLTLogging::BuildLogString(NULL, args, true /*append*/));