From 9ce4bf4ada6a5aa008e6a94e062edaf819f66b8a Mon Sep 17 00:00:00 2001 From: richterm Date: Fri, 19 Jan 2007 14:15:46 +0000 Subject: [PATCH] - AliHLTFileWriter added - handling of standard components in libHLT added to ComponentHandler - several fixes in the HLT offline framework - dictionary generation fixed for AliHLTSample library in AliRoot build system --- HLT/BASE/AliHLTComponent.cxx | 62 +++++++-- HLT/BASE/AliHLTComponent.h | 27 +++- HLT/BASE/AliHLTComponentHandler.cxx | 57 ++++++-- HLT/BASE/AliHLTComponentHandler.h | 18 +++ HLT/BASE/AliHLTConfiguration.cxx | 92 +++++++++++-- HLT/BASE/AliHLTDataBuffer.cxx | 73 +++++++++-- HLT/BASE/AliHLTDataBuffer.h | 33 +++-- HLT/BASE/AliHLTDataSink.cxx | 11 ++ HLT/BASE/AliHLTDataSink.h | 12 ++ HLT/BASE/AliHLTDataSource.cxx | 6 +- HLT/BASE/AliHLTDataTypes.h | 3 + HLT/BASE/AliHLTFilePublisher.cxx | 33 +++-- HLT/BASE/AliHLTFilePublisher.h | 14 +- HLT/BASE/AliHLTFileWriter.cxx | 174 +++++++++++++++++++++++++ HLT/BASE/AliHLTFileWriter.h | 97 ++++++++++++++ HLT/BASE/AliHLTSystem.cxx | 110 +++++++++++----- HLT/BASE/AliHLTSystem.h | 30 ++++- HLT/BASE/AliHLTTask.h | 9 +- HLT/BASE/HLTbaseLinkDef.h | 1 + HLT/BASE/Makefile.am | 2 + HLT/ChangeLog | 4 + HLT/SampleLib/AliHLTDummyComponent.cxx | 17 ++- HLT/SampleLib/Makefile.am | 5 +- HLT/configure.ac | 11 +- HLT/libAliHLTSample.pkg | 2 +- HLT/libHLTbase.pkg | 6 +- 26 files changed, 777 insertions(+), 132 deletions(-) create mode 100644 HLT/BASE/AliHLTFileWriter.cxx create mode 100644 HLT/BASE/AliHLTFileWriter.h diff --git a/HLT/BASE/AliHLTComponent.cxx b/HLT/BASE/AliHLTComponent.cxx index 19d94fcf155..45b53cd5213 100644 --- a/HLT/BASE/AliHLTComponent.cxx +++ b/HLT/BASE/AliHLTComponent.cxx @@ -94,22 +94,37 @@ int AliHLTComponent::DoDeinit() return 0; } -void AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, char output[14] ) { -memset( output, 0, 14 ); -strncat( output, type.fOrigin, 4 ); -strcat( output, ":" ); -strncat( output, type.fID, 8 ); +void AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2] ) { + memset( output, 0, kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2 ); + strncat( output, type.fOrigin, kAliHLTComponentDataTypefOriginSize ); + strcat( output, ":" ); + strncat( output, type.fID, kAliHLTComponentDataTypefIDsize ); } +string AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type ) +{ + string out(""); + if (type==kAliHLTVoidDataType) { + out="VOID:VOID"; + } else { + out.append(type.fOrigin, kAliHLTComponentDataTypefOriginSize); + out.append(":"); + out.append(type.fID, kAliHLTComponentDataTypefIDsize); + } + return out; +} + + void* AliHLTComponent::AllocMemory( unsigned long size ) { if (fEnvironment.fAllocMemoryFunc) return (*fEnvironment.fAllocMemoryFunc)(fEnvironment.fParam, size ); + HLTFatal("no memory allocation handler registered"); return NULL; } int AliHLTComponent::MakeOutputDataBlockList( const vector& blocks, AliHLTUInt32_t* blockCount, AliHLTComponentBlockData** outputBlocks ) { - if ( !blockCount || !outputBlocks ) + if ( blockCount==NULL || outputBlocks==NULL ) return -EFAULT; AliHLTUInt32_t count = blocks.size(); if ( !count ) @@ -142,9 +157,11 @@ int AliHLTComponent::FindMatchingDataTypes(AliHLTComponent* pConsumer, vectorGetInputDataTypes(ctlist); vector::iterator type=ctlist.begin(); while (type!=ctlist.end() && iResult==0) { - if ((*type)==GetOutputDataType()) { + if ((*type)==GetOutputDataType() || + (*type)==kAliHLTAnyDataType) { if (tgtList) tgtList->push_back(*type); iResult++; + // this loop has to be changed in case of multiple output types break; } type++; @@ -172,9 +189,7 @@ void AliHLTComponent::FillShmData( AliHLTComponentShmData& shmData ) { } void AliHLTComponent::FillDataType( AliHLTComponentDataType& dataType ) { - dataType.fStructSize = sizeof(dataType); - memset( dataType.fID, '*', kAliHLTComponentDataTypefIDsize ); - memset( dataType.fOrigin, '*', kAliHLTComponentDataTypefOriginSize ); + dataType=kAliHLTVoidDataType; } void AliHLTComponent::CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt) { @@ -187,13 +202,36 @@ void AliHLTComponent::SetDataType(AliHLTComponentDataType& tgtdt, const char* id memset(&tgtdt.fID[0], 0, kAliHLTComponentDataTypefIDsize); memset(&tgtdt.fOrigin[0], 0, kAliHLTComponentDataTypefOriginSize); - if (strlen(id)>kAliHLTComponentDataTypefIDsize) { + if ((int)strlen(id)>kAliHLTComponentDataTypefIDsize) { HLTWarning("data type id %s is too long, truncated to %d", id, kAliHLTComponentDataTypefIDsize); } strncpy(&tgtdt.fID[0], id, kAliHLTComponentDataTypefIDsize); - if (strlen(origin)>kAliHLTComponentDataTypefOriginSize) { + if ((int)strlen(origin)>kAliHLTComponentDataTypefOriginSize) { HLTWarning("data type origin %s is too long, truncated to %d", origin, kAliHLTComponentDataTypefOriginSize); } strncpy(&tgtdt.fOrigin[0], origin, kAliHLTComponentDataTypefOriginSize); } + +void AliHLTComponent::FillEventData(AliHLTComponentEventData& evtData) +{ + memset(&evtData, 0, sizeof(AliHLTComponentEventData)); + evtData.fStructSize=sizeof(AliHLTComponentEventData); +} + +void AliHLTComponent::PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt) { + TString msg; + msg.Form("AliHLTComponentDataType(%d): ID=\"", dt.fStructSize); + for ( int i = 0; i < kAliHLTComponentDataTypefIDsize; i++ ) { + if (dt.fID[i]!=0) msg+=dt.fID[i]; + else msg+="\\0"; + } + msg+="\" Origin=\""; + for ( int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++ ) { + if (dt.fOrigin[i]!=0) msg+=dt.fOrigin[i]; + else msg+="\\0"; + } + msg+="\""; + HLTMessage(msg.Data()); +} + diff --git a/HLT/BASE/AliHLTComponent.h b/HLT/BASE/AliHLTComponent.h index 8b2316cfd38..710db3f8912 100644 --- a/HLT/BASE/AliHLTComponent.h +++ b/HLT/BASE/AliHLTComponent.h @@ -18,6 +18,7 @@ */ #include +#include #include "AliHLTLogging.h" #include "AliHLTDataTypes.h" #include "AliHLTDefinitions.h" @@ -45,9 +46,9 @@ class AliHLTComponentHandler; * The interface can be accessed from the online HLT framework or the AliRoot * offline analysis framework. * Components can be of type - * - @ref kSource: components which only produce data - * - @ref kProcessor: components which consume and produce data - * - @ref kSink: components which only consume data + * - @ref AliHLTComponent::kSource: components which only produce data + * - @ref AliHLTComponent::kProcessor: components which consume and produce data + * - @ref AliHLTComponent::kSink: components which only consume data * * where data production and consumption refer to the analysis data stream.
* @@ -185,6 +186,23 @@ class AliHLTComponent : public AliHLTLogging { */ static int UnsetGlobalComponentHandler(); + /** + * Helper function to convert the data type to a string. + */ + static string DataType2Text( const AliHLTComponentDataType& type ); + + /** + * helper function to initialize AliHLTComponentEventData structure + */ + static void FillEventData(AliHLTComponentEventData& evtData); + + /** + * Print info on an AliHLTComponentDataType structure + * This is just a helper function to examine an @ref AliHLTComponentDataType + * structur. + */ + void PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt); + protected: /** @@ -222,6 +240,7 @@ class AliHLTComponent : public AliHLTLogging { * chars of size @ref kAliHLTComponentDataTypefIDsize and * @ref kAliHLTComponentDataTypefOriginSize respectively and not necessarily with * a terminating zero. + * @param tgtdt target data type structure * @param id ID string * @param origin Origin string */ @@ -272,7 +291,7 @@ class AliHLTComponent : public AliHLTLogging { /** * Helper function to convert the data type to a string. */ - void DataType2Text( const AliHLTComponentDataType& type, char output[14] ); + void DataType2Text(const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2]); private: /** The global component handler instance */ diff --git a/HLT/BASE/AliHLTComponentHandler.cxx b/HLT/BASE/AliHLTComponentHandler.cxx index 3f060e2fcc8..8d3796444fd 100644 --- a/HLT/BASE/AliHLTComponentHandler.cxx +++ b/HLT/BASE/AliHLTComponentHandler.cxx @@ -37,6 +37,10 @@ using namespace std; #include "AliHLTDataTypes.h" #include "AliHLTSystem.h" +// the standard components +#include "AliHLTFilePublisher.h" +#include "AliHLTFileWriter.h" + /** ROOT macro for the implementation of ROOT specific class methods */ ClassImp(AliHLTComponentHandler) @@ -45,14 +49,17 @@ AliHLTComponentHandler::AliHLTComponentHandler() fComponentList(), fScheduleList(), fLibraryList(), - fEnvironment() + fEnvironment(), + fStandardList() { memset(&fEnvironment, 0, sizeof(AliHLTComponentEnvironment)); + AddStandardComponents(); } AliHLTComponentHandler::~AliHLTComponentHandler() { UnloadLibraries(); + DeleteStandardComponents(); } int AliHLTComponentHandler::AnnounceVersion() @@ -215,15 +222,7 @@ int AliHLTComponentHandler::LoadLibrary( const char* libraryPath ) if (hLib) { HLTInfo("library %s loaded", libraryPath); fLibraryList.push_back(hLib); - vector::iterator element=fScheduleList.begin(); - int iSize=fScheduleList.size(); - int iLocalResult=0; - while (iSize-- > 0) { - element=fScheduleList.begin(); - iLocalResult=RegisterComponent(*element); - if (iResult==0) iResult=iLocalResult; - fScheduleList.erase(element); - } + iResult=RegisterScheduledComponents(); } else { HLTError("can not load library %s", libraryPath); #ifdef HAVE_DLFCN_H @@ -268,3 +267,41 @@ int AliHLTComponentHandler::UnloadLibraries() } return iResult; } + +int AliHLTComponentHandler::AddStandardComponents() +{ + int iResult=0; + AliHLTComponent::SetGlobalComponentHandler(this); + fStandardList.push_back(new AliHLTFilePublisher); + fStandardList.push_back(new AliHLTFileWriter); + AliHLTComponent::UnsetGlobalComponentHandler(); + iResult=RegisterScheduledComponents(); + return iResult; +} + +int AliHLTComponentHandler::RegisterScheduledComponents() +{ + int iResult=0; + vector::iterator element=fScheduleList.begin(); + int iLocalResult=0; + while (element!=fScheduleList.end()) { + iLocalResult=RegisterComponent(*element); + if (iResult==0) iResult=iLocalResult; + fScheduleList.erase(element); + element=fScheduleList.begin(); + } + return iResult; +} + +int AliHLTComponentHandler::DeleteStandardComponents() +{ + int iResult=0; + vector::iterator element=fStandardList.begin(); + while (element!=fStandardList.end()) { + DeregisterComponent((*element)->GetComponentID()); + delete(*element); + fStandardList.erase(element); + element=fStandardList.begin(); + } + return iResult; +} diff --git a/HLT/BASE/AliHLTComponentHandler.h b/HLT/BASE/AliHLTComponentHandler.h index 2ba8d1639ea..1cdd33f41c0 100644 --- a/HLT/BASE/AliHLTComponentHandler.h +++ b/HLT/BASE/AliHLTComponentHandler.h @@ -88,6 +88,11 @@ class AliHLTComponentHandler : public AliHLTLogging { */ int RegisterComponent(AliHLTComponent* pSample ); + /** + * Registers all scheduled components. + */ + int RegisterScheduledComponents(); + /** * Deregister a component. * @param componentID ID of the component @@ -95,6 +100,17 @@ class AliHLTComponentHandler : public AliHLTLogging { */ int DeregisterComponent( const char* componentID ); + /** + * Add standard components + * The standard components are part of the libHLTbase library and + * need therefore a special handling. + */ + int AddStandardComponents(); + + /** + */ + int DeleteStandardComponents(); + /** * Find the ID of a component with the given output data. * @param dtype data type descriptor @@ -189,6 +205,8 @@ class AliHLTComponentHandler : public AliHLTLogging { vector fLibraryList; /** running environment for the component */ AliHLTComponentEnvironment fEnvironment; + /** list of standard components */ + vector fStandardList; ClassDef(AliHLTComponentHandler, 0); diff --git a/HLT/BASE/AliHLTConfiguration.cxx b/HLT/BASE/AliHLTConfiguration.cxx index 07ca303269e..0a8b9ba0c66 100644 --- a/HLT/BASE/AliHLTConfiguration.cxx +++ b/HLT/BASE/AliHLTConfiguration.cxx @@ -238,9 +238,19 @@ int AliHLTConfiguration::GetArguments(const char*** pArgv) { int iResult=0; if (pArgv) { + if (fArgc==-1) { + if ((iResult=ExtractArguments())<0) { + HLTError("error extracting arguments for configuration %s", GetName()); + fArgc=-EINVAL; + } + } else if (fArgc<0) { + HLTError("previous argument extraction failed"); + } + //HLTDebug("%s fArgc %d", GetName(), fArgc); iResult=fArgc; *pArgv=(const char**)fArgv; } else { + HLTError("invalid parameter"); iResult=-EINVAL; } return iResult; @@ -287,7 +297,7 @@ int AliHLTConfiguration::ExtractArguments() vector tgtList; if ((iResult=InterpreteString(fArguments, tgtList))>=0) { fArgc=tgtList.size(); - //HLTDebug("found %d arguments", fArgc); + //HLTDebug("configuration %s: extracted %d arguments from \"%s\"", GetName(), fArgc, fArguments); if (fArgc>0) { fArgv = new char*[fArgc]; if (fArgv) { @@ -303,6 +313,9 @@ int AliHLTConfiguration::ExtractArguments() } } } + } else { + // there are zero arguments + fArgc=0; } return iResult; } @@ -420,7 +433,7 @@ AliHLTTask::~AliHLTTask() int AliHLTTask::Init(AliHLTConfiguration* pConf, AliHLTComponentHandler* pCH) { int iResult=0; - if (fpConfiguration!=NULL && fpConfiguration!=pConf) { + if (fpConfiguration!=NULL && pConf!=NULL && fpConfiguration!=pConf) { HLTWarning("overriding existing reference to configuration object %p (%s) by %p", fpConfiguration, GetName(), pConf); } @@ -434,10 +447,13 @@ int AliHLTTask::Init(AliHLTConfiguration* pConf, AliHLTComponentHandler* pCH) // TODO: we have to think about the optional environment parameter, // currently just set to NULL. iResult=pCH->CreateComponent(fpConfiguration->GetComponentID(), NULL, argc, argv, fpComponent); - if (fpComponent) { + if (fpComponent || iResult<=0) { } else { - HLTError("can not find component \"%s\"", fpConfiguration->GetComponentID()); + HLTError("can not find component \"%s\" (%d)", fpConfiguration->GetComponentID(), iResult); } + } else { + HLTError("can not get argument list for configuration %s (%s)", fpConfiguration->GetName(), fpConfiguration->GetComponentID()); + iResult=-EINVAL; } } else { HLTError("component handler instance needed for task initialization"); @@ -661,6 +677,8 @@ int AliHLTTask::StartRun() //iResult=Init( AliHLTComponentEnvironment* environ, void* environ_param, int argc, const char** argv ); // allocate internal task variables for bookkeeping aso. + // we allocate the BlockData array with at least one member + if (iNofInputDataBlocks==0) iNofInputDataBlocks=1; fpBlockDataArray=new AliHLTComponentBlockData[iNofInputDataBlocks]; if (fpBlockDataArray) { fBlockDataArraySize=iNofInputDataBlocks; @@ -668,6 +686,29 @@ int AliHLTTask::StartRun() HLTError("memory allocation failed"); iResult=-ENOMEM; } + + // allocate the data buffer, which controls the output buffer and subscriptions + if (iResult>=0) { + fpDataBuffer=new AliHLTDataBuffer; + if (fpDataBuffer!=NULL) { + HLTDebug("created data buffer %p for task %s (%p)", fpDataBuffer, GetName(), this); + TObjLink* lnk=fListTargets.FirstLink(); + while (lnk && iResult>=0) { + AliHLTTask* pTgtTask=(AliHLTTask*)lnk->GetObject(); + if (pTgtTask) { + if ((iResult=fpDataBuffer->SetConsumer(pTgtTask->GetComponent()))>=0) { + } + } else { + break; + iResult=-EFAULT; + } + lnk=lnk->Next(); + } + } else { + HLTFatal("can not create data buffer object, memory allocation failed"); + iResult=-ENOMEM; + } + } } } else { HLTError("task %s (%p) does not have a component", GetName(), this); @@ -686,14 +727,21 @@ int AliHLTTask::EndRun() } else { HLTWarning("task %s (%p) doesn't seem to be in running mode", GetName(), this); } + if (fpDataBuffer) { + AliHLTDataBuffer* pBuffer=fpDataBuffer; + fpDataBuffer=NULL; + delete pBuffer; + } return iResult; } -int AliHLTTask::ProcessTask() +int AliHLTTask::ProcessTask(Int_t eventNo) { int iResult=0; AliHLTComponent* pComponent=GetComponent(); - if (pComponent && fpBlockDataArray) { + if (pComponent && fpDataBuffer) { + HLTDebug("Processing task %s (%p) fpDataBuffer %p", GetName(), this, fpDataBuffer); + fpDataBuffer->Reset(); int iSourceDataBlock=0; int iInputDataVolume=0; @@ -718,7 +766,9 @@ int AliHLTTask::ProcessTask() while (lnk && iResult>=0) { pSrcTask=(AliHLTTask*)lnk->GetObject(); if (pSrcTask) { - if (pSrcTask->GetNofMatchingDataBlocks(this)GetNofMatchingDataBlocks(this); + if (iMatchingDB<=fBlockDataArraySize-iSourceDataBlock) { + if (fpBlockDataArray) { if ((iResult=pSrcTask->Subscribe(this, &fpBlockDataArray[iSourceDataBlock],fBlockDataArraySize-iSourceDataBlock))>0) { for (int i=0; iGetName(), pSrcTask); + HLTDebug("Task %s (%p) successfully subscribed to %d data block(s) of task %s (%p)", GetName(), this, iResult, pSrcTask->GetName(), pSrcTask); iResult=0; } else { HLTError("Task %s (%p): subscription to task %s (%p) failed with error %d", GetName(), this, pSrcTask->GetName(), pSrcTask, iResult); iResult=-EFAULT; } + } else { + HLTFatal("Task %s (%p): BlockData array not allocated", GetName(), this); + iResult=-EFAULT; + } } else { HLTFatal("Task %s (%p): too little space in data block array for subscription to task %s (%p)", GetName(), this, pSrcTask->GetName(), pSrcTask); + HLTDebug("#data types=%d, array size=%d, current index=%d", iMatchingDB, fBlockDataArraySize, iSourceDataBlock); iResult=-EFAULT; } } else { @@ -748,10 +803,17 @@ int AliHLTTask::ProcessTask() if (iResult>=0) { long unsigned int iConstBase=0; double fInputMultiplier=0; - pComponent->GetOutputDataSize(iConstBase, fInputMultiplier); + if (pComponent->GetComponentType()!=AliHLTComponent::kSink) + pComponent->GetOutputDataSize(iConstBase, fInputMultiplier); int iOutputDataSize=int(fInputMultiplier*iInputDataVolume) + iConstBase; - AliHLTUInt8_t* pTgtBuffer=fpDataBuffer->GetTargetBuffer(iOutputDataSize); + //HLTDebug("task %s: reqired output size %d", GetName(), iOutputDataSize); + AliHLTUInt8_t* pTgtBuffer=NULL; + if (iOutputDataSize>0) pTgtBuffer=fpDataBuffer->GetTargetBuffer(iOutputDataSize); + //HLTDebug("provided raw buffer %p", pTgtBuffer); AliHLTComponentEventData evtData; + AliHLTComponent::FillEventData(evtData); + evtData.fEventID=(AliHLTEventID_t)eventNo; + evtData.fBlockCnt=iSourceDataBlock; AliHLTComponentTriggerData trigData; AliHLTUInt32_t size=iOutputDataSize; AliHLTUInt32_t outputBlockCnt=0; @@ -759,10 +821,13 @@ int AliHLTTask::ProcessTask() AliHLTComponentEventDoneData* edd; if (pTgtBuffer!=NULL || iOutputDataSize==0) { iResult=pComponent->ProcessEvent(evtData, fpBlockDataArray, trigData, pTgtBuffer, size, outputBlockCnt, outputBlocks, edd); - if (iResult>=0) { + HLTDebug("task %s: component %s ProcessEvent finnished (%d): size=%d blocks=%d", GetName(), pComponent->GetComponentID(), iResult, size, outputBlockCnt); + if (iResult>=0 && pTgtBuffer) { iResult=fpDataBuffer->SetSegments(pTgtBuffer, outputBlocks, outputBlockCnt); } } else { + HLTError("task %s: no target buffer available", GetName()); + iResult=-EFAULT; } } @@ -779,7 +844,7 @@ int AliHLTTask::ProcessTask() HLTError("Task %s (%p): realease of task %s (%p) failed with error %d", GetName(), this, pSrcTask->GetName(), pSrcTask, iTempRes); } } else { - HLTFatal("internal error in ROOT list handling"); + HLTFatal("task %s (%p): internal error in ROOT list handling", GetName(), this); if (iResult>=0) iResult=-EFAULT; } subscribedTaskList.Remove(lnk); @@ -790,7 +855,7 @@ int AliHLTTask::ProcessTask() HLTError("task %s (%p): could not release all data buffers", GetName(), this); } } else { - HLTError("internal failure: task not initialized"); + HLTError("task %s (%p): internal failure (not initialized component %p, data buffer %p)", GetName(), this, fpComponent, fpDataBuffer); iResult=-EFAULT; } return iResult; @@ -1008,6 +1073,7 @@ int AliHLTConfigurationHandler::RemoveConfiguration(AliHLTConfiguration* pConf) int iResult=0; if (pConf) { // remove the configuration from the list + HLTDebug("remove configuration \"%s\"", pConf->GetName()); fListConfigurations.Remove(pConf); // remove cross links in the remaining configurations TObjLink* lnk=fListConfigurations.FirstLink(); diff --git a/HLT/BASE/AliHLTDataBuffer.cxx b/HLT/BASE/AliHLTDataBuffer.cxx index fa557ad7275..8c6c278cdc9 100644 --- a/HLT/BASE/AliHLTDataBuffer.cxx +++ b/HLT/BASE/AliHLTDataBuffer.cxx @@ -179,15 +179,19 @@ int AliHLTDataBuffer::SetConsumer(AliHLTComponent* pConsumer) { int iResult=0; if (pConsumer) { + if (FindConsumer(pConsumer)) { + HLTWarning("consumer %s (%p) already set to data buffer %p", pConsumer->GetComponentID(), pConsumer, this); + } AliHLTConsumerDescriptor* pDesc=new AliHLTConsumerDescriptor(pConsumer); if (pDesc) { fConsumers.push_back(pDesc); + HLTDebug("set consumer %s (%p) to data buffer %p", pConsumer->GetComponentID(), pConsumer, this); } else { HLTError("memory allocation failed"); iResult=-ENOMEM; } } else { - HLTError("invalid parameter"); + HLTError("invalid parameter: consumer component (nil)"); iResult=-EINVAL; } return iResult; @@ -224,7 +228,8 @@ int AliHLTDataBuffer::FindMatchingDataSegments(const AliHLTComponent* pConsumer, while (segment!=fSegments.end()) { vector::iterator type=dtlist.begin(); while (type!=dtlist.end()) { - if ((*segment).fDataType==(*type)) { + if ((*segment).fDataType==(*type) || + (*type)==kAliHLTAnyDataType) { tgtList.push_back(*segment); iResult++; break; @@ -341,7 +346,11 @@ AliHLTUInt8_t* AliHLTDataBuffer::GetTargetBuffer(int iMinSize) { AliHLTUInt8_t* pTargetBuffer=NULL; fpBuffer=CreateRawBuffer(iMinSize); - pTargetBuffer=(AliHLTUInt8_t*)fpBuffer; + if (fpBuffer) { + pTargetBuffer=(AliHLTUInt8_t*)fpBuffer->fPtr; + } else { + HLTError("can not create raw buffer"); + } return pTargetBuffer; } @@ -354,14 +363,16 @@ int AliHLTDataBuffer::SetSegments(AliHLTUInt8_t* pTgt, AliHLTComponentBlockData* AliHLTDataSegment segment; memset(&segment, 0, sizeof(AliHLTDataSegment)); for (int i=0; ifSize) { + if (arrayBlockData[i].fOffset+arrayBlockData[i].fSize<=fpBuffer->fSize) { segment.fSegmentOffset=arrayBlockData[i].fOffset; segment.fSegmentSize=arrayBlockData[i].fSize; segment.fDataType=arrayBlockData[i].fDataType; segment.fSpecification=arrayBlockData[i].fSpecification; fSegments.push_back(segment); + HLTDebug("set segment %s with size %d at offset %d", AliHLTComponent::DataType2Text(segment.fDataType).data(), segment.fSegmentSize, segment.fSegmentOffset); } else { - HLTError("block data specification #%d (%s@%s) exceeds size of data buffer", i, arrayBlockData[i].fDataType.fOrigin, arrayBlockData[i].fDataType.fID); + HLTError("block data specification %#d (%s) exceeds size of data buffer", i, AliHLTComponent::DataType2Text(arrayBlockData[i].fDataType).data()); + HLTError("block offset=%d, block size=%d, buffer size=%d", arrayBlockData[i].fOffset, arrayBlockData[i].fSize, fpBuffer->fSize); } } } else { @@ -476,7 +487,7 @@ int AliHLTDataBuffer::DeleteRawBuffers() buffer=fFreeBuffers.begin(); } buffer=fActiveBuffers.begin(); - while (buffer!=fFreeBuffers.end()) { + while (buffer!=fActiveBuffers.end()) { fgLogging.Logging(kHLTLogWarning, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "request to delete active raw buffer container (raw buffer %p, size %d)", (*buffer)->fPtr, (*buffer)->fTotalSize); free((*buffer)->fPtr); delete *buffer; @@ -504,6 +515,8 @@ int AliHLTDataBuffer::ResetDataBuffer() int iResult=0; AliHLTRawBuffer* pBuffer=fpBuffer; fpBuffer=NULL; + + // cleanup consumer states vector::iterator desc=fReleasedConsumers.begin(); while (desc!=fReleasedConsumers.end()) { AliHLTConsumerDescriptor* pDesc=*desc; @@ -519,10 +532,26 @@ int AliHLTDataBuffer::ResetDataBuffer() desc=fActiveConsumers.begin(); fConsumers.push_back(pDesc); } - ReleaseRawBuffer(pBuffer); + + // cleanup segments + vector::iterator segment=fSegments.begin(); + while (segment!=fSegments.end()) { + fSegments.erase(segment); + segment=fSegments.begin(); + } + + // cleanup raw buffer + if (pBuffer) { + ReleaseRawBuffer(pBuffer); + } return iResult; } +int AliHLTDataBuffer::Reset() +{ + return ResetDataBuffer(); +} + // this is the version which works on lists of components instead of consumer descriptors // int AliHLTDataBuffer::ChangeConsumerState(AliHLTComponent* pConsumer, vector &srcList, vector &tgtList) // { @@ -550,20 +579,20 @@ int AliHLTDataBuffer::ResetDataBuffer() int AliHLTDataBuffer::ChangeConsumerState(AliHLTConsumerDescriptor* pDesc, vector &srcList, vector &tgtList) { - int iResult=0; + int iResult=-ENOENT; if (pDesc) { vector::iterator desc=srcList.begin(); while (desc!=srcList.end()) { if ((*desc)==pDesc) { srcList.erase(desc); tgtList.push_back(pDesc); + iResult=0; break; } desc++; } - if (desc==srcList.end()) { + if (iResult<0) { HLTError("can not find consumer descriptor %p in list", pDesc); - iResult=-ENOENT; } } else { HLTError("invalid parameter"); @@ -583,3 +612,27 @@ int AliHLTDataBuffer::CleanupConsumerList() { } return iResult; } + +int AliHLTDataBuffer::FindConsumer(AliHLTComponent* pConsumer, int bAllLists) { + vector::iterator desc=fConsumers.begin(); + while (desc!=fConsumers.end()) { + if ((*desc)->GetComponent()==pConsumer) + return 1; + desc++; + } + if (bAllLists==0) return 0; + + desc=fActiveConsumers.begin(); + while (desc!=fActiveConsumers.end()) { + if ((*desc)->GetComponent()==pConsumer) + return 1; + desc++; + } + desc=fReleasedConsumers.begin(); + while (desc!=fReleasedConsumers.end()) { + if ((*desc)->GetComponent()==pConsumer) + return 1; + desc++; + } + return 0; +} diff --git a/HLT/BASE/AliHLTDataBuffer.h b/HLT/BASE/AliHLTDataBuffer.h index 68731de0812..5e4f3c203ba 100644 --- a/HLT/BASE/AliHLTDataBuffer.h +++ b/HLT/BASE/AliHLTDataBuffer.h @@ -111,7 +111,7 @@ class AliHLTConsumerDescriptor : public TObject, public AliHLTLogging { /** * Set an active data segment - * the pointer will be handled in a container, not allocation, copy or cleanup + * the pointer will be handled in a container, no allocation, copy or cleanup * @param offset offset of the segment in the buffer * @param size size of the segment in the buffer * @return >=0 if succeeded @@ -150,15 +150,15 @@ class AliHLTConsumerDescriptor : public TObject, public AliHLTLogging { * @class AliHLTDataBuffer * @brief Handling of data buffers for the HLT. * - * The class provides handling of data buffers for HLT components. Each component gets its + * The class provides handling of data buffers for HLT tasks. Each task gets its * own Data Buffer instance. The buffer is grouped into different data segments according * to the output of the component.
- * The Data Buffer keeps control over the data requests of the 'child' componets. Each - * component can subscribe to a certain segment of the data buffer. It's state is that - * changed from 'reserved' to 'active'. After the data processing the component has to + * The Data Buffer keeps control over the data requests of the 'child' components. Each + * component can subscribe to a certain segment of the data buffer. It's state is then + * changed from 'reserved' to 'active'. After the data processing, the component has to * release the segment and it's state is set to 'processed'. * If all components have requested and released their data, the Raw Buffer is released - * and pushed back in the list of available buffers. + * and pushed back in the list of available buffers. * * @note This class is only used for the @ref alihlt_system. * @@ -290,6 +290,22 @@ class AliHLTDataBuffer : public TObject, public AliHLTLogging { */ int GetNofActiveConsumers(); + /** + * Check if a consumer is already in the list + * @param pConsumer pointer to consumer component + * @param bAllLists search in all lists if 1 + * search only in fConsumer list if 0 + * @return 1 if found, 0 if not + */ + int FindConsumer(AliHLTComponent* pConsumer, int bAllLists=1); + + /** + * Public method to reset the buffer. + * Eventually with some additional checks. In normal operation, + * an external reset should not be necessary. + */ + int Reset(); + private: /* lets see if this is needed AliHLTDataSegment* FindDataSegment(AliHLTComponentDataType datatype); @@ -307,12 +323,11 @@ class AliHLTDataBuffer : public TObject, public AliHLTLogging { /** * Reset the data buffer. - * Removes all consumers back to the @ref fConsumers list - * and releases the Raw Buffer. + * Removes all consumers back to the @ref fConsumers list, deletes + * segments and releases the Raw Buffer. */ int ResetDataBuffer(); - //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // the data description diff --git a/HLT/BASE/AliHLTDataSink.cxx b/HLT/BASE/AliHLTDataSink.cxx index 6e93dd32767..05d8fbd3308 100644 --- a/HLT/BASE/AliHLTDataSink.cxx +++ b/HLT/BASE/AliHLTDataSink.cxx @@ -37,6 +37,17 @@ AliHLTDataSink::~AliHLTDataSink() { } +AliHLTComponentDataType AliHLTDataSink::GetOutputDataType() +{ + return (AliHLTComponentDataType){ sizeof(AliHLTComponentDataType), kAliHLTVoidDataTypeID, kAliHLTVoidDataOrigin}; +} + +void AliHLTDataSink::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) +{ + constBase=0; + inputMultiplier=0; +} + int AliHLTDataSink::ProcessEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, AliHLTComponentTriggerData& trigData, diff --git a/HLT/BASE/AliHLTDataSink.h b/HLT/BASE/AliHLTDataSink.h index abf0177b9e9..42cf4701efd 100644 --- a/HLT/BASE/AliHLTDataSink.h +++ b/HLT/BASE/AliHLTDataSink.h @@ -60,6 +60,18 @@ class AliHLTDataSink : public AliHLTComponent { */ TComponentType GetComponentType() { return AliHLTComponent::kSink;} + /** + * Default implementation for all data sinks. + * There are no output data types. + */ + AliHLTComponentDataType GetOutputDataType(); + + /** + * Default implementation for all data sinks. + * There is no output data. + */ + void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ); + private: /** * Data processing method for the component. diff --git a/HLT/BASE/AliHLTDataSource.cxx b/HLT/BASE/AliHLTDataSource.cxx index 80fdab33f64..2ad38bf1287 100644 --- a/HLT/BASE/AliHLTDataSource.cxx +++ b/HLT/BASE/AliHLTDataSource.cxx @@ -58,11 +58,15 @@ int AliHLTDataSource::ProcessEvent( const AliHLTComponentEventData& evtData, } vector blockData; if (evtData.fBlockCnt > 0) { - HLTWarning("Data source component skips imput data blocks"); + HLTWarning("Data source component skips input data blocks"); } iResult=GetEvent(evtData, trigData, outputPtr, size, blockData); + HLTDebug("component %s (%p) GetEvent finished (%d)", GetComponentID(), this, iResult); if (iResult>=0) { iResult=MakeOutputDataBlockList(blockData, &outputBlockCnt, &outputBlocks); + if (iResult<0) { + HLTFatal("component %s (%p): can not convert output block descriptor list", GetComponentID(), this); + } } edd = NULL; return iResult; diff --git a/HLT/BASE/AliHLTDataTypes.h b/HLT/BASE/AliHLTDataTypes.h index b865828419b..e71d5f92db7 100644 --- a/HLT/BASE/AliHLTDataTypes.h +++ b/HLT/BASE/AliHLTDataTypes.h @@ -57,7 +57,10 @@ extern "C" { # define kAliHLTVoidDataTypeID "\0\0\0\0\0\0\0" # define kAliHLTVoidDataOrigin "\0\0\0" +# define kAliHLTAnyDataTypeID "*******" +# define kAliHLTAnyDataOrigin "***" const AliHLTComponentDataType kAliHLTVoidDataType = {sizeof(AliHLTComponentDataType), kAliHLTVoidDataTypeID, kAliHLTVoidDataOrigin}; + const AliHLTComponentDataType kAliHLTAnyDataType = {sizeof(AliHLTComponentDataType), kAliHLTAnyDataTypeID, kAliHLTAnyDataOrigin}; struct AliHLTComponentBlockData { diff --git a/HLT/BASE/AliHLTFilePublisher.cxx b/HLT/BASE/AliHLTFilePublisher.cxx index 1754c75c3bd..e825155c730 100644 --- a/HLT/BASE/AliHLTFilePublisher.cxx +++ b/HLT/BASE/AliHLTFilePublisher.cxx @@ -76,11 +76,6 @@ const char* AliHLTFilePublisher::GetComponentID() return "FilePublisher"; } -void AliHLTFilePublisher::GetInputDataTypes( vector& list) -{ - list.clear(); -} - AliHLTComponentDataType AliHLTFilePublisher::GetOutputDataType() { return (AliHLTComponentDataType){ sizeof(AliHLTComponentDataType), kAliHLTVoidDataTypeID, kAliHLTVoidDataOrigin}; @@ -99,10 +94,11 @@ AliHLTComponent* AliHLTFilePublisher::Spawn() int AliHLTFilePublisher::DoInit( int argc, const char** argv ) { + //HLTDebug("%d %s", argc, argv[0]); int iResult=0; TString argument=""; int bMissingParam=0; - for (int i; i=0; i++) { argument=argv[i]; // -datafile @@ -140,8 +136,16 @@ int AliHLTFilePublisher::DoInit( int argc, const char** argv ) if ((bMissingParam=(++i>=argc))) break; memcpy(&fDataType.fOrigin, argv[i], TMath::Min(kAliHLTComponentDataTypefOriginSize,(Int_t)strlen(argv[i]))); } else { - HLTError("unknown argument %s", argument.Data()); - iResult=-EINVAL; + if ((iResult=ScanArgument(argc-i, &argv[i]))==-EINVAL) { + HLTError("unknown argument %s", argument.Data()); + break; + } else if (iResult==-EPROTO) { + bMissingParam=1; + break; + } else if (iResult>=0) { + i+=iResult; + iResult=0; + } } } if (bMissingParam) { @@ -159,6 +163,12 @@ int AliHLTFilePublisher::DoInit( int argc, const char** argv ) return iResult; } +int AliHLTFilePublisher::ScanArgument(int argc, const char** argv) +{ + // there are no other arguments than the standard ones + return -EINVAL; +} + int AliHLTFilePublisher::OpenFiles() { int iResult=0; @@ -200,8 +210,7 @@ int AliHLTFilePublisher::GetEvent( const AliHLTComponentEventData& evtData, vector& outputBlocks ) { int iResult=0; - TFile * pFile=NULL; - TObjLink *lnk; + TObjLink *lnk=NULL; if (fpCurrent) lnk=fpCurrent->Next(); if (lnk==NULL) lnk=fFiles.FirstLink(); fpCurrent=lnk; @@ -209,7 +218,8 @@ int AliHLTFilePublisher::GetEvent( const AliHLTComponentEventData& evtData, TFile* pFile=(TFile*)lnk->GetObject(); if (pFile) { int iCopy=pFile->GetSize(); - if (iCopy>size) { + pFile->Seek(0); + if (iCopy>(int)size) { iCopy=size; HLTWarning("buffer to small, data of file %s truncated", pFile->GetName()); } @@ -228,6 +238,7 @@ int AliHLTFilePublisher::GetEvent( const AliHLTComponentEventData& evtData, size=iCopy; } } else { + HLTError("no file available"); iResult=-EFAULT; } } else { diff --git a/HLT/BASE/AliHLTFilePublisher.h b/HLT/BASE/AliHLTFilePublisher.h index b45d14ddeed..382ed48dac5 100644 --- a/HLT/BASE/AliHLTFilePublisher.h +++ b/HLT/BASE/AliHLTFilePublisher.h @@ -45,7 +45,6 @@ class AliHLTFilePublisher : public AliHLTDataSource { virtual ~AliHLTFilePublisher(); const char* GetComponentID(); - void GetInputDataTypes( vector& list); AliHLTComponentDataType GetOutputDataType(); void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ); AliHLTComponent* Spawn(); @@ -84,6 +83,19 @@ class AliHLTFilePublisher : public AliHLTDataSource { AliHLTUInt32_t& size, vector& outputBlocks ); + /** + * Scan one argument and adjacent parameters. + * Can be overloaded by child classes in order to add additional arguments + * beyond the standard arguments of the file publisher. The method is called + * whenever a non-standard argument is recognized. + * @param argc size of the argument array + * @param argv agument array for component initialization + * @return number of processed members of the argv
+ * -EINVAL unknown argument
+ * -EPROTO parameter for argument missing
+ */ + virtual int ScanArgument(int argc, const char** argv); + private: TList fFileNames; TList fFiles; diff --git a/HLT/BASE/AliHLTFileWriter.cxx b/HLT/BASE/AliHLTFileWriter.cxx new file mode 100644 index 00000000000..3dd484e17e1 --- /dev/null +++ b/HLT/BASE/AliHLTFileWriter.cxx @@ -0,0 +1,174 @@ +// $Id$ + +/************************************************************************** + * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * * + * Authors: Matthias Richter * + * for The ALICE Off-line Project. * + * * + * Permission to use, copy, modify and distribute this software and its * + * documentation strictly for non-commercial purposes is hereby granted * + * without fee, provided that the above copyright notice appears in all * + * copies and that both the copyright notice and this permission notice * + * appear in the supporting documentation. The authors make no claims * + * about the suitability of this software for any purpose. It is * + * provided "as is" without express or implied warranty. * + **************************************************************************/ + +/** @file AliHLTFileWriter.cxx + @author Matthias Richter + @date + @brief HLT file writer component implementation. */ + +#if __GNUC__>= 3 +using namespace std; +#endif + +#include "AliHLTFileWriter.h" +#include +#include +#include + +/** ROOT macro for the implementation of ROOT specific class methods */ +ClassImp(AliHLTFileWriter) + +AliHLTFileWriter::AliHLTFileWriter() + : + fBaseName(""), + fDirectory(""), + fEnumeration(""), + fbSeparate(0) +{ +} + +AliHLTFileWriter::AliHLTFileWriter(const AliHLTFileWriter&) + : + fBaseName(""), + fDirectory(""), + fEnumeration(""), + fbSeparate(0) +{ + HLTFatal("copy constructor untested"); +} + +AliHLTFileWriter& AliHLTFileWriter::operator=(const AliHLTFileWriter&) +{ + HLTFatal("assignment operator untested"); + return *this; +} + +AliHLTFileWriter::~AliHLTFileWriter() +{ + // file list and file name list are owner of their objects and + // delete all the objects +} + +const char* AliHLTFileWriter::GetComponentID() +{ + return "FileWriter"; +} + +void AliHLTFileWriter::GetInputDataTypes( vector& list) +{ + list.clear(); + list.push_back(kAliHLTAnyDataType); +} + +AliHLTComponent* AliHLTFileWriter::Spawn() +{ + return new AliHLTFileWriter; +} + +int AliHLTFileWriter::DoInit( int argc, const char** argv ) +{ + int iResult=0; + TString argument=""; + int bMissingParam=0; + for (int i=0; i=0; i++) { + argument=argv[i]; + + // -basename + if (argument.CompareTo("-datafile")==0) { + if ((bMissingParam=(++i>=argc))) break; + fBaseName=argv[i]; + + // -directory + } else if (argument.CompareTo("-directory")==0) { + if ((bMissingParam=(++i>=argc))) break; + fDirectory=argv[i]; + + // -enumeration + } else if (argument.CompareTo("-enumeration")==0) { + if ((bMissingParam=(++i>=argc))) break; + fEnumeration=argv[i]; + + // -separate + } else if (argument.CompareTo("-enumeration")==0) { + if ((bMissingParam=(++i>=argc))) break; + TString parameter(argv[i]); + fbSeparate=parameter.Atoi(); + if (fbSeparate < 0 || fbSeparate > 1) { + HLTError("invalid parameter for argument %s", argument.Data()); + } + + } else { + if ((iResult=ScanArgument(argc-i, &argv[i]))==-EINVAL) { + HLTError("unknown argument %s", argument.Data()); + break; + } else if (iResult==-EPROTO) { + bMissingParam=1; + break; + } else if (iResult>=0) { + i+=iResult; + iResult=0; + } + } + } + if (bMissingParam) { + HLTError("missing parameter for argument %s", argument.Data()); + iResult=-EINVAL; + } + return iResult; +} + +int AliHLTFileWriter::ScanArgument(int argc, const char** argv) +{ + // there are no other arguments than the standard ones + return -EINVAL; +} + +int AliHLTFileWriter::DoDeinit() +{ + int iResult=0; + return iResult; +} + +int AliHLTFileWriter::DumpEvent( const AliHLTComponentEventData& evtData, + const AliHLTComponentBlockData* blocks, + AliHLTComponentTriggerData& trigData ) +{ + int iResult=0; + for (int n=0; n<(int)evtData.fBlockCnt; n++ ) { + //HLTDebug("block %d out of %d", n, evtData.fBlockCnt); + TString filename; + iResult=BuildFileName(evtData.fEventID, n, blocks[n].fDataType, filename); + if (iResult>=0) { + ofstream dump(filename.Data()); + if (dump.good()) { + dump.write((const char*)blocks[n].fPtr, blocks[n].fSize); + HLTDebug("wrote %d byte(s) to file %s", blocks[n].fSize, filename.Data()); + } + dump.close(); + } + } + return iResult; +} + +int AliHLTFileWriter::BuildFileName(const AliHLTEventID_t eventID, const int blockID, const AliHLTComponentDataType& dataType, TString& filename) +{ + int iResult=0; + //HLTDebug("build file name for event %d block %d", eventID, blockID); + filename.Form("event_%#08x_0x%x_", eventID, blockID); + filename+=AliHLTComponent::DataType2Text(dataType).data(); + return iResult; +} diff --git a/HLT/BASE/AliHLTFileWriter.h b/HLT/BASE/AliHLTFileWriter.h new file mode 100644 index 00000000000..4aacf183382 --- /dev/null +++ b/HLT/BASE/AliHLTFileWriter.h @@ -0,0 +1,97 @@ +// @(#) $Id$ + +#ifndef ALIHLTFILEWRITER_H +#define ALIHLTFILEWRITER_H +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/** @file AliHLTFileWriter.h + @author Matthias Richter + @date + @brief An HLT file dump (data sink) component. + @note The class is used in Offline (AliRoot) context +*/ + +#include "AliHLTDataSink.h" +#include + +/** + * @class AliHLTFileWriter + * An HLT data sink component which writes data to file(s) + * + * @ingroup alihlt_component + */ +class AliHLTFileWriter : public AliHLTDataSink { + public: + /** standard constructor */ + AliHLTFileWriter(); + /** not a valid copy constructor, defined according to effective C++ style */ + AliHLTFileWriter(const AliHLTFileWriter&); + /** not a valid assignment op, but defined according to effective C++ style */ + AliHLTFileWriter& operator=(const AliHLTFileWriter&); + /** destructor */ + virtual ~AliHLTFileWriter(); + + const char* GetComponentID(); + void GetInputDataTypes( vector& list); + AliHLTComponent* Spawn(); + + protected: + /** + * Init method. + */ + int DoInit( int argc, const char** argv ); + + /** + * Deinit method. + */ + int DoDeinit(); + + /** + * Data processing method for the component. + * @param evtData event data structure + * @param blocks input data block descriptors + * @param trigData trigger data structure + */ + int DumpEvent( const AliHLTComponentEventData& evtData, + const AliHLTComponentBlockData* blocks, + AliHLTComponentTriggerData& trigData ); + + /** + * Scan one argument and adjacent parameters. + * Can be overloaded by child classes in order to add additional arguments + * beyond the standard arguments of the file publisher. The method is called + * whenever a non-standard argument is recognized. + * @param argc size of the argument array + * @param argv agument array for component initialization + * @return number of processed members of the argv
+ * -EINVAL unknown argument
+ * -EPROTO parameter for argument missing
+ */ + virtual int ScanArgument(int argc, const char** argv); + + private: + /** + * Build file name from eventID data type and the specified directory and basename. + * @param eventID [in] the ID of the event + * @param blockID [in] the ID of the current block + * @param dataType [in] the data type of the data block + * @param filename [out] string to receive the file name + */ + int BuildFileName(const AliHLTEventID_t eventID, const int blockID, const AliHLTComponentDataType& dataType, TString& filename); + + /** the basename of the output file */ + TString fBaseName; + /** target directory */ + TString fDirectory; + /** enumeration format string */ + TString fEnumeration; + /** + * flag to indicate whether to write each incoming block to separate files + * or all blocks of one event to one file. + */ + Int_t fbSeparate; + + ClassDef(AliHLTFileWriter, 0) +}; +#endif diff --git a/HLT/BASE/AliHLTSystem.cxx b/HLT/BASE/AliHLTSystem.cxx index 23567ba2fa4..9b1b968170e 100644 --- a/HLT/BASE/AliHLTSystem.cxx +++ b/HLT/BASE/AliHLTSystem.cxx @@ -34,6 +34,19 @@ using namespace std; #include "AliHLTTask.h" #include "TString.h" +// #include +// #include +// #include "AliLog.h" + +// ostringstream g_logstr; + +// void LogNotification(AliLog::EType_t level, const char* message) +// { +// cout << "notification handler" << endl; +// cout << g_logstr.str() << endl; +// g_logstr.clear(); +// } + /** ROOT macro for the implementation of ROOT specific class methods */ ClassImp(AliHLTSystem) @@ -46,6 +59,7 @@ AliHLTSystem::AliHLTSystem() if (fpComponentHandler) { AliHLTComponentEnvironment env; memset(&env, 0, sizeof(AliHLTComponentEnvironment)); + env.fAllocMemoryFunc=AliHLTSystem::AllocMemory; env.fLoggingFunc=AliHLTLogging::Message; fpComponentHandler->SetEnvironment(&env); @@ -59,6 +73,11 @@ AliHLTSystem::AliHLTSystem() } else { HLTFatal("can not create Configuration Handler"); } +// AliLog log; +// log.SetLogNotification(LogNotification); +// log.SetStreamOutput(&g_logstr); +// AliInfo("this is a printf message"); +// AliInfoStream() << "this is a stream message" << endl; } AliHLTSystem::AliHLTSystem(const AliHLTSystem&) @@ -262,42 +281,49 @@ void AliHLTSystem::PrintTaskList() } } -void AliHLTSystem::PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt) { - TString msg; - msg.Form("AliHLTComponentDataType(%d): ID=\"", dt.fStructSize); - for ( unsigned i = 0; i < kAliHLTComponentDataTypefIDsize; i++ ) { - if (dt.fID[i]!=0) msg+=dt.fID[i]; - else msg+="\\0"; - } - msg+="\" Origin=\""; - for ( unsigned i = 0; i < kAliHLTComponentDataTypefOriginSize; i++ ) { - if (dt.fOrigin[i]!=0) msg+=dt.fOrigin[i]; - else msg+="\\0"; - } - msg+="\""; - HLTMessage(msg.Data()); -} - int AliHLTSystem::Run(Int_t iNofEvents) { int iResult=0; - if ((iResult=StartTasks())>=0) { - for (int i=0; i=0; i++) { - iResult=ProcessTasks(i); - if (iResult>=0) { - HLTInfo("Event %d successfully finished (%d)", i, iResult); - iResult=0; - } else { - HLTError("Processing of event %d failed (%d)", i, iResult); - // TODO: define different running modes to either ignore errors in - // event processing or not - // currently ignored - iResult=0; + if ((iResult=InitTasks())>=0) { + if ((iResult=StartTasks())>=0) { + for (int i=0; i=0; i++) { + iResult=ProcessTasks(i); + if (iResult>=0) { + HLTInfo("Event %d successfully finished (%d)", i, iResult); + iResult=0; + } else { + HLTError("Processing of event %d failed (%d)", i, iResult); + // TODO: define different running modes to either ignore errors in + // event processing or not + // currently ignored + //iResult=0; + } } + StopTasks(); + } else { + HLTError("can not start task list"); } - StopTasks(); + DeinitTasks(); } else { - HLTError("can not start task list"); + HLTError("can not initialize task list"); + } + return iResult; +} + +int AliHLTSystem::InitTasks() +{ + int iResult=0; + TObjLink *lnk=fTaskList.FirstLink(); + while (lnk && iResult>=0) { + TObject* obj=lnk->GetObject(); + if (obj) { + AliHLTTask* pTask=(AliHLTTask*)obj; + iResult=pTask->Init(NULL, fpComponentHandler); + } else { + } + lnk = lnk->Next(); + } + if (iResult<0) { } return iResult; } @@ -329,7 +355,8 @@ int AliHLTSystem::ProcessTasks(Int_t eventNo) TObject* obj=lnk->GetObject(); if (obj) { AliHLTTask* pTask=(AliHLTTask*)obj; - iResult=pTask->ProcessTask(); + iResult=pTask->ProcessTask(eventNo); + HLTDebug("task %s finnished (%d)", pTask->GetName(), iResult); } else { } lnk = lnk->Next(); @@ -352,3 +379,24 @@ int AliHLTSystem::StopTasks() } return iResult; } + +int AliHLTSystem::DeinitTasks() +{ + int iResult=0; + TObjLink *lnk=fTaskList.FirstLink(); + while (lnk && iResult>=0) { + TObject* obj=lnk->GetObject(); + if (obj) { + AliHLTTask* pTask=(AliHLTTask*)obj; + iResult=pTask->Deinit(); + } else { + } + lnk = lnk->Next(); + } + return iResult; +} + +void* AliHLTSystem::AllocMemory( void* param, unsigned long size ) +{ + return (void*)new char[size]; +} diff --git a/HLT/BASE/AliHLTSystem.h b/HLT/BASE/AliHLTSystem.h index c48cb6e96a7..3967093350f 100644 --- a/HLT/BASE/AliHLTSystem.h +++ b/HLT/BASE/AliHLTSystem.h @@ -114,19 +114,25 @@ class AliHLTSystem : public AliHLTLogging { */ void PrintTaskList(); - /** - * Print info on an AliHLTComponentDataType structure - */ - void PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt); - /** * Run the task list. + * The method checks whether the task list has already been build. If not, + * or the configuration list has been changed, the @ref BuildTaskList + * method is scalled * All tasks of the list will be subsequently processed for each event. * @param iNofEvents number of events * @return neg error code if failed */ int Run(Int_t iNofEvents=1); + /** + * Init all tasks from the list. + * The @ref AliHLTTask::Init method is called for each task, the components + * will be created. + * @return neg error code if failed + */ + int InitTasks(); + /** * Start task list. * The @ref AliHLTTask::StartRun method is called for each task, the components @@ -150,6 +156,20 @@ class AliHLTSystem : public AliHLTLogging { */ int StopTasks(); + /** + * De-init all tasks from the list. + * The @ref AliHLTTask::Deinit method is called for each task, the components + * will be deleted. + * @return neg error code if failed + */ + int DeinitTasks(); + + /** + * The memory allocation function for components. + * This function is part of the running environment of the components. + */ + static void* AllocMemory( void* param, unsigned long size ); + protected: int ProcessTask(); int StartEvent(); diff --git a/HLT/BASE/AliHLTTask.h b/HLT/BASE/AliHLTTask.h index fbb1f77b30b..2f2e7ec7efb 100644 --- a/HLT/BASE/AliHLTTask.h +++ b/HLT/BASE/AliHLTTask.h @@ -173,14 +173,7 @@ class AliHLTTask : public TObject, public AliHLTLogging { * processing, the data blocks are released.
* The @ref StartRun method must be called before. */ - int ProcessTask(); - - // clear the list of source data blocks - // the list of source data blocks has to be cleared at the beginning of - // a new event - /* this function is most likely depricated - int ClearSourceBlocks(); - */ + int ProcessTask(Int_t eventNo); /** * Determine the number of matching data block between the component and the diff --git a/HLT/BASE/HLTbaseLinkDef.h b/HLT/BASE/HLTbaseLinkDef.h index ada0fbde63e..03ababd55d0 100644 --- a/HLT/BASE/HLTbaseLinkDef.h +++ b/HLT/BASE/HLTbaseLinkDef.h @@ -18,6 +18,7 @@ #pragma link C++ class AliHLTDataSource; #pragma link C++ class AliHLTDataSink; #pragma link C++ class AliHLTFilePublisher; +#pragma link C++ class AliHLTFileWriter; #endif diff --git a/HLT/BASE/Makefile.am b/HLT/BASE/Makefile.am index d4a186c4f6f..fdb6fe65888 100644 --- a/HLT/BASE/Makefile.am +++ b/HLT/BASE/Makefile.am @@ -8,6 +8,8 @@ # e.g. for libHLTbase, MODULE=HLTbase MODULE = HLTbase +EXTRA_DIST = HLTbaseLinkDef.h + AM_CPPFLAGS = -DMODULE=$(MODULE) bin_SCRIPTS = setenv.sh setenv.csh diff --git a/HLT/ChangeLog b/HLT/ChangeLog index 04076d26c75..ceedd744537 100644 --- a/HLT/ChangeLog +++ b/HLT/ChangeLog @@ -1,3 +1,7 @@ +2007-01-19 + - AliHLTFileWriter added, handling of standard components in libHLT + added to ComponentHandler + - several fixes in the HLT offline framework 2007-01-05 - changes according to coding conventions and documentation - AliHLTTPCDigitReaderRaw: HAVE_TPC_MAPPING dependend implementation diff --git a/HLT/SampleLib/AliHLTDummyComponent.cxx b/HLT/SampleLib/AliHLTDummyComponent.cxx index 8427789cf24..140d134e16c 100644 --- a/HLT/SampleLib/AliHLTDummyComponent.cxx +++ b/HLT/SampleLib/AliHLTDummyComponent.cxx @@ -52,15 +52,22 @@ const char* AliHLTDummyComponent::GetComponentID() void AliHLTDummyComponent::GetInputDataTypes( vector& list) { - list.clear(); // We do not have any requirements for our input data type(s). + /* in order to be backward compatible we have to keep the old code, at + * least for a while. Remember to use the new const kAliHLTVoidDataType + * if you are using a more recent AliRoot version (from Jan 07) + list.push_back(kAliHLTAnyDataType); // We do not have any requirements for our input data type(s). + */ + list.push_back((AliHLTComponentDataType){ sizeof(AliHLTComponentDataType), {'*','*','*','*','*','*','*','\0'},{'*','*','*','\0'}}); } AliHLTComponentDataType AliHLTDummyComponent::GetOutputDataType() { - AliHLTComponentDataType dt; - SetDataType(dt, "DUMMY", "DUMY"); - cout << "SetDataType: size " << dt.fStructSize << endl; - return dt; + /* in order to be backward compatible we have to keep the old code, at + * least for a while. Remember to use the new const kAliHLTVoidDataType + * if you are using a more recent AliRoot version (from Jan 07) + return kAliHLTVoidDataType; + */ + return (AliHLTComponentDataType){ sizeof(AliHLTComponentDataType), {'\0','\0','\0','0','\0','\0','\0','\0'},{'\0','\0','\0','\0'}}; } void AliHLTDummyComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) diff --git a/HLT/SampleLib/Makefile.am b/HLT/SampleLib/Makefile.am index 457103b5899..e2011ce8afb 100644 --- a/HLT/SampleLib/Makefile.am +++ b/HLT/SampleLib/Makefile.am @@ -8,10 +8,7 @@ MODULE = AliHLTSample -EXTRA_DIST = -if STANDALONE_SAMPLELIB -EXTRA_DIST += libAliHLTSample.pkg -endif +EXTRA_DIST = AliHLTSampleLinkDef.h # include the pkg definition which actually contains the source # file definitions diff --git a/HLT/configure.ac b/HLT/configure.ac index 785673a3ac1..f8640d051ca 100644 --- a/HLT/configure.ac +++ b/HLT/configure.ac @@ -295,17 +295,18 @@ if test "x$with_pubsub" != "xno" ; then # directory layout if test -d ${with_pubsub}/include/HOMER ; then # the 'early' location of the include files with separated HOMER sub dirs - HOMER_CPPFLAGS="-I${with_pubsub}/include/HOMER -I${with_pubsub}/include/HOMER/reader" + HOMER_INCDIRS="${with_pubsub}/include/HOMER ${with_pubsub}/include/HOMER/reader" elif test -d ${with_pubsub}/include/Util/HOMER ; then # location for HLT Framework versions after Sep 2006 - HOMER_CPPFLAGS="-I${with_pubsub}/include/Util/HOMER" + HOMER_INCDIRS="${with_pubsub}/include/Util/HOMER" elif test -d ${with_pubsub}/src/Util/HOMER/include ; then # fall back if include files were not installed (versions after Sep 06) - HOMER_CPPFLAGS="-I${with_pubsub}/src/Util/HOMER/include" + HOMER_INCDIRS="${with_pubsub}/src/Util/HOMER/include" else # fall back if include files were not installed (versions before Sep 06) - HOMER_CPPFLAGS="-I${with_pubsub}/src/Util/HOMER/reader/include -I${with_pubsub}/src/Util/HOMER/data/include" + HOMER_INCDIRS="${with_pubsub}/src/Util/HOMER/reader/include ${with_pubsub}/src/Util/HOMER/data/include" fi + HOMER_CPPFLAGS=`for i in ${HOMER_INCDIRS}; do echo -n "-I$i " ; done` HOMER_BINDIR="${with_pubsub}/bin/`uname -s`-`uname -m`" HOMER_LIBDIR="${with_pubsub}/lib/`uname -s`-`uname -m`" HOMER_LDFLAGS="-L${HOMER_LIBDIR}" @@ -322,7 +323,7 @@ if test "x$with_pubsub" != "xno" ; then [with_homer=yes HOMER_LIBS="-lHOMERReader"])]) LIBS="$LIBS $HOMER_LIBS" - AC_MSG_CHECKING([for HOMER version]) + AC_MSG_CHECKING([version of HOMER library]) dnl The Homer library has no versioning, so we do our own dnl version description dnl ---------------------------------------------------------------------- diff --git a/HLT/libAliHLTSample.pkg b/HLT/libAliHLTSample.pkg index 72602d2bbbb..be66b2f2053 100644 --- a/HLT/libAliHLTSample.pkg +++ b/HLT/libAliHLTSample.pkg @@ -32,7 +32,7 @@ MODULE_HDRS:= $(CLASS_HDRS) # classes. The *LinkDef.h must be added to DHDR in that case. # There might be an extension also in ALIROOT which allows to # generate the LinkDef automatically. -DHDR:= +DHDR:= SampleLib/AliHLTSampleLinkDef.h CINTAUTOLINK:= # extra defines and flags for the AliRoot build system. NOTE: include diff --git a/HLT/libHLTbase.pkg b/HLT/libHLTbase.pkg index e15863f8df2..2aa25574293 100644 --- a/HLT/libHLTbase.pkg +++ b/HLT/libHLTbase.pkg @@ -13,7 +13,8 @@ MODULE_SRCS= AliHLTComponent.cxx \ AliHLTDataBuffer.cxx \ AliHLTDataSource.cxx \ AliHLTDataSink.cxx \ - AliHLTFilePublisher.cxx + AliHLTFilePublisher.cxx \ + AliHLTFileWriter.cxx CLASS_HDRS:= AliHLTComponent.h \ AliHLTComponentHandler.h \ @@ -26,7 +27,8 @@ CLASS_HDRS:= AliHLTComponent.h \ AliHLTDataBuffer.h \ AliHLTDataSource.h \ AliHLTDataSink.h \ - AliHLTFilePublisher.h + AliHLTFilePublisher.h \ + AliHLTFileWriter.h MODULE_HDRS:= $(CLASS_HDRS) \ AliHLTDataTypes.h \ -- 2.43.0