3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project *
5 //* ALICE Experiment at CERN, All rights reserved. *
7 //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 //* Timm Steinbeck <timm@kip.uni-heidelberg.de> *
9 //* for The ALICE HLT Project. *
11 //* Permission to use, copy, modify and distribute this software and its *
12 //* documentation strictly for non-commercial purposes is hereby granted *
13 //* without fee, provided that the above copyright notice appears in all *
14 //* copies and that both the copyright notice and this permission notice *
15 //* appear in the supporting documentation. The authors make no claims *
16 //* about the suitability of this software for any purpose. It is *
17 //* provided "as is" without express or implied warranty. *
18 //**************************************************************************
20 /** @file AliHLTComponent.cxx
21 @author Matthias Richter, Timm Steinbeck
23 @brief Base class implementation for HLT components. */
29 //#include "AliHLTStdIncludes.h"
30 #include "AliHLTComponent.h"
31 #include "AliHLTComponentHandler.h"
32 #include "AliHLTMessage.h"
33 #include "AliHLTCTPData.h"
36 #include "TObjArray.h"
37 #include "TObjectTable.h"
39 #include "TStopwatch.h"
41 #include "AliHLTMemoryFile.h"
42 #include "AliHLTMisc.h"
47 * default compression level for ROOT objects
49 #define ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION 5
50 #define ALIHLTCOMPONENT_STATTIME_SCALER 1000000
52 /** ROOT macro for the implementation of ROOT specific class methods */
53 ClassImp(AliHLTComponent);
55 /** stopwatch macro using the stopwatch guard */
56 #define ALIHLTCOMPONENT_STOPWATCH(type) AliHLTStopwatchGuard swguard(fpStopwatches!=NULL?reinterpret_cast<TStopwatch*>(fpStopwatches->At((int)type)):NULL)
57 //#define ALIHLTCOMPONENT_STOPWATCH(type)
59 /** stopwatch macro for operations of the base class */
60 #define ALIHLTCOMPONENT_BASE_STOPWATCH() ALIHLTCOMPONENT_STOPWATCH(kSWBase)
61 /** stopwatch macro for operations of the detector algorithm (DA) */
62 #define ALIHLTCOMPONENT_DA_STOPWATCH() ALIHLTCOMPONENT_STOPWATCH(kSWDA)
64 AliHLTComponent::AliHLTComponent()
72 fCurrentInputBlock(-1),
73 fSearchDataType(kAliHLTVoidDataType),
78 fOutputBufferFilled(0),
80 fpStopwatches(new TObjArray(kSWTypeCount)),
84 fCDBSetRunNoFunc(false),
88 fRequireSteeringBlocks(false),
89 fEventType(gkAliEventTypeUnknown),
92 fEventDoneDataSize(0),
93 fCompressionLevel(ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION)
97 // see header file for class documentation
99 // refer to README to build package
101 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
102 memset(&fEnvironment, 0, sizeof(AliHLTAnalysisEnvironment));
103 if (fgpComponentHandler)
104 fgpComponentHandler->ScheduleRegister(this);
105 //SetLocalLoggingLevel(kHLTLogDefault);
108 AliHLTComponent::~AliHLTComponent()
110 // see header file for function documentation
111 if (fpBenchmark) delete fpBenchmark;
114 CleanupInputObjects();
115 if (fpStopwatches!=NULL) delete fpStopwatches;
117 AliHLTMemoryFilePList::iterator element=fMemFiles.begin();
118 while (element!=fMemFiles.end()) {
120 if ((*element)->IsClosed()==0) {
121 HLTWarning("memory file has not been closed, possible data loss or incomplete buffer");
122 // close but do not flush as we dont know whether the buffer is still valid
123 (*element)->CloseMemoryFile(0);
135 delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
144 AliHLTComponentHandler* AliHLTComponent::fgpComponentHandler=NULL;
146 int AliHLTComponent::SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite)
148 // see header file for function documentation
150 if (fgpComponentHandler==NULL || bOverwrite!=0)
151 fgpComponentHandler=pCH;
157 int AliHLTComponent::UnsetGlobalComponentHandler()
159 // see header file for function documentation
160 return SetGlobalComponentHandler(NULL,1);
163 int AliHLTComponent::SetComponentEnvironment(const AliHLTAnalysisEnvironment* comenv, void* environParam)
165 // see header file for function documentation
166 HLTLogKeyword(fChainId.c_str());
169 memset(&fEnvironment, 0, sizeof(AliHLTAnalysisEnvironment));
170 memcpy(&fEnvironment, comenv, comenv->fStructSize<sizeof(AliHLTAnalysisEnvironment)?comenv->fStructSize:sizeof(AliHLTAnalysisEnvironment));
171 fEnvironment.fStructSize=sizeof(AliHLTAnalysisEnvironment);
172 fEnvironment.fParam=environParam;
177 int AliHLTComponent::Init(const AliHLTAnalysisEnvironment* comenv, void* environParam, int argc, const char** argv )
179 // see header file for function documentation
180 HLTLogKeyword(fChainId.c_str());
183 SetComponentEnvironment(comenv, environParam);
186 const char** pArguments=NULL;
191 pArguments=new const char*[argc];
193 for (int i=0; i<argc && iResult>=0; i++) {
194 if (fComponentArgs.size()>0) fComponentArgs+=" ";
195 fComponentArgs+=argv[i];
197 if (argument.IsNull()) continue;
200 if (argument.CompareTo("-benchmark")==0) {
203 } else if (argument.BeginsWith("-loglevel=")) {
204 TString parameter=argument.ReplaceAll("-loglevel=", "");
205 parameter.Remove(TString::kLeading, ' '); // remove all blanks
206 if (parameter.BeginsWith("0x") &&
207 parameter.Replace(0,2,"",0).IsHex()) {
208 unsigned int loglevel=kHLTLogNone;
209 sscanf(parameter.Data(),"%x", &loglevel);
210 SetLocalLoggingLevel((AliHLTComponentLogSeverity)loglevel);
212 HLTError("wrong parameter for argument %s, hex number expected", argument.Data());
215 // -object-compression=
216 } else if (argument.BeginsWith("-object-compression=")) {
217 argument.ReplaceAll("-object-compression=", "");
218 if (argument.IsDigit()) {
219 fCompressionLevel=argument.Atoi();
220 if (fCompressionLevel<0 || fCompressionLevel>9) {
221 HLTWarning("invalid compression level %d, setting to default %d", fCompressionLevel, ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION);
222 fCompressionLevel=ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION;
225 HLTError("wrong parameter for argument -object-compression, number expected");
228 pArguments[iNofChildArgs++]=argv[i];
236 HLTError("missing parameter for argument %s", argument.Data());
240 iResult=DoInit(iNofChildArgs, pArguments);
245 // find out if the component wants to get the steering events
247 AliHLTComponentDataTypeList inputDt;
248 GetInputDataTypes(inputDt);
249 for (AliHLTComponentDataTypeList::iterator dt=inputDt.begin();
250 dt!=inputDt.end() && !fRequireSteeringBlocks;
252 fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeSOR);
253 fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeRunType);
254 fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeEOR);
255 fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeDDL);
256 fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeComponentStatistics);
259 if (pArguments) delete [] pArguments;
261 #if defined(__DEBUG) || defined(HLT_COMPONENT_STATISTICS)
262 // benchmarking stopwatch for the component statistics
263 fpBenchmark=new TStopwatch;
269 int AliHLTComponent::Deinit()
271 // see header file for function documentation
272 HLTLogKeyword(fChainId.c_str());
276 // TODO: the warning should be kept, but the condition is wrong since the
277 // AliHLTRunDesc is set before the SOR event in the SetRunDescription
278 // method. A couple of state flags should be defined but that is a bit more
279 // work to do. For the moment disable the warning (2009-07-01)
280 //HLTWarning("did not receive EOR for run %d", fpRunDesc->fRunNo);
281 AliHLTRunDesc* pRunDesc=fpRunDesc;
294 int AliHLTComponent::InitCDB(const char* cdbPath, AliHLTComponentHandler* pHandler)
296 // see header file for function documentation
298 HLTInfo("Using CDB: %s", cdbPath);
300 // I have to think about separating the library handling from the
301 // component handler. Requiring the component handler here is not
302 // the cleanest solution.
303 // We presume the library already to be loaded, which is the case
304 // because it is loaded in the initialization of the logging functionality
307 AliHLTMiscInitCDB_t pFunc=(AliHLTMiscInitCDB_t)pHandler->FindSymbol(ALIHLTMISC_LIBRARY, ALIHLTMISC_INIT_CDB);
310 if (cdbPath && cdbPath[0]!=0) {
312 // very temporary fix, have to check for other formats
313 if (!path.BeginsWith("local://")) {
318 if ((iResult=(*pFunc)(path.Data()))>=0) {
319 if (!(fCDBSetRunNoFunc=pHandler->FindSymbol(ALIHLTMISC_LIBRARY, ALIHLTMISC_SET_CDB_RUNNO))) {
320 Message(NULL, kHLTLogWarning, "AliHLTComponent::InitCDB", "init CDB",
321 "can not find function to set CDB run no");
325 Message(NULL, kHLTLogError, "AliHLTComponent::InitCDB", "init CDB",
326 "can not find initialization function");
335 int AliHLTComponent::SetCDBRunNo(int runNo)
337 // see header file for function documentation
338 if (!fCDBSetRunNoFunc) return 0;
339 return (*((AliHLTMiscSetCDBRunNo_t)fCDBSetRunNoFunc))(runNo);
342 int AliHLTComponent::SetRunDescription(const AliHLTRunDesc* desc, const char* /*runType*/)
344 // see header file for function documentation
345 if (!desc) return -EINVAL;
346 if (desc->fStructSize!=sizeof(AliHLTRunDesc)) {
347 HLTError("invalid size of RunDesc struct (%ul)", desc->fStructSize);
352 fpRunDesc=new AliHLTRunDesc;
353 if (!fpRunDesc) return -ENOMEM;
354 *fpRunDesc=kAliHLTVoidRunDesc;
357 if (fpRunDesc->fRunNo!=kAliHLTVoidRunNo && fpRunDesc->fRunNo!=desc->fRunNo) {
358 HLTWarning("Run description has already been set");
361 SetCDBRunNo(fpRunDesc->fRunNo);
362 // TODO: we have to decide about the runType
366 int AliHLTComponent::SetComponentDescription(const char* desc)
368 // see header file for function documentation
372 TString descriptor=desc;
373 TObjArray* pTokens=descriptor.Tokenize(" ");
375 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
376 TString argument=((TObjString*)pTokens->At(i++))->GetString();
377 if (!argument || argument.IsNull()) continue;
380 if (argument.BeginsWith("chainid")) {
381 argument.ReplaceAll("chainid", "");
382 if (argument.BeginsWith("=")) {
383 fChainId=argument.Replace(0,1,"");
384 fChainIdCrc=CalculateChecksum((const AliHLTUInt8_t*)fChainId.c_str(), fChainId.length());
385 HLTDebug("setting component description: chain id %s crc 0x%8x", fChainId.c_str(), fChainIdCrc);
390 HLTWarning("unknown component description %s", argument.Data());
398 int AliHLTComponent::ConfigureFromArgumentString(int argc, const char** argv)
400 // see header file for function documentation
402 vector<const char*> array;
403 TObjArray choppedArguments;
406 for (i=0; i<argc && iResult>=0; i++) {
408 if (argument.IsNull()) continue;
409 TObjArray* pTokens=argument.Tokenize(" ");
411 if (pTokens->GetEntriesFast()>0) {
412 for (int n=0; n<pTokens->GetEntriesFast(); n++) {
413 choppedArguments.AddLast(pTokens->At(n));
414 TString data=((TObjString*)pTokens->At(n))->GetString();
415 if (!data.IsNull()) {
416 array.push_back(data.Data());
419 pTokens->SetOwner(kFALSE);
425 for (i=0; (unsigned)i<array.size() && iResult>=0;) {
426 int result=ScanConfigurationArgument(array.size()-i, &array[i]);
428 HLTWarning("unknown component argument %s", array[i]);
430 } else if (result>0) {
434 if (iResult==-EINVAL) {
435 HLTError("unknown argument %s", array[i]);
436 } else if (iResult==-EPROTO) {
437 HLTError("missing/wrong parameter for argument %s (%s)", array[i], (array.size()>(unsigned)i+1)?array[i+1]:"missing");
439 HLTError("scan of argument %s failed (%d)", array[i], iResult);
447 int AliHLTComponent::ConfigureFromCDBTObjString(const char* entries)
449 // see header file for function documentation
452 TString confEntries=entries;
453 TObjArray* pTokens=confEntries.Tokenize(" ");
455 for (int n=0; n<pTokens->GetEntriesFast(); n++) {
456 const char* path=((TObjString*)pTokens->At(n))->GetString().Data();
457 const char* chainId=GetChainId();
458 HLTInfo("configure from entry %s, chain id %s", path, (chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
459 TObject* pOCDBObject = LoadAndExtractOCDBObject(path);
461 TObjString* pString=dynamic_cast<TObjString*>(pOCDBObject);
463 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
464 arguments+=pString->GetString().Data();
467 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
471 HLTError("can not fetch object \"%s\" from OCDB", path);
477 if (iResult>=0 && !arguments.IsNull()) {
478 const char* array=arguments.Data();
479 iResult=ConfigureFromArgumentString(1, &array);
484 TObject* AliHLTComponent::LoadAndExtractOCDBObject(const char* path, int version, int subVersion)
486 // see header file for function documentation
487 AliCDBEntry* pEntry=AliHLTMisc::Instance().LoadOCDBEntry(path, GetRunNo(), version, subVersion);
488 if (!pEntry) return NULL;
489 return AliHLTMisc::Instance().ExtractObject(pEntry);
492 int AliHLTComponent::DoInit( int /*argc*/, const char** /*argv*/)
494 // default implementation, childs can overload
495 HLTLogKeyword("dummy");
499 int AliHLTComponent::DoDeinit()
501 // default implementation, childs can overload
502 HLTLogKeyword("dummy");
506 int AliHLTComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/)
508 // default implementation, childs can overload
509 HLTLogKeyword("dummy");
513 int AliHLTComponent::ReadPreprocessorValues(const char* /*modules*/)
515 // default implementation, childs can overload
516 HLTLogKeyword("dummy");
520 int AliHLTComponent::ScanConfigurationArgument(int /*argc*/, const char** /*argv*/)
522 // default implementation, childs can overload
523 HLTLogKeyword("dummy");
524 HLTWarning("The function needs to be implemented by the component");
528 int AliHLTComponent::StartOfRun()
530 // default implementation, childs can overload
531 HLTLogKeyword("dummy");
535 int AliHLTComponent::EndOfRun()
537 // default implementation, childs can overload
538 HLTLogKeyword("dummy");
543 int AliHLTComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& /*tgtList*/)
545 // default implementation, childs can overload
546 HLTLogKeyword("dummy");
550 void AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2] ) const
552 // see header file for function documentation
553 memset( output, 0, kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2 );
554 strncat( output, type.fOrigin, kAliHLTComponentDataTypefOriginSize );
555 strcat( output, ":" );
556 strncat( output, type.fID, kAliHLTComponentDataTypefIDsize );
559 string AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, int mode)
561 // see header file for function documentation
567 for (i=0; i<kAliHLTComponentDataTypefOriginSize; i++) {
568 sprintf(tmp, "'%d", type.fOrigin[i]);
572 for (i=0; i<kAliHLTComponentDataTypefIDsize; i++) {
573 sprintf(tmp, "%d'", type.fID[i]);
582 for (i=0; i<kAliHLTComponentDataTypefOriginSize; i++) {
583 unsigned char* puc=(unsigned char*)type.fOrigin;
585 sprintf(tmp, "'\\%x", type.fOrigin[i]);
587 sprintf(tmp, "'%c", type.fOrigin[i]);
591 for (i=0; i<kAliHLTComponentDataTypefIDsize; i++) {
592 unsigned char* puc=(unsigned char*)type.fID;
594 sprintf(tmp, "\\%x'", type.fID[i]);
596 sprintf(tmp, "%c'", type.fID[i]);
602 if (type==kAliHLTVoidDataType) {
605 // some gymnastics in order to avoid a '0' which is part of either or both
606 // ID and origin terminating the whole string. Unfortunately, string doesn't
607 // stop appending at the '0' if the number of elements to append was
608 // explicitely specified
610 tmp.append(type.fOrigin, kAliHLTComponentDataTypefOriginSize);
611 out.append(tmp.c_str());
614 tmp.append(type.fID, kAliHLTComponentDataTypefIDsize);
615 out.append(tmp.c_str());
621 void* AliHLTComponent::AllocMemory( unsigned long size )
623 // see header file for function documentation
624 if (fEnvironment.fAllocMemoryFunc)
625 return (*fEnvironment.fAllocMemoryFunc)(fEnvironment.fParam, size );
626 HLTFatal("no memory allocation handler registered");
630 int AliHLTComponent::MakeOutputDataBlockList( const AliHLTComponentBlockDataList& blocks, AliHLTUInt32_t* blockCount,
631 AliHLTComponentBlockData** outputBlocks )
633 // see header file for function documentation
634 if ( blockCount==NULL || outputBlocks==NULL )
636 AliHLTUInt32_t count = blocks.size();
640 *outputBlocks = NULL;
643 *outputBlocks = reinterpret_cast<AliHLTComponentBlockData*>( AllocMemory( sizeof(AliHLTComponentBlockData)*count ) );
644 if ( !*outputBlocks )
646 for ( unsigned long i = 0; i < count; i++ ) {
647 (*outputBlocks)[i] = blocks[i];
648 if (MatchExactly(blocks[i].fDataType, kAliHLTAnyDataType)) {
649 (*outputBlocks)[i].fDataType=GetOutputDataType();
650 /* data type was set to the output data type by the PubSub AliRoot
651 Wrapper component, if data type of the block was ********:****.
652 Now handled by the component base class in order to have same
653 behavior when running embedded in AliRoot
654 memset((*outputBlocks)[i].fDataType.fID, '*', kAliHLTComponentDataTypefIDsize);
655 memset((*outputBlocks)[i].fDataType.fOrigin, '*', kAliHLTComponentDataTypefOriginSize);
664 int AliHLTComponent::GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd )
666 // see header file for function documentation
667 if (fEnvironment.fGetEventDoneDataFunc)
668 return (*fEnvironment.fGetEventDoneDataFunc)(fEnvironment.fParam, fCurrentEvent, size, edd );
672 int AliHLTComponent::ReserveEventDoneData( unsigned long size )
674 // see header file for function documentation
677 unsigned long capacity=fEventDoneDataSize;
678 if (fEventDoneData) capacity-=sizeof(AliHLTComponentEventDoneData)+fEventDoneData->fDataSize;
680 unsigned long newSize=sizeof(AliHLTComponentEventDoneData)+size+(fEventDoneDataSize-capacity);
681 AliHLTComponentEventDoneData* newEDD = reinterpret_cast<AliHLTComponentEventDoneData*>( new AliHLTUInt8_t[newSize] );
684 newEDD->fStructSize = sizeof(AliHLTComponentEventDoneData);
685 newEDD->fDataSize = 0;
686 newEDD->fData = reinterpret_cast<AliHLTUInt8_t*>(newEDD)+newEDD->fStructSize;
687 if (fEventDoneData) {
688 memcpy( newEDD->fData, fEventDoneData->fData, fEventDoneData->fDataSize );
689 newEDD->fDataSize = fEventDoneData->fDataSize;
690 delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
692 fEventDoneData = newEDD;
693 fEventDoneDataSize = newSize;
699 int AliHLTComponent::PushEventDoneData( AliHLTUInt32_t eddDataWord )
703 if (fEventDoneData->fDataSize+sizeof(AliHLTUInt32_t)>fEventDoneDataSize)
705 *reinterpret_cast<AliHLTUInt32_t*>((reinterpret_cast<AliHLTUInt8_t*>(fEventDoneData->fData)+fEventDoneData->fDataSize)) = eddDataWord;
706 fEventDoneData->fDataSize += sizeof(AliHLTUInt32_t);
710 void AliHLTComponent::ReleaseEventDoneData()
713 delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
714 fEventDoneData = NULL;
715 fEventDoneDataSize = 0;
719 int AliHLTComponent::FindMatchingDataTypes(AliHLTComponent* pConsumer, AliHLTComponentDataTypeList* tgtList)
721 // see header file for function documentation
724 AliHLTComponentDataTypeList itypes;
725 AliHLTComponentDataTypeList otypes;
726 otypes.push_back(GetOutputDataType());
727 if (MatchExactly(otypes[0],kAliHLTMultipleDataType)) {
730 if ((count=GetOutputDataTypes(otypes))>0) {
731 } else if (GetComponentType()!=kSink) {
732 HLTWarning("component %s indicates multiple output data types but GetOutputDataTypes returns %d", GetComponentID(), count);
735 ((AliHLTComponent*)pConsumer)->GetInputDataTypes(itypes);
736 AliHLTComponentDataTypeList::iterator otype=otypes.begin();
737 for (;otype!=otypes.end();otype++) {
738 //PrintDataTypeContent((*otype), "publisher \'%s\'");
739 if ((*otype)==(kAliHLTAnyDataType|kAliHLTDataOriginPrivate)) {
740 if (tgtList) tgtList->push_back(*otype);
745 AliHLTComponentDataTypeList::iterator itype=itypes.begin();
746 for ( ; itype!=itypes.end() && (*itype)!=(*otype) ; itype++) {/* empty body */};
747 //if (itype!=itypes.end()) PrintDataTypeContent(*itype, "consumer \'%s\'");
748 if (itype!=itypes.end()) {
749 if (tgtList) tgtList->push_back(*otype);
759 void AliHLTComponent::PrintDataTypeContent(AliHLTComponentDataType& dt, const char* format)
761 // see header file for function documentation
762 const char* fmt="\'%s\'";
763 if (format) fmt=format;
764 AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, Form(fmt, (DataType2Text(dt)).c_str()));
765 AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL,
766 Form("%x %x %x %x %x %x %x %x : %x %x %x %x",
781 void AliHLTComponent::FillBlockData( AliHLTComponentBlockData& blockData )
783 // see header file for function documentation
784 blockData.fStructSize = sizeof(blockData);
785 FillShmData( blockData.fShmKey );
786 blockData.fOffset = ~(AliHLTUInt32_t)0;
787 blockData.fPtr = NULL;
789 FillDataType( blockData.fDataType );
790 blockData.fSpecification = kAliHLTVoidDataSpec;
793 void AliHLTComponent::FillShmData( AliHLTComponentShmData& shmData )
795 // see header file for function documentation
796 shmData.fStructSize = sizeof(shmData);
797 shmData.fShmType = gkAliHLTComponentInvalidShmType;
798 shmData.fShmID = gkAliHLTComponentInvalidShmID;
801 void AliHLTComponent::FillDataType( AliHLTComponentDataType& dataType )
803 // see header file for function documentation
804 dataType=kAliHLTAnyDataType;
807 void AliHLTComponent::CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt)
809 // see header file for function documentation
810 memcpy(&tgtdt.fID[0], &srcdt.fID[0], kAliHLTComponentDataTypefIDsize);
811 memcpy(&tgtdt.fOrigin[0], &srcdt.fOrigin[0], kAliHLTComponentDataTypefOriginSize);
814 void AliHLTComponent::SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin)
816 // see header file for function documentation
817 tgtdt.fStructSize=sizeof(AliHLTComponentDataType);
819 memset(&tgtdt.fID[0], 0, kAliHLTComponentDataTypefIDsize);
820 strncpy(&tgtdt.fID[0], id, strlen(id)<(size_t)kAliHLTComponentDataTypefIDsize?strlen(id):kAliHLTComponentDataTypefIDsize);
823 memset(&tgtdt.fOrigin[0], 0, kAliHLTComponentDataTypefOriginSize);
824 strncpy(&tgtdt.fOrigin[0], origin, strlen(origin)<(size_t)kAliHLTComponentDataTypefOriginSize?strlen(origin):kAliHLTComponentDataTypefOriginSize);
828 void AliHLTComponent::SetDataType(AliHLTComponentDataType& dt, AliHLTUInt64_t id, AliHLTUInt32_t origin)
830 // see header file for function documentation
831 dt.fStructSize=sizeof(AliHLTComponentDataType);
832 assert(kAliHLTComponentDataTypefIDsize==sizeof(id));
833 assert(kAliHLTComponentDataTypefOriginSize==sizeof(origin));
834 memcpy(&dt.fID, &id, kAliHLTComponentDataTypefIDsize);
835 memcpy(&dt.fOrigin, &origin, kAliHLTComponentDataTypefOriginSize);
838 void AliHLTComponent::FillEventData(AliHLTComponentEventData& evtData)
840 // see header file for function documentation
841 memset(&evtData, 0, sizeof(AliHLTComponentEventData));
842 evtData.fStructSize=sizeof(AliHLTComponentEventData);
843 evtData.fEventID=kAliHLTVoidEventID;
846 void AliHLTComponent::PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt)
848 // see header file for function documentation
850 msg.Form("AliHLTComponentDataType(%d): ID=\"", dt.fStructSize);
851 for ( int i = 0; i < kAliHLTComponentDataTypefIDsize; i++ ) {
852 if (dt.fID[i]!=0) msg+=dt.fID[i];
856 for ( int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++ ) {
857 if (dt.fOrigin[i]!=0) msg+=dt.fOrigin[i];
861 AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, msg.Data());
864 int AliHLTComponent::GetEventCount() const
866 // see header file for function documentation
870 int AliHLTComponent::IncrementEventCounter()
872 // see header file for function documentation
873 if (fEventCount>=0) fEventCount++;
877 int AliHLTComponent::GetNumberOfInputBlocks() const
879 // see header file for function documentation
880 if (fpInputBlocks!=NULL) {
881 return fCurrentEventData.fBlockCnt;
886 AliHLTEventID_t AliHLTComponent::GetEventId() const
888 // see header file for function documentation
889 if (fpInputBlocks!=NULL) {
890 return fCurrentEventData.fEventID;
895 const TObject* AliHLTComponent::GetFirstInputObject(const AliHLTComponentDataType& dt,
896 const char* classname,
899 // see header file for function documentation
900 ALIHLTCOMPONENT_BASE_STOPWATCH();
902 if (classname) fClassName=classname;
903 else fClassName.clear();
904 int idx=FindInputBlock(fSearchDataType, 0, 1);
907 HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(dt).c_str());
908 if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) {
909 fCurrentInputBlock=idx;
916 const TObject* AliHLTComponent::GetFirstInputObject(const char* dtID,
917 const char* dtOrigin,
918 const char* classname,
921 // see header file for function documentation
922 ALIHLTCOMPONENT_BASE_STOPWATCH();
923 AliHLTComponentDataType dt;
924 SetDataType(dt, dtID, dtOrigin);
925 return GetFirstInputObject(dt, classname, bForce);
928 const TObject* AliHLTComponent::GetNextInputObject(int bForce)
930 // see header file for function documentation
931 ALIHLTCOMPONENT_BASE_STOPWATCH();
932 int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1, 1);
933 //HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(fSearchDataType).c_str());
936 if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) {
937 fCurrentInputBlock=idx;
943 int AliHLTComponent::FindInputBlock(const AliHLTComponentDataType& dt, int startIdx, int bObject) const
945 // see header file for function documentation
947 if (fpInputBlocks!=NULL) {
948 int idx=startIdx<0?0:startIdx;
949 for ( ; (UInt_t)idx<fCurrentEventData.fBlockCnt && iResult==-ENOENT; idx++) {
950 if (dt!=fpInputBlocks[idx].fDataType) continue;
953 if (fpInputBlocks[idx].fPtr==NULL) continue;
954 AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr);
955 if (firstWord!=fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) continue;
963 TObject* AliHLTComponent::CreateInputObject(int idx, int bForce)
965 // see header file for function documentation
967 if (fpInputBlocks!=NULL) {
968 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
969 if (fpInputBlocks[idx].fPtr) {
970 AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr);
971 if (firstWord==fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) {
972 HLTDebug("create object from block %d size %d", idx, fpInputBlocks[idx].fSize);
973 AliHLTMessage msg(fpInputBlocks[idx].fPtr, fpInputBlocks[idx].fSize);
974 TClass* objclass=msg.GetClass();
975 pObj=msg.ReadObject(objclass);
976 if (pObj && objclass) {
977 HLTDebug("object %p type %s created", pObj, objclass->GetName());
981 } else if (bForce!=0) {
982 HLTError("size mismatch: block size %d, indicated %d", fpInputBlocks[idx].fSize, firstWord+sizeof(AliHLTUInt32_t));
985 HLTFatal("block descriptor empty");
988 HLTError("index %d out of range %d", idx, fCurrentEventData.fBlockCnt);
991 HLTError("no input blocks available");
997 TObject* AliHLTComponent::GetInputObject(int idx, const char* /*classname*/, int bForce)
999 // see header file for function documentation
1000 if (fpInputObjects==NULL) {
1001 fpInputObjects=new TObjArray(fCurrentEventData.fBlockCnt);
1004 if (fpInputObjects) {
1005 pObj=fpInputObjects->At(idx);
1007 pObj=CreateInputObject(idx, bForce);
1009 fpInputObjects->AddAt(pObj, idx);
1013 HLTFatal("memory allocation failed: TObjArray of size %d", fCurrentEventData.fBlockCnt);
1018 int AliHLTComponent::CleanupInputObjects()
1020 // see header file for function documentation
1021 if (!fpInputObjects) return 0;
1022 TObjArray* array=fpInputObjects;
1023 fpInputObjects=NULL;
1024 for (int i=0; i<array->GetEntries(); i++) {
1025 TObject* pObj=array->At(i);
1026 // grrr, garbage collection strikes back: When read via AliHLTMessage
1027 // (CreateInputObject), and written to a TFile afterwards, the
1028 // TFile::Close calls ROOOT's garbage collection. No clue why the
1029 // object ended up in the key list and needs to be deleted
1031 // Matthias 09.11.2008 follow up
1032 // This approach doesn't actually work in all cases: the object table
1033 // can be switched off globally, the flag needs to be checked here as
1034 // well in order to avoid memory leaks.
1035 // This means we have to find another solution for the problem if it
1038 (!TObject::GetObjectStat() || gObjectTable->PtrIsValid(pObj))) {
1046 AliHLTComponentDataType AliHLTComponent::GetDataType(const TObject* pObject)
1048 // see header file for function documentation
1049 ALIHLTCOMPONENT_BASE_STOPWATCH();
1050 AliHLTComponentDataType dt=kAliHLTVoidDataType;
1051 int idx=fCurrentInputBlock;
1053 if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
1055 HLTError("unknown object %p", pObject);
1059 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
1060 dt=fpInputBlocks[idx].fDataType;
1062 HLTFatal("severe internal error, index out of range");
1068 AliHLTUInt32_t AliHLTComponent::GetSpecification(const TObject* pObject)
1070 // see header file for function documentation
1071 ALIHLTCOMPONENT_BASE_STOPWATCH();
1072 AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec;
1073 int idx=fCurrentInputBlock;
1075 if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
1077 HLTError("unknown object %p", pObject);
1081 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
1082 iSpec=fpInputBlocks[idx].fSpecification;
1084 HLTFatal("severe internal error, index out of range");
1090 int AliHLTComponent::Forward(const TObject* pObject)
1092 // see header file for function documentation
1094 int idx=fCurrentInputBlock;
1096 if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
1098 HLTError("unknown object %p", pObject);
1103 fOutputBlocks.push_back(fpInputBlocks[idx]);
1108 int AliHLTComponent::Forward(const AliHLTComponentBlockData* pBlock)
1110 // see header file for function documentation
1112 int idx=fCurrentInputBlock;
1114 if (fpInputObjects==NULL || (idx=FindInputBlock(pBlock))>=0) {
1116 HLTError("unknown Block %p", pBlock);
1121 // check for fpInputBlocks pointer done in FindInputBlock
1122 fOutputBlocks.push_back(fpInputBlocks[idx]);
1127 const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const AliHLTComponentDataType& dt)
1129 // see header file for function documentation
1130 ALIHLTCOMPONENT_BASE_STOPWATCH();
1133 int idx=FindInputBlock(fSearchDataType, 0);
1134 const AliHLTComponentBlockData* pBlock=NULL;
1136 // check for fpInputBlocks pointer done in FindInputBlock
1137 pBlock=&fpInputBlocks[idx];
1138 fCurrentInputBlock=idx;
1143 const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const char* dtID,
1144 const char* dtOrigin)
1146 // see header file for function documentation
1147 ALIHLTCOMPONENT_BASE_STOPWATCH();
1148 AliHLTComponentDataType dt;
1149 SetDataType(dt, dtID, dtOrigin);
1150 return GetFirstInputBlock(dt);
1153 const AliHLTComponentBlockData* AliHLTComponent::GetInputBlock(int index) const
1155 // see header file for function documentation
1156 ALIHLTCOMPONENT_BASE_STOPWATCH();
1157 assert( 0 <= index and index < (int)fCurrentEventData.fBlockCnt );
1158 return &fpInputBlocks[index];
1161 const AliHLTComponentBlockData* AliHLTComponent::GetNextInputBlock()
1163 // see header file for function documentation
1164 ALIHLTCOMPONENT_BASE_STOPWATCH();
1165 int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1);
1166 const AliHLTComponentBlockData* pBlock=NULL;
1168 // check for fpInputBlocks pointer done in FindInputBlock
1169 pBlock=&fpInputBlocks[idx];
1170 fCurrentInputBlock=idx;
1175 int AliHLTComponent::FindInputBlock(const AliHLTComponentBlockData* pBlock) const
1177 // see header file for function documentation
1178 int iResult=-ENOENT;
1179 if (fpInputBlocks!=NULL) {
1181 if (pBlock>=fpInputBlocks && pBlock<fpInputBlocks+fCurrentEventData.fBlockCnt) {
1182 iResult=(int)(pBlock-fpInputBlocks);
1191 AliHLTUInt32_t AliHLTComponent::GetSpecification(const AliHLTComponentBlockData* pBlock)
1193 // see header file for function documentation
1194 ALIHLTCOMPONENT_BASE_STOPWATCH();
1195 AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec;
1196 int idx=fCurrentInputBlock;
1198 if (fpInputObjects==NULL || (idx=FindInputBlock(pBlock))>=0) {
1200 HLTError("unknown Block %p", pBlock);
1204 // check for fpInputBlocks pointer done in FindInputBlock
1205 iSpec=fpInputBlocks[idx].fSpecification;
1210 int AliHLTComponent::PushBack(TObject* pObject, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
1211 void* pHeader, int headerSize)
1213 // see header file for function documentation
1214 ALIHLTCOMPONENT_BASE_STOPWATCH();
1218 AliHLTMessage msg(kMESS_OBJECT);
1219 msg.SetCompressionLevel(fCompressionLevel);
1220 msg.WriteObject(pObject);
1221 Int_t iMsgLength=msg.Length();
1223 // Matthias Sep 2008
1224 // NOTE: AliHLTMessage does implement it's own SetLength method
1225 // which is not architecture independent. The original SetLength
1226 // stores the size always in network byte order.
1227 // I'm trying to remember the rational for that, might be that
1228 // it was just some lack of knowledge. Want to change this, but
1229 // has to be done carefullt to be backward compatible.
1230 msg.SetLength(); // sets the length to the first (reserved) word
1232 // does nothing if the level is 0
1235 char *mbuf = msg.Buffer();
1236 if (msg.CompBuffer()) {
1237 msg.SetLength(); // set once more to have to byte order
1238 mbuf = msg.CompBuffer();
1239 iMsgLength = msg.CompLength();
1242 iResult=InsertOutputBlock(mbuf, iMsgLength, dt, spec, pHeader, headerSize);
1244 HLTDebug("object %s (%p) size %d compression %d inserted to output", pObject->ClassName(), pObject, iMsgLength, msg.GetCompressionLevel());
1246 fLastObjectSize=iMsgLength;
1248 HLTError("object serialization failed for object %p", pObject);
1257 int AliHLTComponent::PushBack(TObject* pObject, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec,
1258 void* pHeader, int headerSize)
1260 // see header file for function documentation
1261 ALIHLTCOMPONENT_BASE_STOPWATCH();
1262 AliHLTComponentDataType dt;
1263 SetDataType(dt, dtID, dtOrigin);
1264 return PushBack(pObject, dt, spec, pHeader, headerSize);
1267 int AliHLTComponent::PushBack(const void* pBuffer, int iSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
1268 const void* pHeader, int headerSize)
1270 // see header file for function documentation
1271 ALIHLTCOMPONENT_BASE_STOPWATCH();
1272 return InsertOutputBlock(pBuffer, iSize, dt, spec, pHeader, headerSize);
1275 int AliHLTComponent::PushBack(const void* pBuffer, int iSize, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec,
1276 const void* pHeader, int headerSize)
1278 // see header file for function documentation
1279 ALIHLTCOMPONENT_BASE_STOPWATCH();
1280 AliHLTComponentDataType dt;
1281 SetDataType(dt, dtID, dtOrigin);
1282 return PushBack(pBuffer, iSize, dt, spec, pHeader, headerSize);
1285 int AliHLTComponent::InsertOutputBlock(const void* pBuffer, int iBufferSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
1286 const void* pHeader, int iHeaderSize)
1288 // see header file for function documentation
1290 int iBlkSize = iBufferSize + iHeaderSize;
1292 if ((pBuffer!=NULL && iBufferSize>0) || (pHeader!=NULL && iHeaderSize>0)) {
1293 if (fpOutputBuffer && iBlkSize<=(int)(fOutputBufferSize-fOutputBufferFilled)) {
1294 AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled;
1296 // copy header if provided but skip if the header is the target location
1297 // in that case it has already been copied
1298 if (pHeader!=NULL && pHeader!=pTgt) {
1299 memcpy(pTgt, pHeader, iHeaderSize);
1302 pTgt += (AliHLTUInt8_t) iHeaderSize;
1304 // copy buffer if provided but skip if buffer is the target location
1305 // in that case it has already been copied
1306 if (pBuffer!=NULL && pBuffer!=pTgt) {
1307 memcpy(pTgt, pBuffer, iBufferSize);
1309 //AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)pBuffer);
1310 //HLTDebug("copy %d bytes from %p to output buffer %p, first word %#x", iBufferSize, pBuffer, pTgt, firstWord);
1312 //HLTDebug("buffer inserted to output: size %d data type %s spec %#x", iBlkSize, DataType2Text(dt).c_str(), spec);
1314 if (fpOutputBuffer) {
1315 HLTError("too little space in output buffer: %d of %d, required %d", fOutputBufferSize-fOutputBufferFilled, fOutputBufferSize, iBlkSize);
1317 HLTError("output buffer not available");
1323 AliHLTComponentBlockData bd;
1324 FillBlockData( bd );
1325 bd.fOffset = fOutputBufferFilled;
1326 bd.fSize = iBlkSize;
1328 bd.fSpecification = spec;
1329 fOutputBlocks.push_back( bd );
1330 fOutputBufferFilled+=bd.fSize;
1336 int AliHLTComponent::EstimateObjectSize(TObject* pObject) const
1338 // see header file for function documentation
1339 if (!pObject) return -EINVAL;
1340 AliHLTMessage msg(kMESS_OBJECT);
1341 msg.WriteObject(pObject);
1342 return msg.Length();
1345 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(int capacity, const char* dtID,
1346 const char* dtOrigin,
1347 AliHLTUInt32_t spec)
1349 // see header file for function documentation
1350 ALIHLTCOMPONENT_BASE_STOPWATCH();
1351 AliHLTComponentDataType dt;
1352 SetDataType(dt, dtID, dtOrigin);
1353 return CreateMemoryFile(capacity, dt, spec);
1356 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(int capacity,
1357 const AliHLTComponentDataType& dt,
1358 AliHLTUInt32_t spec)
1360 // see header file for function documentation
1361 ALIHLTCOMPONENT_BASE_STOPWATCH();
1362 AliHLTMemoryFile* pFile=NULL;
1363 if (capacity>=0 && static_cast<unsigned int>(capacity)<=fOutputBufferSize-fOutputBufferFilled){
1364 AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled;
1365 pFile=new AliHLTMemoryFile((char*)pTgt, capacity);
1367 unsigned int nofBlocks=fOutputBlocks.size();
1368 if (nofBlocks+1>fMemFiles.size()) {
1369 fMemFiles.resize(nofBlocks+1, NULL);
1371 if (nofBlocks<fMemFiles.size()) {
1372 fMemFiles[nofBlocks]=pFile;
1373 AliHLTComponentBlockData bd;
1374 FillBlockData( bd );
1375 bd.fOffset = fOutputBufferFilled;
1376 bd.fSize = capacity;
1378 bd.fSpecification = spec;
1379 fOutputBufferFilled+=bd.fSize;
1380 fOutputBlocks.push_back( bd );
1382 HLTError("can not allocate/grow object array");
1383 pFile->CloseMemoryFile(0);
1389 HLTError("can not create memory file of size %d (%d available)", capacity, fOutputBufferSize-fOutputBufferFilled);
1394 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(const char* dtID,
1395 const char* dtOrigin,
1396 AliHLTUInt32_t spec,
1399 // see header file for function documentation
1400 ALIHLTCOMPONENT_BASE_STOPWATCH();
1401 AliHLTComponentDataType dt;
1402 SetDataType(dt, dtID, dtOrigin);
1403 int size=fOutputBufferSize-fOutputBufferFilled;
1404 if (capacity<0 || capacity>1.0) {
1405 HLTError("invalid parameter: capacity %f", capacity);
1408 size=(int)(size*capacity);
1409 return CreateMemoryFile(size, dt, spec);
1412 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(const AliHLTComponentDataType& dt,
1413 AliHLTUInt32_t spec,
1416 // see header file for function documentation
1417 ALIHLTCOMPONENT_BASE_STOPWATCH();
1418 int size=fOutputBufferSize-fOutputBufferFilled;
1419 if (capacity<0 || capacity>1.0) {
1420 HLTError("invalid parameter: capacity %f", capacity);
1423 size=(int)(size*capacity);
1424 return CreateMemoryFile(size, dt, spec);
1427 int AliHLTComponent::Write(AliHLTMemoryFile* pFile, const TObject* pObject,
1428 const char* key, int option)
1430 // see header file for function documentation
1432 if (pFile && pObject) {
1434 iResult=pObject->Write(key, option);
1438 iResult=-pFile->GetErrno();
1439 if (iResult==-ENOSPC) {
1440 HLTError("error writing memory file, buffer too small");
1449 int AliHLTComponent::CloseMemoryFile(AliHLTMemoryFile* pFile)
1451 // see header file for function documentation
1454 AliHLTMemoryFilePList::iterator element=fMemFiles.begin();
1456 while (element!=fMemFiles.end() && iResult>=0) {
1457 if (*element && *element==pFile) {
1458 iResult=pFile->CloseMemoryFile();
1460 // sync memory files and descriptors
1462 fOutputBlocks[i].fSize=(*element)->GetSize()+(*element)->GetHeaderSize();
1470 HLTError("can not find memory file %p", pFile);
1478 int AliHLTComponent::CreateEventDoneData(AliHLTComponentEventDoneData edd)
1480 // see header file for function documentation
1483 AliHLTComponentEventDoneData* newEDD = NULL;
1485 unsigned long newSize=edd.fDataSize;
1487 newSize += fEventDoneData->fDataSize;
1489 if (newSize>fEventDoneDataSize) {
1490 newEDD = reinterpret_cast<AliHLTComponentEventDoneData*>( new AliHLTUInt8_t[ sizeof(AliHLTComponentEventDoneData)+newSize ] );
1493 newEDD->fStructSize = sizeof(AliHLTComponentEventDoneData);
1494 newEDD->fDataSize = newSize;
1495 newEDD->fData = reinterpret_cast<AliHLTUInt8_t*>(newEDD)+newEDD->fStructSize;
1496 unsigned long long offset = 0;
1497 if (fEventDoneData) {
1498 memcpy( newEDD->fData, fEventDoneData->fData, fEventDoneData->fDataSize );
1499 offset += fEventDoneData->fDataSize;
1501 memcpy( reinterpret_cast<AliHLTUInt8_t*>(newEDD->fData)+offset, edd.fData, edd.fDataSize );
1503 delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
1504 fEventDoneData = newEDD;
1505 fEventDoneDataSize = newSize;
1508 memcpy( reinterpret_cast<AliHLTUInt8_t*>(fEventDoneData->fData)+fEventDoneData->fDataSize, edd.fData, edd.fDataSize );
1509 fEventDoneData->fDataSize += edd.fDataSize;
1514 int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
1515 const AliHLTComponentBlockData* blocks,
1516 AliHLTComponentTriggerData& trigData,
1517 AliHLTUInt8_t* outputPtr,
1518 AliHLTUInt32_t& size,
1519 AliHLTUInt32_t& outputBlockCnt,
1520 AliHLTComponentBlockData*& outputBlocks,
1521 AliHLTComponentEventDoneData*& edd )
1523 // see header file for function documentation
1524 HLTLogKeyword(fChainId.c_str());
1525 ALIHLTCOMPONENT_BASE_STOPWATCH();
1527 fCurrentEvent=evtData.fEventID;
1528 fCurrentEventData=evtData;
1529 fpInputBlocks=blocks;
1530 fCurrentInputBlock=-1;
1531 fSearchDataType=kAliHLTAnyDataType;
1532 fpOutputBuffer=outputPtr;
1533 fOutputBufferSize=size;
1534 fOutputBufferFilled=0;
1535 fOutputBlocks.clear();
1539 AliHLTComponentBlockDataList forwardedBlocks;
1541 // optional component statistics
1542 AliHLTComponentStatisticsList compStats;
1543 bool bAddComponentTableEntry=false;
1544 vector<AliHLTUInt32_t> parentComponentTables;
1545 #if defined(__DEBUG) || defined(HLT_COMPONENT_STATISTICS)
1546 AliHLTComponentStatistics outputStat;
1547 memset(&outputStat, 0, sizeof(AliHLTComponentStatistics));
1548 outputStat.fStructSize=sizeof(AliHLTComponentStatistics);
1549 outputStat.fId=fChainIdCrc;
1551 fpBenchmark->Stop();
1552 outputStat.fComponentCycleTime=(AliHLTUInt32_t)(fpBenchmark->RealTime()*ALIHLTCOMPONENT_STATTIME_SCALER);
1553 fpBenchmark->Reset();
1554 fpBenchmark->Start();
1556 compStats.push_back(outputStat);
1559 // data processing is skipped
1560 // - if there are only steering events in the block list.
1561 // For the sake of data source components data processing
1562 // is not skipped if there is no block list at all or if it
1563 // just contains the eventType block
1564 // - always skipped if the event is of type
1565 // - gkAliEventTypeConfiguration
1566 // - gkAliEventTypeReadPreprocessor
1567 const unsigned int skipModeDefault=0x1;
1568 const unsigned int skipModeForce=0x2;
1569 unsigned int bSkipDataProcessing=skipModeDefault;
1571 // find special events
1572 if (fpInputBlocks && evtData.fBlockCnt>0) {
1573 // first look for all special events and execute in the appropriate
1574 // sequence afterwords
1575 int indexComConfEvent=-1;
1576 int indexUpdtDCSEvent=-1;
1577 int indexSOREvent=-1;
1578 int indexEOREvent=-1;
1579 int indexECSParamBlock=-1;
1580 for (unsigned int i=0; i<evtData.fBlockCnt && iResult>=0; i++) {
1581 if (fpInputBlocks[i].fDataType==kAliHLTDataTypeSOR) {
1583 // the AliHLTCalibrationProcessor relies on the SOR and EOR events
1584 bSkipDataProcessing&=~skipModeDefault;
1585 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeRunType) {
1587 // handling is not clear yet
1588 if (fpInputBlocks[i].fPtr) {
1589 HLTDebug("got run type \"%s\"\n", fpInputBlocks[i].fPtr);
1591 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeEOR) {
1593 // the calibration processor relies on the SOR and EOR events
1594 bSkipDataProcessing&=~skipModeDefault;
1595 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeDDL) {
1597 // this event is most likely deprecated
1598 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComConf) {
1599 indexComConfEvent=i;
1600 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeUpdtDCS) {
1601 indexUpdtDCSEvent=i;
1602 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeEvent) {
1603 fEventType=fpInputBlocks[i].fSpecification;
1605 // skip always in case of gkAliEventTypeConfiguration
1606 if (fpInputBlocks[i].fSpecification==gkAliEventTypeConfiguration) bSkipDataProcessing|=skipModeForce;
1608 // skip always in case of gkAliEventTypeReadPreprocessor
1609 if (fpInputBlocks[i].fSpecification==gkAliEventTypeReadPreprocessor) bSkipDataProcessing|=skipModeForce;
1611 // never skip if the event type block is the only block
1612 if (evtData.fBlockCnt==1) bSkipDataProcessing&=~skipModeDefault;
1614 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComponentStatistics) {
1615 if (compStats.size()>0) {
1616 AliHLTUInt8_t* pData=reinterpret_cast<AliHLTUInt8_t*>(fpInputBlocks[i].fPtr);
1617 for (AliHLTUInt32_t offset=0;
1618 offset+sizeof(AliHLTComponentStatistics)<=fpInputBlocks[i].fSize;
1619 offset+=sizeof(AliHLTComponentStatistics)) {
1620 AliHLTComponentStatistics* pStat=reinterpret_cast<AliHLTComponentStatistics*>(pData+offset);
1621 if (pStat && compStats[0].fLevel<=pStat->fLevel) {
1622 compStats[0].fLevel=pStat->fLevel+1;
1624 compStats.push_back(*pStat);
1627 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComponentTable) {
1628 forwardedBlocks.push_back(fpInputBlocks[i]);
1629 parentComponentTables.push_back(fpInputBlocks[i].fSpecification);
1630 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeECSParam) {
1631 indexECSParamBlock=i;
1633 // the processing function is called if there is at least one
1634 // non-steering data block. Steering blocks are not filtered out
1635 // for sake of performance
1636 bSkipDataProcessing&=~skipModeDefault;
1637 if (compStats.size()>0) {
1638 compStats[0].fInputBlockCount++;
1639 compStats[0].fTotalInputSize+=fpInputBlocks[i].fSize;
1644 if (indexSOREvent>=0) {
1646 bAddComponentTableEntry=true;
1647 if (fpRunDesc==NULL) {
1648 fpRunDesc=new AliHLTRunDesc;
1649 if (fpRunDesc) *fpRunDesc=kAliHLTVoidRunDesc;
1652 AliHLTRunDesc rundesc;
1653 if ((iResult=CopyStruct(&rundesc, sizeof(AliHLTRunDesc), indexSOREvent, "AliHLTRunDesc", "SOR"))>0) {
1654 if (fpRunDesc->fRunNo==kAliHLTVoidRunNo) {
1656 HLTDebug("set run decriptor, run no %d", fpRunDesc->fRunNo);
1657 SetCDBRunNo(fpRunDesc->fRunNo);
1658 } else if (fpRunDesc->fRunNo!=rundesc.fRunNo) {
1659 HLTWarning("already set run properties run no %d, ignoring SOR with run no %d", fpRunDesc->fRunNo, rundesc.fRunNo);
1666 if (indexECSParamBlock>=0) {
1667 if (fpInputBlocks[indexECSParamBlock].fSize>0) {
1668 const char* param=reinterpret_cast<const char*>(fpInputBlocks[indexECSParamBlock].fPtr);
1669 TString paramString;
1670 if (param[fpInputBlocks[indexECSParamBlock].fSize-1]!=0) {
1671 HLTWarning("ECS parameter string not terminated");
1672 paramString.Insert(0, param, fpInputBlocks[indexECSParamBlock].fSize);
1677 ScanECSParam(paramString.Data());
1679 HLTWarning("empty ECS parameter received");
1682 // TODO: later on we might throw a warning here since the CTP trigger classes
1683 // should be mandatory
1686 if (indexEOREvent>=0) {
1687 bAddComponentTableEntry=true;
1688 if (fpRunDesc!=NULL) {
1690 AliHLTRunDesc rundesc;
1691 if ((iResult=CopyStruct(&rundesc, sizeof(AliHLTRunDesc), indexEOREvent, "AliHLTRunDesc", "SOR"))>0) {
1692 if (fpRunDesc->fRunNo!=rundesc.fRunNo) {
1693 HLTWarning("run no mismatch: SOR %d, EOR %d", fpRunDesc->fRunNo, rundesc.fRunNo);
1695 HLTDebug("EOR run no %d", fpRunDesc->fRunNo);
1698 AliHLTRunDesc* pRunDesc=fpRunDesc;
1703 HLTWarning("did not receive SOR, ignoring EOR");
1706 if (indexComConfEvent>=0 || fEventType==gkAliEventTypeConfiguration) {
1708 if (indexComConfEvent>=0 && fpInputBlocks[indexComConfEvent].fPtr!=NULL && fpInputBlocks[indexComConfEvent].fSize>0) {
1709 cdbEntry.Append(reinterpret_cast<const char*>(fpInputBlocks[indexComConfEvent].fPtr), fpInputBlocks[indexComConfEvent].fSize);
1711 HLTDebug("received component configuration command: entry %s", cdbEntry.IsNull()?"none":cdbEntry.Data());
1712 int tmpResult=Reconfigure(cdbEntry[0]==0?NULL:cdbEntry.Data(), fChainId.c_str());
1714 HLTWarning("reconfiguration of component %p (%s) failed with error code %d", this, GetComponentID(), tmpResult);
1717 if (indexUpdtDCSEvent>=0 || fEventType==gkAliEventTypeReadPreprocessor) {
1719 if (fpInputBlocks[indexUpdtDCSEvent].fPtr!=NULL && fpInputBlocks[indexUpdtDCSEvent].fSize>0) {
1720 modules.Append(reinterpret_cast<const char*>(fpInputBlocks[indexUpdtDCSEvent].fPtr), fpInputBlocks[indexUpdtDCSEvent].fSize);
1722 HLTDebug("received preprocessor update command: detectors %s", modules.IsNull()?"ALL":modules.Data());
1723 int tmpResult=ReadPreprocessorValues(modules[0]==0?"ALL":modules.Data());
1725 HLTWarning("preprocessor update of component %p (%s) failed with error code %d", this, GetComponentID(), tmpResult);
1729 // processing function needs to be called if there are no input data
1730 // blocks in order to make data source components working.
1731 bSkipDataProcessing&=~skipModeDefault;
1734 // data processing is not skipped if the component explicitly asks
1735 // for the private blocks
1736 if (fRequireSteeringBlocks) bSkipDataProcessing=0;
1738 // increment CTP trigger counters if available
1739 if (fpCTPData && IsDataEvent()) fpCTPData->Increment(trigData);
1741 AliHLTComponentBlockDataList blockData;
1742 if (iResult>=0 && !bSkipDataProcessing)
1743 { // dont delete, sets the scope for the stopwatch guard
1744 // do not use ALIHLTCOMPONENT_DA_STOPWATCH(); macro
1745 // in order to avoid 'shadowed variable' warning
1746 AliHLTStopwatchGuard swguard2(fpStopwatches!=NULL?reinterpret_cast<TStopwatch*>(fpStopwatches->At((int)kSWDA)):NULL);
1747 iResult=DoProcessing(evtData, blocks, trigData, outputPtr, size, blockData, edd);
1748 } // end of the scope of the stopwatch guard
1749 if (iResult>=0 && !bSkipDataProcessing) {
1750 if (fOutputBlocks.size()>0) {
1751 // High Level interface
1753 //HLTDebug("got %d block(s) via high level interface", fOutputBlocks.size());
1754 // sync memory files and descriptors
1755 AliHLTMemoryFilePList::iterator element=fMemFiles.begin();
1757 while (element!=fMemFiles.end() && iResult>=0) {
1759 if ((*element)->IsClosed()==0) {
1760 HLTWarning("memory file has not been closed, force flush");
1761 iResult=CloseMemoryFile(*element);
1768 // create the descriptor list
1769 if (blockData.size()>0) {
1770 HLTError("low level and high interface must not be mixed; use PushBack methods to insert data blocks");
1773 if (compStats.size()>0 && IsDataEvent()) {
1774 int offset=AddComponentStatistics(fOutputBlocks, fpOutputBuffer, fOutputBufferSize, fOutputBufferFilled, compStats);
1775 if (offset>0) fOutputBufferFilled+=offset;
1777 if (bAddComponentTableEntry) {
1778 int offset=AddComponentTableEntry(fOutputBlocks, fpOutputBuffer, fOutputBufferSize, fOutputBufferFilled, parentComponentTables);
1779 if (offset>0) size+=offset;
1781 if (forwardedBlocks.size()>0) {
1782 fOutputBlocks.insert(fOutputBlocks.end(), forwardedBlocks.begin(), forwardedBlocks.end());
1784 iResult=MakeOutputDataBlockList(fOutputBlocks, &outputBlockCnt, &outputBlocks);
1785 size=fOutputBufferFilled;
1789 // Low Level interface
1790 if (compStats.size()>0) {
1791 int offset=AddComponentStatistics(blockData, fpOutputBuffer, fOutputBufferSize, size, compStats);
1792 if (offset>0) size+=offset;
1794 if (bAddComponentTableEntry) {
1795 int offset=AddComponentTableEntry(blockData, fpOutputBuffer, fOutputBufferSize, size, parentComponentTables);
1796 if (offset>0) size+=offset;
1798 if (forwardedBlocks.size()>0) {
1799 blockData.insert(blockData.end(), forwardedBlocks.begin(), forwardedBlocks.end());
1801 iResult=MakeOutputDataBlockList(blockData, &outputBlockCnt, &outputBlocks);
1804 HLTFatal("component %s (%p): can not convert output block descriptor list", GetComponentID(), this);
1807 if (iResult<0 || bSkipDataProcessing) {
1811 CleanupInputObjects();
1812 if (iResult>=0 && IsDataEvent()) {
1813 IncrementEventCounter();
1815 if (outputBlockCnt==0) {
1816 // no output blocks, set size to 0
1820 // reset the internal EventData struct
1821 FillEventData(fCurrentEventData);
1825 int AliHLTComponent::AddComponentStatistics(AliHLTComponentBlockDataList& blocks,
1826 AliHLTUInt8_t* buffer,
1827 AliHLTUInt32_t bufferSize,
1828 AliHLTUInt32_t offset,
1829 AliHLTComponentStatisticsList& stats) const
1831 // see header file for function documentation
1833 #if defined(__DEBUG) || defined(HLT_COMPONENT_STATISTICS)
1834 if (stats.size()==0) return -ENOENT;
1835 // check if there is space for at least one entry
1836 if (offset+sizeof(AliHLTComponentStatistics)>bufferSize) return 0;
1837 stats[0].fTotalOutputSize=offset;
1838 stats[0].fOutputBlockCount=blocks.size();
1840 fpBenchmark->Stop();
1841 stats[0].fTime=(AliHLTUInt32_t)(fpBenchmark->RealTime()*ALIHLTCOMPONENT_STATTIME_SCALER);
1842 stats[0].fCTime=(AliHLTUInt32_t)(fpBenchmark->CpuTime()*ALIHLTCOMPONENT_STATTIME_SCALER);
1843 fpBenchmark->Continue();
1845 if (offset+stats.size()*sizeof(AliHLTComponentStatistics)>bufferSize) {
1846 AliHLTUInt32_t removedLevel=0;
1848 // remove all entries of the level of the last entry
1849 removedLevel=stats.back().fLevel;
1850 AliHLTComponentStatisticsList::iterator element=stats.begin();
1852 while (element!=stats.end()) {
1853 if (element->fLevel<=removedLevel) {
1854 element=stats.erase(element);
1859 } while (stats.size()>1 &&
1860 (offset+stats.size()*sizeof(AliHLTComponentStatistics)>bufferSize));
1862 assert(stats.size()>0);
1863 if (stats.size()==0) return 0;
1865 if (offset+stats.size()*sizeof(AliHLTComponentStatistics)<=bufferSize) {
1866 AliHLTComponentBlockData bd;
1867 FillBlockData( bd );
1868 bd.fOffset = offset;
1869 bd.fSize = stats.size()*sizeof(AliHLTComponentStatistics);
1870 bd.fDataType = kAliHLTDataTypeComponentStatistics;
1871 bd.fSpecification = kAliHLTVoidDataSpec;
1872 unsigned int master=0;
1873 for (unsigned int i=1; i<blocks.size(); i++) {
1874 if (blocks[i].fSize>blocks[master].fSize &&
1875 !MatchExactly(blocks[i].fDataType, kAliHLTVoidDataType|kAliHLTDataOriginPrivate))
1878 if (blocks.size()>0 && !MatchExactly(blocks[master].fDataType, kAliHLTVoidDataType|kAliHLTDataOriginPrivate)) {
1879 // take the data origin of the biggest block as specification
1880 // this is similar to the treatment in the HOMER interface. For traditional
1881 // reasons, the bytes are swapped there on a little endian architecture, so
1882 // we do it as well.
1883 memcpy(&bd.fSpecification, &blocks[master].fDataType.fOrigin, sizeof(bd.fSpecification));
1884 #ifdef R__BYTESWAP // set on little endian architectures
1885 bd.fSpecification=((bd.fSpecification & 0xFFULL) << 24) |
1886 ((bd.fSpecification & 0xFF00ULL) << 8) |
1887 ((bd.fSpecification & 0xFF0000ULL) >> 8) |
1888 ((bd.fSpecification & 0xFF000000ULL) >> 24);
1891 memcpy(buffer+offset, &(stats[0]), bd.fSize);
1892 blocks.push_back(bd);
1896 if (blocks.size() && buffer && bufferSize && offset && stats.size()) {
1897 // get rid of warning
1903 int AliHLTComponent::AddComponentTableEntry(AliHLTComponentBlockDataList& blocks,
1904 AliHLTUInt8_t* buffer,
1905 AliHLTUInt32_t bufferSize,
1906 AliHLTUInt32_t offset,
1907 const vector<AliHLTUInt32_t>& parents) const
1909 // see header file for function documentation
1911 #if defined(__DEBUG) || defined(HLT_COMPONENT_STATISTICS)
1912 // the payload consists of the AliHLTComponentTableEntry struct,
1913 // followed by a an array of 32bit crc chain ids and the component
1914 // description string
1915 unsigned int payloadSize=sizeof(AliHLTComponentTableEntry);
1916 payloadSize+=parents.size()*sizeof(AliHLTUInt32_t);
1918 // the component description has the following format:
1919 // chain-id{component-id:arguments}
1920 const char* componentId=const_cast<AliHLTComponent*>(this)->GetComponentID();
1921 unsigned int descriptionSize=fChainId.size()+1;
1922 descriptionSize+=2; // the '{}' around the component id
1923 descriptionSize+=strlen(componentId);
1924 descriptionSize+=1; // the ':' between component id and arguments
1925 descriptionSize+=fComponentArgs.size();
1927 payloadSize+=descriptionSize;
1928 if (buffer && (offset+payloadSize<=bufferSize)) {
1929 AliHLTUInt8_t* pTgt=buffer+offset;
1930 memset(pTgt, 0, payloadSize);
1933 AliHLTComponentTableEntry* pEntry=reinterpret_cast<AliHLTComponentTableEntry*>(pTgt);
1934 pEntry->fStructSize=sizeof(AliHLTComponentTableEntry);
1935 pEntry->fNofParents=parents.size();
1936 pEntry->fSizeDescription=descriptionSize;
1937 pTgt=pEntry->fBuffer;
1939 // write array of parents
1940 if (parents.size()>0) {
1941 unsigned int copy=parents.size()*sizeof(vector<AliHLTUInt32_t>::value_type);
1942 memcpy(pTgt, &parents[0], parents.size()*sizeof(vector<AliHLTUInt32_t>::value_type));
1946 // write component description
1947 memcpy(pTgt, fChainId.c_str(), fChainId.size());
1948 pTgt+=fChainId.size();
1950 memcpy(pTgt, componentId, strlen(componentId));
1951 pTgt+=strlen(componentId);
1953 memcpy(pTgt, fComponentArgs.c_str(), fComponentArgs.size());
1954 pTgt+=fComponentArgs.size();
1958 AliHLTComponentBlockData bd;
1959 FillBlockData( bd );
1960 bd.fOffset = offset;
1961 bd.fSize = payloadSize;
1962 bd.fDataType = kAliHLTDataTypeComponentTable;
1963 bd.fSpecification = fChainIdCrc;
1964 blocks.push_back(bd);
1968 if (blocks.size() && buffer && bufferSize && offset && parents.size()) {
1969 // get rid of warning
1975 AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard()
1980 // standard constructor (not for use)
1983 AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(TStopwatch* pStopwatch)
1985 fpStopwatch(pStopwatch),
1990 // check for already existing guard
1991 if (fgpCurrent) fpPrec=fgpCurrent;
1994 // stop the preceeding guard if it controls a different stopwatch
1996 if (fpPrec && fpPrec!=this) bStart=fpPrec->Hold(fpStopwatch);
1998 // start the stopwatch if the current guard controls a different one
1999 if (fpStopwatch && bStart==1) fpStopwatch->Start(kFALSE);
2002 AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(const AliHLTStopwatchGuard&)
2008 // copy constructor not for use
2012 AliHLTComponent::AliHLTStopwatchGuard& AliHLTComponent::AliHLTStopwatchGuard::operator=(const AliHLTStopwatchGuard&)
2015 // assignment operator not for use
2022 AliHLTComponent::AliHLTStopwatchGuard* AliHLTComponent::AliHLTStopwatchGuard::fgpCurrent=NULL;
2024 AliHLTComponent::AliHLTStopwatchGuard::~AliHLTStopwatchGuard()
2028 // resume the preceeding guard if it controls a different stopwatch
2030 if (fpPrec && fpPrec!=this) bStop=fpPrec->Resume(fpStopwatch);
2032 // stop the stopwatch if the current guard controls a different one
2033 if (fpStopwatch && bStop==1) fpStopwatch->Stop();
2035 // resume to the preceeding guard
2039 int AliHLTComponent::AliHLTStopwatchGuard::Hold(TStopwatch* pSucc)
2041 // see header file for function documentation
2042 if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Stop();
2043 return fpStopwatch!=pSucc?1:0;
2046 int AliHLTComponent::AliHLTStopwatchGuard::Resume(TStopwatch* pSucc)
2048 // see header file for function documentation
2049 if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Start(kFALSE);
2050 return fpStopwatch!=pSucc?1:0;
2053 int AliHLTComponent::SetStopwatch(TObject* pSW, AliHLTStopwatchType type)
2055 // see header file for function documentation
2057 if (pSW!=NULL && type<kSWTypeCount) {
2058 if (fpStopwatches) {
2059 TObject* pObj=fpStopwatches->At((int)type);
2060 if (pSW==NULL // explicit reset
2061 || pObj==NULL) { // explicit set
2062 fpStopwatches->AddAt(pSW, (int)type);
2063 } else if (pObj!=pSW) {
2064 HLTWarning("stopwatch %d already set, reset first", (int)type);
2074 int AliHLTComponent::SetStopwatches(TObjArray* pStopwatches)
2076 // see header file for function documentation
2077 if (pStopwatches==NULL) return -EINVAL;
2080 for (int i=0 ; i<(int)kSWTypeCount && pStopwatches->GetEntries(); i++)
2081 SetStopwatch(pStopwatches->At(i), (AliHLTStopwatchType)i);
2085 AliHLTUInt32_t AliHLTComponent::GetRunNo() const
2087 // see header file for function documentation
2088 if (fpRunDesc==NULL) return kAliHLTVoidRunNo;
2089 return fpRunDesc->fRunNo;
2092 AliHLTUInt32_t AliHLTComponent::GetRunType() const
2094 // see header file for function documentation
2095 if (fpRunDesc==NULL) return kAliHLTVoidRunType;
2096 return fpRunDesc->fRunType;
2099 AliHLTUInt32_t AliHLTComponent::GetTimeStamp() const
2101 // see header file for function documentation
2102 return fCurrentEventData.fEventCreation_s>0? fCurrentEventData.fEventCreation_s:1;
2105 AliHLTUInt32_t AliHLTComponent::GetPeriodNumber() const
2107 // see header file for function documentation
2108 return (GetEventId()>>36)&0xfffffff;
2111 AliHLTUInt32_t AliHLTComponent::GetOrbitNumber() const
2113 // see header file for function documentation
2114 return (GetEventId()>>12)&0xffffff;
2117 AliHLTUInt16_t AliHLTComponent::GetBunchCrossNumber() const
2119 // see header file for function documentation
2120 return GetEventId()&0xfff;
2123 bool AliHLTComponent::IsDataEvent(AliHLTUInt32_t* pTgt)
2125 // see header file for function documentation
2126 if (pTgt) *pTgt=fEventType;
2127 return (fEventType==gkAliEventTypeData ||
2128 fEventType==gkAliEventTypeDataReplay ||
2129 fEventType==gkAliEventTypeCalibration);
2132 int AliHLTComponent::CopyStruct(void* pStruct, unsigned int iStructSize, unsigned int iBlockNo,
2133 const char* structname, const char* eventname)
2135 // see header file for function documentation
2137 if (pStruct!=NULL && iStructSize>sizeof(AliHLTUInt32_t)) {
2138 if (fpInputBlocks!=NULL && iBlockNo<fCurrentEventData.fBlockCnt) {
2139 AliHLTUInt32_t* pTgt=(AliHLTUInt32_t*)pStruct;
2140 if (fpInputBlocks[iBlockNo].fPtr && fpInputBlocks[iBlockNo].fSize) {
2141 AliHLTUInt32_t copy=*((AliHLTUInt32_t*)fpInputBlocks[iBlockNo].fPtr);
2142 if (fpInputBlocks[iBlockNo].fSize!=copy) {
2143 HLTWarning("%s event: mismatch of block size (%d) and structure size (%d)", eventname, fpInputBlocks[iBlockNo].fSize, copy);
2144 if (copy>fpInputBlocks[iBlockNo].fSize) copy=fpInputBlocks[iBlockNo].fSize;
2146 if (copy!=iStructSize) {
2147 HLTWarning("%s event: mismatch in %s version (data type version %d)", eventname, structname, ALIHLT_DATA_TYPES_VERSION);
2148 if (copy>iStructSize) {
2151 memset(pTgt, 0, iStructSize);
2154 memcpy(pTgt, fpInputBlocks[iBlockNo].fPtr, copy);
2158 HLTWarning("%s event: missing data block", eventname);
2164 HLTError("invalid struct");
2170 void AliHLTComponent::SetDDLBit(AliHLTEventDDL &list, Int_t ddlId, Bool_t state ) const
2172 // see header file for function documentation
2174 // -- Detector offset
2175 Int_t ddlIdBase = TMath::FloorNint( (Double_t) ddlId / 256.0 );
2177 // -- Word Base = 1. word of detector ( TPC has 8 words, TOF 3 )
2180 if ( ddlIdBase <= 3 )
2181 wordBase = ddlIdBase;
2182 else if ( ddlIdBase > 3 && ddlIdBase < 5 )
2183 wordBase = ddlIdBase + 7;
2185 wordBase = ddlIdBase + 9;
2187 // -- Bit index in Word
2188 Int_t bitIdx = ddlId % 32;
2191 Int_t wordIdx = wordBase;
2193 // -- if TPC (3) or TOD (5) add word idx
2194 if ( ( ddlIdBase == 3 ) || ( ddlIdBase == 5 ) ) {
2195 wordIdx += TMath::FloorNint( (Double_t) ( ddlId - ( ddlIdBase * 256 ) ) / 32.0 );
2198 // -- Set -- 'OR' word with bit mask;
2200 list.fList[wordIdx] |= ( 0x00000001 << bitIdx );
2201 // -- Unset -- 'AND' word with bit mask;
2203 list.fList[wordIdx] &= ( 0xFFFFFFFF ^ ( 0x00000001 << bitIdx ) );
2206 Int_t AliHLTComponent::GetFirstUsedDDLWord(AliHLTEventDDL &list) const
2208 // see header file for function documentation
2212 for ( Int_t wordNdx = 0 ; wordNdx < gkAliHLTDDLListSize ; wordNdx++ ) {
2214 if ( list.fList[wordNdx] != 0 && iResult == -1 ) {
2215 // check for special cases TPC and TOF
2216 if ( wordNdx > 3 && wordNdx <= 10 ) {
2220 else if ( wordNdx > 12 && wordNdx <= 14 ) {
2227 else if ( list.fList[wordNdx] != 0 && iResult >= 0 ) {
2228 HLTError( "DDLIDs for minimum of TWO detectors ( %d, %d ) set, this function works only for ONE detector.", iResult, wordNdx );
2237 AliHLTUInt32_t AliHLTComponent::CalculateChecksum(const AliHLTUInt8_t* buffer, int size)
2239 // see header file for function documentation
2240 AliHLTUInt32_t remainder = 0;
2241 const AliHLTUInt8_t crcwidth=(8*sizeof(AliHLTUInt32_t));
2242 const AliHLTUInt32_t topbit=1 << (crcwidth-1);
2243 const AliHLTUInt32_t polynomial=0xD8; /* 11011 followed by 0's */
2246 // http://www.netrino.com/Embedded-Systems/How-To/CRC-Calculation-C-Code
2249 * Perform modulo-2 division, a byte at a time.
2251 for (int byte = 0; byte < size; ++byte)
2254 * Bring the next byte into the remainder.
2256 remainder ^= (buffer[byte] << (crcwidth - 8));
2259 * Perform modulo-2 division, a bit at a time.
2261 for (uint8_t bit = 8; bit > 0; --bit)
2264 * Try to divide the current data bit.
2266 if (remainder & topbit)
2268 remainder = (remainder << 1) ^ polynomial;
2272 remainder = (remainder << 1);
2278 * The final remainder is the CRC result.
2283 int AliHLTComponent::ExtractComponentTableEntry(const AliHLTUInt8_t* pBuffer, AliHLTUInt32_t size,
2284 string& retChainId, string& retCompId, string& retCompArgs,
2285 vector<AliHLTUInt32_t>& parents)
2287 // see header file for function documentation
2290 retCompArgs.clear();
2292 if (!pBuffer || size==0) return 0;
2294 const AliHLTComponentTableEntry* pEntry=reinterpret_cast<const AliHLTComponentTableEntry*>(pBuffer);
2295 if (size<8/* the initial size of the structure*/ ||
2296 pEntry==NULL || pEntry->fStructSize<8) return -ENOMSG;
2297 const AliHLTUInt32_t* pParents=reinterpret_cast<const AliHLTUInt32_t*>(pEntry->fBuffer);
2298 const AliHLTUInt8_t* pEnd=pBuffer+size;
2300 if (pParents+pEntry->fNofParents>=reinterpret_cast<const AliHLTUInt32_t*>(pEnd)) return -ENODEV;
2301 for (unsigned int i=0; i<pEntry->fNofParents; i++, pParents++) {
2302 parents.push_back(*pParents);
2305 const char* pDescription=reinterpret_cast<const char*>(pParents);
2306 if (pDescription+pEntry->fSizeDescription>=reinterpret_cast<const char*>(pEnd) ||
2307 *(pDescription+pEntry->fSizeDescription)!=0) {
2311 TString descriptor=reinterpret_cast<const char*>(pDescription);
2315 TObjArray* pTokens=descriptor.Tokenize("{");
2318 if (pTokens->GetEntries()>n) {
2319 retChainId=((TObjString*)pTokens->At(n++))->GetString();
2321 if (pTokens->GetEntries()>n) {
2322 compId=((TObjString*)pTokens->At(n++))->GetString();
2326 if (!compId.IsNull() && (pTokens=compId.Tokenize(":"))!=NULL) {
2328 if (pTokens->GetEntries()>n) {
2329 compId=((TObjString*)pTokens->At(n++))->GetString();
2331 if (pTokens->GetEntries()>n) {
2332 compArgs=((TObjString*)pTokens->At(n++))->GetString();
2336 compId.ReplaceAll("}", "");
2337 compArgs.ReplaceAll("}", "");
2340 retCompArgs=compArgs;
2342 if (retChainId.size()==0) return -ENODATA;
2347 int AliHLTComponent::LoggingVarargs(AliHLTComponentLogSeverity severity,
2348 const char* originClass, const char* originFunc,
2349 const char* file, int line, ... ) const
2351 // see header file for function documentation
2355 va_start(args, line);
2357 // logging function needs to be const in order to be called from const member functions
2358 // without problems. But at this point we face the problem with virtual members which
2359 // are not necessarily const.
2360 AliHLTComponent* nonconst=const_cast<AliHLTComponent*>(this);
2361 AliHLTLogging::SetLogString("%s (%s, %p): ",
2362 fChainId[0]!=0?fChainId.c_str():nonconst->GetComponentID(),
2363 nonconst->GetComponentID(), this);
2364 iResult=SendMessage(severity, originClass, originFunc, file, line, AliHLTLogging::BuildLogString(NULL, args, true /*append*/));
2370 int AliHLTComponent::ScanECSParam(const char* ecsParam)
2372 // see header file for function documentation
2374 // format of the parameter string from ECS
2375 // <command>;<parameterkey>=<parametervalue>;<parameterkey>=<parametervalue>;...
2376 // search for a subset of the parameterkeys
2378 TString string=ecsParam;
2379 TObjArray* parameter=string.Tokenize(";");
2381 for (int i=0; i<parameter->GetEntries(); i++) {
2382 TString entry=((TObjString*)parameter->At(i))->GetString();
2383 HLTDebug("scanning ECS entry: %s", entry.Data());
2384 TObjArray* entryParams=entry.Tokenize("=");
2386 if (entryParams->GetEntries()>1) {
2387 if ((((TObjString*)entryParams->At(0))->GetString()).CompareTo("CTP_TRIGGER_CLASS")==0) {
2388 int result=InitCTPTriggerClasses((((TObjString*)entryParams->At(1))->GetString()).Data());
2389 if (iResult>=0 && result<0) iResult=result;
2391 // TODO: scan the other parameters
2392 // e.g. consistency check of run number
2404 int AliHLTComponent::SetupCTPData()
2406 // see header file for function documentation
2407 if (fpCTPData) delete fpCTPData;
2408 fpCTPData=new AliHLTCTPData;
2409 if (!fpCTPData) return -ENOMEM;
2413 int AliHLTComponent::InitCTPTriggerClasses(const char* ctpString)
2415 // see header file for function documentation
2416 if (!fpCTPData) return 0; // silently accept as the component has to announce that it want's the CTP info
2417 return fpCTPData->InitCTPTriggerClasses(ctpString);
2420 bool AliHLTComponent::EvaluateCTPTriggerClass(const char* expression, AliHLTComponentTriggerData& trigData) const
2422 // see header file for function documentation
2424 static bool bWarningThrown=false;
2425 if (!bWarningThrown) HLTError("Trigger classes not initialized, use SetupCTPData from DoInit()");
2426 bWarningThrown=true;
2430 return fpCTPData->EvaluateCTPTriggerClass(expression, trigData);