diff --git a/Control/AthenaKernel/AthenaKernel/IMetaDataSvc.h b/Control/AthenaKernel/AthenaKernel/IMetaDataSvc.h index ec82de1182d47ea34d36ea20ad36c5f245305acf..bf81f6019be4a58f1906b467b20a6050295ec1c4 100644 --- a/Control/AthenaKernel/AthenaKernel/IMetaDataSvc.h +++ b/Control/AthenaKernel/AthenaKernel/IMetaDataSvc.h @@ -39,6 +39,10 @@ public: // Non-static members template <typename T, typename TKEY> StatusCode record(T* p2BRegistered, const TKEY& key); + /// Record an object with a key, take ownership of the unique_ptr obj + template <typename T, typename TKEY> + StatusCode record(std::unique_ptr<T> pUnique, const TKEY& key); + /// Remove object with this type+key template <typename T, typename TKEY> StatusCode remove(const TKEY& key, bool ignoreIfAbsent=false); @@ -103,6 +107,19 @@ StatusCode IMetaDataSvc::record(T* pObject, const TKEY& key) return StatusCode::FAILURE; } + +template <typename T, typename TKEY> +StatusCode IMetaDataSvc::record(std::unique_ptr<T> pUnique, const TKEY& key) +{ + if( this->record( pUnique.get(), key ).isSuccess() ) { + pUnique.release(); + return StatusCode::SUCCESS; + } + pUnique.reset(); + return StatusCode::FAILURE; +} + + template <typename T, class TKEY> StatusCode IMetaDataSvc::remove(const TKEY& key, bool ignoreIfAbsent) { diff --git a/Database/AthenaPOOL/OutputStreamAthenaPool/src/CopyEventStreamInfo.cxx b/Database/AthenaPOOL/OutputStreamAthenaPool/src/CopyEventStreamInfo.cxx index a9a7e911770e1fca860a8d7712728d85f018df56..2ea6e688543d509adf92df8ee97f7ad1cc68373c 100644 --- a/Database/AthenaPOOL/OutputStreamAthenaPool/src/CopyEventStreamInfo.cxx +++ b/Database/AthenaPOOL/OutputStreamAthenaPool/src/CopyEventStreamInfo.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ /** @file CopyEventStreamInfo.cxx @@ -17,7 +17,7 @@ CopyEventStreamInfo::CopyEventStreamInfo(const std::string& type, const std::string& name, const IInterface* parent) : ::AthAlgTool(type, name, parent), - m_metaDataStore("StoreGateSvc/MetaDataStore", name), + m_metaDataSvc("MetaDataSvc", name), m_inputMetaDataStore("StoreGateSvc/InputMetaDataStore", name) { // Declare IMetaDataTool interface declareInterface<IMetaDataTool>(this); @@ -31,9 +31,9 @@ CopyEventStreamInfo::~CopyEventStreamInfo() { //___________________________________________________________________________ StatusCode CopyEventStreamInfo::initialize() { ATH_MSG_INFO("Initializing " << name() << " - package version " << PACKAGE_VERSION); - // Locate the MetaDataStore and InputMetaDataStore - if (!m_metaDataStore.retrieve().isSuccess()) { - ATH_MSG_FATAL("Could not find MetaDataStore"); + // Locate the MetaDataSvc and InputMetaDataStore + if (!m_metaDataSvc.retrieve().isSuccess()) { + ATH_MSG_FATAL("Could not find MetaDataSvc"); return(StatusCode::FAILURE); } if (!m_inputMetaDataStore.retrieve().isSuccess()) { @@ -45,9 +45,9 @@ StatusCode CopyEventStreamInfo::initialize() { //___________________________________________________________________________ StatusCode CopyEventStreamInfo::finalize() { ATH_MSG_DEBUG("in finalize()"); - // release the MetaDataStore and InputMetaDataStore - if (!m_metaDataStore.release().isSuccess()) { - ATH_MSG_WARNING("Could not release MetaDataStore"); + // release the MetaDataSvc and InputMetaDataStore + if (!m_metaDataSvc.release().isSuccess()) { + ATH_MSG_WARNING("Could not release MetaDataSvc"); } if (!m_inputMetaDataStore.release().isSuccess()) { ATH_MSG_WARNING("Could not release InputMetaDataStore"); @@ -79,40 +79,37 @@ StatusCode CopyEventStreamInfo::beginInputFile(const SG::SourceID&) EventStreamInfo* evtStrInfo_out = 0; for (SG::ObjectWithVersion<EventStreamInfo>& obj : allVersions) { const EventStreamInfo* evtStrInfo_in = obj.dataObject.cptr(); - if (!m_metaDataStore->contains<EventStreamInfo>(key)) { - evtStrInfo_out = new EventStreamInfo(*evtStrInfo_in); - if (!m_metaDataStore->record(evtStrInfo_out, key).isSuccess()) { + evtStrInfo_out = m_metaDataSvc->tryRetrieve<EventStreamInfo>(key); + if( !evtStrInfo_out ) { + auto esinfo_up = std::make_unique<EventStreamInfo>(*evtStrInfo_in); + if( m_metaDataSvc->record( std::move(esinfo_up), key ).isFailure()) { ATH_MSG_ERROR("Could not record DataObject: " << key); return StatusCode::FAILURE; } } else { - if (!m_metaDataStore->retrieve(evtStrInfo_out, key).isSuccess()) { - ATH_MSG_ERROR("Could not find DataObject in output: " << key); - return StatusCode::FAILURE; - } evtStrInfo_out->addEvent(evtStrInfo_in->getNumberOfEvents()); for (auto elem = evtStrInfo_in->getRunNumbers().begin(), - lastElem = evtStrInfo_in->getRunNumbers().end(); + lastElem = evtStrInfo_in->getRunNumbers().end(); elem != lastElem; elem++) { - evtStrInfo_out->insertRunNumber(*elem); + evtStrInfo_out->insertRunNumber(*elem); } for (auto elem = evtStrInfo_in->getLumiBlockNumbers().begin(), - lastElem = evtStrInfo_in->getLumiBlockNumbers().end(); + lastElem = evtStrInfo_in->getLumiBlockNumbers().end(); elem != lastElem; elem++) { evtStrInfo_out->insertLumiBlockNumber(*elem); } for (auto elem = evtStrInfo_in->getProcessingTags().begin(), - lastElem = evtStrInfo_in->getProcessingTags().end(); + lastElem = evtStrInfo_in->getProcessingTags().end(); elem != lastElem; elem++) { evtStrInfo_out->insertProcessingTag(*elem); } for (auto elem = evtStrInfo_in->getItemList().begin(), - lastElem = evtStrInfo_in->getItemList().end(); + lastElem = evtStrInfo_in->getItemList().end(); elem != lastElem; elem++) { evtStrInfo_out->insertItemList((*elem).first, (*elem).second); } for (auto elem = evtStrInfo_in->getEventTypes().begin(), - lastElem = evtStrInfo_in->getEventTypes().end(); + lastElem = evtStrInfo_in->getEventTypes().end(); elem != lastElem; elem++) { evtStrInfo_out->insertEventType(*elem); } diff --git a/Database/AthenaPOOL/OutputStreamAthenaPool/src/CopyEventStreamInfo.h b/Database/AthenaPOOL/OutputStreamAthenaPool/src/CopyEventStreamInfo.h index 7d6e68dbf4e5eba29136726aeb9ff6a1373f63a9..43682f60954130197f0e45219fc232c6107e023a 100644 --- a/Database/AthenaPOOL/OutputStreamAthenaPool/src/CopyEventStreamInfo.h +++ b/Database/AthenaPOOL/OutputStreamAthenaPool/src/CopyEventStreamInfo.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #ifndef COPYEVENTSTREAMINFO_H @@ -15,6 +15,7 @@ #include "AthenaBaseComps/AthAlgTool.h" #include "AthenaKernel/IMetaDataTool.h" +#include "AthenaKernel/IMetaDataSvc.h" #include <string> @@ -48,8 +49,9 @@ private: /// Key, the StoreGate key for the EventStreamInfo object. StringProperty m_key; - /// Pointer to the metadata stores - ServiceHandle<StoreGateSvc> m_metaDataStore; + /// Access to output MetaDataStore through MetaDataSvc (using MetaContainers) + ServiceHandle<IMetaDataSvc> m_metaDataSvc; + /// MetaDataStore for input ServiceHandle<StoreGateSvc> m_inputMetaDataStore; }; #endif diff --git a/Database/AthenaPOOL/OutputStreamAthenaPool/src/MakeEventStreamInfo.cxx b/Database/AthenaPOOL/OutputStreamAthenaPool/src/MakeEventStreamInfo.cxx index 462cecda784ed2539a84345c27b075803770b15e..8b49f3e3ae13203315fd108dc7e33812616c297e 100644 --- a/Database/AthenaPOOL/OutputStreamAthenaPool/src/MakeEventStreamInfo.cxx +++ b/Database/AthenaPOOL/OutputStreamAthenaPool/src/MakeEventStreamInfo.cxx @@ -102,10 +102,10 @@ StatusCode MakeEventStreamInfo::postExecute() { EventStreamInfo* pEventStream = m_metaDataSvc->tryRetrieve<EventStreamInfo>(m_key.value()); if( !pEventStream ) { - pEventStream = new EventStreamInfo(); - if( m_metaDataSvc->record(pEventStream, m_key.value() ).isFailure()) { + auto esinfo_up = std::make_unique<EventStreamInfo>(); + pEventStream = esinfo_up.get(); + if( m_metaDataSvc->record(std::move(esinfo_up), m_key.value()).isFailure() ) { ATH_MSG_ERROR("Could not register EventStreamInfo object"); - delete pEventStream; return(StatusCode::FAILURE); } }