ATLAS Offline Software
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Private Attributes | List of all members
MeasurementContainerListWithDimension< derived_t, T_Container > Class Template Reference

#include <MeasurementContainerWithDimension.h>

Inheritance diagram for MeasurementContainerListWithDimension< derived_t, T_Container >:
Collaboration diagram for MeasurementContainerListWithDimension< derived_t, T_Container >:

Public Types

using Base = MeasurementContainerWithDimension< derived_t, T_Container... >
 
using measurement_container_variant_t = Base::measurement_container_variant_t
 

Public Member Functions

std::size_t size () const
 
const measurement_container_variant_tat (std::size_t container_index) const
 
const std::vector< measurement_container_variant_t > & containerList () const
 
template<typename container_t >
void setContainer (std::size_t container_index, const container_t &container)
 

Static Public Member Functions

static constexpr std::size_t getMeasurementDimMax ()
 
static void dumpVariantTypes ()
 

Protected Member Functions

const derived_t & derived () const
 

Static Protected Member Functions

static constexpr T lvalue (T &&a)
 
static constexpr std::size_t dimMax (std::size_t max_dim=0ul)
 
static constexpr bool isSameContainer ()
 
static constexpr unsigned int countVariants ()
 
static unsigned int countDerivedVariants (const container_t &a)
 
static void dumpVariantTypes (std::ostream &out)
 
static void throwContainerNotInVariant (const char *a)
 
static measurement_container_variant_t getContainerWithDimensionNoAmbiguities (const container_t &a, unsigned int dimension=0)
 
static unsigned int getDimensionOfDerivedVariantOption (const container_t &a)
 
static measurement_container_variant_t getContainerWithDimension (const container_t &a)
 

Private Attributes

std::vector< measurement_container_variant_tm_containerList
 

Detailed Description

template<typename derived_t, typename... T_Container>
class MeasurementContainerListWithDimension< derived_t, T_Container >

Definition at line 258 of file MeasurementContainerWithDimension.h.

Member Typedef Documentation

◆ Base

template<typename derived_t , typename... T_Container>
using MeasurementContainerListWithDimension< derived_t, T_Container >::Base = MeasurementContainerWithDimension<derived_t,T_Container...>

Definition at line 260 of file MeasurementContainerWithDimension.h.

◆ measurement_container_variant_t

template<typename derived_t , typename... T_Container>
using MeasurementContainerListWithDimension< derived_t, T_Container >::measurement_container_variant_t = Base::measurement_container_variant_t

Definition at line 261 of file MeasurementContainerWithDimension.h.

Member Function Documentation

◆ at()

template<typename derived_t , typename... T_Container>
const measurement_container_variant_t& MeasurementContainerListWithDimension< derived_t, T_Container >::at ( std::size_t  container_index) const
inline

Definition at line 277 of file MeasurementContainerWithDimension.h.

277  {
278  return m_containerList.at(container_index);
279  }

◆ containerList()

template<typename derived_t , typename... T_Container>
const std::vector< measurement_container_variant_t >& MeasurementContainerListWithDimension< derived_t, T_Container >::containerList ( ) const
inline

Definition at line 280 of file MeasurementContainerWithDimension.h.

280 { return m_containerList;}

◆ countDerivedVariants()

static unsigned int MeasurementContainerWithDimension< derived_t, T_Container >::countDerivedVariants ( const container_t &  a)
inlinestaticprotectedinherited

Definition at line 75 of file MeasurementContainerWithDimension.h.

75  {
76  if constexpr(N==0) {
77  return 0;
78  }
79  else {
80  if constexpr(isSameContainer<container_t, N-1>()) {
81  return countDerivedVariants<container_t, N-1>(a)+1;
82  }
83  else {
84  using this_variant_type = decltype( lvalue(std::get<N-1>(measurement_container_variant_t{}) ) );
85  using this_container_type = typename this_variant_type::container_type;
86  if constexpr(std::is_base_of_v<container_t, this_container_type>
87  && std::has_virtual_destructor_v<this_container_type> && std::has_virtual_destructor_v<container_t>) {
88  return countDerivedVariants<container_t, N-1>(a)+ ( dynamic_cast<const this_container_type *>(&a) != nullptr );
89  }
90  else {
91  return countDerivedVariants<container_t, N-1>(a);
92  }
93  }
94  }
95  }

