From: jthaeder Date: Sun, 19 Oct 2008 16:28:41 +0000 (+0000) Subject: New Component: X-Git-Url: http://git.uio.no/git/?p=u%2Fmrichter%2FAliRoot.git;a=commitdiff_plain;h=fa5e8413a96e716ec0f372f18d0d40987f0c7df0 New Component: * AliHLTESDMCEventPublisherComponent Publishs AliESDEvents and AliMCEvents in the offline aliroot context. * exa/rootfilepublisher.C Testmacro to test the new component * New DataOrigin added -kAliHLTDataOriginHLT -kAliHLTDataOriginOffline * New DataType Added -kAliHLTMCObjectDataTypeID --- diff --git a/HLT/BASE/AliHLTDataTypes.cxx b/HLT/BASE/AliHLTDataTypes.cxx index 405752bee6a..a25c72d96be 100644 --- a/HLT/BASE/AliHLTDataTypes.cxx +++ b/HLT/BASE/AliHLTDataTypes.cxx @@ -79,6 +79,10 @@ const AliHLTComponentDataType kAliHLTDataTypeUpdtDCS = AliHLTComponentDataTypeIn const char kAliHLTDDLRawDataTypeIDstring[8] = kAliHLTDDLRawDataTypeID; const AliHLTComponentDataType kAliHLTDataTypeDDLRaw = AliHLTComponentDataTypeInitializer(kAliHLTDDLRawDataTypeIDstring, kAliHLTDataOriginAny); +/** MC data specification */ +const char kAliHLTMCObjectDataTypeIDstring[8] = kAliHLTMCObjectDataTypeID; +const AliHLTComponentDataType kAliHLTDataTypeMCObject = AliHLTComponentDataTypeInitializer(kAliHLTMCObjectDataTypeIDstring, kAliHLTDataOriginOffline); + /** ESD data specification */ const char kAliHLTESDObjectDataTypeIDstring[8] = kAliHLTESDObjectDataTypeID; const AliHLTComponentDataType kAliHLTDataTypeESDObject = AliHLTComponentDataTypeInitializer(kAliHLTESDObjectDataTypeIDstring, kAliHLTDataOriginAny); @@ -163,6 +167,12 @@ const AliHLTComponentDataType kAliHLTDataTypeExternalTrackParam = AliHLTComponen /** HLT out */ const char kAliHLTDataOriginOut[kAliHLTComponentDataTypefOriginSize] = {'H','L','T',' '}; +/** HLT */ +const char kAliHLTDataOriginHLT[kAliHLTComponentDataTypefOriginSize] = {'H','L','T',' '}; + +/** Offline */ +const char kAliHLTDataOriginOffline[kAliHLTComponentDataTypefOriginSize] = {'O','F','F','L'}; + /** HLT/PubSub private internal */ const char kAliHLTDataOriginPrivate[kAliHLTComponentDataTypefOriginSize] = {'P','R','I','V'}; @@ -198,3 +208,4 @@ const char kAliHLTDataOriginSample[kAliHLTComponentDataTypefOriginSize] = {'S', /** EMCAL */ const char kAliHLTDataOriginEMCAL[kAliHLTComponentDataTypefOriginSize] = {'E','M','C','L'}; + diff --git a/HLT/BASE/AliHLTDataTypes.h b/HLT/BASE/AliHLTDataTypes.h index 3e8685bab0a..076a1d4a8b0 100644 --- a/HLT/BASE/AliHLTDataTypes.h +++ b/HLT/BASE/AliHLTDataTypes.h @@ -44,8 +44,13 @@ * AliHLTComponentEnvironment -> AliHLTAnalysisEnvironment * 9 added data types for arrays of AliHLTExternalTrackParam sets and * TClonesArrays of AliExternalTrackParam objects. + * 10 Changes for information objects neededfor running with offline + * chains and analysis tasks. + * kAliHLTMCObjectDataType added + * kAliHLTDataOriginOffline added + * kAliHLTDataOriginHLT added */ -#define ALIHLT_DATA_TYPES_VERSION 9 +#define ALIHLT_DATA_TYPES_VERSION 10 ////////////////////////////////////////////////////////////////////////// // @@ -55,7 +60,7 @@ // the operator| // // AliHLTComponentDataType dt; -// dt = kAliHLTDataTypeDDLRaw | gkAliHLTDataOriginTPC; +// dt = kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC; // ////////////////////////////////////////////////////////////////////////// @@ -84,6 +89,17 @@ const int kAliHLTComponentDataTypefOriginSize=4; */ extern const char kAliHLTDataOriginOut[kAliHLTComponentDataTypefOriginSize]; +/** Data origin HLT, used for HLT specifc data + * in offline chains. This not a bug! + * @ingroup alihlt_component_datatypes + */ +extern const char kAliHLTDataOriginHLT[kAliHLTComponentDataTypefOriginSize]; + +/** Data origin Offline + * @ingroup alihlt_component_datatypes + */ +extern const char kAliHLTDataOriginOffline[kAliHLTComponentDataTypefOriginSize]; + /** Data origin HLT/PubSub private internal * @ingroup alihlt_component_datatypes */ @@ -223,6 +239,13 @@ const int kAliHLTComponentDataTypefIDsize=8; */ # define kAliHLTUpdtDCSDataTypeID {'U','P','D','T','_','D','C','S'} +/** MC data block + * an AliMCEvent object of varying origin + * The 'V0' at the end allows a versioning + * @ingroup alihlt_component_datatypes + */ +# define kAliHLTMCObjectDataTypeID {'A','L','I','M','C','_','V','0'} + /** ESD data block * an AliESD object of varying origin * The 'V0' at the end allows a versioning @@ -778,15 +801,19 @@ extern "C" { */ extern const AliHLTComponentDataType kAliHLTDataTypeDDLRaw; + /** AliMCEvent object data specification, origin is 'OFFL' + * @ingroup alihlt_component_datatypes + */ + extern const AliHLTComponentDataType kAliHLTDataTypeMCObject; + /** ESD object data specification, origin is 'any' * @ingroup alihlt_component_datatypes */ extern const AliHLTComponentDataType kAliHLTDataTypeESDObject; /** ESD Tree data specification, origin is 'any' - - * @ingroup alihlt_component_datatypes - */ + * @ingroup alihlt_component_datatypes + */ extern const AliHLTComponentDataType kAliHLTDataTypeESDTree; /** AliRoot TreeD data specification, origin is 'any' diff --git a/HLT/BASE/util/AliHLTAgentUtil.cxx b/HLT/BASE/util/AliHLTAgentUtil.cxx index 44b754d0e8d..0c4ef4d3e22 100644 --- a/HLT/BASE/util/AliHLTAgentUtil.cxx +++ b/HLT/BASE/util/AliHLTAgentUtil.cxx @@ -34,6 +34,7 @@ #include "AliHLTRootFileStreamerComponent.h" #include "AliHLTRootFileWriterComponent.h" #include "AliHLTRootFilePublisherComponent.h" +#include "AliHLTESDMCEventPublisherComponent.h" #include "AliHLTFileWriter.h" #include "AliHLTFilePublisher.h" #include "AliHLTBlockFilterComponent.h" @@ -112,6 +113,7 @@ int AliHLTAgentUtil::RegisterComponents(AliHLTComponentHandler* pHandler) const pHandler->AddComponent(new AliHLTRootFileStreamerComponent); pHandler->AddComponent(new AliHLTRootFileWriterComponent); pHandler->AddComponent(new AliHLTRootFilePublisherComponent); + pHandler->AddComponent(new AliHLTESDMCEventPublisherComponent); pHandler->AddComponent(new AliHLTFileWriter); pHandler->AddComponent(new AliHLTFilePublisher); pHandler->AddComponent(new AliHLTBlockFilterComponent); @@ -123,7 +125,7 @@ int AliHLTAgentUtil::RegisterComponents(AliHLTComponentHandler* pHandler) const int AliHLTAgentUtil::GetHandlerDescription(AliHLTComponentDataType dt, AliHLTUInt32_t /*spec*/, - AliHLTOUTHandlerDesc& desc) const + AliHLTOUTHandlerDesc& desc) const { // see header file for class documentation diff --git a/HLT/BASE/util/AliHLTESDMCEventPublisherComponent.cxx b/HLT/BASE/util/AliHLTESDMCEventPublisherComponent.cxx new file mode 100644 index 00000000000..7cecdc0d072 --- /dev/null +++ b/HLT/BASE/util/AliHLTESDMCEventPublisherComponent.cxx @@ -0,0 +1,657 @@ +// $Id: AliHLTESDMCEventPublisherComponent.cxx 25452 2008-04-25 21:46:04Z richterm $ + +/************************************************************************** + * This file is property of and copyright by the ALICE HLT Project * + * ALICE Experiment at CERN, All rights reserved. * + * * + * Primary Authors: Jochen Thaeder * + * for The ALICE HLT 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 AliHLTESDMCEventPublisherComponent.cxx + @author Jochen Thaeder + @date + @brief Component for publishing ESD and MC events. + @note The class is used in Offline (AliRoot) context +*/ + +#include "AliHLTESDMCEventPublisherComponent.h" + +#include "TList.h" +#include "TTree.h" +#include "TKey.h" +#include "TFile.h" + +/** ROOT macro for the implementation of ROOT specific class methods */ +ClassImp(AliHLTESDMCEventPublisherComponent) + +/* + * --------------------------------------------------------------------------------- + * Constructor / Destructor + * --------------------------------------------------------------------------------- + */ + +// ################################################################################# +AliHLTESDMCEventPublisherComponent::AliHLTESDMCEventPublisherComponent() + : + AliHLTFilePublisher(), + fpCurrentFolder(NULL), + fpCurrentFileList(NULL), + fCurrentEvent(0), + fNEventsInFolder(0), + fFolderList(), + fSpecification(0), + fPublishESD(kFALSE), + fPublishHLTESD(kFALSE), + fPublishMC(kFALSE), + fpTreeESD(NULL), + fpTreeHLTESD(NULL), + fpTreeE(NULL), + fpTreeK(NULL), + fpTreeTR(NULL), + fpESD(NULL), + fpHLTESD(NULL), + fpMC(NULL) { + // see header file for class documentation + // or + // refer to README to build package + // or + // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt + + // Set file to ROOT-File + SetIsRawFile( kFALSE ); + + fFolderList.SetOwner(); +} + +// ################################################################################# +AliHLTESDMCEventPublisherComponent::~AliHLTESDMCEventPublisherComponent() { + // see header file for class documentation + + // file list and file name list are owner of their objects and + // delete all the objects +} + +/* + * --------------------------------------------------------------------------------- + * Public functions to implement AliHLTComponent's interface. + * These functions are required for the registration process + * --------------------------------------------------------------------------------- + */ + +// ################################################################################# +const char* AliHLTESDMCEventPublisherComponent::GetComponentID() { + // see header file for class documentation + return "ESDMCEventPublisher"; +} + +// ################################################################################# +AliHLTComponent* AliHLTESDMCEventPublisherComponent::Spawn() { + // see header file for class documentation + return new AliHLTESDMCEventPublisherComponent; +} + +/* + * --------------------------------------------------------------------------------- + * Protected functions to implement AliHLTComponent's interface. + * These functions provide initialization as well as the actual processing + * capabilities of the component. + * --------------------------------------------------------------------------------- + */ + +// ################################################################################# +Int_t AliHLTESDMCEventPublisherComponent::DoInit(Int_t argc, const char** argv) { + // see header file for class documentation + + Int_t iResult = 0; + Int_t bMissingParam=0; + + TString argument=""; + + fSpecification = kAliHLTVoidDataSpec; + + // -- Loop over all arguments + for ( Int_t iter = 0; iter=0; iter++) { + argument=argv[iter]; + if (argument.IsNull()) continue; + + // -- Check for which type to publish + // Can be one, all or some of : ESD, HLTESD and MC + if ( !argument.CompareTo("-entrytype") ) { + if ((bMissingParam=(++iter>=argc))) break; + + TString parameter(argv[iter]); + parameter.Remove(TString::kLeading, ' '); + + if ( !parameter.CompareTo("ESD") ) + fPublishESD = kTRUE; + else if ( !parameter.CompareTo("HLTESD") ) + fPublishHLTESD = kTRUE; + else if ( !parameter.CompareTo("MC") ) + fPublishMC = kTRUE; + else { + HLTError("Wrong parameter %s for argument %s.", parameter.Data(), argument.Data()); + iResult=-EINVAL; + } + } + + // -- Data path to reconstructed data + else if ( ! argument.CompareTo("-datapath") ) { + if ((bMissingParam=(++iter>=argc))) break; + + TString parameter(argv[iter]); + parameter.Remove(TString::kLeading, ' '); + + fFolderList.Add( new TObjString(parameter) ); + } + + // -- Data Specification + // -- see header file !!! + else if ( ! argument.CompareTo("-dataspec") ) { + if ((bMissingParam=(++iter>=argc))) break; + + TString parameter(argv[iter]); + parameter.Remove(TString::kLeading, ' '); + + if ( parameter.IsDigit() ) + fSpecification = (AliHLTUInt32_t) parameter.Atoi(); + else if ( parameter.BeginsWith("0x") && parameter.Replace(0,2,"",0).IsHex() ) + sscanf(parameter.Data(),"%x", &fSpecification); + else { + HLTError("Wrong parameter for argument %s, number expected", argument.Data()); + iResult=-EINVAL; + } + } + + // -- Argument not known + else { + HLTError("Unknown argument %s.", argument.Data()); + iResult = -EINVAL; + } + + } // for ( Int iter = 0; iter=0; iter++) { + + // -- Check if parameter is missing + if ( bMissingParam ) { + HLTError("Missing parameter for argument %s.", argument.Data()); + iResult=-EINVAL; + } + + // -- Check if at least on entrytype was specified + if ( fPublishESD||fPublishHLTESD||fPublishMC ) + AddDataTypesToOutputlist(); + else { + HLTError("At least one -entrytype argument needs to be specified."); + iResult=-EINVAL; + } + + // -- Check if at least one datapath was specified + if ( !fFolderList.GetEntries() ) { + HLTError("At least one -datapath argument needs to be specified."); + iResult=-EINVAL; + } + + // -- Add files according to entry type to event + if ( iResult >= 0 ) { + iResult = InsertFiles(); + } + + // -- Calculate event size + if ( fPublishESD ) + fMaxSize += sizeof(AliESDEvent); + if ( fPublishHLTESD ) + fMaxSize += sizeof(AliESDEvent); + if ( fPublishMC ) + fMaxSize += sizeof(AliMCEvent); + + if ( fEvents.GetSize() == 0) { + HLTError("No Files have been added."); + iResult=-EINVAL; + } + + if ( iResult < 0 ) { + fEvents.Clear(); + } + + return iResult; +} + +// ################################################################################# +Int_t AliHLTESDMCEventPublisherComponent::DoDeinit() { + // see header file for class documentation + + Int_t iResult = 0; + + if ( fpESD ) + delete fpESD; + fpESD = NULL; + + if ( fpHLTESD ) + delete fpHLTESD; + fpHLTESD = NULL; + + if ( fpMC ) + delete fpMC; + fpMC = NULL; + + CloseCurrentFileList(); + + AliHLTFilePublisher::DoDeinit(); + + return iResult; +} + +// ################################################################################# +void AliHLTESDMCEventPublisherComponent::AddDataTypesToOutputlist() { + // see header file for class documentation + + // add all different data types to the list + if ( fPublishESD ) + fOutputDataTypes.push_back(kAliHLTDataTypeESDObject|kAliHLTDataOriginOffline); + else if ( fPublishHLTESD ) + fOutputDataTypes.push_back(kAliHLTDataTypeESDObject|kAliHLTDataOriginHLT); + else if( fPublishMC ) + fOutputDataTypes.push_back(kAliHLTDataTypeMCObject); +} + +// ################################################################################# +Int_t AliHLTESDMCEventPublisherComponent::InsertFiles(){ + // see header file for class documentation + + Int_t iResult=0; + + EventFiles* pCurrentFolder = NULL; + + TObjString *objPath = 0; + TIter next(&fFolderList); + + // Loop over all folders + while ( ( objPath = (TObjString*) next() ) && iResult>=0 ) { + + TString pathAliESDs = objPath->GetString(); + pathAliESDs.Append("/AliESDs.root"); + + TString pathKinematics = objPath->GetString(); + pathKinematics.Append("/Kinematics.root"); + + TString pathgalice = objPath->GetString(); + pathgalice.Append("/galice.root"); + + TString pathTrackRefs = objPath->GetString(); + pathTrackRefs.Append("/TrackRefs.root"); + + + // Add ESD file for this folder + if ( fPublishESD || fPublishHLTESD ) { + FileDesc* pDesc=new FileDesc( pathAliESDs.Data(), kAliHLTDataTypeESDObject, kAliHLTVoidDataSpec, kFALSE); + if ( pDesc ) + iResult = InsertFile( pCurrentFolder, pDesc ); + else + iResult = -ENOMEM; + } + + // Add MC files for this folder + if ( fPublishMC ) { + FileDesc* pDescKinematics=new FileDesc( pathKinematics.Data(), kAliHLTDataTypeMCObject, kAliHLTVoidDataSpec, kFALSE); + if ( pDescKinematics ) + iResult = InsertFile( pCurrentFolder, pDescKinematics ); + else + iResult = -ENOMEM; + + FileDesc* pDescgalice=new FileDesc( pathgalice.Data(), kAliHLTDataTypeMCObject, kAliHLTVoidDataSpec, kFALSE); + if ( pDescgalice ) + iResult = InsertFile( pCurrentFolder, pDescgalice ); + else + iResult = -ENOMEM; + + FileDesc* pDescTrackRefs=new FileDesc( pathTrackRefs.Data(), kAliHLTDataTypeMCObject, kAliHLTVoidDataSpec, kFALSE); + if ( pDescTrackRefs ) + iResult = InsertFile( pCurrentFolder, pDescTrackRefs ); + else + iResult = -ENOMEM; + } + + // -- Add all files belonging to one eventfolder + InsertEvent( pCurrentFolder ); + + } // while ( ( path = (TObjString*)next() ) ) { + + return iResult; +} + +// ################################################################################# +Int_t AliHLTESDMCEventPublisherComponent::GetEvent( const AliHLTComponentEventData& /*evtData*/, + AliHLTComponentTriggerData& /*trigData*/, + AliHLTUInt8_t* /*outputPtr*/, + AliHLTUInt32_t& size, + vector& /*outputBlocks*/ ) { + // see header file for class documentation + + if ( !IsDataEvent() ) return 0; + + Int_t iResult=0; + size=0; + + // -- Initialize folder list and + // re-initialize after reaching the end in the event before + // + if ( !fpCurrentFolder ) { + fpCurrentFolder = GetEventList()->FirstLink(); + + // -- Set file list of this folder and open the files + if ( fpCurrentFolder ) { + iResult = OpenCurrentFileList(); + } + else { + HLTError("Folder link can not be retrieved from folder list."); + iResult=-ENOENT; + } + } + + // -- if file list was properly created + if ( iResult >= 0 && fpCurrentFileList ) { + + // -- Publish ESDs + if ( fPublishESD && fpTreeESD ) { + fpTreeESD->GetEntry(fCurrentEvent); + PushBack( fpESD, kAliHLTDataTypeESDObject|kAliHLTDataOriginOffline , fSpecification ); + } + + // -- Publish HLTESDs + if ( fPublishHLTESD && fpTreeHLTESD ) { + fpTreeHLTESD->GetEntry(fCurrentEvent); + PushBack( fpHLTESD, kAliHLTDataTypeESDObject|kAliHLTDataOriginHLT , fSpecification ); + } + + // -- Publish MC + if ( fPublishMC ) { + + TObjLink *flnk = fpCurrentFileList->FirstLink(); + + // -- Loop over files in the current list + while (flnk && iResult>=0) { + + FileDesc* pFileDesc = dynamic_cast( flnk->GetObject() ); + TFile* pFile = *pFileDesc; + + TString filename = pFile->GetName(); + filename.Remove(0,filename.Last('/')+1); + + TString foldername( Form("Event%d", fCurrentEvent) ); + + // -- Open Kinematics + if ( !filename.CompareTo("Kinematics.root") ){ + + if ( fNEventsInFolder != (UInt_t)(pFile->GetListOfKeys()->GetEntries()) ) { + HLTError("Not all files contain the same number of events : %u and %d", + fNEventsInFolder, pFile->GetListOfKeys()->GetEntries() ); + iResult=-EFAULT; + } + + // -- Get Tree K + else { + TDirectoryFile *dirK = dynamic_cast (pFile->Get(foldername)); + if ( dirK ) + fpTreeK = dynamic_cast (dirK->Get("TreeK")); + else { + HLTError("Directory %s could not be found.", foldername.Data() ); + iResult=-EFAULT; + } + } + } // if ( !filename.CompareTo("Kinematics.root") ){ + + // -- Open TrackReferences + else if ( !filename.CompareTo("TrackRefs.root") ){ + + if ( fNEventsInFolder != (UInt_t)(pFile->GetListOfKeys()->GetEntries()) ) { + HLTError("Not all files contain the same number of events : %u and %d", + fNEventsInFolder, pFile->GetListOfKeys()->GetEntries() ); + iResult=-EFAULT; + } + + // -- Get Tree TR + else { + TDirectoryFile *dirTR = dynamic_cast (pFile->Get(foldername)); + if ( dirTR ) + fpTreeTR = dynamic_cast (dirTR->Get("TreeTR")); + else { + HLTError("Directory %s could not be found.", foldername.Data() ); + iResult=-EFAULT; + } + } + } // else if ( !filename.CompareTo("TrackRefs.root") ){ + + flnk = flnk->Next(); + + } // while (flnk && iResult>=0) { + + if ( fpMC ) delete fpMC; + fpMC = new AliMCEvent(); + + if ( fpTreeE && fpTreeK && fpTreeTR ) { + + fpMC->ConnectTreeE(fpTreeE); + fpTreeE->GetEntry(fCurrentEvent); + + fpMC->ConnectTreeK(fpTreeK); + fpMC->ConnectTreeTR(fpTreeTR); + } + else { + HLTError("Not all trees needed for MC Event have been created."); + iResult=-EFAULT; + } + + if ( iResult>=0 && fpMC ) { + PushBack( fpMC, kAliHLTDataTypeMCObject|kAliHLTDataOriginOffline , fSpecification ); + } + + } // if ( fPublishMC ) { + + // -- Next Event in Folder, + // if last event was already reached: + // -> Reser and close files + if ( ++fCurrentEvent >= fNEventsInFolder ) + iResult = CloseCurrentFileList(); + + } // if ( iResult >= 0 && fCurrentFileList ) { + + // -- Next Folder + // (fpCurrentEvent will be NULL*pFileDesc if end of events in file is reached) + if ( iResult >= 0 && fpCurrentFolder && !fCurrentEvent ) { + fpCurrentFolder=fpCurrentFolder->Next(); + + // -- if next Folder present : Set current file list of next folder + // else : end of folder list reached, reset fpCurrentFileList + if ( fpCurrentFolder ) + iResult = OpenCurrentFileList(); + + } + + return iResult; +} + +// ################################################################################# +Int_t AliHLTESDMCEventPublisherComponent::OpenCurrentFileList() { + // see header file for class documentation + + Int_t iResult = 0; + Int_t nEntries = -1; + + // -- Get Current Folder + EventFiles* pCurrentFolderDesc = dynamic_cast( fpCurrentFolder->GetObject() ); + + // -- Get List of files in current folder + if ( pCurrentFolderDesc ) + fpCurrentFileList = *pCurrentFolderDesc; // type conversion operator defined + else { + HLTError("Folder descriptor can not be retrieved from folder list link"); + iResult=-EFAULT; + } + + if ( fpCurrentFileList && iResult >= 0 ) { + + TObjLink *flnk = fpCurrentFileList->FirstLink(); + + // -- Loop over all files in folder + // ---------------------------------- + while ( flnk && iResult>=0 ) { + FileDesc* pFileDesc = dynamic_cast( flnk->GetObject() ); + TFile* pFile = NULL; + + // If file is not opened yet, open it ... which it should not + if ( pFileDesc && ( pFile = *pFileDesc ) == NULL ) + pFileDesc->OpenFile(); + else { + HLTError("File already open, this should not happen."); + iResult=-EFAULT; + } + + if ( (pFile = *pFileDesc ) == NULL ) { + HLTError("Opening file failed." ); + iResult=-EFAULT; + } + + // -- Open trees + // --------------- + TString filename = pFile->GetName(); + filename.Remove(0,filename.Last('/')+1); + + // -- Open ESD tree + if ( !filename.CompareTo("AliESDs.root") && fPublishESD ) { + fpTreeESD = dynamic_cast(pFile->Get("esdTree") ); + + if ( fpTreeESD ) { + if ( nEntries == -1 ) + nEntries = (Int_t)(fpTreeESD->GetEntriesFast()); + else if ( nEntries != (Int_t)(fpTreeESD->GetEntriesFast()) ) { + HLTError("Not all files contain the same number of events : %d and %ld", + nEntries, fpTreeESD->GetEntriesFast()); + iResult=-EFAULT; + } + + // Setup AliESDEvent + if ( fpESD ) delete fpESD; + fpESD = new AliESDEvent(); + fpESD->ReadFromTree(fpTreeESD); + + } // if ( fpTreeESD ) { + else { + HLTError("Getting ESD tree failed for file %s.", pFile->GetName() ); + iResult=-EFAULT; + } + } // if ( !filename.CompareTo("AliESDs.root") && fPublishESD ){ + + + // -- Open HLTESD tree + if ( !filename.CompareTo("AliESDs.root") && fPublishHLTESD ) { + fpTreeHLTESD = dynamic_cast(pFile->Get("HLTesdTree") ); + + if ( fpTreeHLTESD ) { + if ( nEntries == -1 ) + nEntries = (Int_t)(fpTreeHLTESD->GetEntriesFast()); + else if ( nEntries != (Int_t)(fpTreeHLTESD->GetEntriesFast()) ) { + HLTError("Not all files contain the same number of events : %d and %ld", + nEntries, fpTreeHLTESD->GetEntriesFast()); + iResult=-EFAULT; + } + + // Setup AliESDEvent + if ( fpHLTESD ) delete fpHLTESD; + fpHLTESD = new AliESDEvent(); + fpHLTESD->ReadFromTree(fpTreeHLTESD); + + } // if ( fpTreeHLTESD ) { + else { + HLTError("Getting HLTESD tree failed for file %s.", pFile->GetName() ); + iResult=-EFAULT; + } + + } // if ( !filename.CompareTo("AliESDs.root") && fPublishHLTESD ){ + + // -- Open galice tree : TreeE + else if ( !filename.CompareTo("galice.root") && fPublishMC ) { + fpTreeE = dynamic_cast(pFile->Get("TE") ); + + if ( fpTreeE ) { + if ( nEntries == -1 ) + nEntries = (Int_t)(fpTreeE->GetEntriesFast()); + else if ( nEntries != (Int_t)(fpTreeE->GetEntriesFast()) ) { + HLTError("Not all files contain the same number of events : %d and %ld", + nEntries, fpTreeE->GetEntriesFast()); + iResult=-EFAULT; + } + } // if ( fpTreeE ) { + else { + HLTError("Getting TreeE failed for file %s.", pFile->GetName() ); + iResult=-EFAULT; + } + } // if ( !filename.CompareTo("galice.root") && fPublishMC ){ + + flnk = flnk->Next(); + + } // while ( flnk && iResult>=0 ) { + + } // if ( fpCurrentFileList && iResult >= 0 ) { + else { + HLTError("Current file list could not get created."); + iResult=-EFAULT; + } + + if ( iResult >= 0 ) + fNEventsInFolder = (UInt_t)(nEntries); + + return iResult; +} + +// ################################################################################# +Int_t AliHLTESDMCEventPublisherComponent::CloseCurrentFileList() { + // see header file for class documentation + + Int_t iResult = 0; + + // -- Reset + fCurrentEvent = 0; + fNEventsInFolder = 0; + + // if not set, no files are open ... + if ( fpCurrentFileList ) { + + TObjLink *flnk = fpCurrentFileList->FirstLink(); + + // -- Loop over all files in folder + while ( flnk && iResult>=0 ) { + FileDesc* pFileDesc = dynamic_cast( flnk->GetObject() ); + + TFile* pFile = NULL; + + // If is opened, close it + if ( pFileDesc && ( pFile = *pFileDesc ) != NULL ) + pFileDesc->CloseFile(); + else { + HLTError("File already open, this should not happen."); + iResult=-EFAULT; + } + + if ( (pFile = *pFileDesc ) != NULL ) { + HLTError("Closing file %s failed.", pFile->GetName() ); + iResult=-EFAULT; + } + + flnk = flnk->Next(); + + } // while ( flnk && iResult>=0 ) { + + fpCurrentFileList = NULL; + + } // if ( fpCurrentFileList && iResult >= 0 ) { + + return iResult; +} diff --git a/HLT/BASE/util/AliHLTESDMCEventPublisherComponent.h b/HLT/BASE/util/AliHLTESDMCEventPublisherComponent.h new file mode 100644 index 00000000000..169d318d4de --- /dev/null +++ b/HLT/BASE/util/AliHLTESDMCEventPublisherComponent.h @@ -0,0 +1,282 @@ +// -*- Mode: C++ -*- +// $Id: AliHLTESDMCEventPublisherComponent.h 27447 2008-07-19 21:59:56Z richterm $ + +#ifndef ALIHLTESDMCEVENTPUBLISHERCOMPONENT_H +#define ALIHLTESDMCEVENTPUBLISHERCOMPONENT_H +//* This file is property of and copyright by the ALICE HLT Project * +//* ALICE Experiment at CERN, All rights reserved. * +//* See cxx source for full Copyright notice * + +/** @file AliHLTESDMCEventPublisherComponent.h + @author Jochen Thaeder + @date + @brief Component for publishing ESD and MC events. + @note The class is used in Offline (AliRoot) context +*/ + +#include "AliHLTFilePublisher.h" + +#include "TList.h" +#include "TTree.h" + +#include "AliESDEvent.h" +#include "AliMCEvent.h" + + +/** + * @class AliHLTESDMCEventPublisherComponent + * An HLT data source component which publishes AliESDEvent and AliMCEvent objects + * out of a series of datapaths.
+ * + *

