diff --git a/Event/ByteStreamCnvSvc/ByteStreamCnvSvc/ByteStreamInputSvc.h b/Event/ByteStreamCnvSvc/ByteStreamCnvSvc/ByteStreamInputSvc.h index 2718e1f6c8f22ed405b64524ddf363a5d462c326..377473a07b910a282dde981debe7802cf8d198c3 100644 --- a/Event/ByteStreamCnvSvc/ByteStreamCnvSvc/ByteStreamInputSvc.h +++ b/Event/ByteStreamCnvSvc/ByteStreamCnvSvc/ByteStreamInputSvc.h @@ -38,7 +38,7 @@ public: virtual const RawEvent* currentEvent() const = 0; /// virtual method for accessing the current event status virtual unsigned int currentEventStatus() const; - virtual long getBlockIterator(const std::string /* file */); + virtual std::pair<long,std::string> getBlockIterator(const std::string /* file */); virtual void closeBlockIterator(bool); virtual bool ready(); virtual StatusCode generateDataHeader(); @@ -57,7 +57,7 @@ inline unsigned int ByteStreamInputSvc::currentEventStatus() const { } // Virtual methods needed for file input -inline long ByteStreamInputSvc::getBlockIterator(const std::string /* file */) {return -1;} +inline std::pair<long,std::string> ByteStreamInputSvc::getBlockIterator(const std::string /* file */) {return std::make_pair(-1,"GUID");} inline void ByteStreamInputSvc::closeBlockIterator(bool) {} inline bool ByteStreamInputSvc::ready() {return false;} inline StatusCode ByteStreamInputSvc::generateDataHeader() {return StatusCode::SUCCESS;} diff --git a/Event/ByteStreamCnvSvc/python/ByteStreamConfig.py b/Event/ByteStreamCnvSvc/python/ByteStreamConfig.py index 36bb8fab6cdfe151b1c559e217e0172beab809e9..584ed0078ae62600d75dbec1cb51971e1047cc4b 100644 --- a/Event/ByteStreamCnvSvc/python/ByteStreamConfig.py +++ b/Event/ByteStreamCnvSvc/python/ByteStreamConfig.py @@ -50,8 +50,6 @@ def TrigBSReadCfg( inputFlags ): from ByteStreamCnvSvc.ByteStreamCnvSvcConf import ByteStreamMetadataTool bsMetaDataTool = ByteStreamMetadataTool() - bsMetaDataTool.InputCollName = "ByteStreamMetadata" - bsMetaDataTool.OutputCollName = "ByteStreamMetadata" acc.addPublicTool( bsMetaDataTool ) from StoreGate.StoreGateConf import ProxyProviderSvc, StoreGateSvc @@ -123,3 +121,4 @@ if __name__ == "__main__": acc = TrigBSReadCfg( ConfigFlags ) acc.store( file( "test.pkl", "w" ) ) print "All OK" + diff --git a/Event/ByteStreamCnvSvc/python/ReadByteStream.py b/Event/ByteStreamCnvSvc/python/ReadByteStream.py index f6fab4ce1083699bd29c71ad41342eb2ece50ff7..0c5653caa2ff65c1de138fcabb5d581a6939ee71 100644 --- a/Event/ByteStreamCnvSvc/python/ReadByteStream.py +++ b/Event/ByteStreamCnvSvc/python/ReadByteStream.py @@ -67,9 +67,8 @@ if not hasattr (svcMgr.ToolSvc, 'IOVDbMetaDataTool'): svcMgr.MetaDataSvc.MetaDataTools += [ "ByteStreamMetadataTool" ] if not hasattr (svcMgr.ToolSvc, 'ByteStreamMetadataTool'): svcMgr.ToolSvc += CfgMgr.ByteStreamMetadataTool() - svcMgr.ToolSvc.ByteStreamMetadataTool.InputCollName = "ByteStreamMetadata" - svcMgr.ToolSvc.ByteStreamMetadataTool.OutputCollName = "ByteStreamMetadata" # User metadata in FMD if not hasattr (svcMgr, 'ByteStreamAttListMetadataSvc'): svcMgr += CfgMgr.ByteStreamAttListMetadataSvc ("ByteStreamAttListMetadataSvc") + diff --git a/Event/ByteStreamCnvSvc/src/ByteStreamEventStorageInputSvc.cxx b/Event/ByteStreamCnvSvc/src/ByteStreamEventStorageInputSvc.cxx index 4a7511a92fcaf0b756430f029f486d3f1e08e6ca..01a7d4549a2e4a4d3ae64c1cc2dae97eb0aef86a 100644 --- a/Event/ByteStreamCnvSvc/src/ByteStreamEventStorageInputSvc.cxx +++ b/Event/ByteStreamCnvSvc/src/ByteStreamEventStorageInputSvc.cxx @@ -598,7 +598,7 @@ bool ByteStreamEventStorageInputSvc::ready() } //__________________________________________________________________________ -long ByteStreamEventStorageInputSvc::getBlockIterator(const std::string fileName) +std::pair<long,std::string> ByteStreamEventStorageInputSvc::getBlockIterator(const std::string fileName) { m_fullFile = fileName; @@ -608,7 +608,7 @@ long ByteStreamEventStorageInputSvc::getBlockIterator(const std::string fileName if (!m_reader) { ATH_MSG_ERROR("Failed to open file " << fileName); closeBlockIterator(); - return -1; + return std::make_pair(-1,"END"); } // Initilaize offset vector m_evtOffsets.resize(m_reader->eventsInFile(), -1); @@ -622,12 +622,12 @@ long ByteStreamEventStorageInputSvc::getBlockIterator(const std::string fileName // enable sequentialReading if multiple files if (m_sequential) { bool test = setSequentialRead(); - if (!test) return -1; + if (!test) return std::make_pair(-1,"SEQ"); } ATH_MSG_INFO("Picked valid file: " << m_reader->fileName()); // initialize offsets and counters m_evtOffsets.push_back((long long)m_reader->getPosition()); - return m_reader->eventsInFile(); + return std::make_pair(m_reader->eventsInFile(),m_reader->GUID());; } //__________________________________________________________________________ diff --git a/Event/ByteStreamCnvSvc/src/ByteStreamEventStorageInputSvc.h b/Event/ByteStreamCnvSvc/src/ByteStreamEventStorageInputSvc.h index b54252a8cf22d889ac1ca5aab9233281de41fec6..4f25b662c2c455b466096b41f88c2e48c9820e3c 100644 --- a/Event/ByteStreamCnvSvc/src/ByteStreamEventStorageInputSvc.h +++ b/Event/ByteStreamCnvSvc/src/ByteStreamEventStorageInputSvc.h @@ -57,7 +57,7 @@ public: virtual long positionInBlock(); - virtual long getBlockIterator(const std::string fileName); + virtual std::pair<long,std::string> getBlockIterator(const std::string fileName); void closeBlockIterator(bool clearMetadata=true); bool setSequentialRead(); bool ready(); diff --git a/Event/ByteStreamCnvSvc/src/ByteStreamMetadataTool.cxx b/Event/ByteStreamCnvSvc/src/ByteStreamMetadataTool.cxx index d9dc41baaa81c24c0861fd207b3c30618a31ee0c..fb3934a4da323d62ba6331287c0715fafa4725f0 100644 --- a/Event/ByteStreamCnvSvc/src/ByteStreamMetadataTool.cxx +++ b/Event/ByteStreamCnvSvc/src/ByteStreamMetadataTool.cxx @@ -10,15 +10,19 @@ #include "ByteStreamMetadataTool.h" +//#include "GaudiKernel/IIncidentSvc.h" +//#include "GaudiKernel/FileIncident.h" + +#include "ByteStreamData/ByteStreamMetadataContainer.h" +#include "StoreGate/StoreGateSvc.h" + //___________________________________________________________________________ ByteStreamMetadataTool::ByteStreamMetadataTool(const std::string& type, - const std::string& name, - const IInterface* parent) - : GenericMetadataToolNoAux <ByteStreamMetadataContainer>(type, name, parent) -{ - m_inputCollName="ByteStreamMetadata"; - m_outputCollName="ByteStreamMetadata"; - m_markIncomplete=false; + const std::string& name, + const IInterface* parent) : AthAlgTool(type, name, parent), + m_pMetaDataStore("StoreGateSvc/MetaDataStore", name), + m_pInputStore("StoreGateSvc/InputMetaDataStore", name) { + declareInterface<IMetaDataTool>(this); } //___________________________________________________________________________ @@ -28,46 +32,139 @@ ByteStreamMetadataTool::~ByteStreamMetadataTool() { //___________________________________________________________________________ StatusCode ByteStreamMetadataTool::initialize() { ATH_MSG_INFO("Initializing " << name() << " - package version " << PACKAGE_VERSION); + if (!::AthAlgTool::initialize().isSuccess()) { + ATH_MSG_FATAL("Cannot initialize AthService base class."); + return(StatusCode::FAILURE); + } + + // locate the DetectorStore and initialize our local ptr + StatusCode status = m_pMetaDataStore.retrieve(); + if (!status.isSuccess() || 0 == m_pMetaDataStore) { + ATH_MSG_ERROR("Could not find MetaDataStore"); + return(status); + } + status = m_pInputStore.retrieve(); + if (!status.isSuccess() || 0 == m_pInputStore) { + ATH_MSG_ERROR("Could not find InputMetaDataStore"); + return(status); + } return(StatusCode::SUCCESS); } //___________________________________________________________________________ StatusCode ByteStreamMetadataTool::finalize() { ATH_MSG_INFO("in finalize()"); - return(StatusCode::SUCCESS); + return(::AthAlgTool::finalize()); } -StatusCode ByteStreamMetadataTool::updateContainer( - ByteStreamMetadataContainer* bsmdc_out, - const ByteStreamMetadataContainer* bsmdc_in ) +StatusCode ByteStreamMetadataTool::beginInputFile(const SG::SourceID&) +{ + return this->beginInputFile(); +} + +StatusCode ByteStreamMetadataTool::beginInputFile() { + std::vector<std::string> vKeys; + std::set<std::string> keys; + m_pInputStore->keys<ByteStreamMetadata>(vKeys); + keys.insert(vKeys.begin(), vKeys.end()); + m_pInputStore->keys<ByteStreamMetadataContainer>(vKeys); + keys.insert(vKeys.begin(), vKeys.end()); + std::vector<ByteStreamMetadata*> copy; std::set<std::string> transGuids; - - // Put input into vector of components - for (const ByteStreamMetadata* md : *bsmdc_in) { - copy.push_back(new ByteStreamMetadata(*md)); - } - // If anything was in the input, copy to output - if (!copy.empty()) { - transGuids.clear(); - // Check for existing guid in output container - for (auto iter = bsmdc_out->begin(), iterEnd = bsmdc_out->end(); - iter != iterEnd; iter++) { - transGuids.insert((*iter)->getGuid()); + for (std::set<std::string>::const_iterator keyIter = keys.begin(), keyEnd = keys.end(); + keyIter != keyEnd; keyIter++) { + ATH_MSG_DEBUG("Processing Input ByteStreamMetadata, key = " << *keyIter); + copy.clear(); + if (m_pInputStore->contains<ByteStreamMetadata>(*keyIter)) { + std::list<SG::ObjectWithVersion<ByteStreamMetadata> > allVersions; + StatusCode status = m_pInputStore->retrieveAllVersions(allVersions, *keyIter); + if (!status.isSuccess()) { + ATH_MSG_ERROR("Could not find Input ByteStreamMetadata"); + return StatusCode::FAILURE; + } else { + ATH_MSG_DEBUG("Found Input ByteStreamMetadata"); + } + for (SG::ObjectWithVersion<ByteStreamMetadata>& obj : allVersions) { + copy.push_back(new ByteStreamMetadata(*obj.dataObject)); + } } - for (auto iter = copy.begin(), iterEnd = copy.end(); - iter != iterEnd; iter++) { - // Only insert new metadata records (with GUID not yet in container) - if (transGuids.insert((*iter)->getGuid()).second) { - bsmdc_out->push_back(*iter); - *iter = 0; + if (m_pInputStore->contains<ByteStreamMetadataContainer>(*keyIter)) { + std::list<SG::ObjectWithVersion<ByteStreamMetadataContainer> > allVersions; + StatusCode status = m_pInputStore->retrieveAllVersions(allVersions, *keyIter); + if (!status.isSuccess()) { + ATH_MSG_ERROR("Could not find Input ByteStreamMetadataContainer"); + return StatusCode::FAILURE; } else { - delete *iter; *iter = 0; + ATH_MSG_DEBUG("Found Input ByteStreamMetadataContainer"); + } + for (SG::ObjectWithVersion<ByteStreamMetadataContainer>& obj : allVersions) { + const ByteStreamMetadataContainer& bsmdc = *obj.dataObject; + for (const ByteStreamMetadata* md : bsmdc) { + copy.push_back(new ByteStreamMetadata(*md)); + } + } + } + if (!copy.empty()) { + transGuids.clear(); + // Check for existing container + ByteStreamMetadataContainer* bsmdc = 0; + if (m_pMetaDataStore->contains<ByteStreamMetadataContainer>(*keyIter)) { + ATH_MSG_DEBUG("Pre-existing ByteStreamMetadataContainer found"); + StatusCode status = m_pMetaDataStore->retrieve(bsmdc, *keyIter); + if (!status.isSuccess()) { + ATH_MSG_ERROR("Could not retrieve " << *keyIter << " ByteStreamMetadataContainer"); + return StatusCode::FAILURE; + } + for (ByteStreamMetadataContainer::const_iterator iter = bsmdc->begin(), iterEnd = bsmdc->end(); + iter != iterEnd; iter++) { + transGuids.insert((*iter)->getGuid()); + } + } else { + bsmdc = new ByteStreamMetadataContainer; + StatusCode status = m_pMetaDataStore->record(bsmdc, *keyIter); + if (!status.isSuccess()) { + ATH_MSG_ERROR("Could not store ByteStreamMetadata in Metadata store"); + return StatusCode::FAILURE; + } else { + ATH_MSG_DEBUG("ByteStreamMetadata copied to MetaDataStore"); + } + } + for (std::vector<ByteStreamMetadata*>::iterator iter = copy.begin(), iterEnd = copy.end(); + iter != iterEnd; iter++) { + // Only insert new metadata records (with GUID not yet in container) + if (transGuids.insert((*iter)->getGuid()).second) { + bsmdc->push_back(*iter); + *iter = 0; + } else { + delete *iter; *iter = 0; + } } } } return StatusCode::SUCCESS; } + +StatusCode ByteStreamMetadataTool::endInputFile(const SG::SourceID&) +{ + return StatusCode::SUCCESS; +} + +StatusCode ByteStreamMetadataTool::endInputFile() +{ + return StatusCode::SUCCESS; +} + +StatusCode ByteStreamMetadataTool::metaDataStop(const SG::SourceID&) +{ + return StatusCode::SUCCESS; +} + +StatusCode ByteStreamMetadataTool::metaDataStop() +{ + return StatusCode::SUCCESS; +} + diff --git a/Event/ByteStreamCnvSvc/src/ByteStreamMetadataTool.h b/Event/ByteStreamCnvSvc/src/ByteStreamMetadataTool.h index f2a2d3853c3a9fc160a74b8cc0a4e566d707c748..6a2ff656b363aed7b71056fea8dc99534645698d 100644 --- a/Event/ByteStreamCnvSvc/src/ByteStreamMetadataTool.h +++ b/Event/ByteStreamCnvSvc/src/ByteStreamMetadataTool.h @@ -1,21 +1,20 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration */ #ifndef BYTESTREAMMETADATATOOL_H #define BYTESTREAMMETADATATOOL_H /** @file ByteStreamMetadataTool.h - * @brief This class is an implementation of the GenericMetadataToolNoAux - * for the ByteStreamMetadataContainer. + * @brief This file contains the class definition for the ByteStreamMetadataTool class. * @author Peter van Gemmeren <gemmeren@anl.gov> * $Id: $ **/ #include "GaudiKernel/ServiceHandle.h" +#include "AthenaBaseComps/AthAlgTool.h" #include "AthenaKernel/SourceID.h" -#include "AthenaKernel/GenericMetadataToolNoAux.h" -#include "ByteStreamData/ByteStreamMetadataContainer.h" +#include "AthenaKernel/IMetaDataTool.h" #include <string> @@ -24,8 +23,8 @@ class StoreGateSvc; /** @class ByteStreamMetadataTool * @brief This class provides the MetaDataTool for ByteStreamMetadata objects **/ -class ByteStreamMetadataTool : public GenericMetadataToolNoAux <ByteStreamMetadataContainer> -{ +class ByteStreamMetadataTool : public ::AthAlgTool, + virtual public IMetaDataTool { public: /// Standard Service Constructor ByteStreamMetadataTool(const std::string& type, const std::string& name, const IInterface* parent); @@ -33,11 +32,22 @@ public: virtual ~ByteStreamMetadataTool(); /// Gaudi Service Interface method implementations: - StatusCode initialize() override; - StatusCode finalize() override; - /// Virtual method to update a container with information from another one - virtual StatusCode updateContainer(ByteStreamMetadataContainer* bsmdc_out, - const ByteStreamMetadataContainer* bsmdc_in ) override; + StatusCode initialize(); + StatusCode finalize(); + + /// Incident service handle listening for BeginInputFile and EndInputFile. + virtual StatusCode beginInputFile(); + virtual StatusCode endInputFile(); + virtual StatusCode metaDataStop(const SG::SourceID&); + virtual StatusCode beginInputFile(const SG::SourceID&); + virtual StatusCode endInputFile(const SG::SourceID&); + virtual StatusCode metaDataStop(); + +private: + typedef ServiceHandle<StoreGateSvc> StoreGateSvc_t; + StoreGateSvc_t m_pMetaDataStore; + StoreGateSvc_t m_pInputStore; }; #endif + diff --git a/Event/ByteStreamCnvSvc/src/EventSelectorByteStream.cxx b/Event/ByteStreamCnvSvc/src/EventSelectorByteStream.cxx index f864a4ed24a7aa1a1c8b34dda056548e117dacf7..d3b0479d8b532a346f8766c4c95c7fbeb0c7cc87 100644 --- a/Event/ByteStreamCnvSvc/src/EventSelectorByteStream.cxx +++ b/Event/ByteStreamCnvSvc/src/EventSelectorByteStream.cxx @@ -379,14 +379,16 @@ StatusCode EventSelectorByteStream::openNewRun() const { } std::string blockname = *m_inputCollectionsIterator; // try to open a file, if failure go to next FIXME: PVG: silient failure? - long nev = m_eventSource->getBlockIterator(blockname); + //long nev = m_eventSource->getBlockIterator(blockname); + auto nevguid = m_eventSource->getBlockIterator(blockname); + long nev = nevguid.first; if (nev == -1) { ATH_MSG_FATAL("Unable to access file " << *m_inputCollectionsIterator << ", stopping here"); throw ByteStreamExceptions::fileAccessError(); } // Fire the incident if (!m_beginFileFired) { - FileIncident beginInputFileIncident(name(), "BeginInputFile", "BSF:" + *m_inputCollectionsIterator); + FileIncident beginInputFileIncident(name(), "BeginInputFile", "BSF:" + *m_inputCollectionsIterator,nevguid.second); m_incidentSvc->fireIncident(beginInputFileIncident); //m_beginFileFired = true; // Should go here, but can't because IEvtSelector next is const } @@ -693,7 +695,8 @@ StatusCode EventSelectorByteStream::seek(Context& it, int evtNum) const { std::string fileName = m_inputCollectionsProp.value()[fileNum]; m_fileCount = fileNum; // Open the correct file - long nev = m_eventSource->getBlockIterator(fileName); + auto nevguid = m_eventSource->getBlockIterator(fileName); + long nev = nevguid.first; if (nev == -1) { ATH_MSG_FATAL("Unable to open file with seeked event " << evtNum << " file " << fileName); return StatusCode::FAILURE; @@ -849,7 +852,8 @@ int EventSelectorByteStream::findEvent(int evtNum) const { // if file not opened yet, check it if (m_numEvt[i] == -1) { std::string fileName = m_inputCollectionsProp.value()[i]; - int nev = m_eventSource->getBlockIterator(fileName); + auto nevguid = m_eventSource->getBlockIterator(fileName); + long nev = nevguid.first; // if failure on file open, exit if (nev==-1) { break;