◆ countVariants()

static constexpr unsigned int MeasurementContainerWithDimension< derived_t, T_Container >::countVariants
inlinestaticconstexprprotectedinherited

Definition at line 66 of file MeasurementContainerWithDimension.h.

66  {
67  if constexpr(N==0) {
68  return 0;
69  }
70  else {
71  return countVariants<container_t, N-1>()+ isSameContainer<container_t, N-1>();
72  }
73  }

◆ derived()

const derived_t& MeasurementContainerWithDimension< derived_t, T_Container >::derived
inlineprotectedinherited

Definition at line 44 of file MeasurementContainerWithDimension.h.

44 { return *static_cast<const derived_t *>(this); }

◆ dimMax()

static constexpr std::size_t MeasurementContainerWithDimension< derived_t, T_Container >::dimMax ( std::size_t  max_dim = 0ul)
inlinestaticconstexprprotectedinherited

Definition at line 50 of file MeasurementContainerWithDimension.h.

50  {
51  if constexpr(N>0) {
52  using this_variant_type = decltype( lvalue(std::get<N-1>(measurement_container_variant_t{}) ) );
53  return dimMax<N-1>(std::max( this_variant_type::dimension(), max_dim ) );
54  }
55  return max_dim;
56  }

◆ dumpVariantTypes() [1/2]

template<typename derived_t , typename... T_Container>
static void MeasurementContainerListWithDimension< derived_t, T_Container >::dumpVariantTypes ( )
inlinestatic

Definition at line 269 of file MeasurementContainerWithDimension.h.

269  {
271  }

◆ dumpVariantTypes() [2/2]

static void MeasurementContainerWithDimension< derived_t, T_Container >::dumpVariantTypes ( std::ostream &  out)
inlinestaticinherited

Definition at line 98 of file MeasurementContainerWithDimension.h.

98  {
99  if constexpr(N>0) {
100  using a_type = decltype( lvalue(std::get<N-1>(measurement_container_variant_t{}) ) );
101  out << N-1 << ": " << typeid(a_type).name() << std::endl;
102  dumpVariantTypes<N-1>(out);
103  }
104  }

◆ getContainerWithDimension()

static measurement_container_variant_t MeasurementContainerWithDimension< derived_t, T_Container >::getContainerWithDimension ( const container_t &  a)
inlinestaticprotectedinherited

Definition at line 236 of file MeasurementContainerWithDimension.h.

236  {
237  constexpr unsigned int variant_multiplicity = countVariants<container_t>();
238  // the container must by among the options of the measurement_container_variant_t
239  static constexpr std::size_t NVariants = std::variant_size_v< measurement_container_variant_t >;
240  if constexpr( variant_multiplicity == 1) {
241  return getContainerWithDimensionNoAmbiguities<container_t, false, NVariants>(a);
242  }
243  else {
244  if (variant_multiplicity==0) {
245  if (countDerivedVariants<container_t>(a) == 1) {
246  return getContainerWithDimensionNoAmbiguities<container_t, false, NVariants>(a);
247  }
248  }
249  DEBUG_TRACE( std::cout << "DEBUG need to search with dimension check for " << typeid(container_t).name() << " (aka " << typeid(a).name() << ")"
250  << " multiplicity : " << variant_multiplicity << " derived " << countDerivedVariants<container_t>(a)
251  << std:: endl );
252  return getContainerWithDimensionNoAmbiguities<container_t, true, NVariants>(a, getDimensionOfDerivedVariantOption<container_t,NVariants>(a));
253  }
254  }

◆ getContainerWithDimensionNoAmbiguities()

static measurement_container_variant_t MeasurementContainerWithDimension< derived_t, T_Container >::getContainerWithDimensionNoAmbiguities ( const container_t &  a,
unsigned int  dimension = 0 
)
inlinestaticprotectedinherited