General properties:

+ * + * Component ID: \b ESDMCEventPublisher
+ * Library: \b libAliHLTUtil.so
+ * Input Data Types: none
+ * Output Data Types: according to arguments
+ * - AliESDEvent -> kAliHLTDataTypeESDObject + * - HLTESD -> kAliHLTDataOriginHLT + * - ESD -> kAliHLTDataOriginOffline + * + * - AliMCEvent -> kAliHLTDataTypeMCObject + * -> kAliHLTDataOriginOffline + * + *

Mandatory arguments:

+ * + * \li -entrytype Type of events to publish
+ * Can be one, all or some of :
+ * - ESD
+ * - HLTESD
+ * - MC
+ * + * \li -datapath Path to list of data files
+ * - AliESDs.root
+ * - Kinematics.root
+ * - galice.root
+ * - TrackRefs.root
+ * + *

Optional arguments:

+ * \li -dataspec Specification
+ * Data specification treated as decimal number or hex number if + * prepended by '0x'
+ * If not given void spec ist used. Otherwise each Bit corresponds to + * the detectorID specified at ALICE-INT-2007-016, Table 1 + * + *

Configuration:

+ * + * Configuration by component arguments. + * + *

Default CDB entries:

+ * The component loads no CDB entries. + * + *

Performance:

