diff --git a/Database/AthenaPOOL/OutputStreamAthenaPool/src/CopyEventStreamInfo.cxx b/Database/AthenaPOOL/OutputStreamAthenaPool/src/CopyEventStreamInfo.cxx index a966b65e1692e7516940a367a3fbcd46cf00636b..6c324572f19999c9d8435c502800356513c50a27 100644 --- a/Database/AthenaPOOL/OutputStreamAthenaPool/src/CopyEventStreamInfo.cxx +++ b/Database/AthenaPOOL/OutputStreamAthenaPool/src/CopyEventStreamInfo.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ /** @file CopyEventStreamInfo.cxx @@ -10,48 +10,125 @@ #include "CopyEventStreamInfo.h" +#include "GaudiKernel/FileIncident.h" + +#include "EventInfo/EventStreamInfo.h" +#include "StoreGate/StoreGateSvc.h" //___________________________________________________________________________ CopyEventStreamInfo::CopyEventStreamInfo(const std::string& type, - const std::string& name, - const IInterface* parent) - : GenericMetadataToolNoAux <EventStreamInfo>(type, name, parent) -{ + const std::string& name, + const IInterface* parent) : ::AthAlgTool(type, name, parent), + m_metaDataStore("StoreGateSvc/MetaDataStore", name), + m_inputMetaDataStore("StoreGateSvc/InputMetaDataStore", name) { + // Declare IMetaDataTool interface + declareInterface<IMetaDataTool>(this); + + // Declare the properties + declareProperty("Key", m_key = std::string()); } //___________________________________________________________________________ CopyEventStreamInfo::~CopyEventStreamInfo() { } - - -StatusCode CopyEventStreamInfo::updateContainer( - EventStreamInfo* evtStrInfo_out, - const EventStreamInfo* evtStrInfo_in ) -{ - evtStrInfo_out->addEvent(evtStrInfo_in->getNumberOfEvents()); - for (auto elem = evtStrInfo_in->getRunNumbers().begin(), - lastElem = evtStrInfo_in->getRunNumbers().end(); - elem != lastElem; elem++) { - evtStrInfo_out->insertRunNumber(*elem); +//___________________________________________________________________________ +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"); + return(StatusCode::FAILURE); + } + if (!m_inputMetaDataStore.retrieve().isSuccess()) { + ATH_MSG_FATAL("Could not find InputMetaDataStore"); + return(StatusCode::FAILURE); } - for (auto elem = evtStrInfo_in->getLumiBlockNumbers().begin(), - lastElem = evtStrInfo_in->getLumiBlockNumbers().end(); - elem != lastElem; elem++) { - evtStrInfo_out->insertLumiBlockNumber(*elem); + return(StatusCode::SUCCESS); +} +//___________________________________________________________________________ +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"); } - for (auto elem = evtStrInfo_in->getProcessingTags().begin(), - lastElem = evtStrInfo_in->getProcessingTags().end(); - elem != lastElem; elem++) { - evtStrInfo_out->insertProcessingTag(*elem); + if (!m_inputMetaDataStore.release().isSuccess()) { + ATH_MSG_WARNING("Could not release InputMetaDataStore"); } - for (auto elem = evtStrInfo_in->getItemList().begin(), - lastElem = evtStrInfo_in->getItemList().end(); - elem != lastElem; elem++) { - evtStrInfo_out->insertItemList((*elem).first, (*elem).second); + return(StatusCode::SUCCESS); +} + + +StatusCode CopyEventStreamInfo::beginInputFile(const SG::SourceID&) +{ + std::vector<std::string> keys; + if (m_key.value().empty()) { + m_inputMetaDataStore->keys<EventStreamInfo>(keys); + } else { + keys.push_back(m_key); } - for (auto elem = evtStrInfo_in->getEventTypes().begin(), - lastElem = evtStrInfo_in->getEventTypes().end(); - elem != lastElem; elem++) { - evtStrInfo_out->insertEventType(*elem); + for (const auto &key : keys) { + // Ignore versioned container + if (key.substr(0, 1) == ";" && key.substr(3, 1) == ";") { + ATH_MSG_VERBOSE( "Ignore versioned container: " << key ); + continue; + } + if (m_inputMetaDataStore->contains<EventStreamInfo>(key)) { + std::list<SG::ObjectWithVersion<EventStreamInfo> > allVersions; + if (!m_inputMetaDataStore->retrieveAllVersions(allVersions, key).isSuccess()) { + ATH_MSG_ERROR("Could not retrieve all versions for EventStreamInfo"); + return StatusCode::FAILURE; + } + 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()) { + 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(); + elem != lastElem; elem++) { + evtStrInfo_out->insertRunNumber(*elem); + } + for (auto elem = evtStrInfo_in->getLumiBlockNumbers().begin(), + lastElem = evtStrInfo_in->getLumiBlockNumbers().end(); + elem != lastElem; elem++) { + evtStrInfo_out->insertLumiBlockNumber(*elem); + } + for (auto elem = evtStrInfo_in->getProcessingTags().begin(), + lastElem = evtStrInfo_in->getProcessingTags().end(); + elem != lastElem; elem++) { + evtStrInfo_out->insertProcessingTag(*elem); + } + for (auto elem = evtStrInfo_in->getItemList().begin(), + 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(); + elem != lastElem; elem++) { + evtStrInfo_out->insertEventType(*elem); + } + } + } + } } return(StatusCode::SUCCESS); } +StatusCode CopyEventStreamInfo::endInputFile(const SG::SourceID&) +{ + return(StatusCode::SUCCESS); +} +StatusCode CopyEventStreamInfo::metaDataStop() +{ + return(StatusCode::SUCCESS); +} diff --git a/Database/AthenaPOOL/OutputStreamAthenaPool/src/CopyEventStreamInfo.h b/Database/AthenaPOOL/OutputStreamAthenaPool/src/CopyEventStreamInfo.h index c47114f86e6d3b9c94aea8218d99d978fe191b3f..7d6e68dbf4e5eba29136726aeb9ff6a1373f63a9 100644 --- a/Database/AthenaPOOL/OutputStreamAthenaPool/src/CopyEventStreamInfo.h +++ b/Database/AthenaPOOL/OutputStreamAthenaPool/src/CopyEventStreamInfo.h @@ -4,13 +4,17 @@ #ifndef COPYEVENTSTREAMINFO_H #define COPYEVENTSTREAMINFO_H + /** @file CopyEventStreamInfo.h * @brief This file contains the class definition for the CopyEventStreamInfo class. * @author Peter van Gemmeren <gemmeren@anl.gov> **/ -#include "AthenaKernel/GenericMetadataToolNoAux.h" -#include "EventInfo/EventStreamInfo.h" +#include "GaudiKernel/ServiceHandle.h" + +#include "AthenaBaseComps/AthAlgTool.h" + +#include "AthenaKernel/IMetaDataTool.h" #include <string> @@ -19,21 +23,33 @@ class StoreGateSvc; /** @class CopyEventStreamInfo * @brief This class provides an algorithm to make the EventStreamInfo object and update it. **/ -class CopyEventStreamInfo : public GenericMetadataToolNoAux <EventStreamInfo> { +class CopyEventStreamInfo : public ::AthAlgTool, virtual public IMetaDataTool { public: /// Standard AlgTool Constructor - CopyEventStreamInfo(const std::string& type, - const std::string& name, - const IInterface* parent); + CopyEventStreamInfo(const std::string& type, const std::string& name, const IInterface* parent); /// Destructor virtual ~CopyEventStreamInfo(); /// AthAlgTool Interface method implementations: - //StatusCode initialize(); - //StatusCode finalize(); - /// Helper class to update a container with information from another one - virtual StatusCode updateContainer(EventStreamInfo* evtStrInfo_out, - const EventStreamInfo* evtStrInfo_in ); + StatusCode initialize(); + StatusCode finalize(); + + /// Function called when a new input file is opened + virtual StatusCode beginInputFile(const SG::SourceID& = "Serial"); + + /// Function called when the currently open input file got completely + /// processed + virtual StatusCode endInputFile(const SG::SourceID& = "Serial"); + + /// Function called when the tool should write out its metadata + virtual StatusCode metaDataStop(); + +private: + /// Key, the StoreGate key for the EventStreamInfo object. + StringProperty m_key; + /// Pointer to the metadata stores + ServiceHandle<StoreGateSvc> m_metaDataStore; + ServiceHandle<StoreGateSvc> m_inputMetaDataStore; }; #endif