Definition at line 114 of file MeasurementContainerWithDimension.h.

114  {
115  if constexpr(N==0) {
116  // this measns that the container_t has not been found in the list of possible options of the variant
117  // reasons: the type is not in the list, a derived type was provided and compaibility was not understood
118  throwContainerNotInVariant(typeid(a).name());
119  using this_variant_type = decltype( lvalue(std::get<0>(measurement_container_variant_t{}) ) );
120  return this_variant_type();
121  }
122  else {
123  using this_variant_type = decltype( lvalue(std::get<N-1>(measurement_container_variant_t{}) ) );
124  using this_container_type = typename this_variant_type::container_type ;
125  DEBUG_TRACE( std::cout << "DEBUG search option for " << typeid(container_t).name() << " (aka " << typeid(a).name() << ")"
126  << " option: " << N << " " << typeid(this_container_type).name() << " dim " << this_variant_type::dimension()
127  << " check dimension ? " << check_dimension << " desired dimension " << dimension
128  << std:: endl );
129  if constexpr(std::is_same_v<this_container_type, container_t>) {
130  // this option of the variant has perfect type match.
131  if constexpr(!check_dimension && countVariants<container_t>()==1) {
132  // if dimensions are not to be checked there must not be other options which also match the type
133  // the caller should have ensureed that this branch is impossible,
134  // but this can only be excluded at runtime, so a static_assert
135  // is impossible here
136  assert( (countVariants<this_container_type,N-1>()) == 0 );
137  DEBUG_TRACE( std::cout << "DEBUG --> for " << typeid(container_t).name() << " (aka " << typeid(a).name() << ")"
138  << " foumd unambiguous option: " << N << " " << typeid(this_container_type).name() << " dim " << this_variant_type::dimension()
139  << std:: endl );
141  }
142  else {
143  // otherwise check if the dimension of this option is identical to the
144  // expected dimension
145  if (this_variant_type::dimension() == dimension) {
146  DEBUG_TRACE( std::cout << "DEBUG --> for " << typeid(container_t).name() << " (aka " << typeid(a).name() << ")"
147  << " foumd dimension option: " << N << " " << typeid(this_container_type).name() << " dim " << this_variant_type::dimension()
148  << std:: endl );
150  }
151  }
152  }
153  else if constexpr(std::is_base_of_v<container_t, this_container_type>) {
154  // it is also possible that the container is a base of an option of the variant.
155  if constexpr(std::has_virtual_destructor_v<this_container_type> && std::has_virtual_destructor_v<container_t>) {
156  // casting can only be done safely if dynamic casts are possible, which requires
157  // a virtuaal destructor
158  const this_container_type *derived_container = dynamic_cast<const this_container_type *>(&a);
159  if (derived_container) {
160  // if the provided container can be casted to the type of this variant option
161  // then check the dimensions
162  if constexpr(!check_dimension) {
163  // Branch may be incorrectly chose and/or assert may fail
164  // if A is base of B and B is Base of C and both B and C are options of the variant
165  // the auto-detection will treat B
166  if constexpr(countVariants<container_t,N-1>() != 0) {
167  return getContainerWithDimensionNoAmbiguities<container_t, check_dimension, N-1>(a, dimension);
168  }
169  else {
170  DEBUG_TRACE( std::cout << "DEBUG --> for " << typeid(this_container_type).name() << " (aka " << typeid(a).name() << ")"
171  << " foumd derived option: " << N << " " << typeid(this_container_type).name() << " dim " << this_variant_type::dimension()
172  << std:: endl );
174  }
175  }
176  else {
177  if (this_variant_type::dimension() == dimension) {
178  DEBUG_TRACE( std::cout << "DEBUG --> for " << typeid(this_container_type).name() << " (aka " << typeid(a).name() << ")"
179  << " derived with dimension option: " << N << " " << typeid(this_container_type).name()
180  << " dim " << this_variant_type::dimension()
181  << std:: endl );
183  }
184  }
185  }
186  }
187  }
188  return getContainerWithDimensionNoAmbiguities<container_t, check_dimension, N-1>(a, dimension);
189  }
190  }

