Skip to content
Snippets Groups Projects
Verified Commit a74ccd10 authored by Tadej Novak's avatar Tadej Novak
Browse files

Add isPresent and isAvailable to standalone VarDecorHandles

parent 2d93f494
No related branches found
No related tags found
No related merge requests found
......@@ -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();
// /**
......
......@@ -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());
}
// /**
......
......@@ -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);
// /**
......
......@@ -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());
}
// /**
......
......@@ -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;
};
}
......
......@@ -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
}
}
......@@ -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)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment