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. */
24 // @note The class is both used in Online (PubSub) and Offline (AliRoot)
28 //#include "AliHLTStdIncludes.h"
29 #include "AliHLTComponent.h"
30 #include "AliHLTComponentHandler.h"
31 #include "AliHLTMessage.h"
32 #include "AliHLTCTPData.h"
33 #include "AliHLTErrorGuard.h"
34 #include "AliHLTCDHWrapper.h"
37 #include "TObjArray.h"
38 #include "TObjectTable.h"
40 #include "TStopwatch.h"
45 #include "AliHLTMemoryFile.h"
46 #include "AliHLTMisc.h"
52 * default compression level for ROOT objects
54 #define ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION 5
55 #define ALIHLTCOMPONENT_STATTIME_SCALER 1000000
57 /** ROOT macro for the implementation of ROOT specific class methods */
58 ClassImp(AliHLTComponent);
60 /** stopwatch macro using the stopwatch guard */
61 #define ALIHLTCOMPONENT_STOPWATCH(type) AliHLTStopwatchGuard swguard(fpStopwatches!=NULL?reinterpret_cast<TStopwatch*>(fpStopwatches->At((int)type)):NULL)
62 //#define ALIHLTCOMPONENT_STOPWATCH(type)
64 /** stopwatch macro for operations of the base class */
65 #define ALIHLTCOMPONENT_BASE_STOPWATCH() ALIHLTCOMPONENT_STOPWATCH(kSWBase)
66 /** stopwatch macro for operations of the detector algorithm (DA) */
67 #define ALIHLTCOMPONENT_DA_STOPWATCH() ALIHLTCOMPONENT_STOPWATCH(kSWDA)
69 AliHLTComponent::AliHLTComponent()
77 fCurrentInputBlock(-1),
78 fSearchDataType(kAliHLTVoidDataType),
83 fOutputBufferFilled(0),
85 fpStopwatches(new TObjArray(kSWTypeCount)),
88 fCDBSetRunNoFunc(NULL),
93 fEventType(gkAliEventTypeUnknown),
96 fEventDoneDataSize(0),
97 fCompressionLevel(ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION)
101 , fLastPushBackTime(-1),
104 // see header file for class documentation
106 // refer to README to build package
108 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
109 memset(&fEnvironment, 0, sizeof(AliHLTAnalysisEnvironment));
110 if (fgpComponentHandler)
111 fgpComponentHandler->ScheduleRegister(this);
112 //SetLocalLoggingLevel(kHLTLogDefault);
115 AliHLTComponent::~AliHLTComponent()
117 // see header file for function documentation
118 if (fpBenchmark) delete fpBenchmark;
121 CleanupInputObjects();
122 if (fpStopwatches!=NULL) delete fpStopwatches;
124 AliHLTMemoryFilePList::iterator element=fMemFiles.begin();
125 while (element!=fMemFiles.end()) {
127 if ((*element)->IsClosed()==0) {
128 HLTWarning("memory file has not been closed, possible data loss or incomplete buffer");
129 // close but do not flush as we dont know whether the buffer is still valid
130 (*element)->CloseMemoryFile(0);
142 delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
151 AliHLTComponentHandler* AliHLTComponent::fgpComponentHandler=NULL;
153 int AliHLTComponent::SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite)
155 // see header file for function documentation
157 if (fgpComponentHandler==NULL || bOverwrite!=0)
158 fgpComponentHandler=pCH;
164 int AliHLTComponent::UnsetGlobalComponentHandler()
166 // see header file for function documentation
167 return SetGlobalComponentHandler(NULL,1);
170 int AliHLTComponent::SetComponentEnvironment(const AliHLTAnalysisEnvironment* comenv, void* environParam)
172 // see header file for function documentation
173 HLTLogKeyword(fChainId.c_str());
176 memset(&fEnvironment, 0, sizeof(AliHLTAnalysisEnvironment));
177 memcpy(&fEnvironment, comenv, comenv->fStructSize<sizeof(AliHLTAnalysisEnvironment)?comenv->fStructSize:sizeof(AliHLTAnalysisEnvironment));
178 fEnvironment.fStructSize=sizeof(AliHLTAnalysisEnvironment);
179 fEnvironment.fParam=environParam;
184 int AliHLTComponent::Init(const AliHLTAnalysisEnvironment* comenv, void* environParam, int argc, const char** argv )
186 // see header file for function documentation
187 HLTLogKeyword(fChainId.c_str());
190 SetComponentEnvironment(comenv, environParam);
193 fLastPushBackTime=-1;
196 const char** pArguments=NULL;
201 pArguments=new const char*[argc];
203 for (int i=0; i<argc && iResult>=0; i++) {
204 if (fComponentArgs.size()>0) fComponentArgs+=" ";
205 fComponentArgs+=argv[i];
207 if (argument.IsNull()) continue;
210 if (argument.CompareTo("-benchmark")==0) {
213 } else if (argument.BeginsWith("-loglevel=")) {
214 TString parameter=argument.ReplaceAll("-loglevel=", "");
215 parameter.Remove(TString::kLeading, ' '); // remove all blanks
216 if (parameter.BeginsWith("0x") &&
217 parameter.Replace(0,2,"",0).IsHex()) {
218 unsigned int loglevel=kHLTLogNone;
219 sscanf(parameter.Data(),"%x", &loglevel);
220 SetLocalLoggingLevel((AliHLTComponentLogSeverity)loglevel);
222 HLTError("wrong parameter for argument %s, hex number expected", argument.Data());
225 // -object-compression=
226 } else if (argument.BeginsWith("-object-compression=")) {
227 argument.ReplaceAll("-object-compression=", "");
228 if (argument.IsDigit()) {
229 fCompressionLevel=argument.Atoi();
230 if (fCompressionLevel<0 || fCompressionLevel>9) {
231 HLTWarning("invalid compression level %d, setting to default %d", fCompressionLevel, ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION);
232 fCompressionLevel=ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION;
235 HLTError("wrong parameter for argument -object-compression, number expected");
238 } else if (argument.BeginsWith("-pushback-period=")) {
239 argument.ReplaceAll("-pushback-period=", "");
240 if (argument.IsDigit()) {
241 fPushbackPeriod=argument.Atoi();
243 HLTError("wrong parameter for argument -pushback-period, number expected");
246 } else if (argument.BeginsWith("-event-modulo=")) {
247 argument.ReplaceAll("-event-modulo=", "");
248 if (argument.IsDigit()) {
249 fEventModulo=argument.Atoi();
250 if (fEventModulo < 1)
253 HLTError("number passed in -event-modulo must be a positive integer greater or equal to 1.");
256 HLTError("wrong parameter for argument -event-modulo, integer number expected");
258 // -disable-component-stat
259 } else if (argument.CompareTo("-disable-component-stat")==0) {
260 fFlags|=kDisableComponentStat;
262 pArguments[iNofChildArgs++]=argv[i];
270 HLTError("missing parameter for argument %s", argument.Data());
274 iResult=CheckOCDBEntries();
277 iResult=DoInit(iNofChildArgs, pArguments);
282 // find out if the component wants to get the steering events
284 AliHLTComponentDataTypeList inputDt;
285 GetInputDataTypes(inputDt);
286 bool bRequireSteeringBlocks=false;
287 for (AliHLTComponentDataTypeList::iterator dt=inputDt.begin();
288 dt!=inputDt.end() && !bRequireSteeringBlocks;
290 bRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeSOR);
291 bRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeRunType);
292 bRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeEOR);
293 bRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeDDL);
294 bRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeComponentStatistics);
296 if (bRequireSteeringBlocks) fFlags|=kRequireSteeringBlocks;
298 if (pArguments) delete [] pArguments;
300 #if defined(HLT_COMPONENT_STATISTICS)
301 // benchmarking stopwatch for the component statistics
302 fpBenchmark=new TStopwatch;
303 #endif // HLT_COMPONENT_STATISTICS
308 int AliHLTComponent::Deinit()
310 // see header file for function documentation
311 HLTLogKeyword(fChainId.c_str());
315 // TODO: the warning should be kept, but the condition is wrong since the
316 // AliHLTRunDesc is set before the SOR event in the SetRunDescription
317 // method. A couple of state flags should be defined but that is a bit more
318 // work to do. For the moment disable the warning (2009-07-01)
319 // 2009-09-08: now, the info is not cleared in the ProcessEvent, because it
320 // might be needed by components during the event processing.
321 //HLTWarning("did not receive EOR for run %d", fpRunDesc->fRunNo);
322 AliHLTRunDesc* pRunDesc=fpRunDesc;
336 int AliHLTComponent::InitCDB(const char* cdbPath, AliHLTComponentHandler* pHandler)
338 // see header file for function documentation
340 HLTInfo("Using CDB: %s", cdbPath);
342 // I have to think about separating the library handling from the
343 // component handler. Requiring the component handler here is not
344 // the cleanest solution.
345 // We presume the library already to be loaded, which is the case
346 // because it is loaded in the initialization of the logging functionality
349 AliHLTMiscInitCDB_t pFunc=(AliHLTMiscInitCDB_t)pHandler->FindSymbol(ALIHLTMISC_LIBRARY, ALIHLTMISC_INIT_CDB);
352 if (cdbPath && cdbPath[0]!=0) {
354 // very temporary fix, have to check for other formats
355 if (!path.BeginsWith("local://")) {
360 if ((iResult=(*pFunc)(path.Data()))>=0) {
361 if (!(fCDBSetRunNoFunc=pHandler->FindSymbol(ALIHLTMISC_LIBRARY, ALIHLTMISC_SET_CDB_RUNNO))) {
362 Message(NULL, kHLTLogWarning, "AliHLTComponent::InitCDB", "init CDB",
363 "can not find function to set CDB run no");
367 Message(NULL, kHLTLogError, "AliHLTComponent::InitCDB", "init CDB",
368 "can not find initialization function");
377 int AliHLTComponent::SetCDBRunNo(int runNo)
379 // see header file for function documentation
380 if (!fCDBSetRunNoFunc) return 0;
381 return (*((AliHLTMiscSetCDBRunNo_t)fCDBSetRunNoFunc))(runNo);
384 int AliHLTComponent::SetRunDescription(const AliHLTRunDesc* desc, const char* /*runType*/)
386 // see header file for function documentation
387 if (!desc) return -EINVAL;
388 if (desc->fStructSize!=sizeof(AliHLTRunDesc)) {
389 HLTError("invalid size of RunDesc struct (%ul)", desc->fStructSize);
394 fpRunDesc=new AliHLTRunDesc;
395 if (!fpRunDesc) return -ENOMEM;
396 *fpRunDesc=kAliHLTVoidRunDesc;
399 if (fpRunDesc->fRunNo!=kAliHLTVoidRunNo && fpRunDesc->fRunNo!=desc->fRunNo) {
400 HLTWarning("Run description has already been set");
403 SetCDBRunNo(fpRunDesc->fRunNo);
404 // TODO: we have to decide about the runType
408 int AliHLTComponent::SetComponentDescription(const char* desc)
410 // see header file for function documentation
414 TString descriptor=desc;
415 TObjArray* pTokens=descriptor.Tokenize(" ");
417 for (int i=0; i<pTokens->GetEntriesFast() && iResult>=0; i++) {
418 TString argument=pTokens->At(i++)->GetName();
419 if (!argument || argument.IsNull()) continue;
422 if (argument.BeginsWith("chainid")) {
423 argument.ReplaceAll("chainid", "");
424 if (argument.BeginsWith("=")) {
425 fChainId=argument.Replace(0,1,"");
426 fChainIdCrc=CalculateChecksum((const AliHLTUInt8_t*)fChainId.c_str(), fChainId.length());
427 HLTDebug("setting component description: chain id %s crc 0x%8x", fChainId.c_str(), fChainIdCrc);
432 HLTWarning("unknown component description %s", argument.Data());
441 int AliHLTComponent::ConfigureFromArgumentString(int argc, const char** argv)
443 // Configure from an array of argument strings
444 // Function supports individual arguments in the argv array and arguments
445 // separated by blanks.
447 // Each argv entry can contain blanks, quotes and newlines. Newlines are interpreted
448 // as blanks. Enclosing quotes deactivate blank as delimiter.
449 // The separated arguments are stored in an array of strings, and the pointers to
450 // those strings in an array of pointers. The latter is used in the custom argument
451 // scan of the component.
454 vector<string> stringarray; // array of argument copies
455 // array of pointers to the argument copies
456 // note: not necessarily in sync with the entries in stringarray
457 // can contain any pointer to valid arguments in arbitrary sequence
458 vector<const char*> ptrarray;
462 for (i=0; i<argc && iResult>=0; i++) {
464 if (argument.IsWhitespace()) continue;
466 // special handling for single component arguments ending with
467 // a sequence of blanks. All characters until the first occurence
468 // of a blank are removed. If the remainder contains only whitespaces
469 // the argument is a single argument, just having whitespaces at the end.
470 argument.Remove(0, argument.First(' '));
471 if (argument.IsWhitespace()) {
472 stringarray.push_back(argv[i]);
476 // outer loop checks for enclosing quotes
477 // extra blank to insert blank token before leading quotes, then
478 // quoted arguments are always the even ones
481 // insert blank in consecutive quotes to correctly tokenize
482 argument.ReplaceAll("''", "' '");
483 // replace newlines by blanks
484 argument.ReplaceAll("\n", " ");
485 if (argument.IsNull()) continue;
486 TObjArray* pTokensQuote=argument.Tokenize("'");
488 if (pTokensQuote->GetEntriesFast()>0) {
489 for (int k=0; k<pTokensQuote->GetEntriesFast(); k++) {
490 argument=pTokensQuote->At(k)->GetName();
491 if (argument.IsWhitespace()) continue;
493 // every second entry is enclosed by quotes and thus
494 // one single argument
495 stringarray.push_back(argument.Data());
497 TObjArray* pTokens=argument.Tokenize(" ");
499 if (pTokens->GetEntriesFast()>0) {
500 for (int n=0; n<pTokens->GetEntriesFast(); n++) {
501 TString data=pTokens->At(n)->GetName();
502 if (!data.IsNull() && !data.IsWhitespace()) {
503 stringarray.push_back(data.Data());
516 // fill ptrarray; should be safe at this point
517 // since stringarray isn't modified any further
519 for(idx=0; idx<stringarray.size(); ++idx) {
520 ptrarray.push_back(stringarray.at(idx).c_str());
523 for (i=0; (unsigned)i<ptrarray.size() && iResult>=0;) {
524 int result=ScanConfigurationArgument(ptrarray.size()-i, &ptrarray[i]);
526 HLTWarning("unknown component argument %s", ptrarray[i]);
528 } else if (result>0) {
532 if (iResult==-EINVAL) {
533 HLTError("unknown argument %s", ptrarray[i]);
534 } else if (iResult==-EPROTO) {
535 HLTError("missing/wrong parameter for argument %s (%s)", ptrarray[i], (ptrarray.size()>(unsigned)i+1)?ptrarray[i+1]:"missing");
537 HLTError("scan of argument %s failed (%d)", ptrarray[i], iResult);
545 int AliHLTComponent::ConfigureFromCDBTObjString(const char* entries, const char* key)
547 // load a list of OCDB objects and configure from the objects
548 // can either be a TObjString or a TMap with a TObjString:TObjString key-value pair
551 TString confEntries=entries;
552 TObjArray* pTokens=confEntries.Tokenize(" ");
554 for (int n=0; n<pTokens->GetEntriesFast(); n++) {
555 const char* path=pTokens->At(n)->GetName();
556 const char* chainId=GetChainId();
557 HLTInfo("configure from entry \"%s\"%s%s, chain id %s", path, key?" key ":"",key?key:"", (chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
558 TObject* pOCDBObject = LoadAndExtractOCDBObject(path, key);
560 TObjString* pString=dynamic_cast<TObjString*>(pOCDBObject);
562 TMap* pMap=dynamic_cast<TMap*>(pOCDBObject);
564 // this is the case where no key has been specified and the OCDB
565 // object is a TMap, search for the default key
566 TObject* pObject=pMap->GetValue("default");
567 if (pObject && (pString=dynamic_cast<TObjString*>(pObject))!=NULL) {
568 HLTInfo("using default key of TMap of configuration object \"%s\"", path);
570 HLTError("no default key available in TMap of configuration object \"%s\"", path);
578 HLTInfo("received configuration object string: \'%s\'", pString->GetName());
579 arguments+=pString->GetName();
582 HLTError("configuration object \"%s\"%s%s has wrong type, required TObjString", path, key?" key ":"",key?key:"");
586 HLTError("can not fetch object \"%s\" from OCDB", path);
592 if (iResult>=0 && !arguments.IsNull()) {
593 const char* array=arguments.Data();
594 iResult=ConfigureFromArgumentString(1, &array);
599 TObject* AliHLTComponent::LoadAndExtractOCDBObject(const char* path, const char* key) const
601 // see header file for function documentation
602 AliCDBEntry* pEntry=AliHLTMisc::Instance().LoadOCDBEntry(path, GetRunNo());
603 if (!pEntry) return NULL;
604 TObject* pObject=AliHLTMisc::Instance().ExtractObject(pEntry);
605 TMap* pMap=dynamic_cast<TMap*>(pObject);
607 pObject=pMap->GetValue(key);
609 pObject=pMap->GetValue("default");
611 HLTWarning("can not find object for key \"%s\" in TMap of configuration object \"%s\", using key \"default\"", key, path);
615 HLTError("can not find object for key \"%s\" in TMap of configuration object \"%s\"", key, path);
622 int AliHLTComponent::DoInit( int /*argc*/, const char** /*argv*/)
624 // default implementation, childs can overload
625 HLTLogKeyword("dummy");
629 int AliHLTComponent::DoDeinit()
631 // default implementation, childs can overload
632 HLTLogKeyword("dummy");
636 int AliHLTComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/)
638 // default implementation, childs can overload
639 HLTLogKeyword("dummy");
643 int AliHLTComponent::ReadPreprocessorValues(const char* /*modules*/)
645 // default implementation, childs can overload
646 HLTLogKeyword("dummy");
650 int AliHLTComponent::ScanConfigurationArgument(int /*argc*/, const char** /*argv*/)
652 // default implementation, childs can overload
653 HLTLogKeyword("dummy");
654 HLTWarning("The function needs to be implemented by the component");
658 int AliHLTComponent::StartOfRun()
660 // default implementation, childs can overload
661 HLTLogKeyword("dummy");
665 int AliHLTComponent::EndOfRun()
667 // default implementation, childs can overload
668 HLTLogKeyword("dummy");
673 int AliHLTComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& /*tgtList*/)
675 // default implementation, childs can overload
676 HLTLogKeyword("dummy");
680 void AliHLTComponent::GetOCDBObjectDescription( TMap* const /*targetArray*/)
682 // default implementation, childs can overload
683 HLTLogKeyword("dummy");
686 int AliHLTComponent::CheckOCDBEntries(const TMap* const externList)
688 // check the availability of the OCDB entry descriptions in the TMap
689 // key : complete OCDB path of the entry
690 // value : auxiliary object - short description
691 // if the external map was not provided the function invokes
692 // interface function GetOCDBObjectDescription() to retrieve the list.
695 iResult=AliHLTMisc::Instance().CheckOCDBEntries(externList);
699 pMap->SetOwnerKeyValue(kTRUE);
700 GetOCDBObjectDescription(pMap);
701 iResult=AliHLTMisc::Instance().CheckOCDBEntries(pMap);
710 void AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2] ) const
712 // see header file for function documentation
713 memset( output, 0, kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2 );
714 strncat( output, type.fOrigin, kAliHLTComponentDataTypefOriginSize );
715 strncat( output, ":", 1 );
716 strncat( output, type.fID, kAliHLTComponentDataTypefIDsize );
719 string AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, int mode)
721 // see header file for function documentation
725 // aligned to 8 and 4 chars respectively, blocks enclosed in quotes and
726 // separated by blank e.g.
732 for (i=0; i<kAliHLTComponentDataTypefIDsize; i++) {
733 unsigned char* puc=(unsigned char*)type.fID;
735 sprintf(tmp, "\\%x", type.fID[i]);
737 sprintf(tmp, "%c", type.fID[i]);
741 for (i=0; i<kAliHLTComponentDataTypefOriginSize; i++) {
742 unsigned char* puc=(unsigned char*)type.fOrigin;
744 sprintf(tmp, "\\%x", type.fOrigin[i]);
746 sprintf(tmp, "%c", type.fOrigin[i]);
753 // origin typeid as numbers separated by colon e.g.
754 // aligned to 8 and 4 chars respectively, all characters separated by
756 // '84'80'67'32':'68'68'76'95'82'65'87'32'
760 for (i=0; i<kAliHLTComponentDataTypefOriginSize; i++) {
761 sprintf(tmp, "'%d", type.fOrigin[i]);
765 for (i=0; i<kAliHLTComponentDataTypefIDsize; i++) {
766 sprintf(tmp, "%d'", type.fID[i]);
772 // origin typeid separated by colon e.g.
773 // aligned to 8 and 4 chars respectively, all characters separated by
775 // 'T'P'C' ':'D'D'L'_'R'A'W' '
779 for (i=0; i<kAliHLTComponentDataTypefOriginSize; i++) {
780 unsigned char* puc=(unsigned char*)type.fOrigin;
782 sprintf(tmp, "'\\%x", type.fOrigin[i]);
784 sprintf(tmp, "'%c", type.fOrigin[i]);
788 for (i=0; i<kAliHLTComponentDataTypefIDsize; i++) {
789 unsigned char* puc=(unsigned char*)type.fID;
791 sprintf(tmp, "\\%x'", type.fID[i]);
793 sprintf(tmp, "%c'", type.fID[i]);
800 // aligned to 8 and 4 chars respectively, separated by colon e.g.
802 if (type==kAliHLTVoidDataType) {
805 // some gymnastics in order to avoid a '0' which is part of either or both
806 // ID and origin terminating the whole string. Unfortunately, string doesn't
807 // stop appending at the '0' if the number of elements to append was
808 // explicitely specified
810 tmp.append(type.fOrigin, kAliHLTComponentDataTypefOriginSize);
811 out.append(tmp.c_str());
814 tmp.append(type.fID, kAliHLTComponentDataTypefIDsize);
815 out.append(tmp.c_str());
821 void* AliHLTComponent::AllocMemory( unsigned long size )
823 // see header file for function documentation
824 if (fEnvironment.fAllocMemoryFunc)
825 return (*fEnvironment.fAllocMemoryFunc)(fEnvironment.fParam, size );
826 HLTFatal("no memory allocation handler registered");
830 int AliHLTComponent::MakeOutputDataBlockList( const AliHLTComponentBlockDataList& blocks, AliHLTUInt32_t* blockCount,
831 AliHLTComponentBlockData** outputBlocks )
833 // see header file for function documentation
834 if ( blockCount==NULL || outputBlocks==NULL )
836 AliHLTUInt32_t count = blocks.size();
840 *outputBlocks = NULL;
843 *outputBlocks = reinterpret_cast<AliHLTComponentBlockData*>( AllocMemory( sizeof(AliHLTComponentBlockData)*count ) );
844 if ( !*outputBlocks )
846 for ( unsigned long i = 0; i < count; i++ ) {
847 (*outputBlocks)[i] = blocks[i];
848 if (MatchExactly(blocks[i].fDataType, kAliHLTAnyDataType)) {
849 (*outputBlocks)[i].fDataType=GetOutputDataType();
850 /* data type was set to the output data type by the PubSub AliRoot
851 Wrapper component, if data type of the block was ********:****.
852 Now handled by the component base class in order to have same
853 behavior when running embedded in AliRoot
854 memset((*outputBlocks)[i].fDataType.fID, '*', kAliHLTComponentDataTypefIDsize);
855 memset((*outputBlocks)[i].fDataType.fOrigin, '*', kAliHLTComponentDataTypefOriginSize);
864 int AliHLTComponent::GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd ) const
866 // see header file for function documentation
867 if (fEnvironment.fGetEventDoneDataFunc)
868 return (*fEnvironment.fGetEventDoneDataFunc)(fEnvironment.fParam, fCurrentEvent, size, edd );
872 int AliHLTComponent::ReserveEventDoneData( unsigned long size )
874 // see header file for function documentation
877 unsigned long capacity=fEventDoneDataSize;
878 if (fEventDoneData) capacity-=sizeof(AliHLTComponentEventDoneData)+fEventDoneData->fDataSize;
880 unsigned long newSize=sizeof(AliHLTComponentEventDoneData)+size+(fEventDoneDataSize-capacity);
881 AliHLTComponentEventDoneData* newEDD = reinterpret_cast<AliHLTComponentEventDoneData*>( new AliHLTUInt8_t[newSize] );
884 newEDD->fStructSize = sizeof(AliHLTComponentEventDoneData);
885 newEDD->fDataSize = 0;
886 newEDD->fData = reinterpret_cast<AliHLTUInt8_t*>(newEDD)+newEDD->fStructSize;
887 if (fEventDoneData) {
888 memcpy( newEDD->fData, fEventDoneData->fData, fEventDoneData->fDataSize );
889 newEDD->fDataSize = fEventDoneData->fDataSize;
890 delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
892 fEventDoneData = newEDD;
893 fEventDoneDataSize = newSize;
899 int AliHLTComponent::PushEventDoneData( AliHLTUInt32_t eddDataWord )
901 // see header file for function documentation
904 if (fEventDoneData->fDataSize+sizeof(AliHLTUInt32_t)>fEventDoneDataSize)
906 *reinterpret_cast<AliHLTUInt32_t*>((reinterpret_cast<AliHLTUInt8_t*>(fEventDoneData->fData)+fEventDoneData->fDataSize)) = eddDataWord;
907 fEventDoneData->fDataSize += sizeof(AliHLTUInt32_t);
911 void AliHLTComponent::ReleaseEventDoneData()
913 // see header file for function documentation
915 delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
916 fEventDoneData = NULL;
917 fEventDoneDataSize = 0;
921 int AliHLTComponent::FindMatchingDataTypes(AliHLTComponent* pConsumer, AliHLTComponentDataTypeList* tgtList)
923 // see header file for function documentation
926 AliHLTComponentDataTypeList itypes;
927 AliHLTComponentDataTypeList otypes;
928 otypes.push_back(GetOutputDataType());
929 if (MatchExactly(otypes[0],kAliHLTMultipleDataType)) {
932 if ((count=GetOutputDataTypes(otypes))>0) {
933 } else if (GetComponentType()!=kSink) {
934 HLTWarning("component %s indicates multiple output data types but GetOutputDataTypes returns %d", GetComponentID(), count);
937 pConsumer->GetInputDataTypes(itypes);
938 AliHLTComponentDataTypeList::iterator otype=otypes.begin();
939 for (;otype!=otypes.end();otype++) {
940 //PrintDataTypeContent((*otype), "publisher \'%s\'");
941 if ((*otype)==(kAliHLTAnyDataType|kAliHLTDataOriginPrivate)) {
942 if (tgtList) tgtList->push_back(*otype);
947 AliHLTComponentDataTypeList::iterator itype=itypes.begin();
948 for ( ; itype!=itypes.end() && (*itype)!=(*otype) ; itype++) {/* empty body */};
949 //if (itype!=itypes.end()) PrintDataTypeContent(*itype, "consumer \'%s\'");
950 if (itype!=itypes.end()) {
951 if (tgtList) tgtList->push_back(*otype);
961 void AliHLTComponent::PrintDataTypeContent(AliHLTComponentDataType& dt, const char* format)
963 // see header file for function documentation
964 const char* fmt="\'%s\'";
965 if (format) fmt=format;
966 AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, Form(fmt, (DataType2Text(dt)).c_str()));
967 AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL,
968 Form("%x %x %x %x %x %x %x %x : %x %x %x %x",
983 void AliHLTComponent::FillBlockData( AliHLTComponentBlockData& blockData )
985 // see header file for function documentation
986 blockData.fStructSize = sizeof(blockData);
987 FillShmData( blockData.fShmKey );
988 blockData.fOffset = ~(AliHLTUInt32_t)0;
989 blockData.fPtr = NULL;
991 FillDataType( blockData.fDataType );
992 blockData.fSpecification = kAliHLTVoidDataSpec;
995 void AliHLTComponent::FillShmData( AliHLTComponentShmData& shmData )
997 // see header file for function documentation
998 shmData.fStructSize = sizeof(shmData);
999 shmData.fShmType = gkAliHLTComponentInvalidShmType;
1000 shmData.fShmID = gkAliHLTComponentInvalidShmID;
1003 void AliHLTComponent::FillDataType( AliHLTComponentDataType& dataType )
1005 // see header file for function documentation
1006 dataType=kAliHLTAnyDataType;
1009 void AliHLTComponent::CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt)
1011 // see header file for function documentation
1012 memcpy(&tgtdt.fID[0], &srcdt.fID[0], kAliHLTComponentDataTypefIDsize);
1013 memcpy(&tgtdt.fOrigin[0], &srcdt.fOrigin[0], kAliHLTComponentDataTypefOriginSize);
1016 void AliHLTComponent::SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin)
1018 // see header file for function documentation
1019 tgtdt.fStructSize=sizeof(AliHLTComponentDataType);
1021 memset(&tgtdt.fID[0], 0, kAliHLTComponentDataTypefIDsize);
1022 strncpy(&tgtdt.fID[0], id, strlen(id)<(size_t)kAliHLTComponentDataTypefIDsize?strlen(id):kAliHLTComponentDataTypefIDsize);
1025 memset(&tgtdt.fOrigin[0], 0, kAliHLTComponentDataTypefOriginSize);
1026 strncpy(&tgtdt.fOrigin[0], origin, strlen(origin)<(size_t)kAliHLTComponentDataTypefOriginSize?strlen(origin):kAliHLTComponentDataTypefOriginSize);
1030 void AliHLTComponent::SetDataType(AliHLTComponentDataType& dt, AliHLTUInt64_t id, AliHLTUInt32_t origin)
1032 // see header file for function documentation
1033 dt.fStructSize=sizeof(AliHLTComponentDataType);
1034 assert(kAliHLTComponentDataTypefIDsize==sizeof(id));
1035 assert(kAliHLTComponentDataTypefOriginSize==sizeof(origin));
1036 memcpy(&dt.fID, &id, kAliHLTComponentDataTypefIDsize);
1037 memcpy(&dt.fOrigin, &origin, kAliHLTComponentDataTypefOriginSize);
1040 void AliHLTComponent::FillEventData(AliHLTComponentEventData& evtData)
1042 // see header file for function documentation
1043 memset(&evtData, 0, sizeof(AliHLTComponentEventData));
1044 evtData.fStructSize=sizeof(AliHLTComponentEventData);
1045 evtData.fEventID=kAliHLTVoidEventID;
1046 evtData.fEventCreation_s = kMaxUInt;
1049 void AliHLTComponent::PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt)
1051 // see header file for function documentation
1053 msg.Form("AliHLTComponentDataType(%d): ID=\"", dt.fStructSize);
1054 for ( int i = 0; i < kAliHLTComponentDataTypefIDsize; i++ ) {
1055 if (dt.fID[i]!=0) msg+=dt.fID[i];
1058 msg+="\" Origin=\"";
1059 for ( int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++ ) {
1060 if (dt.fOrigin[i]!=0) msg+=dt.fOrigin[i];
1064 AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, msg.Data());
1067 int AliHLTComponent::GetEventCount() const
1069 // see header file for function documentation
1073 int AliHLTComponent::IncrementEventCounter()
1075 // see header file for function documentation
1076 if (fEventCount>=0) fEventCount++;
1080 int AliHLTComponent::GetNumberOfInputBlocks() const
1082 // see header file for function documentation
1083 if (fpInputBlocks!=NULL) {
1084 return fCurrentEventData.fBlockCnt;
1089 AliHLTEventID_t AliHLTComponent::GetEventId() const
1091 // see header file for function documentation
1092 if (fpInputBlocks!=NULL) {
1093 return fCurrentEventData.fEventID;
1098 const TObject* AliHLTComponent::GetFirstInputObject(const AliHLTComponentDataType& dt,
1099 const char* classname,
1102 // see header file for function documentation
1103 ALIHLTCOMPONENT_BASE_STOPWATCH();
1105 if (classname) fClassName=classname;
1106 else fClassName.clear();
1107 int idx=FindInputBlock(fSearchDataType, 0, 1);
1110 HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(dt).c_str());
1111 if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) {
1112 fCurrentInputBlock=idx;
1119 const TObject* AliHLTComponent::GetFirstInputObject(const char* dtID,
1120 const char* dtOrigin,
1121 const char* classname,
1124 // see header file for function documentation
1125 ALIHLTCOMPONENT_BASE_STOPWATCH();
1126 AliHLTComponentDataType dt;
1127 SetDataType(dt, dtID, dtOrigin);
1128 return GetFirstInputObject(dt, classname, bForce);
1131 const TObject* AliHLTComponent::GetNextInputObject(int bForce)
1133 // see header file for function documentation
1134 ALIHLTCOMPONENT_BASE_STOPWATCH();
1135 int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1, 1);
1136 //HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(fSearchDataType).c_str());
1139 if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) {
1140 fCurrentInputBlock=idx;
1146 int AliHLTComponent::FindInputBlock(const AliHLTComponentDataType& dt, int startIdx, int bObject) const
1148 // see header file for function documentation
1149 int iResult=-ENOENT;
1150 if (fpInputBlocks!=NULL) {
1151 int idx=startIdx<0?0:startIdx;
1152 for ( ; (UInt_t)idx<fCurrentEventData.fBlockCnt && iResult==-ENOENT; idx++) {
1153 if (dt!=fpInputBlocks[idx].fDataType) continue;
1156 if (fpInputBlocks[idx].fPtr==NULL) continue;
1157 AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr);
1158 if (firstWord!=fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) continue;
1166 TObject* AliHLTComponent::CreateInputObject(int idx, int bForce)
1168 // see header file for function documentation
1170 if (fpInputBlocks!=NULL) {
1171 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
1172 if (fpInputBlocks[idx].fPtr) {
1173 AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr);
1174 if (firstWord==fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) {
1175 HLTDebug("create object from block %d size %d", idx, fpInputBlocks[idx].fSize);
1176 AliHLTMessage msg(fpInputBlocks[idx].fPtr, fpInputBlocks[idx].fSize);
1177 TClass* objclass=msg.GetClass();
1178 pObj=msg.ReadObject(objclass);
1179 if (pObj && objclass) {
1180 HLTDebug("object %p type %s created", pObj, objclass->GetName());
1184 } else if (bForce!=0) {
1185 HLTError("size mismatch: block size %d, indicated %d", fpInputBlocks[idx].fSize, firstWord+sizeof(AliHLTUInt32_t));
1188 HLTFatal("block descriptor empty");
1191 HLTError("index %d out of range %d", idx, fCurrentEventData.fBlockCnt);
1194 HLTError("no input blocks available");
1200 TObject* AliHLTComponent::GetInputObject(int idx, const char* /*classname*/, int bForce)
1202 // see header file for function documentation
1203 if (fpInputObjects==NULL) {
1204 fpInputObjects=new TObjArray(fCurrentEventData.fBlockCnt);
1207 if (fpInputObjects) {
1208 pObj=fpInputObjects->At(idx);
1210 pObj=CreateInputObject(idx, bForce);
1212 fpInputObjects->AddAt(pObj, idx);
1216 HLTFatal("memory allocation failed: TObjArray of size %d", fCurrentEventData.fBlockCnt);
1221 int AliHLTComponent::CleanupInputObjects()
1223 // see header file for function documentation
1224 if (!fpInputObjects) return 0;
1225 TObjArray* array=fpInputObjects;
1226 fpInputObjects=NULL;
1227 for (int i=0; i<array->GetEntriesFast(); i++) {
1228 TObject* pObj=array->At(i);
1229 // grrr, garbage collection strikes back: When read via AliHLTMessage
1230 // (CreateInputObject), and written to a TFile afterwards, the
1231 // TFile::Close calls ROOOT's garbage collection. No clue why the
1232 // object ended up in the key list and needs to be deleted
1234 // Matthias 09.11.2008 follow up
1235 // This approach doesn't actually work in all cases: the object table
1236 // can be switched off globally, the flag needs to be checked here as
1237 // well in order to avoid memory leaks.
1238 // This means we have to find another solution for the problem if it
1241 (!TObject::GetObjectStat() || gObjectTable->PtrIsValid(pObj))) {
1249 AliHLTComponentDataType AliHLTComponent::GetDataType(const TObject* pObject)
1251 // see header file for function documentation
1252 ALIHLTCOMPONENT_BASE_STOPWATCH();
1253 AliHLTComponentDataType dt=kAliHLTVoidDataType;
1254 int idx=fCurrentInputBlock;
1256 if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
1258 HLTError("unknown object %p", pObject);
1262 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
1263 dt=fpInputBlocks[idx].fDataType;
1265 HLTFatal("severe internal error, index out of range");
1271 AliHLTUInt32_t AliHLTComponent::GetSpecification(const TObject* pObject)
1273 // see header file for function documentation
1274 ALIHLTCOMPONENT_BASE_STOPWATCH();
1275 AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec;
1276 int idx=fCurrentInputBlock;
1278 if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
1280 HLTError("unknown object %p", pObject);
1284 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
1285 iSpec=fpInputBlocks[idx].fSpecification;
1287 HLTFatal("severe internal error, index out of range");
1293 int AliHLTComponent::Forward(const TObject* pObject)
1295 // see header file for function documentation
1297 int idx=fCurrentInputBlock;
1299 if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
1301 HLTError("unknown object %p", pObject);
1306 fOutputBlocks.push_back(fpInputBlocks[idx]);
1311 int AliHLTComponent::Forward(const AliHLTComponentBlockData* pBlock)
1313 // see header file for function documentation
1315 int idx=fCurrentInputBlock;
1317 if ((idx=FindInputBlock(pBlock))>=0) {
1319 HLTError("unknown Block %p", pBlock);
1324 // check for fpInputBlocks pointer done in FindInputBlock
1325 fOutputBlocks.push_back(fpInputBlocks[idx]);
1330 const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const AliHLTComponentDataType& dt)
1332 // see header file for function documentation
1333 ALIHLTCOMPONENT_BASE_STOPWATCH();
1336 int idx=FindInputBlock(fSearchDataType, 0);
1337 const AliHLTComponentBlockData* pBlock=NULL;
1339 // check for fpInputBlocks pointer done in FindInputBlock
1340 pBlock=&fpInputBlocks[idx];
1341 fCurrentInputBlock=idx;
1346 const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const char* dtID,
1347 const char* dtOrigin)
1349 // see header file for function documentation
1350 ALIHLTCOMPONENT_BASE_STOPWATCH();
1351 AliHLTComponentDataType dt;
1352 SetDataType(dt, dtID, dtOrigin);
1353 return GetFirstInputBlock(dt);
1356 const AliHLTComponentBlockData* AliHLTComponent::GetInputBlock(int index) const
1358 // see header file for function documentation
1359 ALIHLTCOMPONENT_BASE_STOPWATCH();
1360 assert( 0 <= index and index < (int)fCurrentEventData.fBlockCnt );
1361 return &fpInputBlocks[index];
1364 const AliHLTComponentBlockData* AliHLTComponent::GetNextInputBlock()
1366 // see header file for function documentation
1367 ALIHLTCOMPONENT_BASE_STOPWATCH();
1368 int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1);
1369 const AliHLTComponentBlockData* pBlock=NULL;
1371 // check for fpInputBlocks pointer done in FindInputBlock
1372 pBlock=&fpInputBlocks[idx];
1373 fCurrentInputBlock=idx;
1378 int AliHLTComponent::FindInputBlock(const AliHLTComponentBlockData* pBlock) const
1380 // see header file for function documentation
1381 int iResult=-ENOENT;
1382 if (fpInputBlocks!=NULL) {
1384 if (pBlock>=fpInputBlocks && pBlock<fpInputBlocks+fCurrentEventData.fBlockCnt) {
1385 iResult=(int)(pBlock-fpInputBlocks);
1394 AliHLTUInt32_t AliHLTComponent::GetSpecification(const AliHLTComponentBlockData* pBlock)
1396 // see header file for function documentation
1397 ALIHLTCOMPONENT_BASE_STOPWATCH();
1398 AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec;
1399 int idx=fCurrentInputBlock;
1401 if (fpInputObjects==NULL || (idx=FindInputBlock(pBlock))>=0) {
1403 HLTError("unknown Block %p", pBlock);
1407 // check for fpInputBlocks pointer done in FindInputBlock
1408 iSpec=fpInputBlocks[idx].fSpecification;
1413 int AliHLTComponent::PushBack(const TObject* pObject, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
1414 void* pHeader, int headerSize)
1416 // see header file for function documentation
1417 ALIHLTCOMPONENT_BASE_STOPWATCH();
1420 if (fPushbackPeriod>0) {
1421 // suppress the output
1423 if (fLastPushBackTime<0 || (int)time.Get()-fLastPushBackTime<fPushbackPeriod) return 0;
1426 AliHLTMessage msg(kMESS_OBJECT);
1427 msg.SetCompressionLevel(fCompressionLevel);
1428 msg.WriteObject(pObject);
1429 Int_t iMsgLength=msg.Length();
1431 // Matthias Sep 2008
1432 // NOTE: AliHLTMessage does implement it's own SetLength method
1433 // which is not architecture independent. The original SetLength
1434 // stores the size always in network byte order.
1435 // I'm trying to remember the rational for that, might be that
1436 // it was just some lack of knowledge. Want to change this, but
1437 // has to be done carefullt to be backward compatible.
1438 msg.SetLength(); // sets the length to the first (reserved) word
1440 // does nothing if the level is 0
1443 char *mbuf = msg.Buffer();
1444 if (msg.CompBuffer()) {
1445 msg.SetLength(); // set once more to have to byte order
1446 mbuf = msg.CompBuffer();
1447 iMsgLength = msg.CompLength();
1450 iResult=InsertOutputBlock(mbuf, iMsgLength, dt, spec, pHeader, headerSize);
1452 HLTDebug("object %s (%p) size %d compression %d inserted to output", pObject->ClassName(), pObject, iMsgLength, msg.GetCompressionLevel());
1454 fLastObjectSize=iMsgLength;
1456 HLTError("object serialization failed for object %p", pObject);
1465 int AliHLTComponent::PushBack(const TObject* pObject, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec,
1466 void* pHeader, int headerSize)
1468 // see header file for function documentation
1469 ALIHLTCOMPONENT_BASE_STOPWATCH();
1470 AliHLTComponentDataType dt;
1471 SetDataType(dt, dtID, dtOrigin);
1472 return PushBack(pObject, dt, spec, pHeader, headerSize);
1475 int AliHLTComponent::PushBack(const void* pBuffer, int iSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
1476 const void* pHeader, int headerSize)
1478 // see header file for function documentation
1479 ALIHLTCOMPONENT_BASE_STOPWATCH();
1480 if (fPushbackPeriod>0) {
1481 // suppress the output
1483 if (fLastPushBackTime<0 || (int)time.Get()-fLastPushBackTime<fPushbackPeriod) return 0;
1486 return InsertOutputBlock(pBuffer, iSize, dt, spec, pHeader, headerSize);
1489 int AliHLTComponent::PushBack(const void* pBuffer, int iSize, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec,
1490 const void* pHeader, int headerSize)
1492 // see header file for function documentation
1493 ALIHLTCOMPONENT_BASE_STOPWATCH();
1494 AliHLTComponentDataType dt;
1495 SetDataType(dt, dtID, dtOrigin);
1496 return PushBack(pBuffer, iSize, dt, spec, pHeader, headerSize);
1499 int AliHLTComponent::InsertOutputBlock(const void* pBuffer, int iBufferSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
1500 const void* pHeader, int iHeaderSize)
1502 // see header file for function documentation
1504 int iBlkSize = iBufferSize + iHeaderSize;
1506 if ((pBuffer!=NULL && iBufferSize>0) || (pHeader!=NULL && iHeaderSize>0)) {
1507 if (fpOutputBuffer && iBlkSize<=(int)(fOutputBufferSize-fOutputBufferFilled)) {
1508 AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled;
1510 // copy header if provided but skip if the header is the target location
1511 // in that case it has already been copied
1512 if (pHeader!=NULL && pHeader!=pTgt) {
1513 memcpy(pTgt, pHeader, iHeaderSize);
1516 pTgt += (AliHLTUInt8_t) iHeaderSize;
1518 // copy buffer if provided but skip if buffer is the target location
1519 // in that case it has already been copied
1520 if (pBuffer!=NULL && pBuffer!=pTgt) {
1521 memcpy(pTgt, pBuffer, iBufferSize);
1523 //AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)pBuffer);
1524 //HLTDebug("copy %d bytes from %p to output buffer %p, first word %#x", iBufferSize, pBuffer, pTgt, firstWord);
1526 //HLTDebug("buffer inserted to output: size %d data type %s spec %#x", iBlkSize, DataType2Text(dt).c_str(), spec);
1528 if (fpOutputBuffer) {
1529 HLTError("too little space in output buffer: %d of %d, required %d", fOutputBufferSize-fOutputBufferFilled, fOutputBufferSize, iBlkSize);
1531 HLTError("output buffer not available");
1537 AliHLTComponentBlockData bd;
1538 FillBlockData( bd );
1539 bd.fOffset = fOutputBufferFilled;
1540 bd.fSize = iBlkSize;
1542 bd.fSpecification = spec;
1543 fOutputBlocks.push_back( bd );
1544 fOutputBufferFilled+=bd.fSize;
1550 int AliHLTComponent::EstimateObjectSize(const TObject* pObject) const
1552 // see header file for function documentation
1553 if (!pObject) return 0;
1555 AliHLTMessage msg(kMESS_OBJECT);
1556 msg.WriteObject(pObject);
1557 return msg.Length();
1560 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(int capacity, const char* dtID,
1561 const char* dtOrigin,
1562 AliHLTUInt32_t spec)
1564 // see header file for function documentation
1565 ALIHLTCOMPONENT_BASE_STOPWATCH();
1566 AliHLTComponentDataType dt;
1567 SetDataType(dt, dtID, dtOrigin);
1568 return CreateMemoryFile(capacity, dt, spec);
1571 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(int capacity,
1572 const AliHLTComponentDataType& dt,
1573 AliHLTUInt32_t spec)
1575 // see header file for function documentation
1576 ALIHLTCOMPONENT_BASE_STOPWATCH();
1577 AliHLTMemoryFile* pFile=NULL;
1578 if (capacity>=0 && static_cast<unsigned int>(capacity)<=fOutputBufferSize-fOutputBufferFilled){
1579 AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled;
1580 pFile=new AliHLTMemoryFile((char*)pTgt, capacity);
1582 unsigned int nofBlocks=fOutputBlocks.size();
1583 if (nofBlocks+1>fMemFiles.size()) {
1584 fMemFiles.resize(nofBlocks+1, NULL);
1586 if (nofBlocks<fMemFiles.size()) {
1587 fMemFiles[nofBlocks]=pFile;
1588 AliHLTComponentBlockData bd;
1589 FillBlockData( bd );
1590 bd.fOffset = fOutputBufferFilled;
1591 bd.fSize = capacity;
1593 bd.fSpecification = spec;
1594 fOutputBufferFilled+=bd.fSize;
1595 fOutputBlocks.push_back( bd );
1597 HLTError("can not allocate/grow object array");
1598 pFile->CloseMemoryFile(0);
1604 HLTError("can not create memory file of size %d (%d available)", capacity, fOutputBufferSize-fOutputBufferFilled);
1609 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(const char* dtID,
1610 const char* dtOrigin,
1611 AliHLTUInt32_t spec,
1614 // see header file for function documentation
1615 ALIHLTCOMPONENT_BASE_STOPWATCH();
1616 AliHLTComponentDataType dt;
1617 SetDataType(dt, dtID, dtOrigin);
1618 int size=fOutputBufferSize-fOutputBufferFilled;
1619 if (capacity<0 || capacity>1.0) {
1620 HLTError("invalid parameter: capacity %f", capacity);
1623 size=(int)(size*capacity);
1624 return CreateMemoryFile(size, dt, spec);
1627 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(const AliHLTComponentDataType& dt,
1628 AliHLTUInt32_t spec,
1631 // see header file for function documentation
1632 ALIHLTCOMPONENT_BASE_STOPWATCH();
1633 int size=fOutputBufferSize-fOutputBufferFilled;
1634 if (capacity<0 || capacity>1.0) {
1635 HLTError("invalid parameter: capacity %f", capacity);
1638 size=(int)(size*capacity);
1639 return CreateMemoryFile(size, dt, spec);
1642 int AliHLTComponent::Write(AliHLTMemoryFile* pFile, const TObject* pObject,
1643 const char* key, int option)
1645 // see header file for function documentation
1647 if (pFile && pObject) {
1649 iResult=pObject->Write(key, option);
1653 iResult=-pFile->GetErrno();
1654 if (iResult==-ENOSPC) {
1655 HLTError("error writing memory file, buffer too small");
1664 int AliHLTComponent::CloseMemoryFile(AliHLTMemoryFile* pFile)
1666 // see header file for function documentation
1669 AliHLTMemoryFilePList::iterator element=fMemFiles.begin();
1671 while (element!=fMemFiles.end() && iResult>=0) {
1672 if (*element && *element==pFile) {
1673 iResult=pFile->CloseMemoryFile();
1675 // sync memory files and descriptors
1677 fOutputBlocks[i].fSize=(*element)->GetSize()+(*element)->GetHeaderSize();
1685 HLTError("can not find memory file %p", pFile);
1693 int AliHLTComponent::CreateEventDoneData(AliHLTComponentEventDoneData edd)
1695 // see header file for function documentation
1698 AliHLTComponentEventDoneData* newEDD = NULL;
1700 unsigned long newSize=edd.fDataSize;
1702 newSize += fEventDoneData->fDataSize;
1704 if (newSize>fEventDoneDataSize) {
1705 newEDD = reinterpret_cast<AliHLTComponentEventDoneData*>( new AliHLTUInt8_t[ sizeof(AliHLTComponentEventDoneData)+newSize ] );
1708 newEDD->fStructSize = sizeof(AliHLTComponentEventDoneData);
1709 newEDD->fDataSize = newSize;
1710 newEDD->fData = reinterpret_cast<AliHLTUInt8_t*>(newEDD)+newEDD->fStructSize;
1711 unsigned long long offset = 0;
1712 if (fEventDoneData) {
1713 memcpy( newEDD->fData, fEventDoneData->fData, fEventDoneData->fDataSize );
1714 offset += fEventDoneData->fDataSize;
1716 memcpy( reinterpret_cast<AliHLTUInt8_t*>(newEDD->fData)+offset, edd.fData, edd.fDataSize );
1718 delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
1719 fEventDoneData = newEDD;
1720 fEventDoneDataSize = newSize;
1722 else if (fEventDoneData) {
1723 memcpy( reinterpret_cast<AliHLTUInt8_t*>(fEventDoneData->fData)+fEventDoneData->fDataSize, edd.fData, edd.fDataSize );
1724 fEventDoneData->fDataSize += edd.fDataSize;
1727 HLTError("internal mismatch, fEventDoneData=%d but buffer is NULL", fEventDoneDataSize);
1735 // helper function for std:sort, implements an operator<
1736 bool SortComponentStatisticsById(const AliHLTComponentStatistics& a, const AliHLTComponentStatistics& b)
1741 // helper function for std:sort
1742 bool SortComponentStatisticsDescendingByLevel(const AliHLTComponentStatistics& a, const AliHLTComponentStatistics& b)
1747 // helper class to define operator== between AliHLTComponentStatistics and AliHLTComponentStatistics.fId
1748 class AliHLTComponentStatisticsId {
1750 AliHLTComponentStatisticsId(AliHLTUInt32_t id) : fId(id) {}
1751 AliHLTComponentStatisticsId(const AliHLTComponentStatisticsId& src) : fId(src.fId) {}
1752 AliHLTComponentStatisticsId& operator=(const AliHLTComponentStatisticsId& src) {
1753 if (this==&src) return *this;
1754 fId=src.fId; return *this;
1756 bool operator==(const AliHLTComponentStatistics& a) const {return a.fId==fId;}
1758 AliHLTComponentStatisticsId();
1762 // operator for std::find of AliHLTComponentStatistics by id
1763 bool operator==(const AliHLTComponentStatistics& a, const AliHLTComponentStatisticsId& b)
1768 bool AliHLTComponentStatisticsCompareIds(const AliHLTComponentStatistics& a, const AliHLTComponentStatistics& b)
1770 return a.fId==b.fId;
1773 // helper class to define operator== between AliHLTComponentBlockData and AliHLTComponentBlockData.fSpecification
1774 class AliHLTComponentBlockDataSpecification {
1776 AliHLTComponentBlockDataSpecification(AliHLTUInt32_t specification) : fSpecification(specification) {}
1777 AliHLTComponentBlockDataSpecification(const AliHLTComponentBlockDataSpecification& src) : fSpecification(src.fSpecification) {}
1778 AliHLTComponentBlockDataSpecification& operator=(const AliHLTComponentBlockDataSpecification& src) {
1779 if (this==&src) return *this;
1780 fSpecification=src.fSpecification; return *this;
1782 bool operator==(const AliHLTComponentBlockData& bd) const {return bd.fSpecification==fSpecification;}
1784 AliHLTComponentBlockDataSpecification();
1785 AliHLTUInt32_t fSpecification;
1788 // operator for std::find of AliHLTComponentBlockData by specification
1789 bool operator==(const AliHLTComponentBlockData& bd, const AliHLTComponentBlockDataSpecification& spec)
1794 // operator for std::find
1795 bool operator==(const AliHLTComponentBlockData& a, const AliHLTComponentBlockData& b)
1797 if (!MatchExactly(a.fDataType,b.fDataType)) return false;
1798 return a.fSpecification==b.fSpecification;
1801 } // end of namespace
1803 int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
1804 const AliHLTComponentBlockData* blocks,
1805 AliHLTComponentTriggerData& trigData,
1806 AliHLTUInt8_t* outputPtr,
1807 AliHLTUInt32_t& size,
1808 AliHLTUInt32_t& outputBlockCnt,
1809 AliHLTComponentBlockData*& outputBlocks,
1810 AliHLTComponentEventDoneData*& edd )
1812 // see header file for function documentation
1813 HLTLogKeyword(fChainId.c_str());
1814 ALIHLTCOMPONENT_BASE_STOPWATCH();
1816 fCurrentEvent=evtData.fEventID;
1817 fCurrentEventData=evtData;
1818 fpInputBlocks=blocks;
1819 fCurrentInputBlock=-1;
1820 fSearchDataType=kAliHLTAnyDataType;
1821 fpOutputBuffer=outputPtr;
1822 fOutputBufferSize=size;
1823 fOutputBufferFilled=0;
1824 fOutputBlocks.clear();
1828 AliHLTComponentBlockDataList forwardedBlocks;
1830 // optional component statistics
1831 AliHLTComponentStatisticsList compStats;
1832 bool bAddComponentTableEntry=false;
1833 vector<AliHLTUInt32_t> parentComponentTables;
1834 int processingLevel=-1;
1835 #if defined(HLT_COMPONENT_STATISTICS)
1836 if ((fFlags&kDisableComponentStat)==0) {
1837 AliHLTComponentStatistics outputStat;
1838 memset(&outputStat, 0, sizeof(AliHLTComponentStatistics));
1839 outputStat.fStructSize=sizeof(AliHLTComponentStatistics);
1840 outputStat.fId=fChainIdCrc;
1842 fpBenchmark->Stop();
1843 outputStat.fComponentCycleTime=(AliHLTUInt32_t)(fpBenchmark->RealTime()*ALIHLTCOMPONENT_STATTIME_SCALER);
1844 fpBenchmark->Reset();
1845 fpBenchmark->Start();
1847 compStats.push_back(outputStat);
1849 #endif // HLT_COMPONENT_STATISTICS
1851 // data processing is skipped
1852 // - if there are only steering events in the block list.
1853 // For the sake of data source components data processing
1854 // is not skipped if there is no block list at all or if it
1855 // just contains the eventType block
1856 // - always skipped if the event is of type
1857 // - gkAliEventTypeConfiguration
1858 // - gkAliEventTypeReadPreprocessor
1859 const unsigned int skipModeDefault=0x1;
1860 const unsigned int skipModeForce=0x2;
1861 unsigned int bSkipDataProcessing=skipModeDefault;
1863 // find special events
1864 if (fpInputBlocks && evtData.fBlockCnt>0) {
1865 // first look for all special events and execute in the appropriate
1866 // sequence afterwords
1867 int indexComConfEvent=-1;
1868 int indexUpdtDCSEvent=-1;
1869 int indexSOREvent=-1;
1870 int indexEOREvent=-1;
1871 int indexECSParamBlock=-1;
1872 for (unsigned int i=0; i<evtData.fBlockCnt && iResult>=0; i++) {
1873 if (fpInputBlocks[i].fDataType==kAliHLTDataTypeSOR) {
1875 // the AliHLTCalibrationProcessor relies on the SOR and EOR events
1876 bSkipDataProcessing&=~skipModeDefault;
1877 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeRunType) {
1879 // handling is not clear yet
1880 if (fpInputBlocks[i].fPtr) {
1881 HLTDebug("got run type \"%s\"\n", fpInputBlocks[i].fPtr);
1883 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeEOR) {
1885 // the calibration processor relies on the SOR and EOR events
1886 bSkipDataProcessing&=~skipModeDefault;
1887 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeDDL) {
1889 // this event is most likely deprecated
1890 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComConf) {
1891 indexComConfEvent=i;
1892 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeUpdtDCS) {
1893 indexUpdtDCSEvent=i;
1894 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeEvent) {
1895 fEventType=fpInputBlocks[i].fSpecification;
1896 if (fEventType != gkAliEventTypeConfiguration and
1897 fEventType != gkAliEventTypeReadPreprocessor
1900 // We can actually get the event type from the CDH if it is valid.
1901 // Otherwise just use the specification of the input block.
1902 AliHLTCDHWrapper cdh;
1903 if (ExtractTriggerData(trigData, NULL, NULL, &cdh, NULL) == 0)
1905 fEventType = ExtractEventTypeFromCDH(&cdh);
1909 // skip always in case of gkAliEventTypeConfiguration
1910 if (fpInputBlocks[i].fSpecification==gkAliEventTypeConfiguration) bSkipDataProcessing|=skipModeForce;
1912 // skip always in case of gkAliEventTypeReadPreprocessor
1913 if (fpInputBlocks[i].fSpecification==gkAliEventTypeReadPreprocessor) bSkipDataProcessing|=skipModeForce;
1915 // never skip if the event type block is the only block
1916 if (evtData.fBlockCnt==1) bSkipDataProcessing&=~skipModeDefault;
1918 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComponentStatistics) {
1919 if (compStats.size()>0) {
1920 AliHLTUInt8_t* pData=reinterpret_cast<AliHLTUInt8_t*>(fpInputBlocks[i].fPtr);
1921 for (AliHLTUInt32_t offset=0;
1922 offset+sizeof(AliHLTComponentStatistics)<=fpInputBlocks[i].fSize;
1923 offset+=sizeof(AliHLTComponentStatistics)) {
1924 AliHLTComponentStatistics* pStat=reinterpret_cast<AliHLTComponentStatistics*>(pData+offset);
1925 if (pStat && compStats[0].fLevel<=pStat->fLevel) {
1926 compStats[0].fLevel=pStat->fLevel+1;
1928 if (find(compStats.begin(), compStats.end(), AliHLTComponentStatisticsId(pStat->fId))==compStats.end()) {
1929 compStats.push_back(*pStat);
1933 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComponentTable) {
1934 AliHLTComponentBlockDataList::iterator element=forwardedBlocks.begin();
1935 while ((element=find(element, forwardedBlocks.end(), AliHLTComponentBlockDataSpecification(fpInputBlocks[i].fSpecification)))!=forwardedBlocks.end()) {
1936 if (element->fDataType==fpInputBlocks[i].fDataType) break;
1937 // TODO: think about some more checks inclusing also the actual data buffers
1938 // this has to handle multiplicity>1 in the online system, where all components
1939 // send the information on SOR, because this event is broadcasted
1941 if (element==forwardedBlocks.end()) {
1942 forwardedBlocks.push_back(fpInputBlocks[i]);
1944 parentComponentTables.push_back(fpInputBlocks[i].fSpecification);
1945 if (fpInputBlocks[i].fSize>=sizeof(AliHLTComponentTableEntry)) {
1946 const AliHLTComponentTableEntry* entry=reinterpret_cast<AliHLTComponentTableEntry*>(fpInputBlocks[i].fPtr);
1947 if (entry->fStructSize==sizeof(AliHLTComponentTableEntry)) {
1948 if (processingLevel<0 || processingLevel<=(int)entry->fLevel)
1949 processingLevel=entry->fLevel+1;
1952 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeECSParam) {
1953 indexECSParamBlock=i;
1955 // the processing function is called if there is at least one
1956 // non-steering data block. Steering blocks are not filtered out
1957 // for sake of performance
1958 bSkipDataProcessing&=~skipModeDefault;
1959 if (compStats.size()>0) {
1960 compStats[0].fInputBlockCount++;
1961 compStats[0].fTotalInputSize+=fpInputBlocks[i].fSize;
1966 if (indexSOREvent>=0) {
1968 bAddComponentTableEntry=true;
1969 compStats.clear(); // no component statistics for SOR
1970 if (fpRunDesc==NULL) {
1971 fpRunDesc=new AliHLTRunDesc;
1972 if (fpRunDesc) *fpRunDesc=kAliHLTVoidRunDesc;
1975 AliHLTRunDesc rundesc;
1976 if ((iResult=CopyStruct(&rundesc, sizeof(AliHLTRunDesc), indexSOREvent, "AliHLTRunDesc", "SOR"))>0) {
1977 if (fpRunDesc->fRunNo==kAliHLTVoidRunNo) {
1979 HLTDebug("set run decriptor, run no %d", fpRunDesc->fRunNo);
1980 SetCDBRunNo(fpRunDesc->fRunNo);
1981 } else if (fpRunDesc->fRunNo!=rundesc.fRunNo) {
1982 HLTWarning("already set run properties run no %d, ignoring SOR with run no %d", fpRunDesc->fRunNo, rundesc.fRunNo);
1989 if (indexECSParamBlock>=0) {
1990 if (fpInputBlocks[indexECSParamBlock].fSize>0) {
1991 const char* param=reinterpret_cast<const char*>(fpInputBlocks[indexECSParamBlock].fPtr);
1992 TString paramString;
1993 if (param[fpInputBlocks[indexECSParamBlock].fSize-1]!=0) {
1994 HLTWarning("ECS parameter string not terminated");
1995 paramString.Insert(0, param, fpInputBlocks[indexECSParamBlock].fSize);
2000 ScanECSParam(paramString.Data());
2002 HLTWarning("empty ECS parameter received");
2005 // TODO: later on we might throw a warning here since the CTP trigger classes
2006 // should be mandatory
2009 if (indexEOREvent>=0) {
2010 fLastPushBackTime=0; // always send at EOR
2011 bAddComponentTableEntry=true;
2012 compStats.clear(); // no component statistics for EOR
2013 if (fpRunDesc!=NULL) {
2015 AliHLTRunDesc rundesc;
2016 if ((iResult=CopyStruct(&rundesc, sizeof(AliHLTRunDesc), indexEOREvent, "AliHLTRunDesc", "SOR"))>0) {
2017 if (fpRunDesc->fRunNo!=rundesc.fRunNo) {
2018 HLTWarning("run no mismatch: SOR %d, EOR %d", fpRunDesc->fRunNo, rundesc.fRunNo);
2020 HLTDebug("EOR run no %d", fpRunDesc->fRunNo);
2023 // we do not unload the fpRunDesc struct here in order to have the run information
2024 // available during the event processing
2025 // https://savannah.cern.ch/bugs/?39711
2026 // the info will be cleared in DeInit
2029 HLTWarning("did not receive SOR, ignoring EOR");
2032 if (fEventType==gkAliEventTypeConfiguration) {
2033 if (indexComConfEvent>=0) {
2035 if (indexComConfEvent>=0 && fpInputBlocks[indexComConfEvent].fPtr!=NULL && fpInputBlocks[indexComConfEvent].fSize>0) {
2036 cdbEntry.Append(reinterpret_cast<const char*>(fpInputBlocks[indexComConfEvent].fPtr), fpInputBlocks[indexComConfEvent].fSize);
2038 HLTDebug("received component configuration command: entry %s", cdbEntry.IsNull()?"none":cdbEntry.Data());
2039 int tmpResult=Reconfigure(cdbEntry[0]==0?NULL:cdbEntry.Data(), fChainId.c_str());
2041 HLTWarning("reconfiguration of component %p (%s) failed with error code %d", this, GetComponentID(), tmpResult);
2044 ALIHLTERRORGUARD(1, "incomplete Configure event, missing parameter data block");
2047 if (fEventType==gkAliEventTypeReadPreprocessor) {
2048 if (indexUpdtDCSEvent>=0) {
2050 if (fpInputBlocks[indexUpdtDCSEvent].fPtr!=NULL && fpInputBlocks[indexUpdtDCSEvent].fSize>0) {
2051 modules.Append(reinterpret_cast<const char*>(fpInputBlocks[indexUpdtDCSEvent].fPtr), fpInputBlocks[indexUpdtDCSEvent].fSize);
2053 HLTDebug("received preprocessor update command: detectors %s", modules.IsNull()?"ALL":modules.Data());
2054 int tmpResult=ReadPreprocessorValues(modules[0]==0?"ALL":modules.Data());
2056 HLTWarning("preprocessor update of component %p (%s) failed with error code %d", this, GetComponentID(), tmpResult);
2059 ALIHLTERRORGUARD(1, "incomplete ReadPreprocessor event, missing parameter data block");
2063 // processing function needs to be called if there are no input data
2064 // blocks in order to make data source components working.
2065 bSkipDataProcessing&=~skipModeDefault;
2068 // data processing is not skipped if the component explicitly asks
2069 // for the private blocks
2070 if ((fFlags&kRequireSteeringBlocks)!=0) bSkipDataProcessing=0;
2072 // data processing is not skipped for data sources
2073 if (GetComponentType()==AliHLTComponent::kSource) bSkipDataProcessing=0;
2076 // set the active triggers for this event
2077 fpCTPData->SetTriggers(trigData);
2078 // increment CTP trigger counters if available
2079 if (IsDataEvent()) fpCTPData->Increment(trigData);
2082 // Check if the event processing should be skipped because of the
2083 // down scaling from the event modulo argument. Using a prime number
2084 // as pre divisor to pseudo-randomise the event number to get a more
2085 // uniform distribution.
2086 if (fEventModulo > 1)
2088 bSkipDataProcessing |= ( ((AliHLTUInt64_t(fCurrentEvent) / AliHLTUInt64_t(4789)) % AliHLTUInt64_t(fEventModulo)) != 0 );
2091 AliHLTComponentBlockDataList blockData;
2092 if (iResult>=0 && !bSkipDataProcessing)
2093 { // dont delete, sets the scope for the stopwatch guard
2094 // do not use ALIHLTCOMPONENT_DA_STOPWATCH(); macro
2095 // in order to avoid 'shadowed variable' warning
2096 AliHLTStopwatchGuard swguard2(fpStopwatches!=NULL?reinterpret_cast<TStopwatch*>(fpStopwatches->At((int)kSWDA)):NULL);
2097 AliHLTMisc::AliOnlineGuard onlineGuard;
2098 iResult=DoProcessing(evtData, blocks, trigData, outputPtr, size, blockData, edd);
2099 } // end of the scope of the stopwatch guard
2100 if (iResult>=0 && !bSkipDataProcessing) {
2101 if (fOutputBlocks.size()>0) {
2102 // High Level interface
2104 //HLTDebug("got %d block(s) via high level interface", fOutputBlocks.size());
2105 // sync memory files and descriptors
2106 AliHLTMemoryFilePList::iterator element=fMemFiles.begin();
2108 while (element!=fMemFiles.end() && iResult>=0) {
2110 if ((*element)->IsClosed()==0) {
2111 HLTWarning("memory file has not been closed, force flush");
2112 iResult=CloseMemoryFile(*element);
2119 // create the descriptor list
2120 if (blockData.size()>0) {
2121 HLTError("low level and high interface must not be mixed; use PushBack methods to insert data blocks");
2124 if (compStats.size()>0 && IsDataEvent()) {
2125 int offset=AddComponentStatistics(fOutputBlocks, fpOutputBuffer, fOutputBufferSize, fOutputBufferFilled, compStats);
2126 if (offset>0) fOutputBufferFilled+=offset;
2128 if (bAddComponentTableEntry) {
2129 int offset=AddComponentTableEntry(fOutputBlocks, fpOutputBuffer, fOutputBufferSize, fOutputBufferFilled, parentComponentTables, processingLevel);
2130 if (offset>0) size+=offset;
2132 if (forwardedBlocks.size()>0) {
2133 fOutputBlocks.insert(fOutputBlocks.end(), forwardedBlocks.begin(), forwardedBlocks.end());
2135 iResult=MakeOutputDataBlockList(fOutputBlocks, &outputBlockCnt, &outputBlocks);
2136 size=fOutputBufferFilled;
2140 // Low Level interface
2141 if (blockData.empty() && size!=0) {
2142 // set the size to zero because there is no announced data
2143 //HLTWarning("no output blocks added by component but output buffer filled %d of %d", size, fOutputBufferSize);
2147 if (compStats.size()>0) {
2148 int offset=AddComponentStatistics(blockData, fpOutputBuffer, fOutputBufferSize, size, compStats);
2149 if (offset>0) size+=offset;
2151 if (bAddComponentTableEntry) {
2152 int offset=AddComponentTableEntry(blockData, fpOutputBuffer, fOutputBufferSize, size, parentComponentTables, processingLevel);
2153 if (offset>0) size+=offset;
2155 if (forwardedBlocks.size()>0) {
2156 blockData.insert(blockData.end(), forwardedBlocks.begin(), forwardedBlocks.end());
2158 iResult=MakeOutputDataBlockList(blockData, &outputBlockCnt, &outputBlocks);
2161 HLTFatal("component %s (%p): can not convert output block descriptor list", GetComponentID(), this);
2164 if (iResult<0 || bSkipDataProcessing) {
2168 CleanupInputObjects();
2169 if (iResult>=0 && IsDataEvent()) {
2170 IncrementEventCounter();
2172 if (outputBlockCnt==0) {
2173 // no output blocks, set size to 0
2177 // reset the internal EventData struct
2178 FillEventData(fCurrentEventData);
2180 // reset the active triggers
2181 if (fpCTPData) fpCTPData->SetTriggers(0);
2183 // set the time for the pushback period
2184 if (fPushbackPeriod>0) {
2185 // suppress the output
2187 if (fLastPushBackTime<0) {
2188 // choose a random offset at beginning to equalize traffic for multiple instances
2190 gRandom->SetSeed(fChainIdCrc);
2191 fLastPushBackTime=time.Get();
2192 fLastPushBackTime-=gRandom->Integer(fPushbackPeriod);
2193 } else if ((int)time.Get()-fLastPushBackTime>=fPushbackPeriod) {
2194 fLastPushBackTime=time.Get();
2201 int AliHLTComponent::AddComponentStatistics(AliHLTComponentBlockDataList& blocks,
2202 AliHLTUInt8_t* buffer,
2203 AliHLTUInt32_t bufferSize,
2204 AliHLTUInt32_t offset,
2205 AliHLTComponentStatisticsList& stats) const
2207 // see header file for function documentation
2209 if ((fFlags&kDisableComponentStat)!=0) return 0;
2210 #if defined(HLT_COMPONENT_STATISTICS)
2211 if (stats.size()==0) return -ENOENT;
2212 // check if there is space for at least one entry
2213 if (offset+sizeof(AliHLTComponentStatistics)>bufferSize) return 0;
2214 stats[0].fTotalOutputSize=offset;
2215 stats[0].fOutputBlockCount=blocks.size();
2217 fpBenchmark->Stop();
2218 stats[0].fTime=(AliHLTUInt32_t)(fpBenchmark->RealTime()*ALIHLTCOMPONENT_STATTIME_SCALER);
2219 stats[0].fCTime=(AliHLTUInt32_t)(fpBenchmark->CpuTime()*ALIHLTCOMPONENT_STATTIME_SCALER);
2220 fpBenchmark->Continue();
2223 sort(stats.begin(), stats.end(), SortComponentStatisticsDescendingByLevel);
2225 // shrink the number of entries if the buffer is too small
2226 if (offset+stats.size()*sizeof(AliHLTComponentStatistics)>bufferSize) {
2227 unsigned originalSize=stats.size();
2228 AliHLTUInt32_t removedLevel=0;
2230 // remove all entries of the level of the last entry
2231 removedLevel=stats.back().fLevel;
2232 AliHLTComponentStatisticsList::iterator element=stats.begin();
2234 while (element!=stats.end()) {
2235 if (element->fLevel<=removedLevel) {
2236 element=stats.erase(element);
2241 } while (stats.size()>1 &&
2242 (offset+stats.size()*sizeof(AliHLTComponentStatistics)>bufferSize));
2243 HLTWarning("too little space in output buffer to add block of %d statistics entries (size %d), available %d, removed %d entries",
2244 originalSize, sizeof(AliHLTComponentStatistics), bufferSize-offset, originalSize-stats.size());
2246 HLTDebug("adding block of %d statistics entries", stats.size());
2248 assert(stats.size()>0);
2249 if (stats.size()==0) return 0;
2251 if (offset+stats.size()*sizeof(AliHLTComponentStatistics)<=bufferSize) {
2252 AliHLTComponentBlockData bd;
2253 FillBlockData( bd );
2254 bd.fOffset = offset;
2255 bd.fSize = stats.size()*sizeof(AliHLTComponentStatistics);
2256 bd.fDataType = kAliHLTDataTypeComponentStatistics;
2257 bd.fSpecification = fChainIdCrc;
2258 memcpy(buffer+offset, &(stats[0]), bd.fSize);
2259 blocks.push_back(bd);
2263 if (blocks.size() && buffer && bufferSize && offset && stats.size()) {
2264 // get rid of warning
2266 #endif // HLT_COMPONENT_STATISTICS
2270 int AliHLTComponent::AddComponentTableEntry(AliHLTComponentBlockDataList& blocks,
2271 AliHLTUInt8_t* buffer,
2272 AliHLTUInt32_t bufferSize,
2273 AliHLTUInt32_t offset,
2274 const vector<AliHLTUInt32_t>& parents,
2275 int processingLevel) const
2277 // see header file for function documentation
2279 if ((fFlags&kDisableComponentStat)!=0) return 0;
2280 #if defined(HLT_COMPONENT_STATISTICS)
2281 // the payload consists of the AliHLTComponentTableEntry struct,
2282 // followed by a an array of 32bit crc chain ids and the component
2283 // description string
2284 unsigned int payloadSize=sizeof(AliHLTComponentTableEntry);
2285 payloadSize+=parents.size()*sizeof(AliHLTUInt32_t);
2287 // the component description has the following format:
2288 // chain-id{component-id:arguments}
2289 const char* componentId=const_cast<AliHLTComponent*>(this)->GetComponentID();
2290 unsigned int descriptionSize=fChainId.size()+1;
2291 descriptionSize+=2; // the '{}' around the component id
2292 descriptionSize+=strlen(componentId);
2293 descriptionSize+=1; // the ':' between component id and arguments
2294 descriptionSize+=fComponentArgs.size();
2296 payloadSize+=descriptionSize;
2297 if (buffer && (offset+payloadSize<=bufferSize)) {
2298 AliHLTUInt8_t* pTgt=buffer+offset;
2299 memset(pTgt, 0, payloadSize);
2302 AliHLTComponentTableEntry* pEntry=reinterpret_cast<AliHLTComponentTableEntry*>(pTgt);
2303 pEntry->fStructSize=sizeof(AliHLTComponentTableEntry);
2304 pEntry->fLevel=processingLevel>=0?processingLevel:0;
2305 pEntry->fNofParents=parents.size();
2306 pEntry->fSizeDescription=descriptionSize;
2307 pTgt=pEntry->fBuffer;
2309 // write array of parents
2310 if (parents.size()>0) {
2311 unsigned int copy=parents.size()*sizeof(vector<AliHLTUInt32_t>::value_type);
2312 memcpy(pTgt, &parents[0], parents.size()*sizeof(vector<AliHLTUInt32_t>::value_type));
2316 // write component description
2317 memcpy(pTgt, fChainId.c_str(), fChainId.size());
2318 pTgt+=fChainId.size();
2320 memcpy(pTgt, componentId, strlen(componentId));
2321 pTgt+=strlen(componentId);
2323 memcpy(pTgt, fComponentArgs.c_str(), fComponentArgs.size());
2324 pTgt+=fComponentArgs.size();
2328 AliHLTComponentBlockData bd;
2329 FillBlockData( bd );
2330 bd.fOffset = offset;
2331 bd.fSize = payloadSize;
2332 bd.fDataType = kAliHLTDataTypeComponentTable;
2333 bd.fSpecification = fChainIdCrc;
2334 blocks.push_back(bd);
2338 if (blocks.size() && buffer && bufferSize && offset && parents.size() && processingLevel) {
2339 // get rid of warning
2341 #endif // HLT_COMPONENT_STATISTICS
2345 AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard()
2350 // standard constructor (not for use)
2353 AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(TStopwatch* pStopwatch)
2355 fpStopwatch(pStopwatch),
2360 // check for already existing guard
2361 if (fgpCurrent) fpPrec=fgpCurrent;
2364 // stop the preceeding guard if it controls a different stopwatch
2366 if (fpPrec && fpPrec!=this) bStart=fpPrec->Hold(fpStopwatch);
2368 // start the stopwatch if the current guard controls a different one
2369 if (fpStopwatch && bStart==1) fpStopwatch->Start(kFALSE);
2372 AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(const AliHLTStopwatchGuard&)
2378 // copy constructor not for use
2382 AliHLTComponent::AliHLTStopwatchGuard& AliHLTComponent::AliHLTStopwatchGuard::operator=(const AliHLTStopwatchGuard& other)
2385 // assignment operator not for use
2387 if (this==&other) return *this;
2393 AliHLTComponent::AliHLTStopwatchGuard* AliHLTComponent::AliHLTStopwatchGuard::fgpCurrent=NULL;
2395 AliHLTComponent::AliHLTStopwatchGuard::~AliHLTStopwatchGuard()
2399 // resume the preceeding guard if it controls a different stopwatch
2401 if (fpPrec && fpPrec!=this) bStop=fpPrec->Resume(fpStopwatch);
2403 // stop the stopwatch if the current guard controls a different one
2404 if (fpStopwatch && bStop==1) fpStopwatch->Stop();
2406 // resume to the preceeding guard
2410 int AliHLTComponent::AliHLTStopwatchGuard::Hold(const TStopwatch* pSucc)
2412 // see header file for function documentation
2413 if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Stop();
2414 return fpStopwatch!=pSucc?1:0;
2417 int AliHLTComponent::AliHLTStopwatchGuard::Resume(const TStopwatch* pSucc)
2419 // see header file for function documentation
2420 if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Start(kFALSE);
2421 return fpStopwatch!=pSucc?1:0;
2424 int AliHLTComponent::SetStopwatch(TObject* pSW, AliHLTStopwatchType type)
2426 // see header file for function documentation
2428 if (pSW!=NULL && type<kSWTypeCount) {
2429 if (fpStopwatches) {
2430 TObject* pObj=fpStopwatches->At((int)type);
2431 if (pSW==NULL // explicit reset
2432 || pObj==NULL) { // explicit set
2433 fpStopwatches->AddAt(pSW, (int)type);
2434 } else if (pObj!=pSW) {
2435 HLTWarning("stopwatch %d already set, reset first", (int)type);
2445 int AliHLTComponent::SetStopwatches(TObjArray* pStopwatches)
2447 // see header file for function documentation
2448 if (pStopwatches==NULL) return -EINVAL;
2451 for (int i=0 ; i<(int)kSWTypeCount && pStopwatches->GetEntriesFast(); i++)
2452 SetStopwatch(pStopwatches->At(i), (AliHLTStopwatchType)i);
2456 AliHLTUInt32_t AliHLTComponent::GetRunNo() const
2458 // see header file for function documentation
2460 // 2010-02-11 OCDB is now the reliable source for the run number, it is
2461 // initialized either by aliroot or the external interface depending
2462 // on the environment. It turned out that the rundescriptor is not set
2463 // in the aliroot mode, resulting in an invalid run number. However this
2464 // did not cause problems until now. OCDB initialization has been revised
2465 // already in 10/2009. This was a remnant.
2466 // Have to check whether we get rid of the rundescriptor at some point.
2467 if (fpRunDesc==NULL) return AliHLTMisc::Instance().GetCDBRunNo();
2468 if (fpRunDesc->fRunNo!=(unsigned)AliHLTMisc::Instance().GetCDBRunNo()) {
2469 HLTWarning("run number mismatch: ocdb %d run descriptor %d", AliHLTMisc::Instance().GetCDBRunNo(), fpRunDesc->fRunNo);
2471 return fpRunDesc->fRunNo;
2474 AliHLTUInt32_t AliHLTComponent::GetRunType() const
2476 // see header file for function documentation
2477 if (fpRunDesc==NULL) return kAliHLTVoidRunType;
2478 return fpRunDesc->fRunType;
2482 AliHLTUInt32_t AliHLTComponent::GetTimeStamp() const
2484 // see header file for function documentation
2485 if (fCurrentEventData.fEventCreation_s < kMaxUInt ) {
2486 return fCurrentEventData.fEventCreation_s;
2488 // using the actual UTC if the time stamp was not set by the framework
2489 return static_cast<AliHLTUInt32_t>(time(NULL));
2492 AliHLTUInt32_t AliHLTComponent::GetPeriodNumber() const
2494 // see header file for function documentation
2495 return (GetEventId()>>36)&0xfffffff;
2498 AliHLTUInt32_t AliHLTComponent::GetOrbitNumber() const
2500 // see header file for function documentation
2501 return (GetEventId()>>12)&0xffffff;
2504 AliHLTUInt16_t AliHLTComponent::GetBunchCrossNumber() const
2506 // see header file for function documentation
2507 return GetEventId()&0xfff;
2510 bool AliHLTComponent::IsDataEvent(AliHLTUInt32_t* pTgt) const
2512 // see header file for function documentation
2513 if (pTgt) *pTgt=fEventType;
2514 return (fEventType==gkAliEventTypeData ||
2515 fEventType==gkAliEventTypeDataReplay);
2518 int AliHLTComponent::CopyStruct(void* pStruct, unsigned int iStructSize, unsigned int iBlockNo,
2519 const char* structname, const char* eventname)
2521 // see header file for function documentation
2523 if (pStruct!=NULL && iStructSize>sizeof(AliHLTUInt32_t)) {
2524 if (fpInputBlocks!=NULL && iBlockNo<fCurrentEventData.fBlockCnt) {
2525 AliHLTUInt32_t* pTgt=(AliHLTUInt32_t*)pStruct;
2526 if (fpInputBlocks[iBlockNo].fPtr && fpInputBlocks[iBlockNo].fSize) {
2527 AliHLTUInt32_t copy=*((AliHLTUInt32_t*)fpInputBlocks[iBlockNo].fPtr);
2528 if (fpInputBlocks[iBlockNo].fSize!=copy) {
2529 HLTWarning("%s event: mismatch of block size (%d) and structure size (%d)", eventname, fpInputBlocks[iBlockNo].fSize, copy);
2530 if (copy>fpInputBlocks[iBlockNo].fSize) copy=fpInputBlocks[iBlockNo].fSize;
2532 if (copy!=iStructSize) {
2533 HLTWarning("%s event: mismatch in %s version (data type version %d)", eventname, structname, ALIHLT_DATA_TYPES_VERSION);
2534 if (copy>iStructSize) {
2537 memset(pTgt, 0, iStructSize);
2540 memcpy(pTgt, fpInputBlocks[iBlockNo].fPtr, copy);
2544 HLTWarning("%s event: missing data block", eventname);
2550 HLTError("invalid struct");
2556 AliHLTUInt32_t AliHLTComponent::CalculateChecksum(const AliHLTUInt8_t* buffer, int size)
2558 // see header file for function documentation
2559 AliHLTUInt32_t remainder = 0;
2560 const AliHLTUInt8_t crcwidth=(8*sizeof(AliHLTUInt32_t));
2561 const AliHLTUInt32_t topbit=1 << (crcwidth-1);
2562 const AliHLTUInt32_t polynomial=0xD8; /* 11011 followed by 0's */
2565 // http://www.netrino.com/Embedded-Systems/How-To/CRC-Calculation-C-Code
2568 * Perform modulo-2 division, a byte at a time.
2570 for (int byte = 0; byte < size; ++byte)
2573 * Bring the next byte into the remainder.
2575 remainder ^= (buffer[byte] << (crcwidth - 8));
2578 * Perform modulo-2 division, a bit at a time.
2580 for (uint8_t bit = 8; bit > 0; --bit)
2583 * Try to divide the current data bit.
2585 if (remainder & topbit)
2587 remainder = (remainder << 1) ^ polynomial;
2591 remainder = (remainder << 1);
2597 * The final remainder is the CRC result.
2602 int AliHLTComponent::ExtractComponentTableEntry(const AliHLTUInt8_t* pBuffer, AliHLTUInt32_t size,
2603 string& retChainId, string& retCompId, string& retCompArgs,
2604 vector<AliHLTUInt32_t>& parents, int& level)
2606 // see header file for function documentation
2609 retCompArgs.clear();
2612 if (!pBuffer || size==0) return 0;
2614 const AliHLTComponentTableEntry* pEntry=reinterpret_cast<const AliHLTComponentTableEntry*>(pBuffer);
2615 if (size<8/* the initial size of the structure*/ ||
2616 pEntry==NULL || pEntry->fStructSize<8) return -ENOMSG;
2618 if (pEntry->fStructSize!=sizeof(AliHLTComponentTableEntry)) return -EBADF;
2619 level=pEntry->fLevel;
2620 const AliHLTUInt32_t* pParents=reinterpret_cast<const AliHLTUInt32_t*>(pEntry->fBuffer);
2621 const AliHLTUInt8_t* pEnd=pBuffer+size;
2623 if (pParents+pEntry->fNofParents>=reinterpret_cast<const AliHLTUInt32_t*>(pEnd)) return -ENODEV;
2624 for (unsigned int i=0; i<pEntry->fNofParents; i++, pParents++) {
2625 parents.push_back(*pParents);
2628 const char* pDescription=reinterpret_cast<const char*>(pParents);
2629 if (pDescription+pEntry->fSizeDescription>=reinterpret_cast<const char*>(pEnd) ||
2630 *(pDescription+pEntry->fSizeDescription)!=0) {
2634 TString descriptor=reinterpret_cast<const char*>(pDescription);
2638 TObjArray* pTokens=descriptor.Tokenize("{");
2641 if (pTokens->GetEntriesFast()>n) {
2642 retChainId=pTokens->At(n++)->GetName();
2644 if (pTokens->GetEntriesFast()>n) {
2645 compId=pTokens->At(n++)->GetName();
2649 if (!compId.IsNull() && (pTokens=compId.Tokenize(":"))!=NULL) {
2651 if (pTokens->GetEntriesFast()>n) {
2652 compId=pTokens->At(n++)->GetName();
2654 if (pTokens->GetEntriesFast()>n) {
2655 compArgs=pTokens->At(n++)->GetName();
2659 compId.ReplaceAll("}", "");
2660 compArgs.ReplaceAll("}", "");
2663 retCompArgs=compArgs;
2665 if (retChainId.size()==0) return -ENODATA;
2670 int AliHLTComponent::ExtractTriggerData(
2671 const AliHLTComponentTriggerData& trigData,
2672 const AliHLTUInt8_t (**attributes)[gkAliHLTBlockDAttributeCount],
2673 AliHLTUInt64_t* status,
2674 AliHLTCDHWrapper* const cdh,
2675 AliHLTReadoutList* readoutlist,
2679 // see header file for function documentation
2681 // Check that the trigger data structure is the correct size.
2682 if (trigData.fStructSize != sizeof(AliHLTComponentTriggerData))
2687 log.LoggingVarargs(kHLTLogError, Class_Name(), FUNCTIONNAME(), __FILE__, __LINE__,
2688 "Invalid trigger structure size: %d but expected %d.", trigData.fStructSize, sizeof(AliHLTComponentTriggerData)
2694 // Get the size of the AliHLTEventTriggerData structure without the readout list part.
2695 // The way we do this here should also handle memory alignment correctly.
2696 AliHLTEventTriggerData* dummy = NULL;
2697 size_t sizeWithoutReadout = (char*)(&dummy->fReadoutList) - (char*)(dummy);
2699 // Check that the trigger data pointer points to data of a size we can handle.
2700 // Either it is the size of AliHLTEventTriggerData or the size of the old
2701 // version of AliHLTEventTriggerData using AliHLTEventDDLV0 or V1.
2702 if (trigData.fDataSize != sizeof(AliHLTEventTriggerData) and
2703 trigData.fDataSize != sizeWithoutReadout + sizeof(AliHLTEventDDLV0) and
2704 trigData.fDataSize != sizeWithoutReadout + sizeof(AliHLTEventDDLV1)
2710 log.LoggingVarargs(kHLTLogError, Class_Name(), FUNCTIONNAME(), __FILE__, __LINE__,
2711 "Invalid trigger data size: %d but expected %d.", trigData.fDataSize, sizeof(AliHLTEventTriggerData)
2717 AliHLTEventTriggerData* evtData = reinterpret_cast<AliHLTEventTriggerData*>(trigData.fData);
2718 assert(evtData != NULL);
2720 // Check that the CDH has the right number of words.
2721 if ( cdh != NULL and
2722 evtData->fCommonHeaderWordCnt != gkAliHLTCommonHeaderCount and
2723 evtData->fCommonHeaderWordCnt != gkAliHLTCommonHeaderCountV2
2729 log.LoggingVarargs(kHLTLogError, Class_Name(), FUNCTIONNAME(), __FILE__, __LINE__,
2730 "Common Data Header (CDH) has wrong number of data words: %d but expected %d",
2731 evtData->fCommonHeaderWordCnt, gkAliHLTCommonHeaderCount
2737 // Check that the readout list has the correct count of words. i.e. something we can handle,
2738 if (readoutlist != NULL and
2739 evtData->fReadoutList.fCount != (unsigned)gkAliHLTDDLListSizeV0 and
2740 evtData->fReadoutList.fCount != (unsigned)gkAliHLTDDLListSizeV1
2746 log.LoggingVarargs(kHLTLogError, Class_Name(), FUNCTIONNAME(), __FILE__, __LINE__,
2747 "Readout list structure has wrong number of data words: %d but expected %d",
2748 evtData->fReadoutList.fCount, gkAliHLTDDLListSize
2754 if (attributes != NULL)
2756 *attributes = &evtData->fAttributes;
2760 *status = evtData->fHLTStatus;
2764 *cdh = &(evtData->fCommonHeader[0]);
2766 if (readoutlist != NULL)
2768 *readoutlist = AliHLTReadoutList(evtData->fReadoutList);
2773 AliHLTUInt32_t AliHLTComponent::ExtractEventTypeFromCDH(const AliHLTCDHWrapper* const cdh)
2775 // see header file for function documentation
2776 UChar_t l1msg = cdh->GetL1TriggerMessage();
2777 if ((l1msg & 0x1) == 0x0) return gkAliEventTypeData;
2778 // The L2SwC bit must be one if we got here, i.e. l1msg & 0x1 == 0x1.
2779 if (((l1msg >> 2) & 0xF) == 0xE) return gkAliEventTypeStartOfRun;
2780 if (((l1msg >> 2) & 0xF) == 0xF) return gkAliEventTypeEndOfRun;
2781 // Check the C1T bit to see if this is a calibration event,
2782 // if not then it must be some other software trigger event.
2783 if (((l1msg >> 6) & 0x1) == 0x1) return gkAliEventTypeCalibration;
2784 return gkAliEventTypeSoftware;
2787 int AliHLTComponent::LoggingVarargs(AliHLTComponentLogSeverity severity,
2788 const char* originClass, const char* originFunc,
2789 const char* file, int line, ... ) const
2791 // see header file for function documentation
2795 va_start(args, line);
2797 // logging function needs to be const in order to be called from const member functions
2798 // without problems. But at this point we face the problem with virtual members which
2799 // are not necessarily const.
2800 AliHLTComponent* nonconst=const_cast<AliHLTComponent*>(this);
2801 AliHLTLogging::SetLogString(this, ", %p", "%s (%s_pfmt_): ",
2802 fChainId[0]!=0?fChainId.c_str():nonconst->GetComponentID(),
2803 nonconst->GetComponentID());
2804 iResult=SendMessage(severity, originClass, originFunc, file, line, AliHLTLogging::BuildLogString(NULL, args, true /*append*/));
2810 TUUID AliHLTComponent::GenerateGUID()
2812 // Generates a globally unique identifier.
2814 // Start by creating a new UUID. We cannot use the one automatically generated
2815 // by ROOT because the algorithm used will not guarantee unique IDs when generating
2816 // these UUIDs at a high rate in parallel.
2818 // We then use the generated UUID to form part of the random number seeds which
2819 // will be used to generate a proper random UUID. For good measure we use a MD5
2820 // hash also. Note that we want to use the TUUID class because it will combine the
2821 // host address information into the UUID. Using gSystem->GetHostByName() apparently
2822 // can cause problems on Windows machines with a firewall, because it always tries
2823 // to contact a DNS. The TUUID class handles this case appropriately.
2832 md5.Update(buf, sizeof(buf));
2835 dword[0] += gSystem->GetUid();
2836 dword[1] += gSystem->GetGid();
2837 dword[2] += gSystem->GetPid();
2838 for (int i = 0; i < 4; ++i)
2840 gRandom->SetSeed(dword[i]);
2841 dword[i] = gRandom->Integer(0xFFFFFFFF);
2843 md52.Update(buf, sizeof(buf));
2845 // To keep to the standard we need to set the version and reserved bits.
2846 word[3] = (word[3] & 0x0FFF) | 0x4000;
2847 buf[8] = (buf[8] & 0x3F) | 0x80;
2849 // Create the name of the new class and file.
2851 sprintf(uuidstr, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
2852 dword[0], word[2], word[3], buf[8], buf[9], buf[10], buf[11], buf[12], buf[13], buf[14], buf[15]
2855 uuid.SetUUID(uuidstr);
2859 int AliHLTComponent::ScanECSParam(const char* ecsParam)
2861 // see header file for function documentation
2863 // format of the parameter string from ECS
2864 // <command>;<parameterkey>=<parametervalue>;<parameterkey>=<parametervalue>;...
2865 // search for a subset of the parameterkeys
2869 // CTP_TRIGGER_CLASS=
2870 // DATA_FORMAT_VERSION=
2872 // HLT_OUT_DDL_LIST=
2873 // HLT_TRIGGER_CODE=
2876 // The command apears not to be sent by the online framework
2878 TString string=ecsParam;
2879 TObjArray* parameter=string.Tokenize(";");
2881 for (int i=0; i<parameter->GetEntriesFast(); i++) {
2882 TString entry=parameter->At(i)->GetName();
2883 HLTDebug("scanning ECS entry: %s", entry.Data());
2884 TObjArray* entryParams=entry.Tokenize("=");
2886 if (entryParams->GetEntriesFast()>1) {
2887 if ((((TObjString*)entryParams->At(0))->GetString()).CompareTo("CTP_TRIGGER_CLASS")==0) {
2888 int result=InitCTPTriggerClasses(entryParams->At(1)->GetName());
2889 if (iResult>=0 && result<0) iResult=result;
2891 // TODO: scan the other parameters
2892 // e.g. consistency check of run number
2904 int AliHLTComponent::SetupCTPData()
2906 // see header file for function documentation
2907 if (fpCTPData) delete fpCTPData;
2908 fpCTPData=new AliHLTCTPData;
2909 if (!fpCTPData) return -ENOMEM;
2913 int AliHLTComponent::InitCTPTriggerClasses(const char* ctpString)
2915 // see header file for function documentation
2916 if (!fpCTPData) return 0; // silently accept as the component has to announce that it want's the CTP info
2917 return fpCTPData->InitCTPTriggerClasses(ctpString);
2920 bool AliHLTComponent::EvaluateCTPTriggerClass(const char* expression, AliHLTComponentTriggerData& trigData) const
2922 // see header file for function documentation
2924 static bool bWarningThrown=false;
2925 if (!bWarningThrown) HLTError("Trigger classes not initialized, use SetupCTPData from DoInit()");
2926 bWarningThrown=true;
2930 return fpCTPData->EvaluateCTPTriggerClass(expression, trigData);
2933 int AliHLTComponent::CheckCTPTrigger(const char* name) const
2935 // see header file for function documentation
2937 static bool bWarningThrown=false;
2938 if (!bWarningThrown) HLTError("Trigger classes not initialized, use SetupCTPData from DoInit()");
2939 bWarningThrown=true;
2943 return fpCTPData->CheckTrigger(name);
2946 Double_t AliHLTComponent::GetBz()
2949 return AliHLTMisc::Instance().GetBz();
2952 Double_t AliHLTComponent::GetBz(const Double_t *r)
2954 // Returns Bz (kG) at the point "r" .
2955 return AliHLTMisc::Instance().GetBz(r);
2958 void AliHLTComponent::GetBxByBz(const Double_t r[3], Double_t b[3])
2960 // Returns Bx, By and Bz (kG) at the point "r" .
2961 AliHLTMisc::Instance().GetBxByBz(r, b);