◆ getDimensionOfDerivedVariantOption()

static unsigned int MeasurementContainerWithDimension< derived_t, T_Container >::getDimensionOfDerivedVariantOption ( const container_t &  a)
inlinestaticprotectedinherited

Definition at line 193 of file MeasurementContainerWithDimension.h.

193  {
194  if constexpr(N==0) {
195  // failure
196  return 0;
197  }
198  else {
199  using this_variant_type = decltype( lvalue(std::get<N-1>(measurement_container_variant_t{}) ) );
200  using this_container_type = typename this_variant_type::container_type;
201 
202  DEBUG_TRACE( std::cout << "DEBUG determin dimension for " << typeid(container_t).name() << " (aka " << typeid(a).name() << ")"
203  << " option: " << N << " " << typeid(this_container_type).name() << " dim " << this_variant_type::dimension()
204  << std:: endl );
205 
207  DEBUG_TRACE( std::cout << "DEBUG get dimension for " << typeid(container_t).name() << " (aka " << typeid(a).name() << ")"
208  << " option: " << N << " " << typeid(this_container_type).name() << " dim " << this_variant_type::dimension()
209  << std:: endl );
210  return derived_t::getDimension(a);
211  }
212  else if constexpr(std::is_base_of_v<container_t, this_container_type>) {
213  DEBUG_TRACE( std::cout << "DEBUG try get dimension for derived " << typeid(container_t).name() << " (aka " << typeid(a).name() << ")"
214  << " option: " << N << " " << typeid(this_container_type).name() << " dim " << this_variant_type::dimension()
215  << std:: endl );
216  // it is also possible that the container is a base of an option of the variant.
217  if constexpr(std::has_virtual_destructor_v<this_container_type> && std::has_virtual_destructor_v<container_t>) {
218  // if there is no ambiguity there is no point in determining the dimension
219  // @TODO but this does not guarantee that this option matches if the provided container
220  // can have multiple dimensions.
221  if constexpr(countVariants<this_container_type>() > 1) {
222  // casting can only be done safely if dynamic casts are possible, which requires
223  // a virtual destructor
224  const this_container_type *derived_container = dynamic_cast<const this_container_type *>(&a);
225  if (derived_container) {
226  return derived_t::getDimension(*derived_container);
227  }
228  }
229  }
230  }
231  return getDimensionOfDerivedVariantOption<container_t, N-1>(a);
232  }
233  }

◆ getMeasurementDimMax()

template<typename derived_t , typename... T_Container>
static constexpr std::size_t MeasurementContainerListWithDimension< derived_t, T_Container >::getMeasurementDimMax ( )
inlinestaticconstexpr

Definition at line 266 of file MeasurementContainerWithDimension.h.

266  {
267  return Base::dimMax();
268  }

◆ isSameContainer()

static constexpr bool MeasurementContainerWithDimension< derived_t, T_Container >::isSameContainer
inlinestaticconstexprprotectedinherited

Definition at line 59 of file MeasurementContainerWithDimension.h.

59  {
60  using this_variant_type = decltype( lvalue(std::get<N>(measurement_container_variant_t{}) ) );
62  }

◆ lvalue()

static constexpr T MeasurementContainerWithDimension< derived_t, T_Container >::lvalue ( T &&  a)
inlinestaticconstexprprotectedinherited

Definition at line 47 of file MeasurementContainerWithDimension.h.

47 { return a;}

◆ setContainer()

template<typename derived_t , typename... T_Container>
template<typename container_t >
void MeasurementContainerListWithDimension< derived_t, T_Container >::setContainer ( std::size_t  container_index,
const container_t &  container 
)
inline

Definition at line 283 of file MeasurementContainerWithDimension.h.

283  {
284  if (container_index>=m_containerList.size()) {
285  m_containerList.resize(container_index+1);
286  }
287  m_containerList[container_index] = this->getContainerWithDimension(container);
288  if ( std::holds_alternative< decltype(this->lvalue(get<0>(measurement_container_variant_t{}))) >( m_containerList[container_index])
289  && std::get<0>(m_containerList[container_index]).containerPtr() == nullptr) {
290  // @TODO should never happen
291  std::runtime_error("Unhandled measurement type");
292  }
293 
294  }