+ * The component does not process any event data. + * + *

Memory consumption:

+ * The component does not process any event data. + * + *

Output size:

+ * According to the available data. The component is an AliHLTDataSource + * and inteded to be used in the AliHLTSystem framework only. The component + * implements the standard AliHLTSystem adaptive buffer allocation. + * + * The component needs at least one argument \em -datapath. + * It can occur multiple times. The \em -entrytype and \em -dataspec + * parameters are valid for all data paths + * + * All files are broken up and published in individual events. Then one data + * block is pulished for each entrytype. + * + * @ingroup alihlt_util_components + */ + +class AliHLTESDMCEventPublisherComponent : public AliHLTFilePublisher { + public: + + /* + * --------------------------------------------------------------------------------- + * Constructor / Destructor + * --------------------------------------------------------------------------------- + */ + + /** standard constructor */ + AliHLTESDMCEventPublisherComponent(); + + /** destructor */ + virtual ~AliHLTESDMCEventPublisherComponent(); + + /* + * --------------------------------------------------------------------------------- + * Public functions to implement AliHLTComponent's interface. + * These functions are required for the registration process + * --------------------------------------------------------------------------------- + */ + + /** interface function, see @ref AliHLTComponent for description */ + const char* GetComponentID(); + + /** interface function, see @ref AliHLTComponent for description */ + AliHLTComponent* Spawn(); + + protected: + /* + * --------------------------------------------------------------------------------- + * Protected functions to implement AliHLTComponent's interface. + * These functions provide initialization as well as the actual processing + * capabilities of the component. + * --------------------------------------------------------------------------------- + */ + + /** + * Init method. + * Overwrites the AliHLTFilePublisher::DoInit() method. + * @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
+ */ + Int_t DoInit( Int_t argc, const Char_t** argv ); + + + /** + * Deinit method. Calls also the one of AliHLTFilePublisher. + */ + Int_t DoDeinit(); + + /** + * Data processing method for the component. + * The component uses the @ref alihltcomponent-high-level-interface + * to put serialized Root object into the output stream. Despite of that it + * implements the low-level DumpEvent method in order to allow child classes + * to use the low-level method. + * @param evtData event data structure + * @param trigData trigger data structure + * @param outputPtr not used + * @param size not used + * @param outputBlocks not used + * @return + */ + Int_t GetEvent( const AliHLTComponentEventData& evtData, + AliHLTComponentTriggerData& trigData, + AliHLTUInt8_t* outputPtr, + AliHLTUInt32_t& size, + vector& outputBlocks); + + using AliHLTFilePublisher::GetEvent; + + private: + + /* + * --------------------------------------------------------------------------------- + * Private functions to implement AliHLTComponent's interface. + * These functions provide initialization as well as the actual processing + * capabilities of the component. + * --------------------------------------------------------------------------------- + */ + + /** copy constructor prohibited */ + AliHLTESDMCEventPublisherComponent(const AliHLTESDMCEventPublisherComponent&); + + /** assignment operator prohibited */ + AliHLTESDMCEventPublisherComponent& operator=(const AliHLTESDMCEventPublisherComponent&); + + + /* + * --------------------------------------------------------------------------------- + * Helper functions - private + * --------------------------------------------------------------------------------- + */ + + /** Add output datatypes according to the fPublish* flags + * - AliESDEvent -> kAliHLTDataTypeESDObject + * - HLTESD -> kAliHLTDataOriginHLT + * - ESD -> kAliHLTDataOriginOffline + * + * - AliMCEvent -> kAliHLTDataTypeMCObject + * -> kAliHLTDataOriginOffline + */ + void AddDataTypesToOutputlist(); + + /** Insert datafiles according to the fPublish* flags + * into folders. + * @return negative number in error case + */ + Int_t InsertFiles(); + + /** Open all files for current folder. Get ESD tree's and TreeE. + * @return negative number in error case + */ + Int_t OpenCurrentFileList(); + + /** Close all files for current folder. + * @return negative number in error case + */ + Int_t CloseCurrentFileList(); + + /* + * --------------------------------------------------------------------------------- + * Members - private + * --------------------------------------------------------------------------------- + */ + + /** The current folder, containing 1 set of files */ + TObjLink *fpCurrentFolder; //! transient + + /** List of files in current folder*/ + TList *fpCurrentFileList; //! transient + + /** Event in current folder ( inside files ) */ + UInt_t fCurrentEvent; //! see above + + /** Number of event in current folder ( inside files ) */ + UInt_t fNEventsInFolder; //! see above + + /** List containing TObjStrings + * -> Contain paths to reconstructed data + */ + TList fFolderList; //! see above + + /** Data specification */ + AliHLTUInt32_t fSpecification; //! transient + + /** Publish class AliESDEvent, containing normal ESD */ + Bool_t fPublishESD; //! see above + + /** Publish class AliESDEvent, containing normal HLTESD */ + Bool_t fPublishHLTESD; //! see above + + /** Publish class AliMCEvent */ + Bool_t fPublishMC; //! see above + + /** Pointer to ESD tree in current file */ + TTree* fpTreeESD; //! transient + + /** Pointer to HLT ESD tree in current file */ + TTree* fpTreeHLTESD; //! transient + + /** Pointer to TreeE tree in current galice file */ + TTree* fpTreeE; //! transient + + /** Pointer to TreeK tree in current kinematics file + * - changes every event + */ + TTree* fpTreeK; //! transient + + /** Pointer to TreeTR tree in current track refernce file + * - changes every event + */ + TTree* fpTreeTR; //! transient + + /* Ptr to current AliESDEvent, to be shipped out*/ + AliESDEvent* fpESD; //! transient + + /* Ptr to current HLT - AliESDEvent, to be shipped out*/ + AliESDEvent* fpHLTESD; //! transient + + /* Ptr to current AliMCEvent, to be shipped out*/ + AliMCEvent* fpMC; //! transient + + ClassDef(AliHLTESDMCEventPublisherComponent, 0) +}; +#endif diff --git a/HLT/BASE/util/AliHLTFilePublisher.h b/HLT/BASE/util/AliHLTFilePublisher.h index a0e02a7d417..0ff0a5b4977 100644 --- a/HLT/BASE/util/AliHLTFilePublisher.h +++ b/HLT/BASE/util/AliHLTFilePublisher.h @@ -111,7 +111,7 @@ class AliHLTFilePublisher : public AliHLTDataSource { /** * Init method. */ - int DoInit( int argc, const char** argv ); + virtual int DoInit( int argc, const char** argv ); /** * Deinit method. @@ -243,6 +243,7 @@ class AliHLTFilePublisher : public AliHLTDataSource { void Add(TObject* pObj) {fFiles.Add(pObj);} operator TList&() {return fFiles;} + operator TList*() {return &fFiles;} private: /** list of file names for the event */ diff --git a/HLT/exa/ESDMCEventPublisher.C b/HLT/exa/ESDMCEventPublisher.C new file mode 100644 index 00000000000..4a27bdaa7b8 --- /dev/null +++ b/HLT/exa/ESDMCEventPublisher.C @@ -0,0 +1,67 @@ +/** + * @file ESDMCEventPublisher.C + * @brief Macro for testing AliESDEvent and AliMCEvent publishing and writing + * + * This macro is a testing/example macro of how to use the ESDMCEventPublisher + * (AliHLTESDMCEventPublisherComponent) and RootFileWriter (AliHLTRootFileWriter). + * It defines only two component in the chain, the publisher, which + * publishes the content of the root files according to the selection. + * Be aware there can be several root objects in one root file. + * + * The file datapath has to be changed with an actual one. It must contain + * the files:
+ * - AliESDs.root
+ * - Kinematics.root
+ * - galice.root
+ * - TrackRefs.root
+ * + * Entry type can be one, all or some of :
+ * - ESD
+ * - HLTESD
+ * - MC
+ * + * For more descriptions, especially the used datatypes and specification: + * @see AliHLTESDMCEventPublisherComponent + * + * @author thaeder@kip.uni-heidelberg.de + * @ingroup alihlt_tutorial + */ + +/** ESDMCEventPublisher test macro + * @param nEvents Number of events which should be processed + */ +void ESDMCEventPublisher(Int_t nEvents=1) { + + TString writerInput; + TString arg; + + AliHLTSystem gHLT; + gHLT.LoadComponentLibraries("libAliHLTUtil.so"); + + // -- Root publisher configuration + // !!! myDataPath has to be exchanged with an existing one. + arg.Form("-entrytype ESD -entrytype HLTESD -entrytype MC -dataspec 0x0000001F -datapath /opt/HLT/analysis/HLT-HEAD_2008-09-24/exa -datapath /home/jthaeder/jet/data/test"); + // arg.Form("-entrytype ESD -entrytype HLTESD -entrytype MC -dataspec 0x0000001F -datapath mydatapath0 -datapath mydatapath1"); + + // -- The AliHLTESDMCEventPublisher (Id 'ESDMCEventPublisher') is a data source. + // It provides AliESDEvents and AliMCEvents out of the given datapaths to + // the subsequent components in the chain. + // see AliHLTESDMCEventPublisherComponent for more options + AliHLTConfiguration ESDMCEventPublisher("ESDMCEventPublisher", "ESDMCEventPublisher", NULL, arg.Data() ); + if (!writerInput.IsNull()) writerInput+=" "; + writerInput+="ESDMCEventPublisher"; + + // - + // -- Processing Components can be put in here + // - + + // -- The AliHLTRootFileWriter (Id 'ROOTFileWriter') is a data sink. It writes + // all incoming data blocks to files. Several options available. + AliHLTConfiguration rootWriter("RootWriter", "ROOTFileWriter", writerInput.Data(),"-datafile event"); + + // -- Here you specify the top most configuration of the chain. The + // configuration depends on all the parents. The task lisy is build + // according to that. + gHLT.BuildTaskList("RootWriter"); + gHLT.Run(nEvents); +} diff --git a/HLT/exa/rootfilepublisher.C b/HLT/exa/rootfilepublisher.C index b1482521e1d..75fe93c8e3e 100644 --- a/HLT/exa/rootfilepublisher.C +++ b/HLT/exa/rootfilepublisher.C @@ -1,4 +1,3 @@ - /** * @file rootfilepublisher-sample.C * @brief Macro for testing ROOT-file publishing and writing @@ -35,10 +34,12 @@ void rootfilepublisher(Int_t nEvents=1) { // !!! myRootFile.root has to be exchanged with an existing one. arg.Form("-objectname HLTesdTree -datatype 'ESD_TREE' 'TPC '-dataspec 0x00000000 -datafile myRootFile.root"); - // -- The AliHLTRootFilePublisher (component Id \em 'ROOTFilePublisher' provides - // the given file (see AliHLTRootFilePublisher for more options) to the - // subsequent components in the chain. - AliHLTConfiguration rootPublisher("RootPublisher", "ROOTFilePublisher", NULL, arg.Data() ); + // -- The AliHLTRootFilePublisher (Id 'ROOTFilePublisher') is a data source. + // It provides the given files to the subsequent components in the chain. + // see AliHLTRootFilePublisher for more options + AliHLTConfiguration RootPublisher("RootPublisher", "ROOTFilePublisher", NULL, arg.Data() ); + if (!writerInput.IsNull()) writerInput+=" "; + writerInput+="RootPublisher"; // - // -- Processing Components can be put in here @@ -46,8 +47,7 @@ void rootfilepublisher(Int_t nEvents=1) { // -- The AliHLTRootFileWriter (Id 'ROOTFileWriter') is a data sink. It writes // all incoming data blocks to files. Several options available. - // AliHLTConfiguration sink1("sink1", "FileWriter", "ESDPublisher", NULL); - AliHLTConfiguration rootWriter("RootWriter", "ROOTFileWriter", "RootPublisher","-datafile event"); + AliHLTConfiguration RootWriter("RootWriter", "ROOTFileWriter", writerInput.Data(),"-datafile event"); // -- Here you specify the top most configuration of the chain. The // configuration depends on all the parents. The task lisy is build diff --git a/HLT/libAliHLTUtil.pkg b/HLT/libAliHLTUtil.pkg index 6e0f7c792fe..eb0697a2488 100644 --- a/HLT/libAliHLTUtil.pkg +++ b/HLT/libAliHLTUtil.pkg @@ -4,6 +4,7 @@ CLASS_HDRS:= AliHLTFilePublisher.h \ AliHLTFileWriter.h \ AliHLTRootFilePublisherComponent.h \ + AliHLTESDMCEventPublisherComponent.h \ AliHLTRootFileWriterComponent.h \ AliHLTRootFileStreamerComponent.h \ AliHLTLoaderPublisherComponent.h \