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"
33 #include "AliHLTCTPData.h"
36 #include "TObjArray.h"
37 #include "TObjectTable.h"
39 #include "TStopwatch.h"
41 #include "AliHLTMemoryFile.h"
42 #include "AliHLTMisc.h"
48 * default compression level for ROOT objects
50 #define ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION 5
51 #define ALIHLTCOMPONENT_STATTIME_SCALER 1000000
53 /** ROOT macro for the implementation of ROOT specific class methods */
54 ClassImp(AliHLTComponent);
56 /** stopwatch macro using the stopwatch guard */
57 #define ALIHLTCOMPONENT_STOPWATCH(type) AliHLTStopwatchGuard swguard(fpStopwatches!=NULL?reinterpret_cast<TStopwatch*>(fpStopwatches->At((int)type)):NULL)
58 //#define ALIHLTCOMPONENT_STOPWATCH(type)
60 /** stopwatch macro for operations of the base class */
61 #define ALIHLTCOMPONENT_BASE_STOPWATCH() ALIHLTCOMPONENT_STOPWATCH(kSWBase)
62 /** stopwatch macro for operations of the detector algorithm (DA) */
63 #define ALIHLTCOMPONENT_DA_STOPWATCH() ALIHLTCOMPONENT_STOPWATCH(kSWDA)
65 AliHLTComponent::AliHLTComponent()
73 fCurrentInputBlock(-1),
74 fSearchDataType(kAliHLTVoidDataType),
79 fOutputBufferFilled(0),
81 fpStopwatches(new TObjArray(kSWTypeCount)),
85 fCDBSetRunNoFunc(false),
89 fRequireSteeringBlocks(false),
90 fEventType(gkAliEventTypeUnknown),
93 fEventDoneDataSize(0),
94 fCompressionLevel(ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION)
98 // see header file for class documentation
100 // refer to README to build package
102 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
103 memset(&fEnvironment, 0, sizeof(AliHLTAnalysisEnvironment));
104 if (fgpComponentHandler)
105 fgpComponentHandler->ScheduleRegister(this);
106 //SetLocalLoggingLevel(kHLTLogDefault);
109 AliHLTComponent::~AliHLTComponent()
111 // see header file for function documentation
112 if (fpBenchmark) delete fpBenchmark;
115 CleanupInputObjects();
116 if (fpStopwatches!=NULL) delete fpStopwatches;
118 AliHLTMemoryFilePList::iterator element=fMemFiles.begin();
119 while (element!=fMemFiles.end()) {
121 if ((*element)->IsClosed()==0) {
122 HLTWarning("memory file has not been closed, possible data loss or incomplete buffer");
123 // close but do not flush as we dont know whether the buffer is still valid
124 (*element)->CloseMemoryFile(0);
136 delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
145 AliHLTComponentHandler* AliHLTComponent::fgpComponentHandler=NULL;
147 int AliHLTComponent::SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite)
149 // see header file for function documentation
151 if (fgpComponentHandler==NULL || bOverwrite!=0)
152 fgpComponentHandler=pCH;
158 int AliHLTComponent::UnsetGlobalComponentHandler()
160 // see header file for function documentation
161 return SetGlobalComponentHandler(NULL,1);
164 int AliHLTComponent::SetComponentEnvironment(const AliHLTAnalysisEnvironment* comenv, void* environParam)
166 // see header file for function documentation
167 HLTLogKeyword(fChainId.c_str());
170 memset(&fEnvironment, 0, sizeof(AliHLTAnalysisEnvironment));
171 memcpy(&fEnvironment, comenv, comenv->fStructSize<sizeof(AliHLTAnalysisEnvironment)?comenv->fStructSize:sizeof(AliHLTAnalysisEnvironment));
172 fEnvironment.fStructSize=sizeof(AliHLTAnalysisEnvironment);
173 fEnvironment.fParam=environParam;
178 int AliHLTComponent::Init(const AliHLTAnalysisEnvironment* comenv, void* environParam, int argc, const char** argv )
180 // see header file for function documentation
181 HLTLogKeyword(fChainId.c_str());
184 SetComponentEnvironment(comenv, environParam);
187 const char** pArguments=NULL;
192 pArguments=new const char*[argc];
194 for (int i=0; i<argc && iResult>=0; i++) {
195 if (fComponentArgs.size()>0) fComponentArgs+=" ";
196 fComponentArgs+=argv[i];
198 if (argument.IsNull()) continue;
201 if (argument.CompareTo("-benchmark")==0) {
204 } else if (argument.BeginsWith("-loglevel=")) {
205 TString parameter=argument.ReplaceAll("-loglevel=", "");
206 parameter.Remove(TString::kLeading, ' '); // remove all blanks
207 if (parameter.BeginsWith("0x") &&
208 parameter.Replace(0,2,"",0).IsHex()) {
209 unsigned int loglevel=kHLTLogNone;
210 sscanf(parameter.Data(),"%x", &loglevel);
211 SetLocalLoggingLevel((AliHLTComponentLogSeverity)loglevel);
213 HLTError("wrong parameter for argument %s, hex number expected", argument.Data());
216 // -object-compression=
217 } else if (argument.BeginsWith("-object-compression=")) {
218 argument.ReplaceAll("-object-compression=", "");
219 if (argument.IsDigit()) {
220 fCompressionLevel=argument.Atoi();
221 if (fCompressionLevel<0 || fCompressionLevel>9) {
222 HLTWarning("invalid compression level %d, setting to default %d", fCompressionLevel, ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION);
223 fCompressionLevel=ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION;
226 HLTError("wrong parameter for argument -object-compression, number expected");
229 pArguments[iNofChildArgs++]=argv[i];
237 HLTError("missing parameter for argument %s", argument.Data());
241 iResult=DoInit(iNofChildArgs, pArguments);
246 // find out if the component wants to get the steering events
248 AliHLTComponentDataTypeList inputDt;
249 GetInputDataTypes(inputDt);
250 for (AliHLTComponentDataTypeList::iterator dt=inputDt.begin();
251 dt!=inputDt.end() && !fRequireSteeringBlocks;
253 fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeSOR);
254 fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeRunType);
255 fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeEOR);
256 fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeDDL);
257 fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeComponentStatistics);
260 if (pArguments) delete [] pArguments;
262 #if defined(__DEBUG) || defined(HLT_COMPONENT_STATISTICS)
263 // benchmarking stopwatch for the component statistics
264 fpBenchmark=new TStopwatch;
270 int AliHLTComponent::Deinit()
272 // see header file for function documentation
273 HLTLogKeyword(fChainId.c_str());
277 // TODO: the warning should be kept, but the condition is wrong since the
278 // AliHLTRunDesc is set before the SOR event in the SetRunDescription
279 // method. A couple of state flags should be defined but that is a bit more
280 // work to do. For the moment disable the warning (2009-07-01)
281 // 2009-09-08: now, the info is not cleared in the ProcessEvent, because it
282 // might be needed by components during the event processing.
283 //HLTWarning("did not receive EOR for run %d", fpRunDesc->fRunNo);
284 AliHLTRunDesc* pRunDesc=fpRunDesc;
297 int AliHLTComponent::InitCDB(const char* cdbPath, AliHLTComponentHandler* pHandler)
299 // see header file for function documentation
301 HLTInfo("Using CDB: %s", cdbPath);
303 // I have to think about separating the library handling from the
304 // component handler. Requiring the component handler here is not
305 // the cleanest solution.
306 // We presume the library already to be loaded, which is the case
307 // because it is loaded in the initialization of the logging functionality
310 AliHLTMiscInitCDB_t pFunc=(AliHLTMiscInitCDB_t)pHandler->FindSymbol(ALIHLTMISC_LIBRARY, ALIHLTMISC_INIT_CDB);
313 if (cdbPath && cdbPath[0]!=0) {
315 // very temporary fix, have to check for other formats
316 if (!path.BeginsWith("local://")) {
321 if ((iResult=(*pFunc)(path.Data()))>=0) {
322 if (!(fCDBSetRunNoFunc=pHandler->FindSymbol(ALIHLTMISC_LIBRARY, ALIHLTMISC_SET_CDB_RUNNO))) {
323 Message(NULL, kHLTLogWarning, "AliHLTComponent::InitCDB", "init CDB",
324 "can not find function to set CDB run no");
328 Message(NULL, kHLTLogError, "AliHLTComponent::InitCDB", "init CDB",
329 "can not find initialization function");
338 int AliHLTComponent::SetCDBRunNo(int runNo)
340 // see header file for function documentation
341 if (!fCDBSetRunNoFunc) return 0;
342 return (*((AliHLTMiscSetCDBRunNo_t)fCDBSetRunNoFunc))(runNo);
345 int AliHLTComponent::SetRunDescription(const AliHLTRunDesc* desc, const char* /*runType*/)
347 // see header file for function documentation
348 if (!desc) return -EINVAL;
349 if (desc->fStructSize!=sizeof(AliHLTRunDesc)) {
350 HLTError("invalid size of RunDesc struct (%ul)", desc->fStructSize);
355 fpRunDesc=new AliHLTRunDesc;
356 if (!fpRunDesc) return -ENOMEM;
357 *fpRunDesc=kAliHLTVoidRunDesc;
360 if (fpRunDesc->fRunNo!=kAliHLTVoidRunNo && fpRunDesc->fRunNo!=desc->fRunNo) {
361 HLTWarning("Run description has already been set");
364 SetCDBRunNo(fpRunDesc->fRunNo);
365 // TODO: we have to decide about the runType
369 int AliHLTComponent::SetComponentDescription(const char* desc)
371 // see header file for function documentation
375 TString descriptor=desc;
376 TObjArray* pTokens=descriptor.Tokenize(" ");
378 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
379 TString argument=((TObjString*)pTokens->At(i++))->GetString();
380 if (!argument || argument.IsNull()) continue;
383 if (argument.BeginsWith("chainid")) {
384 argument.ReplaceAll("chainid", "");
385 if (argument.BeginsWith("=")) {
386 fChainId=argument.Replace(0,1,"");
387 fChainIdCrc=CalculateChecksum((const AliHLTUInt8_t*)fChainId.c_str(), fChainId.length());
388 HLTDebug("setting component description: chain id %s crc 0x%8x", fChainId.c_str(), fChainIdCrc);
393 HLTWarning("unknown component description %s", argument.Data());
401 int AliHLTComponent::ConfigureFromArgumentString(int argc, const char** argv)
403 // see header file for function documentation
405 vector<const char*> array;
406 TObjArray choppedArguments;
409 for (i=0; i<argc && iResult>=0; i++) {
411 if (argument.IsNull()) continue;
412 TObjArray* pTokens=argument.Tokenize(" ");
414 if (pTokens->GetEntriesFast()>0) {
415 for (int n=0; n<pTokens->GetEntriesFast(); n++) {
416 choppedArguments.AddLast(pTokens->At(n));
417 TString data=((TObjString*)pTokens->At(n))->GetString();
418 if (!data.IsNull()) {
419 array.push_back(data.Data());
422 pTokens->SetOwner(kFALSE);
428 for (i=0; (unsigned)i<array.size() && iResult>=0;) {
429 int result=ScanConfigurationArgument(array.size()-i, &array[i]);
431 HLTWarning("unknown component argument %s", array[i]);
433 } else if (result>0) {
437 if (iResult==-EINVAL) {
438 HLTError("unknown argument %s", array[i]);
439 } else if (iResult==-EPROTO) {
440 HLTError("missing/wrong parameter for argument %s (%s)", array[i], (array.size()>(unsigned)i+1)?array[i+1]:"missing");
442 HLTError("scan of argument %s failed (%d)", array[i], iResult);
450 int AliHLTComponent::ConfigureFromCDBTObjString(const char* entries)
452 // see header file for function documentation
455 TString confEntries=entries;
456 TObjArray* pTokens=confEntries.Tokenize(" ");
458 for (int n=0; n<pTokens->GetEntriesFast(); n++) {
459 const char* path=((TObjString*)pTokens->At(n))->GetString().Data();
460 const char* chainId=GetChainId();
461 HLTInfo("configure from entry %s, chain id %s", path, (chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
462 TObject* pOCDBObject = LoadAndExtractOCDBObject(path);
464 TObjString* pString=dynamic_cast<TObjString*>(pOCDBObject);
466 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
467 arguments+=pString->GetString().Data();
470 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
474 HLTError("can not fetch object \"%s\" from OCDB", path);
480 if (iResult>=0 && !arguments.IsNull()) {
481 const char* array=arguments.Data();
482 iResult=ConfigureFromArgumentString(1, &array);
487 TObject* AliHLTComponent::LoadAndExtractOCDBObject(const char* path, int version, int subVersion)
489 // see header file for function documentation
490 AliCDBEntry* pEntry=AliHLTMisc::Instance().LoadOCDBEntry(path, GetRunNo(), version, subVersion);
491 if (!pEntry) return NULL;
492 return AliHLTMisc::Instance().ExtractObject(pEntry);
495 int AliHLTComponent::DoInit( int /*argc*/, const char** /*argv*/)
497 // default implementation, childs can overload
498 HLTLogKeyword("dummy");
502 int AliHLTComponent::DoDeinit()
504 // default implementation, childs can overload
505 HLTLogKeyword("dummy");
509 int AliHLTComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/)
511 // default implementation, childs can overload
512 HLTLogKeyword("dummy");
516 int AliHLTComponent::ReadPreprocessorValues(const char* /*modules*/)
518 // default implementation, childs can overload
519 HLTLogKeyword("dummy");
523 int AliHLTComponent::ScanConfigurationArgument(int /*argc*/, const char** /*argv*/)
525 // default implementation, childs can overload
526 HLTLogKeyword("dummy");
527 HLTWarning("The function needs to be implemented by the component");
531 int AliHLTComponent::StartOfRun()
533 // default implementation, childs can overload
534 HLTLogKeyword("dummy");
538 int AliHLTComponent::EndOfRun()
540 // default implementation, childs can overload
541 HLTLogKeyword("dummy");
546 int AliHLTComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& /*tgtList*/)
548 // default implementation, childs can overload
549 HLTLogKeyword("dummy");
553 void AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2] ) const
555 // see header file for function documentation
556 memset( output, 0, kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2 );
557 strncat( output, type.fOrigin, kAliHLTComponentDataTypefOriginSize );
558 strcat( output, ":" );
559 strncat( output, type.fID, kAliHLTComponentDataTypefIDsize );
562 string AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, int mode)
564 // see header file for function documentation
570 for (i=0; i<kAliHLTComponentDataTypefOriginSize; i++) {
571 sprintf(tmp, "'%d", type.fOrigin[i]);
575 for (i=0; i<kAliHLTComponentDataTypefIDsize; i++) {
576 sprintf(tmp, "%d'", type.fID[i]);
585 for (i=0; i<kAliHLTComponentDataTypefOriginSize; i++) {
586 unsigned char* puc=(unsigned char*)type.fOrigin;
588 sprintf(tmp, "'\\%x", type.fOrigin[i]);
590 sprintf(tmp, "'%c", type.fOrigin[i]);
594 for (i=0; i<kAliHLTComponentDataTypefIDsize; i++) {
595 unsigned char* puc=(unsigned char*)type.fID;
597 sprintf(tmp, "\\%x'", type.fID[i]);
599 sprintf(tmp, "%c'", type.fID[i]);
605 if (type==kAliHLTVoidDataType) {
608 // some gymnastics in order to avoid a '0' which is part of either or both
609 // ID and origin terminating the whole string. Unfortunately, string doesn't
610 // stop appending at the '0' if the number of elements to append was
611 // explicitely specified
613 tmp.append(type.fOrigin, kAliHLTComponentDataTypefOriginSize);
614 out.append(tmp.c_str());
617 tmp.append(type.fID, kAliHLTComponentDataTypefIDsize);
618 out.append(tmp.c_str());
624 void* AliHLTComponent::AllocMemory( unsigned long size )
626 // see header file for function documentation
627 if (fEnvironment.fAllocMemoryFunc)
628 return (*fEnvironment.fAllocMemoryFunc)(fEnvironment.fParam, size );
629 HLTFatal("no memory allocation handler registered");
633 int AliHLTComponent::MakeOutputDataBlockList( const AliHLTComponentBlockDataList& blocks, AliHLTUInt32_t* blockCount,
634 AliHLTComponentBlockData** outputBlocks )
636 // see header file for function documentation
637 if ( blockCount==NULL || outputBlocks==NULL )
639 AliHLTUInt32_t count = blocks.size();
643 *outputBlocks = NULL;
646 *outputBlocks = reinterpret_cast<AliHLTComponentBlockData*>( AllocMemory( sizeof(AliHLTComponentBlockData)*count ) );
647 if ( !*outputBlocks )
649 for ( unsigned long i = 0; i < count; i++ ) {
650 (*outputBlocks)[i] = blocks[i];
651 if (MatchExactly(blocks[i].fDataType, kAliHLTAnyDataType)) {
652 (*outputBlocks)[i].fDataType=GetOutputDataType();
653 /* data type was set to the output data type by the PubSub AliRoot
654 Wrapper component, if data type of the block was ********:****.
655 Now handled by the component base class in order to have same
656 behavior when running embedded in AliRoot
657 memset((*outputBlocks)[i].fDataType.fID, '*', kAliHLTComponentDataTypefIDsize);
658 memset((*outputBlocks)[i].fDataType.fOrigin, '*', kAliHLTComponentDataTypefOriginSize);
667 int AliHLTComponent::GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd )
669 // see header file for function documentation
670 if (fEnvironment.fGetEventDoneDataFunc)
671 return (*fEnvironment.fGetEventDoneDataFunc)(fEnvironment.fParam, fCurrentEvent, size, edd );
675 int AliHLTComponent::ReserveEventDoneData( unsigned long size )
677 // see header file for function documentation
680 unsigned long capacity=fEventDoneDataSize;
681 if (fEventDoneData) capacity-=sizeof(AliHLTComponentEventDoneData)+fEventDoneData->fDataSize;
683 unsigned long newSize=sizeof(AliHLTComponentEventDoneData)+size+(fEventDoneDataSize-capacity);
684 AliHLTComponentEventDoneData* newEDD = reinterpret_cast<AliHLTComponentEventDoneData*>( new AliHLTUInt8_t[newSize] );
687 newEDD->fStructSize = sizeof(AliHLTComponentEventDoneData);
688 newEDD->fDataSize = 0;
689 newEDD->fData = reinterpret_cast<AliHLTUInt8_t*>(newEDD)+newEDD->fStructSize;
690 if (fEventDoneData) {
691 memcpy( newEDD->fData, fEventDoneData->fData, fEventDoneData->fDataSize );
692 newEDD->fDataSize = fEventDoneData->fDataSize;
693 delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
695 fEventDoneData = newEDD;
696 fEventDoneDataSize = newSize;
702 int AliHLTComponent::PushEventDoneData( AliHLTUInt32_t eddDataWord )
706 if (fEventDoneData->fDataSize+sizeof(AliHLTUInt32_t)>fEventDoneDataSize)
708 *reinterpret_cast<AliHLTUInt32_t*>((reinterpret_cast<AliHLTUInt8_t*>(fEventDoneData->fData)+fEventDoneData->fDataSize)) = eddDataWord;
709 fEventDoneData->fDataSize += sizeof(AliHLTUInt32_t);
713 void AliHLTComponent::ReleaseEventDoneData()
716 delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
717 fEventDoneData = NULL;
718 fEventDoneDataSize = 0;
722 int AliHLTComponent::FindMatchingDataTypes(AliHLTComponent* pConsumer, AliHLTComponentDataTypeList* tgtList)
724 // see header file for function documentation
727 AliHLTComponentDataTypeList itypes;
728 AliHLTComponentDataTypeList otypes;
729 otypes.push_back(GetOutputDataType());
730 if (MatchExactly(otypes[0],kAliHLTMultipleDataType)) {
733 if ((count=GetOutputDataTypes(otypes))>0) {
734 } else if (GetComponentType()!=kSink) {
735 HLTWarning("component %s indicates multiple output data types but GetOutputDataTypes returns %d", GetComponentID(), count);
738 ((AliHLTComponent*)pConsumer)->GetInputDataTypes(itypes);
739 AliHLTComponentDataTypeList::iterator otype=otypes.begin();
740 for (;otype!=otypes.end();otype++) {
741 //PrintDataTypeContent((*otype), "publisher \'%s\'");
742 if ((*otype)==(kAliHLTAnyDataType|kAliHLTDataOriginPrivate)) {
743 if (tgtList) tgtList->push_back(*otype);
748 AliHLTComponentDataTypeList::iterator itype=itypes.begin();
749 for ( ; itype!=itypes.end() && (*itype)!=(*otype) ; itype++) {/* empty body */};
750 //if (itype!=itypes.end()) PrintDataTypeContent(*itype, "consumer \'%s\'");
751 if (itype!=itypes.end()) {
752 if (tgtList) tgtList->push_back(*otype);
762 void AliHLTComponent::PrintDataTypeContent(AliHLTComponentDataType& dt, const char* format)
764 // see header file for function documentation
765 const char* fmt="\'%s\'";
766 if (format) fmt=format;
767 AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, Form(fmt, (DataType2Text(dt)).c_str()));
768 AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL,
769 Form("%x %x %x %x %x %x %x %x : %x %x %x %x",
784 void AliHLTComponent::FillBlockData( AliHLTComponentBlockData& blockData )
786 // see header file for function documentation
787 blockData.fStructSize = sizeof(blockData);
788 FillShmData( blockData.fShmKey );
789 blockData.fOffset = ~(AliHLTUInt32_t)0;
790 blockData.fPtr = NULL;
792 FillDataType( blockData.fDataType );
793 blockData.fSpecification = kAliHLTVoidDataSpec;
796 void AliHLTComponent::FillShmData( AliHLTComponentShmData& shmData )
798 // see header file for function documentation
799 shmData.fStructSize = sizeof(shmData);
800 shmData.fShmType = gkAliHLTComponentInvalidShmType;
801 shmData.fShmID = gkAliHLTComponentInvalidShmID;
804 void AliHLTComponent::FillDataType( AliHLTComponentDataType& dataType )
806 // see header file for function documentation
807 dataType=kAliHLTAnyDataType;
810 void AliHLTComponent::CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt)
812 // see header file for function documentation
813 memcpy(&tgtdt.fID[0], &srcdt.fID[0], kAliHLTComponentDataTypefIDsize);
814 memcpy(&tgtdt.fOrigin[0], &srcdt.fOrigin[0], kAliHLTComponentDataTypefOriginSize);
817 void AliHLTComponent::SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin)
819 // see header file for function documentation
820 tgtdt.fStructSize=sizeof(AliHLTComponentDataType);
822 memset(&tgtdt.fID[0], 0, kAliHLTComponentDataTypefIDsize);
823 strncpy(&tgtdt.fID[0], id, strlen(id)<(size_t)kAliHLTComponentDataTypefIDsize?strlen(id):kAliHLTComponentDataTypefIDsize);
826 memset(&tgtdt.fOrigin[0], 0, kAliHLTComponentDataTypefOriginSize);
827 strncpy(&tgtdt.fOrigin[0], origin, strlen(origin)<(size_t)kAliHLTComponentDataTypefOriginSize?strlen(origin):kAliHLTComponentDataTypefOriginSize);
831 void AliHLTComponent::SetDataType(AliHLTComponentDataType& dt, AliHLTUInt64_t id, AliHLTUInt32_t origin)
833 // see header file for function documentation
834 dt.fStructSize=sizeof(AliHLTComponentDataType);
835 assert(kAliHLTComponentDataTypefIDsize==sizeof(id));
836 assert(kAliHLTComponentDataTypefOriginSize==sizeof(origin));
837 memcpy(&dt.fID, &id, kAliHLTComponentDataTypefIDsize);
838 memcpy(&dt.fOrigin, &origin, kAliHLTComponentDataTypefOriginSize);
841 void AliHLTComponent::FillEventData(AliHLTComponentEventData& evtData)
843 // see header file for function documentation
844 memset(&evtData, 0, sizeof(AliHLTComponentEventData));
845 evtData.fStructSize=sizeof(AliHLTComponentEventData);
846 evtData.fEventID=kAliHLTVoidEventID;
849 void AliHLTComponent::PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt)
851 // see header file for function documentation
853 msg.Form("AliHLTComponentDataType(%d): ID=\"", dt.fStructSize);
854 for ( int i = 0; i < kAliHLTComponentDataTypefIDsize; i++ ) {
855 if (dt.fID[i]!=0) msg+=dt.fID[i];
859 for ( int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++ ) {
860 if (dt.fOrigin[i]!=0) msg+=dt.fOrigin[i];
864 AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, msg.Data());
867 int AliHLTComponent::GetEventCount() const
869 // see header file for function documentation
873 int AliHLTComponent::IncrementEventCounter()
875 // see header file for function documentation
876 if (fEventCount>=0) fEventCount++;
880 int AliHLTComponent::GetNumberOfInputBlocks() const
882 // see header file for function documentation
883 if (fpInputBlocks!=NULL) {
884 return fCurrentEventData.fBlockCnt;
889 AliHLTEventID_t AliHLTComponent::GetEventId() const
891 // see header file for function documentation
892 if (fpInputBlocks!=NULL) {
893 return fCurrentEventData.fEventID;
898 const TObject* AliHLTComponent::GetFirstInputObject(const AliHLTComponentDataType& dt,
899 const char* classname,
902 // see header file for function documentation
903 ALIHLTCOMPONENT_BASE_STOPWATCH();
905 if (classname) fClassName=classname;
906 else fClassName.clear();
907 int idx=FindInputBlock(fSearchDataType, 0, 1);
910 HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(dt).c_str());
911 if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) {
912 fCurrentInputBlock=idx;
919 const TObject* AliHLTComponent::GetFirstInputObject(const char* dtID,
920 const char* dtOrigin,
921 const char* classname,
924 // see header file for function documentation
925 ALIHLTCOMPONENT_BASE_STOPWATCH();
926 AliHLTComponentDataType dt;
927 SetDataType(dt, dtID, dtOrigin);
928 return GetFirstInputObject(dt, classname, bForce);
931 const TObject* AliHLTComponent::GetNextInputObject(int bForce)
933 // see header file for function documentation
934 ALIHLTCOMPONENT_BASE_STOPWATCH();
935 int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1, 1);
936 //HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(fSearchDataType).c_str());
939 if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) {
940 fCurrentInputBlock=idx;
946 int AliHLTComponent::FindInputBlock(const AliHLTComponentDataType& dt, int startIdx, int bObject) const
948 // see header file for function documentation
950 if (fpInputBlocks!=NULL) {
951 int idx=startIdx<0?0:startIdx;
952 for ( ; (UInt_t)idx<fCurrentEventData.fBlockCnt && iResult==-ENOENT; idx++) {
953 if (dt!=fpInputBlocks[idx].fDataType) continue;
956 if (fpInputBlocks[idx].fPtr==NULL) continue;
957 AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr);
958 if (firstWord!=fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) continue;
966 TObject* AliHLTComponent::CreateInputObject(int idx, int bForce)
968 // see header file for function documentation
970 if (fpInputBlocks!=NULL) {
971 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
972 if (fpInputBlocks[idx].fPtr) {
973 AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr);
974 if (firstWord==fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) {
975 HLTDebug("create object from block %d size %d", idx, fpInputBlocks[idx].fSize);
976 AliHLTMessage msg(fpInputBlocks[idx].fPtr, fpInputBlocks[idx].fSize);
977 TClass* objclass=msg.GetClass();
978 pObj=msg.ReadObject(objclass);
979 if (pObj && objclass) {
980 HLTDebug("object %p type %s created", pObj, objclass->GetName());
984 } else if (bForce!=0) {
985 HLTError("size mismatch: block size %d, indicated %d", fpInputBlocks[idx].fSize, firstWord+sizeof(AliHLTUInt32_t));
988 HLTFatal("block descriptor empty");
991 HLTError("index %d out of range %d", idx, fCurrentEventData.fBlockCnt);
994 HLTError("no input blocks available");
1000 TObject* AliHLTComponent::GetInputObject(int idx, const char* /*classname*/, int bForce)
1002 // see header file for function documentation
1003 if (fpInputObjects==NULL) {
1004 fpInputObjects=new TObjArray(fCurrentEventData.fBlockCnt);
1007 if (fpInputObjects) {
1008 pObj=fpInputObjects->At(idx);
1010 pObj=CreateInputObject(idx, bForce);
1012 fpInputObjects->AddAt(pObj, idx);
1016 HLTFatal("memory allocation failed: TObjArray of size %d", fCurrentEventData.fBlockCnt);
1021 int AliHLTComponent::CleanupInputObjects()
1023 // see header file for function documentation
1024 if (!fpInputObjects) return 0;
1025 TObjArray* array=fpInputObjects;
1026 fpInputObjects=NULL;
1027 for (int i=0; i<array->GetEntries(); i++) {
1028 TObject* pObj=array->At(i);
1029 // grrr, garbage collection strikes back: When read via AliHLTMessage
1030 // (CreateInputObject), and written to a TFile afterwards, the
1031 // TFile::Close calls ROOOT's garbage collection. No clue why the
1032 // object ended up in the key list and needs to be deleted
1034 // Matthias 09.11.2008 follow up
1035 // This approach doesn't actually work in all cases: the object table
1036 // can be switched off globally, the flag needs to be checked here as
1037 // well in order to avoid memory leaks.
1038 // This means we have to find another solution for the problem if it
1041 (!TObject::GetObjectStat() || gObjectTable->PtrIsValid(pObj))) {
1049 AliHLTComponentDataType AliHLTComponent::GetDataType(const TObject* pObject)
1051 // see header file for function documentation
1052 ALIHLTCOMPONENT_BASE_STOPWATCH();
1053 AliHLTComponentDataType dt=kAliHLTVoidDataType;
1054 int idx=fCurrentInputBlock;
1056 if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
1058 HLTError("unknown object %p", pObject);
1062 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
1063 dt=fpInputBlocks[idx].fDataType;
1065 HLTFatal("severe internal error, index out of range");
1071 AliHLTUInt32_t AliHLTComponent::GetSpecification(const TObject* pObject)
1073 // see header file for function documentation
1074 ALIHLTCOMPONENT_BASE_STOPWATCH();
1075 AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec;
1076 int idx=fCurrentInputBlock;
1078 if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
1080 HLTError("unknown object %p", pObject);
1084 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
1085 iSpec=fpInputBlocks[idx].fSpecification;
1087 HLTFatal("severe internal error, index out of range");
1093 int AliHLTComponent::Forward(const TObject* pObject)
1095 // see header file for function documentation
1097 int idx=fCurrentInputBlock;
1099 if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
1101 HLTError("unknown object %p", pObject);
1106 fOutputBlocks.push_back(fpInputBlocks[idx]);
1111 int AliHLTComponent::Forward(const AliHLTComponentBlockData* pBlock)
1113 // see header file for function documentation
1115 int idx=fCurrentInputBlock;
1117 if (fpInputObjects==NULL || (idx=FindInputBlock(pBlock))>=0) {
1119 HLTError("unknown Block %p", pBlock);
1124 // check for fpInputBlocks pointer done in FindInputBlock
1125 fOutputBlocks.push_back(fpInputBlocks[idx]);
1130 const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const AliHLTComponentDataType& dt)
1132 // see header file for function documentation
1133 ALIHLTCOMPONENT_BASE_STOPWATCH();
1136 int idx=FindInputBlock(fSearchDataType, 0);
1137 const AliHLTComponentBlockData* pBlock=NULL;
1139 // check for fpInputBlocks pointer done in FindInputBlock
1140 pBlock=&fpInputBlocks[idx];
1141 fCurrentInputBlock=idx;
1146 const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const char* dtID,
1147 const char* dtOrigin)
1149 // see header file for function documentation
1150 ALIHLTCOMPONENT_BASE_STOPWATCH();
1151 AliHLTComponentDataType dt;
1152 SetDataType(dt, dtID, dtOrigin);
1153 return GetFirstInputBlock(dt);
1156 const AliHLTComponentBlockData* AliHLTComponent::GetInputBlock(int index) const
1158 // see header file for function documentation
1159 ALIHLTCOMPONENT_BASE_STOPWATCH();
1160 assert( 0 <= index and index < (int)fCurrentEventData.fBlockCnt );
1161 return &fpInputBlocks[index];
1164 const AliHLTComponentBlockData* AliHLTComponent::GetNextInputBlock()
1166 // see header file for function documentation
1167 ALIHLTCOMPONENT_BASE_STOPWATCH();
1168 int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1);
1169 const AliHLTComponentBlockData* pBlock=NULL;
1171 // check for fpInputBlocks pointer done in FindInputBlock
1172 pBlock=&fpInputBlocks[idx];
1173 fCurrentInputBlock=idx;
1178 int AliHLTComponent::FindInputBlock(const AliHLTComponentBlockData* pBlock) const
1180 // see header file for function documentation
1181 int iResult=-ENOENT;
1182 if (fpInputBlocks!=NULL) {
1184 if (pBlock>=fpInputBlocks && pBlock<fpInputBlocks+fCurrentEventData.fBlockCnt) {
1185 iResult=(int)(pBlock-fpInputBlocks);
1194 AliHLTUInt32_t AliHLTComponent::GetSpecification(const AliHLTComponentBlockData* pBlock)
1196 // see header file for function documentation
1197 ALIHLTCOMPONENT_BASE_STOPWATCH();
1198 AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec;
1199 int idx=fCurrentInputBlock;
1201 if (fpInputObjects==NULL || (idx=FindInputBlock(pBlock))>=0) {
1203 HLTError("unknown Block %p", pBlock);
1207 // check for fpInputBlocks pointer done in FindInputBlock
1208 iSpec=fpInputBlocks[idx].fSpecification;
1213 int AliHLTComponent::PushBack(TObject* pObject, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
1214 void* pHeader, int headerSize)
1216 // see header file for function documentation
1217 ALIHLTCOMPONENT_BASE_STOPWATCH();
1221 AliHLTMessage msg(kMESS_OBJECT);
1222 msg.SetCompressionLevel(fCompressionLevel);
1223 msg.WriteObject(pObject);
1224 Int_t iMsgLength=msg.Length();
1226 // Matthias Sep 2008
1227 // NOTE: AliHLTMessage does implement it's own SetLength method
1228 // which is not architecture independent. The original SetLength
1229 // stores the size always in network byte order.
1230 // I'm trying to remember the rational for that, might be that
1231 // it was just some lack of knowledge. Want to change this, but
1232 // has to be done carefullt to be backward compatible.
1233 msg.SetLength(); // sets the length to the first (reserved) word
1235 // does nothing if the level is 0
1238 char *mbuf = msg.Buffer();
1239 if (msg.CompBuffer()) {
1240 msg.SetLength(); // set once more to have to byte order
1241 mbuf = msg.CompBuffer();
1242 iMsgLength = msg.CompLength();
1245 iResult=InsertOutputBlock(mbuf, iMsgLength, dt, spec, pHeader, headerSize);
1247 HLTDebug("object %s (%p) size %d compression %d inserted to output", pObject->ClassName(), pObject, iMsgLength, msg.GetCompressionLevel());
1249 fLastObjectSize=iMsgLength;
1251 HLTError("object serialization failed for object %p", pObject);
1260 int AliHLTComponent::PushBack(TObject* pObject, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec,
1261 void* pHeader, int headerSize)
1263 // see header file for function documentation
1264 ALIHLTCOMPONENT_BASE_STOPWATCH();
1265 AliHLTComponentDataType dt;
1266 SetDataType(dt, dtID, dtOrigin);
1267 return PushBack(pObject, dt, spec, pHeader, headerSize);
1270 int AliHLTComponent::PushBack(const void* pBuffer, int iSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
1271 const void* pHeader, int headerSize)
1273 // see header file for function documentation
1274 ALIHLTCOMPONENT_BASE_STOPWATCH();
1275 return InsertOutputBlock(pBuffer, iSize, dt, spec, pHeader, headerSize);
1278 int AliHLTComponent::PushBack(const void* pBuffer, int iSize, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec,
1279 const void* pHeader, int headerSize)
1281 // see header file for function documentation
1282 ALIHLTCOMPONENT_BASE_STOPWATCH();
1283 AliHLTComponentDataType dt;
1284 SetDataType(dt, dtID, dtOrigin);
1285 return PushBack(pBuffer, iSize, dt, spec, pHeader, headerSize);
1288 int AliHLTComponent::InsertOutputBlock(const void* pBuffer, int iBufferSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
1289 const void* pHeader, int iHeaderSize)
1291 // see header file for function documentation
1293 int iBlkSize = iBufferSize + iHeaderSize;
1295 if ((pBuffer!=NULL && iBufferSize>0) || (pHeader!=NULL && iHeaderSize>0)) {
1296 if (fpOutputBuffer && iBlkSize<=(int)(fOutputBufferSize-fOutputBufferFilled)) {
1297 AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled;
1299 // copy header if provided but skip if the header is the target location
1300 // in that case it has already been copied
1301 if (pHeader!=NULL && pHeader!=pTgt) {
1302 memcpy(pTgt, pHeader, iHeaderSize);
1305 pTgt += (AliHLTUInt8_t) iHeaderSize;
1307 // copy buffer if provided but skip if buffer is the target location
1308 // in that case it has already been copied
1309 if (pBuffer!=NULL && pBuffer!=pTgt) {
1310 memcpy(pTgt, pBuffer, iBufferSize);
1312 //AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)pBuffer);
1313 //HLTDebug("copy %d bytes from %p to output buffer %p, first word %#x", iBufferSize, pBuffer, pTgt, firstWord);
1315 //HLTDebug("buffer inserted to output: size %d data type %s spec %#x", iBlkSize, DataType2Text(dt).c_str(), spec);
1317 if (fpOutputBuffer) {
1318 HLTError("too little space in output buffer: %d of %d, required %d", fOutputBufferSize-fOutputBufferFilled, fOutputBufferSize, iBlkSize);
1320 HLTError("output buffer not available");
1326 AliHLTComponentBlockData bd;
1327 FillBlockData( bd );
1328 bd.fOffset = fOutputBufferFilled;
1329 bd.fSize = iBlkSize;
1331 bd.fSpecification = spec;
1332 fOutputBlocks.push_back( bd );
1333 fOutputBufferFilled+=bd.fSize;
1339 int AliHLTComponent::EstimateObjectSize(TObject* pObject) const
1341 // see header file for function documentation
1342 if (!pObject) return -EINVAL;
1343 AliHLTMessage msg(kMESS_OBJECT);
1344 msg.WriteObject(pObject);
1345 return msg.Length();
1348 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(int capacity, const char* dtID,
1349 const char* dtOrigin,
1350 AliHLTUInt32_t spec)
1352 // see header file for function documentation
1353 ALIHLTCOMPONENT_BASE_STOPWATCH();
1354 AliHLTComponentDataType dt;
1355 SetDataType(dt, dtID, dtOrigin);
1356 return CreateMemoryFile(capacity, dt, spec);
1359 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(int capacity,
1360 const AliHLTComponentDataType& dt,
1361 AliHLTUInt32_t spec)
1363 // see header file for function documentation
1364 ALIHLTCOMPONENT_BASE_STOPWATCH();
1365 AliHLTMemoryFile* pFile=NULL;
1366 if (capacity>=0 && static_cast<unsigned int>(capacity)<=fOutputBufferSize-fOutputBufferFilled){
1367 AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled;
1368 pFile=new AliHLTMemoryFile((char*)pTgt, capacity);
1370 unsigned int nofBlocks=fOutputBlocks.size();
1371 if (nofBlocks+1>fMemFiles.size()) {
1372 fMemFiles.resize(nofBlocks+1, NULL);
1374 if (nofBlocks<fMemFiles.size()) {
1375 fMemFiles[nofBlocks]=pFile;
1376 AliHLTComponentBlockData bd;
1377 FillBlockData( bd );
1378 bd.fOffset = fOutputBufferFilled;
1379 bd.fSize = capacity;
1381 bd.fSpecification = spec;
1382 fOutputBufferFilled+=bd.fSize;
1383 fOutputBlocks.push_back( bd );
1385 HLTError("can not allocate/grow object array");
1386 pFile->CloseMemoryFile(0);
1392 HLTError("can not create memory file of size %d (%d available)", capacity, fOutputBufferSize-fOutputBufferFilled);
1397 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(const char* dtID,
1398 const char* dtOrigin,
1399 AliHLTUInt32_t spec,
1402 // see header file for function documentation
1403 ALIHLTCOMPONENT_BASE_STOPWATCH();
1404 AliHLTComponentDataType dt;
1405 SetDataType(dt, dtID, dtOrigin);
1406 int size=fOutputBufferSize-fOutputBufferFilled;
1407 if (capacity<0 || capacity>1.0) {
1408 HLTError("invalid parameter: capacity %f", capacity);
1411 size=(int)(size*capacity);
1412 return CreateMemoryFile(size, dt, spec);
1415 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(const AliHLTComponentDataType& dt,
1416 AliHLTUInt32_t spec,
1419 // see header file for function documentation
1420 ALIHLTCOMPONENT_BASE_STOPWATCH();
1421 int size=fOutputBufferSize-fOutputBufferFilled;
1422 if (capacity<0 || capacity>1.0) {
1423 HLTError("invalid parameter: capacity %f", capacity);
1426 size=(int)(size*capacity);
1427 return CreateMemoryFile(size, dt, spec);
1430 int AliHLTComponent::Write(AliHLTMemoryFile* pFile, const TObject* pObject,
1431 const char* key, int option)
1433 // see header file for function documentation
1435 if (pFile && pObject) {
1437 iResult=pObject->Write(key, option);
1441 iResult=-pFile->GetErrno();
1442 if (iResult==-ENOSPC) {
1443 HLTError("error writing memory file, buffer too small");
1452 int AliHLTComponent::CloseMemoryFile(AliHLTMemoryFile* pFile)
1454 // see header file for function documentation
1457 AliHLTMemoryFilePList::iterator element=fMemFiles.begin();
1459 while (element!=fMemFiles.end() && iResult>=0) {
1460 if (*element && *element==pFile) {
1461 iResult=pFile->CloseMemoryFile();
1463 // sync memory files and descriptors
1465 fOutputBlocks[i].fSize=(*element)->GetSize()+(*element)->GetHeaderSize();
1473 HLTError("can not find memory file %p", pFile);
1481 int AliHLTComponent::CreateEventDoneData(AliHLTComponentEventDoneData edd)
1483 // see header file for function documentation
1486 AliHLTComponentEventDoneData* newEDD = NULL;
1488 unsigned long newSize=edd.fDataSize;
1490 newSize += fEventDoneData->fDataSize;
1492 if (newSize>fEventDoneDataSize) {
1493 newEDD = reinterpret_cast<AliHLTComponentEventDoneData*>( new AliHLTUInt8_t[ sizeof(AliHLTComponentEventDoneData)+newSize ] );
1496 newEDD->fStructSize = sizeof(AliHLTComponentEventDoneData);
1497 newEDD->fDataSize = newSize;
1498 newEDD->fData = reinterpret_cast<AliHLTUInt8_t*>(newEDD)+newEDD->fStructSize;
1499 unsigned long long offset = 0;
1500 if (fEventDoneData) {
1501 memcpy( newEDD->fData, fEventDoneData->fData, fEventDoneData->fDataSize );
1502 offset += fEventDoneData->fDataSize;
1504 memcpy( reinterpret_cast<AliHLTUInt8_t*>(newEDD->fData)+offset, edd.fData, edd.fDataSize );
1506 delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
1507 fEventDoneData = newEDD;
1508 fEventDoneDataSize = newSize;
1511 memcpy( reinterpret_cast<AliHLTUInt8_t*>(fEventDoneData->fData)+fEventDoneData->fDataSize, edd.fData, edd.fDataSize );
1512 fEventDoneData->fDataSize += edd.fDataSize;
1517 int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
1518 const AliHLTComponentBlockData* blocks,
1519 AliHLTComponentTriggerData& trigData,
1520 AliHLTUInt8_t* outputPtr,
1521 AliHLTUInt32_t& size,
1522 AliHLTUInt32_t& outputBlockCnt,
1523 AliHLTComponentBlockData*& outputBlocks,
1524 AliHLTComponentEventDoneData*& edd )
1526 // see header file for function documentation
1527 HLTLogKeyword(fChainId.c_str());
1528 ALIHLTCOMPONENT_BASE_STOPWATCH();
1530 fCurrentEvent=evtData.fEventID;
1531 fCurrentEventData=evtData;
1532 fpInputBlocks=blocks;
1533 fCurrentInputBlock=-1;
1534 fSearchDataType=kAliHLTAnyDataType;
1535 fpOutputBuffer=outputPtr;
1536 fOutputBufferSize=size;
1537 fOutputBufferFilled=0;
1538 fOutputBlocks.clear();
1542 AliHLTComponentBlockDataList forwardedBlocks;
1544 // optional component statistics
1545 AliHLTComponentStatisticsList compStats;
1546 bool bAddComponentTableEntry=false;
1547 vector<AliHLTUInt32_t> parentComponentTables;
1548 #if defined(__DEBUG) || defined(HLT_COMPONENT_STATISTICS)
1549 AliHLTComponentStatistics outputStat;
1550 memset(&outputStat, 0, sizeof(AliHLTComponentStatistics));
1551 outputStat.fStructSize=sizeof(AliHLTComponentStatistics);
1552 outputStat.fId=fChainIdCrc;
1554 fpBenchmark->Stop();
1555 outputStat.fComponentCycleTime=(AliHLTUInt32_t)(fpBenchmark->RealTime()*ALIHLTCOMPONENT_STATTIME_SCALER);
1556 fpBenchmark->Reset();
1557 fpBenchmark->Start();
1559 compStats.push_back(outputStat);
1562 // data processing is skipped
1563 // - if there are only steering events in the block list.
1564 // For the sake of data source components data processing
1565 // is not skipped if there is no block list at all or if it
1566 // just contains the eventType block
1567 // - always skipped if the event is of type
1568 // - gkAliEventTypeConfiguration
1569 // - gkAliEventTypeReadPreprocessor
1570 const unsigned int skipModeDefault=0x1;
1571 const unsigned int skipModeForce=0x2;
1572 unsigned int bSkipDataProcessing=skipModeDefault;
1574 // find special events
1575 if (fpInputBlocks && evtData.fBlockCnt>0) {
1576 // first look for all special events and execute in the appropriate
1577 // sequence afterwords
1578 int indexComConfEvent=-1;
1579 int indexUpdtDCSEvent=-1;
1580 int indexSOREvent=-1;
1581 int indexEOREvent=-1;
1582 int indexECSParamBlock=-1;
1583 for (unsigned int i=0; i<evtData.fBlockCnt && iResult>=0; i++) {
1584 if (fpInputBlocks[i].fDataType==kAliHLTDataTypeSOR) {
1586 // the AliHLTCalibrationProcessor relies on the SOR and EOR events
1587 bSkipDataProcessing&=~skipModeDefault;
1588 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeRunType) {
1590 // handling is not clear yet
1591 if (fpInputBlocks[i].fPtr) {
1592 HLTDebug("got run type \"%s\"\n", fpInputBlocks[i].fPtr);
1594 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeEOR) {
1596 // the calibration processor relies on the SOR and EOR events
1597 bSkipDataProcessing&=~skipModeDefault;
1598 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeDDL) {
1600 // this event is most likely deprecated
1601 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComConf) {
1602 indexComConfEvent=i;
1603 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeUpdtDCS) {
1604 indexUpdtDCSEvent=i;
1605 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeEvent) {
1606 fEventType=fpInputBlocks[i].fSpecification;
1608 // skip always in case of gkAliEventTypeConfiguration
1609 if (fpInputBlocks[i].fSpecification==gkAliEventTypeConfiguration) bSkipDataProcessing|=skipModeForce;
1611 // skip always in case of gkAliEventTypeReadPreprocessor
1612 if (fpInputBlocks[i].fSpecification==gkAliEventTypeReadPreprocessor) bSkipDataProcessing|=skipModeForce;
1614 // never skip if the event type block is the only block
1615 if (evtData.fBlockCnt==1) bSkipDataProcessing&=~skipModeDefault;
1617 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComponentStatistics) {
1618 if (compStats.size()>0) {
1619 AliHLTUInt8_t* pData=reinterpret_cast<AliHLTUInt8_t*>(fpInputBlocks[i].fPtr);
1620 for (AliHLTUInt32_t offset=0;
1621 offset+sizeof(AliHLTComponentStatistics)<=fpInputBlocks[i].fSize;
1622 offset+=sizeof(AliHLTComponentStatistics)) {
1623 AliHLTComponentStatistics* pStat=reinterpret_cast<AliHLTComponentStatistics*>(pData+offset);
1624 if (pStat && compStats[0].fLevel<=pStat->fLevel) {
1625 compStats[0].fLevel=pStat->fLevel+1;
1627 compStats.push_back(*pStat);
1630 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComponentTable) {
1631 forwardedBlocks.push_back(fpInputBlocks[i]);
1632 parentComponentTables.push_back(fpInputBlocks[i].fSpecification);
1633 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeECSParam) {
1634 indexECSParamBlock=i;
1636 // the processing function is called if there is at least one
1637 // non-steering data block. Steering blocks are not filtered out
1638 // for sake of performance
1639 bSkipDataProcessing&=~skipModeDefault;
1640 if (compStats.size()>0) {
1641 compStats[0].fInputBlockCount++;
1642 compStats[0].fTotalInputSize+=fpInputBlocks[i].fSize;
1647 if (indexSOREvent>=0) {
1649 bAddComponentTableEntry=true;
1650 if (fpRunDesc==NULL) {
1651 fpRunDesc=new AliHLTRunDesc;
1652 if (fpRunDesc) *fpRunDesc=kAliHLTVoidRunDesc;
1655 AliHLTRunDesc rundesc;
1656 if ((iResult=CopyStruct(&rundesc, sizeof(AliHLTRunDesc), indexSOREvent, "AliHLTRunDesc", "SOR"))>0) {
1657 if (fpRunDesc->fRunNo==kAliHLTVoidRunNo) {
1659 HLTDebug("set run decriptor, run no %d", fpRunDesc->fRunNo);
1660 SetCDBRunNo(fpRunDesc->fRunNo);
1661 } else if (fpRunDesc->fRunNo!=rundesc.fRunNo) {
1662 HLTWarning("already set run properties run no %d, ignoring SOR with run no %d", fpRunDesc->fRunNo, rundesc.fRunNo);
1669 if (indexECSParamBlock>=0) {
1670 if (fpInputBlocks[indexECSParamBlock].fSize>0) {
1671 const char* param=reinterpret_cast<const char*>(fpInputBlocks[indexECSParamBlock].fPtr);
1672 TString paramString;
1673 if (param[fpInputBlocks[indexECSParamBlock].fSize-1]!=0) {
1674 HLTWarning("ECS parameter string not terminated");
1675 paramString.Insert(0, param, fpInputBlocks[indexECSParamBlock].fSize);
1680 ScanECSParam(paramString.Data());
1682 HLTWarning("empty ECS parameter received");
1685 // TODO: later on we might throw a warning here since the CTP trigger classes
1686 // should be mandatory
1689 if (indexEOREvent>=0) {
1690 bAddComponentTableEntry=true;
1691 if (fpRunDesc!=NULL) {
1693 AliHLTRunDesc rundesc;
1694 if ((iResult=CopyStruct(&rundesc, sizeof(AliHLTRunDesc), indexEOREvent, "AliHLTRunDesc", "SOR"))>0) {
1695 if (fpRunDesc->fRunNo!=rundesc.fRunNo) {
1696 HLTWarning("run no mismatch: SOR %d, EOR %d", fpRunDesc->fRunNo, rundesc.fRunNo);
1698 HLTDebug("EOR run no %d", fpRunDesc->fRunNo);
1701 // we do not unload the fpRunDesc struct here in order to have the run information
1702 // available during the event processing
1703 // https://savannah.cern.ch/bugs/?39711
1704 // the info will be cleared in DeInit
1707 HLTWarning("did not receive SOR, ignoring EOR");
1710 if (indexComConfEvent>=0 || fEventType==gkAliEventTypeConfiguration) {
1712 if (indexComConfEvent>=0 && fpInputBlocks[indexComConfEvent].fPtr!=NULL && fpInputBlocks[indexComConfEvent].fSize>0) {
1713 cdbEntry.Append(reinterpret_cast<const char*>(fpInputBlocks[indexComConfEvent].fPtr), fpInputBlocks[indexComConfEvent].fSize);
1715 HLTDebug("received component configuration command: entry %s", cdbEntry.IsNull()?"none":cdbEntry.Data());
1716 int tmpResult=Reconfigure(cdbEntry[0]==0?NULL:cdbEntry.Data(), fChainId.c_str());
1718 HLTWarning("reconfiguration of component %p (%s) failed with error code %d", this, GetComponentID(), tmpResult);
1721 if (indexUpdtDCSEvent>=0 || fEventType==gkAliEventTypeReadPreprocessor) {
1723 if (fpInputBlocks[indexUpdtDCSEvent].fPtr!=NULL && fpInputBlocks[indexUpdtDCSEvent].fSize>0) {
1724 modules.Append(reinterpret_cast<const char*>(fpInputBlocks[indexUpdtDCSEvent].fPtr), fpInputBlocks[indexUpdtDCSEvent].fSize);
1726 HLTDebug("received preprocessor update command: detectors %s", modules.IsNull()?"ALL":modules.Data());
1727 int tmpResult=ReadPreprocessorValues(modules[0]==0?"ALL":modules.Data());
1729 HLTWarning("preprocessor update of component %p (%s) failed with error code %d", this, GetComponentID(), tmpResult);
1733 // processing function needs to be called if there are no input data
1734 // blocks in order to make data source components working.
1735 bSkipDataProcessing&=~skipModeDefault;
1738 // data processing is not skipped if the component explicitly asks
1739 // for the private blocks
1740 if (fRequireSteeringBlocks) bSkipDataProcessing=0;
1742 // increment CTP trigger counters if available
1743 if (fpCTPData && IsDataEvent()) fpCTPData->Increment(trigData);
1745 AliHLTComponentBlockDataList blockData;
1746 if (iResult>=0 && !bSkipDataProcessing)
1747 { // dont delete, sets the scope for the stopwatch guard
1748 // do not use ALIHLTCOMPONENT_DA_STOPWATCH(); macro
1749 // in order to avoid 'shadowed variable' warning
1750 AliHLTStopwatchGuard swguard2(fpStopwatches!=NULL?reinterpret_cast<TStopwatch*>(fpStopwatches->At((int)kSWDA)):NULL);
1751 iResult=DoProcessing(evtData, blocks, trigData, outputPtr, size, blockData, edd);
1752 } // end of the scope of the stopwatch guard
1753 if (iResult>=0 && !bSkipDataProcessing) {
1754 if (fOutputBlocks.size()>0) {
1755 // High Level interface
1757 //HLTDebug("got %d block(s) via high level interface", fOutputBlocks.size());
1758 // sync memory files and descriptors
1759 AliHLTMemoryFilePList::iterator element=fMemFiles.begin();
1761 while (element!=fMemFiles.end() && iResult>=0) {
1763 if ((*element)->IsClosed()==0) {
1764 HLTWarning("memory file has not been closed, force flush");
1765 iResult=CloseMemoryFile(*element);
1772 // create the descriptor list
1773 if (blockData.size()>0) {
1774 HLTError("low level and high interface must not be mixed; use PushBack methods to insert data blocks");
1777 if (compStats.size()>0 && IsDataEvent()) {
1778 int offset=AddComponentStatistics(fOutputBlocks, fpOutputBuffer, fOutputBufferSize, fOutputBufferFilled, compStats);
1779 if (offset>0) fOutputBufferFilled+=offset;
1781 if (bAddComponentTableEntry) {
1782 int offset=AddComponentTableEntry(fOutputBlocks, fpOutputBuffer, fOutputBufferSize, fOutputBufferFilled, parentComponentTables);
1783 if (offset>0) size+=offset;
1785 if (forwardedBlocks.size()>0) {
1786 fOutputBlocks.insert(fOutputBlocks.end(), forwardedBlocks.begin(), forwardedBlocks.end());
1788 iResult=MakeOutputDataBlockList(fOutputBlocks, &outputBlockCnt, &outputBlocks);
1789 size=fOutputBufferFilled;
1793 // Low Level interface
1794 if (compStats.size()>0) {
1795 int offset=AddComponentStatistics(blockData, fpOutputBuffer, fOutputBufferSize, size, compStats);
1796 if (offset>0) size+=offset;
1798 if (bAddComponentTableEntry) {
1799 int offset=AddComponentTableEntry(blockData, fpOutputBuffer, fOutputBufferSize, size, parentComponentTables);
1800 if (offset>0) size+=offset;
1802 if (forwardedBlocks.size()>0) {
1803 blockData.insert(blockData.end(), forwardedBlocks.begin(), forwardedBlocks.end());
1805 iResult=MakeOutputDataBlockList(blockData, &outputBlockCnt, &outputBlocks);
1808 HLTFatal("component %s (%p): can not convert output block descriptor list", GetComponentID(), this);
1811 if (iResult<0 || bSkipDataProcessing) {
1815 CleanupInputObjects();
1816 if (iResult>=0 && IsDataEvent()) {
1817 IncrementEventCounter();
1819 if (outputBlockCnt==0) {
1820 // no output blocks, set size to 0
1824 // reset the internal EventData struct
1825 FillEventData(fCurrentEventData);
1829 int AliHLTComponent::AddComponentStatistics(AliHLTComponentBlockDataList& blocks,
1830 AliHLTUInt8_t* buffer,
1831 AliHLTUInt32_t bufferSize,
1832 AliHLTUInt32_t offset,
1833 AliHLTComponentStatisticsList& stats) const
1835 // see header file for function documentation
1837 #if defined(__DEBUG) || defined(HLT_COMPONENT_STATISTICS)
1838 if (stats.size()==0) return -ENOENT;
1839 // check if there is space for at least one entry
1840 if (offset+sizeof(AliHLTComponentStatistics)>bufferSize) return 0;
1841 stats[0].fTotalOutputSize=offset;
1842 stats[0].fOutputBlockCount=blocks.size();
1844 fpBenchmark->Stop();
1845 stats[0].fTime=(AliHLTUInt32_t)(fpBenchmark->RealTime()*ALIHLTCOMPONENT_STATTIME_SCALER);
1846 stats[0].fCTime=(AliHLTUInt32_t)(fpBenchmark->CpuTime()*ALIHLTCOMPONENT_STATTIME_SCALER);
1847 fpBenchmark->Continue();
1849 if (offset+stats.size()*sizeof(AliHLTComponentStatistics)>bufferSize) {
1850 AliHLTUInt32_t removedLevel=0;
1852 // remove all entries of the level of the last entry
1853 removedLevel=stats.back().fLevel;
1854 AliHLTComponentStatisticsList::iterator element=stats.begin();
1856 while (element!=stats.end()) {
1857 if (element->fLevel<=removedLevel) {
1858 element=stats.erase(element);
1863 } while (stats.size()>1 &&
1864 (offset+stats.size()*sizeof(AliHLTComponentStatistics)>bufferSize));
1866 assert(stats.size()>0);
1867 if (stats.size()==0) return 0;
1869 if (offset+stats.size()*sizeof(AliHLTComponentStatistics)<=bufferSize) {
1870 AliHLTComponentBlockData bd;
1871 FillBlockData( bd );
1872 bd.fOffset = offset;
1873 bd.fSize = stats.size()*sizeof(AliHLTComponentStatistics);
1874 bd.fDataType = kAliHLTDataTypeComponentStatistics;
1875 bd.fSpecification = kAliHLTVoidDataSpec;
1876 unsigned int master=0;
1877 for (unsigned int i=1; i<blocks.size(); i++) {
1878 if (blocks[i].fSize>blocks[master].fSize &&
1879 !MatchExactly(blocks[i].fDataType, kAliHLTVoidDataType|kAliHLTDataOriginPrivate))
1882 if (blocks.size()>0 && !MatchExactly(blocks[master].fDataType, kAliHLTVoidDataType|kAliHLTDataOriginPrivate)) {
1883 // take the data origin of the biggest block as specification
1884 // this is similar to the treatment in the HOMER interface. For traditional
1885 // reasons, the bytes are swapped there on a little endian architecture, so
1886 // we do it as well.
1887 memcpy(&bd.fSpecification, &blocks[master].fDataType.fOrigin, sizeof(bd.fSpecification));
1888 #ifdef R__BYTESWAP // set on little endian architectures
1889 bd.fSpecification=((bd.fSpecification & 0xFFULL) << 24) |
1890 ((bd.fSpecification & 0xFF00ULL) << 8) |
1891 ((bd.fSpecification & 0xFF0000ULL) >> 8) |
1892 ((bd.fSpecification & 0xFF000000ULL) >> 24);
1895 memcpy(buffer+offset, &(stats[0]), bd.fSize);
1896 blocks.push_back(bd);
1900 if (blocks.size() && buffer && bufferSize && offset && stats.size()) {
1901 // get rid of warning
1907 int AliHLTComponent::AddComponentTableEntry(AliHLTComponentBlockDataList& blocks,
1908 AliHLTUInt8_t* buffer,
1909 AliHLTUInt32_t bufferSize,
1910 AliHLTUInt32_t offset,
1911 const vector<AliHLTUInt32_t>& parents) const
1913 // see header file for function documentation
1915 #if defined(__DEBUG) || defined(HLT_COMPONENT_STATISTICS)
1916 // the payload consists of the AliHLTComponentTableEntry struct,
1917 // followed by a an array of 32bit crc chain ids and the component
1918 // description string
1919 unsigned int payloadSize=sizeof(AliHLTComponentTableEntry);
1920 payloadSize+=parents.size()*sizeof(AliHLTUInt32_t);
1922 // the component description has the following format:
1923 // chain-id{component-id:arguments}
1924 const char* componentId=const_cast<AliHLTComponent*>(this)->GetComponentID();
1925 unsigned int descriptionSize=fChainId.size()+1;
1926 descriptionSize+=2; // the '{}' around the component id
1927 descriptionSize+=strlen(componentId);
1928 descriptionSize+=1; // the ':' between component id and arguments
1929 descriptionSize+=fComponentArgs.size();
1931 payloadSize+=descriptionSize;
1932 if (buffer && (offset+payloadSize<=bufferSize)) {
1933 AliHLTUInt8_t* pTgt=buffer+offset;
1934 memset(pTgt, 0, payloadSize);
1937 AliHLTComponentTableEntry* pEntry=reinterpret_cast<AliHLTComponentTableEntry*>(pTgt);
1938 pEntry->fStructSize=sizeof(AliHLTComponentTableEntry);
1939 pEntry->fNofParents=parents.size();
1940 pEntry->fSizeDescription=descriptionSize;
1941 pTgt=pEntry->fBuffer;
1943 // write array of parents
1944 if (parents.size()>0) {
1945 unsigned int copy=parents.size()*sizeof(vector<AliHLTUInt32_t>::value_type);
1946 memcpy(pTgt, &parents[0], parents.size()*sizeof(vector<AliHLTUInt32_t>::value_type));
1950 // write component description
1951 memcpy(pTgt, fChainId.c_str(), fChainId.size());
1952 pTgt+=fChainId.size();
1954 memcpy(pTgt, componentId, strlen(componentId));
1955 pTgt+=strlen(componentId);
1957 memcpy(pTgt, fComponentArgs.c_str(), fComponentArgs.size());
1958 pTgt+=fComponentArgs.size();
1962 AliHLTComponentBlockData bd;
1963 FillBlockData( bd );
1964 bd.fOffset = offset;
1965 bd.fSize = payloadSize;
1966 bd.fDataType = kAliHLTDataTypeComponentTable;
1967 bd.fSpecification = fChainIdCrc;
1968 blocks.push_back(bd);
1972 if (blocks.size() && buffer && bufferSize && offset && parents.size()) {
1973 // get rid of warning
1979 AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard()
1984 // standard constructor (not for use)
1987 AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(TStopwatch* pStopwatch)
1989 fpStopwatch(pStopwatch),
1994 // check for already existing guard
1995 if (fgpCurrent) fpPrec=fgpCurrent;
1998 // stop the preceeding guard if it controls a different stopwatch
2000 if (fpPrec && fpPrec!=this) bStart=fpPrec->Hold(fpStopwatch);
2002 // start the stopwatch if the current guard controls a different one
2003 if (fpStopwatch && bStart==1) fpStopwatch->Start(kFALSE);
2006 AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(const AliHLTStopwatchGuard&)
2012 // copy constructor not for use
2016 AliHLTComponent::AliHLTStopwatchGuard& AliHLTComponent::AliHLTStopwatchGuard::operator=(const AliHLTStopwatchGuard&)
2019 // assignment operator not for use
2026 AliHLTComponent::AliHLTStopwatchGuard* AliHLTComponent::AliHLTStopwatchGuard::fgpCurrent=NULL;
2028 AliHLTComponent::AliHLTStopwatchGuard::~AliHLTStopwatchGuard()
2032 // resume the preceeding guard if it controls a different stopwatch
2034 if (fpPrec && fpPrec!=this) bStop=fpPrec->Resume(fpStopwatch);
2036 // stop the stopwatch if the current guard controls a different one
2037 if (fpStopwatch && bStop==1) fpStopwatch->Stop();
2039 // resume to the preceeding guard
2043 int AliHLTComponent::AliHLTStopwatchGuard::Hold(TStopwatch* pSucc)
2045 // see header file for function documentation
2046 if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Stop();
2047 return fpStopwatch!=pSucc?1:0;
2050 int AliHLTComponent::AliHLTStopwatchGuard::Resume(TStopwatch* pSucc)
2052 // see header file for function documentation
2053 if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Start(kFALSE);
2054 return fpStopwatch!=pSucc?1:0;
2057 int AliHLTComponent::SetStopwatch(TObject* pSW, AliHLTStopwatchType type)
2059 // see header file for function documentation
2061 if (pSW!=NULL && type<kSWTypeCount) {
2062 if (fpStopwatches) {
2063 TObject* pObj=fpStopwatches->At((int)type);
2064 if (pSW==NULL // explicit reset
2065 || pObj==NULL) { // explicit set
2066 fpStopwatches->AddAt(pSW, (int)type);
2067 } else if (pObj!=pSW) {
2068 HLTWarning("stopwatch %d already set, reset first", (int)type);
2078 int AliHLTComponent::SetStopwatches(TObjArray* pStopwatches)
2080 // see header file for function documentation
2081 if (pStopwatches==NULL) return -EINVAL;
2084 for (int i=0 ; i<(int)kSWTypeCount && pStopwatches->GetEntries(); i++)
2085 SetStopwatch(pStopwatches->At(i), (AliHLTStopwatchType)i);
2089 AliHLTUInt32_t AliHLTComponent::GetRunNo() const
2091 // see header file for function documentation
2092 if (fpRunDesc==NULL) return kAliHLTVoidRunNo;
2093 return fpRunDesc->fRunNo;
2096 AliHLTUInt32_t AliHLTComponent::GetRunType() const
2098 // see header file for function documentation
2099 if (fpRunDesc==NULL) return kAliHLTVoidRunType;
2100 return fpRunDesc->fRunType;
2103 AliHLTUInt32_t AliHLTComponent::GetTimeStamp() const
2105 // see header file for function documentation
2106 if (fCurrentEventData.fEventCreation_s) {
2107 return fCurrentEventData.fEventCreation_s;
2109 // using the actual UTC if the time stamp was not set by the framework
2110 return static_cast<AliHLTUInt32_t>(time(NULL));
2113 AliHLTUInt32_t AliHLTComponent::GetPeriodNumber() const
2115 // see header file for function documentation
2116 return (GetEventId()>>36)&0xfffffff;
2119 AliHLTUInt32_t AliHLTComponent::GetOrbitNumber() const
2121 // see header file for function documentation
2122 return (GetEventId()>>12)&0xffffff;
2125 AliHLTUInt16_t AliHLTComponent::GetBunchCrossNumber() const
2127 // see header file for function documentation
2128 return GetEventId()&0xfff;
2131 bool AliHLTComponent::IsDataEvent(AliHLTUInt32_t* pTgt)
2133 // see header file for function documentation
2134 if (pTgt) *pTgt=fEventType;
2135 return (fEventType==gkAliEventTypeData ||
2136 fEventType==gkAliEventTypeDataReplay ||
2137 fEventType==gkAliEventTypeCalibration);
2140 int AliHLTComponent::CopyStruct(void* pStruct, unsigned int iStructSize, unsigned int iBlockNo,
2141 const char* structname, const char* eventname)
2143 // see header file for function documentation
2145 if (pStruct!=NULL && iStructSize>sizeof(AliHLTUInt32_t)) {
2146 if (fpInputBlocks!=NULL && iBlockNo<fCurrentEventData.fBlockCnt) {
2147 AliHLTUInt32_t* pTgt=(AliHLTUInt32_t*)pStruct;
2148 if (fpInputBlocks[iBlockNo].fPtr && fpInputBlocks[iBlockNo].fSize) {
2149 AliHLTUInt32_t copy=*((AliHLTUInt32_t*)fpInputBlocks[iBlockNo].fPtr);
2150 if (fpInputBlocks[iBlockNo].fSize!=copy) {
2151 HLTWarning("%s event: mismatch of block size (%d) and structure size (%d)", eventname, fpInputBlocks[iBlockNo].fSize, copy);
2152 if (copy>fpInputBlocks[iBlockNo].fSize) copy=fpInputBlocks[iBlockNo].fSize;
2154 if (copy!=iStructSize) {
2155 HLTWarning("%s event: mismatch in %s version (data type version %d)", eventname, structname, ALIHLT_DATA_TYPES_VERSION);
2156 if (copy>iStructSize) {
2159 memset(pTgt, 0, iStructSize);
2162 memcpy(pTgt, fpInputBlocks[iBlockNo].fPtr, copy);
2166 HLTWarning("%s event: missing data block", eventname);
2172 HLTError("invalid struct");
2178 void AliHLTComponent::SetDDLBit(AliHLTEventDDL &list, Int_t ddlId, Bool_t state ) const
2180 // see header file for function documentation
2182 // -- Detector offset
2183 Int_t ddlIdBase = TMath::FloorNint( (Double_t) ddlId / 256.0 );
2185 // -- Word Base = 1. word of detector ( TPC has 8 words, TOF 3 )
2188 if ( ddlIdBase <= 3 )
2189 wordBase = ddlIdBase;
2190 else if ( ddlIdBase > 3 && ddlIdBase < 5 )
2191 wordBase = ddlIdBase + 7;
2193 wordBase = ddlIdBase + 9;
2195 // -- Bit index in Word
2196 Int_t bitIdx = ddlId % 32;
2199 Int_t wordIdx = wordBase;
2201 // -- if TPC (3) or TOD (5) add word idx
2202 if ( ( ddlIdBase == 3 ) || ( ddlIdBase == 5 ) ) {
2203 wordIdx += TMath::FloorNint( (Double_t) ( ddlId - ( ddlIdBase * 256 ) ) / 32.0 );
2206 // -- Set -- 'OR' word with bit mask;
2208 list.fList[wordIdx] |= ( 0x00000001 << bitIdx );
2209 // -- Unset -- 'AND' word with bit mask;
2211 list.fList[wordIdx] &= ( 0xFFFFFFFF ^ ( 0x00000001 << bitIdx ) );
2214 Int_t AliHLTComponent::GetFirstUsedDDLWord(AliHLTEventDDL &list) const
2216 // see header file for function documentation
2220 for ( Int_t wordNdx = 0 ; wordNdx < gkAliHLTDDLListSize ; wordNdx++ ) {
2222 if ( list.fList[wordNdx] != 0 && iResult == -1 ) {
2223 // check for special cases TPC and TOF
2224 if ( wordNdx > 3 && wordNdx <= 10 ) {
2228 else if ( wordNdx > 12 && wordNdx <= 14 ) {
2235 else if ( list.fList[wordNdx] != 0 && iResult >= 0 ) {
2236 HLTError( "DDLIDs for minimum of TWO detectors ( %d, %d ) set, this function works only for ONE detector.", iResult, wordNdx );
2245 AliHLTUInt32_t AliHLTComponent::CalculateChecksum(const AliHLTUInt8_t* buffer, int size)
2247 // see header file for function documentation
2248 AliHLTUInt32_t remainder = 0;
2249 const AliHLTUInt8_t crcwidth=(8*sizeof(AliHLTUInt32_t));
2250 const AliHLTUInt32_t topbit=1 << (crcwidth-1);
2251 const AliHLTUInt32_t polynomial=0xD8; /* 11011 followed by 0's */
2254 // http://www.netrino.com/Embedded-Systems/How-To/CRC-Calculation-C-Code
2257 * Perform modulo-2 division, a byte at a time.
2259 for (int byte = 0; byte < size; ++byte)
2262 * Bring the next byte into the remainder.
2264 remainder ^= (buffer[byte] << (crcwidth - 8));
2267 * Perform modulo-2 division, a bit at a time.
2269 for (uint8_t bit = 8; bit > 0; --bit)
2272 * Try to divide the current data bit.
2274 if (remainder & topbit)
2276 remainder = (remainder << 1) ^ polynomial;
2280 remainder = (remainder << 1);
2286 * The final remainder is the CRC result.
2291 int AliHLTComponent::ExtractComponentTableEntry(const AliHLTUInt8_t* pBuffer, AliHLTUInt32_t size,
2292 string& retChainId, string& retCompId, string& retCompArgs,
2293 vector<AliHLTUInt32_t>& parents)
2295 // see header file for function documentation
2298 retCompArgs.clear();
2300 if (!pBuffer || size==0) return 0;
2302 const AliHLTComponentTableEntry* pEntry=reinterpret_cast<const AliHLTComponentTableEntry*>(pBuffer);
2303 if (size<8/* the initial size of the structure*/ ||
2304 pEntry==NULL || pEntry->fStructSize<8) return -ENOMSG;
2305 const AliHLTUInt32_t* pParents=reinterpret_cast<const AliHLTUInt32_t*>(pEntry->fBuffer);
2306 const AliHLTUInt8_t* pEnd=pBuffer+size;
2308 if (pParents+pEntry->fNofParents>=reinterpret_cast<const AliHLTUInt32_t*>(pEnd)) return -ENODEV;
2309 for (unsigned int i=0; i<pEntry->fNofParents; i++, pParents++) {
2310 parents.push_back(*pParents);
2313 const char* pDescription=reinterpret_cast<const char*>(pParents);
2314 if (pDescription+pEntry->fSizeDescription>=reinterpret_cast<const char*>(pEnd) ||
2315 *(pDescription+pEntry->fSizeDescription)!=0) {
2319 TString descriptor=reinterpret_cast<const char*>(pDescription);
2323 TObjArray* pTokens=descriptor.Tokenize("{");
2326 if (pTokens->GetEntries()>n) {
2327 retChainId=((TObjString*)pTokens->At(n++))->GetString();
2329 if (pTokens->GetEntries()>n) {
2330 compId=((TObjString*)pTokens->At(n++))->GetString();
2334 if (!compId.IsNull() && (pTokens=compId.Tokenize(":"))!=NULL) {
2336 if (pTokens->GetEntries()>n) {
2337 compId=((TObjString*)pTokens->At(n++))->GetString();
2339 if (pTokens->GetEntries()>n) {
2340 compArgs=((TObjString*)pTokens->At(n++))->GetString();
2344 compId.ReplaceAll("}", "");
2345 compArgs.ReplaceAll("}", "");
2348 retCompArgs=compArgs;
2350 if (retChainId.size()==0) return -ENODATA;
2355 int AliHLTComponent::LoggingVarargs(AliHLTComponentLogSeverity severity,
2356 const char* originClass, const char* originFunc,
2357 const char* file, int line, ... ) const
2359 // see header file for function documentation
2363 va_start(args, line);
2365 // logging function needs to be const in order to be called from const member functions
2366 // without problems. But at this point we face the problem with virtual members which
2367 // are not necessarily const.
2368 AliHLTComponent* nonconst=const_cast<AliHLTComponent*>(this);
2369 AliHLTLogging::SetLogString("%s (%s, %p): ",
2370 fChainId[0]!=0?fChainId.c_str():nonconst->GetComponentID(),
2371 nonconst->GetComponentID(), this);
2372 iResult=SendMessage(severity, originClass, originFunc, file, line, AliHLTLogging::BuildLogString(NULL, args, true /*append*/));
2378 int AliHLTComponent::ScanECSParam(const char* ecsParam)
2380 // see header file for function documentation
2382 // format of the parameter string from ECS
2383 // <command>;<parameterkey>=<parametervalue>;<parameterkey>=<parametervalue>;...
2384 // search for a subset of the parameterkeys
2386 TString string=ecsParam;
2387 TObjArray* parameter=string.Tokenize(";");
2389 for (int i=0; i<parameter->GetEntries(); i++) {
2390 TString entry=((TObjString*)parameter->At(i))->GetString();
2391 HLTDebug("scanning ECS entry: %s", entry.Data());
2392 TObjArray* entryParams=entry.Tokenize("=");
2394 if (entryParams->GetEntries()>1) {
2395 if ((((TObjString*)entryParams->At(0))->GetString()).CompareTo("CTP_TRIGGER_CLASS")==0) {
2396 int result=InitCTPTriggerClasses((((TObjString*)entryParams->At(1))->GetString()).Data());
2397 if (iResult>=0 && result<0) iResult=result;
2399 // TODO: scan the other parameters
2400 // e.g. consistency check of run number
2412 int AliHLTComponent::SetupCTPData()
2414 // see header file for function documentation
2415 if (fpCTPData) delete fpCTPData;
2416 fpCTPData=new AliHLTCTPData;
2417 if (!fpCTPData) return -ENOMEM;
2421 int AliHLTComponent::InitCTPTriggerClasses(const char* ctpString)
2423 // see header file for function documentation
2424 if (!fpCTPData) return 0; // silently accept as the component has to announce that it want's the CTP info
2425 return fpCTPData->InitCTPTriggerClasses(ctpString);
2428 bool AliHLTComponent::EvaluateCTPTriggerClass(const char* expression, AliHLTComponentTriggerData& trigData) const
2430 // see header file for function documentation
2432 static bool bWarningThrown=false;
2433 if (!bWarningThrown) HLTError("Trigger classes not initialized, use SetupCTPData from DoInit()");
2434 bWarningThrown=true;
2438 return fpCTPData->EvaluateCTPTriggerClass(expression, trigData);