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)
32 //#include "AliHLTStdIncludes.h"
33 #include "AliHLTComponent.h"
34 #include "AliHLTComponentHandler.h"
35 #include "AliHLTMessage.h"
36 #include "AliHLTCTPData.h"
37 #include "AliHLTErrorGuard.h"
38 #include "AliRawDataHeader.h"
41 #include "TObjArray.h"
42 #include "TObjectTable.h"
44 #include "TStopwatch.h"
49 #include "AliHLTMemoryFile.h"
50 #include "AliHLTMisc.h"
56 * default compression level for ROOT objects
58 #define ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION 5
59 #define ALIHLTCOMPONENT_STATTIME_SCALER 1000000
61 /** ROOT macro for the implementation of ROOT specific class methods */
62 ClassImp(AliHLTComponent);
64 /** stopwatch macro using the stopwatch guard */
65 #define ALIHLTCOMPONENT_STOPWATCH(type) AliHLTStopwatchGuard swguard(fpStopwatches!=NULL?reinterpret_cast<TStopwatch*>(fpStopwatches->At((int)type)):NULL)
66 //#define ALIHLTCOMPONENT_STOPWATCH(type)
68 /** stopwatch macro for operations of the base class */
69 #define ALIHLTCOMPONENT_BASE_STOPWATCH() ALIHLTCOMPONENT_STOPWATCH(kSWBase)
70 /** stopwatch macro for operations of the detector algorithm (DA) */
71 #define ALIHLTCOMPONENT_DA_STOPWATCH() ALIHLTCOMPONENT_STOPWATCH(kSWDA)
73 AliHLTComponent::AliHLTComponent()
81 fCurrentInputBlock(-1),
82 fSearchDataType(kAliHLTVoidDataType),
87 fOutputBufferFilled(0),
89 fpStopwatches(new TObjArray(kSWTypeCount)),
92 fCDBSetRunNoFunc(false),
97 fEventType(gkAliEventTypeUnknown),
100 fEventDoneDataSize(0),
101 fCompressionLevel(ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION)
105 , fLastPushBackTime(-1)
107 // see header file for class documentation
109 // refer to README to build package
111 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
112 memset(&fEnvironment, 0, sizeof(AliHLTAnalysisEnvironment));
113 if (fgpComponentHandler)
114 fgpComponentHandler->ScheduleRegister(this);
115 //SetLocalLoggingLevel(kHLTLogDefault);
118 AliHLTComponent::~AliHLTComponent()
120 // see header file for function documentation
121 if (fpBenchmark) delete fpBenchmark;
124 CleanupInputObjects();
125 if (fpStopwatches!=NULL) delete fpStopwatches;
127 AliHLTMemoryFilePList::iterator element=fMemFiles.begin();
128 while (element!=fMemFiles.end()) {
130 if ((*element)->IsClosed()==0) {
131 HLTWarning("memory file has not been closed, possible data loss or incomplete buffer");
132 // close but do not flush as we dont know whether the buffer is still valid
133 (*element)->CloseMemoryFile(0);
145 delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
154 AliHLTComponentHandler* AliHLTComponent::fgpComponentHandler=NULL;
156 int AliHLTComponent::SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite)
158 // see header file for function documentation
160 if (fgpComponentHandler==NULL || bOverwrite!=0)
161 fgpComponentHandler=pCH;
167 int AliHLTComponent::UnsetGlobalComponentHandler()
169 // see header file for function documentation
170 return SetGlobalComponentHandler(NULL,1);
173 int AliHLTComponent::SetComponentEnvironment(const AliHLTAnalysisEnvironment* comenv, void* environParam)
175 // see header file for function documentation
176 HLTLogKeyword(fChainId.c_str());
179 memset(&fEnvironment, 0, sizeof(AliHLTAnalysisEnvironment));
180 memcpy(&fEnvironment, comenv, comenv->fStructSize<sizeof(AliHLTAnalysisEnvironment)?comenv->fStructSize:sizeof(AliHLTAnalysisEnvironment));
181 fEnvironment.fStructSize=sizeof(AliHLTAnalysisEnvironment);
182 fEnvironment.fParam=environParam;
187 int AliHLTComponent::Init(const AliHLTAnalysisEnvironment* comenv, void* environParam, int argc, const char** argv )
189 // see header file for function documentation
190 HLTLogKeyword(fChainId.c_str());
193 SetComponentEnvironment(comenv, environParam);
196 fLastPushBackTime=-1;
199 const char** pArguments=NULL;
204 pArguments=new const char*[argc];
206 for (int i=0; i<argc && iResult>=0; i++) {
207 if (fComponentArgs.size()>0) fComponentArgs+=" ";
208 fComponentArgs+=argv[i];
210 if (argument.IsNull()) continue;
213 if (argument.CompareTo("-benchmark")==0) {
216 } else if (argument.BeginsWith("-loglevel=")) {
217 TString parameter=argument.ReplaceAll("-loglevel=", "");
218 parameter.Remove(TString::kLeading, ' '); // remove all blanks
219 if (parameter.BeginsWith("0x") &&
220 parameter.Replace(0,2,"",0).IsHex()) {
221 unsigned int loglevel=kHLTLogNone;
222 sscanf(parameter.Data(),"%x", &loglevel);
223 SetLocalLoggingLevel((AliHLTComponentLogSeverity)loglevel);
225 HLTError("wrong parameter for argument %s, hex number expected", argument.Data());
228 // -object-compression=
229 } else if (argument.BeginsWith("-object-compression=")) {
230 argument.ReplaceAll("-object-compression=", "");
231 if (argument.IsDigit()) {
232 fCompressionLevel=argument.Atoi();
233 if (fCompressionLevel<0 || fCompressionLevel>9) {
234 HLTWarning("invalid compression level %d, setting to default %d", fCompressionLevel, ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION);
235 fCompressionLevel=ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION;
238 HLTError("wrong parameter for argument -object-compression, number expected");
241 } else if (argument.BeginsWith("-pushback-period=")) {
242 argument.ReplaceAll("-pushback-period=", "");
243 if (argument.IsDigit()) {
244 fPushbackPeriod=argument.Atoi();
246 HLTError("wrong parameter for argument -pushback-period, number expected");
248 // -disable-component-stat
249 } else if (argument.CompareTo("-disable-component-stat")==0) {
250 fFlags|=kDisableComponentStat;
252 pArguments[iNofChildArgs++]=argv[i];
260 HLTError("missing parameter for argument %s", argument.Data());
264 iResult=CheckOCDBEntries();
267 iResult=DoInit(iNofChildArgs, pArguments);
272 // find out if the component wants to get the steering events
274 AliHLTComponentDataTypeList inputDt;
275 GetInputDataTypes(inputDt);
276 bool bRequireSteeringBlocks=false;
277 for (AliHLTComponentDataTypeList::iterator dt=inputDt.begin();
278 dt!=inputDt.end() && !bRequireSteeringBlocks;
280 bRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeSOR);
281 bRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeRunType);
282 bRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeEOR);
283 bRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeDDL);
284 bRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeComponentStatistics);
286 if (bRequireSteeringBlocks) fFlags|=kRequireSteeringBlocks;
288 if (pArguments) delete [] pArguments;
290 #if defined(HLT_COMPONENT_STATISTICS)
291 // benchmarking stopwatch for the component statistics
292 fpBenchmark=new TStopwatch;
293 #endif // HLT_COMPONENT_STATISTICS
298 int AliHLTComponent::Deinit()
300 // see header file for function documentation
301 HLTLogKeyword(fChainId.c_str());
305 // TODO: the warning should be kept, but the condition is wrong since the
306 // AliHLTRunDesc is set before the SOR event in the SetRunDescription
307 // method. A couple of state flags should be defined but that is a bit more
308 // work to do. For the moment disable the warning (2009-07-01)
309 // 2009-09-08: now, the info is not cleared in the ProcessEvent, because it
310 // might be needed by components during the event processing.
311 //HLTWarning("did not receive EOR for run %d", fpRunDesc->fRunNo);
312 AliHLTRunDesc* pRunDesc=fpRunDesc;
326 int AliHLTComponent::InitCDB(const char* cdbPath, AliHLTComponentHandler* pHandler)
328 // see header file for function documentation
330 HLTInfo("Using CDB: %s", cdbPath);
332 // I have to think about separating the library handling from the
333 // component handler. Requiring the component handler here is not
334 // the cleanest solution.
335 // We presume the library already to be loaded, which is the case
336 // because it is loaded in the initialization of the logging functionality
339 AliHLTMiscInitCDB_t pFunc=(AliHLTMiscInitCDB_t)pHandler->FindSymbol(ALIHLTMISC_LIBRARY, ALIHLTMISC_INIT_CDB);
342 if (cdbPath && cdbPath[0]!=0) {
344 // very temporary fix, have to check for other formats
345 if (!path.BeginsWith("local://")) {
350 if ((iResult=(*pFunc)(path.Data()))>=0) {
351 if (!(fCDBSetRunNoFunc=pHandler->FindSymbol(ALIHLTMISC_LIBRARY, ALIHLTMISC_SET_CDB_RUNNO))) {
352 Message(NULL, kHLTLogWarning, "AliHLTComponent::InitCDB", "init CDB",
353 "can not find function to set CDB run no");
357 Message(NULL, kHLTLogError, "AliHLTComponent::InitCDB", "init CDB",
358 "can not find initialization function");
367 int AliHLTComponent::SetCDBRunNo(int runNo)
369 // see header file for function documentation
370 if (!fCDBSetRunNoFunc) return 0;
371 return (*((AliHLTMiscSetCDBRunNo_t)fCDBSetRunNoFunc))(runNo);
374 int AliHLTComponent::SetRunDescription(const AliHLTRunDesc* desc, const char* /*runType*/)
376 // see header file for function documentation
377 if (!desc) return -EINVAL;
378 if (desc->fStructSize!=sizeof(AliHLTRunDesc)) {
379 HLTError("invalid size of RunDesc struct (%ul)", desc->fStructSize);
384 fpRunDesc=new AliHLTRunDesc;
385 if (!fpRunDesc) return -ENOMEM;
386 *fpRunDesc=kAliHLTVoidRunDesc;
389 if (fpRunDesc->fRunNo!=kAliHLTVoidRunNo && fpRunDesc->fRunNo!=desc->fRunNo) {
390 HLTWarning("Run description has already been set");
393 SetCDBRunNo(fpRunDesc->fRunNo);
394 // TODO: we have to decide about the runType
398 int AliHLTComponent::SetComponentDescription(const char* desc)
400 // see header file for function documentation
404 TString descriptor=desc;
405 TObjArray* pTokens=descriptor.Tokenize(" ");
407 for (int i=0; i<pTokens->GetEntriesFast() && iResult>=0; i++) {
408 TString argument=pTokens->At(i++)->GetName();
409 if (!argument || argument.IsNull()) continue;
412 if (argument.BeginsWith("chainid")) {
413 argument.ReplaceAll("chainid", "");
414 if (argument.BeginsWith("=")) {
415 fChainId=argument.Replace(0,1,"");
416 fChainIdCrc=CalculateChecksum((const AliHLTUInt8_t*)fChainId.c_str(), fChainId.length());
417 HLTDebug("setting component description: chain id %s crc 0x%8x", fChainId.c_str(), fChainIdCrc);
422 HLTWarning("unknown component description %s", argument.Data());
431 int AliHLTComponent::ConfigureFromArgumentString(int argc, const char** argv)
433 // Configure from an array of argument strings
434 // Function supports individual arguments in the argv array and arguments
435 // separated by blanks.
437 // Each argv entry can contain blanks, quotes and newlines. Newlines are interpreted
438 // as blanks. Enclosing quotes deactivate blank as delimiter.
439 // The separated arguments are stored in an array of strings, and the pointers to
440 // those strings in an array of pointers. The latter is used in the custom argument
441 // scan of the component.
444 vector<string> stringarray; // array of argument copies
445 // array of pointers to the argument copies
446 // note: not necessarily in sync with the entries in stringarray
447 // can contain any pointer to valid arguments in arbitrary sequence
448 vector<const char*> ptrarray;
452 for (i=0; i<argc && iResult>=0; i++) {
454 if (argument.IsWhitespace()) continue;
456 // special handling for single component arguments ending with
457 // a sequence of blanks. All characters until the first occurence
458 // of a blank are removed. If the remainder contains only whitespaces
459 // the argument is a single argument, just having whitespaces at the end.
460 argument.Remove(0, argument.First(' '));
461 if (argument.IsWhitespace()) {
462 ptrarray.push_back(argv[i]);
466 // outer loop checks for enclosing quotes
467 // extra blank to insert blank token before leading quotes, then
468 // quoted arguments are always the even ones
471 // insert blank in consecutive quotes to correctly tokenize
472 argument.ReplaceAll("''", "' '");
473 // replace newlines by blanks
474 argument.ReplaceAll("\n", " ");
475 if (argument.IsNull()) continue;
476 TObjArray* pTokensQuote=argument.Tokenize("'");
478 if (pTokensQuote->GetEntriesFast()>0) {
479 for (int k=0; k<pTokensQuote->GetEntriesFast(); k++) {
480 argument=pTokensQuote->At(k)->GetName();
481 if (argument.IsWhitespace()) continue;
483 // every second entry is enclosed by quotes and thus
484 // one single argument
485 stringarray.push_back(argument.Data());
486 ptrarray.push_back(stringarray.back().c_str());
488 TObjArray* pTokens=argument.Tokenize(" ");
490 if (pTokens->GetEntriesFast()>0) {
491 for (int n=0; n<pTokens->GetEntriesFast(); n++) {
492 TString data=pTokens->At(n)->GetName();
493 if (!data.IsNull() && !data.IsWhitespace()) {
494 stringarray.push_back(data.Data());
495 ptrarray.push_back(stringarray.back().c_str());
508 for (i=0; (unsigned)i<ptrarray.size() && iResult>=0;) {
509 int result=ScanConfigurationArgument(ptrarray.size()-i, &ptrarray[i]);
511 HLTWarning("unknown component argument %s", ptrarray[i]);
513 } else if (result>0) {
517 if (iResult==-EINVAL) {
518 HLTError("unknown argument %s", ptrarray[i]);
519 } else if (iResult==-EPROTO) {
520 HLTError("missing/wrong parameter for argument %s (%s)", ptrarray[i], (ptrarray.size()>(unsigned)i+1)?ptrarray[i+1]:"missing");
522 HLTError("scan of argument %s failed (%d)", ptrarray[i], iResult);
530 int AliHLTComponent::ConfigureFromCDBTObjString(const char* entries, const char* key)
532 // load a list of OCDB objects and configure from the objects
533 // can either be a TObjString or a TMap with a TObjString:TObjString key-value pair
536 TString confEntries=entries;
537 TObjArray* pTokens=confEntries.Tokenize(" ");
539 for (int n=0; n<pTokens->GetEntriesFast(); n++) {
540 const char* path=pTokens->At(n)->GetName();
541 const char* chainId=GetChainId();
542 HLTInfo("configure from entry \"%s\"%s%s, chain id %s", path, key?" key ":"",key?key:"", (chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
543 TObject* pOCDBObject = LoadAndExtractOCDBObject(path, key);
545 TObjString* pString=dynamic_cast<TObjString*>(pOCDBObject);
547 TMap* pMap=dynamic_cast<TMap*>(pOCDBObject);
549 // this is the case where no key has been specified and the OCDB
550 // object is a TMap, search for the default key
551 TObject* pObject=pMap->GetValue("default");
552 if (pObject && (pString=dynamic_cast<TObjString*>(pObject))!=NULL) {
553 HLTInfo("using default key of TMap of configuration object \"%s\"", path);
555 HLTError("no default key available in TMap of configuration object \"%s\"", path);
563 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
564 arguments+=pString->GetString().Data();
567 HLTError("configuration object \"%s\"%s%s has wrong type, required TObjString", path, key?" key ":"",key?key:"");
571 HLTError("can not fetch object \"%s\" from OCDB", path);
577 if (iResult>=0 && !arguments.IsNull()) {
578 const char* array=arguments.Data();
579 iResult=ConfigureFromArgumentString(1, &array);
584 TObject* AliHLTComponent::LoadAndExtractOCDBObject(const char* path, int version, int subVersion, const char* key) const
586 // see header file for function documentation
587 AliCDBEntry* pEntry=AliHLTMisc::Instance().LoadOCDBEntry(path, GetRunNo(), version, subVersion);
588 if (!pEntry) return NULL;
589 TObject* pObject=AliHLTMisc::Instance().ExtractObject(pEntry);
590 TMap* pMap=dynamic_cast<TMap*>(pObject);
592 pObject=pMap->GetValue(key);
594 pObject=pMap->GetValue("default");
596 HLTWarning("can not find object for key \"%s\" in TMap of configuration object \"%s\", using key \"default\"", key, path);
600 HLTError("can not find object for key \"%s\" in TMap of configuration object \"%s\"", key, path);
607 int AliHLTComponent::DoInit( int /*argc*/, const char** /*argv*/)
609 // default implementation, childs can overload
610 HLTLogKeyword("dummy");
614 int AliHLTComponent::DoDeinit()
616 // default implementation, childs can overload
617 HLTLogKeyword("dummy");
621 int AliHLTComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/)
623 // default implementation, childs can overload
624 HLTLogKeyword("dummy");
628 int AliHLTComponent::ReadPreprocessorValues(const char* /*modules*/)
630 // default implementation, childs can overload
631 HLTLogKeyword("dummy");
635 int AliHLTComponent::ScanConfigurationArgument(int /*argc*/, const char** /*argv*/)
637 // default implementation, childs can overload
638 HLTLogKeyword("dummy");
639 HLTWarning("The function needs to be implemented by the component");
643 int AliHLTComponent::StartOfRun()
645 // default implementation, childs can overload
646 HLTLogKeyword("dummy");
650 int AliHLTComponent::EndOfRun()
652 // default implementation, childs can overload
653 HLTLogKeyword("dummy");
658 int AliHLTComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& /*tgtList*/)
660 // default implementation, childs can overload
661 HLTLogKeyword("dummy");
665 void AliHLTComponent::GetOCDBObjectDescription( TMap* const /*targetArray*/)
667 // default implementation, childs can overload
668 HLTLogKeyword("dummy");
671 int AliHLTComponent::CheckOCDBEntries(const TMap* const externList)
673 // check the availability of the OCDB entry descriptions in the TMap
674 // key : complete OCDB path of the entry
675 // value : auxiliary object - short description
676 // if the external map was not provided the function invokes
677 // interface function GetOCDBObjectDescription() to retrieve the list.
680 iResult=AliHLTMisc::Instance().CheckOCDBEntries(externList);
684 pMap->SetOwnerKeyValue(kTRUE);
685 GetOCDBObjectDescription(pMap);
686 iResult=AliHLTMisc::Instance().CheckOCDBEntries(pMap);
695 void AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2] ) const
697 // see header file for function documentation
698 memset( output, 0, kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2 );
699 strncat( output, type.fOrigin, kAliHLTComponentDataTypefOriginSize );
700 strncat( output, ":", 1 );
701 strncat( output, type.fID, kAliHLTComponentDataTypefIDsize );
704 string AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, int mode)
706 // see header file for function documentation
710 // aligned to 8 and 4 chars respectively, blocks enclosed in quotes and
711 // separated by blank e.g.
717 for (i=0; i<kAliHLTComponentDataTypefIDsize; i++) {
718 unsigned char* puc=(unsigned char*)type.fID;
720 sprintf(tmp, "\\%x", type.fID[i]);
722 sprintf(tmp, "%c", type.fID[i]);
726 for (i=0; i<kAliHLTComponentDataTypefOriginSize; i++) {
727 unsigned char* puc=(unsigned char*)type.fOrigin;
729 sprintf(tmp, "\\%x", type.fOrigin[i]);
731 sprintf(tmp, "%c", type.fOrigin[i]);
738 // origin typeid as numbers separated by colon e.g.
739 // aligned to 8 and 4 chars respectively, all characters separated by
741 // '84'80'67'32':'68'68'76'95'82'65'87'32'
745 for (i=0; i<kAliHLTComponentDataTypefOriginSize; i++) {
746 sprintf(tmp, "'%d", type.fOrigin[i]);
750 for (i=0; i<kAliHLTComponentDataTypefIDsize; i++) {
751 sprintf(tmp, "%d'", type.fID[i]);
757 // origin typeid separated by colon e.g.
758 // aligned to 8 and 4 chars respectively, all characters separated by
760 // 'T'P'C' ':'D'D'L'_'R'A'W' '
764 for (i=0; i<kAliHLTComponentDataTypefOriginSize; i++) {
765 unsigned char* puc=(unsigned char*)type.fOrigin;
767 sprintf(tmp, "'\\%x", type.fOrigin[i]);
769 sprintf(tmp, "'%c", type.fOrigin[i]);
773 for (i=0; i<kAliHLTComponentDataTypefIDsize; i++) {
774 unsigned char* puc=(unsigned char*)type.fID;
776 sprintf(tmp, "\\%x'", type.fID[i]);
778 sprintf(tmp, "%c'", type.fID[i]);
785 // aligned to 8 and 4 chars respectively, separated by colon e.g.
787 if (type==kAliHLTVoidDataType) {
790 // some gymnastics in order to avoid a '0' which is part of either or both
791 // ID and origin terminating the whole string. Unfortunately, string doesn't
792 // stop appending at the '0' if the number of elements to append was
793 // explicitely specified
795 tmp.append(type.fOrigin, kAliHLTComponentDataTypefOriginSize);
796 out.append(tmp.c_str());
799 tmp.append(type.fID, kAliHLTComponentDataTypefIDsize);
800 out.append(tmp.c_str());
806 void* AliHLTComponent::AllocMemory( unsigned long size )
808 // see header file for function documentation
809 if (fEnvironment.fAllocMemoryFunc)
810 return (*fEnvironment.fAllocMemoryFunc)(fEnvironment.fParam, size );
811 HLTFatal("no memory allocation handler registered");
815 int AliHLTComponent::MakeOutputDataBlockList( const AliHLTComponentBlockDataList& blocks, AliHLTUInt32_t* blockCount,
816 AliHLTComponentBlockData** outputBlocks )
818 // see header file for function documentation
819 if ( blockCount==NULL || outputBlocks==NULL )
821 AliHLTUInt32_t count = blocks.size();
825 *outputBlocks = NULL;
828 *outputBlocks = reinterpret_cast<AliHLTComponentBlockData*>( AllocMemory( sizeof(AliHLTComponentBlockData)*count ) );
829 if ( !*outputBlocks )
831 for ( unsigned long i = 0; i < count; i++ ) {
832 (*outputBlocks)[i] = blocks[i];
833 if (MatchExactly(blocks[i].fDataType, kAliHLTAnyDataType)) {
834 (*outputBlocks)[i].fDataType=GetOutputDataType();
835 /* data type was set to the output data type by the PubSub AliRoot
836 Wrapper component, if data type of the block was ********:****.
837 Now handled by the component base class in order to have same
838 behavior when running embedded in AliRoot
839 memset((*outputBlocks)[i].fDataType.fID, '*', kAliHLTComponentDataTypefIDsize);
840 memset((*outputBlocks)[i].fDataType.fOrigin, '*', kAliHLTComponentDataTypefOriginSize);
849 int AliHLTComponent::GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd ) const
851 // see header file for function documentation
852 if (fEnvironment.fGetEventDoneDataFunc)
853 return (*fEnvironment.fGetEventDoneDataFunc)(fEnvironment.fParam, fCurrentEvent, size, edd );
857 int AliHLTComponent::ReserveEventDoneData( unsigned long size )
859 // see header file for function documentation
862 unsigned long capacity=fEventDoneDataSize;
863 if (fEventDoneData) capacity-=sizeof(AliHLTComponentEventDoneData)+fEventDoneData->fDataSize;
865 unsigned long newSize=sizeof(AliHLTComponentEventDoneData)+size+(fEventDoneDataSize-capacity);
866 AliHLTComponentEventDoneData* newEDD = reinterpret_cast<AliHLTComponentEventDoneData*>( new AliHLTUInt8_t[newSize] );
869 newEDD->fStructSize = sizeof(AliHLTComponentEventDoneData);
870 newEDD->fDataSize = 0;
871 newEDD->fData = reinterpret_cast<AliHLTUInt8_t*>(newEDD)+newEDD->fStructSize;
872 if (fEventDoneData) {
873 memcpy( newEDD->fData, fEventDoneData->fData, fEventDoneData->fDataSize );
874 newEDD->fDataSize = fEventDoneData->fDataSize;
875 delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
877 fEventDoneData = newEDD;
878 fEventDoneDataSize = newSize;
884 int AliHLTComponent::PushEventDoneData( AliHLTUInt32_t eddDataWord )
886 // see header file for function documentation
889 if (fEventDoneData->fDataSize+sizeof(AliHLTUInt32_t)>fEventDoneDataSize)
891 *reinterpret_cast<AliHLTUInt32_t*>((reinterpret_cast<AliHLTUInt8_t*>(fEventDoneData->fData)+fEventDoneData->fDataSize)) = eddDataWord;
892 fEventDoneData->fDataSize += sizeof(AliHLTUInt32_t);
896 void AliHLTComponent::ReleaseEventDoneData()
898 // see header file for function documentation
900 delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
901 fEventDoneData = NULL;
902 fEventDoneDataSize = 0;
906 int AliHLTComponent::FindMatchingDataTypes(AliHLTComponent* pConsumer, AliHLTComponentDataTypeList* tgtList)
908 // see header file for function documentation
911 AliHLTComponentDataTypeList itypes;
912 AliHLTComponentDataTypeList otypes;
913 otypes.push_back(GetOutputDataType());
914 if (MatchExactly(otypes[0],kAliHLTMultipleDataType)) {
917 if ((count=GetOutputDataTypes(otypes))>0) {
918 } else if (GetComponentType()!=kSink) {
919 HLTWarning("component %s indicates multiple output data types but GetOutputDataTypes returns %d", GetComponentID(), count);
922 pConsumer->GetInputDataTypes(itypes);
923 AliHLTComponentDataTypeList::iterator otype=otypes.begin();
924 for (;otype!=otypes.end();otype++) {
925 //PrintDataTypeContent((*otype), "publisher \'%s\'");
926 if ((*otype)==(kAliHLTAnyDataType|kAliHLTDataOriginPrivate)) {
927 if (tgtList) tgtList->push_back(*otype);
932 AliHLTComponentDataTypeList::iterator itype=itypes.begin();
933 for ( ; itype!=itypes.end() && (*itype)!=(*otype) ; itype++) {/* empty body */};
934 //if (itype!=itypes.end()) PrintDataTypeContent(*itype, "consumer \'%s\'");
935 if (itype!=itypes.end()) {
936 if (tgtList) tgtList->push_back(*otype);
946 void AliHLTComponent::PrintDataTypeContent(AliHLTComponentDataType& dt, const char* format)
948 // see header file for function documentation
949 const char* fmt="\'%s\'";
950 if (format) fmt=format;
951 AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, Form(fmt, (DataType2Text(dt)).c_str()));
952 AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL,
953 Form("%x %x %x %x %x %x %x %x : %x %x %x %x",
968 void AliHLTComponent::FillBlockData( AliHLTComponentBlockData& blockData )
970 // see header file for function documentation
971 blockData.fStructSize = sizeof(blockData);
972 FillShmData( blockData.fShmKey );
973 blockData.fOffset = ~(AliHLTUInt32_t)0;
974 blockData.fPtr = NULL;
976 FillDataType( blockData.fDataType );
977 blockData.fSpecification = kAliHLTVoidDataSpec;
980 void AliHLTComponent::FillShmData( AliHLTComponentShmData& shmData )
982 // see header file for function documentation
983 shmData.fStructSize = sizeof(shmData);
984 shmData.fShmType = gkAliHLTComponentInvalidShmType;
985 shmData.fShmID = gkAliHLTComponentInvalidShmID;
988 void AliHLTComponent::FillDataType( AliHLTComponentDataType& dataType )
990 // see header file for function documentation
991 dataType=kAliHLTAnyDataType;
994 void AliHLTComponent::CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt)
996 // see header file for function documentation
997 memcpy(&tgtdt.fID[0], &srcdt.fID[0], kAliHLTComponentDataTypefIDsize);
998 memcpy(&tgtdt.fOrigin[0], &srcdt.fOrigin[0], kAliHLTComponentDataTypefOriginSize);
1001 void AliHLTComponent::SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin)
1003 // see header file for function documentation
1004 tgtdt.fStructSize=sizeof(AliHLTComponentDataType);
1006 memset(&tgtdt.fID[0], 0, kAliHLTComponentDataTypefIDsize);
1007 strncpy(&tgtdt.fID[0], id, strlen(id)<(size_t)kAliHLTComponentDataTypefIDsize?strlen(id):kAliHLTComponentDataTypefIDsize);
1010 memset(&tgtdt.fOrigin[0], 0, kAliHLTComponentDataTypefOriginSize);
1011 strncpy(&tgtdt.fOrigin[0], origin, strlen(origin)<(size_t)kAliHLTComponentDataTypefOriginSize?strlen(origin):kAliHLTComponentDataTypefOriginSize);
1015 void AliHLTComponent::SetDataType(AliHLTComponentDataType& dt, AliHLTUInt64_t id, AliHLTUInt32_t origin)
1017 // see header file for function documentation
1018 dt.fStructSize=sizeof(AliHLTComponentDataType);
1019 assert(kAliHLTComponentDataTypefIDsize==sizeof(id));
1020 assert(kAliHLTComponentDataTypefOriginSize==sizeof(origin));
1021 memcpy(&dt.fID, &id, kAliHLTComponentDataTypefIDsize);
1022 memcpy(&dt.fOrigin, &origin, kAliHLTComponentDataTypefOriginSize);
1025 void AliHLTComponent::FillEventData(AliHLTComponentEventData& evtData)
1027 // see header file for function documentation
1028 memset(&evtData, 0, sizeof(AliHLTComponentEventData));
1029 evtData.fStructSize=sizeof(AliHLTComponentEventData);
1030 evtData.fEventID=kAliHLTVoidEventID;
1033 void AliHLTComponent::PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt)
1035 // see header file for function documentation
1037 msg.Form("AliHLTComponentDataType(%d): ID=\"", dt.fStructSize);
1038 for ( int i = 0; i < kAliHLTComponentDataTypefIDsize; i++ ) {
1039 if (dt.fID[i]!=0) msg+=dt.fID[i];
1042 msg+="\" Origin=\"";
1043 for ( int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++ ) {
1044 if (dt.fOrigin[i]!=0) msg+=dt.fOrigin[i];
1048 AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, msg.Data());
1051 int AliHLTComponent::GetEventCount() const
1053 // see header file for function documentation
1057 int AliHLTComponent::IncrementEventCounter()
1059 // see header file for function documentation
1060 if (fEventCount>=0) fEventCount++;
1064 int AliHLTComponent::GetNumberOfInputBlocks() const
1066 // see header file for function documentation
1067 if (fpInputBlocks!=NULL) {
1068 return fCurrentEventData.fBlockCnt;
1073 AliHLTEventID_t AliHLTComponent::GetEventId() const
1075 // see header file for function documentation
1076 if (fpInputBlocks!=NULL) {
1077 return fCurrentEventData.fEventID;
1082 const TObject* AliHLTComponent::GetFirstInputObject(const AliHLTComponentDataType& dt,
1083 const char* classname,
1086 // see header file for function documentation
1087 ALIHLTCOMPONENT_BASE_STOPWATCH();
1089 if (classname) fClassName=classname;
1090 else fClassName.clear();
1091 int idx=FindInputBlock(fSearchDataType, 0, 1);
1094 HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(dt).c_str());
1095 if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) {
1096 fCurrentInputBlock=idx;
1103 const TObject* AliHLTComponent::GetFirstInputObject(const char* dtID,
1104 const char* dtOrigin,
1105 const char* classname,
1108 // see header file for function documentation
1109 ALIHLTCOMPONENT_BASE_STOPWATCH();
1110 AliHLTComponentDataType dt;
1111 SetDataType(dt, dtID, dtOrigin);
1112 return GetFirstInputObject(dt, classname, bForce);
1115 const TObject* AliHLTComponent::GetNextInputObject(int bForce)
1117 // see header file for function documentation
1118 ALIHLTCOMPONENT_BASE_STOPWATCH();
1119 int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1, 1);
1120 //HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(fSearchDataType).c_str());
1123 if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) {
1124 fCurrentInputBlock=idx;
1130 int AliHLTComponent::FindInputBlock(const AliHLTComponentDataType& dt, int startIdx, int bObject) const
1132 // see header file for function documentation
1133 int iResult=-ENOENT;
1134 if (fpInputBlocks!=NULL) {
1135 int idx=startIdx<0?0:startIdx;
1136 for ( ; (UInt_t)idx<fCurrentEventData.fBlockCnt && iResult==-ENOENT; idx++) {
1137 if (dt!=fpInputBlocks[idx].fDataType) continue;
1140 if (fpInputBlocks[idx].fPtr==NULL) continue;
1141 AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr);
1142 if (firstWord!=fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) continue;
1150 TObject* AliHLTComponent::CreateInputObject(int idx, int bForce)
1152 // see header file for function documentation
1154 if (fpInputBlocks!=NULL) {
1155 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
1156 if (fpInputBlocks[idx].fPtr) {
1157 AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr);
1158 if (firstWord==fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) {
1159 HLTDebug("create object from block %d size %d", idx, fpInputBlocks[idx].fSize);
1160 AliHLTMessage msg(fpInputBlocks[idx].fPtr, fpInputBlocks[idx].fSize);
1161 TClass* objclass=msg.GetClass();
1162 pObj=msg.ReadObject(objclass);
1163 if (pObj && objclass) {
1164 HLTDebug("object %p type %s created", pObj, objclass->GetName());
1168 } else if (bForce!=0) {
1169 HLTError("size mismatch: block size %d, indicated %d", fpInputBlocks[idx].fSize, firstWord+sizeof(AliHLTUInt32_t));
1172 HLTFatal("block descriptor empty");
1175 HLTError("index %d out of range %d", idx, fCurrentEventData.fBlockCnt);
1178 HLTError("no input blocks available");
1184 TObject* AliHLTComponent::GetInputObject(int idx, const char* /*classname*/, int bForce)
1186 // see header file for function documentation
1187 if (fpInputObjects==NULL) {
1188 fpInputObjects=new TObjArray(fCurrentEventData.fBlockCnt);
1191 if (fpInputObjects) {
1192 pObj=fpInputObjects->At(idx);
1194 pObj=CreateInputObject(idx, bForce);
1196 fpInputObjects->AddAt(pObj, idx);
1200 HLTFatal("memory allocation failed: TObjArray of size %d", fCurrentEventData.fBlockCnt);
1205 int AliHLTComponent::CleanupInputObjects()
1207 // see header file for function documentation
1208 if (!fpInputObjects) return 0;
1209 TObjArray* array=fpInputObjects;
1210 fpInputObjects=NULL;
1211 for (int i=0; i<array->GetEntriesFast(); i++) {
1212 TObject* pObj=array->At(i);
1213 // grrr, garbage collection strikes back: When read via AliHLTMessage
1214 // (CreateInputObject), and written to a TFile afterwards, the
1215 // TFile::Close calls ROOOT's garbage collection. No clue why the
1216 // object ended up in the key list and needs to be deleted
1218 // Matthias 09.11.2008 follow up
1219 // This approach doesn't actually work in all cases: the object table
1220 // can be switched off globally, the flag needs to be checked here as
1221 // well in order to avoid memory leaks.
1222 // This means we have to find another solution for the problem if it
1225 (!TObject::GetObjectStat() || gObjectTable->PtrIsValid(pObj))) {
1233 AliHLTComponentDataType AliHLTComponent::GetDataType(const TObject* pObject)
1235 // see header file for function documentation
1236 ALIHLTCOMPONENT_BASE_STOPWATCH();
1237 AliHLTComponentDataType dt=kAliHLTVoidDataType;
1238 int idx=fCurrentInputBlock;
1240 if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
1242 HLTError("unknown object %p", pObject);
1246 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
1247 dt=fpInputBlocks[idx].fDataType;
1249 HLTFatal("severe internal error, index out of range");
1255 AliHLTUInt32_t AliHLTComponent::GetSpecification(const TObject* pObject)
1257 // see header file for function documentation
1258 ALIHLTCOMPONENT_BASE_STOPWATCH();
1259 AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec;
1260 int idx=fCurrentInputBlock;
1262 if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
1264 HLTError("unknown object %p", pObject);
1268 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
1269 iSpec=fpInputBlocks[idx].fSpecification;
1271 HLTFatal("severe internal error, index out of range");
1277 int AliHLTComponent::Forward(const TObject* pObject)
1279 // see header file for function documentation
1281 int idx=fCurrentInputBlock;
1283 if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
1285 HLTError("unknown object %p", pObject);
1290 fOutputBlocks.push_back(fpInputBlocks[idx]);
1295 int AliHLTComponent::Forward(const AliHLTComponentBlockData* pBlock)
1297 // see header file for function documentation
1299 int idx=fCurrentInputBlock;
1301 if ((idx=FindInputBlock(pBlock))>=0) {
1303 HLTError("unknown Block %p", pBlock);
1308 // check for fpInputBlocks pointer done in FindInputBlock
1309 fOutputBlocks.push_back(fpInputBlocks[idx]);
1314 const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const AliHLTComponentDataType& dt)
1316 // see header file for function documentation
1317 ALIHLTCOMPONENT_BASE_STOPWATCH();
1320 int idx=FindInputBlock(fSearchDataType, 0);
1321 const AliHLTComponentBlockData* pBlock=NULL;
1323 // check for fpInputBlocks pointer done in FindInputBlock
1324 pBlock=&fpInputBlocks[idx];
1325 fCurrentInputBlock=idx;
1330 const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const char* dtID,
1331 const char* dtOrigin)
1333 // see header file for function documentation
1334 ALIHLTCOMPONENT_BASE_STOPWATCH();
1335 AliHLTComponentDataType dt;
1336 SetDataType(dt, dtID, dtOrigin);
1337 return GetFirstInputBlock(dt);
1340 const AliHLTComponentBlockData* AliHLTComponent::GetInputBlock(int index) const
1342 // see header file for function documentation
1343 ALIHLTCOMPONENT_BASE_STOPWATCH();
1344 assert( 0 <= index and index < (int)fCurrentEventData.fBlockCnt );
1345 return &fpInputBlocks[index];
1348 const AliHLTComponentBlockData* AliHLTComponent::GetNextInputBlock()
1350 // see header file for function documentation
1351 ALIHLTCOMPONENT_BASE_STOPWATCH();
1352 int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1);
1353 const AliHLTComponentBlockData* pBlock=NULL;
1355 // check for fpInputBlocks pointer done in FindInputBlock
1356 pBlock=&fpInputBlocks[idx];
1357 fCurrentInputBlock=idx;
1362 int AliHLTComponent::FindInputBlock(const AliHLTComponentBlockData* pBlock) const
1364 // see header file for function documentation
1365 int iResult=-ENOENT;
1366 if (fpInputBlocks!=NULL) {
1368 if (pBlock>=fpInputBlocks && pBlock<fpInputBlocks+fCurrentEventData.fBlockCnt) {
1369 iResult=(int)(pBlock-fpInputBlocks);
1378 AliHLTUInt32_t AliHLTComponent::GetSpecification(const AliHLTComponentBlockData* pBlock)
1380 // see header file for function documentation
1381 ALIHLTCOMPONENT_BASE_STOPWATCH();
1382 AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec;
1383 int idx=fCurrentInputBlock;
1385 if (fpInputObjects==NULL || (idx=FindInputBlock(pBlock))>=0) {
1387 HLTError("unknown Block %p", pBlock);
1391 // check for fpInputBlocks pointer done in FindInputBlock
1392 iSpec=fpInputBlocks[idx].fSpecification;
1397 int AliHLTComponent::PushBack(const TObject* pObject, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
1398 void* pHeader, int headerSize)
1400 // see header file for function documentation
1401 ALIHLTCOMPONENT_BASE_STOPWATCH();
1404 if (fPushbackPeriod>0) {
1405 // suppress the output
1407 if (fLastPushBackTime<0 || (int)time.Get()-fLastPushBackTime<fPushbackPeriod) return 0;
1410 AliHLTMessage msg(kMESS_OBJECT);
1411 msg.SetCompressionLevel(fCompressionLevel);
1412 msg.WriteObject(pObject);
1413 Int_t iMsgLength=msg.Length();
1415 // Matthias Sep 2008
1416 // NOTE: AliHLTMessage does implement it's own SetLength method
1417 // which is not architecture independent. The original SetLength
1418 // stores the size always in network byte order.
1419 // I'm trying to remember the rational for that, might be that
1420 // it was just some lack of knowledge. Want to change this, but
1421 // has to be done carefullt to be backward compatible.
1422 msg.SetLength(); // sets the length to the first (reserved) word
1424 // does nothing if the level is 0
1427 char *mbuf = msg.Buffer();
1428 if (msg.CompBuffer()) {
1429 msg.SetLength(); // set once more to have to byte order
1430 mbuf = msg.CompBuffer();
1431 iMsgLength = msg.CompLength();
1434 iResult=InsertOutputBlock(mbuf, iMsgLength, dt, spec, pHeader, headerSize);
1436 HLTDebug("object %s (%p) size %d compression %d inserted to output", pObject->ClassName(), pObject, iMsgLength, msg.GetCompressionLevel());
1438 fLastObjectSize=iMsgLength;
1440 HLTError("object serialization failed for object %p", pObject);
1449 int AliHLTComponent::PushBack(const TObject* pObject, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec,
1450 void* pHeader, int headerSize)
1452 // see header file for function documentation
1453 ALIHLTCOMPONENT_BASE_STOPWATCH();
1454 AliHLTComponentDataType dt;
1455 SetDataType(dt, dtID, dtOrigin);
1456 return PushBack(pObject, dt, spec, pHeader, headerSize);
1459 int AliHLTComponent::PushBack(const void* pBuffer, int iSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
1460 const void* pHeader, int headerSize)
1462 // see header file for function documentation
1463 ALIHLTCOMPONENT_BASE_STOPWATCH();
1464 if (fPushbackPeriod>0) {
1465 // suppress the output
1467 if (fLastPushBackTime<0 || (int)time.Get()-fLastPushBackTime<fPushbackPeriod) return 0;
1470 return InsertOutputBlock(pBuffer, iSize, dt, spec, pHeader, headerSize);
1473 int AliHLTComponent::PushBack(const void* pBuffer, int iSize, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec,
1474 const void* pHeader, int headerSize)
1476 // see header file for function documentation
1477 ALIHLTCOMPONENT_BASE_STOPWATCH();
1478 AliHLTComponentDataType dt;
1479 SetDataType(dt, dtID, dtOrigin);
1480 return PushBack(pBuffer, iSize, dt, spec, pHeader, headerSize);
1483 int AliHLTComponent::InsertOutputBlock(const void* pBuffer, int iBufferSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
1484 const void* pHeader, int iHeaderSize)
1486 // see header file for function documentation
1488 int iBlkSize = iBufferSize + iHeaderSize;
1490 if ((pBuffer!=NULL && iBufferSize>0) || (pHeader!=NULL && iHeaderSize>0)) {
1491 if (fpOutputBuffer && iBlkSize<=(int)(fOutputBufferSize-fOutputBufferFilled)) {
1492 AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled;
1494 // copy header if provided but skip if the header is the target location
1495 // in that case it has already been copied
1496 if (pHeader!=NULL && pHeader!=pTgt) {
1497 memcpy(pTgt, pHeader, iHeaderSize);
1500 pTgt += (AliHLTUInt8_t) iHeaderSize;
1502 // copy buffer if provided but skip if buffer is the target location
1503 // in that case it has already been copied
1504 if (pBuffer!=NULL && pBuffer!=pTgt) {
1505 memcpy(pTgt, pBuffer, iBufferSize);
1507 //AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)pBuffer);
1508 //HLTDebug("copy %d bytes from %p to output buffer %p, first word %#x", iBufferSize, pBuffer, pTgt, firstWord);
1510 //HLTDebug("buffer inserted to output: size %d data type %s spec %#x", iBlkSize, DataType2Text(dt).c_str(), spec);
1512 if (fpOutputBuffer) {
1513 HLTError("too little space in output buffer: %d of %d, required %d", fOutputBufferSize-fOutputBufferFilled, fOutputBufferSize, iBlkSize);
1515 HLTError("output buffer not available");
1521 AliHLTComponentBlockData bd;
1522 FillBlockData( bd );
1523 bd.fOffset = fOutputBufferFilled;
1524 bd.fSize = iBlkSize;
1526 bd.fSpecification = spec;
1527 fOutputBlocks.push_back( bd );
1528 fOutputBufferFilled+=bd.fSize;
1534 int AliHLTComponent::EstimateObjectSize(const TObject* pObject) const
1536 // see header file for function documentation
1537 if (!pObject) return 0;
1539 AliHLTMessage msg(kMESS_OBJECT);
1540 msg.WriteObject(pObject);
1541 return msg.Length();
1544 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(int capacity, const char* dtID,
1545 const char* dtOrigin,
1546 AliHLTUInt32_t spec)
1548 // see header file for function documentation
1549 ALIHLTCOMPONENT_BASE_STOPWATCH();
1550 AliHLTComponentDataType dt;
1551 SetDataType(dt, dtID, dtOrigin);
1552 return CreateMemoryFile(capacity, dt, spec);
1555 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(int capacity,
1556 const AliHLTComponentDataType& dt,
1557 AliHLTUInt32_t spec)
1559 // see header file for function documentation
1560 ALIHLTCOMPONENT_BASE_STOPWATCH();
1561 AliHLTMemoryFile* pFile=NULL;
1562 if (capacity>=0 && static_cast<unsigned int>(capacity)<=fOutputBufferSize-fOutputBufferFilled){
1563 AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled;
1564 pFile=new AliHLTMemoryFile((char*)pTgt, capacity);
1566 unsigned int nofBlocks=fOutputBlocks.size();
1567 if (nofBlocks+1>fMemFiles.size()) {
1568 fMemFiles.resize(nofBlocks+1, NULL);
1570 if (nofBlocks<fMemFiles.size()) {
1571 fMemFiles[nofBlocks]=pFile;
1572 AliHLTComponentBlockData bd;
1573 FillBlockData( bd );
1574 bd.fOffset = fOutputBufferFilled;
1575 bd.fSize = capacity;
1577 bd.fSpecification = spec;
1578 fOutputBufferFilled+=bd.fSize;
1579 fOutputBlocks.push_back( bd );
1581 HLTError("can not allocate/grow object array");
1582 pFile->CloseMemoryFile(0);
1588 HLTError("can not create memory file of size %d (%d available)", capacity, fOutputBufferSize-fOutputBufferFilled);
1593 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(const char* dtID,
1594 const char* dtOrigin,
1595 AliHLTUInt32_t spec,
1598 // see header file for function documentation
1599 ALIHLTCOMPONENT_BASE_STOPWATCH();
1600 AliHLTComponentDataType dt;
1601 SetDataType(dt, dtID, dtOrigin);
1602 int size=fOutputBufferSize-fOutputBufferFilled;
1603 if (capacity<0 || capacity>1.0) {
1604 HLTError("invalid parameter: capacity %f", capacity);
1607 size=(int)(size*capacity);
1608 return CreateMemoryFile(size, dt, spec);
1611 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(const AliHLTComponentDataType& dt,
1612 AliHLTUInt32_t spec,
1615 // see header file for function documentation
1616 ALIHLTCOMPONENT_BASE_STOPWATCH();
1617 int size=fOutputBufferSize-fOutputBufferFilled;
1618 if (capacity<0 || capacity>1.0) {
1619 HLTError("invalid parameter: capacity %f", capacity);
1622 size=(int)(size*capacity);
1623 return CreateMemoryFile(size, dt, spec);
1626 int AliHLTComponent::Write(AliHLTMemoryFile* pFile, const TObject* pObject,
1627 const char* key, int option)
1629 // see header file for function documentation
1631 if (pFile && pObject) {
1633 iResult=pObject->Write(key, option);
1637 iResult=-pFile->GetErrno();
1638 if (iResult==-ENOSPC) {
1639 HLTError("error writing memory file, buffer too small");
1648 int AliHLTComponent::CloseMemoryFile(AliHLTMemoryFile* pFile)
1650 // see header file for function documentation
1653 AliHLTMemoryFilePList::iterator element=fMemFiles.begin();
1655 while (element!=fMemFiles.end() && iResult>=0) {
1656 if (*element && *element==pFile) {
1657 iResult=pFile->CloseMemoryFile();
1659 // sync memory files and descriptors
1661 fOutputBlocks[i].fSize=(*element)->GetSize()+(*element)->GetHeaderSize();
1669 HLTError("can not find memory file %p", pFile);
1677 int AliHLTComponent::CreateEventDoneData(AliHLTComponentEventDoneData edd)
1679 // see header file for function documentation
1682 AliHLTComponentEventDoneData* newEDD = NULL;
1684 unsigned long newSize=edd.fDataSize;
1686 newSize += fEventDoneData->fDataSize;
1688 if (newSize>fEventDoneDataSize) {
1689 newEDD = reinterpret_cast<AliHLTComponentEventDoneData*>( new AliHLTUInt8_t[ sizeof(AliHLTComponentEventDoneData)+newSize ] );
1692 newEDD->fStructSize = sizeof(AliHLTComponentEventDoneData);
1693 newEDD->fDataSize = newSize;
1694 newEDD->fData = reinterpret_cast<AliHLTUInt8_t*>(newEDD)+newEDD->fStructSize;
1695 unsigned long long offset = 0;
1696 if (fEventDoneData) {
1697 memcpy( newEDD->fData, fEventDoneData->fData, fEventDoneData->fDataSize );
1698 offset += fEventDoneData->fDataSize;
1700 memcpy( reinterpret_cast<AliHLTUInt8_t*>(newEDD->fData)+offset, edd.fData, edd.fDataSize );
1702 delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
1703 fEventDoneData = newEDD;
1704 fEventDoneDataSize = newSize;
1706 else if (fEventDoneData) {
1707 memcpy( reinterpret_cast<AliHLTUInt8_t*>(fEventDoneData->fData)+fEventDoneData->fDataSize, edd.fData, edd.fDataSize );
1708 fEventDoneData->fDataSize += edd.fDataSize;
1711 HLTError("internal mismatch, fEventDoneData=%d but buffer is NULL", fEventDoneDataSize);
1719 // helper function for std:sort, implements an operator<
1720 bool SortComponentStatisticsById(const AliHLTComponentStatistics& a, const AliHLTComponentStatistics& b)
1725 // helper function for std:sort
1726 bool SortComponentStatisticsDescendingByLevel(const AliHLTComponentStatistics& a, const AliHLTComponentStatistics& b)
1731 // helper class to define operator== between AliHLTComponentStatistics and AliHLTComponentStatistics.fId
1732 class AliHLTComponentStatisticsId {
1734 AliHLTComponentStatisticsId(AliHLTUInt32_t id) : fId(id) {}
1735 AliHLTComponentStatisticsId(const AliHLTComponentStatisticsId& src) : fId(src.fId) {}
1736 bool operator==(const AliHLTComponentStatistics& a) const {return a.fId==fId;}
1738 AliHLTComponentStatisticsId();
1742 // operator for std::find of AliHLTComponentStatistics by id
1743 bool operator==(const AliHLTComponentStatistics& a, const AliHLTComponentStatisticsId& b)
1748 bool AliHLTComponentStatisticsCompareIds(const AliHLTComponentStatistics& a, const AliHLTComponentStatistics& b)
1750 return a.fId==b.fId;
1753 // helper class to define operator== between AliHLTComponentBlockData and AliHLTComponentBlockData.fSpecification
1754 class AliHLTComponentBlockDataSpecification {
1756 AliHLTComponentBlockDataSpecification(AliHLTUInt32_t specification) : fSpecification(specification) {}
1757 AliHLTComponentBlockDataSpecification(const AliHLTComponentBlockDataSpecification& src) : fSpecification(src.fSpecification) {}
1758 bool operator==(const AliHLTComponentBlockData& bd) const {return bd.fSpecification==fSpecification;}
1760 AliHLTComponentBlockDataSpecification();
1761 AliHLTUInt32_t fSpecification;
1764 // operator for std::find of AliHLTComponentBlockData by specification
1765 bool operator==(const AliHLTComponentBlockData& bd, const AliHLTComponentBlockDataSpecification& spec)
1770 // operator for std::find
1771 bool operator==(const AliHLTComponentBlockData& a, const AliHLTComponentBlockData& b)
1773 if (!MatchExactly(a.fDataType,b.fDataType)) return false;
1774 return a.fSpecification==b.fSpecification;
1777 } // end of namespace
1779 int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
1780 const AliHLTComponentBlockData* blocks,
1781 AliHLTComponentTriggerData& trigData,
1782 AliHLTUInt8_t* outputPtr,
1783 AliHLTUInt32_t& size,
1784 AliHLTUInt32_t& outputBlockCnt,
1785 AliHLTComponentBlockData*& outputBlocks,
1786 AliHLTComponentEventDoneData*& edd )
1788 // see header file for function documentation
1789 HLTLogKeyword(fChainId.c_str());
1790 ALIHLTCOMPONENT_BASE_STOPWATCH();
1792 fCurrentEvent=evtData.fEventID;
1793 fCurrentEventData=evtData;
1794 fpInputBlocks=blocks;
1795 fCurrentInputBlock=-1;
1796 fSearchDataType=kAliHLTAnyDataType;
1797 fpOutputBuffer=outputPtr;
1798 fOutputBufferSize=size;
1799 fOutputBufferFilled=0;
1800 fOutputBlocks.clear();
1804 AliHLTComponentBlockDataList forwardedBlocks;
1806 // optional component statistics
1807 AliHLTComponentStatisticsList compStats;
1808 bool bAddComponentTableEntry=false;
1809 vector<AliHLTUInt32_t> parentComponentTables;
1810 int processingLevel=-1;
1811 #if defined(HLT_COMPONENT_STATISTICS)
1812 if ((fFlags&kDisableComponentStat)==0) {
1813 AliHLTComponentStatistics outputStat;
1814 memset(&outputStat, 0, sizeof(AliHLTComponentStatistics));
1815 outputStat.fStructSize=sizeof(AliHLTComponentStatistics);
1816 outputStat.fId=fChainIdCrc;
1818 fpBenchmark->Stop();
1819 outputStat.fComponentCycleTime=(AliHLTUInt32_t)(fpBenchmark->RealTime()*ALIHLTCOMPONENT_STATTIME_SCALER);
1820 fpBenchmark->Reset();
1821 fpBenchmark->Start();
1823 compStats.push_back(outputStat);
1825 #endif // HLT_COMPONENT_STATISTICS
1827 // data processing is skipped
1828 // - if there are only steering events in the block list.
1829 // For the sake of data source components data processing
1830 // is not skipped if there is no block list at all or if it
1831 // just contains the eventType block
1832 // - always skipped if the event is of type
1833 // - gkAliEventTypeConfiguration
1834 // - gkAliEventTypeReadPreprocessor
1835 const unsigned int skipModeDefault=0x1;
1836 const unsigned int skipModeForce=0x2;
1837 unsigned int bSkipDataProcessing=skipModeDefault;
1839 // find special events
1840 if (fpInputBlocks && evtData.fBlockCnt>0) {
1841 // first look for all special events and execute in the appropriate
1842 // sequence afterwords
1843 int indexComConfEvent=-1;
1844 int indexUpdtDCSEvent=-1;
1845 int indexSOREvent=-1;
1846 int indexEOREvent=-1;
1847 int indexECSParamBlock=-1;
1848 for (unsigned int i=0; i<evtData.fBlockCnt && iResult>=0; i++) {
1849 if (fpInputBlocks[i].fDataType==kAliHLTDataTypeSOR) {
1851 // the AliHLTCalibrationProcessor relies on the SOR and EOR events
1852 bSkipDataProcessing&=~skipModeDefault;
1853 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeRunType) {
1855 // handling is not clear yet
1856 if (fpInputBlocks[i].fPtr) {
1857 HLTDebug("got run type \"%s\"\n", fpInputBlocks[i].fPtr);
1859 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeEOR) {
1861 // the calibration processor relies on the SOR and EOR events
1862 bSkipDataProcessing&=~skipModeDefault;
1863 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeDDL) {
1865 // this event is most likely deprecated
1866 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComConf) {
1867 indexComConfEvent=i;
1868 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeUpdtDCS) {
1869 indexUpdtDCSEvent=i;
1870 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeEvent) {
1871 fEventType=fpInputBlocks[i].fSpecification;
1872 if (fEventType != gkAliEventTypeConfiguration and
1873 fEventType != gkAliEventTypeReadPreprocessor
1876 // We can actually get the event type from the CDH if it is valid.
1877 // Otherwise just use the specification of the input block.
1878 const AliRawDataHeader* cdh;
1879 if (ExtractTriggerData(trigData, NULL, NULL, &cdh, NULL) == 0)
1881 fEventType = ExtractEventTypeFromCDH(cdh);
1885 // skip always in case of gkAliEventTypeConfiguration
1886 if (fpInputBlocks[i].fSpecification==gkAliEventTypeConfiguration) bSkipDataProcessing|=skipModeForce;
1888 // skip always in case of gkAliEventTypeReadPreprocessor
1889 if (fpInputBlocks[i].fSpecification==gkAliEventTypeReadPreprocessor) bSkipDataProcessing|=skipModeForce;
1891 // never skip if the event type block is the only block
1892 if (evtData.fBlockCnt==1) bSkipDataProcessing&=~skipModeDefault;
1894 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComponentStatistics) {
1895 if (compStats.size()>0) {
1896 AliHLTUInt8_t* pData=reinterpret_cast<AliHLTUInt8_t*>(fpInputBlocks[i].fPtr);
1897 for (AliHLTUInt32_t offset=0;
1898 offset+sizeof(AliHLTComponentStatistics)<=fpInputBlocks[i].fSize;
1899 offset+=sizeof(AliHLTComponentStatistics)) {
1900 AliHLTComponentStatistics* pStat=reinterpret_cast<AliHLTComponentStatistics*>(pData+offset);
1901 if (pStat && compStats[0].fLevel<=pStat->fLevel) {
1902 compStats[0].fLevel=pStat->fLevel+1;
1904 if (find(compStats.begin(), compStats.end(), AliHLTComponentStatisticsId(pStat->fId))==compStats.end()) {
1905 compStats.push_back(*pStat);
1909 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComponentTable) {
1910 AliHLTComponentBlockDataList::iterator element=forwardedBlocks.begin();
1911 while ((element=find(element, forwardedBlocks.end(), AliHLTComponentBlockDataSpecification(fpInputBlocks[i].fSpecification)))!=forwardedBlocks.end()) {
1912 if (element->fDataType==fpInputBlocks[i].fDataType) break;
1913 // TODO: think about some more checks inclusing also the actual data buffers
1914 // this has to handle multiplicity>1 in the online system, where all components
1915 // send the information on SOR, because this event is broadcasted
1917 if (element==forwardedBlocks.end()) {
1918 forwardedBlocks.push_back(fpInputBlocks[i]);
1920 parentComponentTables.push_back(fpInputBlocks[i].fSpecification);
1921 if (fpInputBlocks[i].fSize>=sizeof(AliHLTComponentTableEntry)) {
1922 const AliHLTComponentTableEntry* entry=reinterpret_cast<AliHLTComponentTableEntry*>(fpInputBlocks[i].fPtr);
1923 if (entry->fStructSize==sizeof(AliHLTComponentTableEntry)) {
1924 if (processingLevel<0 || processingLevel<=(int)entry->fLevel)
1925 processingLevel=entry->fLevel+1;
1928 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeECSParam) {
1929 indexECSParamBlock=i;
1931 // the processing function is called if there is at least one
1932 // non-steering data block. Steering blocks are not filtered out
1933 // for sake of performance
1934 bSkipDataProcessing&=~skipModeDefault;
1935 if (compStats.size()>0) {
1936 compStats[0].fInputBlockCount++;
1937 compStats[0].fTotalInputSize+=fpInputBlocks[i].fSize;
1942 if (indexSOREvent>=0) {
1944 bAddComponentTableEntry=true;
1945 compStats.clear(); // no component statistics for SOR
1946 if (fpRunDesc==NULL) {
1947 fpRunDesc=new AliHLTRunDesc;
1948 if (fpRunDesc) *fpRunDesc=kAliHLTVoidRunDesc;
1951 AliHLTRunDesc rundesc;
1952 if ((iResult=CopyStruct(&rundesc, sizeof(AliHLTRunDesc), indexSOREvent, "AliHLTRunDesc", "SOR"))>0) {
1953 if (fpRunDesc->fRunNo==kAliHLTVoidRunNo) {
1955 HLTDebug("set run decriptor, run no %d", fpRunDesc->fRunNo);
1956 SetCDBRunNo(fpRunDesc->fRunNo);
1957 } else if (fpRunDesc->fRunNo!=rundesc.fRunNo) {
1958 HLTWarning("already set run properties run no %d, ignoring SOR with run no %d", fpRunDesc->fRunNo, rundesc.fRunNo);
1965 if (indexECSParamBlock>=0) {
1966 if (fpInputBlocks[indexECSParamBlock].fSize>0) {
1967 const char* param=reinterpret_cast<const char*>(fpInputBlocks[indexECSParamBlock].fPtr);
1968 TString paramString;
1969 if (param[fpInputBlocks[indexECSParamBlock].fSize-1]!=0) {
1970 HLTWarning("ECS parameter string not terminated");
1971 paramString.Insert(0, param, fpInputBlocks[indexECSParamBlock].fSize);
1976 ScanECSParam(paramString.Data());
1978 HLTWarning("empty ECS parameter received");
1981 // TODO: later on we might throw a warning here since the CTP trigger classes
1982 // should be mandatory
1985 if (indexEOREvent>=0) {
1986 fLastPushBackTime=0; // always send at EOR
1987 bAddComponentTableEntry=true;
1988 compStats.clear(); // no component statistics for EOR
1989 if (fpRunDesc!=NULL) {
1991 AliHLTRunDesc rundesc;
1992 if ((iResult=CopyStruct(&rundesc, sizeof(AliHLTRunDesc), indexEOREvent, "AliHLTRunDesc", "SOR"))>0) {
1993 if (fpRunDesc->fRunNo!=rundesc.fRunNo) {
1994 HLTWarning("run no mismatch: SOR %d, EOR %d", fpRunDesc->fRunNo, rundesc.fRunNo);
1996 HLTDebug("EOR run no %d", fpRunDesc->fRunNo);
1999 // we do not unload the fpRunDesc struct here in order to have the run information
2000 // available during the event processing
2001 // https://savannah.cern.ch/bugs/?39711
2002 // the info will be cleared in DeInit
2005 HLTWarning("did not receive SOR, ignoring EOR");
2008 if (fEventType==gkAliEventTypeConfiguration) {
2009 if (indexComConfEvent>=0) {
2011 if (indexComConfEvent>=0 && fpInputBlocks[indexComConfEvent].fPtr!=NULL && fpInputBlocks[indexComConfEvent].fSize>0) {
2012 cdbEntry.Append(reinterpret_cast<const char*>(fpInputBlocks[indexComConfEvent].fPtr), fpInputBlocks[indexComConfEvent].fSize);
2014 HLTDebug("received component configuration command: entry %s", cdbEntry.IsNull()?"none":cdbEntry.Data());
2015 int tmpResult=Reconfigure(cdbEntry[0]==0?NULL:cdbEntry.Data(), fChainId.c_str());
2017 HLTWarning("reconfiguration of component %p (%s) failed with error code %d", this, GetComponentID(), tmpResult);
2020 ALIHLTERRORGUARD(1, "incomplete Configure event, missing parameter data block");
2023 if (fEventType==gkAliEventTypeReadPreprocessor) {
2024 if (indexUpdtDCSEvent>=0) {
2026 if (fpInputBlocks[indexUpdtDCSEvent].fPtr!=NULL && fpInputBlocks[indexUpdtDCSEvent].fSize>0) {
2027 modules.Append(reinterpret_cast<const char*>(fpInputBlocks[indexUpdtDCSEvent].fPtr), fpInputBlocks[indexUpdtDCSEvent].fSize);
2029 HLTDebug("received preprocessor update command: detectors %s", modules.IsNull()?"ALL":modules.Data());
2030 int tmpResult=ReadPreprocessorValues(modules[0]==0?"ALL":modules.Data());
2032 HLTWarning("preprocessor update of component %p (%s) failed with error code %d", this, GetComponentID(), tmpResult);
2035 ALIHLTERRORGUARD(1, "incomplete ReadPreprocessor event, missing parameter data block");
2039 // processing function needs to be called if there are no input data
2040 // blocks in order to make data source components working.
2041 bSkipDataProcessing&=~skipModeDefault;
2044 // data processing is not skipped if the component explicitly asks
2045 // for the private blocks
2046 if ((fFlags&kRequireSteeringBlocks)!=0) bSkipDataProcessing=0;
2048 // data processing is not skipped for data sources
2049 if (GetComponentType()==AliHLTComponent::kSource) bSkipDataProcessing=0;
2052 // set the active triggers for this event
2053 fpCTPData->SetTriggers(trigData);
2054 // increment CTP trigger counters if available
2055 if (IsDataEvent()) fpCTPData->Increment(trigData);
2058 AliHLTComponentBlockDataList blockData;
2059 if (iResult>=0 && !bSkipDataProcessing)
2060 { // dont delete, sets the scope for the stopwatch guard
2061 // do not use ALIHLTCOMPONENT_DA_STOPWATCH(); macro
2062 // in order to avoid 'shadowed variable' warning
2063 AliHLTStopwatchGuard swguard2(fpStopwatches!=NULL?reinterpret_cast<TStopwatch*>(fpStopwatches->At((int)kSWDA)):NULL);
2064 AliHLTMisc::AliOnlineGuard onlineGuard;
2065 iResult=DoProcessing(evtData, blocks, trigData, outputPtr, size, blockData, edd);
2066 } // end of the scope of the stopwatch guard
2067 if (iResult>=0 && !bSkipDataProcessing) {
2068 if (fOutputBlocks.size()>0) {
2069 // High Level interface
2071 //HLTDebug("got %d block(s) via high level interface", fOutputBlocks.size());
2072 // sync memory files and descriptors
2073 AliHLTMemoryFilePList::iterator element=fMemFiles.begin();
2075 while (element!=fMemFiles.end() && iResult>=0) {
2077 if ((*element)->IsClosed()==0) {
2078 HLTWarning("memory file has not been closed, force flush");
2079 iResult=CloseMemoryFile(*element);
2086 // create the descriptor list
2087 if (blockData.size()>0) {
2088 HLTError("low level and high interface must not be mixed; use PushBack methods to insert data blocks");
2091 if (compStats.size()>0 && IsDataEvent()) {
2092 int offset=AddComponentStatistics(fOutputBlocks, fpOutputBuffer, fOutputBufferSize, fOutputBufferFilled, compStats);
2093 if (offset>0) fOutputBufferFilled+=offset;
2095 if (bAddComponentTableEntry) {
2096 int offset=AddComponentTableEntry(fOutputBlocks, fpOutputBuffer, fOutputBufferSize, fOutputBufferFilled, parentComponentTables, processingLevel);
2097 if (offset>0) size+=offset;
2099 if (forwardedBlocks.size()>0) {
2100 fOutputBlocks.insert(fOutputBlocks.end(), forwardedBlocks.begin(), forwardedBlocks.end());
2102 iResult=MakeOutputDataBlockList(fOutputBlocks, &outputBlockCnt, &outputBlocks);
2103 size=fOutputBufferFilled;
2107 // Low Level interface
2108 if (blockData.empty() && size!=0) {
2109 // set the size to zero because there is no announced data
2110 //HLTWarning("no output blocks added by component but output buffer filled %d of %d", size, fOutputBufferSize);
2114 if (compStats.size()>0) {
2115 int offset=AddComponentStatistics(blockData, fpOutputBuffer, fOutputBufferSize, size, compStats);
2116 if (offset>0) size+=offset;
2118 if (bAddComponentTableEntry) {
2119 int offset=AddComponentTableEntry(blockData, fpOutputBuffer, fOutputBufferSize, size, parentComponentTables, processingLevel);
2120 if (offset>0) size+=offset;
2122 if (forwardedBlocks.size()>0) {
2123 blockData.insert(blockData.end(), forwardedBlocks.begin(), forwardedBlocks.end());
2125 iResult=MakeOutputDataBlockList(blockData, &outputBlockCnt, &outputBlocks);
2128 HLTFatal("component %s (%p): can not convert output block descriptor list", GetComponentID(), this);
2131 if (iResult<0 || bSkipDataProcessing) {
2135 CleanupInputObjects();
2136 if (iResult>=0 && IsDataEvent()) {
2137 IncrementEventCounter();
2139 if (outputBlockCnt==0) {
2140 // no output blocks, set size to 0
2144 // reset the internal EventData struct
2145 FillEventData(fCurrentEventData);
2147 // reset the active triggers
2148 if (fpCTPData) fpCTPData->SetTriggers(0);
2150 // set the time for the pushback period
2151 if (fPushbackPeriod>0) {
2152 // suppress the output
2154 if (fLastPushBackTime<0) {
2155 // choose a random offset at beginning to equalize traffic for multiple instances
2157 gRandom->SetSeed(fChainIdCrc);
2158 fLastPushBackTime=time.Get();
2159 fLastPushBackTime-=gRandom->Integer(fPushbackPeriod);
2160 } else if ((int)time.Get()-fLastPushBackTime>=fPushbackPeriod) {
2161 fLastPushBackTime=time.Get();
2168 int AliHLTComponent::AddComponentStatistics(AliHLTComponentBlockDataList& blocks,
2169 AliHLTUInt8_t* buffer,
2170 AliHLTUInt32_t bufferSize,
2171 AliHLTUInt32_t offset,
2172 AliHLTComponentStatisticsList& stats) const
2174 // see header file for function documentation
2176 if ((fFlags&kDisableComponentStat)!=0) return 0;
2177 #if defined(HLT_COMPONENT_STATISTICS)
2178 if (stats.size()==0) return -ENOENT;
2179 // check if there is space for at least one entry
2180 if (offset+sizeof(AliHLTComponentStatistics)>bufferSize) return 0;
2181 stats[0].fTotalOutputSize=offset;
2182 stats[0].fOutputBlockCount=blocks.size();
2184 fpBenchmark->Stop();
2185 stats[0].fTime=(AliHLTUInt32_t)(fpBenchmark->RealTime()*ALIHLTCOMPONENT_STATTIME_SCALER);
2186 stats[0].fCTime=(AliHLTUInt32_t)(fpBenchmark->CpuTime()*ALIHLTCOMPONENT_STATTIME_SCALER);
2187 fpBenchmark->Continue();
2190 sort(stats.begin(), stats.end(), SortComponentStatisticsDescendingByLevel);
2192 // shrink the number of entries if the buffer is too small
2193 if (offset+stats.size()*sizeof(AliHLTComponentStatistics)>bufferSize) {
2194 unsigned originalSize=stats.size();
2195 AliHLTUInt32_t removedLevel=0;
2197 // remove all entries of the level of the last entry
2198 removedLevel=stats.back().fLevel;
2199 AliHLTComponentStatisticsList::iterator element=stats.begin();
2201 while (element!=stats.end()) {
2202 if (element->fLevel<=removedLevel) {
2203 element=stats.erase(element);
2208 } while (stats.size()>1 &&
2209 (offset+stats.size()*sizeof(AliHLTComponentStatistics)>bufferSize));
2210 HLTWarning("too little space in output buffer to add block of %d statistics entries (size %d), available %d, removed %d entries",
2211 originalSize, sizeof(AliHLTComponentStatistics), bufferSize-offset, originalSize-stats.size());
2213 HLTDebug("adding block of %d statistics entries", stats.size());
2215 assert(stats.size()>0);
2216 if (stats.size()==0) return 0;
2218 if (offset+stats.size()*sizeof(AliHLTComponentStatistics)<=bufferSize) {
2219 AliHLTComponentBlockData bd;
2220 FillBlockData( bd );
2221 bd.fOffset = offset;
2222 bd.fSize = stats.size()*sizeof(AliHLTComponentStatistics);
2223 bd.fDataType = kAliHLTDataTypeComponentStatistics;
2224 bd.fSpecification = fChainIdCrc;
2225 memcpy(buffer+offset, &(stats[0]), bd.fSize);
2226 blocks.push_back(bd);
2230 if (blocks.size() && buffer && bufferSize && offset && stats.size()) {
2231 // get rid of warning
2233 #endif // HLT_COMPONENT_STATISTICS
2237 int AliHLTComponent::AddComponentTableEntry(AliHLTComponentBlockDataList& blocks,
2238 AliHLTUInt8_t* buffer,
2239 AliHLTUInt32_t bufferSize,
2240 AliHLTUInt32_t offset,
2241 const vector<AliHLTUInt32_t>& parents,
2242 int processingLevel) const
2244 // see header file for function documentation
2246 if ((fFlags&kDisableComponentStat)!=0) return 0;
2247 #if defined(HLT_COMPONENT_STATISTICS)
2248 // the payload consists of the AliHLTComponentTableEntry struct,
2249 // followed by a an array of 32bit crc chain ids and the component
2250 // description string
2251 unsigned int payloadSize=sizeof(AliHLTComponentTableEntry);
2252 payloadSize+=parents.size()*sizeof(AliHLTUInt32_t);
2254 // the component description has the following format:
2255 // chain-id{component-id:arguments}
2256 const char* componentId=const_cast<AliHLTComponent*>(this)->GetComponentID();
2257 unsigned int descriptionSize=fChainId.size()+1;
2258 descriptionSize+=2; // the '{}' around the component id
2259 descriptionSize+=strlen(componentId);
2260 descriptionSize+=1; // the ':' between component id and arguments
2261 descriptionSize+=fComponentArgs.size();
2263 payloadSize+=descriptionSize;
2264 if (buffer && (offset+payloadSize<=bufferSize)) {
2265 AliHLTUInt8_t* pTgt=buffer+offset;
2266 memset(pTgt, 0, payloadSize);
2269 AliHLTComponentTableEntry* pEntry=reinterpret_cast<AliHLTComponentTableEntry*>(pTgt);
2270 pEntry->fStructSize=sizeof(AliHLTComponentTableEntry);
2271 pEntry->fLevel=processingLevel>=0?processingLevel:0;
2272 pEntry->fNofParents=parents.size();
2273 pEntry->fSizeDescription=descriptionSize;
2274 pTgt=pEntry->fBuffer;
2276 // write array of parents
2277 if (parents.size()>0) {
2278 unsigned int copy=parents.size()*sizeof(vector<AliHLTUInt32_t>::value_type);
2279 memcpy(pTgt, &parents[0], parents.size()*sizeof(vector<AliHLTUInt32_t>::value_type));
2283 // write component description
2284 memcpy(pTgt, fChainId.c_str(), fChainId.size());
2285 pTgt+=fChainId.size();
2287 memcpy(pTgt, componentId, strlen(componentId));
2288 pTgt+=strlen(componentId);
2290 memcpy(pTgt, fComponentArgs.c_str(), fComponentArgs.size());
2291 pTgt+=fComponentArgs.size();
2295 AliHLTComponentBlockData bd;
2296 FillBlockData( bd );
2297 bd.fOffset = offset;
2298 bd.fSize = payloadSize;
2299 bd.fDataType = kAliHLTDataTypeComponentTable;
2300 bd.fSpecification = fChainIdCrc;
2301 blocks.push_back(bd);
2305 if (blocks.size() && buffer && bufferSize && offset && parents.size() && processingLevel) {
2306 // get rid of warning
2308 #endif // HLT_COMPONENT_STATISTICS
2312 AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard()
2317 // standard constructor (not for use)
2320 AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(TStopwatch* pStopwatch)
2322 fpStopwatch(pStopwatch),
2327 // check for already existing guard
2328 if (fgpCurrent) fpPrec=fgpCurrent;
2331 // stop the preceeding guard if it controls a different stopwatch
2333 if (fpPrec && fpPrec!=this) bStart=fpPrec->Hold(fpStopwatch);
2335 // start the stopwatch if the current guard controls a different one
2336 if (fpStopwatch && bStart==1) fpStopwatch->Start(kFALSE);
2339 AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(const AliHLTStopwatchGuard&)
2345 // copy constructor not for use
2349 AliHLTComponent::AliHLTStopwatchGuard& AliHLTComponent::AliHLTStopwatchGuard::operator=(const AliHLTStopwatchGuard&)
2352 // assignment operator not for use
2359 AliHLTComponent::AliHLTStopwatchGuard* AliHLTComponent::AliHLTStopwatchGuard::fgpCurrent=NULL;
2361 AliHLTComponent::AliHLTStopwatchGuard::~AliHLTStopwatchGuard()
2365 // resume the preceeding guard if it controls a different stopwatch
2367 if (fpPrec && fpPrec!=this) bStop=fpPrec->Resume(fpStopwatch);
2369 // stop the stopwatch if the current guard controls a different one
2370 if (fpStopwatch && bStop==1) fpStopwatch->Stop();
2372 // resume to the preceeding guard
2376 int AliHLTComponent::AliHLTStopwatchGuard::Hold(const TStopwatch* pSucc)
2378 // see header file for function documentation
2379 if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Stop();
2380 return fpStopwatch!=pSucc?1:0;
2383 int AliHLTComponent::AliHLTStopwatchGuard::Resume(const TStopwatch* pSucc)
2385 // see header file for function documentation
2386 if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Start(kFALSE);
2387 return fpStopwatch!=pSucc?1:0;
2390 int AliHLTComponent::SetStopwatch(TObject* pSW, AliHLTStopwatchType type)
2392 // see header file for function documentation
2394 if (pSW!=NULL && type<kSWTypeCount) {
2395 if (fpStopwatches) {
2396 TObject* pObj=fpStopwatches->At((int)type);
2397 if (pSW==NULL // explicit reset
2398 || pObj==NULL) { // explicit set
2399 fpStopwatches->AddAt(pSW, (int)type);
2400 } else if (pObj!=pSW) {
2401 HLTWarning("stopwatch %d already set, reset first", (int)type);
2411 int AliHLTComponent::SetStopwatches(TObjArray* pStopwatches)
2413 // see header file for function documentation
2414 if (pStopwatches==NULL) return -EINVAL;
2417 for (int i=0 ; i<(int)kSWTypeCount && pStopwatches->GetEntriesFast(); i++)
2418 SetStopwatch(pStopwatches->At(i), (AliHLTStopwatchType)i);
2422 AliHLTUInt32_t AliHLTComponent::GetRunNo() const
2424 // see header file for function documentation
2426 // 2010-02-11 OCDB is now the reliable source for the run number, it is
2427 // initialized either by aliroot or the external interface depending
2428 // on the environment. It turned out that the rundescriptor is not set
2429 // in the aliroot mode, resulting in an invalid run number. However this
2430 // did not cause problems until now. OCDB initialization has been revised
2431 // already in 10/2009. This was a remnant.
2432 // Have to check whether we get rid of the rundescriptor at some point.
2433 if (fpRunDesc==NULL) return AliHLTMisc::Instance().GetCDBRunNo();
2434 if (fpRunDesc->fRunNo!=(unsigned)AliHLTMisc::Instance().GetCDBRunNo()) {
2435 HLTWarning("run number mismatch: ocdb %d run descriptor %d", AliHLTMisc::Instance().GetCDBRunNo(), fpRunDesc->fRunNo);
2437 return fpRunDesc->fRunNo;
2440 AliHLTUInt32_t AliHLTComponent::GetRunType() const
2442 // see header file for function documentation
2443 if (fpRunDesc==NULL) return kAliHLTVoidRunType;
2444 return fpRunDesc->fRunType;
2447 AliHLTUInt32_t AliHLTComponent::GetTimeStamp() const
2449 // see header file for function documentation
2450 if (fCurrentEventData.fEventCreation_s) {
2451 return fCurrentEventData.fEventCreation_s;
2453 // using the actual UTC if the time stamp was not set by the framework
2454 return static_cast<AliHLTUInt32_t>(time(NULL));
2457 AliHLTUInt32_t AliHLTComponent::GetPeriodNumber() const
2459 // see header file for function documentation
2460 return (GetEventId()>>36)&0xfffffff;
2463 AliHLTUInt32_t AliHLTComponent::GetOrbitNumber() const
2465 // see header file for function documentation
2466 return (GetEventId()>>12)&0xffffff;
2469 AliHLTUInt16_t AliHLTComponent::GetBunchCrossNumber() const
2471 // see header file for function documentation
2472 return GetEventId()&0xfff;
2475 bool AliHLTComponent::IsDataEvent(AliHLTUInt32_t* pTgt) const
2477 // see header file for function documentation
2478 if (pTgt) *pTgt=fEventType;
2479 return (fEventType==gkAliEventTypeData ||
2480 fEventType==gkAliEventTypeDataReplay);
2483 int AliHLTComponent::CopyStruct(void* pStruct, unsigned int iStructSize, unsigned int iBlockNo,
2484 const char* structname, const char* eventname)
2486 // see header file for function documentation
2488 if (pStruct!=NULL && iStructSize>sizeof(AliHLTUInt32_t)) {
2489 if (fpInputBlocks!=NULL && iBlockNo<fCurrentEventData.fBlockCnt) {
2490 AliHLTUInt32_t* pTgt=(AliHLTUInt32_t*)pStruct;
2491 if (fpInputBlocks[iBlockNo].fPtr && fpInputBlocks[iBlockNo].fSize) {
2492 AliHLTUInt32_t copy=*((AliHLTUInt32_t*)fpInputBlocks[iBlockNo].fPtr);
2493 if (fpInputBlocks[iBlockNo].fSize!=copy) {
2494 HLTWarning("%s event: mismatch of block size (%d) and structure size (%d)", eventname, fpInputBlocks[iBlockNo].fSize, copy);
2495 if (copy>fpInputBlocks[iBlockNo].fSize) copy=fpInputBlocks[iBlockNo].fSize;
2497 if (copy!=iStructSize) {
2498 HLTWarning("%s event: mismatch in %s version (data type version %d)", eventname, structname, ALIHLT_DATA_TYPES_VERSION);
2499 if (copy>iStructSize) {
2502 memset(pTgt, 0, iStructSize);
2505 memcpy(pTgt, fpInputBlocks[iBlockNo].fPtr, copy);
2509 HLTWarning("%s event: missing data block", eventname);
2515 HLTError("invalid struct");
2521 AliHLTUInt32_t AliHLTComponent::CalculateChecksum(const AliHLTUInt8_t* buffer, int size)
2523 // see header file for function documentation
2524 AliHLTUInt32_t remainder = 0;
2525 const AliHLTUInt8_t crcwidth=(8*sizeof(AliHLTUInt32_t));
2526 const AliHLTUInt32_t topbit=1 << (crcwidth-1);
2527 const AliHLTUInt32_t polynomial=0xD8; /* 11011 followed by 0's */
2530 // http://www.netrino.com/Embedded-Systems/How-To/CRC-Calculation-C-Code
2533 * Perform modulo-2 division, a byte at a time.
2535 for (int byte = 0; byte < size; ++byte)
2538 * Bring the next byte into the remainder.
2540 remainder ^= (buffer[byte] << (crcwidth - 8));
2543 * Perform modulo-2 division, a bit at a time.
2545 for (uint8_t bit = 8; bit > 0; --bit)
2548 * Try to divide the current data bit.
2550 if (remainder & topbit)
2552 remainder = (remainder << 1) ^ polynomial;
2556 remainder = (remainder << 1);
2562 * The final remainder is the CRC result.
2567 int AliHLTComponent::ExtractComponentTableEntry(const AliHLTUInt8_t* pBuffer, AliHLTUInt32_t size,
2568 string& retChainId, string& retCompId, string& retCompArgs,
2569 vector<AliHLTUInt32_t>& parents, int& level)
2571 // see header file for function documentation
2574 retCompArgs.clear();
2577 if (!pBuffer || size==0) return 0;
2579 const AliHLTComponentTableEntry* pEntry=reinterpret_cast<const AliHLTComponentTableEntry*>(pBuffer);
2580 if (size<8/* the initial size of the structure*/ ||
2581 pEntry==NULL || pEntry->fStructSize<8) return -ENOMSG;
2583 if (pEntry->fStructSize!=sizeof(AliHLTComponentTableEntry)) return -EBADF;
2584 level=pEntry->fLevel;
2585 const AliHLTUInt32_t* pParents=reinterpret_cast<const AliHLTUInt32_t*>(pEntry->fBuffer);
2586 const AliHLTUInt8_t* pEnd=pBuffer+size;
2588 if (pParents+pEntry->fNofParents>=reinterpret_cast<const AliHLTUInt32_t*>(pEnd)) return -ENODEV;
2589 for (unsigned int i=0; i<pEntry->fNofParents; i++, pParents++) {
2590 parents.push_back(*pParents);
2593 const char* pDescription=reinterpret_cast<const char*>(pParents);
2594 if (pDescription+pEntry->fSizeDescription>=reinterpret_cast<const char*>(pEnd) ||
2595 *(pDescription+pEntry->fSizeDescription)!=0) {
2599 TString descriptor=reinterpret_cast<const char*>(pDescription);
2603 TObjArray* pTokens=descriptor.Tokenize("{");
2606 if (pTokens->GetEntriesFast()>n) {
2607 retChainId=pTokens->At(n++)->GetName();
2609 if (pTokens->GetEntriesFast()>n) {
2610 compId=pTokens->At(n++)->GetName();
2614 if (!compId.IsNull() && (pTokens=compId.Tokenize(":"))!=NULL) {
2616 if (pTokens->GetEntriesFast()>n) {
2617 compId=pTokens->At(n++)->GetName();
2619 if (pTokens->GetEntriesFast()>n) {
2620 compArgs=pTokens->At(n++)->GetName();
2624 compId.ReplaceAll("}", "");
2625 compArgs.ReplaceAll("}", "");
2628 retCompArgs=compArgs;
2630 if (retChainId.size()==0) return -ENODATA;
2635 int AliHLTComponent::ExtractTriggerData(
2636 const AliHLTComponentTriggerData& trigData,
2637 const AliHLTUInt8_t (**attributes)[gkAliHLTBlockDAttributeCount],
2638 AliHLTUInt64_t* status,
2639 const AliRawDataHeader** cdh,
2640 AliHLTReadoutList* readoutlist,
2644 // see header file for function documentation
2646 // Check that the trigger data structure is the correct size.
2647 if (trigData.fStructSize != sizeof(AliHLTComponentTriggerData))
2652 log.LoggingVarargs(kHLTLogError, Class_Name(), FUNCTIONNAME(), __FILE__, __LINE__,
2653 "Invalid trigger structure size: %d but expected %d.", trigData.fStructSize, sizeof(AliHLTComponentTriggerData)
2659 // Get the size of the AliHLTEventTriggerData structure without the readout list part.
2660 // The way we do this here should also handle memory alignment correctly.
2661 AliHLTEventTriggerData* dummy = NULL;
2662 size_t sizeWithoutReadout = (char*)(&dummy->fReadoutList) - (char*)(dummy);
2664 // Check that the trigger data pointer points to data of a size we can handle.
2665 // Either it is the size of AliHLTEventTriggerData or the size of the old
2666 // version of AliHLTEventTriggerData using AliHLTEventDDLV0.
2667 if (trigData.fDataSize != sizeof(AliHLTEventTriggerData) and
2668 trigData.fDataSize != sizeWithoutReadout + sizeof(AliHLTEventDDLV0)
2674 log.LoggingVarargs(kHLTLogError, Class_Name(), FUNCTIONNAME(), __FILE__, __LINE__,
2675 "Invalid trigger data size: %d but expected %d.", trigData.fDataSize, sizeof(AliHLTEventTriggerData)
2681 AliHLTEventTriggerData* evtData = reinterpret_cast<AliHLTEventTriggerData*>(trigData.fData);
2682 assert(evtData != NULL);
2684 // Check that the CDH has 8 words.
2685 if (cdh != NULL and evtData->fCommonHeaderWordCnt != 8)
2690 log.LoggingVarargs(kHLTLogError, Class_Name(), FUNCTIONNAME(), __FILE__, __LINE__,
2691 "Common Data Header (CDH) has wrong number of data words: %d but expected %d",
2692 evtData->fCommonHeaderWordCnt, sizeof(AliRawDataHeader)/sizeof(AliHLTUInt32_t)
2698 // Check that the readout list has the correct count of words. i.e. something we can handle,
2699 if (readoutlist != NULL and
2700 evtData->fReadoutList.fCount != (unsigned)gkAliHLTDDLListSizeV0 and
2701 evtData->fReadoutList.fCount != (unsigned)gkAliHLTDDLListSizeV1
2707 log.LoggingVarargs(kHLTLogError, Class_Name(), FUNCTIONNAME(), __FILE__, __LINE__,
2708 "Readout list structure has wrong number of data words: %d but expected %d",
2709 evtData->fReadoutList.fCount, gkAliHLTDDLListSize
2715 if (attributes != NULL)
2717 *attributes = &evtData->fAttributes;
2721 *status = evtData->fHLTStatus;
2725 const AliRawDataHeader* cdhptr = reinterpret_cast<const AliRawDataHeader*>(&evtData->fCommonHeader[0]);
2728 if (readoutlist != NULL)
2730 *readoutlist = AliHLTReadoutList(evtData->fReadoutList);
2735 AliHLTUInt32_t AliHLTComponent::ExtractEventTypeFromCDH(const AliRawDataHeader* cdh)
2737 // see header file for function documentation
2739 UChar_t l1msg = cdh->GetL1TriggerMessage();
2740 if ((l1msg & 0x1) == 0x0) return gkAliEventTypeData;
2741 // The L2SwC bit must be one if we got here, i.e. l1msg & 0x1 == 0x1.
2742 if (((l1msg >> 2) & 0xF) == 0xE) return gkAliEventTypeStartOfRun;
2743 if (((l1msg >> 2) & 0xF) == 0xF) return gkAliEventTypeEndOfRun;
2744 // Check the C1T bit to see if this is a calibration event,
2745 // if not then it must be some other software trigger event.
2746 if (((l1msg >> 6) & 0x1) == 0x1) return gkAliEventTypeCalibration;
2747 return gkAliEventTypeSoftware;
2750 int AliHLTComponent::LoggingVarargs(AliHLTComponentLogSeverity severity,
2751 const char* originClass, const char* originFunc,
2752 const char* file, int line, ... ) const
2754 // see header file for function documentation
2758 va_start(args, line);
2760 // logging function needs to be const in order to be called from const member functions
2761 // without problems. But at this point we face the problem with virtual members which
2762 // are not necessarily const.
2763 AliHLTComponent* nonconst=const_cast<AliHLTComponent*>(this);
2764 AliHLTLogging::SetLogString(this, ", %p", "%s (%s_pfmt_): ",
2765 fChainId[0]!=0?fChainId.c_str():nonconst->GetComponentID(),
2766 nonconst->GetComponentID());
2767 iResult=SendMessage(severity, originClass, originFunc, file, line, AliHLTLogging::BuildLogString(NULL, args, true /*append*/));
2773 TUUID AliHLTComponent::GenerateGUID()
2775 // Generates a globally unique identifier.
2777 // Start by creating a new UUID. We cannot use the one automatically generated
2778 // by ROOT because the algorithm used will not guarantee unique IDs when generating
2779 // these UUIDs at a high rate in parallel.
2781 // We then use the generated UUID to form part of the random number seeds which
2782 // will be used to generate a proper random UUID. For good measure we use a MD5
2783 // hash also. Note that we want to use the TUUID class because it will combine the
2784 // host address information into the UUID. Using gSystem->GetHostByName() apparently
2785 // can cause problems on Windows machines with a firewall, because it always tries
2786 // to contact a DNS. The TUUID class handles this case appropriately.
2795 md5.Update(buf, sizeof(buf));
2798 dword[0] += gSystem->GetUid();
2799 dword[1] += gSystem->GetGid();
2800 dword[2] += gSystem->GetPid();
2801 for (int i = 0; i < 4; ++i)
2803 gRandom->SetSeed(dword[i]);
2804 dword[i] = gRandom->Integer(0xFFFFFFFF);
2806 md52.Update(buf, sizeof(buf));
2808 // To keep to the standard we need to set the version and reserved bits.
2809 word[3] = (word[3] & 0x0FFF) | 0x4000;
2810 buf[8] = (buf[8] & 0x3F) | 0x80;
2812 // Create the name of the new class and file.
2814 sprintf(uuidstr, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
2815 dword[0], word[2], word[3], buf[8], buf[9], buf[10], buf[11], buf[12], buf[13], buf[14], buf[15]
2818 uuid.SetUUID(uuidstr);
2822 int AliHLTComponent::ScanECSParam(const char* ecsParam)
2824 // see header file for function documentation
2826 // format of the parameter string from ECS
2827 // <command>;<parameterkey>=<parametervalue>;<parameterkey>=<parametervalue>;...
2828 // search for a subset of the parameterkeys
2832 // CTP_TRIGGER_CLASS=
2833 // DATA_FORMAT_VERSION=
2835 // HLT_OUT_DDL_LIST=
2836 // HLT_TRIGGER_CODE=
2839 // The command apears not to be sent by the online framework
2841 TString string=ecsParam;
2842 TObjArray* parameter=string.Tokenize(";");
2844 for (int i=0; i<parameter->GetEntriesFast(); i++) {
2845 TString entry=parameter->At(i)->GetName();
2846 HLTDebug("scanning ECS entry: %s", entry.Data());
2847 TObjArray* entryParams=entry.Tokenize("=");
2849 if (entryParams->GetEntriesFast()>1) {
2850 if ((((TObjString*)entryParams->At(0))->GetString()).CompareTo("CTP_TRIGGER_CLASS")==0) {
2851 int result=InitCTPTriggerClasses(entryParams->At(1)->GetName());
2852 if (iResult>=0 && result<0) iResult=result;
2854 // TODO: scan the other parameters
2855 // e.g. consistency check of run number
2867 int AliHLTComponent::SetupCTPData()
2869 // see header file for function documentation
2870 if (fpCTPData) delete fpCTPData;
2871 fpCTPData=new AliHLTCTPData;
2872 if (!fpCTPData) return -ENOMEM;
2876 int AliHLTComponent::InitCTPTriggerClasses(const char* ctpString)
2878 // see header file for function documentation
2879 if (!fpCTPData) return 0; // silently accept as the component has to announce that it want's the CTP info
2880 return fpCTPData->InitCTPTriggerClasses(ctpString);
2883 bool AliHLTComponent::EvaluateCTPTriggerClass(const char* expression, AliHLTComponentTriggerData& trigData) const
2885 // see header file for function documentation
2887 static bool bWarningThrown=false;
2888 if (!bWarningThrown) HLTError("Trigger classes not initialized, use SetupCTPData from DoInit()");
2889 bWarningThrown=true;
2893 return fpCTPData->EvaluateCTPTriggerClass(expression, trigData);
2896 int AliHLTComponent::CheckCTPTrigger(const char* name) const
2898 // see header file for function documentation
2900 static bool bWarningThrown=false;
2901 if (!bWarningThrown) HLTError("Trigger classes not initialized, use SetupCTPData from DoInit()");
2902 bWarningThrown=true;
2906 return fpCTPData->CheckTrigger(name);
2909 Double_t AliHLTComponent::GetBz()
2912 return AliHLTMisc::Instance().GetBz();
2915 Double_t AliHLTComponent::GetBz(const Double_t *r)
2917 // Returns Bz (kG) at the point "r" .
2918 return AliHLTMisc::Instance().GetBz(r);
2921 void AliHLTComponent::GetBxByBz(const Double_t r[3], Double_t b[3])
2923 // Returns Bx, By and Bz (kG) at the point "r" .
2924 AliHLTMisc::Instance().GetBxByBz(r, b);