From da6f1bbe04e8ee7bfa60e7e803f075cbca88fd60 Mon Sep 17 00:00:00 2001 From: charles leggett Date: Mon, 21 Oct 2019 11:04:34 -0700 Subject: [PATCH 1/9] create range dependencies for WriteCondHandles --- Control/StoreGate/StoreGate/WriteCondHandle.h | 47 ++++++++++++++++++- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/Control/StoreGate/StoreGate/WriteCondHandle.h b/Control/StoreGate/StoreGate/WriteCondHandle.h index 45bdd8d92fd..1b62f83f5b8 100644 --- a/Control/StoreGate/StoreGate/WriteCondHandle.h +++ b/Control/StoreGate/StoreGate/WriteCondHandle.h @@ -10,6 +10,7 @@ #include "StoreGate/StoreGateSvc.h" #include "StoreGate/WriteCondHandleKey.h" +#include "StoreGate/ReadCondHandle.h" #include "GaudiKernel/ServiceHandle.h" #include "GaudiKernel/DataHandle.h" @@ -42,9 +43,22 @@ namespace SG { bool isValid(); bool isValid(const EventIDBase& t) const; + template + void addDependency(const SG::ReadCondHandle& rch); + + template + void addDependency(const ReadCondHandle& rch, Args... args); + StatusCode record(const EventIDRange& range, T* t); StatusCode record(const EventIDRange& range, std::unique_ptr t); - + + /** + * @brief record handle, range must have been set by addDependency(...) + * @param t unique_ptr to handle + */ + StatusCode record(std::unique_ptr t) { + return record(m_range, t); + } /** * @brief Extend the range of the last IOV. @@ -67,10 +81,11 @@ namespace SG { CondCont* m_cc {nullptr}; const SG::WriteCondHandleKey& m_hkey; + + EventIDRange m_range; }; - //--------------------------------------------------------------------------- template @@ -147,6 +162,16 @@ namespace SG { return record (r, std::unique_ptr (t)); } + template + StatusCode + WriteCondHandle::record(std::unique_ptr t) { + if (m_range.start().isValid() && m_range.end().isValid()) { + return record(m_range, std::move(t)); + } + return StatusCode::FAILURE; + } + + //--------------------------------------------------------------------------- @@ -187,6 +212,24 @@ namespace SG { return (m_cc->valid(m_ctx.eventID())); } + //--------------------------------------------------------------------------- + + template + template< typename R> + void + WriteCondHandle::addDependency(const SG::ReadCondHandle& rch) { + m_range = m_range.intersect(m_range, rch.range()); + } + + template< typename T> + template + void + WriteCondHandle::addDependency(const ReadCondHandle& rch, Args... args) { + addDependency( rch ); + return addDependency( args... ); + } + + } #endif -- GitLab From f98b9abc0666285ca14f273f308d53c8e3401e28 Mon Sep 17 00:00:00 2001 From: charles leggett Date: Mon, 21 Oct 2019 21:08:57 -0700 Subject: [PATCH 2/9] fix record --- Control/StoreGate/StoreGate/WriteCondHandle.h | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/Control/StoreGate/StoreGate/WriteCondHandle.h b/Control/StoreGate/StoreGate/WriteCondHandle.h index 1b62f83f5b8..82fd78d48a0 100644 --- a/Control/StoreGate/StoreGate/WriteCondHandle.h +++ b/Control/StoreGate/StoreGate/WriteCondHandle.h @@ -44,10 +44,10 @@ namespace SG { bool isValid(const EventIDBase& t) const; template - void addDependency(const SG::ReadCondHandle& rch); + void addDependency(SG::ReadCondHandle& rch); template - void addDependency(const ReadCondHandle& rch, Args... args); + void addDependency(ReadCondHandle& rch, Args... args); StatusCode record(const EventIDRange& range, T* t); StatusCode record(const EventIDRange& range, std::unique_ptr t); @@ -56,9 +56,7 @@ namespace SG { * @brief record handle, range must have been set by addDependency(...) * @param t unique_ptr to handle */ - StatusCode record(std::unique_ptr t) { - return record(m_range, t); - } + StatusCode record(std::unique_ptr t); /** * @brief Extend the range of the last IOV. @@ -74,6 +72,8 @@ namespace SG { const EventContext& ctx = Gaudi::Hive::currentContext()); const std::string& dbKey() const { return m_hkey.dbKey(); } + + const EventIDRange& range() const { return m_range; } private: @@ -164,8 +164,8 @@ namespace SG { template StatusCode - WriteCondHandle::record(std::unique_ptr t) { - if (m_range.start().isValid() && m_range.end().isValid()) { + WriteCondHandle::record(std::unique_ptr t) { + if (m_range.start().isValid() && m_range.stop().isValid()) { return record(m_range, std::move(t)); } return StatusCode::FAILURE; @@ -214,17 +214,20 @@ namespace SG { //--------------------------------------------------------------------------- + // Can't take a const RCH, as RCH.range() can load the ptr. template template< typename R> void - WriteCondHandle::addDependency(const SG::ReadCondHandle& rch) { - m_range = m_range.intersect(m_range, rch.range()); + WriteCondHandle::addDependency(SG::ReadCondHandle& rch) { + EventIDRange r; + rch.range(r); + m_range = m_range.intersect(m_range, r); } template< typename T> template void - WriteCondHandle::addDependency(const ReadCondHandle& rch, Args... args) { + WriteCondHandle::addDependency(ReadCondHandle& rch, Args... args) { addDependency( rch ); return addDependency( args... ); } -- GitLab From 8947a72728058d7617a6c973fd5a549f376f36f3 Mon Sep 17 00:00:00 2001 From: charles leggett Date: Mon, 21 Oct 2019 21:09:48 -0700 Subject: [PATCH 3/9] expand AthExHive CondAlgs to test dependencies --- .../AthExHive/AthExHive/CondDataObjZ.h | 38 ++++++ .../src/components/AthExHive_entries.cxx | 4 + .../AthExHive/src/condEx/AlgE.cxx | 119 ++++++++++++++++++ .../AthExHive/src/condEx/AlgE.h | 44 +++++++ .../AthExHive/src/condEx/CondAlgZ.cxx | 108 ++++++++++++++++ .../AthExHive/src/condEx/CondAlgZ.h | 49 ++++++++ 6 files changed, 362 insertions(+) create mode 100644 Control/AthenaExamples/AthExHive/AthExHive/CondDataObjZ.h create mode 100644 Control/AthenaExamples/AthExHive/src/condEx/AlgE.cxx create mode 100644 Control/AthenaExamples/AthExHive/src/condEx/AlgE.h create mode 100644 Control/AthenaExamples/AthExHive/src/condEx/CondAlgZ.cxx create mode 100644 Control/AthenaExamples/AthExHive/src/condEx/CondAlgZ.h diff --git a/Control/AthenaExamples/AthExHive/AthExHive/CondDataObjZ.h b/Control/AthenaExamples/AthExHive/AthExHive/CondDataObjZ.h new file mode 100644 index 00000000000..aec5cdab74e --- /dev/null +++ b/Control/AthenaExamples/AthExHive/AthExHive/CondDataObjZ.h @@ -0,0 +1,38 @@ +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef CONDALGS_CONDDATAOBJZ_H +#define CONDALGS_CONDDATAOBJZ_H + +class CondDataObjZ { + +public: + + CondDataObjZ():m_val(0) {}; + CondDataObjZ(float f): m_val(f) {}; + virtual ~CondDataObjZ(){}; + + void val(float f) { m_val = f; } + float val() const { return m_val; } + +private: + float m_val; +}; + +#include +inline std::ostream& operator<<(std::ostream& ost, const CondDataObjZ& rhs) { + ost << rhs.val(); + return ost; +} + + +//using the macros below we can assign an identifier (and a version) +//to the type CondDataObjZ +//This is required and checked at compile time when you try to record/retrieve +#include "AthenaKernel/CLASS_DEF.h" +CLASS_DEF( CondDataObjZ , 6664395 , 1 ) +CLASS_DEF( CondCont , 210255841 , 1 ) + + +#endif diff --git a/Control/AthenaExamples/AthExHive/src/components/AthExHive_entries.cxx b/Control/AthenaExamples/AthExHive/src/components/AthExHive_entries.cxx index d13f9928f9d..f0378c1c8b8 100644 --- a/Control/AthenaExamples/AthExHive/src/components/AthExHive_entries.cxx +++ b/Control/AthenaExamples/AthExHive/src/components/AthExHive_entries.cxx @@ -23,9 +23,11 @@ #include "../condEx/AlgB.h" #include "../condEx/AlgC.h" #include "../condEx/AlgD.h" +#include "../condEx/AlgE.h" #include "../condEx/AlgT.h" #include "../condEx/CondAlgX.h" #include "../condEx/CondAlgY.h" +#include "../condEx/CondAlgZ.h" #include "../condEx/ASCIICondDbSvc.h" #include "../ThreadInitTool.h" @@ -52,9 +54,11 @@ DECLARE_COMPONENT( AlgA ) DECLARE_COMPONENT( AlgB ) DECLARE_COMPONENT( AlgC ) DECLARE_COMPONENT( AlgD ) +DECLARE_COMPONENT( AlgE ) DECLARE_COMPONENT( AlgT ) DECLARE_COMPONENT( CondAlgX ) DECLARE_COMPONENT( CondAlgY ) +DECLARE_COMPONENT( CondAlgZ ) DECLARE_COMPONENT( ThreadInitTool ) DECLARE_COMPONENT( HiveTool ) diff --git a/Control/AthenaExamples/AthExHive/src/condEx/AlgE.cxx b/Control/AthenaExamples/AthExHive/src/condEx/AlgE.cxx new file mode 100644 index 00000000000..c334250e455 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/condEx/AlgE.cxx @@ -0,0 +1,119 @@ +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ + +#include "AlgE.h" +#include "StoreGate/ReadHandle.h" +#include "StoreGate/ReadCondHandle.h" + +#include "GaudiKernel/ServiceHandle.h" +#include +#include +#include + + +AlgE::AlgE( const std::string& name, + ISvcLocator* pSvcLocator ) : + ::AthAlgorithm( name, pSvcLocator ) +{ +} + +//--------------------------------------------------------------------------- + +AlgE::~AlgE() {} + +//--------------------------------------------------------------------------- + +StatusCode AlgE::initialize() { + ATH_MSG_DEBUG("initialize " << name()); + + ATH_CHECK( m_rdh1.initialize() ); + ATH_CHECK( m_rch1.initialize() ); + ATH_CHECK( m_rch2.initialize() ); + ATH_CHECK( m_rch3.initialize() ); + ATH_CHECK( m_rch4.initialize() ); + + ATH_MSG_INFO( "m_rdh1 id: " << m_rdh1.fullKey() ); + ATH_MSG_INFO( "m_rch1 id: " << m_rch1.fullKey() ); + ATH_MSG_INFO( "m_rch2 id: " << m_rch2.fullKey() ); + ATH_MSG_INFO( "m_rch3 id: " << m_rch3.fullKey() ); + ATH_MSG_INFO( "m_rch4 id: " << m_rch4.fullKey() ); + + return StatusCode::SUCCESS; +} + +//--------------------------------------------------------------------------- + +StatusCode AlgE::finalize() { + ATH_MSG_DEBUG("finalize " << name()); + return StatusCode::SUCCESS; +} + +//--------------------------------------------------------------------------- + +StatusCode AlgE::execute() { + ATH_MSG_DEBUG("execute " << name()); + + SG::ReadHandle rh1(m_rdh1); + if (!rh1.isValid()) { + ATH_MSG_ERROR ("Could not retrieve HiveDataObj with key " << m_rdh1.key()); + return StatusCode::FAILURE; + } + + ATH_MSG_INFO(" read: " << rh1.key() << " = " << rh1->val() ); + + SG::ReadCondHandle ch1( m_rch1 ); + SG::ReadCondHandle ch2( m_rch2 ); + SG::ReadCondHandle ch3( m_rch3 ); + SG::ReadCondHandle ch4( m_rch4 ); + + EventIDBase t( getContext().eventID() ); + + + float val {0.0}; + + const CondDataObj* cdo = *ch1; + if (cdo != 0) { + ATH_MSG_INFO(" CDO1: " << *cdo ); + val += cdo->val(); + } else { + ATH_MSG_ERROR(" CDO1 ptr == zero"); + } + + const CondDataObjY* cdoy = *ch2; + if (cdoy != 0) { + ATH_MSG_INFO(" CDO2: " << *cdoy ); + val += cdoy->val(); + } else { + ATH_MSG_ERROR(" CDO2 ptr == zero"); + } + + cdoy = *ch3; + if (cdoy != 0) { + ATH_MSG_INFO(" CDO3: " << *cdoy ); + val += cdoy->val(); + } else { + ATH_MSG_ERROR(" CDO3 ptr == zero"); + } + + const CondDataObjZ *cdoz = *ch4; + if (cdoz != 0) { + ATH_MSG_INFO(" CDO4: " << *cdoz ); + + if (cdoz->val() != val) { + ATH_MSG_ERROR(" value of CDO4 is incorrect "); + } + + } else { + ATH_MSG_ERROR(" CDO# ptr == zero"); + } + + + ATH_MSG_INFO("TEST: " << getContext().eventID().event_number() << " " + << rh1->val() << " " << **ch1 << " " << **ch2 << " " << **ch3 + << " " << **ch4); + + return StatusCode::SUCCESS; + +} + diff --git a/Control/AthenaExamples/AthExHive/src/condEx/AlgE.h b/Control/AthenaExamples/AthExHive/src/condEx/AlgE.h new file mode 100644 index 00000000000..88452b01d98 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/condEx/AlgE.h @@ -0,0 +1,44 @@ +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef CONDALGS_ALGE_H +#define CONDALGS_ALGE_H 1 + +#include "AthenaBaseComps/AthAlgorithm.h" +#include "StoreGate/ReadHandleKey.h" +#include "StoreGate/ReadCondHandleKey.h" + +#include "AthExHive/HiveDataObj.h" +#include "AthExHive/CondDataObj.h" +#include "AthExHive/CondDataObjY.h" +#include "AthExHive/CondDataObjZ.h" + +#include + +class AlgE : public AthAlgorithm { + +public: + + AlgE (const std::string& name, ISvcLocator* pSvcLocator); + virtual ~AlgE(); + + virtual bool isClonable() const override { return true; } + + virtual StatusCode initialize() override; + virtual StatusCode execute() override; + virtual StatusCode finalize() override; + +private: + + SG::ReadHandleKey m_rdh1 {this, "Key_R1", "a1", "read key 1"}; + + SG::ReadCondHandleKey m_rch1 {this, "Key_CH1", "X2", "cond read key1"}; + SG::ReadCondHandleKey m_rch2 {this, "Key_CH2", "Y1", "cond read key2"}; + SG::ReadCondHandleKey m_rch3 {this, "Key_CH3", "Y2", "cond read key3"}; + + SG::ReadCondHandleKey m_rch4 {this, "Key_CH4", "Z1", "cond read key4"}; + + +}; +#endif diff --git a/Control/AthenaExamples/AthExHive/src/condEx/CondAlgZ.cxx b/Control/AthenaExamples/AthExHive/src/condEx/CondAlgZ.cxx new file mode 100644 index 00000000000..de4f03bec02 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/condEx/CondAlgZ.cxx @@ -0,0 +1,108 @@ +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ + +#include "CondAlgZ.h" +#include "AthExHive/IASCIICondDbSvc.h" +#include "StoreGate/WriteCondHandle.h" + +#include "GaudiKernel/ServiceHandle.h" + +#include +#include +#include + +CondAlgZ::CondAlgZ( const std::string& name, + ISvcLocator* pSvcLocator ) : + ::AthAlgorithm( name, pSvcLocator ), + m_cs("CondSvc",name) +{ +} + +CondAlgZ::~CondAlgZ() {} + +StatusCode CondAlgZ::initialize() { + ATH_MSG_DEBUG("initialize " << name()); + + if (m_cs.retrieve().isFailure()) { + ATH_MSG_ERROR("unable to retrieve CondSvc"); + } + + if (m_rchk1.initialize().isFailure()) { + ATH_MSG_ERROR("unable to initialize ReadCondHandleKey with key" << m_rchk1.key() ); + return StatusCode::FAILURE; + } + + if (m_rchk2.initialize().isFailure()) { + ATH_MSG_ERROR("unable to initialize ReadCondHandleKey with key" << m_rchk2.key() ); + return StatusCode::FAILURE; + } + + if (m_rchk3.initialize().isFailure()) { + ATH_MSG_ERROR("unable to initialize ReadCondHandleKey with key" << m_rchk3.key() ); + return StatusCode::FAILURE; + } + + + if (m_wch.initialize().isFailure()) { + ATH_MSG_ERROR("unable to initialize WriteCondHandleKey with key" << m_wch.key() ); + return StatusCode::FAILURE; + } + + + if (m_cs->regHandle(this, m_wch).isFailure()) { + ATH_MSG_ERROR("unable to register WriteCondHandle " << m_wch.fullKey() + << " with CondSvc"); + return StatusCode::FAILURE; + } + + return StatusCode::SUCCESS; +} + +StatusCode CondAlgZ::finalize() { + ATH_MSG_DEBUG("finalize " << name()); + return StatusCode::SUCCESS; +} + +StatusCode CondAlgZ::execute() { + ATH_MSG_DEBUG("execute " << name()); + + EventIDBase now(getContext().eventID()); + + SG::ReadCondHandle rch1(m_rchk1); + SG::ReadCondHandle rch2(m_rchk2); + SG::ReadCondHandle rch3(m_rchk3); + + const CondDataObj *cdo1 = *rch1; + const CondDataObjY *cdo2 = *rch2; + const CondDataObjY *cdo3 = *rch3; + + SG::WriteCondHandle wch(m_wch); + + // do we have a valid m_wch for current time? + if ( !wch.isValid(now) ) { + + ATH_MSG_DEBUG(" CondHandle " << wch.key() + << " not valid."); + + wch.addDependency(rch1); + wch.addDependency(rch2,rch3); + + float val = rch1->val() + rch2->val() + rch3->val(); + + + if (wch.record( std::make_unique + ( CondDataObjZ(val) ) ).isFailure()) { + ATH_MSG_ERROR("could not record CondDataObjZ " << wch.key() + << " val: " << val + << " with EventRange " << wch.range() ); + return StatusCode::FAILURE; + } + ATH_MSG_INFO("recorded new CDO " << wch.key() << " = " << val + << " with range " << wch.range() ); + } + + return StatusCode::SUCCESS; + +} + diff --git a/Control/AthenaExamples/AthExHive/src/condEx/CondAlgZ.h b/Control/AthenaExamples/AthExHive/src/condEx/CondAlgZ.h new file mode 100644 index 00000000000..08a7c50c352 --- /dev/null +++ b/Control/AthenaExamples/AthExHive/src/condEx/CondAlgZ.h @@ -0,0 +1,49 @@ +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef CONDALGS_CONDALGZ_H +#define CONDALGS_CONDALGZ_H 1 + +#include "AthenaBaseComps/AthAlgorithm.h" +#include "StoreGate/ReadHandle.h" +#include "StoreGate/ReadCondHandleKey.h" +#include "StoreGate/WriteCondHandleKey.h" + +#include "AthExHive/CondDataObj.h" +#include "AthExHive/CondDataObjY.h" +#include "AthExHive/CondDataObjZ.h" +#include "AthExHive/IASCIICondDbSvc.h" + +#include "xAODEventInfo/EventInfo.h" +#include "GaudiKernel/ICondSvc.h" + +#include + +class CondAlgZ : public AthAlgorithm { + +public: + + CondAlgZ (const std::string& name, ISvcLocator* pSvcLocator); + virtual ~CondAlgZ(); + + virtual bool isClonable() const override { return true; } + + virtual StatusCode initialize() override; + virtual StatusCode execute() override; + virtual StatusCode finalize() override; + +private: + + SG::ReadCondHandleKey m_rchk1 {this, "Key_RCH1", "X2", "read cond handle key 1"}; + SG::ReadCondHandleKey m_rchk2 {this, "Key_RCH2", "Y1", "read cond handle key 2"}; + SG::ReadCondHandleKey m_rchk3 {this, "Key_RCH3", "Y2", "read cond handle key 3"}; + + SG::WriteCondHandleKey m_wch {this, "Key_WCH", "Z1", "write cond handle key"}; + + ServiceHandle m_cs; + + +}; + +#endif -- GitLab From e84adb296a4ad5165c33c95c23d0e34fc7776481 Mon Sep 17 00:00:00 2001 From: charles leggett Date: Wed, 23 Oct 2019 11:42:36 -0700 Subject: [PATCH 4/9] add test --- .../StoreGate/share/WriteCondHandle_test.ref | 52 +++ .../StoreGate/share/WriteCondHandle_test.txt | 2 + .../StoreGate/test/WriteCondHandle_test.cxx | 415 ++++++++++++++++++ 3 files changed, 469 insertions(+) create mode 100644 Control/StoreGate/share/WriteCondHandle_test.ref create mode 100644 Control/StoreGate/share/WriteCondHandle_test.txt create mode 100644 Control/StoreGate/test/WriteCondHandle_test.cxx diff --git a/Control/StoreGate/share/WriteCondHandle_test.ref b/Control/StoreGate/share/WriteCondHandle_test.ref new file mode 100644 index 00000000000..6f03be41e85 --- /dev/null +++ b/Control/StoreGate/share/WriteCondHandle_test.ref @@ -0,0 +1,52 @@ + + +Initializing Gaudi ApplicationMgr using job opts /home/leggett/work/condhanddep/src/Control/StoreGate/share/WriteCondHandle_test.txt +JobOptionsSvc INFO # =======> /home/leggett/work/condhanddep/src/Control/StoreGate/share/WriteCondHandle_test.txt +JobOptionsSvc INFO # (1,1): ApplicationMgr.ExtSvc = ["StoreGateSvc/ConditionStore"] +JobOptionsSvc INFO # (2,1): ConditionStore.ProxyProviderSvc = "" +JobOptionsSvc INFO Job options successfully read in from /home/leggett/work/condhanddep/src/Control/StoreGate/share/WriteCondHandle_test.txt +ApplicationMgr SUCCESS +==================================================================================================================================== + Welcome to ApplicationMgr (GaudiCoreSvc v32r2) + running on zeus on Wed Oct 23 11:04:02 2019 +==================================================================================================================================== +ApplicationMgr INFO Application Manager Configured successfully +ClassIDSvc INFO getRegistryEntries: read 764 CLIDRegistry entries for module ALL +EventLoopMgr WARNING Unable to locate service "EventSelector" +EventLoopMgr WARNING No events will be processed from external input. +HistogramPersis...WARNING Histograms saving not required. +ApplicationMgr INFO Application Manager Initialized successfully +ApplicationMgr Ready +test2 +r1: {[0,t:0] - [0,t:3]} {[0,t:3] - [0,t:7]} {[0,t:7] - [0,t:10]} +r2: {[0,t:0] - [0,t:5]} {[0,t:5] - [0,t:10]} +r3: {[0,t:0] - [0,t:2]} {[0,t:2] - [0,t:6]} {[0,t:6] - [0,t:10]} +ClassIDSvc INFO getRegistryEntries: read 2638 CLIDRegistry entries for module ALL +test EventID: [0,t:1] +o1: 1 {[0,t:0] - [0,t:3]} {[0,t:0] - [0,t:3]} +o2: 21 {[0,t:0] - [0,t:5]} +o3: 131 {[0,t:0] - [0,t:2]} +ERROR expected: WriteCondHandle ERROR WriteCondHandle::record() : no range defined +rD: {[0,t:0] - [0,t:2]} +rI: {[0,t:0] - [0,t:2]} +test EventID: [0,t:4] +o1: 2 {[0,t:3] - [0,t:7]} {[0,t:3] - [0,t:7]} +o2: 21 {[0,t:0] - [0,t:5]} +o3: 132 {[0,t:2] - [0,t:6]} +ERROR expected: WriteCondHandle ERROR WriteCondHandle::record() : no range defined +rD: {[0,t:3] - [0,t:5]} +rI: {[0,t:3] - [0,t:5]} +test EventID: [0,t:6] +o1: 2 {[0,t:3] - [0,t:7]} {[0,t:3] - [0,t:7]} +o2: 22 {[0,t:5] - [0,t:10]} +o3: 133 {[0,t:6] - [0,t:10]} +ERROR expected: WriteCondHandle ERROR WriteCondHandle::record() : no range defined +rD: {[0,t:6] - [0,t:7]} +rI: {[0,t:6] - [0,t:7]} +test EventID: [0,t:9] +o1: 3 {[0,t:7] - [0,t:10]} {[0,t:7] - [0,t:10]} +o2: 22 {[0,t:5] - [0,t:10]} +o3: 133 {[0,t:6] - [0,t:10]} +ERROR expected: WriteCondHandle ERROR WriteCondHandle::record() : no range defined +rD: {[0,t:7] - [0,t:10]} +rI: {[0,t:7] - [0,t:10]} diff --git a/Control/StoreGate/share/WriteCondHandle_test.txt b/Control/StoreGate/share/WriteCondHandle_test.txt new file mode 100644 index 00000000000..13390b94d78 --- /dev/null +++ b/Control/StoreGate/share/WriteCondHandle_test.txt @@ -0,0 +1,2 @@ +ApplicationMgr.ExtSvc={"StoreGateSvc/ConditionStore"}; +ConditionStore.ProxyProviderSvc=""; diff --git a/Control/StoreGate/test/WriteCondHandle_test.cxx b/Control/StoreGate/test/WriteCondHandle_test.cxx new file mode 100644 index 00000000000..4feb2f5bace --- /dev/null +++ b/Control/StoreGate/test/WriteCondHandle_test.cxx @@ -0,0 +1,415 @@ +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ + +/** + * @brief Compile tests for WriteCondHandleKeyArray + * @TODO extend to also test functionality + */ + + +#undef NDEBUG +#include "StoreGate/CondHandleKeyArray.h" +#include "StoreGate/exceptions.h" +#include "SGTools/TestStore.h" +#include "AthenaKernel/CLASS_DEF.h" +#include "AthenaKernel/StorableConversions.h" +#include "SGTools/DataProxy.h" +#include "TestTools/initGaudi.h" +#include "TestTools/expect_exception.h" +#include "AthContainersInterfaces/IConstAuxStore.h" +#include "AthContainers/DataVector.h" +#include "AthContainers/ConstDataVector.h" +#include "AthenaKernel/errorcheck.h" +#include "AthenaKernel/ExtendedEventContext.h" +#include "CxxUtils/checker_macros.h" +#include "StoreGate/StoreGate.h" +#include +#include + +#define DEBUG_VHB 1 + + +class MyObjAux + : public SG::IConstAuxStore, public ILockable +{ +public: + MyObjAux(int x=0) : x(x) {} + ~MyObjAux() { deleted.push_back (x); } + int x; + bool m_locked = false; + + virtual const void* getData (SG::auxid_t /*auxid*/) const override { return 0; } + virtual void* getDecoration (SG::auxid_t /*auxid*/, size_t /*size*/, size_t /*capacity*/) override { return 0; } + virtual const SG::auxid_set_t& getAuxIDs() const override { std::abort(); } + virtual bool isDecoration(SG::auxid_t /*auxid*/) const override { std::abort(); } + virtual void lock() override { m_locked = true; } + virtual bool clearDecorations() override { return false; } + virtual size_t size() const override { return 0; } + virtual void lockDecoration (SG::auxid_t) override { std::abort(); } + + static std::vector deleted ATLAS_THREAD_SAFE; +}; +std::vector MyObjAux::deleted; +CLASS_DEF (MyObjAux, 293847296, 1) + +class MyObj { +public: + MyObj(int x=0) : x(x) {} + ~MyObj() { deleted.push_back (x); } + SG::IAuxStore* getStore() const { return nullptr; } + void setStore (SG::IConstAuxStore* store) {aux = dynamic_cast(store); } + int x; + MyObjAux* aux {nullptr}; + + static std::vector deleted ATLAS_THREAD_SAFE; +}; +std::vector MyObj::deleted; +CLASS_DEF( MyObj , 86839352 , 1 ) +#include "AthenaKernel/CondCont.h" +CONDCONT_DEF( MyObj , 265987730 ); + +CLASS_DEF( DataVector , 58451955 , 1 ) + +class MyObj2 { +public: + MyObj2(int x=0) : x(x) {} + ~MyObj2() { deleted.push_back (x); } + int x; + + static std::vector deleted ATLAS_THREAD_SAFE; +}; +std::vector MyObj2::deleted; +CLASS_DEF( MyObj2 , 210631107 , 1 ) +CONDCONT_DEF( MyObj2 , 128580061 ); + +class MyObj3 { +public: + MyObj3(int x=0) : x(x) {} + ~MyObj3() { deleted.push_back (x); } + int x; + + static std::vector deleted ATLAS_THREAD_SAFE; +}; +std::vector MyObj3::deleted; +CLASS_DEF( MyObj3 , 210631106 , 1 ) +CONDCONT_DEF( MyObj3 , 127580062 ); + + +class MyDObj : public DataObject +{ +public: + MyDObj(int x=0) : x(x) {} + ~MyDObj() { deleted.push_back (x); } + int x; + + static std::vector deleted ATLAS_THREAD_SAFE; +}; +std::vector MyDObj::deleted; +CLASS_DEF (MyDObj, 293847297, 1) +CONDCONT_DEF( MyDObj , 45988109 ); + + +std::pair, std::unique_ptr > +makeWithAux (int x=0) +{ + auto obj = std::make_unique(x); + auto aux = std::make_unique(x+100); + obj->setStore (aux.get()); + return std::make_pair (std::move(obj), std::move(aux)); +} + + +void test1() +{ + std::cout << "test1\n"; + + SG::WriteCondHandleKey k1 {"MyObj1"}; + SG::WriteCondHandleKey k2 {"MyObj2"}; + SG::WriteCondHandleKey k3 {"MyObj3"}; + + SG::WriteCondHandleKey kD {"MyObjD"}; + + assert ( k1.mode() == Gaudi::DataHandle::Writer); + assert ( k1.key() == "MyObj1"); + assert ( k1.initialize().isSuccess() ); + + assert ( k2.mode() == Gaudi::DataHandle::Writer); + assert ( k2.key() == "MyObj2"); + assert ( k2.initialize().isSuccess() ); + + assert ( k3.mode() == Gaudi::DataHandle::Writer); + assert ( k3.key() == "MyObj3"); + assert ( k3.initialize().isSuccess() ); + + assert ( kD.mode() == Gaudi::DataHandle::Writer); + assert ( kD.key() == "MyObjD"); + assert ( kD.initialize().isSuccess() ); + + + SG::WriteCondHandle wch1(k1); + SG::WriteCondHandle wch2(k2); + SG::WriteCondHandle wch3(k3); + + EventIDBase s1(0, EventIDBase::UNDEFEVT, 0); + EventIDBase e1(0, EventIDBase::UNDEFEVT, 10); + EventIDRange r1 (s1,e1); + + EventIDBase s2(0, EventIDBase::UNDEFEVT, 3); + EventIDBase e2(0, EventIDBase::UNDEFEVT, 8); + EventIDRange r2 (s2,e2); + + EventIDBase s3(0, EventIDBase::UNDEFEVT, 5); + EventIDBase e3(0, EventIDBase::UNDEFEVT, 15); + EventIDRange r3 (s3,e3); + + + std::cout << "r1: " << r1 << std::endl; + std::cout << "r2: " << r2 << std::endl; + std::cout << "r3: " << r3 << std::endl; + + wch1.record( r1, std::make_unique( MyObj(1) ) ); + wch2.record( r2, std::make_unique( MyObj(2) ) ); + wch3.record( r3, std::make_unique( MyObj(3) ) ); + + SG::ReadCondHandleKey rk1 {"MyObj1"}; + assert ( rk1.mode() == Gaudi::DataHandle::Reader); + assert ( rk1.key() == "MyObj1"); + assert ( rk1.initialize().isSuccess() ); + + SG::ReadCondHandleKey rk2 {"MyObj2"}; + assert ( rk2.mode() == Gaudi::DataHandle::Reader); + assert ( rk2.key() == "MyObj2"); + assert ( rk2.initialize().isSuccess() ); + + SG::ReadCondHandleKey rk3 {"MyObj3"}; + assert ( rk3.mode() == Gaudi::DataHandle::Reader); + assert ( rk3.key() == "MyObj3"); + assert ( rk3.initialize().isSuccess() ); + + + EventIDBase now(0, EventIDBase::UNDEFEVT, 6); + SGTest::TestStore dumstore; + EventContext ctx(1, 1); + ctx.setEventID( now ); + ctx.setExtension( Atlas::ExtendedEventContext(&dumstore) ); + Gaudi::Hive::setCurrentContext(ctx); + + SG::ReadCondHandle rch1(rk1); + SG::ReadCondHandle rch2(rk2); + SG::ReadCondHandle rch3(rk3); + + auto o1 = rch1.retrieve( now ); + EventIDRange rr1 = rch1.getRange(); + + auto o2 = rch2.retrieve( now ); + EventIDRange rr2 = rch2.getRange(); + + auto o3 = rch3.retrieve( now ); + EventIDRange rr3 = rch3.getRange(); + + assert( rr1 == r1 ); + assert( rr2 == r2 ); + assert( rr3 == r3 ); + + std::cout << "o1: " << o1->x << " " << rr1 << std::endl; + std::cout << "o2: " << o2->x << " " << rr2 << std::endl; + std::cout << "o3: " << o3->x << " " << rr3 << std::endl; + + + SG::WriteCondHandle wchD(kD); + // can't record without a range + assert ( wchD.record( std::make_unique( MyDObj(11) ) ).isFailure() ); + + wchD.addDependency( rch1 ); + assert ( wchD.getRange() == r1 ); + wchD.addDependency( rch2, rch3 ); + assert (wchD.record( std::make_unique( MyDObj(11) ) ).isSuccess() ); + + + EventIDRange rD = wchD.getRange(); + std::cout << "rD: " << rD << std::endl; + + EventIDRange rI; + rI = EventIDRange::intersect(r1,r2,r3); + std::cout << "rI: " << rI << std::endl; + + assert (rI == rD); + +} + +void testDep (int timeVal, + EventIDRange& r1, EventIDRange& r2, EventIDRange &r3, + SG::ReadCondHandleKey& rk1, + SG::ReadCondHandleKey& rk2, + SG::ReadCondHandleKey& rk3, + SG::WriteCondHandleKey& kD, + SGTest::TestStore *store, int testval) { + + EventIDBase now(0, EventIDBase::UNDEFEVT, timeVal); + EventContext ctx(1, 1); + ctx.setEventID( now ); + ctx.setExtension( Atlas::ExtendedEventContext(store) ); + Gaudi::Hive::setCurrentContext(ctx); + + std::cout << "test EventID: " << now << std::endl; + + SG::ReadCondHandle rch1(rk1); + SG::ReadCondHandle rch2(rk2); + SG::ReadCondHandle rch3(rk3); + + auto o1 = rch1.retrieve( now ); + EventIDRange rr1 = rch1.getRange(); + + auto o2 = rch2.retrieve( now ); + EventIDRange rr2 = rch2.getRange(); + + auto o3 = rch3.retrieve( now ); + EventIDRange rr3 = rch3.getRange(); + + assert( rr1 == r1 ); + assert( rr2 == r2 ); + assert( rr3 == r3 ); + + std::cout << "o1: " << o1->x << " " << rr1 << " " << rch1.getRange() << std::endl; + std::cout << "o2: " << o2->x << " " << rr2 << std::endl; + std::cout << "o3: " << o3->x << " " << rr3 << std::endl; + + SG::WriteCondHandle wchD(kD); + + // can't record without a range + std::cout << "ERROR expected: "; + assert ( wchD.record( std::make_unique( MyDObj(0) ) ).isFailure() ); + + wchD.addDependency( rch1 ); + assert ( wchD.getRange() == r1 ); + wchD.addDependency( rch2, rch3 ); + int val = rch1->x + rch2->x + rch3->x; + assert (val == testval); + assert (wchD.record( std::make_unique( MyDObj(val) ) ).isSuccess() ); + + + EventIDRange rD = wchD.getRange(); + std::cout << "rD: " << rD << std::endl; + + EventIDRange rI; + rI = EventIDRange::intersect(r1,r2,r3); + std::cout << "rI: " << rI << std::endl; + + assert (rI == rD); + + +} + +void test2() +{ + std::cout << "test2\n"; + + SG::WriteCondHandleKey k1 {"MyObj1"}; + SG::WriteCondHandleKey k2 {"MyObj2"}; + SG::WriteCondHandleKey k3 {"MyObj3"}; + + SG::WriteCondHandleKey kD {"MyObjD"}; + + assert ( k1.mode() == Gaudi::DataHandle::Writer); + assert ( k1.key() == "MyObj1"); + assert ( k1.initialize().isSuccess() ); + + assert ( k2.mode() == Gaudi::DataHandle::Writer); + assert ( k2.key() == "MyObj2"); + assert ( k2.initialize().isSuccess() ); + + assert ( k3.mode() == Gaudi::DataHandle::Writer); + assert ( k3.key() == "MyObj3"); + assert ( k3.initialize().isSuccess() ); + + assert ( kD.mode() == Gaudi::DataHandle::Writer); + assert ( kD.key() == "MyObjD"); + assert ( kD.initialize().isSuccess() ); + + + SG::WriteCondHandle wch1(k1); + SG::WriteCondHandle wch2(k2); + SG::WriteCondHandle wch3(k3); + + EventIDBase s1_1(0, EventIDBase::UNDEFEVT, 0); + EventIDBase e1_1(0, EventIDBase::UNDEFEVT, 3); + EventIDRange r1_1 (s1_1,e1_1); + EventIDBase s1_2(0, EventIDBase::UNDEFEVT, 3); + EventIDBase e1_2(0, EventIDBase::UNDEFEVT, 7); + EventIDRange r1_2 (s1_2,e1_2); + EventIDBase s1_3(0, EventIDBase::UNDEFEVT, 7); + EventIDBase e1_3(0, EventIDBase::UNDEFEVT, 10); + EventIDRange r1_3 (s1_3,e1_3); + + EventIDBase s2_1(0, EventIDBase::UNDEFEVT, 0); + EventIDBase e2_1(0, EventIDBase::UNDEFEVT, 5); + EventIDRange r2_1 (s2_1,e2_1); + EventIDBase s2_2(0, EventIDBase::UNDEFEVT, 5); + EventIDBase e2_2(0, EventIDBase::UNDEFEVT, 10); + EventIDRange r2_2 (s2_2,e2_2); + + EventIDBase s3_1(0, EventIDBase::UNDEFEVT, 0); + EventIDBase e3_1(0, EventIDBase::UNDEFEVT, 2); + EventIDRange r3_1 (s3_1,e3_1); + EventIDBase s3_2(0, EventIDBase::UNDEFEVT, 2); + EventIDBase e3_2(0, EventIDBase::UNDEFEVT, 6); + EventIDRange r3_2 (s3_2,e3_2); + EventIDBase s3_3(0, EventIDBase::UNDEFEVT, 6); + EventIDBase e3_3(0, EventIDBase::UNDEFEVT, 10); + EventIDRange r3_3 (s3_3,e3_3); + + + std::cout << "r1: " << r1_1 << " " << r1_2 << " " << r1_3 << std::endl; + std::cout << "r2: " << r2_1 << " " << r2_2 << std::endl; + std::cout << "r3: " << r3_1 << " " << r3_2 << " " << r3_3 << std::endl; + + wch1.record( r1_1, std::make_unique( MyObj(1) ) ); + wch1.record( r1_2, std::make_unique( MyObj(2) ) ); + wch1.record( r1_3, std::make_unique( MyObj(3) ) ); + wch2.record( r2_1, std::make_unique( MyObj2(21) ) ); + wch2.record( r2_2, std::make_unique( MyObj2(22) ) ); + wch3.record( r3_1, std::make_unique( MyObj3(131) ) ); + wch3.record( r3_2, std::make_unique( MyObj3(132) ) ); + wch3.record( r3_3, std::make_unique( MyObj3(133) ) ); + + SG::ReadCondHandleKey rk1 {"MyObj1"}; + assert ( rk1.mode() == Gaudi::DataHandle::Reader); + assert ( rk1.key() == "MyObj1"); + assert ( rk1.initialize().isSuccess() ); + + SG::ReadCondHandleKey rk2 {"MyObj2"}; + assert ( rk2.mode() == Gaudi::DataHandle::Reader); + assert ( rk2.key() == "MyObj2"); + assert ( rk2.initialize().isSuccess() ); + + SG::ReadCondHandleKey rk3 {"MyObj3"}; + assert ( rk3.mode() == Gaudi::DataHandle::Reader); + assert ( rk3.key() == "MyObj3"); + assert ( rk3.initialize().isSuccess() ); + + + SGTest::TestStore dumstore; + + testDep(1, r1_1, r2_1, r3_1, rk1, rk2, rk3, kD, &dumstore, 153); + testDep(4, r1_2, r2_1, r3_2, rk1, rk2, rk3, kD, &dumstore, 155); + testDep(6, r1_2, r2_2, r3_3, rk1, rk2, rk3, kD, &dumstore, 157); + testDep(9, r1_3, r2_2, r3_3, rk1, rk2, rk3, kD, &dumstore, 158); + + +} + + +int main() +{ + ISvcLocator* svcloc; + //need MessageSvc + if (!Athena_test::initGaudi("WriteCondHandle_test.txt", svcloc)) { + return 1; + } + + // test1(); + + test2(); + return 0; +} -- GitLab From 9eb58f76968cde521c28419c5411ef83316bad63 Mon Sep 17 00:00:00 2001 From: charles leggett Date: Wed, 23 Oct 2019 11:42:54 -0700 Subject: [PATCH 5/9] build test --- Control/StoreGate/CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Control/StoreGate/CMakeLists.txt b/Control/StoreGate/CMakeLists.txt index 8917bfaf452..b7efdfb1bbb 100644 --- a/Control/StoreGate/CMakeLists.txt +++ b/Control/StoreGate/CMakeLists.txt @@ -187,6 +187,12 @@ atlas_add_test( CondHandleKeyArray_test LINK_LIBRARIES StoreGateLib AthContainers TestTools ENVIRONMENT "JOBOPTSEARCHPATH=${CMAKE_CURRENT_SOURCE_DIR}/share" ) +atlas_add_test( WriteCondHandle_test + SOURCES test/WriteCondHandle_test.cxx + INCLUDE_DIRS ${Boost_INCLUDE_DIRS} + LINK_LIBRARIES StoreGateLib AthContainers TestTools + ENVIRONMENT "JOBOPTSEARCHPATH=${CMAKE_CURRENT_SOURCE_DIR}/share" ) + atlas_add_test( WriteDecorHandleKeyArray_test SOURCES test/WriteDecorHandleKeyArray_test.cxx INCLUDE_DIRS ${Boost_INCLUDE_DIRS} -- GitLab From 57f06c2e7e350205f4f90f3a7dda4a1d46e59f0e Mon Sep 17 00:00:00 2001 From: charles leggett Date: Wed, 23 Oct 2019 11:43:17 -0700 Subject: [PATCH 6/9] add getRange() --- Control/StoreGate/StoreGate/ReadCondHandle.h | 26 ++++++++++++++++--- Control/StoreGate/StoreGate/WriteCondHandle.h | 16 ++++++++---- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/Control/StoreGate/StoreGate/ReadCondHandle.h b/Control/StoreGate/StoreGate/ReadCondHandle.h index db4035cb2fe..48fb8bdb139 100644 --- a/Control/StoreGate/StoreGate/ReadCondHandle.h +++ b/Control/StoreGate/StoreGate/ReadCondHandle.h @@ -59,6 +59,7 @@ namespace SG { bool range(EventIDRange& r); bool range(const EventIDBase& t, EventIDRange& r) const; + const EventIDRange& getRange(); private: @@ -208,8 +209,9 @@ namespace SG { return retrieve(); } - pointer_type obj(0); - if (! (m_cc->find(eid, obj) ) ) { + // pointer_type obj(0); + const_pointer_type cobj(0); + if (! (m_cc->find(eid, cobj) ) ) { std::ostringstream ost; m_cc->list(ost); MsgStream msg(Athena::getMessageSvc(), "ReadCondHandle"); @@ -221,7 +223,7 @@ namespace SG { return nullptr; } - const_pointer_type cobj = const_cast( obj ); + // const_pointer_type cobj = const_cast( obj ); return cobj; } @@ -264,6 +266,24 @@ namespace SG { return false; } + template + const EventIDRange& + ReadCondHandle::getRange() { + + if (m_obj == 0) { + if (!initCondHandle()) { + throw std::runtime_error("ReadCondHandle: handle not initialized when doing getRange()"); + } + } + + if (!m_range) { + throw std::runtime_error("ReadCondHandle: range obj not set when doing getRange()"); + } + return *m_range; + + } + + //--------------------------------------------------------------------------- template diff --git a/Control/StoreGate/StoreGate/WriteCondHandle.h b/Control/StoreGate/StoreGate/WriteCondHandle.h index 82fd78d48a0..a50bdd576aa 100644 --- a/Control/StoreGate/StoreGate/WriteCondHandle.h +++ b/Control/StoreGate/StoreGate/WriteCondHandle.h @@ -73,7 +73,7 @@ namespace SG { const std::string& dbKey() const { return m_hkey.dbKey(); } - const EventIDRange& range() const { return m_range; } + const EventIDRange& getRange() const { return m_range; } private: @@ -82,7 +82,7 @@ namespace SG { const SG::WriteCondHandleKey& m_hkey; - EventIDRange m_range; + EventIDRange m_range{}; }; @@ -168,6 +168,10 @@ namespace SG { if (m_range.start().isValid() && m_range.stop().isValid()) { return record(m_range, std::move(t)); } + MsgStream msg(Athena::getMessageSvc(), "WriteCondHandle"); + msg << MSG::ERROR + << "WriteCondHandle::record() : no range defined" + << endmsg; return StatusCode::FAILURE; } @@ -219,9 +223,11 @@ namespace SG { template< typename R> void WriteCondHandle::addDependency(SG::ReadCondHandle& rch) { - EventIDRange r; - rch.range(r); - m_range = m_range.intersect(m_range, r); + if (m_range == EventIDRange()) { + m_range = rch.getRange(); + } else { + m_range = EventIDRange::intersect(m_range, rch.getRange()); + } } template< typename T> -- GitLab From 88fec068ac05838a0eb5fa35b0095262560e9f0f Mon Sep 17 00:00:00 2001 From: charles leggett Date: Wed, 23 Oct 2019 11:43:42 -0700 Subject: [PATCH 7/9] fix CondAlgZ --- Control/AthenaExamples/AthExHive/src/condEx/CondAlgZ.cxx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Control/AthenaExamples/AthExHive/src/condEx/CondAlgZ.cxx b/Control/AthenaExamples/AthExHive/src/condEx/CondAlgZ.cxx index de4f03bec02..04d420dae8d 100644 --- a/Control/AthenaExamples/AthExHive/src/condEx/CondAlgZ.cxx +++ b/Control/AthenaExamples/AthExHive/src/condEx/CondAlgZ.cxx @@ -76,6 +76,9 @@ StatusCode CondAlgZ::execute() { const CondDataObj *cdo1 = *rch1; const CondDataObjY *cdo2 = *rch2; const CondDataObjY *cdo3 = *rch3; + + ATH_MSG_DEBUG(" rh1: " << cdo1->val() << " rh2: " << cdo2->val() + << " rh3: " << cdo3->val()); SG::WriteCondHandle wch(m_wch); @@ -95,11 +98,11 @@ StatusCode CondAlgZ::execute() { ( CondDataObjZ(val) ) ).isFailure()) { ATH_MSG_ERROR("could not record CondDataObjZ " << wch.key() << " val: " << val - << " with EventRange " << wch.range() ); + << " with EventRange " << wch.getRange() ); return StatusCode::FAILURE; } ATH_MSG_INFO("recorded new CDO " << wch.key() << " = " << val - << " with range " << wch.range() ); + << " with range " << wch.getRange() ); } return StatusCode::SUCCESS; -- GitLab From e1ce0528017ad18bc8839e17059751dc66a172d1 Mon Sep 17 00:00:00 2001 From: charles leggett Date: Thu, 24 Oct 2019 12:27:50 -0700 Subject: [PATCH 8/9] test for WriteCondHandle records with explicit range after a dependency added --- Control/StoreGate/StoreGate/WriteCondHandle.h | 19 ++++++-- .../StoreGate/share/WriteCondHandle_test.ref | 20 +++----- .../StoreGate/test/WriteCondHandle_test.cxx | 47 ++++++++++++++----- 3 files changed, 58 insertions(+), 28 deletions(-) diff --git a/Control/StoreGate/StoreGate/WriteCondHandle.h b/Control/StoreGate/StoreGate/WriteCondHandle.h index a50bdd576aa..0e2b94b33ef 100644 --- a/Control/StoreGate/StoreGate/WriteCondHandle.h +++ b/Control/StoreGate/StoreGate/WriteCondHandle.h @@ -83,6 +83,7 @@ namespace SG { const SG::WriteCondHandleKey& m_hkey; EventIDRange m_range{}; + bool m_rangeSet {false}; }; @@ -131,6 +132,15 @@ namespace SG { << "WriteCondHandle::record() : obj at: " << t.get() << " range: " << r << endmsg; + if (m_rangeSet) { + msg << MSG::ERROR + << "WriteCondHandle::record(EventIDRange, T*): for key " + << this->fullKey() + << " cannot use this method if range has already been set via dependencies" + << endmsg; + return StatusCode::FAILURE; + } + StatusCode sc = m_cc->insert(r, std::move(t)); // Preserve sc for return, since it may be DUPLICATE. if (sc.isFailure()) { @@ -165,12 +175,14 @@ namespace SG { template StatusCode WriteCondHandle::record(std::unique_ptr t) { - if (m_range.start().isValid() && m_range.stop().isValid()) { - return record(m_range, std::move(t)); + if (m_rangeSet) { + m_rangeSet = false; + return record(m_range, std::move(t)); } MsgStream msg(Athena::getMessageSvc(), "WriteCondHandle"); msg << MSG::ERROR - << "WriteCondHandle::record() : no range defined" + << "WriteCondHandle::record() : no range defined for key " + << this->fullKey() << endmsg; return StatusCode::FAILURE; } @@ -228,6 +240,7 @@ namespace SG { } else { m_range = EventIDRange::intersect(m_range, rch.getRange()); } + m_rangeSet = true; } template< typename T> diff --git a/Control/StoreGate/share/WriteCondHandle_test.ref b/Control/StoreGate/share/WriteCondHandle_test.ref index 6f03be41e85..ba605ebe046 100644 --- a/Control/StoreGate/share/WriteCondHandle_test.ref +++ b/Control/StoreGate/share/WriteCondHandle_test.ref @@ -8,7 +8,7 @@ JobOptionsSvc INFO Job options successfully read in from /home/leggett/wo ApplicationMgr SUCCESS ==================================================================================================================================== Welcome to ApplicationMgr (GaudiCoreSvc v32r2) - running on zeus on Wed Oct 23 11:04:02 2019 + running on zeus on Thu Oct 24 12:04:07 2019 ==================================================================================================================================== ApplicationMgr INFO Application Manager Configured successfully ClassIDSvc INFO getRegistryEntries: read 764 CLIDRegistry entries for module ALL @@ -22,31 +22,25 @@ r1: {[0,t:0] - [0,t:3]} {[0,t:3] - [0,t:7]} {[0,t:7] - [0,t:10]} r2: {[0,t:0] - [0,t:5]} {[0,t:5] - [0,t:10]} r3: {[0,t:0] - [0,t:2]} {[0,t:2] - [0,t:6]} {[0,t:6] - [0,t:10]} ClassIDSvc INFO getRegistryEntries: read 2638 CLIDRegistry entries for module ALL +expected ERROR: WriteCondHandle ERROR WriteCondHandle::record() : no range defined for key ( 'MyDObj' , 'ConditionStore+MyObjD_err' ) +expected ERROR: WriteCondHandle ERROR WriteCondHandle::record(EventIDRange, T*): for key ( 'MyDObj' , 'ConditionStore+MyObjD_err' ) cannot use this method if range has already been set via dependencies test EventID: [0,t:1] o1: 1 {[0,t:0] - [0,t:3]} {[0,t:0] - [0,t:3]} o2: 21 {[0,t:0] - [0,t:5]} o3: 131 {[0,t:0] - [0,t:2]} -ERROR expected: WriteCondHandle ERROR WriteCondHandle::record() : no range defined -rD: {[0,t:0] - [0,t:2]} -rI: {[0,t:0] - [0,t:2]} +rD: {[0,t:0] - [0,t:2]} == {[0,t:0] - [0,t:2]} test EventID: [0,t:4] o1: 2 {[0,t:3] - [0,t:7]} {[0,t:3] - [0,t:7]} o2: 21 {[0,t:0] - [0,t:5]} o3: 132 {[0,t:2] - [0,t:6]} -ERROR expected: WriteCondHandle ERROR WriteCondHandle::record() : no range defined -rD: {[0,t:3] - [0,t:5]} -rI: {[0,t:3] - [0,t:5]} +rD: {[0,t:3] - [0,t:5]} == {[0,t:3] - [0,t:5]} test EventID: [0,t:6] o1: 2 {[0,t:3] - [0,t:7]} {[0,t:3] - [0,t:7]} o2: 22 {[0,t:5] - [0,t:10]} o3: 133 {[0,t:6] - [0,t:10]} -ERROR expected: WriteCondHandle ERROR WriteCondHandle::record() : no range defined -rD: {[0,t:6] - [0,t:7]} -rI: {[0,t:6] - [0,t:7]} +rD: {[0,t:6] - [0,t:7]} == {[0,t:6] - [0,t:7]} test EventID: [0,t:9] o1: 3 {[0,t:7] - [0,t:10]} {[0,t:7] - [0,t:10]} o2: 22 {[0,t:5] - [0,t:10]} o3: 133 {[0,t:6] - [0,t:10]} -ERROR expected: WriteCondHandle ERROR WriteCondHandle::record() : no range defined -rD: {[0,t:7] - [0,t:10]} -rI: {[0,t:7] - [0,t:10]} +rD: {[0,t:7] - [0,t:10]} == {[0,t:7] - [0,t:10]} diff --git a/Control/StoreGate/test/WriteCondHandle_test.cxx b/Control/StoreGate/test/WriteCondHandle_test.cxx index 4feb2f5bace..e952a389ee7 100644 --- a/Control/StoreGate/test/WriteCondHandle_test.cxx +++ b/Control/StoreGate/test/WriteCondHandle_test.cxx @@ -277,27 +277,19 @@ void testDep (int timeVal, SG::WriteCondHandle wchD(kD); - // can't record without a range - std::cout << "ERROR expected: "; - assert ( wchD.record( std::make_unique( MyDObj(0) ) ).isFailure() ); - wchD.addDependency( rch1 ); assert ( wchD.getRange() == r1 ); + wchD.addDependency( rch2, rch3 ); int val = rch1->x + rch2->x + rch3->x; assert (val == testval); assert (wchD.record( std::make_unique( MyDObj(val) ) ).isSuccess() ); - EventIDRange rD = wchD.getRange(); - std::cout << "rD: " << rD << std::endl; - - EventIDRange rI; - rI = EventIDRange::intersect(r1,r2,r3); - std::cout << "rI: " << rI << std::endl; + EventIDRange rI = EventIDRange::intersect(r1,r2,r3); assert (rI == rD); - + std::cout << "rD: " << rD << " == " << rI << std::endl; } @@ -388,9 +380,35 @@ void test2() assert ( rk3.key() == "MyObj3"); assert ( rk3.initialize().isSuccess() ); - SGTest::TestStore dumstore; + + // test some error conditions + { + SG::WriteCondHandleKey kDe1 {"MyObjD_err"}; + assert( kDe1.initialize().isSuccess() ); + SG::WriteCondHandle we1(kDe1); + + EventIDBase now(0, EventIDBase::UNDEFEVT, 1); + EventContext ctx(1, 1); + ctx.setEventID( now ); + ctx.setExtension( Atlas::ExtendedEventContext(&dumstore) ); + Gaudi::Hive::setCurrentContext(ctx); + + // can't record without a range + std::cout << "expected ERROR: "; + assert ( we1.record( std::make_unique( MyDObj(0) ) ).isFailure() ); + + SG::ReadCondHandle rerr(rk1); + we1.addDependency( rerr ); + assert ( we1.getRange() == r1_1 ); + + // can't record with a range, when dep already set + std::cout << "expected ERROR: "; + assert ( we1.record( r2_1, std::make_unique( MyDObj(0) ) ).isFailure() ); + } + + testDep(1, r1_1, r2_1, r3_1, rk1, rk2, rk3, kD, &dumstore, 153); testDep(4, r1_2, r2_1, r3_2, rk1, rk2, rk3, kD, &dumstore, 155); testDep(6, r1_2, r2_2, r3_3, rk1, rk2, rk3, kD, &dumstore, 157); @@ -408,7 +426,12 @@ int main() return 1; } + StoreGateSvc *cs=nullptr; + assert (svcloc->service("StoreGateSvc/ConditionStore",cs).isSuccess()); + // test1(); + // std::cout << "clearing ConditionStore\n"; + // cs->clearStore(); test2(); return 0; -- GitLab From 4cb34106550f5effb28eadfa3c387e7aa8f6f9ad Mon Sep 17 00:00:00 2001 From: charles leggett Date: Thu, 24 Oct 2019 13:49:08 -0700 Subject: [PATCH 9/9] add record(T*) method, make rangeless records preferable --- Control/StoreGate/StoreGate/WriteCondHandle.h | 88 ++++++++++++------- .../StoreGate/test/WriteCondHandle_test.cxx | 35 +++++--- 2 files changed, 77 insertions(+), 46 deletions(-) diff --git a/Control/StoreGate/StoreGate/WriteCondHandle.h b/Control/StoreGate/StoreGate/WriteCondHandle.h index 0e2b94b33ef..d0cc3fec19e 100644 --- a/Control/StoreGate/StoreGate/WriteCondHandle.h +++ b/Control/StoreGate/StoreGate/WriteCondHandle.h @@ -49,6 +49,11 @@ namespace SG { template void addDependency(ReadCondHandle& rch, Args... args); + /** + * @brief record handle, with explicit range DEPRECATED + * @param range IOVRange of handle + * @param t unique_ptr to handle + */ StatusCode record(const EventIDRange& range, T* t); StatusCode record(const EventIDRange& range, std::unique_ptr t); @@ -57,6 +62,7 @@ namespace SG { * @param t unique_ptr to handle */ StatusCode record(std::unique_ptr t); + StatusCode record(T* t); /** * @brief Extend the range of the last IOV. @@ -127,12 +133,9 @@ namespace SG { StatusCode WriteCondHandle::record(const EventIDRange& r, std::unique_ptr t) { - MsgStream msg(Athena::getMessageSvc(), "WriteCondHandle"); - msg << MSG::DEBUG - << "WriteCondHandle::record() : obj at: " << t.get() << " range: " << r - << endmsg; - + if (m_rangeSet) { + MsgStream msg(Athena::getMessageSvc(), "WriteCondHandle"); msg << MSG::ERROR << "WriteCondHandle::record(EventIDRange, T*): for key " << this->fullKey() @@ -141,18 +144,59 @@ namespace SG { return StatusCode::FAILURE; } - StatusCode sc = m_cc->insert(r, std::move(t)); + m_range = r; + m_rangeSet = true; + + return record( std::move(t) ); + } + + template + StatusCode + WriteCondHandle::record(const EventIDRange& r, T* t) + { + return record (r, std::unique_ptr (t)); + } + + template + StatusCode + WriteCondHandle::record(T* t) { + return record (std::unique_ptr (t)); + } + + template + StatusCode + WriteCondHandle::record(std::unique_ptr t) { + if (! m_rangeSet) { + MsgStream msg(Athena::getMessageSvc(), "WriteCondHandle"); + msg << MSG::ERROR + << "WriteCondHandle::record() : no range defined for key " + << this->fullKey() + << endmsg; + return StatusCode::FAILURE; + } + + #ifndef NDEBUG + MsgStream msg(Athena::getMessageSvc(), "WriteCondHandle"); + if (msg.level() <= MSG::DEBUG) { + msg << MSG::DEBUG + << "WriteCondHandle::record() : obj at: " << t.get() << " range: " + << m_range << endmsg; + } + #endif + + StatusCode sc = m_cc->insert(m_range, std::move(t)); // Preserve sc for return, since it may be DUPLICATE. if (sc.isFailure()) { + MsgStream msg(Athena::getMessageSvc(), "WriteCondHandle"); msg << MSG::ERROR << "WriteCondHandle::record() : unable to insert obj in CondCont" << endmsg; return StatusCode::FAILURE; - } - else if (CondContBase::Category::isOverlap (sc)) { + } else if (CondContBase::Category::isOverlap (sc)) { #if 0 // Temporarily disable this check until caching issues with IOVDbSvc // are sorted out. + MsgStream msg(Athena::getMessageSvc(), "WriteCondHandle"); msg << MSG::ERROR << "WriteCondHandle::record() : IOV ranges overlap." << endmsg; @@ -160,33 +204,9 @@ namespace SG { #endif sc = StatusCode::SUCCESS; } - - return sc; - } - - - template - StatusCode - WriteCondHandle::record(const EventIDRange& r, T* t) - { - return record (r, std::unique_ptr (t)); - } - template - StatusCode - WriteCondHandle::record(std::unique_ptr t) { - if (m_rangeSet) { - m_rangeSet = false; - return record(m_range, std::move(t)); - } - MsgStream msg(Athena::getMessageSvc(), "WriteCondHandle"); - msg << MSG::ERROR - << "WriteCondHandle::record() : no range defined for key " - << this->fullKey() - << endmsg; - return StatusCode::FAILURE; + return sc; } - //--------------------------------------------------------------------------- @@ -235,7 +255,7 @@ namespace SG { template< typename R> void WriteCondHandle::addDependency(SG::ReadCondHandle& rch) { - if (m_range == EventIDRange()) { + if ( !m_rangeSet ) { m_range = rch.getRange(); } else { m_range = EventIDRange::intersect(m_range, rch.getRange()); diff --git a/Control/StoreGate/test/WriteCondHandle_test.cxx b/Control/StoreGate/test/WriteCondHandle_test.cxx index e952a389ee7..a738cf2ec90 100644 --- a/Control/StoreGate/test/WriteCondHandle_test.cxx +++ b/Control/StoreGate/test/WriteCondHandle_test.cxx @@ -293,7 +293,7 @@ void testDep (int timeVal, } -void test2() +void test2( StoreGateSvc* cs ) { std::cout << "test2\n"; @@ -319,7 +319,12 @@ void test2() assert ( kD.key() == "MyObjD"); assert ( kD.initialize().isSuccess() ); - + // fill up the ConditionStore with some test data: + // time --> + // MyObj1 1112222333 + // MyObj2 xxxxxyyyyy + // MyObj3 aabbbbcccc + // SG::WriteCondHandle wch1(k1); SG::WriteCondHandle wch2(k2); SG::WriteCondHandle wch3(k3); @@ -350,20 +355,26 @@ void test2() EventIDBase s3_3(0, EventIDBase::UNDEFEVT, 6); EventIDBase e3_3(0, EventIDBase::UNDEFEVT, 10); EventIDRange r3_3 (s3_3,e3_3); - std::cout << "r1: " << r1_1 << " " << r1_2 << " " << r1_3 << std::endl; std::cout << "r2: " << r2_1 << " " << r2_2 << std::endl; std::cout << "r3: " << r3_1 << " " << r3_2 << " " << r3_3 << std::endl; - wch1.record( r1_1, std::make_unique( MyObj(1) ) ); - wch1.record( r1_2, std::make_unique( MyObj(2) ) ); - wch1.record( r1_3, std::make_unique( MyObj(3) ) ); - wch2.record( r2_1, std::make_unique( MyObj2(21) ) ); - wch2.record( r2_2, std::make_unique( MyObj2(22) ) ); - wch3.record( r3_1, std::make_unique( MyObj3(131) ) ); - wch3.record( r3_2, std::make_unique( MyObj3(132) ) ); - wch3.record( r3_3, std::make_unique( MyObj3(133) ) ); + CondCont *cc1; + assert( cs->retrieve(cc1, k1.key()).isSuccess() ); + CondCont *cc2; + assert( cs->retrieve(cc2, k2.key()).isSuccess() ); + CondCont *cc3; + assert( cs->retrieve(cc3, k3.key()).isSuccess() ); + + assert( cc1->insert( r1_1, std::make_unique( MyObj(1) ) ).isSuccess() ); + assert( cc1->insert( r1_2, std::make_unique( MyObj(2) ) ).isSuccess() ); + assert( cc1->insert( r1_3, std::make_unique( MyObj(3) ) ).isSuccess() ); + assert( cc2->insert( r2_1, std::make_unique( MyObj2(21) ) ).isSuccess() ); + assert( cc2->insert( r2_2, std::make_unique( MyObj2(22) ) ).isSuccess() ); + assert( cc3->insert( r3_1, std::make_unique( MyObj3(131) ) ).isSuccess() ); + assert( cc3->insert( r3_2, std::make_unique( MyObj3(132) ) ).isSuccess() ); + assert( cc3->insert( r3_3, std::make_unique( MyObj3(133) ) ).isSuccess() ); SG::ReadCondHandleKey rk1 {"MyObj1"}; assert ( rk1.mode() == Gaudi::DataHandle::Reader); @@ -433,6 +444,6 @@ int main() // std::cout << "clearing ConditionStore\n"; // cs->clearStore(); - test2(); + test2(cs); return 0; } -- GitLab