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 "AliRawDataHeader.h"
40 #include "TObjArray.h"
41 #include "TObjectTable.h"
43 #include "TStopwatch.h"
48 #include "AliHLTMemoryFile.h"
49 #include "AliHLTMisc.h"
55 * default compression level for ROOT objects
57 #define ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION 5
58 #define ALIHLTCOMPONENT_STATTIME_SCALER 1000000
60 /** ROOT macro for the implementation of ROOT specific class methods */
61 ClassImp(AliHLTComponent);
63 /** stopwatch macro using the stopwatch guard */
64 #define ALIHLTCOMPONENT_STOPWATCH(type) AliHLTStopwatchGuard swguard(fpStopwatches!=NULL?reinterpret_cast<TStopwatch*>(fpStopwatches->At((int)type)):NULL)
65 //#define ALIHLTCOMPONENT_STOPWATCH(type)
67 /** stopwatch macro for operations of the base class */
68 #define ALIHLTCOMPONENT_BASE_STOPWATCH() ALIHLTCOMPONENT_STOPWATCH(kSWBase)
69 /** stopwatch macro for operations of the detector algorithm (DA) */
70 #define ALIHLTCOMPONENT_DA_STOPWATCH() ALIHLTCOMPONENT_STOPWATCH(kSWDA)
72 AliHLTComponent::AliHLTComponent()
80 fCurrentInputBlock(-1),
81 fSearchDataType(kAliHLTVoidDataType),
86 fOutputBufferFilled(0),
88 fpStopwatches(new TObjArray(kSWTypeCount)),
91 fCDBSetRunNoFunc(false),
96 fEventType(gkAliEventTypeUnknown),
99 fEventDoneDataSize(0),
100 fCompressionLevel(ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION)
104 , fLastPushBackTime(-1)
106 // see header file for class documentation
108 // refer to README to build package
110 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
111 memset(&fEnvironment, 0, sizeof(AliHLTAnalysisEnvironment));
112 if (fgpComponentHandler)
113 fgpComponentHandler->ScheduleRegister(this);
114 //SetLocalLoggingLevel(kHLTLogDefault);
117 AliHLTComponent::~AliHLTComponent()
119 // see header file for function documentation
120 if (fpBenchmark) delete fpBenchmark;
123 CleanupInputObjects();
124 if (fpStopwatches!=NULL) delete fpStopwatches;
126 AliHLTMemoryFilePList::iterator element=fMemFiles.begin();
127 while (element!=fMemFiles.end()) {
129 if ((*element)->IsClosed()==0) {
130 HLTWarning("memory file has not been closed, possible data loss or incomplete buffer");
131 // close but do not flush as we dont know whether the buffer is still valid
132 (*element)->CloseMemoryFile(0);
144 delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
153 AliHLTComponentHandler* AliHLTComponent::fgpComponentHandler=NULL;
155 int AliHLTComponent::SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite)
157 // see header file for function documentation
159 if (fgpComponentHandler==NULL || bOverwrite!=0)
160 fgpComponentHandler=pCH;
166 int AliHLTComponent::UnsetGlobalComponentHandler()
168 // see header file for function documentation
169 return SetGlobalComponentHandler(NULL,1);
172 int AliHLTComponent::SetComponentEnvironment(const AliHLTAnalysisEnvironment* comenv, void* environParam)
174 // see header file for function documentation
175 HLTLogKeyword(fChainId.c_str());
178 memset(&fEnvironment, 0, sizeof(AliHLTAnalysisEnvironment));
179 memcpy(&fEnvironment, comenv, comenv->fStructSize<sizeof(AliHLTAnalysisEnvironment)?comenv->fStructSize:sizeof(AliHLTAnalysisEnvironment));
180 fEnvironment.fStructSize=sizeof(AliHLTAnalysisEnvironment);
181 fEnvironment.fParam=environParam;
186 int AliHLTComponent::Init(const AliHLTAnalysisEnvironment* comenv, void* environParam, int argc, const char** argv )
188 // see header file for function documentation
189 HLTLogKeyword(fChainId.c_str());
192 SetComponentEnvironment(comenv, environParam);
195 fLastPushBackTime=-1;
198 const char** pArguments=NULL;
203 pArguments=new const char*[argc];
205 for (int i=0; i<argc && iResult>=0; i++) {
206 if (fComponentArgs.size()>0) fComponentArgs+=" ";
207 fComponentArgs+=argv[i];
209 if (argument.IsNull()) continue;
212 if (argument.CompareTo("-benchmark")==0) {
215 } else if (argument.BeginsWith("-loglevel=")) {
216 TString parameter=argument.ReplaceAll("-loglevel=", "");
217 parameter.Remove(TString::kLeading, ' '); // remove all blanks
218 if (parameter.BeginsWith("0x") &&
219 parameter.Replace(0,2,"",0).IsHex()) {
220 unsigned int loglevel=kHLTLogNone;
221 sscanf(parameter.Data(),"%x", &loglevel);
222 SetLocalLoggingLevel((AliHLTComponentLogSeverity)loglevel);
224 HLTError("wrong parameter for argument %s, hex number expected", argument.Data());
227 // -object-compression=
228 } else if (argument.BeginsWith("-object-compression=")) {
229 argument.ReplaceAll("-object-compression=", "");
230 if (argument.IsDigit()) {
231 fCompressionLevel=argument.Atoi();
232 if (fCompressionLevel<0 || fCompressionLevel>9) {
233 HLTWarning("invalid compression level %d, setting to default %d", fCompressionLevel, ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION);
234 fCompressionLevel=ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION;
237 HLTError("wrong parameter for argument -object-compression, number expected");
240 } else if (argument.BeginsWith("-pushback-period=")) {
241 argument.ReplaceAll("-pushback-period=", "");
242 if (argument.IsDigit()) {
243 fPushbackPeriod=argument.Atoi();
245 HLTError("wrong parameter for argument -pushback-period, number expected");
247 // -disable-component-stat
248 } else if (argument.CompareTo("-disable-component-stat")==0) {
249 fFlags|=kDisableComponentStat;
251 pArguments[iNofChildArgs++]=argv[i];
259 HLTError("missing parameter for argument %s", argument.Data());
263 iResult=CheckOCDBEntries();
266 iResult=DoInit(iNofChildArgs, pArguments);
271 // find out if the component wants to get the steering events
273 AliHLTComponentDataTypeList inputDt;
274 GetInputDataTypes(inputDt);
275 bool bRequireSteeringBlocks=false;
276 for (AliHLTComponentDataTypeList::iterator dt=inputDt.begin();
277 dt!=inputDt.end() && !bRequireSteeringBlocks;
279 bRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeSOR);
280 bRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeRunType);
281 bRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeEOR);
282 bRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeDDL);
283 bRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeComponentStatistics);
285 if (bRequireSteeringBlocks) fFlags|=kRequireSteeringBlocks;
287 if (pArguments) delete [] pArguments;
289 #if defined(HLT_COMPONENT_STATISTICS)
290 // benchmarking stopwatch for the component statistics
291 fpBenchmark=new TStopwatch;
292 #endif // HLT_COMPONENT_STATISTICS
297 int AliHLTComponent::Deinit()
299 // see header file for function documentation
300 HLTLogKeyword(fChainId.c_str());
304 // TODO: the warning should be kept, but the condition is wrong since the
305 // AliHLTRunDesc is set before the SOR event in the SetRunDescription
306 // method. A couple of state flags should be defined but that is a bit more
307 // work to do. For the moment disable the warning (2009-07-01)
308 // 2009-09-08: now, the info is not cleared in the ProcessEvent, because it
309 // might be needed by components during the event processing.
310 //HLTWarning("did not receive EOR for run %d", fpRunDesc->fRunNo);
311 AliHLTRunDesc* pRunDesc=fpRunDesc;
325 int AliHLTComponent::InitCDB(const char* cdbPath, AliHLTComponentHandler* pHandler)
327 // see header file for function documentation
329 HLTInfo("Using CDB: %s", cdbPath);
331 // I have to think about separating the library handling from the
332 // component handler. Requiring the component handler here is not
333 // the cleanest solution.
334 // We presume the library already to be loaded, which is the case
335 // because it is loaded in the initialization of the logging functionality
338 AliHLTMiscInitCDB_t pFunc=(AliHLTMiscInitCDB_t)pHandler->FindSymbol(ALIHLTMISC_LIBRARY, ALIHLTMISC_INIT_CDB);
341 if (cdbPath && cdbPath[0]!=0) {
343 // very temporary fix, have to check for other formats
344 if (!path.BeginsWith("local://")) {
349 if ((iResult=(*pFunc)(path.Data()))>=0) {
350 if (!(fCDBSetRunNoFunc=pHandler->FindSymbol(ALIHLTMISC_LIBRARY, ALIHLTMISC_SET_CDB_RUNNO))) {
351 Message(NULL, kHLTLogWarning, "AliHLTComponent::InitCDB", "init CDB",
352 "can not find function to set CDB run no");
356 Message(NULL, kHLTLogError, "AliHLTComponent::InitCDB", "init CDB",
357 "can not find initialization function");
366 int AliHLTComponent::SetCDBRunNo(int runNo)
368 // see header file for function documentation
369 if (!fCDBSetRunNoFunc) return 0;
370 return (*((AliHLTMiscSetCDBRunNo_t)fCDBSetRunNoFunc))(runNo);
373 int AliHLTComponent::SetRunDescription(const AliHLTRunDesc* desc, const char* /*runType*/)
375 // see header file for function documentation
376 if (!desc) return -EINVAL;
377 if (desc->fStructSize!=sizeof(AliHLTRunDesc)) {
378 HLTError("invalid size of RunDesc struct (%ul)", desc->fStructSize);
383 fpRunDesc=new AliHLTRunDesc;
384 if (!fpRunDesc) return -ENOMEM;
385 *fpRunDesc=kAliHLTVoidRunDesc;
388 if (fpRunDesc->fRunNo!=kAliHLTVoidRunNo && fpRunDesc->fRunNo!=desc->fRunNo) {
389 HLTWarning("Run description has already been set");
392 SetCDBRunNo(fpRunDesc->fRunNo);
393 // TODO: we have to decide about the runType
397 int AliHLTComponent::SetComponentDescription(const char* desc)
399 // see header file for function documentation
403 TString descriptor=desc;
404 TObjArray* pTokens=descriptor.Tokenize(" ");
406 for (int i=0; i<pTokens->GetEntriesFast() && iResult>=0; i++) {
407 TString argument=pTokens->At(i++)->GetName();
408 if (!argument || argument.IsNull()) continue;
411 if (argument.BeginsWith("chainid")) {
412 argument.ReplaceAll("chainid", "");
413 if (argument.BeginsWith("=")) {
414 fChainId=argument.Replace(0,1,"");
415 fChainIdCrc=CalculateChecksum((const AliHLTUInt8_t*)fChainId.c_str(), fChainId.length());
416 HLTDebug("setting component description: chain id %s crc 0x%8x", fChainId.c_str(), fChainIdCrc);
421 HLTWarning("unknown component description %s", argument.Data());
430 int AliHLTComponent::ConfigureFromArgumentString(int argc, const char** argv)
432 // Configure from an array of argument strings
433 // Function supports individual arguments in the argv array and arguments
434 // separated by blanks.
436 // Each argv entry can contain blanks, quotes and newlines. Newlines are interpreted
437 // as blanks. Enclosing quotes deactivate blank as delimiter.
438 // The separated arguments are stored in an array of strings, and the pointers to
439 // those strings in an array of pointers. The latter is used in the custom argument
440 // scan of the component.
443 vector<string> stringarray; // array of argument copies
444 // array of pointers to the argument copies
445 // note: not necessarily in sync with the entries in stringarray
446 // can contain any pointer to valid arguments in arbitrary sequence
447 vector<const char*> ptrarray;
451 for (i=0; i<argc && iResult>=0; i++) {
453 if (argument.IsWhitespace()) continue;
455 // special handling for single component arguments ending with
456 // a sequence of blanks. All characters until the first occurence
457 // of a blank are removed. If the remainder contains only whitespaces
458 // the argument is a single argument, just having whitespaces at the end.
459 argument.Remove(0, argument.First(' '));
460 if (argument.IsWhitespace()) {
461 ptrarray.push_back(argv[i]);
465 // outer loop checks for enclosing quotes
466 // extra blank to insert blank token before leading quotes, then
467 // quoted arguments are always the even ones
470 // insert blank in consecutive quotes to correctly tokenize
471 argument.ReplaceAll("''", "' '");
472 // replace newlines by blanks
473 argument.ReplaceAll("\n", " ");
474 if (argument.IsNull()) continue;
475 TObjArray* pTokensQuote=argument.Tokenize("'");
477 if (pTokensQuote->GetEntriesFast()>0) {
478 for (int k=0; k<pTokensQuote->GetEntriesFast(); k++) {
479 argument=pTokensQuote->At(k)->GetName();
480 if (argument.IsWhitespace()) continue;
482 // every second entry is enclosed by quotes and thus
483 // one single argument
484 stringarray.push_back(argument.Data());
485 ptrarray.push_back(stringarray.back().c_str());
487 TObjArray* pTokens=argument.Tokenize(" ");
489 if (pTokens->GetEntriesFast()>0) {
490 for (int n=0; n<pTokens->GetEntriesFast(); n++) {
491 TString data=pTokens->At(n)->GetName();
492 if (!data.IsNull() && !data.IsWhitespace()) {
493 stringarray.push_back(data.Data());
494 ptrarray.push_back(stringarray.back().c_str());
507 for (i=0; (unsigned)i<ptrarray.size() && iResult>=0;) {
508 int result=ScanConfigurationArgument(ptrarray.size()-i, &ptrarray[i]);
510 HLTWarning("unknown component argument %s", ptrarray[i]);
512 } else if (result>0) {
516 if (iResult==-EINVAL) {
517 HLTError("unknown argument %s", ptrarray[i]);
518 } else if (iResult==-EPROTO) {
519 HLTError("missing/wrong parameter for argument %s (%s)", ptrarray[i], (ptrarray.size()>(unsigned)i+1)?ptrarray[i+1]:"missing");
521 HLTError("scan of argument %s failed (%d)", ptrarray[i], iResult);
529 int AliHLTComponent::ConfigureFromCDBTObjString(const char* entries, const char* key)
531 // load a list of OCDB objects and configure from the objects
532 // can either be a TObjString or a TMap with a TObjString:TObjString key-value pair
535 TString confEntries=entries;
536 TObjArray* pTokens=confEntries.Tokenize(" ");
538 for (int n=0; n<pTokens->GetEntriesFast(); n++) {
539 const char* path=pTokens->At(n)->GetName();
540 const char* chainId=GetChainId();
541 HLTInfo("configure from entry \"%s\"%s%s, chain id %s", path, key?" key ":"",key?key:"", (chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
542 TObject* pOCDBObject = LoadAndExtractOCDBObject(path, key);
544 TObjString* pString=dynamic_cast<TObjString*>(pOCDBObject);
546 TMap* pMap=dynamic_cast<TMap*>(pOCDBObject);
548 // this is the case where no key has been specified and the OCDB
549 // object is a TMap, search for the default key
550 TObject* pObject=pMap->GetValue("default");
551 if (pObject && (pString=dynamic_cast<TObjString*>(pObject))!=NULL) {
552 HLTInfo("using default key of TMap of configuration object \"%s\"", path);
554 HLTError("no default key available in TMap of configuration object \"%s\"", path);
562 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
563 arguments+=pString->GetString().Data();
566 HLTError("configuration object \"%s\"%s%s has wrong type, required TObjString", path, key?" key ":"",key?key:"");
570 HLTError("can not fetch object \"%s\" from OCDB", path);
576 if (iResult>=0 && !arguments.IsNull()) {
577 const char* array=arguments.Data();
578 iResult=ConfigureFromArgumentString(1, &array);
583 TObject* AliHLTComponent::LoadAndExtractOCDBObject(const char* path, int version, int subVersion, const char* key)
585 // see header file for function documentation
586 AliCDBEntry* pEntry=AliHLTMisc::Instance().LoadOCDBEntry(path, GetRunNo(), version, subVersion);
587 if (!pEntry) return NULL;
588 TObject* pObject=AliHLTMisc::Instance().ExtractObject(pEntry);
589 TMap* pMap=dynamic_cast<TMap*>(pObject);
591 pObject=pMap->GetValue(key);
593 pObject=pMap->GetValue("default");
595 HLTWarning("can not find object for key \"%s\" in TMap of configuration object \"%s\", using key \"default\"", key, path);
599 HLTError("can not find object for key \"%s\" in TMap of configuration object \"%s\"", key, path);
606 int AliHLTComponent::DoInit( int /*argc*/, const char** /*argv*/)
608 // default implementation, childs can overload
609 HLTLogKeyword("dummy");
613 int AliHLTComponent::DoDeinit()
615 // default implementation, childs can overload
616 HLTLogKeyword("dummy");
620 int AliHLTComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/)
622 // default implementation, childs can overload
623 HLTLogKeyword("dummy");
627 int AliHLTComponent::ReadPreprocessorValues(const char* /*modules*/)
629 // default implementation, childs can overload
630 HLTLogKeyword("dummy");
634 int AliHLTComponent::ScanConfigurationArgument(int /*argc*/, const char** /*argv*/)
636 // default implementation, childs can overload
637 HLTLogKeyword("dummy");
638 HLTWarning("The function needs to be implemented by the component");
642 int AliHLTComponent::StartOfRun()
644 // default implementation, childs can overload
645 HLTLogKeyword("dummy");
649 int AliHLTComponent::EndOfRun()
651 // default implementation, childs can overload
652 HLTLogKeyword("dummy");
657 int AliHLTComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& /*tgtList*/)
659 // default implementation, childs can overload
660 HLTLogKeyword("dummy");
664 void AliHLTComponent::GetOCDBObjectDescription( TMap* const /*targetArray*/)
666 // default implementation, childs can overload
667 HLTLogKeyword("dummy");
670 int AliHLTComponent::CheckOCDBEntries(const TMap* const externList)
672 // check the availability of the OCDB entry descriptions in the TMap
673 // key : complete OCDB path of the entry
674 // value : auxiliary object - short description
675 // if the external map was not provided the function invokes
676 // interface function GetOCDBObjectDescription() to retrieve the list.
679 iResult=AliHLTMisc::Instance().CheckOCDBEntries(externList);
683 pMap->SetOwnerKeyValue(kTRUE);
684 GetOCDBObjectDescription(pMap);
685 iResult=AliHLTMisc::Instance().CheckOCDBEntries(pMap);
694 void AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2] ) const
696 // see header file for function documentation
697 memset( output, 0, kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2 );
698 strncat( output, type.fOrigin, kAliHLTComponentDataTypefOriginSize );
699 strncat( output, ":", 1 );
700 strncat( output, type.fID, kAliHLTComponentDataTypefIDsize );
703 string AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, int mode)
705 // see header file for function documentation
709 // aligned to 8 and 4 chars respectively, blocks enclosed in quotes and
710 // separated by blank e.g.
716 for (i=0; i<kAliHLTComponentDataTypefIDsize; i++) {
717 unsigned char* puc=(unsigned char*)type.fID;
719 sprintf(tmp, "\\%x", type.fID[i]);
721 sprintf(tmp, "%c", type.fID[i]);
725 for (i=0; i<kAliHLTComponentDataTypefOriginSize; i++) {
726 unsigned char* puc=(unsigned char*)type.fOrigin;
728 sprintf(tmp, "\\%x", type.fOrigin[i]);
730 sprintf(tmp, "%c", type.fOrigin[i]);
737 // origin typeid as numbers separated by colon e.g.
738 // aligned to 8 and 4 chars respectively, all characters separated by
740 // '84'80'67'32':'68'68'76'95'82'65'87'32'
744 for (i=0; i<kAliHLTComponentDataTypefOriginSize; i++) {
745 sprintf(tmp, "'%d", type.fOrigin[i]);
749 for (i=0; i<kAliHLTComponentDataTypefIDsize; i++) {
750 sprintf(tmp, "%d'", type.fID[i]);
756 // origin typeid separated by colon e.g.
757 // aligned to 8 and 4 chars respectively, all characters separated by
759 // 'T'P'C' ':'D'D'L'_'R'A'W' '
763 for (i=0; i<kAliHLTComponentDataTypefOriginSize; i++) {
764 unsigned char* puc=(unsigned char*)type.fOrigin;
766 sprintf(tmp, "'\\%x", type.fOrigin[i]);
768 sprintf(tmp, "'%c", type.fOrigin[i]);
772 for (i=0; i<kAliHLTComponentDataTypefIDsize; i++) {
773 unsigned char* puc=(unsigned char*)type.fID;
775 sprintf(tmp, "\\%x'", type.fID[i]);
777 sprintf(tmp, "%c'", type.fID[i]);
784 // aligned to 8 and 4 chars respectively, separated by colon e.g.
786 if (type==kAliHLTVoidDataType) {
789 // some gymnastics in order to avoid a '0' which is part of either or both
790 // ID and origin terminating the whole string. Unfortunately, string doesn't
791 // stop appending at the '0' if the number of elements to append was
792 // explicitely specified
794 tmp.append(type.fOrigin, kAliHLTComponentDataTypefOriginSize);
795 out.append(tmp.c_str());
798 tmp.append(type.fID, kAliHLTComponentDataTypefIDsize);
799 out.append(tmp.c_str());
805 void* AliHLTComponent::AllocMemory( unsigned long size )
807 // see header file for function documentation
808 if (fEnvironment.fAllocMemoryFunc)
809 return (*fEnvironment.fAllocMemoryFunc)(fEnvironment.fParam, size );
810 HLTFatal("no memory allocation handler registered");
814 int AliHLTComponent::MakeOutputDataBlockList( const AliHLTComponentBlockDataList& blocks, AliHLTUInt32_t* blockCount,
815 AliHLTComponentBlockData** outputBlocks )
817 // see header file for function documentation
818 if ( blockCount==NULL || outputBlocks==NULL )
820 AliHLTUInt32_t count = blocks.size();
824 *outputBlocks = NULL;
827 *outputBlocks = reinterpret_cast<AliHLTComponentBlockData*>( AllocMemory( sizeof(AliHLTComponentBlockData)*count ) );
828 if ( !*outputBlocks )
830 for ( unsigned long i = 0; i < count; i++ ) {
831 (*outputBlocks)[i] = blocks[i];
832 if (MatchExactly(blocks[i].fDataType, kAliHLTAnyDataType)) {
833 (*outputBlocks)[i].fDataType=GetOutputDataType();
834 /* data type was set to the output data type by the PubSub AliRoot
835 Wrapper component, if data type of the block was ********:****.
836 Now handled by the component base class in order to have same
837 behavior when running embedded in AliRoot
838 memset((*outputBlocks)[i].fDataType.fID, '*', kAliHLTComponentDataTypefIDsize);
839 memset((*outputBlocks)[i].fDataType.fOrigin, '*', kAliHLTComponentDataTypefOriginSize);
848 int AliHLTComponent::GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd ) const
850 // see header file for function documentation
851 if (fEnvironment.fGetEventDoneDataFunc)
852 return (*fEnvironment.fGetEventDoneDataFunc)(fEnvironment.fParam, fCurrentEvent, size, edd );
856 int AliHLTComponent::ReserveEventDoneData( unsigned long size )
858 // see header file for function documentation
861 unsigned long capacity=fEventDoneDataSize;
862 if (fEventDoneData) capacity-=sizeof(AliHLTComponentEventDoneData)+fEventDoneData->fDataSize;
864 unsigned long newSize=sizeof(AliHLTComponentEventDoneData)+size+(fEventDoneDataSize-capacity);
865 AliHLTComponentEventDoneData* newEDD = reinterpret_cast<AliHLTComponentEventDoneData*>( new AliHLTUInt8_t[newSize] );
868 newEDD->fStructSize = sizeof(AliHLTComponentEventDoneData);
869 newEDD->fDataSize = 0;
870 newEDD->fData = reinterpret_cast<AliHLTUInt8_t*>(newEDD)+newEDD->fStructSize;
871 if (fEventDoneData) {
872 memcpy( newEDD->fData, fEventDoneData->fData, fEventDoneData->fDataSize );
873 newEDD->fDataSize = fEventDoneData->fDataSize;
874 delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
876 fEventDoneData = newEDD;
877 fEventDoneDataSize = newSize;
883 int AliHLTComponent::PushEventDoneData( AliHLTUInt32_t eddDataWord )
885 // see header file for function documentation
888 if (fEventDoneData->fDataSize+sizeof(AliHLTUInt32_t)>fEventDoneDataSize)
890 *reinterpret_cast<AliHLTUInt32_t*>((reinterpret_cast<AliHLTUInt8_t*>(fEventDoneData->fData)+fEventDoneData->fDataSize)) = eddDataWord;
891 fEventDoneData->fDataSize += sizeof(AliHLTUInt32_t);
895 void AliHLTComponent::ReleaseEventDoneData()
897 // see header file for function documentation
899 delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
900 fEventDoneData = NULL;
901 fEventDoneDataSize = 0;
905 int AliHLTComponent::FindMatchingDataTypes(AliHLTComponent* pConsumer, AliHLTComponentDataTypeList* tgtList)
907 // see header file for function documentation
910 AliHLTComponentDataTypeList itypes;
911 AliHLTComponentDataTypeList otypes;
912 otypes.push_back(GetOutputDataType());
913 if (MatchExactly(otypes[0],kAliHLTMultipleDataType)) {
916 if ((count=GetOutputDataTypes(otypes))>0) {
917 } else if (GetComponentType()!=kSink) {
918 HLTWarning("component %s indicates multiple output data types but GetOutputDataTypes returns %d", GetComponentID(), count);
921 pConsumer->GetInputDataTypes(itypes);
922 AliHLTComponentDataTypeList::iterator otype=otypes.begin();
923 for (;otype!=otypes.end();otype++) {
924 //PrintDataTypeContent((*otype), "publisher \'%s\'");
925 if ((*otype)==(kAliHLTAnyDataType|kAliHLTDataOriginPrivate)) {
926 if (tgtList) tgtList->push_back(*otype);
931 AliHLTComponentDataTypeList::iterator itype=itypes.begin();
932 for ( ; itype!=itypes.end() && (*itype)!=(*otype) ; itype++) {/* empty body */};
933 //if (itype!=itypes.end()) PrintDataTypeContent(*itype, "consumer \'%s\'");
934 if (itype!=itypes.end()) {
935 if (tgtList) tgtList->push_back(*otype);
945 void AliHLTComponent::PrintDataTypeContent(AliHLTComponentDataType& dt, const char* format)
947 // see header file for function documentation
948 const char* fmt="\'%s\'";
949 if (format) fmt=format;
950 AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, Form(fmt, (DataType2Text(dt)).c_str()));
951 AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL,
952 Form("%x %x %x %x %x %x %x %x : %x %x %x %x",
967 void AliHLTComponent::FillBlockData( AliHLTComponentBlockData& blockData )
969 // see header file for function documentation
970 blockData.fStructSize = sizeof(blockData);
971 FillShmData( blockData.fShmKey );
972 blockData.fOffset = ~(AliHLTUInt32_t)0;
973 blockData.fPtr = NULL;
975 FillDataType( blockData.fDataType );
976 blockData.fSpecification = kAliHLTVoidDataSpec;
979 void AliHLTComponent::FillShmData( AliHLTComponentShmData& shmData )
981 // see header file for function documentation
982 shmData.fStructSize = sizeof(shmData);
983 shmData.fShmType = gkAliHLTComponentInvalidShmType;
984 shmData.fShmID = gkAliHLTComponentInvalidShmID;
987 void AliHLTComponent::FillDataType( AliHLTComponentDataType& dataType )
989 // see header file for function documentation
990 dataType=kAliHLTAnyDataType;
993 void AliHLTComponent::CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt)
995 // see header file for function documentation
996 memcpy(&tgtdt.fID[0], &srcdt.fID[0], kAliHLTComponentDataTypefIDsize);
997 memcpy(&tgtdt.fOrigin[0], &srcdt.fOrigin[0], kAliHLTComponentDataTypefOriginSize);
1000 void AliHLTComponent::SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin)
1002 // see header file for function documentation
1003 tgtdt.fStructSize=sizeof(AliHLTComponentDataType);
1005 memset(&tgtdt.fID[0], 0, kAliHLTComponentDataTypefIDsize);
1006 strncpy(&tgtdt.fID[0], id, strlen(id)<(size_t)kAliHLTComponentDataTypefIDsize?strlen(id):kAliHLTComponentDataTypefIDsize);
1009 memset(&tgtdt.fOrigin[0], 0, kAliHLTComponentDataTypefOriginSize);
1010 strncpy(&tgtdt.fOrigin[0], origin, strlen(origin)<(size_t)kAliHLTComponentDataTypefOriginSize?strlen(origin):kAliHLTComponentDataTypefOriginSize);
1014 void AliHLTComponent::SetDataType(AliHLTComponentDataType& dt, AliHLTUInt64_t id, AliHLTUInt32_t origin)
1016 // see header file for function documentation
1017 dt.fStructSize=sizeof(AliHLTComponentDataType);
1018 assert(kAliHLTComponentDataTypefIDsize==sizeof(id));
1019 assert(kAliHLTComponentDataTypefOriginSize==sizeof(origin));
1020 memcpy(&dt.fID, &id, kAliHLTComponentDataTypefIDsize);
1021 memcpy(&dt.fOrigin, &origin, kAliHLTComponentDataTypefOriginSize);
1024 void AliHLTComponent::FillEventData(AliHLTComponentEventData& evtData)
1026 // see header file for function documentation
1027 memset(&evtData, 0, sizeof(AliHLTComponentEventData));
1028 evtData.fStructSize=sizeof(AliHLTComponentEventData);
1029 evtData.fEventID=kAliHLTVoidEventID;
1032 void AliHLTComponent::PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt)
1034 // see header file for function documentation
1036 msg.Form("AliHLTComponentDataType(%d): ID=\"", dt.fStructSize);
1037 for ( int i = 0; i < kAliHLTComponentDataTypefIDsize; i++ ) {
1038 if (dt.fID[i]!=0) msg+=dt.fID[i];
1041 msg+="\" Origin=\"";
1042 for ( int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++ ) {
1043 if (dt.fOrigin[i]!=0) msg+=dt.fOrigin[i];
1047 AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, msg.Data());
1050 int AliHLTComponent::GetEventCount() const
1052 // see header file for function documentation
1056 int AliHLTComponent::IncrementEventCounter()
1058 // see header file for function documentation
1059 if (fEventCount>=0) fEventCount++;
1063 int AliHLTComponent::GetNumberOfInputBlocks() const
1065 // see header file for function documentation
1066 if (fpInputBlocks!=NULL) {
1067 return fCurrentEventData.fBlockCnt;
1072 AliHLTEventID_t AliHLTComponent::GetEventId() const
1074 // see header file for function documentation
1075 if (fpInputBlocks!=NULL) {
1076 return fCurrentEventData.fEventID;
1081 const TObject* AliHLTComponent::GetFirstInputObject(const AliHLTComponentDataType& dt,
1082 const char* classname,
1085 // see header file for function documentation
1086 ALIHLTCOMPONENT_BASE_STOPWATCH();
1088 if (classname) fClassName=classname;
1089 else fClassName.clear();
1090 int idx=FindInputBlock(fSearchDataType, 0, 1);
1093 HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(dt).c_str());
1094 if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) {
1095 fCurrentInputBlock=idx;
1102 const TObject* AliHLTComponent::GetFirstInputObject(const char* dtID,
1103 const char* dtOrigin,
1104 const char* classname,
1107 // see header file for function documentation
1108 ALIHLTCOMPONENT_BASE_STOPWATCH();
1109 AliHLTComponentDataType dt;
1110 SetDataType(dt, dtID, dtOrigin);
1111 return GetFirstInputObject(dt, classname, bForce);
1114 const TObject* AliHLTComponent::GetNextInputObject(int bForce)
1116 // see header file for function documentation
1117 ALIHLTCOMPONENT_BASE_STOPWATCH();
1118 int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1, 1);
1119 //HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(fSearchDataType).c_str());
1122 if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) {
1123 fCurrentInputBlock=idx;
1129 int AliHLTComponent::FindInputBlock(const AliHLTComponentDataType& dt, int startIdx, int bObject) const
1131 // see header file for function documentation
1132 int iResult=-ENOENT;
1133 if (fpInputBlocks!=NULL) {
1134 int idx=startIdx<0?0:startIdx;
1135 for ( ; (UInt_t)idx<fCurrentEventData.fBlockCnt && iResult==-ENOENT; idx++) {
1136 if (dt!=fpInputBlocks[idx].fDataType) continue;
1139 if (fpInputBlocks[idx].fPtr==NULL) continue;
1140 AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr);
1141 if (firstWord!=fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) continue;
1149 TObject* AliHLTComponent::CreateInputObject(int idx, int bForce)
1151 // see header file for function documentation
1153 if (fpInputBlocks!=NULL) {
1154 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
1155 if (fpInputBlocks[idx].fPtr) {
1156 AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr);
1157 if (firstWord==fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) {
1158 HLTDebug("create object from block %d size %d", idx, fpInputBlocks[idx].fSize);
1159 AliHLTMessage msg(fpInputBlocks[idx].fPtr, fpInputBlocks[idx].fSize);
1160 TClass* objclass=msg.GetClass();
1161 pObj=msg.ReadObject(objclass);
1162 if (pObj && objclass) {
1163 HLTDebug("object %p type %s created", pObj, objclass->GetName());
1167 } else if (bForce!=0) {
1168 HLTError("size mismatch: block size %d, indicated %d", fpInputBlocks[idx].fSize, firstWord+sizeof(AliHLTUInt32_t));
1171 HLTFatal("block descriptor empty");
1174 HLTError("index %d out of range %d", idx, fCurrentEventData.fBlockCnt);
1177 HLTError("no input blocks available");
1183 TObject* AliHLTComponent::GetInputObject(int idx, const char* /*classname*/, int bForce)
1185 // see header file for function documentation
1186 if (fpInputObjects==NULL) {
1187 fpInputObjects=new TObjArray(fCurrentEventData.fBlockCnt);
1190 if (fpInputObjects) {
1191 pObj=fpInputObjects->At(idx);
1193 pObj=CreateInputObject(idx, bForce);
1195 fpInputObjects->AddAt(pObj, idx);
1199 HLTFatal("memory allocation failed: TObjArray of size %d", fCurrentEventData.fBlockCnt);
1204 int AliHLTComponent::CleanupInputObjects()
1206 // see header file for function documentation
1207 if (!fpInputObjects) return 0;
1208 TObjArray* array=fpInputObjects;
1209 fpInputObjects=NULL;
1210 for (int i=0; i<array->GetEntriesFast(); i++) {
1211 TObject* pObj=array->At(i);
1212 // grrr, garbage collection strikes back: When read via AliHLTMessage
1213 // (CreateInputObject), and written to a TFile afterwards, the
1214 // TFile::Close calls ROOOT's garbage collection. No clue why the
1215 // object ended up in the key list and needs to be deleted
1217 // Matthias 09.11.2008 follow up
1218 // This approach doesn't actually work in all cases: the object table
1219 // can be switched off globally, the flag needs to be checked here as
1220 // well in order to avoid memory leaks.
1221 // This means we have to find another solution for the problem if it
1224 (!TObject::GetObjectStat() || gObjectTable->PtrIsValid(pObj))) {
1232 AliHLTComponentDataType AliHLTComponent::GetDataType(const TObject* pObject)
1234 // see header file for function documentation
1235 ALIHLTCOMPONENT_BASE_STOPWATCH();
1236 AliHLTComponentDataType dt=kAliHLTVoidDataType;
1237 int idx=fCurrentInputBlock;
1239 if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
1241 HLTError("unknown object %p", pObject);
1245 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
1246 dt=fpInputBlocks[idx].fDataType;
1248 HLTFatal("severe internal error, index out of range");
1254 AliHLTUInt32_t AliHLTComponent::GetSpecification(const TObject* pObject)
1256 // see header file for function documentation
1257 ALIHLTCOMPONENT_BASE_STOPWATCH();
1258 AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec;
1259 int idx=fCurrentInputBlock;
1261 if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
1263 HLTError("unknown object %p", pObject);
1267 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
1268 iSpec=fpInputBlocks[idx].fSpecification;
1270 HLTFatal("severe internal error, index out of range");
1276 int AliHLTComponent::Forward(const TObject* pObject)
1278 // see header file for function documentation
1280 int idx=fCurrentInputBlock;
1282 if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
1284 HLTError("unknown object %p", pObject);
1289 fOutputBlocks.push_back(fpInputBlocks[idx]);
1294 int AliHLTComponent::Forward(const AliHLTComponentBlockData* pBlock)
1296 // see header file for function documentation
1298 int idx=fCurrentInputBlock;
1300 if ((idx=FindInputBlock(pBlock))>=0) {
1302 HLTError("unknown Block %p", pBlock);
1307 // check for fpInputBlocks pointer done in FindInputBlock
1308 fOutputBlocks.push_back(fpInputBlocks[idx]);
1313 const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const AliHLTComponentDataType& dt)
1315 // see header file for function documentation
1316 ALIHLTCOMPONENT_BASE_STOPWATCH();
1319 int idx=FindInputBlock(fSearchDataType, 0);
1320 const AliHLTComponentBlockData* pBlock=NULL;
1322 // check for fpInputBlocks pointer done in FindInputBlock
1323 pBlock=&fpInputBlocks[idx];
1324 fCurrentInputBlock=idx;
1329 const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const char* dtID,
1330 const char* dtOrigin)
1332 // see header file for function documentation
1333 ALIHLTCOMPONENT_BASE_STOPWATCH();
1334 AliHLTComponentDataType dt;
1335 SetDataType(dt, dtID, dtOrigin);
1336 return GetFirstInputBlock(dt);
1339 const AliHLTComponentBlockData* AliHLTComponent::GetInputBlock(int index) const
1341 // see header file for function documentation
1342 ALIHLTCOMPONENT_BASE_STOPWATCH();
1343 assert( 0 <= index and index < (int)fCurrentEventData.fBlockCnt );
1344 return &fpInputBlocks[index];
1347 const AliHLTComponentBlockData* AliHLTComponent::GetNextInputBlock()
1349 // see header file for function documentation
1350 ALIHLTCOMPONENT_BASE_STOPWATCH();
1351 int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1);
1352 const AliHLTComponentBlockData* pBlock=NULL;
1354 // check for fpInputBlocks pointer done in FindInputBlock
1355 pBlock=&fpInputBlocks[idx];
1356 fCurrentInputBlock=idx;
1361 int AliHLTComponent::FindInputBlock(const AliHLTComponentBlockData* pBlock) const
1363 // see header file for function documentation
1364 int iResult=-ENOENT;
1365 if (fpInputBlocks!=NULL) {
1367 if (pBlock>=fpInputBlocks && pBlock<fpInputBlocks+fCurrentEventData.fBlockCnt) {
1368 iResult=(int)(pBlock-fpInputBlocks);
1377 AliHLTUInt32_t AliHLTComponent::GetSpecification(const AliHLTComponentBlockData* pBlock)
1379 // see header file for function documentation
1380 ALIHLTCOMPONENT_BASE_STOPWATCH();
1381 AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec;
1382 int idx=fCurrentInputBlock;
1384 if (fpInputObjects==NULL || (idx=FindInputBlock(pBlock))>=0) {
1386 HLTError("unknown Block %p", pBlock);
1390 // check for fpInputBlocks pointer done in FindInputBlock
1391 iSpec=fpInputBlocks[idx].fSpecification;
1396 int AliHLTComponent::PushBack(const TObject* pObject, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
1397 void* pHeader, int headerSize)
1399 // see header file for function documentation
1400 ALIHLTCOMPONENT_BASE_STOPWATCH();
1403 if (fPushbackPeriod>0) {
1404 // suppress the output
1406 if (fLastPushBackTime<0 || (int)time.Get()-fLastPushBackTime<fPushbackPeriod) return 0;
1409 AliHLTMessage msg(kMESS_OBJECT);
1410 msg.SetCompressionLevel(fCompressionLevel);
1411 msg.WriteObject(pObject);
1412 Int_t iMsgLength=msg.Length();
1414 // Matthias Sep 2008
1415 // NOTE: AliHLTMessage does implement it's own SetLength method
1416 // which is not architecture independent. The original SetLength
1417 // stores the size always in network byte order.
1418 // I'm trying to remember the rational for that, might be that
1419 // it was just some lack of knowledge. Want to change this, but
1420 // has to be done carefullt to be backward compatible.
1421 msg.SetLength(); // sets the length to the first (reserved) word
1423 // does nothing if the level is 0
1426 char *mbuf = msg.Buffer();
1427 if (msg.CompBuffer()) {
1428 msg.SetLength(); // set once more to have to byte order
1429 mbuf = msg.CompBuffer();
1430 iMsgLength = msg.CompLength();
1433 iResult=InsertOutputBlock(mbuf, iMsgLength, dt, spec, pHeader, headerSize);
1435 HLTDebug("object %s (%p) size %d compression %d inserted to output", pObject->ClassName(), pObject, iMsgLength, msg.GetCompressionLevel());
1437 fLastObjectSize=iMsgLength;
1439 HLTError("object serialization failed for object %p", pObject);
1448 int AliHLTComponent::PushBack(const TObject* pObject, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec,
1449 void* pHeader, int headerSize)
1451 // see header file for function documentation
1452 ALIHLTCOMPONENT_BASE_STOPWATCH();
1453 AliHLTComponentDataType dt;
1454 SetDataType(dt, dtID, dtOrigin);
1455 return PushBack(pObject, dt, spec, pHeader, headerSize);
1458 int AliHLTComponent::PushBack(const void* pBuffer, int iSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
1459 const void* pHeader, int headerSize)
1461 // see header file for function documentation
1462 ALIHLTCOMPONENT_BASE_STOPWATCH();
1463 if (fPushbackPeriod>0) {
1464 // suppress the output
1466 if (fLastPushBackTime<0 || (int)time.Get()-fLastPushBackTime<fPushbackPeriod) return 0;
1469 return InsertOutputBlock(pBuffer, iSize, dt, spec, pHeader, headerSize);
1472 int AliHLTComponent::PushBack(const void* pBuffer, int iSize, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec,
1473 const void* pHeader, int headerSize)
1475 // see header file for function documentation
1476 ALIHLTCOMPONENT_BASE_STOPWATCH();
1477 AliHLTComponentDataType dt;
1478 SetDataType(dt, dtID, dtOrigin);
1479 return PushBack(pBuffer, iSize, dt, spec, pHeader, headerSize);
1482 int AliHLTComponent::InsertOutputBlock(const void* pBuffer, int iBufferSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
1483 const void* pHeader, int iHeaderSize)
1485 // see header file for function documentation
1487 int iBlkSize = iBufferSize + iHeaderSize;
1489 if ((pBuffer!=NULL && iBufferSize>0) || (pHeader!=NULL && iHeaderSize>0)) {
1490 if (fpOutputBuffer && iBlkSize<=(int)(fOutputBufferSize-fOutputBufferFilled)) {
1491 AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled;
1493 // copy header if provided but skip if the header is the target location
1494 // in that case it has already been copied
1495 if (pHeader!=NULL && pHeader!=pTgt) {
1496 memcpy(pTgt, pHeader, iHeaderSize);
1499 pTgt += (AliHLTUInt8_t) iHeaderSize;
1501 // copy buffer if provided but skip if buffer is the target location
1502 // in that case it has already been copied
1503 if (pBuffer!=NULL && pBuffer!=pTgt) {
1504 memcpy(pTgt, pBuffer, iBufferSize);
1506 //AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)pBuffer);
1507 //HLTDebug("copy %d bytes from %p to output buffer %p, first word %#x", iBufferSize, pBuffer, pTgt, firstWord);
1509 //HLTDebug("buffer inserted to output: size %d data type %s spec %#x", iBlkSize, DataType2Text(dt).c_str(), spec);
1511 if (fpOutputBuffer) {
1512 HLTError("too little space in output buffer: %d of %d, required %d", fOutputBufferSize-fOutputBufferFilled, fOutputBufferSize, iBlkSize);
1514 HLTError("output buffer not available");
1520 AliHLTComponentBlockData bd;
1521 FillBlockData( bd );
1522 bd.fOffset = fOutputBufferFilled;
1523 bd.fSize = iBlkSize;
1525 bd.fSpecification = spec;
1526 fOutputBlocks.push_back( bd );
1527 fOutputBufferFilled+=bd.fSize;
1533 int AliHLTComponent::EstimateObjectSize(const TObject* pObject) const
1535 // see header file for function documentation
1536 if (!pObject) return 0;
1538 AliHLTMessage msg(kMESS_OBJECT);
1539 msg.WriteObject(pObject);
1540 return msg.Length();
1543 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(int capacity, const char* dtID,
1544 const char* dtOrigin,
1545 AliHLTUInt32_t spec)
1547 // see header file for function documentation
1548 ALIHLTCOMPONENT_BASE_STOPWATCH();
1549 AliHLTComponentDataType dt;
1550 SetDataType(dt, dtID, dtOrigin);
1551 return CreateMemoryFile(capacity, dt, spec);
1554 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(int capacity,
1555 const AliHLTComponentDataType& dt,
1556 AliHLTUInt32_t spec)
1558 // see header file for function documentation
1559 ALIHLTCOMPONENT_BASE_STOPWATCH();
1560 AliHLTMemoryFile* pFile=NULL;
1561 if (capacity>=0 && static_cast<unsigned int>(capacity)<=fOutputBufferSize-fOutputBufferFilled){
1562 AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled;
1563 pFile=new AliHLTMemoryFile((char*)pTgt, capacity);
1565 unsigned int nofBlocks=fOutputBlocks.size();
1566 if (nofBlocks+1>fMemFiles.size()) {
1567 fMemFiles.resize(nofBlocks+1, NULL);
1569 if (nofBlocks<fMemFiles.size()) {
1570 fMemFiles[nofBlocks]=pFile;
1571 AliHLTComponentBlockData bd;
1572 FillBlockData( bd );
1573 bd.fOffset = fOutputBufferFilled;
1574 bd.fSize = capacity;
1576 bd.fSpecification = spec;
1577 fOutputBufferFilled+=bd.fSize;
1578 fOutputBlocks.push_back( bd );
1580 HLTError("can not allocate/grow object array");
1581 pFile->CloseMemoryFile(0);
1587 HLTError("can not create memory file of size %d (%d available)", capacity, fOutputBufferSize-fOutputBufferFilled);
1592 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(const char* dtID,
1593 const char* dtOrigin,
1594 AliHLTUInt32_t spec,
1597 // see header file for function documentation
1598 ALIHLTCOMPONENT_BASE_STOPWATCH();
1599 AliHLTComponentDataType dt;
1600 SetDataType(dt, dtID, dtOrigin);
1601 int size=fOutputBufferSize-fOutputBufferFilled;
1602 if (capacity<0 || capacity>1.0) {
1603 HLTError("invalid parameter: capacity %f", capacity);
1606 size=(int)(size*capacity);
1607 return CreateMemoryFile(size, dt, spec);
1610 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(const AliHLTComponentDataType& dt,
1611 AliHLTUInt32_t spec,
1614 // see header file for function documentation
1615 ALIHLTCOMPONENT_BASE_STOPWATCH();
1616 int size=fOutputBufferSize-fOutputBufferFilled;
1617 if (capacity<0 || capacity>1.0) {
1618 HLTError("invalid parameter: capacity %f", capacity);
1621 size=(int)(size*capacity);
1622 return CreateMemoryFile(size, dt, spec);
1625 int AliHLTComponent::Write(AliHLTMemoryFile* pFile, const TObject* pObject,
1626 const char* key, int option)
1628 // see header file for function documentation
1630 if (pFile && pObject) {
1632 iResult=pObject->Write(key, option);
1636 iResult=-pFile->GetErrno();
1637 if (iResult==-ENOSPC) {
1638 HLTError("error writing memory file, buffer too small");
1647 int AliHLTComponent::CloseMemoryFile(AliHLTMemoryFile* pFile)
1649 // see header file for function documentation
1652 AliHLTMemoryFilePList::iterator element=fMemFiles.begin();
1654 while (element!=fMemFiles.end() && iResult>=0) {
1655 if (*element && *element==pFile) {
1656 iResult=pFile->CloseMemoryFile();
1658 // sync memory files and descriptors
1660 fOutputBlocks[i].fSize=(*element)->GetSize()+(*element)->GetHeaderSize();
1668 HLTError("can not find memory file %p", pFile);
1676 int AliHLTComponent::CreateEventDoneData(AliHLTComponentEventDoneData edd)
1678 // see header file for function documentation
1681 AliHLTComponentEventDoneData* newEDD = NULL;
1683 unsigned long newSize=edd.fDataSize;
1685 newSize += fEventDoneData->fDataSize;
1687 if (newSize>fEventDoneDataSize) {
1688 newEDD = reinterpret_cast<AliHLTComponentEventDoneData*>( new AliHLTUInt8_t[ sizeof(AliHLTComponentEventDoneData)+newSize ] );
1691 newEDD->fStructSize = sizeof(AliHLTComponentEventDoneData);
1692 newEDD->fDataSize = newSize;
1693 newEDD->fData = reinterpret_cast<AliHLTUInt8_t*>(newEDD)+newEDD->fStructSize;
1694 unsigned long long offset = 0;
1695 if (fEventDoneData) {
1696 memcpy( newEDD->fData, fEventDoneData->fData, fEventDoneData->fDataSize );
1697 offset += fEventDoneData->fDataSize;
1699 memcpy( reinterpret_cast<AliHLTUInt8_t*>(newEDD->fData)+offset, edd.fData, edd.fDataSize );
1701 delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
1702 fEventDoneData = newEDD;
1703 fEventDoneDataSize = newSize;
1705 else if (fEventDoneData) {
1706 memcpy( reinterpret_cast<AliHLTUInt8_t*>(fEventDoneData->fData)+fEventDoneData->fDataSize, edd.fData, edd.fDataSize );
1707 fEventDoneData->fDataSize += edd.fDataSize;
1710 HLTError("internal mismatch, fEventDoneData=%d but buffer is NULL", fEventDoneDataSize);
1718 // helper function for std:sort, implements an operator<
1719 bool SortComponentStatisticsById(const AliHLTComponentStatistics& a, const AliHLTComponentStatistics& b)
1724 // helper function for std:sort
1725 bool SortComponentStatisticsDescendingByLevel(const AliHLTComponentStatistics& a, const AliHLTComponentStatistics& b)
1730 // helper class to define operator== between AliHLTComponentStatistics and AliHLTComponentStatistics.fId
1731 class AliHLTComponentStatisticsId {
1733 AliHLTComponentStatisticsId(AliHLTUInt32_t id) : fId(id) {}
1734 AliHLTComponentStatisticsId(const AliHLTComponentStatisticsId& src) : fId(src.fId) {}
1735 bool operator==(const AliHLTComponentStatistics& a) const {return a.fId==fId;}
1737 AliHLTComponentStatisticsId();
1741 // operator for std::find of AliHLTComponentStatistics by id
1742 bool operator==(const AliHLTComponentStatistics& a, const AliHLTComponentStatisticsId& b)
1747 bool AliHLTComponentStatisticsCompareIds(const AliHLTComponentStatistics& a, const AliHLTComponentStatistics& b)
1749 return a.fId==b.fId;
1752 // helper class to define operator== between AliHLTComponentBlockData and AliHLTComponentBlockData.fSpecification
1753 class AliHLTComponentBlockDataSpecification {
1755 AliHLTComponentBlockDataSpecification(AliHLTUInt32_t specification) : fSpecification(specification) {}
1756 AliHLTComponentBlockDataSpecification(const AliHLTComponentBlockDataSpecification& src) : fSpecification(src.fSpecification) {}
1757 bool operator==(const AliHLTComponentBlockData& bd) const {return bd.fSpecification==fSpecification;}
1759 AliHLTComponentBlockDataSpecification();
1760 AliHLTUInt32_t fSpecification;
1763 // operator for std::find of AliHLTComponentBlockData by specification
1764 bool operator==(const AliHLTComponentBlockData& bd, const AliHLTComponentBlockDataSpecification& spec)
1769 // operator for std::find
1770 bool operator==(const AliHLTComponentBlockData& a, const AliHLTComponentBlockData& b)
1772 if (!MatchExactly(a.fDataType,b.fDataType)) return false;
1773 return a.fSpecification==b.fSpecification;
1776 } // end of namespace
1778 int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
1779 const AliHLTComponentBlockData* blocks,
1780 AliHLTComponentTriggerData& trigData,
1781 AliHLTUInt8_t* outputPtr,
1782 AliHLTUInt32_t& size,
1783 AliHLTUInt32_t& outputBlockCnt,
1784 AliHLTComponentBlockData*& outputBlocks,
1785 AliHLTComponentEventDoneData*& edd )
1787 // see header file for function documentation
1788 HLTLogKeyword(fChainId.c_str());
1789 ALIHLTCOMPONENT_BASE_STOPWATCH();
1791 fCurrentEvent=evtData.fEventID;
1792 fCurrentEventData=evtData;
1793 fpInputBlocks=blocks;
1794 fCurrentInputBlock=-1;
1795 fSearchDataType=kAliHLTAnyDataType;
1796 fpOutputBuffer=outputPtr;
1797 fOutputBufferSize=size;
1798 fOutputBufferFilled=0;
1799 fOutputBlocks.clear();
1803 AliHLTComponentBlockDataList forwardedBlocks;
1805 // optional component statistics
1806 AliHLTComponentStatisticsList compStats;
1807 bool bAddComponentTableEntry=false;
1808 vector<AliHLTUInt32_t> parentComponentTables;
1809 int processingLevel=-1;
1810 #if defined(HLT_COMPONENT_STATISTICS)
1811 if ((fFlags&kDisableComponentStat)==0) {
1812 AliHLTComponentStatistics outputStat;
1813 memset(&outputStat, 0, sizeof(AliHLTComponentStatistics));
1814 outputStat.fStructSize=sizeof(AliHLTComponentStatistics);
1815 outputStat.fId=fChainIdCrc;
1817 fpBenchmark->Stop();
1818 outputStat.fComponentCycleTime=(AliHLTUInt32_t)(fpBenchmark->RealTime()*ALIHLTCOMPONENT_STATTIME_SCALER);
1819 fpBenchmark->Reset();
1820 fpBenchmark->Start();
1822 compStats.push_back(outputStat);
1824 #endif // HLT_COMPONENT_STATISTICS
1826 // data processing is skipped
1827 // - if there are only steering events in the block list.
1828 // For the sake of data source components data processing
1829 // is not skipped if there is no block list at all or if it
1830 // just contains the eventType block
1831 // - always skipped if the event is of type
1832 // - gkAliEventTypeConfiguration
1833 // - gkAliEventTypeReadPreprocessor
1834 const unsigned int skipModeDefault=0x1;
1835 const unsigned int skipModeForce=0x2;
1836 unsigned int bSkipDataProcessing=skipModeDefault;
1838 // find special events
1839 if (fpInputBlocks && evtData.fBlockCnt>0) {
1840 // first look for all special events and execute in the appropriate
1841 // sequence afterwords
1842 int indexComConfEvent=-1;
1843 int indexUpdtDCSEvent=-1;
1844 int indexSOREvent=-1;
1845 int indexEOREvent=-1;
1846 int indexECSParamBlock=-1;
1847 for (unsigned int i=0; i<evtData.fBlockCnt && iResult>=0; i++) {
1848 if (fpInputBlocks[i].fDataType==kAliHLTDataTypeSOR) {
1850 // the AliHLTCalibrationProcessor relies on the SOR and EOR events
1851 bSkipDataProcessing&=~skipModeDefault;
1852 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeRunType) {
1854 // handling is not clear yet
1855 if (fpInputBlocks[i].fPtr) {
1856 HLTDebug("got run type \"%s\"\n", fpInputBlocks[i].fPtr);
1858 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeEOR) {
1860 // the calibration processor relies on the SOR and EOR events
1861 bSkipDataProcessing&=~skipModeDefault;
1862 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeDDL) {
1864 // this event is most likely deprecated
1865 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComConf) {
1866 indexComConfEvent=i;
1867 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeUpdtDCS) {
1868 indexUpdtDCSEvent=i;
1869 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeEvent) {
1870 fEventType=fpInputBlocks[i].fSpecification;
1871 if (fEventType != gkAliEventTypeConfiguration and
1872 fEventType != gkAliEventTypeReadPreprocessor
1875 // We can actually get the event type from the CDH if it is valid.
1876 // Otherwise just use the specification of the input block.
1877 const AliRawDataHeader* cdh;
1878 if (ExtractTriggerData(trigData, NULL, NULL, &cdh, NULL) == 0)
1880 fEventType = ExtractEventTypeFromCDH(cdh);
1884 // skip always in case of gkAliEventTypeConfiguration
1885 if (fpInputBlocks[i].fSpecification==gkAliEventTypeConfiguration) bSkipDataProcessing|=skipModeForce;
1887 // skip always in case of gkAliEventTypeReadPreprocessor
1888 if (fpInputBlocks[i].fSpecification==gkAliEventTypeReadPreprocessor) bSkipDataProcessing|=skipModeForce;
1890 // never skip if the event type block is the only block
1891 if (evtData.fBlockCnt==1) bSkipDataProcessing&=~skipModeDefault;
1893 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComponentStatistics) {
1894 if (compStats.size()>0) {
1895 AliHLTUInt8_t* pData=reinterpret_cast<AliHLTUInt8_t*>(fpInputBlocks[i].fPtr);
1896 for (AliHLTUInt32_t offset=0;
1897 offset+sizeof(AliHLTComponentStatistics)<=fpInputBlocks[i].fSize;
1898 offset+=sizeof(AliHLTComponentStatistics)) {
1899 AliHLTComponentStatistics* pStat=reinterpret_cast<AliHLTComponentStatistics*>(pData+offset);
1900 if (pStat && compStats[0].fLevel<=pStat->fLevel) {
1901 compStats[0].fLevel=pStat->fLevel+1;
1903 if (find(compStats.begin(), compStats.end(), AliHLTComponentStatisticsId(pStat->fId))==compStats.end()) {
1904 compStats.push_back(*pStat);
1908 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComponentTable) {
1909 AliHLTComponentBlockDataList::iterator element=forwardedBlocks.begin();
1910 while ((element=find(element, forwardedBlocks.end(), AliHLTComponentBlockDataSpecification(fpInputBlocks[i].fSpecification)))!=forwardedBlocks.end()) {
1911 if (element->fDataType==fpInputBlocks[i].fDataType) break;
1912 // TODO: think about some more checks inclusing also the actual data buffers
1913 // this has to handle multiplicity>1 in the online system, where all components
1914 // send the information on SOR, because this event is broadcasted
1916 if (element==forwardedBlocks.end()) {
1917 forwardedBlocks.push_back(fpInputBlocks[i]);
1919 parentComponentTables.push_back(fpInputBlocks[i].fSpecification);
1920 if (fpInputBlocks[i].fSize>=sizeof(AliHLTComponentTableEntry)) {
1921 const AliHLTComponentTableEntry* entry=reinterpret_cast<AliHLTComponentTableEntry*>(fpInputBlocks[i].fPtr);
1922 if (entry->fStructSize==sizeof(AliHLTComponentTableEntry)) {
1923 if (processingLevel<0 || processingLevel<=(int)entry->fLevel)
1924 processingLevel=entry->fLevel+1;
1927 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeECSParam) {
1928 indexECSParamBlock=i;
1930 // the processing function is called if there is at least one
1931 // non-steering data block. Steering blocks are not filtered out
1932 // for sake of performance
1933 bSkipDataProcessing&=~skipModeDefault;
1934 if (compStats.size()>0) {
1935 compStats[0].fInputBlockCount++;
1936 compStats[0].fTotalInputSize+=fpInputBlocks[i].fSize;
1941 if (indexSOREvent>=0) {
1943 bAddComponentTableEntry=true;
1944 compStats.clear(); // no component statistics for SOR
1945 if (fpRunDesc==NULL) {
1946 fpRunDesc=new AliHLTRunDesc;
1947 if (fpRunDesc) *fpRunDesc=kAliHLTVoidRunDesc;
1950 AliHLTRunDesc rundesc;
1951 if ((iResult=CopyStruct(&rundesc, sizeof(AliHLTRunDesc), indexSOREvent, "AliHLTRunDesc", "SOR"))>0) {
1952 if (fpRunDesc->fRunNo==kAliHLTVoidRunNo) {
1954 HLTDebug("set run decriptor, run no %d", fpRunDesc->fRunNo);
1955 SetCDBRunNo(fpRunDesc->fRunNo);
1956 } else if (fpRunDesc->fRunNo!=rundesc.fRunNo) {
1957 HLTWarning("already set run properties run no %d, ignoring SOR with run no %d", fpRunDesc->fRunNo, rundesc.fRunNo);
1964 if (indexECSParamBlock>=0) {
1965 if (fpInputBlocks[indexECSParamBlock].fSize>0) {
1966 const char* param=reinterpret_cast<const char*>(fpInputBlocks[indexECSParamBlock].fPtr);
1967 TString paramString;
1968 if (param[fpInputBlocks[indexECSParamBlock].fSize-1]!=0) {
1969 HLTWarning("ECS parameter string not terminated");
1970 paramString.Insert(0, param, fpInputBlocks[indexECSParamBlock].fSize);
1975 ScanECSParam(paramString.Data());
1977 HLTWarning("empty ECS parameter received");
1980 // TODO: later on we might throw a warning here since the CTP trigger classes
1981 // should be mandatory
1984 if (indexEOREvent>=0) {
1985 fLastPushBackTime=0; // always send at EOR
1986 bAddComponentTableEntry=true;
1987 compStats.clear(); // no component statistics for EOR
1988 if (fpRunDesc!=NULL) {
1990 AliHLTRunDesc rundesc;
1991 if ((iResult=CopyStruct(&rundesc, sizeof(AliHLTRunDesc), indexEOREvent, "AliHLTRunDesc", "SOR"))>0) {
1992 if (fpRunDesc->fRunNo!=rundesc.fRunNo) {
1993 HLTWarning("run no mismatch: SOR %d, EOR %d", fpRunDesc->fRunNo, rundesc.fRunNo);
1995 HLTDebug("EOR run no %d", fpRunDesc->fRunNo);
1998 // we do not unload the fpRunDesc struct here in order to have the run information
1999 // available during the event processing
2000 // https://savannah.cern.ch/bugs/?39711
2001 // the info will be cleared in DeInit
2004 HLTWarning("did not receive SOR, ignoring EOR");
2007 if (indexComConfEvent>=0 || fEventType==gkAliEventTypeConfiguration) {
2009 if (indexComConfEvent>=0 && fpInputBlocks[indexComConfEvent].fPtr!=NULL && fpInputBlocks[indexComConfEvent].fSize>0) {
2010 cdbEntry.Append(reinterpret_cast<const char*>(fpInputBlocks[indexComConfEvent].fPtr), fpInputBlocks[indexComConfEvent].fSize);
2012 HLTDebug("received component configuration command: entry %s", cdbEntry.IsNull()?"none":cdbEntry.Data());
2013 int tmpResult=Reconfigure(cdbEntry[0]==0?NULL:cdbEntry.Data(), fChainId.c_str());
2015 HLTWarning("reconfiguration of component %p (%s) failed with error code %d", this, GetComponentID(), tmpResult);
2018 if (indexUpdtDCSEvent>=0 || fEventType==gkAliEventTypeReadPreprocessor) {
2020 if (fpInputBlocks[indexUpdtDCSEvent].fPtr!=NULL && fpInputBlocks[indexUpdtDCSEvent].fSize>0) {
2021 modules.Append(reinterpret_cast<const char*>(fpInputBlocks[indexUpdtDCSEvent].fPtr), fpInputBlocks[indexUpdtDCSEvent].fSize);
2023 HLTDebug("received preprocessor update command: detectors %s", modules.IsNull()?"ALL":modules.Data());
2024 int tmpResult=ReadPreprocessorValues(modules[0]==0?"ALL":modules.Data());
2026 HLTWarning("preprocessor update of component %p (%s) failed with error code %d", this, GetComponentID(), tmpResult);
2030 // processing function needs to be called if there are no input data
2031 // blocks in order to make data source components working.
2032 bSkipDataProcessing&=~skipModeDefault;
2035 // data processing is not skipped if the component explicitly asks
2036 // for the private blocks
2037 if ((fFlags&kRequireSteeringBlocks)!=0) bSkipDataProcessing=0;
2039 // data processing is not skipped for data sources
2040 if (GetComponentType()==AliHLTComponent::kSource) bSkipDataProcessing=0;
2043 // set the active triggers for this event
2044 fpCTPData->SetTriggers(trigData);
2045 // increment CTP trigger counters if available
2046 if (IsDataEvent()) fpCTPData->Increment(trigData);
2049 AliHLTComponentBlockDataList blockData;
2050 if (iResult>=0 && !bSkipDataProcessing)
2051 { // dont delete, sets the scope for the stopwatch guard
2052 // do not use ALIHLTCOMPONENT_DA_STOPWATCH(); macro
2053 // in order to avoid 'shadowed variable' warning
2054 AliHLTStopwatchGuard swguard2(fpStopwatches!=NULL?reinterpret_cast<TStopwatch*>(fpStopwatches->At((int)kSWDA)):NULL);
2055 iResult=DoProcessing(evtData, blocks, trigData, outputPtr, size, blockData, edd);
2056 } // end of the scope of the stopwatch guard
2057 if (iResult>=0 && !bSkipDataProcessing) {
2058 if (fOutputBlocks.size()>0) {
2059 // High Level interface
2061 //HLTDebug("got %d block(s) via high level interface", fOutputBlocks.size());
2062 // sync memory files and descriptors
2063 AliHLTMemoryFilePList::iterator element=fMemFiles.begin();
2065 while (element!=fMemFiles.end() && iResult>=0) {
2067 if ((*element)->IsClosed()==0) {
2068 HLTWarning("memory file has not been closed, force flush");
2069 iResult=CloseMemoryFile(*element);
2076 // create the descriptor list
2077 if (blockData.size()>0) {
2078 HLTError("low level and high interface must not be mixed; use PushBack methods to insert data blocks");
2081 if (compStats.size()>0 && IsDataEvent()) {
2082 int offset=AddComponentStatistics(fOutputBlocks, fpOutputBuffer, fOutputBufferSize, fOutputBufferFilled, compStats);
2083 if (offset>0) fOutputBufferFilled+=offset;
2085 if (bAddComponentTableEntry) {
2086 int offset=AddComponentTableEntry(fOutputBlocks, fpOutputBuffer, fOutputBufferSize, fOutputBufferFilled, parentComponentTables, processingLevel);
2087 if (offset>0) size+=offset;
2089 if (forwardedBlocks.size()>0) {
2090 fOutputBlocks.insert(fOutputBlocks.end(), forwardedBlocks.begin(), forwardedBlocks.end());
2092 iResult=MakeOutputDataBlockList(fOutputBlocks, &outputBlockCnt, &outputBlocks);
2093 size=fOutputBufferFilled;
2097 // Low Level interface
2098 if (blockData.empty() && size!=0) {
2099 // set the size to zero because there is no announced data
2100 //HLTWarning("no output blocks added by component but output buffer filled %d of %d", size, fOutputBufferSize);
2104 if (compStats.size()>0) {
2105 int offset=AddComponentStatistics(blockData, fpOutputBuffer, fOutputBufferSize, size, compStats);
2106 if (offset>0) size+=offset;
2108 if (bAddComponentTableEntry) {
2109 int offset=AddComponentTableEntry(blockData, fpOutputBuffer, fOutputBufferSize, size, parentComponentTables, processingLevel);
2110 if (offset>0) size+=offset;
2112 if (forwardedBlocks.size()>0) {
2113 blockData.insert(blockData.end(), forwardedBlocks.begin(), forwardedBlocks.end());
2115 iResult=MakeOutputDataBlockList(blockData, &outputBlockCnt, &outputBlocks);
2118 HLTFatal("component %s (%p): can not convert output block descriptor list", GetComponentID(), this);
2121 if (iResult<0 || bSkipDataProcessing) {
2125 CleanupInputObjects();
2126 if (iResult>=0 && IsDataEvent()) {
2127 IncrementEventCounter();
2129 if (outputBlockCnt==0) {
2130 // no output blocks, set size to 0
2134 // reset the internal EventData struct
2135 FillEventData(fCurrentEventData);
2137 // reset the active triggers
2138 if (fpCTPData) fpCTPData->SetTriggers(0);
2140 // set the time for the pushback period
2141 if (fPushbackPeriod>0) {
2142 // suppress the output
2144 if (fLastPushBackTime<0) {
2145 // choose a random offset at beginning to equalize traffic for multiple instances
2147 gRandom->SetSeed(fChainIdCrc);
2148 fLastPushBackTime=time.Get();
2149 fLastPushBackTime-=gRandom->Integer(fPushbackPeriod);
2150 } else if ((int)time.Get()-fLastPushBackTime>=fPushbackPeriod) {
2151 fLastPushBackTime=time.Get();
2158 int AliHLTComponent::AddComponentStatistics(AliHLTComponentBlockDataList& blocks,
2159 AliHLTUInt8_t* buffer,
2160 AliHLTUInt32_t bufferSize,
2161 AliHLTUInt32_t offset,
2162 AliHLTComponentStatisticsList& stats) const
2164 // see header file for function documentation
2166 if ((fFlags&kDisableComponentStat)!=0) return 0;
2167 #if defined(HLT_COMPONENT_STATISTICS)
2168 if (stats.size()==0) return -ENOENT;
2169 // check if there is space for at least one entry
2170 if (offset+sizeof(AliHLTComponentStatistics)>bufferSize) return 0;
2171 stats[0].fTotalOutputSize=offset;
2172 stats[0].fOutputBlockCount=blocks.size();
2174 fpBenchmark->Stop();
2175 stats[0].fTime=(AliHLTUInt32_t)(fpBenchmark->RealTime()*ALIHLTCOMPONENT_STATTIME_SCALER);
2176 stats[0].fCTime=(AliHLTUInt32_t)(fpBenchmark->CpuTime()*ALIHLTCOMPONENT_STATTIME_SCALER);
2177 fpBenchmark->Continue();
2180 sort(stats.begin(), stats.end(), SortComponentStatisticsDescendingByLevel);
2182 // shrink the number of entries if the buffer is too small
2183 if (offset+stats.size()*sizeof(AliHLTComponentStatistics)>bufferSize) {
2184 unsigned originalSize=stats.size();
2185 AliHLTUInt32_t removedLevel=0;
2187 // remove all entries of the level of the last entry
2188 removedLevel=stats.back().fLevel;
2189 AliHLTComponentStatisticsList::iterator element=stats.begin();
2191 while (element!=stats.end()) {
2192 if (element->fLevel<=removedLevel) {
2193 element=stats.erase(element);
2198 } while (stats.size()>1 &&
2199 (offset+stats.size()*sizeof(AliHLTComponentStatistics)>bufferSize));
2200 HLTWarning("too little space in output buffer to add block of %d statistics entries (size %d), available %d, removed %d entries",
2201 originalSize, sizeof(AliHLTComponentStatistics), bufferSize-offset, originalSize-stats.size());
2203 HLTDebug("adding block of %d statistics entries", stats.size());
2205 assert(stats.size()>0);
2206 if (stats.size()==0) return 0;
2208 if (offset+stats.size()*sizeof(AliHLTComponentStatistics)<=bufferSize) {
2209 AliHLTComponentBlockData bd;
2210 FillBlockData( bd );
2211 bd.fOffset = offset;
2212 bd.fSize = stats.size()*sizeof(AliHLTComponentStatistics);
2213 bd.fDataType = kAliHLTDataTypeComponentStatistics;
2214 bd.fSpecification = fChainIdCrc;
2215 memcpy(buffer+offset, &(stats[0]), bd.fSize);
2216 blocks.push_back(bd);
2220 if (blocks.size() && buffer && bufferSize && offset && stats.size()) {
2221 // get rid of warning
2223 #endif // HLT_COMPONENT_STATISTICS
2227 int AliHLTComponent::AddComponentTableEntry(AliHLTComponentBlockDataList& blocks,
2228 AliHLTUInt8_t* buffer,
2229 AliHLTUInt32_t bufferSize,
2230 AliHLTUInt32_t offset,
2231 const vector<AliHLTUInt32_t>& parents,
2232 int processingLevel) const
2234 // see header file for function documentation
2236 if ((fFlags&kDisableComponentStat)!=0) return 0;
2237 #if defined(HLT_COMPONENT_STATISTICS)
2238 // the payload consists of the AliHLTComponentTableEntry struct,
2239 // followed by a an array of 32bit crc chain ids and the component
2240 // description string
2241 unsigned int payloadSize=sizeof(AliHLTComponentTableEntry);
2242 payloadSize+=parents.size()*sizeof(AliHLTUInt32_t);
2244 // the component description has the following format:
2245 // chain-id{component-id:arguments}
2246 const char* componentId=const_cast<AliHLTComponent*>(this)->GetComponentID();
2247 unsigned int descriptionSize=fChainId.size()+1;
2248 descriptionSize+=2; // the '{}' around the component id
2249 descriptionSize+=strlen(componentId);
2250 descriptionSize+=1; // the ':' between component id and arguments
2251 descriptionSize+=fComponentArgs.size();
2253 payloadSize+=descriptionSize;
2254 if (buffer && (offset+payloadSize<=bufferSize)) {
2255 AliHLTUInt8_t* pTgt=buffer+offset;
2256 memset(pTgt, 0, payloadSize);
2259 AliHLTComponentTableEntry* pEntry=reinterpret_cast<AliHLTComponentTableEntry*>(pTgt);
2260 pEntry->fStructSize=sizeof(AliHLTComponentTableEntry);
2261 pEntry->fLevel=processingLevel>=0?processingLevel:0;
2262 pEntry->fNofParents=parents.size();
2263 pEntry->fSizeDescription=descriptionSize;
2264 pTgt=pEntry->fBuffer;
2266 // write array of parents
2267 if (parents.size()>0) {
2268 unsigned int copy=parents.size()*sizeof(vector<AliHLTUInt32_t>::value_type);
2269 memcpy(pTgt, &parents[0], parents.size()*sizeof(vector<AliHLTUInt32_t>::value_type));
2273 // write component description
2274 memcpy(pTgt, fChainId.c_str(), fChainId.size());
2275 pTgt+=fChainId.size();
2277 memcpy(pTgt, componentId, strlen(componentId));
2278 pTgt+=strlen(componentId);
2280 memcpy(pTgt, fComponentArgs.c_str(), fComponentArgs.size());
2281 pTgt+=fComponentArgs.size();
2285 AliHLTComponentBlockData bd;
2286 FillBlockData( bd );
2287 bd.fOffset = offset;
2288 bd.fSize = payloadSize;
2289 bd.fDataType = kAliHLTDataTypeComponentTable;
2290 bd.fSpecification = fChainIdCrc;
2291 blocks.push_back(bd);
2295 if (blocks.size() && buffer && bufferSize && offset && parents.size() && processingLevel) {
2296 // get rid of warning
2298 #endif // HLT_COMPONENT_STATISTICS
2302 AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard()
2307 // standard constructor (not for use)
2310 AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(TStopwatch* pStopwatch)
2312 fpStopwatch(pStopwatch),
2317 // check for already existing guard
2318 if (fgpCurrent) fpPrec=fgpCurrent;
2321 // stop the preceeding guard if it controls a different stopwatch
2323 if (fpPrec && fpPrec!=this) bStart=fpPrec->Hold(fpStopwatch);
2325 // start the stopwatch if the current guard controls a different one
2326 if (fpStopwatch && bStart==1) fpStopwatch->Start(kFALSE);
2329 AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(const AliHLTStopwatchGuard&)
2335 // copy constructor not for use
2339 AliHLTComponent::AliHLTStopwatchGuard& AliHLTComponent::AliHLTStopwatchGuard::operator=(const AliHLTStopwatchGuard&)
2342 // assignment operator not for use
2349 AliHLTComponent::AliHLTStopwatchGuard* AliHLTComponent::AliHLTStopwatchGuard::fgpCurrent=NULL;
2351 AliHLTComponent::AliHLTStopwatchGuard::~AliHLTStopwatchGuard()
2355 // resume the preceeding guard if it controls a different stopwatch
2357 if (fpPrec && fpPrec!=this) bStop=fpPrec->Resume(fpStopwatch);
2359 // stop the stopwatch if the current guard controls a different one
2360 if (fpStopwatch && bStop==1) fpStopwatch->Stop();
2362 // resume to the preceeding guard
2366 int AliHLTComponent::AliHLTStopwatchGuard::Hold(const TStopwatch* pSucc)
2368 // see header file for function documentation
2369 if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Stop();
2370 return fpStopwatch!=pSucc?1:0;
2373 int AliHLTComponent::AliHLTStopwatchGuard::Resume(const TStopwatch* pSucc)
2375 // see header file for function documentation
2376 if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Start(kFALSE);
2377 return fpStopwatch!=pSucc?1:0;
2380 int AliHLTComponent::SetStopwatch(TObject* pSW, AliHLTStopwatchType type)
2382 // see header file for function documentation
2384 if (pSW!=NULL && type<kSWTypeCount) {
2385 if (fpStopwatches) {
2386 TObject* pObj=fpStopwatches->At((int)type);
2387 if (pSW==NULL // explicit reset
2388 || pObj==NULL) { // explicit set
2389 fpStopwatches->AddAt(pSW, (int)type);
2390 } else if (pObj!=pSW) {
2391 HLTWarning("stopwatch %d already set, reset first", (int)type);
2401 int AliHLTComponent::SetStopwatches(TObjArray* pStopwatches)
2403 // see header file for function documentation
2404 if (pStopwatches==NULL) return -EINVAL;
2407 for (int i=0 ; i<(int)kSWTypeCount && pStopwatches->GetEntriesFast(); i++)
2408 SetStopwatch(pStopwatches->At(i), (AliHLTStopwatchType)i);
2412 AliHLTUInt32_t AliHLTComponent::GetRunNo() const
2414 // see header file for function documentation
2416 // 2010-02-11 OCDB is now the reliable source for the run number, it is
2417 // initialized either by aliroot or the external interface depending
2418 // on the environment. It turned out that the rundescriptor is not set
2419 // in the aliroot mode, resulting in an invalid run number. However this
2420 // did not cause problems until now. OCDB initialization has been revised
2421 // already in 10/2009. This was a remnant.
2422 // Have to check whether we get rid of the rundescriptor at some point.
2423 if (fpRunDesc==NULL) return AliHLTMisc::Instance().GetCDBRunNo();
2424 if (fpRunDesc->fRunNo!=(unsigned)AliHLTMisc::Instance().GetCDBRunNo()) {
2425 HLTWarning("run number mismatch: ocdb %d run descriptor %d", AliHLTMisc::Instance().GetCDBRunNo(), fpRunDesc->fRunNo);
2427 return fpRunDesc->fRunNo;
2430 AliHLTUInt32_t AliHLTComponent::GetRunType() const
2432 // see header file for function documentation
2433 if (fpRunDesc==NULL) return kAliHLTVoidRunType;
2434 return fpRunDesc->fRunType;
2437 AliHLTUInt32_t AliHLTComponent::GetTimeStamp() const
2439 // see header file for function documentation
2440 if (fCurrentEventData.fEventCreation_s) {
2441 return fCurrentEventData.fEventCreation_s;
2443 // using the actual UTC if the time stamp was not set by the framework
2444 return static_cast<AliHLTUInt32_t>(time(NULL));
2447 AliHLTUInt32_t AliHLTComponent::GetPeriodNumber() const
2449 // see header file for function documentation
2450 return (GetEventId()>>36)&0xfffffff;
2453 AliHLTUInt32_t AliHLTComponent::GetOrbitNumber() const
2455 // see header file for function documentation
2456 return (GetEventId()>>12)&0xffffff;
2459 AliHLTUInt16_t AliHLTComponent::GetBunchCrossNumber() const
2461 // see header file for function documentation
2462 return GetEventId()&0xfff;
2465 bool AliHLTComponent::IsDataEvent(AliHLTUInt32_t* pTgt) const
2467 // see header file for function documentation
2468 if (pTgt) *pTgt=fEventType;
2469 return (fEventType==gkAliEventTypeData ||
2470 fEventType==gkAliEventTypeDataReplay);
2473 int AliHLTComponent::CopyStruct(void* pStruct, unsigned int iStructSize, unsigned int iBlockNo,
2474 const char* structname, const char* eventname)
2476 // see header file for function documentation
2478 if (pStruct!=NULL && iStructSize>sizeof(AliHLTUInt32_t)) {
2479 if (fpInputBlocks!=NULL && iBlockNo<fCurrentEventData.fBlockCnt) {
2480 AliHLTUInt32_t* pTgt=(AliHLTUInt32_t*)pStruct;
2481 if (fpInputBlocks[iBlockNo].fPtr && fpInputBlocks[iBlockNo].fSize) {
2482 AliHLTUInt32_t copy=*((AliHLTUInt32_t*)fpInputBlocks[iBlockNo].fPtr);
2483 if (fpInputBlocks[iBlockNo].fSize!=copy) {
2484 HLTWarning("%s event: mismatch of block size (%d) and structure size (%d)", eventname, fpInputBlocks[iBlockNo].fSize, copy);
2485 if (copy>fpInputBlocks[iBlockNo].fSize) copy=fpInputBlocks[iBlockNo].fSize;
2487 if (copy!=iStructSize) {
2488 HLTWarning("%s event: mismatch in %s version (data type version %d)", eventname, structname, ALIHLT_DATA_TYPES_VERSION);
2489 if (copy>iStructSize) {
2492 memset(pTgt, 0, iStructSize);
2495 memcpy(pTgt, fpInputBlocks[iBlockNo].fPtr, copy);
2499 HLTWarning("%s event: missing data block", eventname);
2505 HLTError("invalid struct");
2511 AliHLTUInt32_t AliHLTComponent::CalculateChecksum(const AliHLTUInt8_t* buffer, int size)
2513 // see header file for function documentation
2514 AliHLTUInt32_t remainder = 0;
2515 const AliHLTUInt8_t crcwidth=(8*sizeof(AliHLTUInt32_t));
2516 const AliHLTUInt32_t topbit=1 << (crcwidth-1);
2517 const AliHLTUInt32_t polynomial=0xD8; /* 11011 followed by 0's */
2520 // http://www.netrino.com/Embedded-Systems/How-To/CRC-Calculation-C-Code
2523 * Perform modulo-2 division, a byte at a time.
2525 for (int byte = 0; byte < size; ++byte)
2528 * Bring the next byte into the remainder.
2530 remainder ^= (buffer[byte] << (crcwidth - 8));
2533 * Perform modulo-2 division, a bit at a time.
2535 for (uint8_t bit = 8; bit > 0; --bit)
2538 * Try to divide the current data bit.
2540 if (remainder & topbit)
2542 remainder = (remainder << 1) ^ polynomial;
2546 remainder = (remainder << 1);
2552 * The final remainder is the CRC result.
2557 int AliHLTComponent::ExtractComponentTableEntry(const AliHLTUInt8_t* pBuffer, AliHLTUInt32_t size,
2558 string& retChainId, string& retCompId, string& retCompArgs,
2559 vector<AliHLTUInt32_t>& parents, int& level)
2561 // see header file for function documentation
2564 retCompArgs.clear();
2567 if (!pBuffer || size==0) return 0;
2569 const AliHLTComponentTableEntry* pEntry=reinterpret_cast<const AliHLTComponentTableEntry*>(pBuffer);
2570 if (size<8/* the initial size of the structure*/ ||
2571 pEntry==NULL || pEntry->fStructSize<8) return -ENOMSG;
2573 if (pEntry->fStructSize!=sizeof(AliHLTComponentTableEntry)) return -EBADF;
2574 level=pEntry->fLevel;
2575 const AliHLTUInt32_t* pParents=reinterpret_cast<const AliHLTUInt32_t*>(pEntry->fBuffer);
2576 const AliHLTUInt8_t* pEnd=pBuffer+size;
2578 if (pParents+pEntry->fNofParents>=reinterpret_cast<const AliHLTUInt32_t*>(pEnd)) return -ENODEV;
2579 for (unsigned int i=0; i<pEntry->fNofParents; i++, pParents++) {
2580 parents.push_back(*pParents);
2583 const char* pDescription=reinterpret_cast<const char*>(pParents);
2584 if (pDescription+pEntry->fSizeDescription>=reinterpret_cast<const char*>(pEnd) ||
2585 *(pDescription+pEntry->fSizeDescription)!=0) {
2589 TString descriptor=reinterpret_cast<const char*>(pDescription);
2593 TObjArray* pTokens=descriptor.Tokenize("{");
2596 if (pTokens->GetEntriesFast()>n) {
2597 retChainId=pTokens->At(n++)->GetName();
2599 if (pTokens->GetEntriesFast()>n) {
2600 compId=pTokens->At(n++)->GetName();
2604 if (!compId.IsNull() && (pTokens=compId.Tokenize(":"))!=NULL) {
2606 if (pTokens->GetEntriesFast()>n) {
2607 compId=pTokens->At(n++)->GetName();
2609 if (pTokens->GetEntriesFast()>n) {
2610 compArgs=pTokens->At(n++)->GetName();
2614 compId.ReplaceAll("}", "");
2615 compArgs.ReplaceAll("}", "");
2618 retCompArgs=compArgs;
2620 if (retChainId.size()==0) return -ENODATA;
2625 int AliHLTComponent::ExtractTriggerData(
2626 const AliHLTComponentTriggerData& trigData,
2627 const AliHLTUInt8_t (**attributes)[gkAliHLTBlockDAttributeCount],
2628 AliHLTUInt64_t* status,
2629 const AliRawDataHeader** cdh,
2630 AliHLTReadoutList* readoutlist,
2634 // see header file for function documentation
2636 // Check that the trigger data structure is the correct size.
2637 if (trigData.fStructSize != sizeof(AliHLTComponentTriggerData))
2642 log.LoggingVarargs(kHLTLogError, Class_Name(), FUNCTIONNAME(), __FILE__, __LINE__,
2643 "Invalid trigger structure size: %d but expected %d.", trigData.fStructSize, sizeof(AliHLTComponentTriggerData)
2649 // Get the size of the AliHLTEventTriggerData structure without the readout list part.
2650 // The way we do this here should also handle memory alignment correctly.
2651 AliHLTEventTriggerData* dummy = NULL;
2652 size_t sizeWithoutReadout = (char*)(&dummy->fReadoutList) - (char*)(dummy);
2654 // Check that the trigger data pointer points to data of a size we can handle.
2655 // Either it is the size of AliHLTEventTriggerData or the size of the old
2656 // version of AliHLTEventTriggerData using AliHLTEventDDLV0.
2657 if (trigData.fDataSize != sizeof(AliHLTEventTriggerData) and
2658 trigData.fDataSize != sizeWithoutReadout + sizeof(AliHLTEventDDLV0)
2664 log.LoggingVarargs(kHLTLogError, Class_Name(), FUNCTIONNAME(), __FILE__, __LINE__,
2665 "Invalid trigger data size: %d but expected %d.", trigData.fDataSize, sizeof(AliHLTEventTriggerData)
2671 AliHLTEventTriggerData* evtData = reinterpret_cast<AliHLTEventTriggerData*>(trigData.fData);
2672 assert(evtData != NULL);
2674 // Check that the CDH has 8 words.
2675 if (cdh != NULL and evtData->fCommonHeaderWordCnt != 8)
2680 log.LoggingVarargs(kHLTLogError, Class_Name(), FUNCTIONNAME(), __FILE__, __LINE__,
2681 "Common Data Header (CDH) has wrong number of data words: %d but expected %d",
2682 evtData->fCommonHeaderWordCnt, sizeof(AliRawDataHeader)/sizeof(AliHLTUInt32_t)
2688 // Check that the readout list has the correct count of words. i.e. something we can handle,
2689 if (readoutlist != NULL and
2690 evtData->fReadoutList.fCount != (unsigned)gkAliHLTDDLListSizeV0 and
2691 evtData->fReadoutList.fCount != (unsigned)gkAliHLTDDLListSizeV1
2697 log.LoggingVarargs(kHLTLogError, Class_Name(), FUNCTIONNAME(), __FILE__, __LINE__,
2698 "Readout list structure has wrong number of data words: %d but expected %d",
2699 evtData->fReadoutList.fCount, gkAliHLTDDLListSize
2705 if (attributes != NULL)
2707 *attributes = &evtData->fAttributes;
2711 *status = evtData->fHLTStatus;
2715 const AliRawDataHeader* cdhptr = reinterpret_cast<const AliRawDataHeader*>(&evtData->fCommonHeader[0]);
2718 if (readoutlist != NULL)
2720 *readoutlist = AliHLTReadoutList(evtData->fReadoutList);
2725 AliHLTUInt32_t AliHLTComponent::ExtractEventTypeFromCDH(const AliRawDataHeader* cdh)
2727 // see header file for function documentation
2729 UChar_t l1msg = cdh->GetL1TriggerMessage();
2730 if ((l1msg & 0x1) == 0x0) return gkAliEventTypeData;
2731 // The L2SwC bit must be one if we got here, i.e. l1msg & 0x1 == 0x1.
2732 if (((l1msg >> 2) & 0xF) == 0xE) return gkAliEventTypeStartOfRun;
2733 if (((l1msg >> 2) & 0xF) == 0xF) return gkAliEventTypeEndOfRun;
2734 // Check the C1T bit to see if this is a calibration event,
2735 // if not then it must be some other software trigger event.
2736 if (((l1msg >> 6) & 0x1) == 0x1) return gkAliEventTypeCalibration;
2737 return gkAliEventTypeSoftware;
2740 int AliHLTComponent::LoggingVarargs(AliHLTComponentLogSeverity severity,
2741 const char* originClass, const char* originFunc,
2742 const char* file, int line, ... ) const
2744 // see header file for function documentation
2748 va_start(args, line);
2750 // logging function needs to be const in order to be called from const member functions
2751 // without problems. But at this point we face the problem with virtual members which
2752 // are not necessarily const.
2753 AliHLTComponent* nonconst=const_cast<AliHLTComponent*>(this);
2754 AliHLTLogging::SetLogString(this, ", %p", "%s (%s_pfmt_): ",
2755 fChainId[0]!=0?fChainId.c_str():nonconst->GetComponentID(),
2756 nonconst->GetComponentID());
2757 iResult=SendMessage(severity, originClass, originFunc, file, line, AliHLTLogging::BuildLogString(NULL, args, true /*append*/));
2763 TUUID AliHLTComponent::GenerateGUID()
2765 // Generates a globally unique identifier.
2767 // Start by creating a new UUID. We cannot use the one automatically generated
2768 // by ROOT because the algorithm used will not guarantee unique IDs when generating
2769 // these UUIDs at a high rate in parallel.
2771 // We then use the generated UUID to form part of the random number seeds which
2772 // will be used to generate a proper random UUID. For good measure we use a MD5
2773 // hash also. Note that we want to use the TUUID class because it will combine the
2774 // host address information into the UUID. Using gSystem->GetHostByName() apparently
2775 // can cause problems on Windows machines with a firewall, because it always tries
2776 // to contact a DNS. The TUUID class handles this case appropriately.
2785 md5.Update(buf, sizeof(buf));
2788 dword[0] += gSystem->GetUid();
2789 dword[1] += gSystem->GetGid();
2790 dword[2] += gSystem->GetPid();
2791 for (int i = 0; i < 4; ++i)
2793 gRandom->SetSeed(dword[i]);
2794 dword[i] = gRandom->Integer(0xFFFFFFFF);
2796 md52.Update(buf, sizeof(buf));
2798 // To keep to the standard we need to set the version and reserved bits.
2799 word[3] = (word[3] & 0x0FFF) | 0x4000;
2800 buf[8] = (buf[8] & 0x3F) | 0x80;
2802 // Create the name of the new class and file.
2804 sprintf(uuidstr, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
2805 dword[0], word[2], word[3], buf[8], buf[9], buf[10], buf[11], buf[12], buf[13], buf[14], buf[15]
2808 uuid.SetUUID(uuidstr);
2812 int AliHLTComponent::ScanECSParam(const char* ecsParam)
2814 // see header file for function documentation
2816 // format of the parameter string from ECS
2817 // <command>;<parameterkey>=<parametervalue>;<parameterkey>=<parametervalue>;...
2818 // search for a subset of the parameterkeys
2822 // CTP_TRIGGER_CLASS=
2823 // DATA_FORMAT_VERSION=
2825 // HLT_OUT_DDL_LIST=
2826 // HLT_TRIGGER_CODE=
2829 // The command apears not to be sent by the online framework
2831 TString string=ecsParam;
2832 TObjArray* parameter=string.Tokenize(";");
2834 for (int i=0; i<parameter->GetEntriesFast(); i++) {
2835 TString entry=parameter->At(i)->GetName();
2836 HLTDebug("scanning ECS entry: %s", entry.Data());
2837 TObjArray* entryParams=entry.Tokenize("=");
2839 if (entryParams->GetEntriesFast()>1) {
2840 if ((((TObjString*)entryParams->At(0))->GetString()).CompareTo("CTP_TRIGGER_CLASS")==0) {
2841 int result=InitCTPTriggerClasses(entryParams->At(1)->GetName());
2842 if (iResult>=0 && result<0) iResult=result;
2844 // TODO: scan the other parameters
2845 // e.g. consistency check of run number
2857 int AliHLTComponent::SetupCTPData()
2859 // see header file for function documentation
2860 if (fpCTPData) delete fpCTPData;
2861 fpCTPData=new AliHLTCTPData;
2862 if (!fpCTPData) return -ENOMEM;
2866 int AliHLTComponent::InitCTPTriggerClasses(const char* ctpString)
2868 // see header file for function documentation
2869 if (!fpCTPData) return 0; // silently accept as the component has to announce that it want's the CTP info
2870 return fpCTPData->InitCTPTriggerClasses(ctpString);
2873 bool AliHLTComponent::EvaluateCTPTriggerClass(const char* expression, AliHLTComponentTriggerData& trigData) const
2875 // see header file for function documentation
2877 static bool bWarningThrown=false;
2878 if (!bWarningThrown) HLTError("Trigger classes not initialized, use SetupCTPData from DoInit()");
2879 bWarningThrown=true;
2883 return fpCTPData->EvaluateCTPTriggerClass(expression, trigData);
2886 int AliHLTComponent::CheckCTPTrigger(const char* name) const
2888 // see header file for function documentation
2890 static bool bWarningThrown=false;
2891 if (!bWarningThrown) HLTError("Trigger classes not initialized, use SetupCTPData from DoInit()");
2892 bWarningThrown=true;
2896 return fpCTPData->CheckTrigger(name);
2899 Double_t AliHLTComponent::GetBz()
2902 return AliHLTMisc::Instance().GetBz();
2905 Double_t AliHLTComponent::GetBz(const Double_t *r)
2907 // Returns Bz (kG) at the point "r" .
2908 return AliHLTMisc::Instance().GetBz(r);
2911 void AliHLTComponent::GetBxByBz(const Double_t r[3], Double_t b[3])
2913 // Returns Bx, By and Bz (kG) at the point "r" .
2914 AliHLTMisc::Instance().GetBxByBz(r, b);