Skip to content
Snippets Groups Projects
Commit cba83d53 authored by Mark Hodgkinson's avatar Mark Hodgkinson
Browse files

Merge branch 'pyHelp.AthContainers-20180430' into 'master'

AthContainers: Make AtomicConstAccessor easier to use from Python.

See merge request atlas/athena!10889
parents 7515332a 83923059
No related merge requests found
......@@ -20,6 +20,7 @@
#include "AthContainers/OwnershipPolicy.h"
#include "AthContainers/PackedParameters.h"
#include "AthContainers/PackedContainer.h"
#include "AthContainers/tools/AtomicConstAccessor.h"
#include "AthContainers/debug.h"
#include "AthLinks/DataLink.h"
......@@ -110,6 +111,8 @@ INSTAN_TYPE(std::vector<double>);
INSTAN_TYPE(std::vector<bool>);
INSTAN_TYPE(std::vector<std::string>);
template class SG::AtomicConstAccessor<unsigned int>;
#undef ARGS1
#undef ARGS2
#undef INSTAN_TYPE
......@@ -78,6 +78,8 @@
<class name="SG::AuxElement::ConstAccessor<std::vector<bool> >"/>
<class name="SG::AuxElement::ConstAccessor<std::vector<std::string> >"/>
<class name="SG::AuxElement::AtomicConstAccessor<unsigned int>"/>
<class name="SG::AuxElement::Accessor<char>"/>
<class name="SG::AuxElement::Accessor<unsigned char>"/>
<class name="SG::AuxElement::Accessor<int>"/>
......
......@@ -90,8 +90,11 @@ public:
/**
* @brief Fetch the variable for one element, as a const reference.
* @param e The element for which to fetch the variable.
*
* As this class can be used only read-only for basic types, return
* the result by value. That makes it easier to call from python.
*/
const_reference_type operator() (const AuxElement& e) const;
T operator() (const AuxElement& e) const;
/**
......@@ -102,9 +105,11 @@ public:
* This allows retrieving aux data by container / index.
* Looping over the index via this method will be faster then
* looping over the elements of the container.
*
* As this class can be used only read-only for basic types, return
* the result by value. That makes it easier to call from python.
*/
const_reference_type
operator() (const AuxVectorData& container, size_t index) const;
T operator() (const AuxVectorData& container, size_t index) const;
/**
......
......@@ -43,11 +43,13 @@ AtomicConstAccessor<T>::AtomicConstAccessor (const std::string& name,
/**
* @brief Fetch the variable for one element, as a const reference.
* @param e The element for which to fetch the variable.
*
* As this class can be used only read-only for basic types, return
* the result by value. That makes it easier to call from python.
*/
template <class T>
inline
typename AtomicConstAccessor<T>::const_reference_type
AtomicConstAccessor<T>::operator() (const AuxElement& e) const
T AtomicConstAccessor<T>::operator() (const AuxElement& e) const
{
return reinterpret_cast<const_reference_type> (Base::operator() (e));
}
......@@ -61,12 +63,14 @@ AtomicConstAccessor<T>::operator() (const AuxElement& e) const
* This allows retrieving aux data by container / index.
* Looping over the index via this method will be faster then
* looping over the elements of the container.
*
* As this class can be used only read-only for basic types, return
* the result by value. That makes it easier to call from python.
*/
template <class T>
inline
typename AtomicConstAccessor<T>::const_reference_type
AtomicConstAccessor<T>::operator() (const AuxVectorData& container,
size_t index) const
T AtomicConstAccessor<T>::operator() (const AuxVectorData& container,
size_t index) const
{
return reinterpret_cast<const_reference_type> (Base::operator() (container, index));
}
......
......@@ -82,7 +82,7 @@ void test1()
assert (ityp2.auxid() == ityp2_id);
static_assert (std::is_same<decltype(ityp2(b)),
const std::atomic<int>&>::value, "test");
int>::value, "test");
SG::AtomicDecorator<int> ityp2_d ("anInt2");
ityp2_d(b) = 11;
......@@ -95,7 +95,7 @@ void test1()
ityp3_d(cb) = 12;
assert (12 == ityp3(cb));
assert (ityp3.getDataArray (v)+5 == &ityp3(cb));
assert (*(ityp3.getDataArray (v)+5) == ityp3(cb));
static_assert (std::is_same<decltype(ityp3.getDataArray(v)),
const std::atomic<int>*>::value, "test");
......
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