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 "AliRawDataHeader.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(false),
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 ptrarray.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());
496 ptrarray.push_back(stringarray.back().c_str());
498 TObjArray* pTokens=argument.Tokenize(" ");
500 if (pTokens->GetEntriesFast()>0) {
501 for (int n=0; n<pTokens->GetEntriesFast(); n++) {
502 TString data=pTokens->At(n)->GetName();
503 if (!data.IsNull() && !data.IsWhitespace()) {
504 stringarray.push_back(data.Data());
505 ptrarray.push_back(stringarray.back().c_str());
518 for (i=0; (unsigned)i<ptrarray.size() && iResult>=0;) {
519 int result=ScanConfigurationArgument(ptrarray.size()-i, &ptrarray[i]);
521 HLTWarning("unknown component argument %s", ptrarray[i]);
523 } else if (result>0) {
527 if (iResult==-EINVAL) {
528 HLTError("unknown argument %s", ptrarray[i]);
529 } else if (iResult==-EPROTO) {
530 HLTError("missing/wrong parameter for argument %s (%s)", ptrarray[i], (ptrarray.size()>(unsigned)i+1)?ptrarray[i+1]:"missing");
532 HLTError("scan of argument %s failed (%d)", ptrarray[i], iResult);
540 int AliHLTComponent::ConfigureFromCDBTObjString(const char* entries, const char* key)
542 // load a list of OCDB objects and configure from the objects
543 // can either be a TObjString or a TMap with a TObjString:TObjString key-value pair
546 TString confEntries=entries;
547 TObjArray* pTokens=confEntries.Tokenize(" ");
549 for (int n=0; n<pTokens->GetEntriesFast(); n++) {
550 const char* path=pTokens->At(n)->GetName();
551 const char* chainId=GetChainId();
552 HLTInfo("configure from entry \"%s\"%s%s, chain id %s", path, key?" key ":"",key?key:"", (chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
553 TObject* pOCDBObject = LoadAndExtractOCDBObject(path, key);
555 TObjString* pString=dynamic_cast<TObjString*>(pOCDBObject);
557 TMap* pMap=dynamic_cast<TMap*>(pOCDBObject);
559 // this is the case where no key has been specified and the OCDB
560 // object is a TMap, search for the default key
561 TObject* pObject=pMap->GetValue("default");
562 if (pObject && (pString=dynamic_cast<TObjString*>(pObject))!=NULL) {
563 HLTInfo("using default key of TMap of configuration object \"%s\"", path);
565 HLTError("no default key available in TMap of configuration object \"%s\"", path);
573 HLTInfo("received configuration object string: \'%s\'", pString->GetName());
574 arguments+=pString->GetName();
577 HLTError("configuration object \"%s\"%s%s has wrong type, required TObjString", path, key?" key ":"",key?key:"");
581 HLTError("can not fetch object \"%s\" from OCDB", path);
587 if (iResult>=0 && !arguments.IsNull()) {
588 const char* array=arguments.Data();
589 iResult=ConfigureFromArgumentString(1, &array);
594 TObject* AliHLTComponent::LoadAndExtractOCDBObject(const char* path, const char* key) const
596 // see header file for function documentation
597 AliCDBEntry* pEntry=AliHLTMisc::Instance().LoadOCDBEntry(path, GetRunNo());
598 if (!pEntry) return NULL;
599 TObject* pObject=AliHLTMisc::Instance().ExtractObject(pEntry);
600 TMap* pMap=dynamic_cast<TMap*>(pObject);
602 pObject=pMap->GetValue(key);
604 pObject=pMap->GetValue("default");
606 HLTWarning("can not find object for key \"%s\" in TMap of configuration object \"%s\", using key \"default\"", key, path);
610 HLTError("can not find object for key \"%s\" in TMap of configuration object \"%s\"", key, path);
617 int AliHLTComponent::DoInit( int /*argc*/, const char** /*argv*/)
619 // default implementation, childs can overload
620 HLTLogKeyword("dummy");
624 int AliHLTComponent::DoDeinit()
626 // default implementation, childs can overload
627 HLTLogKeyword("dummy");
631 int AliHLTComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/)
633 // default implementation, childs can overload
634 HLTLogKeyword("dummy");
638 int AliHLTComponent::ReadPreprocessorValues(const char* /*modules*/)
640 // default implementation, childs can overload
641 HLTLogKeyword("dummy");
645 int AliHLTComponent::ScanConfigurationArgument(int /*argc*/, const char** /*argv*/)
647 // default implementation, childs can overload
648 HLTLogKeyword("dummy");
649 HLTWarning("The function needs to be implemented by the component");
653 int AliHLTComponent::StartOfRun()
655 // default implementation, childs can overload
656 HLTLogKeyword("dummy");
660 int AliHLTComponent::EndOfRun()
662 // default implementation, childs can overload
663 HLTLogKeyword("dummy");
668 int AliHLTComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& /*tgtList*/)
670 // default implementation, childs can overload
671 HLTLogKeyword("dummy");
675 void AliHLTComponent::GetOCDBObjectDescription( TMap* const /*targetArray*/)
677 // default implementation, childs can overload
678 HLTLogKeyword("dummy");
681 int AliHLTComponent::CheckOCDBEntries(const TMap* const externList)
683 // check the availability of the OCDB entry descriptions in the TMap
684 // key : complete OCDB path of the entry
685 // value : auxiliary object - short description
686 // if the external map was not provided the function invokes
687 // interface function GetOCDBObjectDescription() to retrieve the list.
690 iResult=AliHLTMisc::Instance().CheckOCDBEntries(externList);
694 pMap->SetOwnerKeyValue(kTRUE);
695 GetOCDBObjectDescription(pMap);
696 iResult=AliHLTMisc::Instance().CheckOCDBEntries(pMap);
705 void AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2] ) const
707 // see header file for function documentation
708 memset( output, 0, kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2 );
709 strncat( output, type.fOrigin, kAliHLTComponentDataTypefOriginSize );
710 strncat( output, ":", 1 );
711 strncat( output, type.fID, kAliHLTComponentDataTypefIDsize );
714 string AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, int mode)
716 // see header file for function documentation
720 // aligned to 8 and 4 chars respectively, blocks enclosed in quotes and
721 // separated by blank e.g.
727 for (i=0; i<kAliHLTComponentDataTypefIDsize; i++) {
728 unsigned char* puc=(unsigned char*)type.fID;
730 sprintf(tmp, "\\%x", type.fID[i]);
732 sprintf(tmp, "%c", type.fID[i]);
736 for (i=0; i<kAliHLTComponentDataTypefOriginSize; i++) {
737 unsigned char* puc=(unsigned char*)type.fOrigin;
739 sprintf(tmp, "\\%x", type.fOrigin[i]);
741 sprintf(tmp, "%c", type.fOrigin[i]);
748 // origin typeid as numbers separated by colon e.g.
749 // aligned to 8 and 4 chars respectively, all characters separated by
751 // '84'80'67'32':'68'68'76'95'82'65'87'32'
755 for (i=0; i<kAliHLTComponentDataTypefOriginSize; i++) {
756 sprintf(tmp, "'%d", type.fOrigin[i]);
760 for (i=0; i<kAliHLTComponentDataTypefIDsize; i++) {
761 sprintf(tmp, "%d'", type.fID[i]);
767 // origin typeid separated by colon e.g.
768 // aligned to 8 and 4 chars respectively, all characters separated by
770 // 'T'P'C' ':'D'D'L'_'R'A'W' '
774 for (i=0; i<kAliHLTComponentDataTypefOriginSize; i++) {
775 unsigned char* puc=(unsigned char*)type.fOrigin;
777 sprintf(tmp, "'\\%x", type.fOrigin[i]);
779 sprintf(tmp, "'%c", type.fOrigin[i]);
783 for (i=0; i<kAliHLTComponentDataTypefIDsize; i++) {
784 unsigned char* puc=(unsigned char*)type.fID;
786 sprintf(tmp, "\\%x'", type.fID[i]);
788 sprintf(tmp, "%c'", type.fID[i]);
795 // aligned to 8 and 4 chars respectively, separated by colon e.g.
797 if (type==kAliHLTVoidDataType) {
800 // some gymnastics in order to avoid a '0' which is part of either or both
801 // ID and origin terminating the whole string. Unfortunately, string doesn't
802 // stop appending at the '0' if the number of elements to append was
803 // explicitely specified
805 tmp.append(type.fOrigin, kAliHLTComponentDataTypefOriginSize);
806 out.append(tmp.c_str());
809 tmp.append(type.fID, kAliHLTComponentDataTypefIDsize);
810 out.append(tmp.c_str());
816 void* AliHLTComponent::AllocMemory( unsigned long size )
818 // see header file for function documentation
819 if (fEnvironment.fAllocMemoryFunc)
820 return (*fEnvironment.fAllocMemoryFunc)(fEnvironment.fParam, size );
821 HLTFatal("no memory allocation handler registered");
825 int AliHLTComponent::MakeOutputDataBlockList( const AliHLTComponentBlockDataList& blocks, AliHLTUInt32_t* blockCount,
826 AliHLTComponentBlockData** outputBlocks )
828 // see header file for function documentation
829 if ( blockCount==NULL || outputBlocks==NULL )
831 AliHLTUInt32_t count = blocks.size();
835 *outputBlocks = NULL;
838 *outputBlocks = reinterpret_cast<AliHLTComponentBlockData*>( AllocMemory( sizeof(AliHLTComponentBlockData)*count ) );
839 if ( !*outputBlocks )
841 for ( unsigned long i = 0; i < count; i++ ) {
842 (*outputBlocks)[i] = blocks[i];
843 if (MatchExactly(blocks[i].fDataType, kAliHLTAnyDataType)) {
844 (*outputBlocks)[i].fDataType=GetOutputDataType();
845 /* data type was set to the output data type by the PubSub AliRoot
846 Wrapper component, if data type of the block was ********:****.
847 Now handled by the component base class in order to have same
848 behavior when running embedded in AliRoot
849 memset((*outputBlocks)[i].fDataType.fID, '*', kAliHLTComponentDataTypefIDsize);
850 memset((*outputBlocks)[i].fDataType.fOrigin, '*', kAliHLTComponentDataTypefOriginSize);
859 int AliHLTComponent::GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd ) const
861 // see header file for function documentation
862 if (fEnvironment.fGetEventDoneDataFunc)
863 return (*fEnvironment.fGetEventDoneDataFunc)(fEnvironment.fParam, fCurrentEvent, size, edd );
867 int AliHLTComponent::ReserveEventDoneData( unsigned long size )
869 // see header file for function documentation
872 unsigned long capacity=fEventDoneDataSize;
873 if (fEventDoneData) capacity-=sizeof(AliHLTComponentEventDoneData)+fEventDoneData->fDataSize;
875 unsigned long newSize=sizeof(AliHLTComponentEventDoneData)+size+(fEventDoneDataSize-capacity);
876 AliHLTComponentEventDoneData* newEDD = reinterpret_cast<AliHLTComponentEventDoneData*>( new AliHLTUInt8_t[newSize] );
879 newEDD->fStructSize = sizeof(AliHLTComponentEventDoneData);
880 newEDD->fDataSize = 0;
881 newEDD->fData = reinterpret_cast<AliHLTUInt8_t*>(newEDD)+newEDD->fStructSize;
882 if (fEventDoneData) {
883 memcpy( newEDD->fData, fEventDoneData->fData, fEventDoneData->fDataSize );
884 newEDD->fDataSize = fEventDoneData->fDataSize;
885 delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
887 fEventDoneData = newEDD;
888 fEventDoneDataSize = newSize;
894 int AliHLTComponent::PushEventDoneData( AliHLTUInt32_t eddDataWord )
896 // see header file for function documentation
899 if (fEventDoneData->fDataSize+sizeof(AliHLTUInt32_t)>fEventDoneDataSize)
901 *reinterpret_cast<AliHLTUInt32_t*>((reinterpret_cast<AliHLTUInt8_t*>(fEventDoneData->fData)+fEventDoneData->fDataSize)) = eddDataWord;
902 fEventDoneData->fDataSize += sizeof(AliHLTUInt32_t);
906 void AliHLTComponent::ReleaseEventDoneData()
908 // see header file for function documentation
910 delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
911 fEventDoneData = NULL;
912 fEventDoneDataSize = 0;
916 int AliHLTComponent::FindMatchingDataTypes(AliHLTComponent* pConsumer, AliHLTComponentDataTypeList* tgtList)
918 // see header file for function documentation
921 AliHLTComponentDataTypeList itypes;
922 AliHLTComponentDataTypeList otypes;
923 otypes.push_back(GetOutputDataType());
924 if (MatchExactly(otypes[0],kAliHLTMultipleDataType)) {
927 if ((count=GetOutputDataTypes(otypes))>0) {
928 } else if (GetComponentType()!=kSink) {
929 HLTWarning("component %s indicates multiple output data types but GetOutputDataTypes returns %d", GetComponentID(), count);
932 pConsumer->GetInputDataTypes(itypes);
933 AliHLTComponentDataTypeList::iterator otype=otypes.begin();
934 for (;otype!=otypes.end();otype++) {
935 //PrintDataTypeContent((*otype), "publisher \'%s\'");
936 if ((*otype)==(kAliHLTAnyDataType|kAliHLTDataOriginPrivate)) {
937 if (tgtList) tgtList->push_back(*otype);
942 AliHLTComponentDataTypeList::iterator itype=itypes.begin();
943 for ( ; itype!=itypes.end() && (*itype)!=(*otype) ; itype++) {/* empty body */};
944 //if (itype!=itypes.end()) PrintDataTypeContent(*itype, "consumer \'%s\'");
945 if (itype!=itypes.end()) {
946 if (tgtList) tgtList->push_back(*otype);
956 void AliHLTComponent::PrintDataTypeContent(AliHLTComponentDataType& dt, const char* format)
958 // see header file for function documentation
959 const char* fmt="\'%s\'";
960 if (format) fmt=format;
961 AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, Form(fmt, (DataType2Text(dt)).c_str()));
962 AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL,
963 Form("%x %x %x %x %x %x %x %x : %x %x %x %x",
978 void AliHLTComponent::FillBlockData( AliHLTComponentBlockData& blockData )
980 // see header file for function documentation
981 blockData.fStructSize = sizeof(blockData);
982 FillShmData( blockData.fShmKey );
983 blockData.fOffset = ~(AliHLTUInt32_t)0;
984 blockData.fPtr = NULL;
986 FillDataType( blockData.fDataType );
987 blockData.fSpecification = kAliHLTVoidDataSpec;
990 void AliHLTComponent::FillShmData( AliHLTComponentShmData& shmData )
992 // see header file for function documentation
993 shmData.fStructSize = sizeof(shmData);
994 shmData.fShmType = gkAliHLTComponentInvalidShmType;
995 shmData.fShmID = gkAliHLTComponentInvalidShmID;
998 void AliHLTComponent::FillDataType( AliHLTComponentDataType& dataType )
1000 // see header file for function documentation
1001 dataType=kAliHLTAnyDataType;
1004 void AliHLTComponent::CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt)
1006 // see header file for function documentation
1007 memcpy(&tgtdt.fID[0], &srcdt.fID[0], kAliHLTComponentDataTypefIDsize);
1008 memcpy(&tgtdt.fOrigin[0], &srcdt.fOrigin[0], kAliHLTComponentDataTypefOriginSize);
1011 void AliHLTComponent::SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin)
1013 // see header file for function documentation
1014 tgtdt.fStructSize=sizeof(AliHLTComponentDataType);
1016 memset(&tgtdt.fID[0], 0, kAliHLTComponentDataTypefIDsize);
1017 strncpy(&tgtdt.fID[0], id, strlen(id)<(size_t)kAliHLTComponentDataTypefIDsize?strlen(id):kAliHLTComponentDataTypefIDsize);
1020 memset(&tgtdt.fOrigin[0], 0, kAliHLTComponentDataTypefOriginSize);
1021 strncpy(&tgtdt.fOrigin[0], origin, strlen(origin)<(size_t)kAliHLTComponentDataTypefOriginSize?strlen(origin):kAliHLTComponentDataTypefOriginSize);
1025 void AliHLTComponent::SetDataType(AliHLTComponentDataType& dt, AliHLTUInt64_t id, AliHLTUInt32_t origin)
1027 // see header file for function documentation
1028 dt.fStructSize=sizeof(AliHLTComponentDataType);
1029 assert(kAliHLTComponentDataTypefIDsize==sizeof(id));
1030 assert(kAliHLTComponentDataTypefOriginSize==sizeof(origin));
1031 memcpy(&dt.fID, &id, kAliHLTComponentDataTypefIDsize);
1032 memcpy(&dt.fOrigin, &origin, kAliHLTComponentDataTypefOriginSize);
1035 void AliHLTComponent::FillEventData(AliHLTComponentEventData& evtData)
1037 // see header file for function documentation
1038 memset(&evtData, 0, sizeof(AliHLTComponentEventData));
1039 evtData.fStructSize=sizeof(AliHLTComponentEventData);
1040 evtData.fEventID=kAliHLTVoidEventID;
1043 void AliHLTComponent::PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt)
1045 // see header file for function documentation
1047 msg.Form("AliHLTComponentDataType(%d): ID=\"", dt.fStructSize);
1048 for ( int i = 0; i < kAliHLTComponentDataTypefIDsize; i++ ) {
1049 if (dt.fID[i]!=0) msg+=dt.fID[i];
1052 msg+="\" Origin=\"";
1053 for ( int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++ ) {
1054 if (dt.fOrigin[i]!=0) msg+=dt.fOrigin[i];
1058 AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, msg.Data());
1061 int AliHLTComponent::GetEventCount() const
1063 // see header file for function documentation
1067 int AliHLTComponent::IncrementEventCounter()
1069 // see header file for function documentation
1070 if (fEventCount>=0) fEventCount++;
1074 int AliHLTComponent::GetNumberOfInputBlocks() const
1076 // see header file for function documentation
1077 if (fpInputBlocks!=NULL) {
1078 return fCurrentEventData.fBlockCnt;
1083 AliHLTEventID_t AliHLTComponent::GetEventId() const
1085 // see header file for function documentation
1086 if (fpInputBlocks!=NULL) {
1087 return fCurrentEventData.fEventID;
1092 const TObject* AliHLTComponent::GetFirstInputObject(const AliHLTComponentDataType& dt,
1093 const char* classname,
1096 // see header file for function documentation
1097 ALIHLTCOMPONENT_BASE_STOPWATCH();
1099 if (classname) fClassName=classname;
1100 else fClassName.clear();
1101 int idx=FindInputBlock(fSearchDataType, 0, 1);
1104 HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(dt).c_str());
1105 if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) {
1106 fCurrentInputBlock=idx;
1113 const TObject* AliHLTComponent::GetFirstInputObject(const char* dtID,
1114 const char* dtOrigin,
1115 const char* classname,
1118 // see header file for function documentation
1119 ALIHLTCOMPONENT_BASE_STOPWATCH();
1120 AliHLTComponentDataType dt;
1121 SetDataType(dt, dtID, dtOrigin);
1122 return GetFirstInputObject(dt, classname, bForce);
1125 const TObject* AliHLTComponent::GetNextInputObject(int bForce)
1127 // see header file for function documentation
1128 ALIHLTCOMPONENT_BASE_STOPWATCH();
1129 int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1, 1);
1130 //HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(fSearchDataType).c_str());
1133 if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) {
1134 fCurrentInputBlock=idx;
1140 int AliHLTComponent::FindInputBlock(const AliHLTComponentDataType& dt, int startIdx, int bObject) const
1142 // see header file for function documentation
1143 int iResult=-ENOENT;
1144 if (fpInputBlocks!=NULL) {
1145 int idx=startIdx<0?0:startIdx;
1146 for ( ; (UInt_t)idx<fCurrentEventData.fBlockCnt && iResult==-ENOENT; idx++) {
1147 if (dt!=fpInputBlocks[idx].fDataType) continue;
1150 if (fpInputBlocks[idx].fPtr==NULL) continue;
1151 AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr);
1152 if (firstWord!=fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) continue;
1160 TObject* AliHLTComponent::CreateInputObject(int idx, int bForce)
1162 // see header file for function documentation
1164 if (fpInputBlocks!=NULL) {
1165 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
1166 if (fpInputBlocks[idx].fPtr) {
1167 AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr);
1168 if (firstWord==fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) {
1169 HLTDebug("create object from block %d size %d", idx, fpInputBlocks[idx].fSize);
1170 AliHLTMessage msg(fpInputBlocks[idx].fPtr, fpInputBlocks[idx].fSize);
1171 TClass* objclass=msg.GetClass();
1172 pObj=msg.ReadObject(objclass);
1173 if (pObj && objclass) {
1174 HLTDebug("object %p type %s created", pObj, objclass->GetName());
1178 } else if (bForce!=0) {
1179 HLTError("size mismatch: block size %d, indicated %d", fpInputBlocks[idx].fSize, firstWord+sizeof(AliHLTUInt32_t));
1182 HLTFatal("block descriptor empty");
1185 HLTError("index %d out of range %d", idx, fCurrentEventData.fBlockCnt);
1188 HLTError("no input blocks available");
1194 TObject* AliHLTComponent::GetInputObject(int idx, const char* /*classname*/, int bForce)
1196 // see header file for function documentation
1197 if (fpInputObjects==NULL) {
1198 fpInputObjects=new TObjArray(fCurrentEventData.fBlockCnt);
1201 if (fpInputObjects) {
1202 pObj=fpInputObjects->At(idx);
1204 pObj=CreateInputObject(idx, bForce);
1206 fpInputObjects->AddAt(pObj, idx);
1210 HLTFatal("memory allocation failed: TObjArray of size %d", fCurrentEventData.fBlockCnt);
1215 int AliHLTComponent::CleanupInputObjects()
1217 // see header file for function documentation
1218 if (!fpInputObjects) return 0;
1219 TObjArray* array=fpInputObjects;
1220 fpInputObjects=NULL;
1221 for (int i=0; i<array->GetEntriesFast(); i++) {
1222 TObject* pObj=array->At(i);
1223 // grrr, garbage collection strikes back: When read via AliHLTMessage
1224 // (CreateInputObject), and written to a TFile afterwards, the
1225 // TFile::Close calls ROOOT's garbage collection. No clue why the
1226 // object ended up in the key list and needs to be deleted
1228 // Matthias 09.11.2008 follow up
1229 // This approach doesn't actually work in all cases: the object table
1230 // can be switched off globally, the flag needs to be checked here as
1231 // well in order to avoid memory leaks.
1232 // This means we have to find another solution for the problem if it
1235 (!TObject::GetObjectStat() || gObjectTable->PtrIsValid(pObj))) {
1243 AliHLTComponentDataType AliHLTComponent::GetDataType(const TObject* pObject)
1245 // see header file for function documentation
1246 ALIHLTCOMPONENT_BASE_STOPWATCH();
1247 AliHLTComponentDataType dt=kAliHLTVoidDataType;
1248 int idx=fCurrentInputBlock;
1250 if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
1252 HLTError("unknown object %p", pObject);
1256 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
1257 dt=fpInputBlocks[idx].fDataType;
1259 HLTFatal("severe internal error, index out of range");
1265 AliHLTUInt32_t AliHLTComponent::GetSpecification(const TObject* pObject)
1267 // see header file for function documentation
1268 ALIHLTCOMPONENT_BASE_STOPWATCH();
1269 AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec;
1270 int idx=fCurrentInputBlock;
1272 if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
1274 HLTError("unknown object %p", pObject);
1278 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
1279 iSpec=fpInputBlocks[idx].fSpecification;
1281 HLTFatal("severe internal error, index out of range");
1287 int AliHLTComponent::Forward(const TObject* pObject)
1289 // see header file for function documentation
1291 int idx=fCurrentInputBlock;
1293 if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
1295 HLTError("unknown object %p", pObject);
1300 fOutputBlocks.push_back(fpInputBlocks[idx]);
1305 int AliHLTComponent::Forward(const AliHLTComponentBlockData* pBlock)
1307 // see header file for function documentation
1309 int idx=fCurrentInputBlock;
1311 if ((idx=FindInputBlock(pBlock))>=0) {
1313 HLTError("unknown Block %p", pBlock);
1318 // check for fpInputBlocks pointer done in FindInputBlock
1319 fOutputBlocks.push_back(fpInputBlocks[idx]);
1324 const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const AliHLTComponentDataType& dt)
1326 // see header file for function documentation
1327 ALIHLTCOMPONENT_BASE_STOPWATCH();
1330 int idx=FindInputBlock(fSearchDataType, 0);
1331 const AliHLTComponentBlockData* pBlock=NULL;
1333 // check for fpInputBlocks pointer done in FindInputBlock
1334 pBlock=&fpInputBlocks[idx];
1335 fCurrentInputBlock=idx;
1340 const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const char* dtID,
1341 const char* dtOrigin)
1343 // see header file for function documentation
1344 ALIHLTCOMPONENT_BASE_STOPWATCH();
1345 AliHLTComponentDataType dt;
1346 SetDataType(dt, dtID, dtOrigin);
1347 return GetFirstInputBlock(dt);
1350 const AliHLTComponentBlockData* AliHLTComponent::GetInputBlock(int index) const
1352 // see header file for function documentation
1353 ALIHLTCOMPONENT_BASE_STOPWATCH();
1354 assert( 0 <= index and index < (int)fCurrentEventData.fBlockCnt );
1355 return &fpInputBlocks[index];
1358 const AliHLTComponentBlockData* AliHLTComponent::GetNextInputBlock()
1360 // see header file for function documentation
1361 ALIHLTCOMPONENT_BASE_STOPWATCH();
1362 int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1);
1363 const AliHLTComponentBlockData* pBlock=NULL;
1365 // check for fpInputBlocks pointer done in FindInputBlock
1366 pBlock=&fpInputBlocks[idx];
1367 fCurrentInputBlock=idx;
1372 int AliHLTComponent::FindInputBlock(const AliHLTComponentBlockData* pBlock) const
1374 // see header file for function documentation
1375 int iResult=-ENOENT;
1376 if (fpInputBlocks!=NULL) {
1378 if (pBlock>=fpInputBlocks && pBlock<fpInputBlocks+fCurrentEventData.fBlockCnt) {
1379 iResult=(int)(pBlock-fpInputBlocks);
1388 AliHLTUInt32_t AliHLTComponent::GetSpecification(const AliHLTComponentBlockData* pBlock)
1390 // see header file for function documentation
1391 ALIHLTCOMPONENT_BASE_STOPWATCH();
1392 AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec;
1393 int idx=fCurrentInputBlock;
1395 if (fpInputObjects==NULL || (idx=FindInputBlock(pBlock))>=0) {
1397 HLTError("unknown Block %p", pBlock);
1401 // check for fpInputBlocks pointer done in FindInputBlock
1402 iSpec=fpInputBlocks[idx].fSpecification;
1407 int AliHLTComponent::PushBack(const TObject* pObject, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
1408 void* pHeader, int headerSize)
1410 // see header file for function documentation
1411 ALIHLTCOMPONENT_BASE_STOPWATCH();
1414 if (fPushbackPeriod>0) {
1415 // suppress the output
1417 if (fLastPushBackTime<0 || (int)time.Get()-fLastPushBackTime<fPushbackPeriod) return 0;
1420 AliHLTMessage msg(kMESS_OBJECT);
1421 msg.SetCompressionLevel(fCompressionLevel);
1422 msg.WriteObject(pObject);
1423 Int_t iMsgLength=msg.Length();
1425 // Matthias Sep 2008
1426 // NOTE: AliHLTMessage does implement it's own SetLength method
1427 // which is not architecture independent. The original SetLength
1428 // stores the size always in network byte order.
1429 // I'm trying to remember the rational for that, might be that
1430 // it was just some lack of knowledge. Want to change this, but
1431 // has to be done carefullt to be backward compatible.
1432 msg.SetLength(); // sets the length to the first (reserved) word
1434 // does nothing if the level is 0
1437 char *mbuf = msg.Buffer();
1438 if (msg.CompBuffer()) {
1439 msg.SetLength(); // set once more to have to byte order
1440 mbuf = msg.CompBuffer();
1441 iMsgLength = msg.CompLength();
1444 iResult=InsertOutputBlock(mbuf, iMsgLength, dt, spec, pHeader, headerSize);
1446 HLTDebug("object %s (%p) size %d compression %d inserted to output", pObject->ClassName(), pObject, iMsgLength, msg.GetCompressionLevel());
1448 fLastObjectSize=iMsgLength;
1450 HLTError("object serialization failed for object %p", pObject);
1459 int AliHLTComponent::PushBack(const TObject* pObject, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec,
1460 void* pHeader, int headerSize)
1462 // see header file for function documentation
1463 ALIHLTCOMPONENT_BASE_STOPWATCH();
1464 AliHLTComponentDataType dt;
1465 SetDataType(dt, dtID, dtOrigin);
1466 return PushBack(pObject, dt, spec, pHeader, headerSize);
1469 int AliHLTComponent::PushBack(const void* pBuffer, int iSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
1470 const void* pHeader, int headerSize)
1472 // see header file for function documentation
1473 ALIHLTCOMPONENT_BASE_STOPWATCH();
1474 if (fPushbackPeriod>0) {
1475 // suppress the output
1477 if (fLastPushBackTime<0 || (int)time.Get()-fLastPushBackTime<fPushbackPeriod) return 0;
1480 return InsertOutputBlock(pBuffer, iSize, dt, spec, pHeader, headerSize);
1483 int AliHLTComponent::PushBack(const void* pBuffer, int iSize, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec,
1484 const void* pHeader, int headerSize)
1486 // see header file for function documentation
1487 ALIHLTCOMPONENT_BASE_STOPWATCH();
1488 AliHLTComponentDataType dt;
1489 SetDataType(dt, dtID, dtOrigin);
1490 return PushBack(pBuffer, iSize, dt, spec, pHeader, headerSize);
1493 int AliHLTComponent::InsertOutputBlock(const void* pBuffer, int iBufferSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
1494 const void* pHeader, int iHeaderSize)
1496 // see header file for function documentation
1498 int iBlkSize = iBufferSize + iHeaderSize;
1500 if ((pBuffer!=NULL && iBufferSize>0) || (pHeader!=NULL && iHeaderSize>0)) {
1501 if (fpOutputBuffer && iBlkSize<=(int)(fOutputBufferSize-fOutputBufferFilled)) {
1502 AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled;
1504 // copy header if provided but skip if the header is the target location
1505 // in that case it has already been copied
1506 if (pHeader!=NULL && pHeader!=pTgt) {
1507 memcpy(pTgt, pHeader, iHeaderSize);
1510 pTgt += (AliHLTUInt8_t) iHeaderSize;
1512 // copy buffer if provided but skip if buffer is the target location
1513 // in that case it has already been copied
1514 if (pBuffer!=NULL && pBuffer!=pTgt) {
1515 memcpy(pTgt, pBuffer, iBufferSize);
1517 //AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)pBuffer);
1518 //HLTDebug("copy %d bytes from %p to output buffer %p, first word %#x", iBufferSize, pBuffer, pTgt, firstWord);
1520 //HLTDebug("buffer inserted to output: size %d data type %s spec %#x", iBlkSize, DataType2Text(dt).c_str(), spec);
1522 if (fpOutputBuffer) {
1523 HLTError("too little space in output buffer: %d of %d, required %d", fOutputBufferSize-fOutputBufferFilled, fOutputBufferSize, iBlkSize);
1525 HLTError("output buffer not available");
1531 AliHLTComponentBlockData bd;
1532 FillBlockData( bd );
1533 bd.fOffset = fOutputBufferFilled;
1534 bd.fSize = iBlkSize;
1536 bd.fSpecification = spec;
1537 fOutputBlocks.push_back( bd );
1538 fOutputBufferFilled+=bd.fSize;
1544 int AliHLTComponent::EstimateObjectSize(const TObject* pObject) const
1546 // see header file for function documentation
1547 if (!pObject) return 0;
1549 AliHLTMessage msg(kMESS_OBJECT);
1550 msg.WriteObject(pObject);
1551 return msg.Length();
1554 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(int capacity, const char* dtID,
1555 const char* dtOrigin,
1556 AliHLTUInt32_t spec)
1558 // see header file for function documentation
1559 ALIHLTCOMPONENT_BASE_STOPWATCH();
1560 AliHLTComponentDataType dt;
1561 SetDataType(dt, dtID, dtOrigin);
1562 return CreateMemoryFile(capacity, dt, spec);
1565 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(int capacity,
1566 const AliHLTComponentDataType& dt,
1567 AliHLTUInt32_t spec)
1569 // see header file for function documentation
1570 ALIHLTCOMPONENT_BASE_STOPWATCH();
1571 AliHLTMemoryFile* pFile=NULL;
1572 if (capacity>=0 && static_cast<unsigned int>(capacity)<=fOutputBufferSize-fOutputBufferFilled){
1573 AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled;
1574 pFile=new AliHLTMemoryFile((char*)pTgt, capacity);
1576 unsigned int nofBlocks=fOutputBlocks.size();
1577 if (nofBlocks+1>fMemFiles.size()) {
1578 fMemFiles.resize(nofBlocks+1, NULL);
1580 if (nofBlocks<fMemFiles.size()) {
1581 fMemFiles[nofBlocks]=pFile;
1582 AliHLTComponentBlockData bd;
1583 FillBlockData( bd );
1584 bd.fOffset = fOutputBufferFilled;
1585 bd.fSize = capacity;
1587 bd.fSpecification = spec;
1588 fOutputBufferFilled+=bd.fSize;
1589 fOutputBlocks.push_back( bd );
1591 HLTError("can not allocate/grow object array");
1592 pFile->CloseMemoryFile(0);
1598 HLTError("can not create memory file of size %d (%d available)", capacity, fOutputBufferSize-fOutputBufferFilled);
1603 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(const char* dtID,
1604 const char* dtOrigin,
1605 AliHLTUInt32_t spec,
1608 // see header file for function documentation
1609 ALIHLTCOMPONENT_BASE_STOPWATCH();
1610 AliHLTComponentDataType dt;
1611 SetDataType(dt, dtID, dtOrigin);
1612 int size=fOutputBufferSize-fOutputBufferFilled;
1613 if (capacity<0 || capacity>1.0) {
1614 HLTError("invalid parameter: capacity %f", capacity);
1617 size=(int)(size*capacity);
1618 return CreateMemoryFile(size, dt, spec);
1621 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(const AliHLTComponentDataType& dt,
1622 AliHLTUInt32_t spec,
1625 // see header file for function documentation
1626 ALIHLTCOMPONENT_BASE_STOPWATCH();
1627 int size=fOutputBufferSize-fOutputBufferFilled;
1628 if (capacity<0 || capacity>1.0) {
1629 HLTError("invalid parameter: capacity %f", capacity);
1632 size=(int)(size*capacity);
1633 return CreateMemoryFile(size, dt, spec);
1636 int AliHLTComponent::Write(AliHLTMemoryFile* pFile, const TObject* pObject,
1637 const char* key, int option)
1639 // see header file for function documentation
1641 if (pFile && pObject) {
1643 iResult=pObject->Write(key, option);
1647 iResult=-pFile->GetErrno();
1648 if (iResult==-ENOSPC) {
1649 HLTError("error writing memory file, buffer too small");
1658 int AliHLTComponent::CloseMemoryFile(AliHLTMemoryFile* pFile)
1660 // see header file for function documentation
1663 AliHLTMemoryFilePList::iterator element=fMemFiles.begin();
1665 while (element!=fMemFiles.end() && iResult>=0) {
1666 if (*element && *element==pFile) {
1667 iResult=pFile->CloseMemoryFile();
1669 // sync memory files and descriptors
1671 fOutputBlocks[i].fSize=(*element)->GetSize()+(*element)->GetHeaderSize();
1679 HLTError("can not find memory file %p", pFile);
1687 int AliHLTComponent::CreateEventDoneData(AliHLTComponentEventDoneData edd)
1689 // see header file for function documentation
1692 AliHLTComponentEventDoneData* newEDD = NULL;
1694 unsigned long newSize=edd.fDataSize;
1696 newSize += fEventDoneData->fDataSize;
1698 if (newSize>fEventDoneDataSize) {
1699 newEDD = reinterpret_cast<AliHLTComponentEventDoneData*>( new AliHLTUInt8_t[ sizeof(AliHLTComponentEventDoneData)+newSize ] );
1702 newEDD->fStructSize = sizeof(AliHLTComponentEventDoneData);
1703 newEDD->fDataSize = newSize;
1704 newEDD->fData = reinterpret_cast<AliHLTUInt8_t*>(newEDD)+newEDD->fStructSize;
1705 unsigned long long offset = 0;
1706 if (fEventDoneData) {
1707 memcpy( newEDD->fData, fEventDoneData->fData, fEventDoneData->fDataSize );
1708 offset += fEventDoneData->fDataSize;
1710 memcpy( reinterpret_cast<AliHLTUInt8_t*>(newEDD->fData)+offset, edd.fData, edd.fDataSize );
1712 delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
1713 fEventDoneData = newEDD;
1714 fEventDoneDataSize = newSize;
1716 else if (fEventDoneData) {
1717 memcpy( reinterpret_cast<AliHLTUInt8_t*>(fEventDoneData->fData)+fEventDoneData->fDataSize, edd.fData, edd.fDataSize );
1718 fEventDoneData->fDataSize += edd.fDataSize;
1721 HLTError("internal mismatch, fEventDoneData=%d but buffer is NULL", fEventDoneDataSize);
1729 // helper function for std:sort, implements an operator<
1730 bool SortComponentStatisticsById(const AliHLTComponentStatistics& a, const AliHLTComponentStatistics& b)
1735 // helper function for std:sort
1736 bool SortComponentStatisticsDescendingByLevel(const AliHLTComponentStatistics& a, const AliHLTComponentStatistics& b)
1741 // helper class to define operator== between AliHLTComponentStatistics and AliHLTComponentStatistics.fId
1742 class AliHLTComponentStatisticsId {
1744 AliHLTComponentStatisticsId(AliHLTUInt32_t id) : fId(id) {}
1745 AliHLTComponentStatisticsId(const AliHLTComponentStatisticsId& src) : fId(src.fId) {}
1746 AliHLTComponentStatisticsId& operator=(const AliHLTComponentStatisticsId& src) {
1747 if (this==&src) return *this;
1748 fId=src.fId; return *this;
1750 bool operator==(const AliHLTComponentStatistics& a) const {return a.fId==fId;}
1752 AliHLTComponentStatisticsId();
1756 // operator for std::find of AliHLTComponentStatistics by id
1757 bool operator==(const AliHLTComponentStatistics& a, const AliHLTComponentStatisticsId& b)
1762 bool AliHLTComponentStatisticsCompareIds(const AliHLTComponentStatistics& a, const AliHLTComponentStatistics& b)
1764 return a.fId==b.fId;
1767 // helper class to define operator== between AliHLTComponentBlockData and AliHLTComponentBlockData.fSpecification
1768 class AliHLTComponentBlockDataSpecification {
1770 AliHLTComponentBlockDataSpecification(AliHLTUInt32_t specification) : fSpecification(specification) {}
1771 AliHLTComponentBlockDataSpecification(const AliHLTComponentBlockDataSpecification& src) : fSpecification(src.fSpecification) {}
1772 AliHLTComponentBlockDataSpecification& operator=(const AliHLTComponentBlockDataSpecification& src) {
1773 if (this==&src) return *this;
1774 fSpecification=src.fSpecification; return *this;
1776 bool operator==(const AliHLTComponentBlockData& bd) const {return bd.fSpecification==fSpecification;}
1778 AliHLTComponentBlockDataSpecification();
1779 AliHLTUInt32_t fSpecification;
1782 // operator for std::find of AliHLTComponentBlockData by specification
1783 bool operator==(const AliHLTComponentBlockData& bd, const AliHLTComponentBlockDataSpecification& spec)
1788 // operator for std::find
1789 bool operator==(const AliHLTComponentBlockData& a, const AliHLTComponentBlockData& b)
1791 if (!MatchExactly(a.fDataType,b.fDataType)) return false;
1792 return a.fSpecification==b.fSpecification;
1795 } // end of namespace
1797 int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
1798 const AliHLTComponentBlockData* blocks,
1799 AliHLTComponentTriggerData& trigData,
1800 AliHLTUInt8_t* outputPtr,
1801 AliHLTUInt32_t& size,
1802 AliHLTUInt32_t& outputBlockCnt,
1803 AliHLTComponentBlockData*& outputBlocks,
1804 AliHLTComponentEventDoneData*& edd )
1806 // see header file for function documentation
1807 HLTLogKeyword(fChainId.c_str());
1808 ALIHLTCOMPONENT_BASE_STOPWATCH();
1810 fCurrentEvent=evtData.fEventID;
1811 fCurrentEventData=evtData;
1812 fpInputBlocks=blocks;
1813 fCurrentInputBlock=-1;
1814 fSearchDataType=kAliHLTAnyDataType;
1815 fpOutputBuffer=outputPtr;
1816 fOutputBufferSize=size;
1817 fOutputBufferFilled=0;
1818 fOutputBlocks.clear();
1822 AliHLTComponentBlockDataList forwardedBlocks;
1824 // optional component statistics
1825 AliHLTComponentStatisticsList compStats;
1826 bool bAddComponentTableEntry=false;
1827 vector<AliHLTUInt32_t> parentComponentTables;
1828 int processingLevel=-1;
1829 #if defined(HLT_COMPONENT_STATISTICS)
1830 if ((fFlags&kDisableComponentStat)==0) {
1831 AliHLTComponentStatistics outputStat;
1832 memset(&outputStat, 0, sizeof(AliHLTComponentStatistics));
1833 outputStat.fStructSize=sizeof(AliHLTComponentStatistics);
1834 outputStat.fId=fChainIdCrc;
1836 fpBenchmark->Stop();
1837 outputStat.fComponentCycleTime=(AliHLTUInt32_t)(fpBenchmark->RealTime()*ALIHLTCOMPONENT_STATTIME_SCALER);
1838 fpBenchmark->Reset();
1839 fpBenchmark->Start();
1841 compStats.push_back(outputStat);
1843 #endif // HLT_COMPONENT_STATISTICS
1845 // data processing is skipped
1846 // - if there are only steering events in the block list.
1847 // For the sake of data source components data processing
1848 // is not skipped if there is no block list at all or if it
1849 // just contains the eventType block
1850 // - always skipped if the event is of type
1851 // - gkAliEventTypeConfiguration
1852 // - gkAliEventTypeReadPreprocessor
1853 const unsigned int skipModeDefault=0x1;
1854 const unsigned int skipModeForce=0x2;
1855 unsigned int bSkipDataProcessing=skipModeDefault;
1857 // find special events
1858 if (fpInputBlocks && evtData.fBlockCnt>0) {
1859 // first look for all special events and execute in the appropriate
1860 // sequence afterwords
1861 int indexComConfEvent=-1;
1862 int indexUpdtDCSEvent=-1;
1863 int indexSOREvent=-1;
1864 int indexEOREvent=-1;
1865 int indexECSParamBlock=-1;
1866 for (unsigned int i=0; i<evtData.fBlockCnt && iResult>=0; i++) {
1867 if (fpInputBlocks[i].fDataType==kAliHLTDataTypeSOR) {
1869 // the AliHLTCalibrationProcessor relies on the SOR and EOR events
1870 bSkipDataProcessing&=~skipModeDefault;
1871 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeRunType) {
1873 // handling is not clear yet
1874 if (fpInputBlocks[i].fPtr) {
1875 HLTDebug("got run type \"%s\"\n", fpInputBlocks[i].fPtr);
1877 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeEOR) {
1879 // the calibration processor relies on the SOR and EOR events
1880 bSkipDataProcessing&=~skipModeDefault;
1881 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeDDL) {
1883 // this event is most likely deprecated
1884 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComConf) {
1885 indexComConfEvent=i;
1886 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeUpdtDCS) {
1887 indexUpdtDCSEvent=i;
1888 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeEvent) {
1889 fEventType=fpInputBlocks[i].fSpecification;
1890 if (fEventType != gkAliEventTypeConfiguration and
1891 fEventType != gkAliEventTypeReadPreprocessor
1894 // We can actually get the event type from the CDH if it is valid.
1895 // Otherwise just use the specification of the input block.
1896 const AliRawDataHeader* cdh;
1897 if (ExtractTriggerData(trigData, NULL, NULL, &cdh, NULL) == 0)
1899 fEventType = ExtractEventTypeFromCDH(cdh);
1903 // skip always in case of gkAliEventTypeConfiguration
1904 if (fpInputBlocks[i].fSpecification==gkAliEventTypeConfiguration) bSkipDataProcessing|=skipModeForce;
1906 // skip always in case of gkAliEventTypeReadPreprocessor
1907 if (fpInputBlocks[i].fSpecification==gkAliEventTypeReadPreprocessor) bSkipDataProcessing|=skipModeForce;
1909 // never skip if the event type block is the only block
1910 if (evtData.fBlockCnt==1) bSkipDataProcessing&=~skipModeDefault;
1912 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComponentStatistics) {
1913 if (compStats.size()>0) {
1914 AliHLTUInt8_t* pData=reinterpret_cast<AliHLTUInt8_t*>(fpInputBlocks[i].fPtr);
1915 for (AliHLTUInt32_t offset=0;
1916 offset+sizeof(AliHLTComponentStatistics)<=fpInputBlocks[i].fSize;
1917 offset+=sizeof(AliHLTComponentStatistics)) {
1918 AliHLTComponentStatistics* pStat=reinterpret_cast<AliHLTComponentStatistics*>(pData+offset);
1919 if (pStat && compStats[0].fLevel<=pStat->fLevel) {
1920 compStats[0].fLevel=pStat->fLevel+1;
1922 if (find(compStats.begin(), compStats.end(), AliHLTComponentStatisticsId(pStat->fId))==compStats.end()) {
1923 compStats.push_back(*pStat);
1927 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComponentTable) {
1928 AliHLTComponentBlockDataList::iterator element=forwardedBlocks.begin();
1929 while ((element=find(element, forwardedBlocks.end(), AliHLTComponentBlockDataSpecification(fpInputBlocks[i].fSpecification)))!=forwardedBlocks.end()) {
1930 if (element->fDataType==fpInputBlocks[i].fDataType) break;
1931 // TODO: think about some more checks inclusing also the actual data buffers
1932 // this has to handle multiplicity>1 in the online system, where all components
1933 // send the information on SOR, because this event is broadcasted
1935 if (element==forwardedBlocks.end()) {
1936 forwardedBlocks.push_back(fpInputBlocks[i]);
1938 parentComponentTables.push_back(fpInputBlocks[i].fSpecification);
1939 if (fpInputBlocks[i].fSize>=sizeof(AliHLTComponentTableEntry)) {
1940 const AliHLTComponentTableEntry* entry=reinterpret_cast<AliHLTComponentTableEntry*>(fpInputBlocks[i].fPtr);
1941 if (entry->fStructSize==sizeof(AliHLTComponentTableEntry)) {
1942 if (processingLevel<0 || processingLevel<=(int)entry->fLevel)
1943 processingLevel=entry->fLevel+1;
1946 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeECSParam) {
1947 indexECSParamBlock=i;
1949 // the processing function is called if there is at least one
1950 // non-steering data block. Steering blocks are not filtered out
1951 // for sake of performance
1952 bSkipDataProcessing&=~skipModeDefault;
1953 if (compStats.size()>0) {
1954 compStats[0].fInputBlockCount++;
1955 compStats[0].fTotalInputSize+=fpInputBlocks[i].fSize;
1960 if (indexSOREvent>=0) {
1962 bAddComponentTableEntry=true;
1963 compStats.clear(); // no component statistics for SOR
1964 if (fpRunDesc==NULL) {
1965 fpRunDesc=new AliHLTRunDesc;
1966 if (fpRunDesc) *fpRunDesc=kAliHLTVoidRunDesc;
1969 AliHLTRunDesc rundesc;
1970 if ((iResult=CopyStruct(&rundesc, sizeof(AliHLTRunDesc), indexSOREvent, "AliHLTRunDesc", "SOR"))>0) {
1971 if (fpRunDesc->fRunNo==kAliHLTVoidRunNo) {
1973 HLTDebug("set run decriptor, run no %d", fpRunDesc->fRunNo);
1974 SetCDBRunNo(fpRunDesc->fRunNo);
1975 } else if (fpRunDesc->fRunNo!=rundesc.fRunNo) {
1976 HLTWarning("already set run properties run no %d, ignoring SOR with run no %d", fpRunDesc->fRunNo, rundesc.fRunNo);
1983 if (indexECSParamBlock>=0) {
1984 if (fpInputBlocks[indexECSParamBlock].fSize>0) {
1985 const char* param=reinterpret_cast<const char*>(fpInputBlocks[indexECSParamBlock].fPtr);
1986 TString paramString;
1987 if (param[fpInputBlocks[indexECSParamBlock].fSize-1]!=0) {
1988 HLTWarning("ECS parameter string not terminated");
1989 paramString.Insert(0, param, fpInputBlocks[indexECSParamBlock].fSize);
1994 ScanECSParam(paramString.Data());
1996 HLTWarning("empty ECS parameter received");
1999 // TODO: later on we might throw a warning here since the CTP trigger classes
2000 // should be mandatory
2003 if (indexEOREvent>=0) {
2004 fLastPushBackTime=0; // always send at EOR
2005 bAddComponentTableEntry=true;
2006 compStats.clear(); // no component statistics for EOR
2007 if (fpRunDesc!=NULL) {
2009 AliHLTRunDesc rundesc;
2010 if ((iResult=CopyStruct(&rundesc, sizeof(AliHLTRunDesc), indexEOREvent, "AliHLTRunDesc", "SOR"))>0) {
2011 if (fpRunDesc->fRunNo!=rundesc.fRunNo) {
2012 HLTWarning("run no mismatch: SOR %d, EOR %d", fpRunDesc->fRunNo, rundesc.fRunNo);
2014 HLTDebug("EOR run no %d", fpRunDesc->fRunNo);
2017 // we do not unload the fpRunDesc struct here in order to have the run information
2018 // available during the event processing
2019 // https://savannah.cern.ch/bugs/?39711
2020 // the info will be cleared in DeInit
2023 HLTWarning("did not receive SOR, ignoring EOR");
2026 if (fEventType==gkAliEventTypeConfiguration) {
2027 if (indexComConfEvent>=0) {
2029 if (indexComConfEvent>=0 && fpInputBlocks[indexComConfEvent].fPtr!=NULL && fpInputBlocks[indexComConfEvent].fSize>0) {
2030 cdbEntry.Append(reinterpret_cast<const char*>(fpInputBlocks[indexComConfEvent].fPtr), fpInputBlocks[indexComConfEvent].fSize);
2032 HLTDebug("received component configuration command: entry %s", cdbEntry.IsNull()?"none":cdbEntry.Data());
2033 int tmpResult=Reconfigure(cdbEntry[0]==0?NULL:cdbEntry.Data(), fChainId.c_str());
2035 HLTWarning("reconfiguration of component %p (%s) failed with error code %d", this, GetComponentID(), tmpResult);
2038 ALIHLTERRORGUARD(1, "incomplete Configure event, missing parameter data block");
2041 if (fEventType==gkAliEventTypeReadPreprocessor) {
2042 if (indexUpdtDCSEvent>=0) {
2044 if (fpInputBlocks[indexUpdtDCSEvent].fPtr!=NULL && fpInputBlocks[indexUpdtDCSEvent].fSize>0) {
2045 modules.Append(reinterpret_cast<const char*>(fpInputBlocks[indexUpdtDCSEvent].fPtr), fpInputBlocks[indexUpdtDCSEvent].fSize);
2047 HLTDebug("received preprocessor update command: detectors %s", modules.IsNull()?"ALL":modules.Data());
2048 int tmpResult=ReadPreprocessorValues(modules[0]==0?"ALL":modules.Data());
2050 HLTWarning("preprocessor update of component %p (%s) failed with error code %d", this, GetComponentID(), tmpResult);
2053 ALIHLTERRORGUARD(1, "incomplete ReadPreprocessor event, missing parameter data block");
2057 // processing function needs to be called if there are no input data
2058 // blocks in order to make data source components working.
2059 bSkipDataProcessing&=~skipModeDefault;
2062 // data processing is not skipped if the component explicitly asks
2063 // for the private blocks
2064 if ((fFlags&kRequireSteeringBlocks)!=0) bSkipDataProcessing=0;
2066 // data processing is not skipped for data sources
2067 if (GetComponentType()==AliHLTComponent::kSource) bSkipDataProcessing=0;
2070 // set the active triggers for this event
2071 fpCTPData->SetTriggers(trigData);
2072 // increment CTP trigger counters if available
2073 if (IsDataEvent()) fpCTPData->Increment(trigData);
2076 // Check if the event processing should be skipped because of the
2077 // down scaling from the event modulo argument. Using a prime number
2078 // as pre divisor to pseudo-randomise the event number to get a more
2079 // uniform distribution.
2080 if (fEventModulo > 1)
2082 bSkipDataProcessing |= ( ((AliHLTUInt64_t(fCurrentEvent) / AliHLTUInt64_t(4789)) % AliHLTUInt64_t(fEventModulo)) != 0 );
2085 AliHLTComponentBlockDataList blockData;
2086 if (iResult>=0 && !bSkipDataProcessing)
2087 { // dont delete, sets the scope for the stopwatch guard
2088 // do not use ALIHLTCOMPONENT_DA_STOPWATCH(); macro
2089 // in order to avoid 'shadowed variable' warning
2090 AliHLTStopwatchGuard swguard2(fpStopwatches!=NULL?reinterpret_cast<TStopwatch*>(fpStopwatches->At((int)kSWDA)):NULL);
2091 AliHLTMisc::AliOnlineGuard onlineGuard;
2092 iResult=DoProcessing(evtData, blocks, trigData, outputPtr, size, blockData, edd);
2093 } // end of the scope of the stopwatch guard
2094 if (iResult>=0 && !bSkipDataProcessing) {
2095 if (fOutputBlocks.size()>0) {
2096 // High Level interface
2098 //HLTDebug("got %d block(s) via high level interface", fOutputBlocks.size());
2099 // sync memory files and descriptors
2100 AliHLTMemoryFilePList::iterator element=fMemFiles.begin();
2102 while (element!=fMemFiles.end() && iResult>=0) {
2104 if ((*element)->IsClosed()==0) {
2105 HLTWarning("memory file has not been closed, force flush");
2106 iResult=CloseMemoryFile(*element);
2113 // create the descriptor list
2114 if (blockData.size()>0) {
2115 HLTError("low level and high interface must not be mixed; use PushBack methods to insert data blocks");
2118 if (compStats.size()>0 && IsDataEvent()) {
2119 int offset=AddComponentStatistics(fOutputBlocks, fpOutputBuffer, fOutputBufferSize, fOutputBufferFilled, compStats);
2120 if (offset>0) fOutputBufferFilled+=offset;
2122 if (bAddComponentTableEntry) {
2123 int offset=AddComponentTableEntry(fOutputBlocks, fpOutputBuffer, fOutputBufferSize, fOutputBufferFilled, parentComponentTables, processingLevel);
2124 if (offset>0) size+=offset;
2126 if (forwardedBlocks.size()>0) {
2127 fOutputBlocks.insert(fOutputBlocks.end(), forwardedBlocks.begin(), forwardedBlocks.end());
2129 iResult=MakeOutputDataBlockList(fOutputBlocks, &outputBlockCnt, &outputBlocks);
2130 size=fOutputBufferFilled;
2134 // Low Level interface
2135 if (blockData.empty() && size!=0) {
2136 // set the size to zero because there is no announced data
2137 //HLTWarning("no output blocks added by component but output buffer filled %d of %d", size, fOutputBufferSize);
2141 if (compStats.size()>0) {
2142 int offset=AddComponentStatistics(blockData, fpOutputBuffer, fOutputBufferSize, size, compStats);
2143 if (offset>0) size+=offset;
2145 if (bAddComponentTableEntry) {
2146 int offset=AddComponentTableEntry(blockData, fpOutputBuffer, fOutputBufferSize, size, parentComponentTables, processingLevel);
2147 if (offset>0) size+=offset;
2149 if (forwardedBlocks.size()>0) {
2150 blockData.insert(blockData.end(), forwardedBlocks.begin(), forwardedBlocks.end());
2152 iResult=MakeOutputDataBlockList(blockData, &outputBlockCnt, &outputBlocks);
2155 HLTFatal("component %s (%p): can not convert output block descriptor list", GetComponentID(), this);
2158 if (iResult<0 || bSkipDataProcessing) {
2162 CleanupInputObjects();
2163 if (iResult>=0 && IsDataEvent()) {
2164 IncrementEventCounter();
2166 if (outputBlockCnt==0) {
2167 // no output blocks, set size to 0
2171 // reset the internal EventData struct
2172 FillEventData(fCurrentEventData);
2174 // reset the active triggers
2175 if (fpCTPData) fpCTPData->SetTriggers(0);
2177 // set the time for the pushback period
2178 if (fPushbackPeriod>0) {
2179 // suppress the output
2181 if (fLastPushBackTime<0) {
2182 // choose a random offset at beginning to equalize traffic for multiple instances
2184 gRandom->SetSeed(fChainIdCrc);
2185 fLastPushBackTime=time.Get();
2186 fLastPushBackTime-=gRandom->Integer(fPushbackPeriod);
2187 } else if ((int)time.Get()-fLastPushBackTime>=fPushbackPeriod) {
2188 fLastPushBackTime=time.Get();
2195 int AliHLTComponent::AddComponentStatistics(AliHLTComponentBlockDataList& blocks,
2196 AliHLTUInt8_t* buffer,
2197 AliHLTUInt32_t bufferSize,
2198 AliHLTUInt32_t offset,
2199 AliHLTComponentStatisticsList& stats) const
2201 // see header file for function documentation
2203 if ((fFlags&kDisableComponentStat)!=0) return 0;
2204 #if defined(HLT_COMPONENT_STATISTICS)
2205 if (stats.size()==0) return -ENOENT;
2206 // check if there is space for at least one entry
2207 if (offset+sizeof(AliHLTComponentStatistics)>bufferSize) return 0;
2208 stats[0].fTotalOutputSize=offset;
2209 stats[0].fOutputBlockCount=blocks.size();
2211 fpBenchmark->Stop();
2212 stats[0].fTime=(AliHLTUInt32_t)(fpBenchmark->RealTime()*ALIHLTCOMPONENT_STATTIME_SCALER);
2213 stats[0].fCTime=(AliHLTUInt32_t)(fpBenchmark->CpuTime()*ALIHLTCOMPONENT_STATTIME_SCALER);
2214 fpBenchmark->Continue();
2217 sort(stats.begin(), stats.end(), SortComponentStatisticsDescendingByLevel);
2219 // shrink the number of entries if the buffer is too small
2220 if (offset+stats.size()*sizeof(AliHLTComponentStatistics)>bufferSize) {
2221 unsigned originalSize=stats.size();
2222 AliHLTUInt32_t removedLevel=0;
2224 // remove all entries of the level of the last entry
2225 removedLevel=stats.back().fLevel;
2226 AliHLTComponentStatisticsList::iterator element=stats.begin();
2228 while (element!=stats.end()) {
2229 if (element->fLevel<=removedLevel) {
2230 element=stats.erase(element);
2235 } while (stats.size()>1 &&
2236 (offset+stats.size()*sizeof(AliHLTComponentStatistics)>bufferSize));
2237 HLTWarning("too little space in output buffer to add block of %d statistics entries (size %d), available %d, removed %d entries",
2238 originalSize, sizeof(AliHLTComponentStatistics), bufferSize-offset, originalSize-stats.size());
2240 HLTDebug("adding block of %d statistics entries", stats.size());
2242 assert(stats.size()>0);
2243 if (stats.size()==0) return 0;
2245 if (offset+stats.size()*sizeof(AliHLTComponentStatistics)<=bufferSize) {
2246 AliHLTComponentBlockData bd;
2247 FillBlockData( bd );
2248 bd.fOffset = offset;
2249 bd.fSize = stats.size()*sizeof(AliHLTComponentStatistics);
2250 bd.fDataType = kAliHLTDataTypeComponentStatistics;
2251 bd.fSpecification = fChainIdCrc;
2252 memcpy(buffer+offset, &(stats[0]), bd.fSize);
2253 blocks.push_back(bd);
2257 if (blocks.size() && buffer && bufferSize && offset && stats.size()) {
2258 // get rid of warning
2260 #endif // HLT_COMPONENT_STATISTICS
2264 int AliHLTComponent::AddComponentTableEntry(AliHLTComponentBlockDataList& blocks,
2265 AliHLTUInt8_t* buffer,
2266 AliHLTUInt32_t bufferSize,
2267 AliHLTUInt32_t offset,
2268 const vector<AliHLTUInt32_t>& parents,
2269 int processingLevel) const
2271 // see header file for function documentation
2273 if ((fFlags&kDisableComponentStat)!=0) return 0;
2274 #if defined(HLT_COMPONENT_STATISTICS)
2275 // the payload consists of the AliHLTComponentTableEntry struct,
2276 // followed by a an array of 32bit crc chain ids and the component
2277 // description string
2278 unsigned int payloadSize=sizeof(AliHLTComponentTableEntry);
2279 payloadSize+=parents.size()*sizeof(AliHLTUInt32_t);
2281 // the component description has the following format:
2282 // chain-id{component-id:arguments}
2283 const char* componentId=const_cast<AliHLTComponent*>(this)->GetComponentID();
2284 unsigned int descriptionSize=fChainId.size()+1;
2285 descriptionSize+=2; // the '{}' around the component id
2286 descriptionSize+=strlen(componentId);
2287 descriptionSize+=1; // the ':' between component id and arguments
2288 descriptionSize+=fComponentArgs.size();
2290 payloadSize+=descriptionSize;
2291 if (buffer && (offset+payloadSize<=bufferSize)) {
2292 AliHLTUInt8_t* pTgt=buffer+offset;
2293 memset(pTgt, 0, payloadSize);
2296 AliHLTComponentTableEntry* pEntry=reinterpret_cast<AliHLTComponentTableEntry*>(pTgt);
2297 pEntry->fStructSize=sizeof(AliHLTComponentTableEntry);
2298 pEntry->fLevel=processingLevel>=0?processingLevel:0;
2299 pEntry->fNofParents=parents.size();
2300 pEntry->fSizeDescription=descriptionSize;
2301 pTgt=pEntry->fBuffer;
2303 // write array of parents
2304 if (parents.size()>0) {
2305 unsigned int copy=parents.size()*sizeof(vector<AliHLTUInt32_t>::value_type);
2306 memcpy(pTgt, &parents[0], parents.size()*sizeof(vector<AliHLTUInt32_t>::value_type));
2310 // write component description
2311 memcpy(pTgt, fChainId.c_str(), fChainId.size());
2312 pTgt+=fChainId.size();
2314 memcpy(pTgt, componentId, strlen(componentId));
2315 pTgt+=strlen(componentId);
2317 memcpy(pTgt, fComponentArgs.c_str(), fComponentArgs.size());
2318 pTgt+=fComponentArgs.size();
2322 AliHLTComponentBlockData bd;
2323 FillBlockData( bd );
2324 bd.fOffset = offset;
2325 bd.fSize = payloadSize;
2326 bd.fDataType = kAliHLTDataTypeComponentTable;
2327 bd.fSpecification = fChainIdCrc;
2328 blocks.push_back(bd);
2332 if (blocks.size() && buffer && bufferSize && offset && parents.size() && processingLevel) {
2333 // get rid of warning
2335 #endif // HLT_COMPONENT_STATISTICS
2339 AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard()
2344 // standard constructor (not for use)
2347 AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(TStopwatch* pStopwatch)
2349 fpStopwatch(pStopwatch),
2354 // check for already existing guard
2355 if (fgpCurrent) fpPrec=fgpCurrent;
2358 // stop the preceeding guard if it controls a different stopwatch
2360 if (fpPrec && fpPrec!=this) bStart=fpPrec->Hold(fpStopwatch);
2362 // start the stopwatch if the current guard controls a different one
2363 if (fpStopwatch && bStart==1) fpStopwatch->Start(kFALSE);
2366 AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(const AliHLTStopwatchGuard&)
2372 // copy constructor not for use
2376 AliHLTComponent::AliHLTStopwatchGuard& AliHLTComponent::AliHLTStopwatchGuard::operator=(const AliHLTStopwatchGuard& other)
2379 // assignment operator not for use
2381 if (this==&other) return *this;
2387 AliHLTComponent::AliHLTStopwatchGuard* AliHLTComponent::AliHLTStopwatchGuard::fgpCurrent=NULL;
2389 AliHLTComponent::AliHLTStopwatchGuard::~AliHLTStopwatchGuard()
2393 // resume the preceeding guard if it controls a different stopwatch
2395 if (fpPrec && fpPrec!=this) bStop=fpPrec->Resume(fpStopwatch);
2397 // stop the stopwatch if the current guard controls a different one
2398 if (fpStopwatch && bStop==1) fpStopwatch->Stop();
2400 // resume to the preceeding guard
2404 int AliHLTComponent::AliHLTStopwatchGuard::Hold(const TStopwatch* pSucc)
2406 // see header file for function documentation
2407 if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Stop();
2408 return fpStopwatch!=pSucc?1:0;
2411 int AliHLTComponent::AliHLTStopwatchGuard::Resume(const TStopwatch* pSucc)
2413 // see header file for function documentation
2414 if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Start(kFALSE);
2415 return fpStopwatch!=pSucc?1:0;
2418 int AliHLTComponent::SetStopwatch(TObject* pSW, AliHLTStopwatchType type)
2420 // see header file for function documentation
2422 if (pSW!=NULL && type<kSWTypeCount) {
2423 if (fpStopwatches) {
2424 TObject* pObj=fpStopwatches->At((int)type);
2425 if (pSW==NULL // explicit reset
2426 || pObj==NULL) { // explicit set
2427 fpStopwatches->AddAt(pSW, (int)type);
2428 } else if (pObj!=pSW) {
2429 HLTWarning("stopwatch %d already set, reset first", (int)type);
2439 int AliHLTComponent::SetStopwatches(TObjArray* pStopwatches)
2441 // see header file for function documentation
2442 if (pStopwatches==NULL) return -EINVAL;
2445 for (int i=0 ; i<(int)kSWTypeCount && pStopwatches->GetEntriesFast(); i++)
2446 SetStopwatch(pStopwatches->At(i), (AliHLTStopwatchType)i);
2450 AliHLTUInt32_t AliHLTComponent::GetRunNo() const
2452 // see header file for function documentation
2454 // 2010-02-11 OCDB is now the reliable source for the run number, it is
2455 // initialized either by aliroot or the external interface depending
2456 // on the environment. It turned out that the rundescriptor is not set
2457 // in the aliroot mode, resulting in an invalid run number. However this
2458 // did not cause problems until now. OCDB initialization has been revised
2459 // already in 10/2009. This was a remnant.
2460 // Have to check whether we get rid of the rundescriptor at some point.
2461 if (fpRunDesc==NULL) return AliHLTMisc::Instance().GetCDBRunNo();
2462 if (fpRunDesc->fRunNo!=(unsigned)AliHLTMisc::Instance().GetCDBRunNo()) {
2463 HLTWarning("run number mismatch: ocdb %d run descriptor %d", AliHLTMisc::Instance().GetCDBRunNo(), fpRunDesc->fRunNo);
2465 return fpRunDesc->fRunNo;
2468 AliHLTUInt32_t AliHLTComponent::GetRunType() const
2470 // see header file for function documentation
2471 if (fpRunDesc==NULL) return kAliHLTVoidRunType;
2472 return fpRunDesc->fRunType;
2475 AliHLTUInt32_t AliHLTComponent::GetTimeStamp() const
2477 // see header file for function documentation
2478 if (fCurrentEventData.fEventCreation_s) {
2479 return fCurrentEventData.fEventCreation_s;
2481 // using the actual UTC if the time stamp was not set by the framework
2482 return static_cast<AliHLTUInt32_t>(time(NULL));
2485 AliHLTUInt32_t AliHLTComponent::GetPeriodNumber() const
2487 // see header file for function documentation
2488 return (GetEventId()>>36)&0xfffffff;
2491 AliHLTUInt32_t AliHLTComponent::GetOrbitNumber() const
2493 // see header file for function documentation
2494 return (GetEventId()>>12)&0xffffff;
2497 AliHLTUInt16_t AliHLTComponent::GetBunchCrossNumber() const
2499 // see header file for function documentation
2500 return GetEventId()&0xfff;
2503 bool AliHLTComponent::IsDataEvent(AliHLTUInt32_t* pTgt) const
2505 // see header file for function documentation
2506 if (pTgt) *pTgt=fEventType;
2507 return (fEventType==gkAliEventTypeData ||
2508 fEventType==gkAliEventTypeDataReplay);
2511 int AliHLTComponent::CopyStruct(void* pStruct, unsigned int iStructSize, unsigned int iBlockNo,
2512 const char* structname, const char* eventname)
2514 // see header file for function documentation
2516 if (pStruct!=NULL && iStructSize>sizeof(AliHLTUInt32_t)) {
2517 if (fpInputBlocks!=NULL && iBlockNo<fCurrentEventData.fBlockCnt) {
2518 AliHLTUInt32_t* pTgt=(AliHLTUInt32_t*)pStruct;
2519 if (fpInputBlocks[iBlockNo].fPtr && fpInputBlocks[iBlockNo].fSize) {
2520 AliHLTUInt32_t copy=*((AliHLTUInt32_t*)fpInputBlocks[iBlockNo].fPtr);
2521 if (fpInputBlocks[iBlockNo].fSize!=copy) {
2522 HLTWarning("%s event: mismatch of block size (%d) and structure size (%d)", eventname, fpInputBlocks[iBlockNo].fSize, copy);
2523 if (copy>fpInputBlocks[iBlockNo].fSize) copy=fpInputBlocks[iBlockNo].fSize;
2525 if (copy!=iStructSize) {
2526 HLTWarning("%s event: mismatch in %s version (data type version %d)", eventname, structname, ALIHLT_DATA_TYPES_VERSION);
2527 if (copy>iStructSize) {
2530 memset(pTgt, 0, iStructSize);
2533 memcpy(pTgt, fpInputBlocks[iBlockNo].fPtr, copy);
2537 HLTWarning("%s event: missing data block", eventname);
2543 HLTError("invalid struct");
2549 AliHLTUInt32_t AliHLTComponent::CalculateChecksum(const AliHLTUInt8_t* buffer, int size)
2551 // see header file for function documentation
2552 AliHLTUInt32_t remainder = 0;
2553 const AliHLTUInt8_t crcwidth=(8*sizeof(AliHLTUInt32_t));
2554 const AliHLTUInt32_t topbit=1 << (crcwidth-1);
2555 const AliHLTUInt32_t polynomial=0xD8; /* 11011 followed by 0's */
2558 // http://www.netrino.com/Embedded-Systems/How-To/CRC-Calculation-C-Code
2561 * Perform modulo-2 division, a byte at a time.
2563 for (int byte = 0; byte < size; ++byte)
2566 * Bring the next byte into the remainder.
2568 remainder ^= (buffer[byte] << (crcwidth - 8));
2571 * Perform modulo-2 division, a bit at a time.
2573 for (uint8_t bit = 8; bit > 0; --bit)
2576 * Try to divide the current data bit.
2578 if (remainder & topbit)
2580 remainder = (remainder << 1) ^ polynomial;
2584 remainder = (remainder << 1);
2590 * The final remainder is the CRC result.
2595 int AliHLTComponent::ExtractComponentTableEntry(const AliHLTUInt8_t* pBuffer, AliHLTUInt32_t size,
2596 string& retChainId, string& retCompId, string& retCompArgs,
2597 vector<AliHLTUInt32_t>& parents, int& level)
2599 // see header file for function documentation
2602 retCompArgs.clear();
2605 if (!pBuffer || size==0) return 0;
2607 const AliHLTComponentTableEntry* pEntry=reinterpret_cast<const AliHLTComponentTableEntry*>(pBuffer);
2608 if (size<8/* the initial size of the structure*/ ||
2609 pEntry==NULL || pEntry->fStructSize<8) return -ENOMSG;
2611 if (pEntry->fStructSize!=sizeof(AliHLTComponentTableEntry)) return -EBADF;
2612 level=pEntry->fLevel;
2613 const AliHLTUInt32_t* pParents=reinterpret_cast<const AliHLTUInt32_t*>(pEntry->fBuffer);
2614 const AliHLTUInt8_t* pEnd=pBuffer+size;
2616 if (pParents+pEntry->fNofParents>=reinterpret_cast<const AliHLTUInt32_t*>(pEnd)) return -ENODEV;
2617 for (unsigned int i=0; i<pEntry->fNofParents; i++, pParents++) {
2618 parents.push_back(*pParents);
2621 const char* pDescription=reinterpret_cast<const char*>(pParents);
2622 if (pDescription+pEntry->fSizeDescription>=reinterpret_cast<const char*>(pEnd) ||
2623 *(pDescription+pEntry->fSizeDescription)!=0) {
2627 TString descriptor=reinterpret_cast<const char*>(pDescription);
2631 TObjArray* pTokens=descriptor.Tokenize("{");
2634 if (pTokens->GetEntriesFast()>n) {
2635 retChainId=pTokens->At(n++)->GetName();
2637 if (pTokens->GetEntriesFast()>n) {
2638 compId=pTokens->At(n++)->GetName();
2642 if (!compId.IsNull() && (pTokens=compId.Tokenize(":"))!=NULL) {
2644 if (pTokens->GetEntriesFast()>n) {
2645 compId=pTokens->At(n++)->GetName();
2647 if (pTokens->GetEntriesFast()>n) {
2648 compArgs=pTokens->At(n++)->GetName();
2652 compId.ReplaceAll("}", "");
2653 compArgs.ReplaceAll("}", "");
2656 retCompArgs=compArgs;
2658 if (retChainId.size()==0) return -ENODATA;
2663 int AliHLTComponent::ExtractTriggerData(
2664 const AliHLTComponentTriggerData& trigData,
2665 const AliHLTUInt8_t (**attributes)[gkAliHLTBlockDAttributeCount],
2666 AliHLTUInt64_t* status,
2667 const AliRawDataHeader** cdh,
2668 AliHLTReadoutList* readoutlist,
2672 // see header file for function documentation
2674 // Check that the trigger data structure is the correct size.
2675 if (trigData.fStructSize != sizeof(AliHLTComponentTriggerData))
2680 log.LoggingVarargs(kHLTLogError, Class_Name(), FUNCTIONNAME(), __FILE__, __LINE__,
2681 "Invalid trigger structure size: %d but expected %d.", trigData.fStructSize, sizeof(AliHLTComponentTriggerData)
2687 // Get the size of the AliHLTEventTriggerData structure without the readout list part.
2688 // The way we do this here should also handle memory alignment correctly.
2689 AliHLTEventTriggerData* dummy = NULL;
2690 size_t sizeWithoutReadout = (char*)(&dummy->fReadoutList) - (char*)(dummy);
2692 // Check that the trigger data pointer points to data of a size we can handle.
2693 // Either it is the size of AliHLTEventTriggerData or the size of the old
2694 // version of AliHLTEventTriggerData using AliHLTEventDDLV0.
2695 if (trigData.fDataSize != sizeof(AliHLTEventTriggerData) and
2696 trigData.fDataSize != sizeWithoutReadout + sizeof(AliHLTEventDDLV0)
2702 log.LoggingVarargs(kHLTLogError, Class_Name(), FUNCTIONNAME(), __FILE__, __LINE__,
2703 "Invalid trigger data size: %d but expected %d.", trigData.fDataSize, sizeof(AliHLTEventTriggerData)
2709 AliHLTEventTriggerData* evtData = reinterpret_cast<AliHLTEventTriggerData*>(trigData.fData);
2710 assert(evtData != NULL);
2712 // Check that the CDH has 8 words.
2713 if (cdh != NULL and evtData->fCommonHeaderWordCnt != 8)
2718 log.LoggingVarargs(kHLTLogError, Class_Name(), FUNCTIONNAME(), __FILE__, __LINE__,
2719 "Common Data Header (CDH) has wrong number of data words: %d but expected %d",
2720 evtData->fCommonHeaderWordCnt, sizeof(AliRawDataHeader)/sizeof(AliHLTUInt32_t)
2726 // Check that the readout list has the correct count of words. i.e. something we can handle,
2727 if (readoutlist != NULL and
2728 evtData->fReadoutList.fCount != (unsigned)gkAliHLTDDLListSizeV0 and
2729 evtData->fReadoutList.fCount != (unsigned)gkAliHLTDDLListSizeV1
2735 log.LoggingVarargs(kHLTLogError, Class_Name(), FUNCTIONNAME(), __FILE__, __LINE__,
2736 "Readout list structure has wrong number of data words: %d but expected %d",
2737 evtData->fReadoutList.fCount, gkAliHLTDDLListSize
2743 if (attributes != NULL)
2745 *attributes = &evtData->fAttributes;
2749 *status = evtData->fHLTStatus;
2753 const AliRawDataHeader* cdhptr = reinterpret_cast<const AliRawDataHeader*>(&evtData->fCommonHeader[0]);
2756 if (readoutlist != NULL)
2758 *readoutlist = AliHLTReadoutList(evtData->fReadoutList);
2763 AliHLTUInt32_t AliHLTComponent::ExtractEventTypeFromCDH(const AliRawDataHeader* cdh)
2765 // see header file for function documentation
2767 UChar_t l1msg = cdh->GetL1TriggerMessage();
2768 if ((l1msg & 0x1) == 0x0) return gkAliEventTypeData;
2769 // The L2SwC bit must be one if we got here, i.e. l1msg & 0x1 == 0x1.
2770 if (((l1msg >> 2) & 0xF) == 0xE) return gkAliEventTypeStartOfRun;
2771 if (((l1msg >> 2) & 0xF) == 0xF) return gkAliEventTypeEndOfRun;
2772 // Check the C1T bit to see if this is a calibration event,
2773 // if not then it must be some other software trigger event.
2774 if (((l1msg >> 6) & 0x1) == 0x1) return gkAliEventTypeCalibration;
2775 return gkAliEventTypeSoftware;
2778 int AliHLTComponent::LoggingVarargs(AliHLTComponentLogSeverity severity,
2779 const char* originClass, const char* originFunc,
2780 const char* file, int line, ... ) const
2782 // see header file for function documentation
2786 va_start(args, line);
2788 // logging function needs to be const in order to be called from const member functions
2789 // without problems. But at this point we face the problem with virtual members which
2790 // are not necessarily const.
2791 AliHLTComponent* nonconst=const_cast<AliHLTComponent*>(this);
2792 AliHLTLogging::SetLogString(this, ", %p", "%s (%s_pfmt_): ",
2793 fChainId[0]!=0?fChainId.c_str():nonconst->GetComponentID(),
2794 nonconst->GetComponentID());
2795 iResult=SendMessage(severity, originClass, originFunc, file, line, AliHLTLogging::BuildLogString(NULL, args, true /*append*/));
2801 TUUID AliHLTComponent::GenerateGUID()
2803 // Generates a globally unique identifier.
2805 // Start by creating a new UUID. We cannot use the one automatically generated
2806 // by ROOT because the algorithm used will not guarantee unique IDs when generating
2807 // these UUIDs at a high rate in parallel.
2809 // We then use the generated UUID to form part of the random number seeds which
2810 // will be used to generate a proper random UUID. For good measure we use a MD5
2811 // hash also. Note that we want to use the TUUID class because it will combine the
2812 // host address information into the UUID. Using gSystem->GetHostByName() apparently
2813 // can cause problems on Windows machines with a firewall, because it always tries
2814 // to contact a DNS. The TUUID class handles this case appropriately.
2823 md5.Update(buf, sizeof(buf));
2826 dword[0] += gSystem->GetUid();
2827 dword[1] += gSystem->GetGid();
2828 dword[2] += gSystem->GetPid();
2829 for (int i = 0; i < 4; ++i)
2831 gRandom->SetSeed(dword[i]);
2832 dword[i] = gRandom->Integer(0xFFFFFFFF);
2834 md52.Update(buf, sizeof(buf));
2836 // To keep to the standard we need to set the version and reserved bits.
2837 word[3] = (word[3] & 0x0FFF) | 0x4000;
2838 buf[8] = (buf[8] & 0x3F) | 0x80;
2840 // Create the name of the new class and file.
2842 sprintf(uuidstr, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
2843 dword[0], word[2], word[3], buf[8], buf[9], buf[10], buf[11], buf[12], buf[13], buf[14], buf[15]
2846 uuid.SetUUID(uuidstr);
2850 int AliHLTComponent::ScanECSParam(const char* ecsParam)
2852 // see header file for function documentation
2854 // format of the parameter string from ECS
2855 // <command>;<parameterkey>=<parametervalue>;<parameterkey>=<parametervalue>;...
2856 // search for a subset of the parameterkeys
2860 // CTP_TRIGGER_CLASS=
2861 // DATA_FORMAT_VERSION=
2863 // HLT_OUT_DDL_LIST=
2864 // HLT_TRIGGER_CODE=
2867 // The command apears not to be sent by the online framework
2869 TString string=ecsParam;
2870 TObjArray* parameter=string.Tokenize(";");
2872 for (int i=0; i<parameter->GetEntriesFast(); i++) {
2873 TString entry=parameter->At(i)->GetName();
2874 HLTDebug("scanning ECS entry: %s", entry.Data());
2875 TObjArray* entryParams=entry.Tokenize("=");
2877 if (entryParams->GetEntriesFast()>1) {
2878 if ((((TObjString*)entryParams->At(0))->GetString()).CompareTo("CTP_TRIGGER_CLASS")==0) {
2879 int result=InitCTPTriggerClasses(entryParams->At(1)->GetName());
2880 if (iResult>=0 && result<0) iResult=result;
2882 // TODO: scan the other parameters
2883 // e.g. consistency check of run number
2895 int AliHLTComponent::SetupCTPData()
2897 // see header file for function documentation
2898 if (fpCTPData) delete fpCTPData;
2899 fpCTPData=new AliHLTCTPData;
2900 if (!fpCTPData) return -ENOMEM;
2904 int AliHLTComponent::InitCTPTriggerClasses(const char* ctpString)
2906 // see header file for function documentation
2907 if (!fpCTPData) return 0; // silently accept as the component has to announce that it want's the CTP info
2908 return fpCTPData->InitCTPTriggerClasses(ctpString);
2911 bool AliHLTComponent::EvaluateCTPTriggerClass(const char* expression, AliHLTComponentTriggerData& trigData) const
2913 // see header file for function documentation
2915 static bool bWarningThrown=false;
2916 if (!bWarningThrown) HLTError("Trigger classes not initialized, use SetupCTPData from DoInit()");
2917 bWarningThrown=true;
2921 return fpCTPData->EvaluateCTPTriggerClass(expression, trigData);
2924 int AliHLTComponent::CheckCTPTrigger(const char* name) const
2926 // see header file for function documentation
2928 static bool bWarningThrown=false;
2929 if (!bWarningThrown) HLTError("Trigger classes not initialized, use SetupCTPData from DoInit()");
2930 bWarningThrown=true;
2934 return fpCTPData->CheckTrigger(name);
2937 Double_t AliHLTComponent::GetBz()
2940 return AliHLTMisc::Instance().GetBz();
2943 Double_t AliHLTComponent::GetBz(const Double_t *r)
2945 // Returns Bz (kG) at the point "r" .
2946 return AliHLTMisc::Instance().GetBz(r);
2949 void AliHLTComponent::GetBxByBz(const Double_t r[3], Double_t b[3])
2951 // Returns Bx, By and Bz (kG) at the point "r" .
2952 AliHLTMisc::Instance().GetBxByBz(r, b);