diff --git a/Control/AthToolSupport/AsgDataHandles/AsgDataHandles/ReadDecorHandle.h b/Control/AthToolSupport/AsgDataHandles/AsgDataHandles/ReadDecorHandle.h index a4174f284db66d16f2023eba112fafab15bfb162..ef69de9eac3fd6a4da9ebddd117ff2e2104c6a75 100644 --- a/Control/AthToolSupport/AsgDataHandles/AsgDataHandles/ReadDecorHandle.h +++ b/Control/AthToolSupport/AsgDataHandles/AsgDataHandles/ReadDecorHandle.h @@ -147,11 +147,11 @@ public: // getDataArray(); -// /** -// * @brief Test to see if this variable exists in the store, -// * for the referenced object. -// */ -// bool isAvailable(); + /** + * @brief Test to see if this variable exists in the store, + * for the referenced object. + */ + bool isAvailable(); // /** diff --git a/Control/AthToolSupport/AsgDataHandles/AsgDataHandles/ReadDecorHandle.icc b/Control/AthToolSupport/AsgDataHandles/AsgDataHandles/ReadDecorHandle.icc index bda9623c1ebf852c3051a04fad9e85e0a506a148..429fdb4636deab1dcdcee31c4fc40513c3cbda27 100644 --- a/Control/AthToolSupport/AsgDataHandles/AsgDataHandles/ReadDecorHandle.icc +++ b/Control/AthToolSupport/AsgDataHandles/AsgDataHandles/ReadDecorHandle.icc @@ -161,17 +161,17 @@ ReadDecorHandle<T, D>::operator() (size_t i) // } -// /** -// * @brief Test to see if this variable exists in the store, -// * for the referenced object. -// */ -// template <class T, class D> -// inline -// bool ReadDecorHandle<T, D>::isAvailable() -// { -// const SG::AuxVectorData* vec = this->vectorData(); -// return vec && vec->isAvailable (m_acc.auxid()); -// } +/** + * @brief Test to see if this variable exists in the store, + * for the referenced object. + */ +template <class T, class D> +inline +bool ReadDecorHandle<T, D>::isAvailable() +{ + const SG::AuxVectorData* vec = this->vectorData(); + return vec && vec->isAvailable (m_acc.auxid()); +} // /** diff --git a/Control/AthToolSupport/AsgDataHandles/AsgDataHandles/WriteDecorHandle.h b/Control/AthToolSupport/AsgDataHandles/AsgDataHandles/WriteDecorHandle.h index e93296a892cce71434939733570e5c17338f6cbd..b02aa5f2189529d5e3208981f5231adb4f91017f 100644 --- a/Control/AthToolSupport/AsgDataHandles/AsgDataHandles/WriteDecorHandle.h +++ b/Control/AthToolSupport/AsgDataHandles/AsgDataHandles/WriteDecorHandle.h @@ -113,15 +113,15 @@ public: // WriteDecorHandle& operator= (WriteDecorHandle&& rhs); -// /** -// * @brief Is the referenced container present in SG? -// * -// * Note that this tests for the presence of the _container_, -// * not for the decoration. -// * -// * Const method; the handle does not change as a result of this. -// */ -// bool isPresent() const; + /** + * @brief Is the referenced container present in SG? + * + * Note that this tests for the presence of the _container_, + * not for the decoration. + * + * Const method; the handle does not change as a result of this. + */ + bool isPresent() const; // /** @@ -161,11 +161,11 @@ public: // getDecorationArray(); -// /** -// * @brief Test to see if this variable exists in the store, -// * for the referenced object. -// */ -// bool isAvailable(); + /** + * @brief Test to see if this variable exists in the store, + * for the referenced object. + */ + bool isAvailable(); // /** @@ -197,22 +197,22 @@ public: // virtual void* typeless_dataPointer_impl (bool quiet) override; -// /** -// * @brief Test to see if this variable exists in the store, -// * for the referenced object. -// * Specialization for the case of a standalone object -// * (@c T derives from @c SG::AuxElement). -// */ -// bool isAvailable (std::true_type); + /** + * @brief Test to see if this variable exists in the store, + * for the referenced object. + * Specialization for the case of a standalone object + * (@c T derives from @c SG::AuxElement). + */ + bool isAvailable (std::true_type); -// /** -// * @brief Test to see if this variable exists in the store, -// * for the referenced object. -// * Specialization for the case of a container -// * (@c T does not derive from @c SG::AuxElement). -// */ -// bool isAvailable (std::false_type); + /** + * @brief Test to see if this variable exists in the store, + * for the referenced object. + * Specialization for the case of a container + * (@c T does not derive from @c SG::AuxElement). + */ + bool isAvailable (std::false_type); // /** diff --git a/Control/AthToolSupport/AsgDataHandles/AsgDataHandles/WriteDecorHandle.icc b/Control/AthToolSupport/AsgDataHandles/AsgDataHandles/WriteDecorHandle.icc index 76b4eb5285485cb1979e673b88c681edd3dcdc86..f54aa1ecba57ba1ee46e410ae3b0849f2c74edf9 100644 --- a/Control/AthToolSupport/AsgDataHandles/AsgDataHandles/WriteDecorHandle.icc +++ b/Control/AthToolSupport/AsgDataHandles/AsgDataHandles/WriteDecorHandle.icc @@ -131,19 +131,19 @@ WriteDecorHandle<T, D>::WriteDecorHandle (const WriteDecorHandleKey<T>& key, // } -// /** -// * @brief Is the referenced container present in SG? -// * -// * Note that this tests for the presence of the _container_, -// * not for the decoration. -// * -// * Const method; the handle does not change as a result of this. -// */ -// template <class T, class D> -// bool WriteDecorHandle<T, D>::isPresent() const -// { -// return Base::isPresent(); -// } +/** + * @brief Is the referenced container present in SG? + * + * Note that this tests for the presence of the _container_, + * not for the decoration. + * + * Const method; the handle does not change as a result of this. + */ +template <class T, class D> +bool WriteDecorHandle<T, D>::isPresent() const +{ + return Base::isPresent(); +} // /** @@ -205,62 +205,62 @@ WriteDecorHandle<T, D>::operator() (const AuxElement& e) // } -// /** -// * @brief Test to see if this variable exists in the store, -// * for the referenced object. -// * Specialization for the case of a standalone object -// * (@c T derives from @c SG::AuxElement). -// */ -// template <class T, class D> -// inline -// bool WriteDecorHandle<T, D>::isAvailable (std::true_type) -// { -// const T* ptr = this->ptr(); -// if (ptr) { -// const SG::AuxVectorData* obj = ptr->container(); -// if (obj) { -// return obj->isAvailable (m_acc.auxid()); -// } -// } - -// return false; -// } +/** + * @brief Test to see if this variable exists in the store, + * for the referenced object. + * Specialization for the case of a standalone object + * (@c T derives from @c SG::AuxElement). + */ +template <class T, class D> +inline +bool WriteDecorHandle<T, D>::isAvailable (std::true_type) +{ + const T* ptr = this->ptr(); + if (ptr) { + const SG::AuxVectorData* obj = ptr->container(); + if (obj) { + return obj->isAvailable (m_acc.auxid()); + } + } + + return false; +} -// /** -// * @brief Test to see if this variable exists in the store, -// * for the referenced object. -// * Specialization for the case of a container -// * (@c T does not derive from @c SG::AuxElement). -// */ -// template <class T, class D> -// inline -// bool WriteDecorHandle<T, D>::isAvailable (std::false_type) -// { -// const T* ptr = this->ptr(); -// if (ptr) { -// return ptr->isAvailable (m_acc.auxid()); -// } +/** + * @brief Test to see if this variable exists in the store, + * for the referenced object. + * Specialization for the case of a container + * (@c T does not derive from @c SG::AuxElement). + */ +template <class T, class D> +inline +bool WriteDecorHandle<T, D>::isAvailable (std::false_type) +{ + const T* ptr = this->ptr(); + if (ptr) { + return ptr->isAvailable (m_acc.auxid()); + } -// return false; -// } + return false; +} -// /** -// * @brief Test to see if this variable exists in the store, -// * for the referenced object. -// */ -// template <class T, class D> -// inline -// bool WriteDecorHandle<T, D>::isAvailable() -// { -// if (!this->m_ptr) { -// ReadHandle<T>::typeless_dataPointer_impl (true); -// } -// // We can't just use vectorData() because that will create the decoration -// // as a side effect. -// return isAvailable (typename std::is_base_of<SG::AuxElement, T>::type()); -// } +/** + * @brief Test to see if this variable exists in the store, + * for the referenced object. + */ +template <class T, class D> +inline +bool WriteDecorHandle<T, D>::isAvailable() +{ + // if (!this->m_ptr) { + // ReadHandle<T>::typeless_dataPointer_impl (true); + // } + // We can't just use vectorData() because that will create the decoration + // as a side effect. + return isAvailable (typename std::is_base_of<SG::AuxElement, T>::type()); +} // /** diff --git a/Control/AthToolSupport/AsgExampleTools/AsgExampleTools/DataHandleTestTool.h b/Control/AthToolSupport/AsgExampleTools/AsgExampleTools/DataHandleTestTool.h index 91f001438ecfb43fb734affc1700f1032f392962..6595cbaf3b563c2e9196e2b8cbb5050005f08118 100644 --- a/Control/AthToolSupport/AsgExampleTools/AsgExampleTools/DataHandleTestTool.h +++ b/Control/AthToolSupport/AsgExampleTools/AsgExampleTools/DataHandleTestTool.h @@ -59,12 +59,14 @@ namespace asg SG::ReadHandleKeyArray<xAOD::MuonContainer> m_readKeyArray {this, "readKeyArray", {}, "array read key"}; SG::WriteHandleKey<xAOD::MuonContainer> m_writeKey {this, "writeKey", "", "regular write key"}; SG::WriteDecorHandleKey<xAOD::MuonContainer> m_writeDecorKey {this, "writeDecorKey", "", "write decor key"}; + SG::WriteDecorHandleKey<xAOD::MuonContainer> m_writeDecorKeyExisting {this, "writeDecorKeyExisting", "", "write decor key (existing)"}; #endif bool m_readFailure {false}; bool m_readArray {false}; bool m_readDecorFailure {false}; std::string m_doWriteName; std::string m_doWriteDecorName; + std::string m_doWriteDecorNameExisting; }; } diff --git a/Control/AthToolSupport/AsgExampleTools/Root/DataHandleTestTool.cxx b/Control/AthToolSupport/AsgExampleTools/Root/DataHandleTestTool.cxx index d7b17616e4349cebcaedc7fe15c9daea3e114cbb..452d872ba95c3dd0db151353eb0b29dcb4a4b522 100644 --- a/Control/AthToolSupport/AsgExampleTools/Root/DataHandleTestTool.cxx +++ b/Control/AthToolSupport/AsgExampleTools/Root/DataHandleTestTool.cxx @@ -39,6 +39,7 @@ namespace asg declareProperty ("readArray", m_readArray, "whether to read from the array"); declareProperty ("doWriteName", m_doWriteName, "if we should write, the name we expect to write to"); declareProperty ("doWriteDecorName", m_doWriteDecorName, "if we should write a decoration, the name we expect to write to"); + declareProperty ("doWriteDecorNameExisting", m_doWriteDecorNameExisting, "if we should try to overwrite an existing decoration, the name we expect to write to"); } @@ -61,6 +62,7 @@ namespace asg ANA_CHECK (m_writeKey.initialize (!m_writeKey.empty())); ANA_CHECK (m_readKeyArray.initialize()); ANA_CHECK (m_writeDecorKey.initialize (!m_writeDecorKey.empty ())); + ANA_CHECK (m_writeDecorKeyExisting.initialize (!m_writeDecorKeyExisting.empty ())); #endif return StatusCode::SUCCESS; } @@ -92,9 +94,13 @@ namespace asg SG::ReadDecorHandle<xAOD::MuonContainer,float> readDecorHandle (m_readDecorKey); if (m_readDecorFailure == true) { + EXPECT_TRUE(readDecorHandle.isPresent()); + EXPECT_FALSE(readDecorHandle.isAvailable()); EXPECT_ANY_THROW (readDecorHandle (*testMuon)); } else { + EXPECT_TRUE(readDecorHandle.isPresent()); + EXPECT_TRUE(readDecorHandle.isAvailable()); SG::AuxElement::ConstAccessor<float> acc ("pt"); EXPECT_EQ (acc (*testMuon), readDecorHandle (*testMuon)); } @@ -128,10 +134,19 @@ namespace asg if (!m_doWriteDecorName.empty()) { auto writeDecorHandle = SG::makeHandle<unsigned> (m_writeDecorKey); + EXPECT_TRUE(writeDecorHandle.isPresent()); + EXPECT_FALSE(writeDecorHandle.isAvailable()); writeDecorHandle (*(*muonsStore)[0]) = 42u; SG::AuxElement::ConstAccessor<unsigned> acc (m_doWriteDecorName); EXPECT_EQ (42u, acc (*(*muonsStore)[0])); } + + if (!m_doWriteDecorNameExisting.empty()) + { + auto writeDecorHandleExisting = SG::makeHandle<float> (m_writeDecorKeyExisting); + EXPECT_TRUE(writeDecorHandleExisting.isPresent()); + EXPECT_TRUE(writeDecorHandleExisting.isAvailable()); + } #endif } } diff --git a/Control/AthToolSupport/AsgExampleTools/test/gt_DataHandlesTest.cxx b/Control/AthToolSupport/AsgExampleTools/test/gt_DataHandlesTest.cxx index e2a09e7af42a8d96e03d63227e0446870a2eab7e..9302fdd383b3fe9e874a4996ca524df36d9af5d7 100644 --- a/Control/AthToolSupport/AsgExampleTools/test/gt_DataHandlesTest.cxx +++ b/Control/AthToolSupport/AsgExampleTools/test/gt_DataHandlesTest.cxx @@ -157,6 +157,17 @@ namespace asg + // do an existing write decor handle test + TEST_F (DataHandlesTest, write_decor_handle_existing) + { + config.setPropertyFromString ("writeDecorKeyExisting", "Muons.pt"); + config.setPropertyFromString ("doWriteDecorNameExisting", "pt"); + ASSERT_SUCCESS (config.makeTool (tool, cleanup)); + tool->runTest (); + } + + + // empty initial handles TEST_F (DataHandlesTest, empty_initial_handles) {