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"
40 #include "AliHLTMemoryFile.h"
41 #include "AliHLTMisc.h"
46 * default compression level for ROOT objects
48 #define ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION 5
49 #define ALIHLTCOMPONENT_STATTIME_SCALER 1000000
51 /** ROOT macro for the implementation of ROOT specific class methods */
52 ClassImp(AliHLTComponent);
54 /** stopwatch macro using the stopwatch guard */
55 #define ALIHLTCOMPONENT_STOPWATCH(type) AliHLTStopwatchGuard swguard(fpStopwatches!=NULL?reinterpret_cast<TStopwatch*>(fpStopwatches->At((int)type)):NULL)
56 //#define ALIHLTCOMPONENT_STOPWATCH(type)
58 /** stopwatch macro for operations of the base class */
59 #define ALIHLTCOMPONENT_BASE_STOPWATCH() ALIHLTCOMPONENT_STOPWATCH(kSWBase)
60 /** stopwatch macro for operations of the detector algorithm (DA) */
61 #define ALIHLTCOMPONENT_DA_STOPWATCH() ALIHLTCOMPONENT_STOPWATCH(kSWDA)
63 AliHLTComponent::AliHLTComponent()
71 fCurrentInputBlock(-1),
72 fSearchDataType(kAliHLTVoidDataType),
77 fOutputBufferFilled(0),
79 fpStopwatches(new TObjArray(kSWTypeCount)),
83 fCDBSetRunNoFunc(false),
87 fRequireSteeringBlocks(false),
88 fEventType(gkAliEventTypeUnknown),
91 fEventDoneDataSize(0),
92 fCompressionLevel(ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION)
94 , fpTriggerClasses(NULL)
96 // see header file for class documentation
98 // refer to README to build package
100 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
101 memset(&fEnvironment, 0, sizeof(AliHLTAnalysisEnvironment));
102 if (fgpComponentHandler)
103 fgpComponentHandler->ScheduleRegister(this);
104 //SetLocalLoggingLevel(kHLTLogDefault);
107 AliHLTComponent::~AliHLTComponent()
109 // see header file for function documentation
110 if (fpBenchmark) delete fpBenchmark;
113 CleanupInputObjects();
114 if (fpStopwatches!=NULL) delete fpStopwatches;
116 AliHLTMemoryFilePList::iterator element=fMemFiles.begin();
117 while (element!=fMemFiles.end()) {
119 if ((*element)->IsClosed()==0) {
120 HLTWarning("memory file has not been closed, possible data loss or incomplete buffer");
121 // close but do not flush as we dont know whether the buffer is still valid
122 (*element)->CloseMemoryFile(0);
134 delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
137 if (fpTriggerClasses) {
138 fpTriggerClasses->Delete();
139 delete fpTriggerClasses;
141 fpTriggerClasses=NULL;
144 AliHLTComponentHandler* AliHLTComponent::fgpComponentHandler=NULL;
146 int AliHLTComponent::SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite)
148 // see header file for function documentation
150 if (fgpComponentHandler==NULL || bOverwrite!=0)
151 fgpComponentHandler=pCH;
157 int AliHLTComponent::UnsetGlobalComponentHandler()
159 // see header file for function documentation
160 return SetGlobalComponentHandler(NULL,1);
163 int AliHLTComponent::SetComponentEnvironment(const AliHLTAnalysisEnvironment* comenv, void* environParam)
165 // see header file for function documentation
166 HLTLogKeyword(fChainId.c_str());
169 memset(&fEnvironment, 0, sizeof(AliHLTAnalysisEnvironment));
170 memcpy(&fEnvironment, comenv, comenv->fStructSize<sizeof(AliHLTAnalysisEnvironment)?comenv->fStructSize:sizeof(AliHLTAnalysisEnvironment));
171 fEnvironment.fStructSize=sizeof(AliHLTAnalysisEnvironment);
172 fEnvironment.fParam=environParam;
177 int AliHLTComponent::Init(const AliHLTAnalysisEnvironment* comenv, void* environParam, int argc, const char** argv )
179 // see header file for function documentation
180 HLTLogKeyword(fChainId.c_str());
183 SetComponentEnvironment(comenv, environParam);
186 const char** pArguments=NULL;
191 pArguments=new const char*[argc];
193 for (int i=0; i<argc && iResult>=0; i++) {
194 if (fComponentArgs.size()>0) fComponentArgs+=" ";
195 fComponentArgs+=argv[i];
197 if (argument.IsNull()) continue;
200 if (argument.CompareTo("-benchmark")==0) {
203 } else if (argument.BeginsWith("-loglevel=")) {
204 TString parameter=argument.ReplaceAll("-loglevel=", "");
205 parameter.Remove(TString::kLeading, ' '); // remove all blanks
206 if (parameter.BeginsWith("0x") &&
207 parameter.Replace(0,2,"",0).IsHex()) {
208 unsigned int loglevel=kHLTLogNone;
209 sscanf(parameter.Data(),"%x", &loglevel);
210 SetLocalLoggingLevel((AliHLTComponentLogSeverity)loglevel);
212 HLTError("wrong parameter for argument %s, hex number expected", argument.Data());
215 // -object-compression=
216 } else if (argument.BeginsWith("-object-compression=")) {
217 argument.ReplaceAll("-object-compression=", "");
218 if (argument.IsDigit()) {
219 fCompressionLevel=argument.Atoi();
220 if (fCompressionLevel<0 || fCompressionLevel>9) {
221 HLTWarning("invalid compression level %d, setting to default %d", fCompressionLevel, ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION);
222 fCompressionLevel=ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION;
225 HLTError("wrong parameter for argument -object-compression, number expected");
228 pArguments[iNofChildArgs++]=argv[i];
236 HLTError("missing parameter for argument %s", argument.Data());
240 iResult=DoInit(iNofChildArgs, pArguments);
245 // find out if the component wants to get the steering events
247 AliHLTComponentDataTypeList inputDt;
248 GetInputDataTypes(inputDt);
249 for (AliHLTComponentDataTypeList::iterator dt=inputDt.begin();
250 dt!=inputDt.end() && !fRequireSteeringBlocks;
252 fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeSOR);
253 fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeRunType);
254 fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeEOR);
255 fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeDDL);
256 fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeComponentStatistics);
259 if (pArguments) delete [] pArguments;
261 #if defined(__DEBUG) || defined(HLT_COMPONENT_STATISTICS)
262 // benchmarking stopwatch for the component statistics
263 fpBenchmark=new TStopwatch;
269 int AliHLTComponent::Deinit()
271 // see header file for function documentation
272 HLTLogKeyword(fChainId.c_str());
276 // TODO: the warning should be kept, but the condition is wrong since the
277 // AliHLTRunDesc is set before the SOR event in the SetRunDescription
278 // method. A couple of state flags should be defined but that is a bit more
279 // work to do. For the moment disable the warning (2009-07-01)
280 //HLTWarning("did not receive EOR for run %d", fpRunDesc->fRunNo);
281 AliHLTRunDesc* pRunDesc=fpRunDesc;
285 if (fpTriggerClasses) {
286 fpTriggerClasses->Delete();
287 delete fpTriggerClasses;
289 fpTriggerClasses=NULL;
295 int AliHLTComponent::InitCDB(const char* cdbPath, AliHLTComponentHandler* pHandler)
297 // see header file for function documentation
299 HLTInfo("Using CDB: %s", cdbPath);
301 // I have to think about separating the library handling from the
302 // component handler. Requiring the component handler here is not
303 // the cleanest solution.
304 // We presume the library already to be loaded, which is the case
305 // because it is loaded in the initialization of the logging functionality
308 AliHLTMiscInitCDB_t pFunc=(AliHLTMiscInitCDB_t)pHandler->FindSymbol(ALIHLTMISC_LIBRARY, ALIHLTMISC_INIT_CDB);
311 if (cdbPath && cdbPath[0]!=0) {
313 // very temporary fix, have to check for other formats
314 if (!path.BeginsWith("local://")) {
319 if ((iResult=(*pFunc)(path.Data()))>=0) {
320 if (!(fCDBSetRunNoFunc=pHandler->FindSymbol(ALIHLTMISC_LIBRARY, ALIHLTMISC_SET_CDB_RUNNO))) {
321 Message(NULL, kHLTLogWarning, "AliHLTComponent::InitCDB", "init CDB",
322 "can not find function to set CDB run no");
326 Message(NULL, kHLTLogError, "AliHLTComponent::InitCDB", "init CDB",
327 "can not find initialization function");
336 int AliHLTComponent::SetCDBRunNo(int runNo)
338 // see header file for function documentation
339 if (!fCDBSetRunNoFunc) return 0;
340 return (*((AliHLTMiscSetCDBRunNo_t)fCDBSetRunNoFunc))(runNo);
343 int AliHLTComponent::SetRunDescription(const AliHLTRunDesc* desc, const char* /*runType*/)
345 // see header file for function documentation
346 if (!desc) return -EINVAL;
347 if (desc->fStructSize!=sizeof(AliHLTRunDesc)) {
348 HLTError("invalid size of RunDesc struct (%ul)", desc->fStructSize);
353 fpRunDesc=new AliHLTRunDesc;
354 if (!fpRunDesc) return -ENOMEM;
355 *fpRunDesc=kAliHLTVoidRunDesc;
358 if (fpRunDesc->fRunNo!=kAliHLTVoidRunNo && fpRunDesc->fRunNo!=desc->fRunNo) {
359 HLTWarning("Run description has already been set");
362 SetCDBRunNo(fpRunDesc->fRunNo);
363 // TODO: we have to decide about the runType
367 int AliHLTComponent::SetComponentDescription(const char* desc)
369 // see header file for function documentation
373 TString descriptor=desc;
374 TObjArray* pTokens=descriptor.Tokenize(" ");
376 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
377 TString argument=((TObjString*)pTokens->At(i++))->GetString();
378 if (!argument || argument.IsNull()) continue;
381 if (argument.BeginsWith("chainid")) {
382 argument.ReplaceAll("chainid", "");
383 if (argument.BeginsWith("=")) {
384 fChainId=argument.Replace(0,1,"");
385 fChainIdCrc=CalculateChecksum((const AliHLTUInt8_t*)fChainId.c_str(), fChainId.length());
386 HLTDebug("setting component description: chain id %s crc 0x%8x", fChainId.c_str(), fChainIdCrc);
391 HLTWarning("unknown component description %s", argument.Data());
399 int AliHLTComponent::DoInit( int /*argc*/, const char** /*argv*/)
401 // default implementation, childs can overload
402 HLTLogKeyword("dummy");
406 int AliHLTComponent::DoDeinit()
408 // default implementation, childs can overload
409 HLTLogKeyword("dummy");
413 int AliHLTComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/)
415 // default implementation, childs can overload
416 HLTLogKeyword("dummy");
420 int AliHLTComponent::ReadPreprocessorValues(const char* /*modules*/)
422 // default implementation, childs can overload
423 HLTLogKeyword("dummy");
427 int AliHLTComponent::StartOfRun()
429 // default implementation, childs can overload
430 HLTLogKeyword("dummy");
434 int AliHLTComponent::EndOfRun()
436 // default implementation, childs can overload
437 HLTLogKeyword("dummy");
442 int AliHLTComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& /*tgtList*/)
444 // default implementation, childs can overload
445 HLTLogKeyword("dummy");
449 void AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2] ) const
451 // see header file for function documentation
452 memset( output, 0, kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2 );
453 strncat( output, type.fOrigin, kAliHLTComponentDataTypefOriginSize );
454 strcat( output, ":" );
455 strncat( output, type.fID, kAliHLTComponentDataTypefIDsize );
458 string AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, int mode)
460 // see header file for function documentation
466 for (i=0; i<kAliHLTComponentDataTypefOriginSize; i++) {
467 sprintf(tmp, "'%d", type.fOrigin[i]);
471 for (i=0; i<kAliHLTComponentDataTypefIDsize; i++) {
472 sprintf(tmp, "%d'", type.fID[i]);
481 for (i=0; i<kAliHLTComponentDataTypefOriginSize; i++) {
482 unsigned char* puc=(unsigned char*)type.fOrigin;
484 sprintf(tmp, "'\\%x", type.fOrigin[i]);
486 sprintf(tmp, "'%c", type.fOrigin[i]);
490 for (i=0; i<kAliHLTComponentDataTypefIDsize; i++) {
491 unsigned char* puc=(unsigned char*)type.fID;
493 sprintf(tmp, "\\%x'", type.fID[i]);
495 sprintf(tmp, "%c'", type.fID[i]);
501 if (type==kAliHLTVoidDataType) {
504 // some gymnastics in order to avoid a '0' which is part of either or both
505 // ID and origin terminating the whole string. Unfortunately, string doesn't
506 // stop appending at the '0' if the number of elements to append was
507 // explicitely specified
509 tmp.append(type.fOrigin, kAliHLTComponentDataTypefOriginSize);
510 out.append(tmp.c_str());
513 tmp.append(type.fID, kAliHLTComponentDataTypefIDsize);
514 out.append(tmp.c_str());
520 void* AliHLTComponent::AllocMemory( unsigned long size )
522 // see header file for function documentation
523 if (fEnvironment.fAllocMemoryFunc)
524 return (*fEnvironment.fAllocMemoryFunc)(fEnvironment.fParam, size );
525 HLTFatal("no memory allocation handler registered");
529 int AliHLTComponent::MakeOutputDataBlockList( const AliHLTComponentBlockDataList& blocks, AliHLTUInt32_t* blockCount,
530 AliHLTComponentBlockData** outputBlocks )
532 // see header file for function documentation
533 if ( blockCount==NULL || outputBlocks==NULL )
535 AliHLTUInt32_t count = blocks.size();
539 *outputBlocks = NULL;
542 *outputBlocks = reinterpret_cast<AliHLTComponentBlockData*>( AllocMemory( sizeof(AliHLTComponentBlockData)*count ) );
543 if ( !*outputBlocks )
545 for ( unsigned long i = 0; i < count; i++ ) {
546 (*outputBlocks)[i] = blocks[i];
547 if (MatchExactly(blocks[i].fDataType, kAliHLTAnyDataType)) {
548 (*outputBlocks)[i].fDataType=GetOutputDataType();
549 /* data type was set to the output data type by the PubSub AliRoot
550 Wrapper component, if data type of the block was ********:****.
551 Now handled by the component base class in order to have same
552 behavior when running embedded in AliRoot
553 memset((*outputBlocks)[i].fDataType.fID, '*', kAliHLTComponentDataTypefIDsize);
554 memset((*outputBlocks)[i].fDataType.fOrigin, '*', kAliHLTComponentDataTypefOriginSize);
563 int AliHLTComponent::GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd )
565 // see header file for function documentation
566 if (fEnvironment.fGetEventDoneDataFunc)
567 return (*fEnvironment.fGetEventDoneDataFunc)(fEnvironment.fParam, fCurrentEvent, size, edd );
571 int AliHLTComponent::ReserveEventDoneData( unsigned long size )
573 // see header file for function documentation
577 if (size>fEventDoneDataSize) {
578 AliHLTComponentEventDoneData* newEDD = reinterpret_cast<AliHLTComponentEventDoneData*>( new AliHLTUInt8_t[ sizeof(AliHLTComponentEventDoneData)+size ] );
581 newEDD->fStructSize = sizeof(AliHLTComponentEventDoneData);
582 newEDD->fDataSize = 0;
583 newEDD->fData = reinterpret_cast<AliHLTUInt8_t*>(newEDD)+newEDD->fStructSize;
584 if (fEventDoneData) {
585 memcpy( newEDD->fData, fEventDoneData->fData, fEventDoneData->fDataSize );
586 newEDD->fDataSize = fEventDoneData->fDataSize;
587 delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
589 fEventDoneData = newEDD;
590 fEventDoneDataSize = size;
596 int AliHLTComponent::PushEventDoneData( AliHLTUInt32_t eddDataWord )
600 if (fEventDoneData->fDataSize+sizeof(AliHLTUInt32_t)>fEventDoneDataSize)
602 *reinterpret_cast<AliHLTUInt32_t*>((reinterpret_cast<AliHLTUInt8_t*>(fEventDoneData->fData)+fEventDoneData->fDataSize)) = eddDataWord;
603 fEventDoneData->fDataSize += sizeof(AliHLTUInt32_t);
607 void AliHLTComponent::ReleaseEventDoneData()
610 delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
611 fEventDoneData = NULL;
612 fEventDoneDataSize = 0;
616 int AliHLTComponent::FindMatchingDataTypes(AliHLTComponent* pConsumer, AliHLTComponentDataTypeList* tgtList)
618 // see header file for function documentation
621 AliHLTComponentDataTypeList itypes;
622 AliHLTComponentDataTypeList otypes;
623 otypes.push_back(GetOutputDataType());
624 if (MatchExactly(otypes[0],kAliHLTMultipleDataType)) {
627 if ((count=GetOutputDataTypes(otypes))>0) {
628 } else if (GetComponentType()!=kSink) {
629 HLTWarning("component %s indicates multiple output data types but GetOutputDataTypes returns %d", GetComponentID(), count);
632 ((AliHLTComponent*)pConsumer)->GetInputDataTypes(itypes);
633 AliHLTComponentDataTypeList::iterator otype=otypes.begin();
634 for (;otype!=otypes.end();otype++) {
635 //PrintDataTypeContent((*otype), "publisher \'%s\'");
636 if ((*otype)==(kAliHLTAnyDataType|kAliHLTDataOriginPrivate)) {
637 if (tgtList) tgtList->push_back(*otype);
642 AliHLTComponentDataTypeList::iterator itype=itypes.begin();
643 for ( ; itype!=itypes.end() && (*itype)!=(*otype) ; itype++) {/* empty body */};
644 //if (itype!=itypes.end()) PrintDataTypeContent(*itype, "consumer \'%s\'");
645 if (itype!=itypes.end()) {
646 if (tgtList) tgtList->push_back(*otype);
656 void AliHLTComponent::PrintDataTypeContent(AliHLTComponentDataType& dt, const char* format)
658 // see header file for function documentation
659 const char* fmt="\'%s\'";
660 if (format) fmt=format;
661 AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, Form(fmt, (DataType2Text(dt)).c_str()));
662 AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL,
663 Form("%x %x %x %x %x %x %x %x : %x %x %x %x",
678 void AliHLTComponent::FillBlockData( AliHLTComponentBlockData& blockData )
680 // see header file for function documentation
681 blockData.fStructSize = sizeof(blockData);
682 FillShmData( blockData.fShmKey );
683 blockData.fOffset = ~(AliHLTUInt32_t)0;
684 blockData.fPtr = NULL;
686 FillDataType( blockData.fDataType );
687 blockData.fSpecification = kAliHLTVoidDataSpec;
690 void AliHLTComponent::FillShmData( AliHLTComponentShmData& shmData )
692 // see header file for function documentation
693 shmData.fStructSize = sizeof(shmData);
694 shmData.fShmType = gkAliHLTComponentInvalidShmType;
695 shmData.fShmID = gkAliHLTComponentInvalidShmID;
698 void AliHLTComponent::FillDataType( AliHLTComponentDataType& dataType )
700 // see header file for function documentation
701 dataType=kAliHLTAnyDataType;
704 void AliHLTComponent::CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt)
706 // see header file for function documentation
707 memcpy(&tgtdt.fID[0], &srcdt.fID[0], kAliHLTComponentDataTypefIDsize);
708 memcpy(&tgtdt.fOrigin[0], &srcdt.fOrigin[0], kAliHLTComponentDataTypefOriginSize);
711 void AliHLTComponent::SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin)
713 // see header file for function documentation
714 tgtdt.fStructSize=sizeof(AliHLTComponentDataType);
716 memset(&tgtdt.fID[0], 0, kAliHLTComponentDataTypefIDsize);
717 strncpy(&tgtdt.fID[0], id, strlen(id)<(size_t)kAliHLTComponentDataTypefIDsize?strlen(id):kAliHLTComponentDataTypefIDsize);
720 memset(&tgtdt.fOrigin[0], 0, kAliHLTComponentDataTypefOriginSize);
721 strncpy(&tgtdt.fOrigin[0], origin, strlen(origin)<(size_t)kAliHLTComponentDataTypefOriginSize?strlen(origin):kAliHLTComponentDataTypefOriginSize);
725 void AliHLTComponent::SetDataType(AliHLTComponentDataType& dt, AliHLTUInt64_t id, AliHLTUInt32_t origin)
727 // see header file for function documentation
728 dt.fStructSize=sizeof(AliHLTComponentDataType);
729 assert(kAliHLTComponentDataTypefIDsize==sizeof(id));
730 assert(kAliHLTComponentDataTypefOriginSize==sizeof(origin));
731 memcpy(&dt.fID, &id, kAliHLTComponentDataTypefIDsize);
732 memcpy(&dt.fOrigin, &origin, kAliHLTComponentDataTypefOriginSize);
735 void AliHLTComponent::FillEventData(AliHLTComponentEventData& evtData)
737 // see header file for function documentation
738 memset(&evtData, 0, sizeof(AliHLTComponentEventData));
739 evtData.fStructSize=sizeof(AliHLTComponentEventData);
740 evtData.fEventID=kAliHLTVoidEventID;
743 void AliHLTComponent::PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt)
745 // see header file for function documentation
747 msg.Form("AliHLTComponentDataType(%d): ID=\"", dt.fStructSize);
748 for ( int i = 0; i < kAliHLTComponentDataTypefIDsize; i++ ) {
749 if (dt.fID[i]!=0) msg+=dt.fID[i];
753 for ( int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++ ) {
754 if (dt.fOrigin[i]!=0) msg+=dt.fOrigin[i];
758 AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, msg.Data());
761 int AliHLTComponent::GetEventCount() const
763 // see header file for function documentation
767 int AliHLTComponent::IncrementEventCounter()
769 // see header file for function documentation
770 if (fEventCount>=0) fEventCount++;
774 int AliHLTComponent::GetNumberOfInputBlocks() const
776 // see header file for function documentation
777 if (fpInputBlocks!=NULL) {
778 return fCurrentEventData.fBlockCnt;
783 AliHLTEventID_t AliHLTComponent::GetEventId() const
785 // see header file for function documentation
786 if (fpInputBlocks!=NULL) {
787 return fCurrentEventData.fEventID;
792 const TObject* AliHLTComponent::GetFirstInputObject(const AliHLTComponentDataType& dt,
793 const char* classname,
796 // see header file for function documentation
797 ALIHLTCOMPONENT_BASE_STOPWATCH();
799 if (classname) fClassName=classname;
800 else fClassName.clear();
801 int idx=FindInputBlock(fSearchDataType, 0, 1);
804 HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(dt).c_str());
805 if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) {
806 fCurrentInputBlock=idx;
813 const TObject* AliHLTComponent::GetFirstInputObject(const char* dtID,
814 const char* dtOrigin,
815 const char* classname,
818 // see header file for function documentation
819 ALIHLTCOMPONENT_BASE_STOPWATCH();
820 AliHLTComponentDataType dt;
821 SetDataType(dt, dtID, dtOrigin);
822 return GetFirstInputObject(dt, classname, bForce);
825 const TObject* AliHLTComponent::GetNextInputObject(int bForce)
827 // see header file for function documentation
828 ALIHLTCOMPONENT_BASE_STOPWATCH();
829 int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1, 1);
830 //HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(fSearchDataType).c_str());
833 if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) {
834 fCurrentInputBlock=idx;
840 int AliHLTComponent::FindInputBlock(const AliHLTComponentDataType& dt, int startIdx, int bObject) const
842 // see header file for function documentation
844 if (fpInputBlocks!=NULL) {
845 int idx=startIdx<0?0:startIdx;
846 for ( ; (UInt_t)idx<fCurrentEventData.fBlockCnt && iResult==-ENOENT; idx++) {
847 if (dt!=fpInputBlocks[idx].fDataType) continue;
850 if (fpInputBlocks[idx].fPtr==NULL) continue;
851 AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr);
852 if (firstWord!=fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) continue;
860 TObject* AliHLTComponent::CreateInputObject(int idx, int bForce)
862 // see header file for function documentation
864 if (fpInputBlocks!=NULL) {
865 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
866 if (fpInputBlocks[idx].fPtr) {
867 AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr);
868 if (firstWord==fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) {
869 HLTDebug("create object from block %d size %d", idx, fpInputBlocks[idx].fSize);
870 AliHLTMessage msg(fpInputBlocks[idx].fPtr, fpInputBlocks[idx].fSize);
871 TClass* objclass=msg.GetClass();
872 pObj=msg.ReadObject(objclass);
873 if (pObj && objclass) {
874 HLTDebug("object %p type %s created", pObj, objclass->GetName());
878 } else if (bForce!=0) {
879 HLTError("size mismatch: block size %d, indicated %d", fpInputBlocks[idx].fSize, firstWord+sizeof(AliHLTUInt32_t));
882 HLTFatal("block descriptor empty");
885 HLTError("index %d out of range %d", idx, fCurrentEventData.fBlockCnt);
888 HLTError("no input blocks available");
894 TObject* AliHLTComponent::GetInputObject(int idx, const char* /*classname*/, int bForce)
896 // see header file for function documentation
897 if (fpInputObjects==NULL) {
898 fpInputObjects=new TObjArray(fCurrentEventData.fBlockCnt);
901 if (fpInputObjects) {
902 pObj=fpInputObjects->At(idx);
904 pObj=CreateInputObject(idx, bForce);
906 fpInputObjects->AddAt(pObj, idx);
910 HLTFatal("memory allocation failed: TObjArray of size %d", fCurrentEventData.fBlockCnt);
915 int AliHLTComponent::CleanupInputObjects()
917 // see header file for function documentation
918 if (!fpInputObjects) return 0;
919 TObjArray* array=fpInputObjects;
921 for (int i=0; i<array->GetEntries(); i++) {
922 TObject* pObj=array->At(i);
923 // grrr, garbage collection strikes back: When read via AliHLTMessage
924 // (CreateInputObject), and written to a TFile afterwards, the
925 // TFile::Close calls ROOOT's garbage collection. No clue why the
926 // object ended up in the key list and needs to be deleted
928 // Matthias 09.11.2008 follow up
929 // This approach doesn't actually work in all cases: the object table
930 // can be switched off globally, the flag needs to be checked here as
931 // well in order to avoid memory leaks.
932 // This means we have to find another solution for the problem if it
935 (!TObject::GetObjectStat() || gObjectTable->PtrIsValid(pObj))) {
943 AliHLTComponentDataType AliHLTComponent::GetDataType(const TObject* pObject)
945 // see header file for function documentation
946 ALIHLTCOMPONENT_BASE_STOPWATCH();
947 AliHLTComponentDataType dt=kAliHLTVoidDataType;
948 int idx=fCurrentInputBlock;
950 if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
952 HLTError("unknown object %p", pObject);
956 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
957 dt=fpInputBlocks[idx].fDataType;
959 HLTFatal("severe internal error, index out of range");
965 AliHLTUInt32_t AliHLTComponent::GetSpecification(const TObject* pObject)
967 // see header file for function documentation
968 ALIHLTCOMPONENT_BASE_STOPWATCH();
969 AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec;
970 int idx=fCurrentInputBlock;
972 if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
974 HLTError("unknown object %p", pObject);
978 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
979 iSpec=fpInputBlocks[idx].fSpecification;
981 HLTFatal("severe internal error, index out of range");
987 int AliHLTComponent::Forward(const TObject* pObject)
989 // see header file for function documentation
991 int idx=fCurrentInputBlock;
993 if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
995 HLTError("unknown object %p", pObject);
1000 fOutputBlocks.push_back(fpInputBlocks[idx]);
1005 int AliHLTComponent::Forward(const AliHLTComponentBlockData* pBlock)
1007 // see header file for function documentation
1009 int idx=fCurrentInputBlock;
1011 if (fpInputObjects==NULL || (idx=FindInputBlock(pBlock))>=0) {
1013 HLTError("unknown Block %p", pBlock);
1018 // check for fpInputBlocks pointer done in FindInputBlock
1019 fOutputBlocks.push_back(fpInputBlocks[idx]);
1024 const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const AliHLTComponentDataType& dt)
1026 // see header file for function documentation
1027 ALIHLTCOMPONENT_BASE_STOPWATCH();
1030 int idx=FindInputBlock(fSearchDataType, 0);
1031 const AliHLTComponentBlockData* pBlock=NULL;
1033 // check for fpInputBlocks pointer done in FindInputBlock
1034 pBlock=&fpInputBlocks[idx];
1035 fCurrentInputBlock=idx;
1040 const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const char* dtID,
1041 const char* dtOrigin)
1043 // see header file for function documentation
1044 ALIHLTCOMPONENT_BASE_STOPWATCH();
1045 AliHLTComponentDataType dt;
1046 SetDataType(dt, dtID, dtOrigin);
1047 return GetFirstInputBlock(dt);
1050 const AliHLTComponentBlockData* AliHLTComponent::GetInputBlock(int index) const
1052 // see header file for function documentation
1053 ALIHLTCOMPONENT_BASE_STOPWATCH();
1054 assert( 0 <= index and index < (int)fCurrentEventData.fBlockCnt );
1055 return &fpInputBlocks[index];
1058 const AliHLTComponentBlockData* AliHLTComponent::GetNextInputBlock()
1060 // see header file for function documentation
1061 ALIHLTCOMPONENT_BASE_STOPWATCH();
1062 int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1);
1063 const AliHLTComponentBlockData* pBlock=NULL;
1065 // check for fpInputBlocks pointer done in FindInputBlock
1066 pBlock=&fpInputBlocks[idx];
1067 fCurrentInputBlock=idx;
1072 int AliHLTComponent::FindInputBlock(const AliHLTComponentBlockData* pBlock) const
1074 // see header file for function documentation
1075 int iResult=-ENOENT;
1076 if (fpInputBlocks!=NULL) {
1078 if (pBlock>=fpInputBlocks && pBlock<fpInputBlocks+fCurrentEventData.fBlockCnt) {
1079 iResult=(int)(pBlock-fpInputBlocks);
1088 AliHLTUInt32_t AliHLTComponent::GetSpecification(const AliHLTComponentBlockData* pBlock)
1090 // see header file for function documentation
1091 ALIHLTCOMPONENT_BASE_STOPWATCH();
1092 AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec;
1093 int idx=fCurrentInputBlock;
1095 if (fpInputObjects==NULL || (idx=FindInputBlock(pBlock))>=0) {
1097 HLTError("unknown Block %p", pBlock);
1101 // check for fpInputBlocks pointer done in FindInputBlock
1102 iSpec=fpInputBlocks[idx].fSpecification;
1107 int AliHLTComponent::PushBack(TObject* pObject, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
1108 void* pHeader, int headerSize)
1110 // see header file for function documentation
1111 ALIHLTCOMPONENT_BASE_STOPWATCH();
1115 AliHLTMessage msg(kMESS_OBJECT);
1116 msg.SetCompressionLevel(fCompressionLevel);
1117 msg.WriteObject(pObject);
1118 Int_t iMsgLength=msg.Length();
1120 // Matthias Sep 2008
1121 // NOTE: AliHLTMessage does implement it's own SetLength method
1122 // which is not architecture independent. The original SetLength
1123 // stores the size always in network byte order.
1124 // I'm trying to remember the rational for that, might be that
1125 // it was just some lack of knowledge. Want to change this, but
1126 // has to be done carefullt to be backward compatible.
1127 msg.SetLength(); // sets the length to the first (reserved) word
1129 // does nothing if the level is 0
1132 char *mbuf = msg.Buffer();
1133 if (msg.CompBuffer()) {
1134 msg.SetLength(); // set once more to have to byte order
1135 mbuf = msg.CompBuffer();
1136 iMsgLength = msg.CompLength();
1139 iResult=InsertOutputBlock(mbuf, iMsgLength, dt, spec, pHeader, headerSize);
1141 HLTDebug("object %s (%p) size %d compression %d inserted to output", pObject->ClassName(), pObject, iMsgLength, msg.GetCompressionLevel());
1143 fLastObjectSize=iMsgLength;
1145 HLTError("object serialization failed for object %p", pObject);
1154 int AliHLTComponent::PushBack(TObject* pObject, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec,
1155 void* pHeader, int headerSize)
1157 // see header file for function documentation
1158 ALIHLTCOMPONENT_BASE_STOPWATCH();
1159 AliHLTComponentDataType dt;
1160 SetDataType(dt, dtID, dtOrigin);
1161 return PushBack(pObject, dt, spec, pHeader, headerSize);
1164 int AliHLTComponent::PushBack(const void* pBuffer, int iSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
1165 const void* pHeader, int headerSize)
1167 // see header file for function documentation
1168 ALIHLTCOMPONENT_BASE_STOPWATCH();
1169 return InsertOutputBlock(pBuffer, iSize, dt, spec, pHeader, headerSize);
1172 int AliHLTComponent::PushBack(const void* pBuffer, int iSize, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec,
1173 const void* pHeader, int headerSize)
1175 // see header file for function documentation
1176 ALIHLTCOMPONENT_BASE_STOPWATCH();
1177 AliHLTComponentDataType dt;
1178 SetDataType(dt, dtID, dtOrigin);
1179 return PushBack(pBuffer, iSize, dt, spec, pHeader, headerSize);
1182 int AliHLTComponent::InsertOutputBlock(const void* pBuffer, int iBufferSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
1183 const void* pHeader, int iHeaderSize)
1185 // see header file for function documentation
1187 int iBlkSize = iBufferSize + iHeaderSize;
1189 if ((pBuffer!=NULL && iBufferSize>0) || (pHeader!=NULL && iHeaderSize>0)) {
1190 if (fpOutputBuffer && iBlkSize<=(int)(fOutputBufferSize-fOutputBufferFilled)) {
1191 AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled;
1193 // copy header if provided but skip if the header is the target location
1194 // in that case it has already been copied
1195 if (pHeader!=NULL && pHeader!=pTgt) {
1196 memcpy(pTgt, pHeader, iHeaderSize);
1199 pTgt += (AliHLTUInt8_t) iHeaderSize;
1201 // copy buffer if provided but skip if buffer is the target location
1202 // in that case it has already been copied
1203 if (pBuffer!=NULL && pBuffer!=pTgt) {
1204 memcpy(pTgt, pBuffer, iBufferSize);
1206 //AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)pBuffer);
1207 //HLTDebug("copy %d bytes from %p to output buffer %p, first word %#x", iBufferSize, pBuffer, pTgt, firstWord);
1209 //HLTDebug("buffer inserted to output: size %d data type %s spec %#x", iBlkSize, DataType2Text(dt).c_str(), spec);
1211 if (fpOutputBuffer) {
1212 HLTError("too little space in output buffer: %d of %d, required %d", fOutputBufferSize-fOutputBufferFilled, fOutputBufferSize, iBlkSize);
1214 HLTError("output buffer not available");
1220 AliHLTComponentBlockData bd;
1221 FillBlockData( bd );
1222 bd.fOffset = fOutputBufferFilled;
1223 bd.fSize = iBlkSize;
1225 bd.fSpecification = spec;
1226 fOutputBlocks.push_back( bd );
1227 fOutputBufferFilled+=bd.fSize;
1233 int AliHLTComponent::EstimateObjectSize(TObject* pObject) const
1235 // see header file for function documentation
1236 if (!pObject) return -EINVAL;
1237 AliHLTMessage msg(kMESS_OBJECT);
1238 msg.WriteObject(pObject);
1239 return msg.Length();
1242 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(int capacity, const char* dtID,
1243 const char* dtOrigin,
1244 AliHLTUInt32_t spec)
1246 // see header file for function documentation
1247 ALIHLTCOMPONENT_BASE_STOPWATCH();
1248 AliHLTComponentDataType dt;
1249 SetDataType(dt, dtID, dtOrigin);
1250 return CreateMemoryFile(capacity, dt, spec);
1253 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(int capacity,
1254 const AliHLTComponentDataType& dt,
1255 AliHLTUInt32_t spec)
1257 // see header file for function documentation
1258 ALIHLTCOMPONENT_BASE_STOPWATCH();
1259 AliHLTMemoryFile* pFile=NULL;
1260 if (capacity>=0 && static_cast<unsigned int>(capacity)<=fOutputBufferSize-fOutputBufferFilled){
1261 AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled;
1262 pFile=new AliHLTMemoryFile((char*)pTgt, capacity);
1264 unsigned int nofBlocks=fOutputBlocks.size();
1265 if (nofBlocks+1>fMemFiles.size()) {
1266 fMemFiles.resize(nofBlocks+1, NULL);
1268 if (nofBlocks<fMemFiles.size()) {
1269 fMemFiles[nofBlocks]=pFile;
1270 AliHLTComponentBlockData bd;
1271 FillBlockData( bd );
1272 bd.fOffset = fOutputBufferFilled;
1273 bd.fSize = capacity;
1275 bd.fSpecification = spec;
1276 fOutputBufferFilled+=bd.fSize;
1277 fOutputBlocks.push_back( bd );
1279 HLTError("can not allocate/grow object array");
1280 pFile->CloseMemoryFile(0);
1286 HLTError("can not create memory file of size %d (%d available)", capacity, fOutputBufferSize-fOutputBufferFilled);
1291 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(const char* dtID,
1292 const char* dtOrigin,
1293 AliHLTUInt32_t spec,
1296 // see header file for function documentation
1297 ALIHLTCOMPONENT_BASE_STOPWATCH();
1298 AliHLTComponentDataType dt;
1299 SetDataType(dt, dtID, dtOrigin);
1300 int size=fOutputBufferSize-fOutputBufferFilled;
1301 if (capacity<0 || capacity>1.0) {
1302 HLTError("invalid parameter: capacity %f", capacity);
1305 size=(int)(size*capacity);
1306 return CreateMemoryFile(size, dt, spec);
1309 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(const AliHLTComponentDataType& dt,
1310 AliHLTUInt32_t spec,
1313 // see header file for function documentation
1314 ALIHLTCOMPONENT_BASE_STOPWATCH();
1315 int size=fOutputBufferSize-fOutputBufferFilled;
1316 if (capacity<0 || capacity>1.0) {
1317 HLTError("invalid parameter: capacity %f", capacity);
1320 size=(int)(size*capacity);
1321 return CreateMemoryFile(size, dt, spec);
1324 int AliHLTComponent::Write(AliHLTMemoryFile* pFile, const TObject* pObject,
1325 const char* key, int option)
1327 // see header file for function documentation
1329 if (pFile && pObject) {
1331 iResult=pObject->Write(key, option);
1335 iResult=-pFile->GetErrno();
1336 if (iResult==-ENOSPC) {
1337 HLTError("error writing memory file, buffer too small");
1346 int AliHLTComponent::CloseMemoryFile(AliHLTMemoryFile* pFile)
1348 // see header file for function documentation
1351 AliHLTMemoryFilePList::iterator element=fMemFiles.begin();
1353 while (element!=fMemFiles.end() && iResult>=0) {
1354 if (*element && *element==pFile) {
1355 iResult=pFile->CloseMemoryFile();
1357 // sync memory files and descriptors
1359 fOutputBlocks[i].fSize=(*element)->GetSize()+(*element)->GetHeaderSize();
1367 HLTError("can not find memory file %p", pFile);
1375 int AliHLTComponent::CreateEventDoneData(AliHLTComponentEventDoneData edd)
1377 // see header file for function documentation
1380 AliHLTComponentEventDoneData* newEDD = NULL;
1382 unsigned long newSize=edd.fDataSize;
1384 newSize += fEventDoneData->fDataSize;
1386 if (newSize>fEventDoneDataSize) {
1387 newEDD = reinterpret_cast<AliHLTComponentEventDoneData*>( new AliHLTUInt8_t[ sizeof(AliHLTComponentEventDoneData)+newSize ] );
1390 newEDD->fStructSize = sizeof(AliHLTComponentEventDoneData);
1391 newEDD->fDataSize = newSize;
1392 newEDD->fData = reinterpret_cast<AliHLTUInt8_t*>(newEDD)+newEDD->fStructSize;
1393 unsigned long long offset = 0;
1394 if (fEventDoneData) {
1395 memcpy( newEDD->fData, fEventDoneData->fData, fEventDoneData->fDataSize );
1396 offset += fEventDoneData->fDataSize;
1398 memcpy( reinterpret_cast<AliHLTUInt8_t*>(newEDD->fData)+offset, edd.fData, edd.fDataSize );
1400 delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
1401 fEventDoneData = newEDD;
1402 fEventDoneDataSize = newSize;
1405 memcpy( reinterpret_cast<AliHLTUInt8_t*>(fEventDoneData->fData)+fEventDoneData->fDataSize, edd.fData, edd.fDataSize );
1406 fEventDoneData->fDataSize += edd.fDataSize;
1411 int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
1412 const AliHLTComponentBlockData* blocks,
1413 AliHLTComponentTriggerData& trigData,
1414 AliHLTUInt8_t* outputPtr,
1415 AliHLTUInt32_t& size,
1416 AliHLTUInt32_t& outputBlockCnt,
1417 AliHLTComponentBlockData*& outputBlocks,
1418 AliHLTComponentEventDoneData*& edd )
1420 // see header file for function documentation
1421 HLTLogKeyword(fChainId.c_str());
1422 ALIHLTCOMPONENT_BASE_STOPWATCH();
1424 fCurrentEvent=evtData.fEventID;
1425 fCurrentEventData=evtData;
1426 fpInputBlocks=blocks;
1427 fCurrentInputBlock=-1;
1428 fSearchDataType=kAliHLTAnyDataType;
1429 fpOutputBuffer=outputPtr;
1430 fOutputBufferSize=size;
1431 fOutputBufferFilled=0;
1432 fOutputBlocks.clear();
1436 AliHLTComponentBlockDataList forwardedBlocks;
1438 // optional component statistics
1439 AliHLTComponentStatisticsList compStats;
1440 bool bAddComponentTableEntry=false;
1441 vector<AliHLTUInt32_t> parentComponentTables;
1442 #if defined(__DEBUG) || defined(HLT_COMPONENT_STATISTICS)
1443 AliHLTComponentStatistics outputStat;
1444 memset(&outputStat, 0, sizeof(AliHLTComponentStatistics));
1445 outputStat.fStructSize=sizeof(AliHLTComponentStatistics);
1446 outputStat.fId=fChainIdCrc;
1448 fpBenchmark->Stop();
1449 outputStat.fComponentCycleTime=(AliHLTUInt32_t)(fpBenchmark->RealTime()*ALIHLTCOMPONENT_STATTIME_SCALER);
1450 fpBenchmark->Reset();
1451 fpBenchmark->Start();
1453 compStats.push_back(outputStat);
1456 // data processing is skipped
1457 // - if there are only steering events in the block list.
1458 // For the sake of data source components data processing
1459 // is not skipped if there is no block list at all or if it
1460 // just contains the eventType block
1461 // - always skipped if the event is of type
1462 // - gkAliEventTypeConfiguration
1463 // - gkAliEventTypeReadPreprocessor
1464 const unsigned int skipModeDefault=0x1;
1465 const unsigned int skipModeForce=0x2;
1466 unsigned int bSkipDataProcessing=skipModeDefault;
1468 // find special events
1469 if (fpInputBlocks && evtData.fBlockCnt>0) {
1470 // first look for all special events and execute in the appropriate
1471 // sequence afterwords
1472 int indexComConfEvent=-1;
1473 int indexUpdtDCSEvent=-1;
1474 int indexSOREvent=-1;
1475 int indexEOREvent=-1;
1476 int indexECSParamBlock=-1;
1477 for (unsigned int i=0; i<evtData.fBlockCnt && iResult>=0; i++) {
1478 if (fpInputBlocks[i].fDataType==kAliHLTDataTypeSOR) {
1480 // the AliHLTCalibrationProcessor relies on the SOR and EOR events
1481 bSkipDataProcessing&=~skipModeDefault;
1482 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeRunType) {
1484 // handling is not clear yet
1485 if (fpInputBlocks[i].fPtr) {
1486 HLTDebug("got run type \"%s\"\n", fpInputBlocks[i].fPtr);
1488 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeEOR) {
1490 // the calibration processor relies on the SOR and EOR events
1491 bSkipDataProcessing&=~skipModeDefault;
1492 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeDDL) {
1494 // this event is most likely deprecated
1495 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComConf) {
1496 indexComConfEvent=i;
1497 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeUpdtDCS) {
1498 indexUpdtDCSEvent=i;
1499 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeEvent) {
1500 fEventType=fpInputBlocks[i].fSpecification;
1502 // skip always in case of gkAliEventTypeConfiguration
1503 if (fpInputBlocks[i].fSpecification==gkAliEventTypeConfiguration) bSkipDataProcessing|=skipModeForce;
1505 // skip always in case of gkAliEventTypeReadPreprocessor
1506 if (fpInputBlocks[i].fSpecification==gkAliEventTypeReadPreprocessor) bSkipDataProcessing|=skipModeForce;
1508 // never skip if the event type block is the only block
1509 if (evtData.fBlockCnt==1) bSkipDataProcessing&=~skipModeDefault;
1511 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComponentStatistics) {
1512 if (compStats.size()>0) {
1513 AliHLTUInt8_t* pData=reinterpret_cast<AliHLTUInt8_t*>(fpInputBlocks[i].fPtr);
1514 for (AliHLTUInt32_t offset=0;
1515 offset+sizeof(AliHLTComponentStatistics)<=fpInputBlocks[i].fSize;
1516 offset+=sizeof(AliHLTComponentStatistics)) {
1517 AliHLTComponentStatistics* pStat=reinterpret_cast<AliHLTComponentStatistics*>(pData+offset);
1518 if (pStat && compStats[0].fLevel<=pStat->fLevel) {
1519 compStats[0].fLevel=pStat->fLevel+1;
1521 compStats.push_back(*pStat);
1524 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComponentTable) {
1525 forwardedBlocks.push_back(fpInputBlocks[i]);
1526 parentComponentTables.push_back(fpInputBlocks[i].fSpecification);
1527 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeECSParam) {
1528 indexECSParamBlock=i;
1530 // the processing function is called if there is at least one
1531 // non-steering data block. Steering blocks are not filtered out
1532 // for sake of performance
1533 bSkipDataProcessing&=~skipModeDefault;
1534 if (compStats.size()>0) {
1535 compStats[0].fInputBlockCount++;
1536 compStats[0].fTotalInputSize+=fpInputBlocks[i].fSize;
1541 if (indexSOREvent>=0) {
1543 bAddComponentTableEntry=true;
1544 if (fpRunDesc==NULL) {
1545 fpRunDesc=new AliHLTRunDesc;
1546 if (fpRunDesc) *fpRunDesc=kAliHLTVoidRunDesc;
1549 AliHLTRunDesc rundesc;
1550 if ((iResult=CopyStruct(&rundesc, sizeof(AliHLTRunDesc), indexSOREvent, "AliHLTRunDesc", "SOR"))>0) {
1551 if (fpRunDesc->fRunNo==kAliHLTVoidRunNo) {
1553 HLTDebug("set run decriptor, run no %d", fpRunDesc->fRunNo);
1554 SetCDBRunNo(fpRunDesc->fRunNo);
1555 } else if (fpRunDesc->fRunNo!=rundesc.fRunNo) {
1556 HLTWarning("already set run properties run no %d, ignoring SOR with run no %d", fpRunDesc->fRunNo, rundesc.fRunNo);
1563 if (indexECSParamBlock>=0) {
1564 if (fpInputBlocks[indexECSParamBlock].fSize>0) {
1565 const char* param=reinterpret_cast<const char*>(fpInputBlocks[indexECSParamBlock].fPtr);
1566 TString paramString;
1567 if (param[fpInputBlocks[indexECSParamBlock].fSize-1]!=0) {
1568 HLTWarning("ECS parameter string not terminated");
1569 paramString.Insert(0, param, fpInputBlocks[indexECSParamBlock].fSize);
1574 ScanECSParam(paramString.Data());
1576 HLTWarning("empty ECS parameter received");
1579 // TODO: later on we might throw a warning here since the CTP trigger classes
1580 // should be mandatory
1583 if (indexEOREvent>=0) {
1584 bAddComponentTableEntry=true;
1585 if (fpRunDesc!=NULL) {
1587 AliHLTRunDesc rundesc;
1588 if ((iResult=CopyStruct(&rundesc, sizeof(AliHLTRunDesc), indexEOREvent, "AliHLTRunDesc", "SOR"))>0) {
1589 if (fpRunDesc->fRunNo!=rundesc.fRunNo) {
1590 HLTWarning("run no mismatch: SOR %d, EOR %d", fpRunDesc->fRunNo, rundesc.fRunNo);
1592 HLTDebug("EOR run no %d", fpRunDesc->fRunNo);
1595 AliHLTRunDesc* pRunDesc=fpRunDesc;
1600 HLTWarning("did not receive SOR, ignoring EOR");
1603 if (indexComConfEvent>=0 || fEventType==gkAliEventTypeConfiguration) {
1605 if (indexComConfEvent>=0 && fpInputBlocks[indexComConfEvent].fPtr!=NULL && fpInputBlocks[indexComConfEvent].fSize>0) {
1606 cdbEntry.Append(reinterpret_cast<const char*>(fpInputBlocks[indexComConfEvent].fPtr), fpInputBlocks[indexComConfEvent].fSize);
1608 HLTDebug("received component configuration command: entry %s", cdbEntry.IsNull()?"none":cdbEntry.Data());
1609 int tmpResult=Reconfigure(cdbEntry[0]==0?NULL:cdbEntry.Data(), fChainId.c_str());
1611 HLTWarning("reconfiguration of component %p (%s) failed with error code %d", this, GetComponentID(), tmpResult);
1614 if (indexUpdtDCSEvent>=0 || fEventType==gkAliEventTypeReadPreprocessor) {
1616 if (fpInputBlocks[indexUpdtDCSEvent].fPtr!=NULL && fpInputBlocks[indexUpdtDCSEvent].fSize>0) {
1617 modules.Append(reinterpret_cast<const char*>(fpInputBlocks[indexUpdtDCSEvent].fPtr), fpInputBlocks[indexUpdtDCSEvent].fSize);
1619 HLTDebug("received preprocessor update command: detectors %s", modules.IsNull()?"ALL":modules.Data());
1620 int tmpResult=ReadPreprocessorValues(modules[0]==0?"ALL":modules.Data());
1622 HLTWarning("preprocessor update of component %p (%s) failed with error code %d", this, GetComponentID(), tmpResult);
1626 // processing function needs to be called if there are no input data
1627 // blocks in order to make data source components working.
1628 bSkipDataProcessing&=~skipModeDefault;
1631 // data processing is not skipped if the component explicitly asks
1632 // for the private blocks
1633 if (fRequireSteeringBlocks) bSkipDataProcessing=0;
1635 AliHLTComponentBlockDataList blockData;
1636 if (iResult>=0 && !bSkipDataProcessing)
1637 { // dont delete, sets the scope for the stopwatch guard
1638 // do not use ALIHLTCOMPONENT_DA_STOPWATCH(); macro
1639 // in order to avoid 'shadowed variable' warning
1640 AliHLTStopwatchGuard swguard2(fpStopwatches!=NULL?reinterpret_cast<TStopwatch*>(fpStopwatches->At((int)kSWDA)):NULL);
1641 iResult=DoProcessing(evtData, blocks, trigData, outputPtr, size, blockData, edd);
1642 } // end of the scope of the stopwatch guard
1643 if (iResult>=0 && !bSkipDataProcessing) {
1644 if (fOutputBlocks.size()>0) {
1645 // High Level interface
1647 //HLTDebug("got %d block(s) via high level interface", fOutputBlocks.size());
1648 // sync memory files and descriptors
1649 AliHLTMemoryFilePList::iterator element=fMemFiles.begin();
1651 while (element!=fMemFiles.end() && iResult>=0) {
1653 if ((*element)->IsClosed()==0) {
1654 HLTWarning("memory file has not been closed, force flush");
1655 iResult=CloseMemoryFile(*element);
1662 // create the descriptor list
1663 if (blockData.size()>0) {
1664 HLTError("low level and high interface must not be mixed; use PushBack methods to insert data blocks");
1667 if (compStats.size()>0 && IsDataEvent()) {
1668 int offset=AddComponentStatistics(fOutputBlocks, fpOutputBuffer, fOutputBufferSize, fOutputBufferFilled, compStats);
1669 if (offset>0) fOutputBufferFilled+=offset;
1671 if (bAddComponentTableEntry) {
1672 int offset=AddComponentTableEntry(fOutputBlocks, fpOutputBuffer, fOutputBufferSize, fOutputBufferFilled, parentComponentTables);
1673 if (offset>0) size+=offset;
1675 if (forwardedBlocks.size()>0) {
1676 fOutputBlocks.insert(fOutputBlocks.end(), forwardedBlocks.begin(), forwardedBlocks.end());
1678 iResult=MakeOutputDataBlockList(fOutputBlocks, &outputBlockCnt, &outputBlocks);
1679 size=fOutputBufferFilled;
1683 // Low Level interface
1684 if (compStats.size()>0) {
1685 int offset=AddComponentStatistics(blockData, fpOutputBuffer, fOutputBufferSize, size, compStats);
1686 if (offset>0) size+=offset;
1688 if (bAddComponentTableEntry) {
1689 int offset=AddComponentTableEntry(blockData, fpOutputBuffer, fOutputBufferSize, size, parentComponentTables);
1690 if (offset>0) size+=offset;
1692 if (forwardedBlocks.size()>0) {
1693 blockData.insert(blockData.end(), forwardedBlocks.begin(), forwardedBlocks.end());
1695 iResult=MakeOutputDataBlockList(blockData, &outputBlockCnt, &outputBlocks);
1698 HLTFatal("component %s (%p): can not convert output block descriptor list", GetComponentID(), this);
1701 if (iResult<0 || bSkipDataProcessing) {
1705 CleanupInputObjects();
1706 if (iResult>=0 && IsDataEvent()) {
1707 IncrementEventCounter();
1709 if (outputBlockCnt==0) {
1710 // no output blocks, set size to 0
1713 FillEventData(fCurrentEventData);
1717 int AliHLTComponent::AddComponentStatistics(AliHLTComponentBlockDataList& blocks,
1718 AliHLTUInt8_t* buffer,
1719 AliHLTUInt32_t bufferSize,
1720 AliHLTUInt32_t offset,
1721 AliHLTComponentStatisticsList& stats) const
1723 // see header file for function documentation
1725 #if defined(__DEBUG) || defined(HLT_COMPONENT_STATISTICS)
1726 if (stats.size()==0) return -ENOENT;
1727 // check if there is space for at least one entry
1728 if (offset+sizeof(AliHLTComponentStatistics)>bufferSize) return 0;
1729 stats[0].fTotalOutputSize=offset;
1730 stats[0].fOutputBlockCount=blocks.size();
1732 fpBenchmark->Stop();
1733 stats[0].fTime=(AliHLTUInt32_t)(fpBenchmark->RealTime()*ALIHLTCOMPONENT_STATTIME_SCALER);
1734 stats[0].fCTime=(AliHLTUInt32_t)(fpBenchmark->CpuTime()*ALIHLTCOMPONENT_STATTIME_SCALER);
1735 fpBenchmark->Continue();
1737 if (offset+stats.size()*sizeof(AliHLTComponentStatistics)>bufferSize) {
1738 AliHLTUInt32_t removedLevel=0;
1740 // remove all entries of the level of the last entry
1741 removedLevel=stats.back().fLevel;
1742 AliHLTComponentStatisticsList::iterator element=stats.begin();
1744 while (element!=stats.end()) {
1745 if (element->fLevel<=removedLevel) {
1746 element=stats.erase(element);
1751 } while (stats.size()>1 &&
1752 (offset+stats.size()*sizeof(AliHLTComponentStatistics)>bufferSize));
1754 assert(stats.size()>0);
1755 if (stats.size()==0) return 0;
1757 if (offset+stats.size()*sizeof(AliHLTComponentStatistics)<=bufferSize) {
1758 AliHLTComponentBlockData bd;
1759 FillBlockData( bd );
1760 bd.fOffset = offset;
1761 bd.fSize = stats.size()*sizeof(AliHLTComponentStatistics);
1762 bd.fDataType = kAliHLTDataTypeComponentStatistics;
1763 bd.fSpecification = kAliHLTVoidDataSpec;
1764 unsigned int master=0;
1765 for (unsigned int i=1; i<blocks.size(); i++) {
1766 if (blocks[i].fSize>blocks[master].fSize &&
1767 !MatchExactly(blocks[i].fDataType, kAliHLTVoidDataType|kAliHLTDataOriginPrivate))
1770 if (blocks.size()>0 && !MatchExactly(blocks[master].fDataType, kAliHLTVoidDataType|kAliHLTDataOriginPrivate)) {
1771 // take the data origin of the biggest block as specification
1772 // this is similar to the treatment in the HOMER interface. For traditional
1773 // reasons, the bytes are swapped there on a little endian architecture, so
1774 // we do it as well.
1775 memcpy(&bd.fSpecification, &blocks[master].fDataType.fOrigin, sizeof(bd.fSpecification));
1776 #ifdef R__BYTESWAP // set on little endian architectures
1777 bd.fSpecification=((bd.fSpecification & 0xFFULL) << 24) |
1778 ((bd.fSpecification & 0xFF00ULL) << 8) |
1779 ((bd.fSpecification & 0xFF0000ULL) >> 8) |
1780 ((bd.fSpecification & 0xFF000000ULL) >> 24);
1783 memcpy(buffer+offset, &(stats[0]), bd.fSize);
1784 blocks.push_back(bd);
1788 if (blocks.size() && buffer && bufferSize && offset && stats.size()) {
1789 // get rid of warning
1795 int AliHLTComponent::AddComponentTableEntry(AliHLTComponentBlockDataList& blocks,
1796 AliHLTUInt8_t* buffer,
1797 AliHLTUInt32_t bufferSize,
1798 AliHLTUInt32_t offset,
1799 const vector<AliHLTUInt32_t>& parents) const
1801 // see header file for function documentation
1803 #if defined(__DEBUG) || defined(HLT_COMPONENT_STATISTICS)
1804 // the payload consists of the AliHLTComponentTableEntry struct,
1805 // followed by a an array of 32bit crc chain ids and the component
1806 // description string
1807 unsigned int payloadSize=sizeof(AliHLTComponentTableEntry);
1808 payloadSize+=parents.size()*sizeof(AliHLTUInt32_t);
1810 // the component description has the following format:
1811 // chain-id{component-id:arguments}
1812 const char* componentId=const_cast<AliHLTComponent*>(this)->GetComponentID();
1813 unsigned int descriptionSize=fChainId.size()+1;
1814 descriptionSize+=2; // the '{}' around the component id
1815 descriptionSize+=strlen(componentId);
1816 descriptionSize+=1; // the ':' between component id and arguments
1817 descriptionSize+=fComponentArgs.size();
1819 payloadSize+=descriptionSize;
1820 if (buffer && (offset+payloadSize<=bufferSize)) {
1821 AliHLTUInt8_t* pTgt=buffer+offset;
1822 memset(pTgt, 0, payloadSize);
1825 AliHLTComponentTableEntry* pEntry=reinterpret_cast<AliHLTComponentTableEntry*>(pTgt);
1826 pEntry->fStructSize=sizeof(AliHLTComponentTableEntry);
1827 pEntry->fNofParents=parents.size();
1828 pEntry->fSizeDescription=descriptionSize;
1829 pTgt=pEntry->fBuffer;
1831 // write array of parents
1832 if (parents.size()>0) {
1833 unsigned int copy=parents.size()*sizeof(vector<AliHLTUInt32_t>::value_type);
1834 memcpy(pTgt, &parents[0], parents.size()*sizeof(vector<AliHLTUInt32_t>::value_type));
1838 // write component description
1839 memcpy(pTgt, fChainId.c_str(), fChainId.size());
1840 pTgt+=fChainId.size();
1842 memcpy(pTgt, componentId, strlen(componentId));
1843 pTgt+=strlen(componentId);
1845 memcpy(pTgt, fComponentArgs.c_str(), fComponentArgs.size());
1846 pTgt+=fComponentArgs.size();
1850 AliHLTComponentBlockData bd;
1851 FillBlockData( bd );
1852 bd.fOffset = offset;
1853 bd.fSize = payloadSize;
1854 bd.fDataType = kAliHLTDataTypeComponentTable;
1855 bd.fSpecification = fChainIdCrc;
1856 blocks.push_back(bd);
1860 if (blocks.size() && buffer && bufferSize && offset && parents.size()) {
1861 // get rid of warning
1867 AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard()
1872 // standard constructor (not for use)
1875 AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(TStopwatch* pStopwatch)
1877 fpStopwatch(pStopwatch),
1882 // check for already existing guard
1883 if (fgpCurrent) fpPrec=fgpCurrent;
1886 // stop the preceeding guard if it controls a different stopwatch
1888 if (fpPrec && fpPrec!=this) bStart=fpPrec->Hold(fpStopwatch);
1890 // start the stopwatch if the current guard controls a different one
1891 if (fpStopwatch && bStart==1) fpStopwatch->Start(kFALSE);
1894 AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(const AliHLTStopwatchGuard&)
1900 // copy constructor not for use
1904 AliHLTComponent::AliHLTStopwatchGuard& AliHLTComponent::AliHLTStopwatchGuard::operator=(const AliHLTStopwatchGuard&)
1907 // assignment operator not for use
1914 AliHLTComponent::AliHLTStopwatchGuard* AliHLTComponent::AliHLTStopwatchGuard::fgpCurrent=NULL;
1916 AliHLTComponent::AliHLTStopwatchGuard::~AliHLTStopwatchGuard()
1920 // resume the preceeding guard if it controls a different stopwatch
1922 if (fpPrec && fpPrec!=this) bStop=fpPrec->Resume(fpStopwatch);
1924 // stop the stopwatch if the current guard controls a different one
1925 if (fpStopwatch && bStop==1) fpStopwatch->Stop();
1927 // resume to the preceeding guard
1931 int AliHLTComponent::AliHLTStopwatchGuard::Hold(TStopwatch* pSucc)
1933 // see header file for function documentation
1934 if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Stop();
1935 return fpStopwatch!=pSucc?1:0;
1938 int AliHLTComponent::AliHLTStopwatchGuard::Resume(TStopwatch* pSucc)
1940 // see header file for function documentation
1941 if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Start(kFALSE);
1942 return fpStopwatch!=pSucc?1:0;
1945 int AliHLTComponent::SetStopwatch(TObject* pSW, AliHLTStopwatchType type)
1947 // see header file for function documentation
1949 if (pSW!=NULL && type<kSWTypeCount) {
1950 if (fpStopwatches) {
1951 TObject* pObj=fpStopwatches->At((int)type);
1952 if (pSW==NULL // explicit reset
1953 || pObj==NULL) { // explicit set
1954 fpStopwatches->AddAt(pSW, (int)type);
1955 } else if (pObj!=pSW) {
1956 HLTWarning("stopwatch %d already set, reset first", (int)type);
1966 int AliHLTComponent::SetStopwatches(TObjArray* pStopwatches)
1968 // see header file for function documentation
1969 if (pStopwatches==NULL) return -EINVAL;
1972 for (int i=0 ; i<(int)kSWTypeCount && pStopwatches->GetEntries(); i++)
1973 SetStopwatch(pStopwatches->At(i), (AliHLTStopwatchType)i);
1977 AliHLTUInt32_t AliHLTComponent::GetRunNo() const
1979 // see header file for function documentation
1980 if (fpRunDesc==NULL) return kAliHLTVoidRunNo;
1981 return fpRunDesc->fRunNo;
1984 AliHLTUInt32_t AliHLTComponent::GetRunType() const
1986 // see header file for function documentation
1987 if (fpRunDesc==NULL) return kAliHLTVoidRunType;
1988 return fpRunDesc->fRunType;
1991 bool AliHLTComponent::IsDataEvent(AliHLTUInt32_t* pTgt)
1993 // see header file for function documentation
1994 if (pTgt) *pTgt=fEventType;
1995 return (fEventType==gkAliEventTypeData ||
1996 fEventType==gkAliEventTypeDataReplay ||
1997 fEventType==gkAliEventTypeCalibration);
2000 int AliHLTComponent::CopyStruct(void* pStruct, unsigned int iStructSize, unsigned int iBlockNo,
2001 const char* structname, const char* eventname)
2003 // see header file for function documentation
2005 if (pStruct!=NULL && iStructSize>sizeof(AliHLTUInt32_t)) {
2006 if (fpInputBlocks!=NULL && iBlockNo<fCurrentEventData.fBlockCnt) {
2007 AliHLTUInt32_t* pTgt=(AliHLTUInt32_t*)pStruct;
2008 if (fpInputBlocks[iBlockNo].fPtr && fpInputBlocks[iBlockNo].fSize) {
2009 AliHLTUInt32_t copy=*((AliHLTUInt32_t*)fpInputBlocks[iBlockNo].fPtr);
2010 if (fpInputBlocks[iBlockNo].fSize!=copy) {
2011 HLTWarning("%s event: mismatch of block size (%d) and structure size (%d)", eventname, fpInputBlocks[iBlockNo].fSize, copy);
2012 if (copy>fpInputBlocks[iBlockNo].fSize) copy=fpInputBlocks[iBlockNo].fSize;
2014 if (copy!=iStructSize) {
2015 HLTWarning("%s event: mismatch in %s version (data type version %d)", eventname, structname, ALIHLT_DATA_TYPES_VERSION);
2016 if (copy>iStructSize) {
2019 memset(pTgt, 0, iStructSize);
2022 memcpy(pTgt, fpInputBlocks[iBlockNo].fPtr, copy);
2026 HLTWarning("%s event: missing data block", eventname);
2032 HLTError("invalid struct");
2038 void AliHLTComponent::SetDDLBit(AliHLTEventDDL &list, Int_t ddlId, Bool_t state ) const
2040 // see header file for function documentation
2042 // -- Detector offset
2043 Int_t ddlIdBase = TMath::FloorNint( (Double_t) ddlId / 256.0 );
2045 // -- Word Base = 1. word of detector ( TPC has 8 words, TOF 3 )
2048 if ( ddlIdBase <= 3 )
2049 wordBase = ddlIdBase;
2050 else if ( ddlIdBase > 3 && ddlIdBase < 5 )
2051 wordBase = ddlIdBase + 7;
2053 wordBase = ddlIdBase + 9;
2055 // -- Bit index in Word
2056 Int_t bitIdx = ddlId % 32;
2059 Int_t wordIdx = wordBase;
2061 // -- if TPC (3) or TOD (5) add word idx
2062 if ( ( ddlIdBase == 3 ) || ( ddlIdBase == 5 ) ) {
2063 wordIdx += TMath::FloorNint( (Double_t) ( ddlId - ( ddlIdBase * 256 ) ) / 32.0 );
2066 // -- Set -- 'OR' word with bit mask;
2068 list.fList[wordIdx] |= ( 0x00000001 << bitIdx );
2069 // -- Unset -- 'AND' word with bit mask;
2071 list.fList[wordIdx] &= ( 0xFFFFFFFF ^ ( 0x00000001 << bitIdx ) );
2074 Int_t AliHLTComponent::GetFirstUsedDDLWord(AliHLTEventDDL &list) const
2076 // see header file for function documentation
2080 for ( Int_t wordNdx = 0 ; wordNdx < gkAliHLTDDLListSize ; wordNdx++ ) {
2082 if ( list.fList[wordNdx] != 0 && iResult == -1 ) {
2083 // check for special cases TPC and TOF
2084 if ( wordNdx > 3 && wordNdx <= 10 ) {
2088 else if ( wordNdx > 12 && wordNdx <= 14 ) {
2095 else if ( list.fList[wordNdx] != 0 && iResult >= 0 ) {
2096 HLTError( "DDLIDs for minimum of TWO detectors ( %d, %d ) set, this function works only for ONE detector.", iResult, wordNdx );
2105 AliHLTUInt32_t AliHLTComponent::CalculateChecksum(const AliHLTUInt8_t* buffer, int size)
2107 // see header file for function documentation
2108 AliHLTUInt32_t remainder = 0;
2109 const AliHLTUInt8_t crcwidth=(8*sizeof(AliHLTUInt32_t));
2110 const AliHLTUInt32_t topbit=1 << (crcwidth-1);
2111 const AliHLTUInt32_t polynomial=0xD8; /* 11011 followed by 0's */
2114 // http://www.netrino.com/Embedded-Systems/How-To/CRC-Calculation-C-Code
2117 * Perform modulo-2 division, a byte at a time.
2119 for (int byte = 0; byte < size; ++byte)
2122 * Bring the next byte into the remainder.
2124 remainder ^= (buffer[byte] << (crcwidth - 8));
2127 * Perform modulo-2 division, a bit at a time.
2129 for (uint8_t bit = 8; bit > 0; --bit)
2132 * Try to divide the current data bit.
2134 if (remainder & topbit)
2136 remainder = (remainder << 1) ^ polynomial;
2140 remainder = (remainder << 1);
2146 * The final remainder is the CRC result.
2151 int AliHLTComponent::ExtractComponentTableEntry(const AliHLTUInt8_t* pBuffer, AliHLTUInt32_t size,
2152 string& retChainId, string& retCompId, string& retCompArgs,
2153 vector<AliHLTUInt32_t>& parents)
2155 // see header file for function documentation
2158 retCompArgs.clear();
2160 if (!pBuffer || size==0) return 0;
2162 const AliHLTComponentTableEntry* pEntry=reinterpret_cast<const AliHLTComponentTableEntry*>(pBuffer);
2163 if (size<8/* the initial size of the structure*/ ||
2164 pEntry==NULL || pEntry->fStructSize<8) return -ENOMSG;
2165 const AliHLTUInt32_t* pParents=reinterpret_cast<const AliHLTUInt32_t*>(pEntry->fBuffer);
2166 const AliHLTUInt8_t* pEnd=pBuffer+size;
2168 if (pParents+pEntry->fNofParents>=reinterpret_cast<const AliHLTUInt32_t*>(pEnd)) return -ENODEV;
2169 for (unsigned int i=0; i<pEntry->fNofParents; i++, pParents++) {
2170 parents.push_back(*pParents);
2173 const char* pDescription=reinterpret_cast<const char*>(pParents);
2174 if (pDescription+pEntry->fSizeDescription>=reinterpret_cast<const char*>(pEnd) ||
2175 *(pDescription+pEntry->fSizeDescription)!=0) {
2179 TString descriptor=reinterpret_cast<const char*>(pDescription);
2183 TObjArray* pTokens=descriptor.Tokenize("{");
2186 if (pTokens->GetEntries()>n) {
2187 retChainId=((TObjString*)pTokens->At(n++))->GetString();
2189 if (pTokens->GetEntries()>n) {
2190 compId=((TObjString*)pTokens->At(n++))->GetString();
2194 if (!compId.IsNull() && (pTokens=compId.Tokenize(":"))!=NULL) {
2196 if (pTokens->GetEntries()>n) {
2197 compId=((TObjString*)pTokens->At(n++))->GetString();
2199 if (pTokens->GetEntries()>n) {
2200 compArgs=((TObjString*)pTokens->At(n++))->GetString();
2204 compId.ReplaceAll("}", "");
2205 compArgs.ReplaceAll("}", "");
2208 retCompArgs=compArgs;
2210 if (retChainId.size()==0) return -ENODATA;
2215 int AliHLTComponent::LoggingVarargs(AliHLTComponentLogSeverity severity,
2216 const char* originClass, const char* originFunc,
2217 const char* file, int line, ... ) const
2219 // see header file for function documentation
2223 va_start(args, line);
2225 // logging function needs to be const in order to be called from const member functions
2226 // without problems. But at this point we face the problem with virtual members which
2227 // are not necessarily const.
2228 AliHLTComponent* nonconst=const_cast<AliHLTComponent*>(this);
2229 AliHLTLogging::SetLogString("%s (%s, %p): ",
2230 fChainId[0]!=0?fChainId.c_str():nonconst->GetComponentID(),
2231 nonconst->GetComponentID(), this);
2232 iResult=SendMessage(severity, originClass, originFunc, file, line, AliHLTLogging::BuildLogString(NULL, args, true /*append*/));
2238 int AliHLTComponent::ScanECSParam(const char* ecsParam)
2240 // see header file for function documentation
2242 // format of the parameter string from ECS
2243 // <command>;<parameterkey>=<parametervalue>;<parameterkey>=<parametervalue>;...
2244 // search for a subset of the parameterkeys
2246 TString string=ecsParam;
2247 TObjArray* parameter=string.Tokenize(";");
2249 for (int i=0; i<parameter->GetEntries(); i++) {
2250 TString entry=((TObjString*)parameter->At(i))->GetString();
2251 HLTDebug("scanning ECS entry: %s", entry.Data());
2252 TObjArray* entryParams=entry.Tokenize("=");
2254 if (entryParams->GetEntries()>1) {
2255 if ((((TObjString*)entryParams->At(0))->GetString()).CompareTo("CTP_TRIGGER_CLASS")==0) {
2256 int result=InitCTPTriggerClasses((((TObjString*)entryParams->At(1))->GetString()).Data());
2257 if (iResult>=0 && result<0) iResult=result;
2259 // TODO: scan the other parameters
2260 // e.g. consistency check of run number
2272 int AliHLTComponent::InitCTPTriggerClasses(const char* ctpString)
2274 // see header file for function documentation
2275 if (!ctpString) return -EINVAL;
2277 if (fpTriggerClasses) {
2278 fpTriggerClasses->Delete();
2280 fpTriggerClasses=new TObjArray(gkNCTPTriggerClasses);
2282 if (!fpTriggerClasses) return -ENOMEM;
2284 // general format of the CTP_TRIGGER_CLASS parameter
2285 // <bit position>:<Trigger class identifier string>:<detector-id-nr>-<detector-id-nr>-...,<bit position>:<Trigger class identifier string>:<detector-id-nr>-<detector-id-nr>-...,...
2286 // the detector ids are ignored for the moment
2287 HLTDebug(": %s", ctpString);
2288 TString string=ctpString;
2289 TObjArray* classEntries=string.Tokenize(",");
2291 for (int i=0; i<classEntries->GetEntries(); i++) {
2292 TString entry=((TObjString*)classEntries->At(i))->GetString();
2293 TObjArray* entryParams=entry.Tokenize(":");
2295 if (entryParams->GetEntries()==3 &&
2296 (((TObjString*)entryParams->At(0))->GetString()).IsDigit()) {
2297 int index=(((TObjString*)entryParams->At(0))->GetString()).Atoi();
2298 if (index<gkNCTPTriggerClasses) {
2299 fpTriggerClasses->AddAt(new TNamed("TriggerClass", (((TObjString*)entryParams->At(1))->GetString()).Data()), index);
2301 // the trigger bitfield is fixed to 50 bits (gkNCTPTriggerClasses)
2302 HLTError("invalid trigger class entry %s, index width of trigger bitfield", entry.Data());
2305 HLTError("invalid trigger class entry %s", entry.Data());
2310 delete classEntries;
2315 bool AliHLTComponent::EvaluateCTPTriggerClass(const char* expression, AliHLTComponentTriggerData& trigData) const
2317 // see header file for function documentation
2318 if (!fpTriggerClasses) {
2319 HLTError("trigger classes not initialized");
2323 if (trigData.fDataSize != sizeof(AliHLTEventTriggerData)) {
2324 HLTError("invalid trigger data size: %d expected %d", trigData.fDataSize, sizeof(AliHLTEventTriggerData));
2328 // trigger mask is 50 bit wide and is stored in word 5 and 6 of the CDH
2329 AliHLTEventTriggerData* evtData=reinterpret_cast<AliHLTEventTriggerData*>(trigData.fData);
2330 AliHLTUInt64_t triggerMask=evtData->fCommonHeader[6];
2332 triggerMask|=evtData->fCommonHeader[5];
2334 // use a TFormula to interprete the expression
2335 // all classname are replaced by '[n]' which means the n'th parameter in the formula
2336 // the parameters are set to 0 or 1 depending on the bit in the trigger mask
2338 // TODO: this will most likely fail for class names like 'base', 'baseA', 'baseB'
2339 // the class names must be fully unique, none must be contained as substring in
2340 // another class name. Probably not needed for the moment but needs to be extended.
2341 vector<Double_t> par;
2342 TString condition=expression;
2343 for (int i=0; i<gkNCTPTriggerClasses; i++) {
2344 if (fpTriggerClasses->At(i)) {
2345 TString className=fpTriggerClasses->At(i)->GetTitle();
2346 //HLTDebug("checking trigger class %s", className.Data());
2347 if (condition.Contains(className)) {
2348 TString replace; replace.Form("[%d]", par.size());
2349 //HLTDebug("replacing %s with %s in \"%s\"", className.Data(), replace.Data(), condition.Data());
2350 condition.ReplaceAll(className, replace);
2351 if (triggerMask&((AliHLTUInt64_t)0x1<<i)) par.push_back(1.0);
2352 else par.push_back(0.0);
2357 TFormula form("trigger expression", condition);
2358 if (form.Compile()!=0) {
2359 HLTError("invalid expression %s", expression);
2362 if (form.EvalPar(&par[0], &par[0])>0.5) return true;