From 1ec01b3362be75be5012599ba2469a7cfdbff151 Mon Sep 17 00:00:00 2001 From: Marco Clemencic <marco.clemencic@cern.ch> Date: Mon, 16 Apr 2018 14:32:19 +0200 Subject: [PATCH] Add test and fix of version propagation in KeyedContainer move (#27) --- .../TestObjectVersion.cpp | 43 +++++++++++++++++++ .../tests/options/TestObjectVersion.py | 4 ++ .../qmtest/gaudiexamples.qms/issue.qms/27.qmt | 6 +++ GaudiKernel/GaudiKernel/KeyedContainer.h | 4 +- 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 GaudiExamples/src/FunctionalAlgorithms/TestObjectVersion.cpp create mode 100644 GaudiExamples/tests/options/TestObjectVersion.py create mode 100644 GaudiExamples/tests/qmtest/gaudiexamples.qms/issue.qms/27.qmt diff --git a/GaudiExamples/src/FunctionalAlgorithms/TestObjectVersion.cpp b/GaudiExamples/src/FunctionalAlgorithms/TestObjectVersion.cpp new file mode 100644 index 0000000000..28772682ed --- /dev/null +++ b/GaudiExamples/src/FunctionalAlgorithms/TestObjectVersion.cpp @@ -0,0 +1,43 @@ +#include <GaudiAlg/Consumer.h> +#include <GaudiAlg/Producer.h> +#include <GaudiKernel/KeyedContainer.h> + +namespace Gaudi +{ + namespace Examples + { + namespace TestObjectVersion + { + // using ObjectType = DataObject; + using ObjectType = KeyedContainer<KeyedObject<std::size_t>>; + + struct CreateObject : Gaudi::Functional::Producer<ObjectType()> { + CreateObject( const std::string& name, ISvcLocator* svcLoc ) + : Producer( name, svcLoc, KeyValue( "OutputLocation", "/Event/SomeData" ) ) + { + } + ObjectType operator()() const override + { + ObjectType o; + o.setVersion( 42 ); + info() << "Created object with version " << static_cast<int>( o.version() ) << endmsg; + return o; + } + }; + DECLARE_COMPONENT( CreateObject ) + + struct UseObject : Gaudi::Functional::Consumer<void( const ObjectType& )> { + UseObject( const std::string& name, ISvcLocator* svcLoc ) + : Consumer( name, svcLoc, KeyValue( "InputLocation", "/Event/SomeData" ) ) + { + } + void operator()( const ObjectType& o ) const override + { + info() << "Retrieved object with version " << static_cast<int>( o.version() ) << endmsg; + if ( o.version() != 42 ) throw GaudiException( "Wrong object version", name(), StatusCode::FAILURE ); + } + }; + DECLARE_COMPONENT( UseObject ) + } + } +} diff --git a/GaudiExamples/tests/options/TestObjectVersion.py b/GaudiExamples/tests/options/TestObjectVersion.py new file mode 100644 index 0000000000..455d227007 --- /dev/null +++ b/GaudiExamples/tests/options/TestObjectVersion.py @@ -0,0 +1,4 @@ +from Gaudi.Configuration import ApplicationMgr +from Configurables import Gaudi__Examples__TestObjectVersion__CreateObject as CO +from Configurables import Gaudi__Examples__TestObjectVersion__UseObject as UO +ApplicationMgr(TopAlg=[CO(), UO()], EvtSel="NONE", EvtMax=1) diff --git a/GaudiExamples/tests/qmtest/gaudiexamples.qms/issue.qms/27.qmt b/GaudiExamples/tests/qmtest/gaudiexamples.qms/issue.qms/27.qmt new file mode 100644 index 0000000000..db7bf892ba --- /dev/null +++ b/GaudiExamples/tests/qmtest/gaudiexamples.qms/issue.qms/27.qmt @@ -0,0 +1,6 @@ +<?xml version="1.0" ?><!DOCTYPE extension PUBLIC '-//QM/2.3/Extension//EN' 'http://www.codesourcery.com/qm/dtds/2.3/-//qm/2.3/extension//en.dtd'> +<extension class="GaudiTest.GaudiExeTest" kind="test"> +<argument name="program"><text>gaudirun.py</text></argument> +<argument name="args"><set><text>$GAUDIEXAMPLESROOT/tests/options/TestObjectVersion.py</text></set></argument> +<argument name="use_temp_dir"><enumeral>true</enumeral></argument> +</extension> diff --git a/GaudiKernel/GaudiKernel/KeyedContainer.h b/GaudiKernel/GaudiKernel/KeyedContainer.h index 9e46a8f188..e80a3b21c1 100644 --- a/GaudiKernel/GaudiKernel/KeyedContainer.h +++ b/GaudiKernel/GaudiKernel/KeyedContainer.h @@ -189,7 +189,9 @@ public: m_cont.setup( (void*)sptr, (void**)rptr ); } KeyedContainer( KeyedContainer&& other ) - : m_cont( std::move( other.m_cont ) ), m_sequential( std::move( other.m_sequential ) ) + : ObjectContainerBase( std::move( other ) ) + , m_cont( std::move( other.m_cont ) ) + , m_sequential( std::move( other.m_sequential ) ) { m_cont.setup( (void*)&m_sequential, (void**)&m_random ); std::for_each( begin(), end(), [this]( ContainedObject* obj ) { obj->setParent( this ); } ); -- GitLab