diff --git a/Control/AthenaServices/src/MetaDataSvc.cxx b/Control/AthenaServices/src/MetaDataSvc.cxx index 95565c66cd655c7e7b8a2a5aefd551dc4392b01c..06394b63e3f2cda4ed299a94b91eaccf472bef6d 100644 --- a/Control/AthenaServices/src/MetaDataSvc.cxx +++ b/Control/AthenaServices/src/MetaDataSvc.cxx @@ -72,6 +72,7 @@ MetaDataSvc::MetaDataSvc(const std::string& name, ISvcLocator* pSvcLocator) : :: m_toolForClid.insert(std::pair<CLID, std::string>(1234982351, "BookkeeperTool")); m_toolForClid.insert(std::pair<CLID, std::string>(1107011239, "xAODMaker::TriggerMenuMetaDataTool")); m_toolForClid.insert(std::pair<CLID, std::string>(1115934851, "LumiBlockMetaDataTool")); + m_toolForClid.insert(std::pair<CLID, std::string>(1188015687, "xAODMaker::TruthMetaDataTool")); } //__________________________________________________________________________ MetaDataSvc::~MetaDataSvc() { @@ -381,9 +382,6 @@ StatusCode MetaDataSvc::addProxyToInputMetaDataStore(const std::string& tokenStr std::istringstream iss(numName); iss >> num; CLID clid = m_persToClid[className]; - const std::string par[2] = { "SHM" , className }; - const unsigned long ipar[2] = { num , 0 }; - IOpaqueAddress* opqAddr = nullptr; if (clid == 167728019) { // EventStreamInfo, will change tool to combine input metadata, clearing things before... bool foundTool = false; for (ToolHandleArray<IAlgTool>::const_iterator iter = m_metaDataTools.begin(), iterEnd = m_metaDataTools.end(); iter != iterEnd; iter++) { @@ -418,7 +416,9 @@ StatusCode MetaDataSvc::addProxyToInputMetaDataStore(const std::string& tokenStr } } } - + const std::string par[3] = { "SHM" , keyName , className }; + const unsigned long ipar[2] = { num , 0 }; + IOpaqueAddress* opqAddr = nullptr; if (!m_addrCrtr->createAddress(m_storageType, clid, par, ipar, opqAddr).isSuccess()) { ATH_MSG_FATAL("addProxyToInputMetaDataStore: Cannot create address for " << tokenStr); return(StatusCode::FAILURE); @@ -432,6 +432,9 @@ StatusCode MetaDataSvc::addProxyToInputMetaDataStore(const std::string& tokenStr ATH_MSG_FATAL("addProxyToInputMetaDataStore: Cannot access data for " << tokenStr); return(StatusCode::FAILURE); } + if (keyName.find("Aux.") != std::string::npos && m_inputDataStore->symLink (clid, keyName, 187169987).isFailure()) { + ATH_MSG_WARNING("addProxyToInputMetaDataStore: Cannot symlink to AuxStore for " << tokenStr); + } std::map<std::string, std::string>::const_iterator iter = m_streamForKey.find(keyName); if (iter == m_streamForKey.end()) { m_streamForKey.insert(std::pair<std::string, std::string>(keyName, fileName)); diff --git a/Database/AthenaPOOL/AthenaPoolCnvSvc/src/AthenaPoolCnvSvc.cxx b/Database/AthenaPOOL/AthenaPoolCnvSvc/src/AthenaPoolCnvSvc.cxx index fb79bfceca1a75011805d82b25cff11494aa2436..78471af3f272d728b5d3cabb81fbd014ced8650e 100644 --- a/Database/AthenaPOOL/AthenaPoolCnvSvc/src/AthenaPoolCnvSvc.cxx +++ b/Database/AthenaPOOL/AthenaPoolCnvSvc/src/AthenaPoolCnvSvc.cxx @@ -838,8 +838,8 @@ StatusCode AthenaPoolCnvSvc::createAddress(long svcType, if (par[0] == "SHM") { token = new Token(); token->setOid(Token::OID_t(ip[0], ip[1])); - token->setAuxString("[PNAME=" + par[1] + "]"); - RootType classDesc = RootType::ByName(par[1]); + token->setAuxString("[PNAME=" + par[2] + "]"); + RootType classDesc = RootType::ByName(par[2]); token->setClassID(pool::DbReflex::guid(classDesc)); } else if (!m_inputStreamingTool.empty() && m_inputStreamingTool->isClient()) { Token addressToken; @@ -873,7 +873,7 @@ StatusCode AthenaPoolCnvSvc::createAddress(long svcType, if (token == nullptr) { return(StatusCode::RECOVERABLE); } - refpAddress = new TokenAddress(POOL_StorageType, clid, "", "", 0, token); + refpAddress = new TokenAddress(POOL_StorageType, clid, "", par[1], ip[0], token); return(StatusCode::SUCCESS); } //______________________________________________________________________________ diff --git a/Event/xAOD/xAODTruth/xAODTruth/selection.xml b/Event/xAOD/xAODTruth/xAODTruth/selection.xml index 20d274ba2e4c288015d6cb25a50c8a93bca4dea8..abd3914cc9dc22eb499e32663223671bd17455b1 100644 --- a/Event/xAOD/xAODTruth/xAODTruth/selection.xml +++ b/Event/xAOD/xAODTruth/xAODTruth/selection.xml @@ -32,6 +32,7 @@ <class name="xAOD::TruthEvent_v1" /> <class name="xAOD::TruthPileupEvent_v1" /> <class name="xAOD::TruthEvent_v1::PdfInfo" /> + <class name="xAOD::TruthMetaData_v1" /> <!-- The persistent classes: --> <class name="xAOD::TruthParticleContainer_v1" diff --git a/Event/xAOD/xAODTruthCnv/CMakeLists.txt b/Event/xAOD/xAODTruthCnv/CMakeLists.txt index 1e263b057c6b49bdb8b509e71064e8c8eaeaa259..89b82f15bba80e7f966914dc5f5ad673e9664401 100644 --- a/Event/xAOD/xAODTruthCnv/CMakeLists.txt +++ b/Event/xAOD/xAODTruthCnv/CMakeLists.txt @@ -5,29 +5,47 @@ # Declare the package name: atlas_subdir( xAODTruthCnv ) -# Declare the package's dependencies: -atlas_depends_on_subdirs( PRIVATE - Control/AthenaBaseComps - Control/AthenaKernel - Control/DataModel - Control/StoreGate - Event/EventInfo - Event/xAOD/xAODEventInfo - Event/xAOD/xAODTruth - GaudiKernel - Generators/GeneratorObjects ) +# Extra package dependencies, based on the build environment: +set( extra_dep ) +if( NOT XAOD_STANDALONE ) + set( extra_dep Database/AthenaPOOL/AthenaPoolKernel + PRIVATE + Control/AthLinks + Control/AthenaBaseComps + Control/StoreGate + Event/EventInfo + Event/xAOD/xAODEventInfo + Event/xAOD/xAODTruth + GaudiKernel + Generators/GeneratorObjects ) +endif() -# External dependencies: -find_package( ROOT COMPONENTS Core Tree MathCore Hist RIO pthread ) +# Declare the package's dependencies: +atlas_depends_on_subdirs( + PUBLIC + Control/AthToolSupport/AsgTools + Event/xAOD/xAODTruth + ${extra_dep} ) # Component(s) in the package: -atlas_add_component( xAODTruthCnv - src/*.cxx - src/components/*.cxx - INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} - LINK_LIBRARIES ${ROOT_LIBRARIES} AthenaBaseComps AthenaKernel DataModel StoreGateLib SGtests EventInfo xAODEventInfo xAODTruth GaudiKernel GeneratorObjects ) +atlas_add_library( xAODTruthCnvLib + xAODTruthCnv/*.h Root/*.cxx + PUBLIC_HEADERS xAODTruthCnv + LINK_LIBRARIES AsgTools xAODTruth ) + +if( NOT XAOD_STANDALONE ) + atlas_add_component( xAODTruthCnv + src/*.h src/*.cxx src/components/*.cxx + LINK_LIBRARIES AthLinks AthenaBaseComps StoreGateLib EventInfo + xAODEventInfo xAODTruth GaudiKernel GeneratorObjects + xAODTruthCnvLib ) +endif() + +atlas_add_dictionary( xAODTruthCnvDict + xAODTruthCnv/xAODTruthCnvDict.h + xAODTruthCnv/selection.xml + LINK_LIBRARIES xAODTruthCnvLib ) # Install files from the package: atlas_install_joboptions( share/*.py ) atlas_install_python_modules( python/*.py ) - diff --git a/Event/xAOD/xAODTruthCnv/Root/TruthMetaDataTool.cxx b/Event/xAOD/xAODTruthCnv/Root/TruthMetaDataTool.cxx new file mode 100644 index 0000000000000000000000000000000000000000..ba3b829a746531a0df3c94c7185e585b652967b9 --- /dev/null +++ b/Event/xAOD/xAODTruthCnv/Root/TruthMetaDataTool.cxx @@ -0,0 +1,109 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// Local include(s): +#include "xAODTruthCnv/TruthMetaDataTool.h" + +namespace xAODMaker { + + // Helper typedef: + typedef xAOD::TruthMetaDataContainer Cont_t; + + TruthMetaDataTool::TruthMetaDataTool( const std::string& name ) + : asg::AsgMetadataTool( name ), + m_truthMeta(), m_truthMetaAux() { + + declareProperty( "InputKey", m_inputKey = "TruthMetaData" ); + declareProperty( "OutputKey", m_outputKey = "TruthMetaData" ); + +#ifdef ASGTOOL_ATHENA + declareInterface< ::IMetaDataTool >( this ); +#endif // ASGTOOL_ATHENA + } + + StatusCode TruthMetaDataTool::initialize() { + + // Greet the user: + ATH_MSG_DEBUG( "Initialising TruthMetaDataTool" ); + ATH_MSG_DEBUG( " InputKey = " << m_inputKey ); + ATH_MSG_DEBUG( " OutputKey = " << m_outputKey ); + + // Reset the internal variable(s): + m_truthMeta.reset(); m_truthMetaAux.reset(); + + // Retrun gracefully: + return StatusCode::SUCCESS; + } + + StatusCode TruthMetaDataTool::beginInputFile() { + + // If the input file doesn't have any trigger configuration metadata, + // then finish right away: + if( ! inputMetaStore()->contains< Cont_t >( m_inputKey ) ) { + return StatusCode::SUCCESS; + } + + // Retrieve the input container: + const Cont_t* input = 0; + ATH_CHECK( inputMetaStore()->retrieve( input, m_inputKey ) ); + + // Create an output container if it doesn't exist yet: + if( ( ! m_truthMeta.get() ) && ( ! m_truthMetaAux.get() ) ) { + ATH_MSG_DEBUG( "Creating output container" ); + m_truthMeta.reset( new xAOD::TruthMetaDataContainer() ); + m_truthMetaAux.reset( new xAOD::TruthMetaDataAuxContainer() ); + m_truthMeta->setStore( m_truthMetaAux.get() ); + } + + // Loop over the configurations of the input file: + for( const xAOD::TruthMetaData* meta : *input ) { + + // Check if this configuration is already in the output container: + bool exists = false; + for( const xAOD::TruthMetaData* existing : *m_truthMeta ) { + if( existing->mcChannelNumber() == meta->mcChannelNumber() ){ + exists = true; + break; + } + } + if( exists ) { + continue; + } + + // If it's a new configuration, put it into the output container: + ATH_MSG_VERBOSE( "Copying configuration with ChannelID: " + << meta->mcChannelNumber() ); + xAOD::TruthMetaData* out = new xAOD::TruthMetaData(); + m_truthMeta->push_back( out ); + *out = *meta; + } + + // Return gracefully: + return StatusCode::SUCCESS; + } + + StatusCode TruthMetaDataTool::metaDataStop() { + + // The output may already have trigger configuration metadata in it. + // For instance from TrigConf::xAODMenuWriter. In this case let that + // object take precedence. + if( outputMetaStore()->contains< Cont_t >( m_outputKey ) ) { + ATH_MSG_DEBUG( "xAOD::TruthMetaDataContainer already in the output" ); + return StatusCode::SUCCESS; + } + + // Record the truth metadata, if any was found in the processed input files. + if( m_truthMeta.get() && m_truthMetaAux.get() ) { + ATH_MSG_DEBUG( "Recording truth metadata" ); + ATH_CHECK( outputMetaStore()->record( m_truthMeta.release(), + m_outputKey ) ); + ATH_CHECK( outputMetaStore()->record( m_truthMetaAux.release(), + m_outputKey + "Aux." ) ); + } + + // Retrun gracefully: + return StatusCode::SUCCESS; + } + +} // namespace xAODMaker diff --git a/Event/xAOD/xAODTruthCnv/src/components/xAODTruthCnv_entries.cxx b/Event/xAOD/xAODTruthCnv/src/components/xAODTruthCnv_entries.cxx index afb6cd10d2700a9778bcff7bcc785b0e66e742ed..5428eb4532786278fd108171eba15c425e6379d7 100644 --- a/Event/xAOD/xAODTruthCnv/src/components/xAODTruthCnv_entries.cxx +++ b/Event/xAOD/xAODTruthCnv/src/components/xAODTruthCnv_entries.cxx @@ -2,12 +2,14 @@ // Local include(s): #include "../xAODTruthCnvAlg.h" +#include "xAODTruthCnv/TruthMetaDataTool.h" #include "../xAODTruthReader.h" #include "../HepMCTruthReader.h" DECLARE_NAMESPACE_ALGORITHM_FACTORY( xAODMaker, xAODTruthCnvAlg ) DECLARE_NAMESPACE_ALGORITHM_FACTORY( xAODReader, xAODTruthReader ) DECLARE_ALGORITHM_FACTORY( HepMCTruthReader ) +DECLARE_NAMESPACE_TOOL_FACTORY( xAODMaker, TruthMetaDataTool ) DECLARE_FACTORY_ENTRIES( xAODCreatorAlgs ) { DECLARE_NAMESPACE_ALGORITHM( xAODMaker, xAODTruthCnvAlg ) @@ -16,5 +18,5 @@ DECLARE_FACTORY_ENTRIES( xAODCreatorAlgs ) { DECLARE_FACTORY_ENTRIES( xAODTruthCnv ) { DECLARE_ALGORITHM( HepMCTruthReader ) + DECLARE_NAMESPACE_TOOL( xAODMaker, TruthMetaDataTool ) } - diff --git a/Event/xAOD/xAODTruthCnv/xAODTruthCnv/TruthMetaDataTool.h b/Event/xAOD/xAODTruthCnv/xAODTruthCnv/TruthMetaDataTool.h new file mode 100644 index 0000000000000000000000000000000000000000..d240b8f55194151c0d619f5010b60104d4c43ad8 --- /dev/null +++ b/Event/xAOD/xAODTruthCnv/xAODTruthCnv/TruthMetaDataTool.h @@ -0,0 +1,84 @@ +// Dear emacs, this is -*- c++ -*- +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef XAODTRUTHCNV_TRUTHMETADATATOOL_H +#define XAODTRUTHCNV_TRUTHMETADATATOOL_H + +// System include(s): +#include <string> +#include <memory> + +// Gaudi/Athena include(s): +#include "AsgTools/AsgMetadataTool.h" +#ifdef ASGTOOL_ATHENA +# include "AthenaPoolKernel/IMetaDataTool.h" +#endif // ASGTOOL_ATHENA + +// EDM include(s): +#include "xAODTruth/TruthMetaDataContainer.h" +#include "xAODTruth/TruthMetaDataAuxContainer.h" + +namespace xAODMaker { + + /// Tool taking care of copying the truth metadata from file to file + /// + /// This tool does the heavy lifting when creating/merging DxAOD files to + /// make sure that the truth metadata ends up in the output. + /// + class TruthMetaDataTool : public asg::AsgMetadataTool +#ifdef ASGTOOL_ATHENA + , public virtual ::IMetaDataTool +#endif // ASGTOOL_ATHENA + { + + /// Declare the correct constructor for Athena + ASG_TOOL_CLASS0( TruthMetaDataTool ) + + public: + /// Regular AlgTool constructor + TruthMetaDataTool( const std::string& name = "TruthMetaDataTool" ); + + /// Function initialising the tool + virtual StatusCode initialize(); + + protected: + /// @name Functions called by the AsgMetadataTool base class + /// @{ + + /// Function collecting the configuration metadata from the input + /// file + virtual StatusCode beginInputFile(); + + /// Function writing out the collected metadata + virtual StatusCode metaDataStop(); + + /// @} + + private: + /// @name Tool properties + /// @{ + + /// The key of the truth metadata in the input file + std::string m_inputKey; + /// The key of the truth metadata for the output file + std::string m_outputKey; + + /// @} + + /// @name Objects accummulating the merged metadata + /// @{ + + /// The merged trigger menu container + std::unique_ptr< xAOD::TruthMetaDataContainer > m_truthMeta; + /// The merged trigger menu auxiliary container + std::unique_ptr< xAOD::TruthMetaDataAuxContainer > m_truthMetaAux; + + /// @} + + }; // class TruthMetaDataTool + +} // namespace xAODMaker + +#endif // XAODTRUTHCNV_TRUTHMETADATATOOL_H diff --git a/Event/xAOD/xAODTruthCnv/xAODTruthCnv/selection.xml b/Event/xAOD/xAODTruthCnv/xAODTruthCnv/selection.xml new file mode 100644 index 0000000000000000000000000000000000000000..a56d7b3296047f6d71dee74a416f4cbb28655ef6 --- /dev/null +++ b/Event/xAOD/xAODTruthCnv/xAODTruthCnv/selection.xml @@ -0,0 +1,5 @@ +<lcgdict> + + <class name="xAODMaker::TruthMetaDataTool" /> + +</lcgdict> diff --git a/Event/xAOD/xAODTruthCnv/xAODTruthCnv/xAODTruthCnvDict.h b/Event/xAOD/xAODTruthCnv/xAODTruthCnv/xAODTruthCnvDict.h new file mode 100644 index 0000000000000000000000000000000000000000..b0021f1e8e53dfda76d764ccc46208421ed2cd66 --- /dev/null +++ b/Event/xAOD/xAODTruthCnv/xAODTruthCnv/xAODTruthCnvDict.h @@ -0,0 +1,11 @@ +// Dear emacs, this is -*- c++ -*- +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ +#ifndef XAODTRUTHCNV_XAODTRUTHCNVDICT_H +#define XAODTRUTHCNV_XAODTRUTHCNVDICT_H + +// Local include(s): +#include "xAODTruthCnv/TruthMetaDataTool.h" + +#endif // XAODTRUTHCNV_XAODTRUTHCNVDICT_H