◆ size()

template<typename derived_t , typename... T_Container>
std::size_t MeasurementContainerListWithDimension< derived_t, T_Container >::size ( ) const
inline

Definition at line 273 of file MeasurementContainerWithDimension.h.

273  {
274  return m_containerList.size();
275  }

◆ throwContainerNotInVariant()

static void MeasurementContainerWithDimension< derived_t, T_Container >::throwContainerNotInVariant ( const char *  a)
inlinestaticprotectedinherited

Definition at line 106 of file MeasurementContainerWithDimension.h.

106  {
107  std::stringstream msg;
108  msg << "Container " << a << " not in variant:" << std::endl;
110  throw std::runtime_error(msg.str());
111  }

Member Data Documentation

◆ m_containerList

template<typename derived_t , typename... T_Container>
std::vector< measurement_container_variant_t > MeasurementContainerListWithDimension< derived_t, T_Container >::m_containerList
private

Definition at line 263 of file MeasurementContainerWithDimension.h.


The documentation for this class was generated from the following file:
MeasurementContainerListWithDimension::measurement_container_variant_t
Base::measurement_container_variant_t measurement_container_variant_t
Definition: MeasurementContainerWithDimension.h:261
MeasurementContainerListWithDimension::m_containerList
std::vector< measurement_container_variant_t > m_containerList
Definition: MeasurementContainerWithDimension.h:263
max
#define max(a, b)
Definition: cfImp.cxx:41
MeasurementContainerWithDimension< derived_t, T_Container... >::getDimensionOfDerivedVariantOption
static unsigned int getDimensionOfDerivedVariantOption(const container_t &a)
Definition: MeasurementContainerWithDimension.h:193
MeasurementContainerWithDimension< derived_t, T_Container... >::dumpVariantTypes
static void dumpVariantTypes(std::ostream &out)
Definition: MeasurementContainerWithDimension.h:98
MeasurementContainerWithDimension< derived_t, T_Container... >::measurement_container_variant_t
std::variant< T_Container... > measurement_container_variant_t
Definition: MeasurementContainerWithDimension.h:40
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
athena.value
value
Definition: athena.py:124
MeasurementContainerWithDimension< derived_t, T_Container... >::getContainerWithDimensionNoAmbiguities
static measurement_container_variant_t getContainerWithDimensionNoAmbiguities(const container_t &a, unsigned int dimension=0)
Definition: MeasurementContainerWithDimension.h:114
JetTiledMap::N
@ N
Definition: TiledEtaPhiMap.h:44
MeasurementContainerWithDimension< derived_t, T_Container... >::countVariants
static constexpr unsigned int countVariants()
Definition: MeasurementContainerWithDimension.h:66
MeasurementContainerWithDimension< derived_t, T_Container... >::lvalue
static constexpr T lvalue(T &&a)
Definition: MeasurementContainerWithDimension.h:47
ContainerRefWithDim
Definition: MeasurementContainerWithDimension.h:10
MeasurementContainerWithDimension< derived_t, T_Container... >::countDerivedVariants
static unsigned int countDerivedVariants(const container_t &a)
Definition: MeasurementContainerWithDimension.h:75
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
a
TList * a
Definition: liststreamerinfos.cxx:10
DEBUG_TRACE
#define DEBUG_TRACE(a)
Definition: MeasurementContainerWithDimension.h:29
MeasurementContainerWithDimension< derived_t, T_Container... >::throwContainerNotInVariant
static void throwContainerNotInVariant(const char *a)
Definition: MeasurementContainerWithDimension.h:106
MeasurementContainerWithDimension< derived_t, T_Container... >::getContainerWithDimension
static measurement_container_variant_t getContainerWithDimension(const container_t &a)
Definition: MeasurementContainerWithDimension.h:236
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
MeasurementContainerWithDimension< derived_t, T_Container... >::dimMax
static constexpr std::size_t dimMax(std::size_t max_dim=0ul)
Definition: MeasurementContainerWithDimension.h:50