CMS 3D CMS Logo

SoAView.h
Go to the documentation of this file.
1 #ifndef DataFormats_SoATemplate_interface_SoAView_h
2 #define DataFormats_SoATemplate_interface_SoAView_h
3 
4 /*
5  * Structure-of-Arrays templates allowing access to a selection of scalars and columns from one
6  * or multiple SoA layouts or views.
7  * This template generator will allow handling subsets of columns from one or multiple SoA views or layouts.
8  */
9 
10 #include "SoACommon.h"
11 
12 #define SOA_VIEW_LAYOUT(TYPE, NAME) (TYPE, NAME)
13 
14 #define SOA_VIEW_LAYOUT_LIST(...) __VA_ARGS__
15 
16 #define SOA_VIEW_VALUE(LAYOUT_NAME, LAYOUT_MEMBER) (LAYOUT_NAME, LAYOUT_MEMBER, LAYOUT_MEMBER)
17 
18 #define SOA_VIEW_VALUE_RENAME(LAYOUT_NAME, LAYOUT_MEMBER, LOCAL_NAME) (LAYOUT_NAME, LAYOUT_MEMBER, LOCAL_NAME)
19 
20 #define SOA_VIEW_VALUE_LIST(...) __VA_ARGS__
21 
22 /*
23  * A macro defining a SoA view (collection of columns from multiple layouts or views.)
24  *
25  * Usage:
26  * GENERATE_SOA_VIEW(PixelXYConstView, PixelXYView,
27  * SOA_VIEW_LAYOUT_LIST(
28  * SOA_VIEW_LAYOUT(PixelDigis, pixelDigis),
29  * SOA_VIEW_LAYOUT(PixelRecHitsLayout, pixelsRecHit)
30  * ),
31  * SOA_VIEW_VALUE_LIST(
32  * SOA_VIEW_VALUE_RENAME(pixelDigis, x, digisX),
33  * SOA_VIEW_VALUE_RENAME(pixelDigis, y, digisY),
34  * SOA_VIEW_VALUE_RENAME(pixelsRecHit, x, recHitsX),
35  * SOA_VIEW_VALUE_RENAME(pixelsRecHit, y, recHitsY)
36  * )
37  * );
38  *
39  */
40 
41 namespace cms::soa {
42 
43  /* Traits for the different column type scenarios */
44  /* Value traits passes the class as is in the case of column type and return
45  * an empty class with functions returning non-scalar as accessors. */
46  template <class C, SoAColumnType COLUMN_TYPE>
47  struct ConstValueTraits : public C {
48  using C::C;
49  };
50 
51  template <class C>
53  // Just take to SoAValue type to generate the right constructor.
54  SOA_HOST_DEVICE SOA_INLINE ConstValueTraits(size_type, const typename C::valueType*) {}
55  SOA_HOST_DEVICE SOA_INLINE ConstValueTraits(size_type, const typename C::Params&) {}
56  SOA_HOST_DEVICE SOA_INLINE ConstValueTraits(size_type, const typename C::ConstParams&) {}
57  // Any attempt to do anything with the "scalar" value a const element will fail.
58  };
59 
60 } // namespace cms::soa
61 
62 /*
63  * Members definitions macros for views
64  */
65 
69 #define _DECLARE_VIEW_LAYOUT_PARAMETRIZED_TEMPLATE_IMPL(TYPE, NAME) \
70  (using BOOST_PP_CAT(TYPE, _default) = BOOST_PP_CAT(TYPE, _StagedTemplates) < VIEW_ALIGNMENT, \
71  VIEW_ALIGNMENT_ENFORCEMENT > ;)
72 
73 #define _DECLARE_VIEW_LAYOUT_PARAMETRIZED_TEMPLATE(R, DATA, TYPE_NAME) \
74  BOOST_PP_EXPAND(_DECLARE_VIEW_LAYOUT_PARAMETRIZED_TEMPLATE_IMPL TYPE_NAME)
75 
79 #define _DECLARE_VIEW_LAYOUT_TYPE_ALIAS_IMPL(TYPE, NAME) using BOOST_PP_CAT(TypeOf_, NAME) = TYPE;
80 
81 #define _DECLARE_VIEW_LAYOUT_TYPE_ALIAS(R, DATA, TYPE_NAME) \
82  BOOST_PP_EXPAND(_DECLARE_VIEW_LAYOUT_TYPE_ALIAS_IMPL TYPE_NAME)
83 
87 // clang-format off
88 #define _DECLARE_VIEW_MEMBER_TYPE_ALIAS_IMPL(LAYOUT_NAME, LAYOUT_MEMBER, LOCAL_NAME, CAST) \
89  using BOOST_PP_CAT(TypeOf_, LOCAL_NAME) = \
90  typename BOOST_PP_CAT(TypeOf_, LAYOUT_NAME)::Metadata::BOOST_PP_CAT(TypeOf_, LAYOUT_MEMBER); \
91  using BOOST_PP_CAT(ParametersTypeOf_, LOCAL_NAME) = \
92  typename BOOST_PP_CAT(TypeOf_, LAYOUT_NAME)::Metadata::BOOST_PP_CAT(ParametersTypeOf_, LAYOUT_MEMBER); \
93  constexpr static cms::soa::SoAColumnType BOOST_PP_CAT(ColumnTypeOf_, LOCAL_NAME) = \
94  BOOST_PP_CAT(TypeOf_, LAYOUT_NAME)::Metadata::BOOST_PP_CAT(ColumnTypeOf_, LAYOUT_MEMBER); \
95  using BOOST_PP_CAT(ConstAccessorOf_, LOCAL_NAME) = \
96  typename cms::soa::SoAAccessors<typename BOOST_PP_CAT(Metadata::TypeOf_, LOCAL_NAME)>:: \
97  template ColumnType<BOOST_PP_CAT(ColumnTypeOf_, LOCAL_NAME)>::template AccessType< \
98  cms::soa::SoAAccessType::constAccess>::template Alignment<conditionalAlignment>:: \
99  template RestrictQualifier<restrictQualify> ; \
100  using BOOST_PP_CAT(MutableAccessorOf_, LOCAL_NAME) = \
101  typename cms::soa::SoAAccessors<typename BOOST_PP_CAT(Metadata::TypeOf_, LOCAL_NAME)>:: \
102  template ColumnType<BOOST_PP_CAT(ColumnTypeOf_, LOCAL_NAME)>::template AccessType< \
103  cms::soa::SoAAccessType::mutableAccess>::template Alignment<conditionalAlignment>:: \
104  template RestrictQualifier<restrictQualify> ; \
105  SOA_HOST_DEVICE SOA_INLINE \
106  const auto BOOST_PP_CAT(parametersOf_, LOCAL_NAME)() const { \
107  return CAST(parent_.BOOST_PP_CAT(LOCAL_NAME, Parameters_)); \
108  };
109 // clang-format on
110 
111 // DATA should be a function used to convert
112 // parent_.LOCAL_NAME ## Parameters_
113 // to
114 // ParametersTypeOf_ ## LOCAL_NAME (for a View)
115 // or
116 // ParametersTypeOf_ ## LOCAL_NAME :: ConstType (for a ConstView)
117 // or empty, if no conversion is necessary.
118 #define _DECLARE_VIEW_MEMBER_TYPE_ALIAS(R, DATA, LAYOUT_MEMBER_NAME) \
119  BOOST_PP_EXPAND(_DECLARE_VIEW_MEMBER_TYPE_ALIAS_IMPL BOOST_PP_TUPLE_PUSH_BACK(LAYOUT_MEMBER_NAME, DATA))
120 
124 // clang-format off
125 #define _DECLARE_VIEW_MEMBER_POINTERS_IMPL(LAYOUT_NAME, LAYOUT_MEMBER, LOCAL_NAME) \
126  SOA_HOST_DEVICE SOA_INLINE auto* BOOST_PP_CAT(addressOf_, LOCAL_NAME)() { \
127  return BOOST_PP_CAT(parametersOf_, LOCAL_NAME)().addr_; \
128  };
129 // clang-format on
130 
131 #define _DECLARE_VIEW_MEMBER_POINTERS(R, DATA, LAYOUT_MEMBER_NAME) \
132  BOOST_PP_EXPAND(_DECLARE_VIEW_MEMBER_POINTERS_IMPL LAYOUT_MEMBER_NAME)
133 
137 // clang-format off
138 #define _DECLARE_VIEW_MEMBER_CONST_POINTERS_IMPL(LAYOUT_NAME, LAYOUT_MEMBER, LOCAL_NAME) \
139  SOA_HOST_DEVICE SOA_INLINE auto const* BOOST_PP_CAT(addressOf_, LOCAL_NAME)() const { \
140  return BOOST_PP_CAT(parametersOf_, LOCAL_NAME)().addr_; \
141  };
142 // clang-format on
143 
144 #define _DECLARE_VIEW_MEMBER_CONST_POINTERS(R, DATA, LAYOUT_MEMBER_NAME) \
145  BOOST_PP_EXPAND(_DECLARE_VIEW_MEMBER_CONST_POINTERS_IMPL LAYOUT_MEMBER_NAME)
146 
150 #define _DECLARE_VIEW_CONSTRUCTION_PARAMETERS_IMPL(LAYOUT_TYPE, LAYOUT_NAME, DATA) (DATA LAYOUT_TYPE & LAYOUT_NAME)
151 
152 #define _DECLARE_VIEW_CONSTRUCTION_PARAMETERS(R, DATA, TYPE_NAME) \
153  BOOST_PP_EXPAND(_DECLARE_VIEW_CONSTRUCTION_PARAMETERS_IMPL BOOST_PP_TUPLE_PUSH_BACK(TYPE_NAME, DATA))
154 
158 #define _DECLARE_VIEW_CONSTRUCTION_BYCOLUMN_PARAMETERS_IMPL(LAYOUT_NAME, LAYOUT_MEMBER, LOCAL_NAME, DATA) \
159  (DATA typename BOOST_PP_CAT(Metadata::ParametersTypeOf_, LOCAL_NAME)::TupleOrPointerType LOCAL_NAME)
160 
161 #define _DECLARE_VIEW_CONSTRUCTION_BYCOLUMN_PARAMETERS(R, DATA, LAYOUT_MEMBER_NAME) \
162  BOOST_PP_EXPAND( \
163  _DECLARE_VIEW_CONSTRUCTION_BYCOLUMN_PARAMETERS_IMPL BOOST_PP_TUPLE_PUSH_BACK(LAYOUT_MEMBER_NAME, DATA))
164 
169 // clang-format off
170 #define _DECLARE_VIEW_MEMBER_INITIALIZERS_IMPL(LAYOUT, MEMBER, NAME) \
171  (BOOST_PP_CAT(NAME, Parameters_)([&]() -> auto { \
172  auto params = LAYOUT.metadata().BOOST_PP_CAT(parametersOf_, MEMBER)(); \
173  if constexpr (alignmentEnforcement == AlignmentEnforcement::enforced) \
174  if (reinterpret_cast<intptr_t>(params.addr_) % alignment) \
175  throw std::runtime_error("In constructor by layout: misaligned column: " #NAME); \
176  return params; \
177  }()))
178 // clang-format on
179 
180 #define _DECLARE_VIEW_MEMBER_INITIALIZERS(R, DATA, LAYOUT_MEMBER_NAME) \
181  BOOST_PP_EXPAND(_DECLARE_VIEW_MEMBER_INITIALIZERS_IMPL LAYOUT_MEMBER_NAME)
182 
187 // clang-format off
188 #define _UPDATE_SIZE_OF_VIEW_IMPL(LAYOUT_TYPE, LAYOUT_NAME) \
189  if (set) { \
190  if (ret != LAYOUT_NAME.metadata().size()) \
191  throw std::runtime_error("In constructor by layout: different sizes from layouts."); \
192  } else { \
193  ret = LAYOUT_NAME.metadata().size(); \
194  set = true; \
195  }
196 // clang-format on
197 
198 #define _UPDATE_SIZE_OF_VIEW(R, DATA, TYPE_NAME) BOOST_PP_EXPAND(_UPDATE_SIZE_OF_VIEW_IMPL TYPE_NAME)
199 
204 // clang-format off
205 #define _DECLARE_VIEW_MEMBER_INITIALIZERS_BYCOLUMN_IMPL(LAYOUT, MEMBER, NAME) \
206  ( \
207  BOOST_PP_CAT(NAME, Parameters_)([&]() -> auto { \
208  if constexpr (alignmentEnforcement == AlignmentEnforcement::enforced) \
209  if (Metadata:: BOOST_PP_CAT(ParametersTypeOf_, NAME)::checkAlignment(NAME, alignment)) \
210  throw std::runtime_error("In constructor by column: misaligned column: " #NAME); \
211  return NAME; \
212  }()) \
213  )
214 // clang-format on
215 
216 #define _DECLARE_VIEW_MEMBER_INITIALIZERS_BYCOLUMN(R, DATA, LAYOUT_MEMBER_NAME) \
217  BOOST_PP_EXPAND(_DECLARE_VIEW_MEMBER_INITIALIZERS_BYCOLUMN_IMPL LAYOUT_MEMBER_NAME)
218 
222 #define _DECLARE_LAYOUT_LIST_IMPL(LAYOUT, NAME) (NAME)
223 
224 #define _DECLARE_LAYOUT_LIST(R, DATA, LAYOUT_MEMBER_NAME) BOOST_PP_EXPAND(_DECLARE_LAYOUT_LIST_IMPL LAYOUT_MEMBER_NAME)
225 
229 #define _DECLARE_VIEW_MEMBER_LIST_IMPL(LAYOUT, MEMBER, NAME) (NAME)
230 
231 #define _DECLARE_VIEW_MEMBER_LIST(R, DATA, LAYOUT_MEMBER_NAME) \
232  BOOST_PP_EXPAND(_DECLARE_VIEW_MEMBER_LIST_IMPL LAYOUT_MEMBER_NAME)
233 
237 #define _DECLARE_VIEW_OTHER_MEMBER_LIST_IMPL(LAYOUT, MEMBER, NAME) \
238  (const_cast_SoAParametersImpl(other.BOOST_PP_CAT(NAME, Parameters_)).tupleOrPointer())
239 
240 #define _DECLARE_VIEW_OTHER_MEMBER_LIST(R, DATA, LAYOUT_MEMBER_NAME) \
241  BOOST_PP_EXPAND(_DECLARE_VIEW_OTHER_MEMBER_LIST_IMPL LAYOUT_MEMBER_NAME)
242 
246 #define _DECLARE_VIEW_MEMBER_INITIALIZERS_FROM_OTHER_IMPL(LAYOUT, MEMBER, LOCAL_NAME, DATA) \
247  (BOOST_PP_CAT(MEMBER, Parameters_){DATA.BOOST_PP_CAT(MEMBER, Parameters_)})
248 
249 #define _DECLARE_VIEW_MEMBER_INITIALIZERS_FROM_OTHER(R, DATA, LAYOUT_MEMBER_NAME) \
250  BOOST_PP_EXPAND(_DECLARE_VIEW_MEMBER_INITIALIZERS_FROM_OTHER_IMPL BOOST_PP_TUPLE_PUSH_BACK(LAYOUT_MEMBER_NAME, DATA))
251 
255 #define _DECLARE_VIEW_MEMBER_ASSIGNMENT_FROM_OTHER_IMPL(LAYOUT, MEMBER, LOCAL_NAME, DATA) \
256  BOOST_PP_CAT(MEMBER, Parameters_) = DATA.BOOST_PP_CAT(MEMBER, Parameters_);
257 
258 #define _DECLARE_VIEW_MEMBER_ASSIGNMENT_FROM_OTHER(R, DATA, LAYOUT_MEMBER_NAME) \
259  BOOST_PP_EXPAND(_DECLARE_VIEW_MEMBER_ASSIGNMENT_FROM_OTHER_IMPL BOOST_PP_TUPLE_PUSH_BACK(LAYOUT_MEMBER_NAME, DATA))
260 
264 #define _DECLARE_VIEW_ELEM_MEMBER_INIT_IMPL(LAYOUT, MEMBER, LOCAL_NAME, DATA) (LOCAL_NAME(DATA, LOCAL_NAME))
265 
266 #define _DECLARE_VIEW_ELEM_MEMBER_INIT(R, DATA, LAYOUT_MEMBER_NAME) \
267  BOOST_PP_EXPAND(_DECLARE_VIEW_ELEM_MEMBER_INIT_IMPL BOOST_PP_TUPLE_PUSH_BACK(LAYOUT_MEMBER_NAME, DATA))
268 
272 #define _COLUMN_TYPE(LAYOUT_NAME, LAYOUT_MEMBER) \
273  typename std::remove_pointer<decltype(BOOST_PP_CAT(LAYOUT_NAME, Type)()::LAYOUT_MEMBER())>::type
274 
278 #define _DECLARE_VIEW_ELEMENT_VALUE_ARG_IMPL(LAYOUT_NAME, LAYOUT_MEMBER, LOCAL_NAME, DATA) \
279  (DATA typename BOOST_PP_CAT(Metadata::ParametersTypeOf_, LOCAL_NAME) LOCAL_NAME)
280 
281 #define _DECLARE_VIEW_ELEMENT_VALUE_ARG(R, DATA, LAYOUT_MEMBER_NAME) \
282  _DECLARE_VIEW_ELEMENT_VALUE_ARG_IMPL BOOST_PP_TUPLE_PUSH_BACK(LAYOUT_MEMBER_NAME, DATA)
283 
287 #define _DECLARE_CONST_VIEW_ELEMENT_VALUE_ARG_IMPL(LAYOUT_NAME, LAYOUT_MEMBER, LOCAL_NAME, DATA) \
288  (DATA typename BOOST_PP_CAT(Metadata::ParametersTypeOf_, LOCAL_NAME)::ConstType LOCAL_NAME)
289 
290 #define _DECLARE_CONST_VIEW_ELEMENT_VALUE_ARG(R, DATA, LAYOUT_MEMBER_NAME) \
291  _DECLARE_CONST_VIEW_ELEMENT_VALUE_ARG_IMPL BOOST_PP_TUPLE_PUSH_BACK(LAYOUT_MEMBER_NAME, DATA)
292 
296 #define _DECLARE_VIEW_CONST_ELEM_MEMBER_INIT_IMPL(LAYOUT_NAME, LAYOUT_MEMBER, LOCAL_NAME, DATA) \
297  (BOOST_PP_CAT(LOCAL_NAME, _)(DATA, LOCAL_NAME))
298 
299 /* declare AoS-like element value args for contructor; these should expand,for columns only */
300 #define _DECLARE_VIEW_CONST_ELEM_MEMBER_INIT(R, DATA, LAYOUT_MEMBER_NAME) \
301  BOOST_PP_EXPAND(_DECLARE_VIEW_CONST_ELEM_MEMBER_INIT_IMPL BOOST_PP_TUPLE_PUSH_BACK(LAYOUT_MEMBER_NAME, DATA))
302 
306 // clang-format off
307 #define _DECLARE_VIEW_CONST_ELEMENT_ACCESSOR_IMPL(LAYOUT_NAME, LAYOUT_MEMBER, LOCAL_NAME) \
308  SOA_HOST_DEVICE SOA_INLINE \
309  const typename SoAConstValueWithConf<BOOST_PP_CAT(Metadata::ColumnTypeOf_, LOCAL_NAME), \
310  const typename BOOST_PP_CAT(Metadata::TypeOf_, LOCAL_NAME)>::RefToConst \
311  LOCAL_NAME() const { \
312  return BOOST_PP_CAT(LOCAL_NAME, _)(); \
313  }
314 // clang-format on
315 
316 #define _DECLARE_VIEW_CONST_ELEMENT_ACCESSOR(R, DATA, LAYOUT_MEMBER_NAME) \
317  _DECLARE_VIEW_CONST_ELEMENT_ACCESSOR_IMPL LAYOUT_MEMBER_NAME
318 
322 // clang-format off
323 #define _DECLARE_VIEW_CONST_ELEMENT_VALUE_MEMBER_IMPL(LAYOUT_NAME, LAYOUT_MEMBER, LOCAL_NAME) \
324  const cms::soa::ConstValueTraits<SoAConstValueWithConf<BOOST_PP_CAT(Metadata::ColumnTypeOf_, LOCAL_NAME), \
325  typename BOOST_PP_CAT(Metadata::TypeOf_, LOCAL_NAME)>, \
326  BOOST_PP_CAT(Metadata::ColumnTypeOf_, LOCAL_NAME)> \
327  BOOST_PP_CAT(LOCAL_NAME, _);
328 // clang-format on
329 
330 #define _DECLARE_VIEW_CONST_ELEMENT_VALUE_MEMBER(R, DATA, LAYOUT_MEMBER_NAME) \
331  _DECLARE_VIEW_CONST_ELEMENT_VALUE_MEMBER_IMPL LAYOUT_MEMBER_NAME
332 
336 #define _DECLARE_VIEW_ELEMENT_VALUE_COPY_IMPL(LAYOUT_NAME, LAYOUT_MEMBER, LOCAL_NAME) \
337  if constexpr (Metadata::BOOST_PP_CAT(ColumnTypeOf_, LOCAL_NAME) != cms::soa::SoAColumnType::scalar) \
338  LOCAL_NAME() = _soa_impl_other.LOCAL_NAME();
339 
340 #define _DECLARE_VIEW_ELEMENT_VALUE_COPY(R, DATA, LAYOUT_MEMBER_NAME) \
341  BOOST_PP_EXPAND(_DECLARE_VIEW_ELEMENT_VALUE_COPY_IMPL LAYOUT_MEMBER_NAME)
342 
346 // clang-format off
347 #define _DECLARE_VIEW_ELEMENT_VALUE_MEMBER_IMPL(LAYOUT_NAME, LAYOUT_MEMBER, LOCAL_NAME) \
348  SoAValueWithConf<BOOST_PP_CAT(Metadata::ColumnTypeOf_, LOCAL_NAME), \
349  typename BOOST_PP_CAT(Metadata::TypeOf_, LOCAL_NAME)> \
350  LOCAL_NAME;
351 // clang-format on
352 
353 #define _DECLARE_VIEW_ELEMENT_VALUE_MEMBER(R, DATA, LAYOUT_MEMBER_NAME) \
354  _DECLARE_VIEW_ELEMENT_VALUE_MEMBER_IMPL LAYOUT_MEMBER_NAME
355 
359 #define _DECLARE_VIEW_CONST_ELEMENT_CONSTR_CALL_IMPL(LAYOUT_NAME, LAYOUT_MEMBER, LOCAL_NAME) \
360  (BOOST_PP_CAT(LOCAL_NAME, Parameters_))
361 
362 #define _DECLARE_VIEW_CONST_ELEMENT_CONSTR_CALL(R, DATA, LAYOUT_MEMBER_NAME) \
363  BOOST_PP_EXPAND(_DECLARE_VIEW_CONST_ELEMENT_CONSTR_CALL_IMPL LAYOUT_MEMBER_NAME)
364 
371 #define _DECLARE_VIEW_ELEMENT_CONSTR_CALL_IMPL(LAYOUT_NAME, LAYOUT_MEMBER, LOCAL_NAME) \
372  (const_cast_SoAParametersImpl(base_type::BOOST_PP_CAT(LOCAL_NAME, Parameters_)))
373 
374 #define _DECLARE_VIEW_ELEMENT_CONSTR_CALL(R, DATA, LAYOUT_MEMBER_NAME) \
375  BOOST_PP_EXPAND(_DECLARE_VIEW_ELEMENT_CONSTR_CALL_IMPL LAYOUT_MEMBER_NAME)
376 
380 // clang-format off
381 #define _DECLARE_VIEW_SOA_ACCESSOR_IMPL(LAYOUT_NAME, LAYOUT_MEMBER, LOCAL_NAME) \
382  /* Column or scalar */ \
383  SOA_HOST_DEVICE SOA_INLINE \
384  typename cms::soa::SoAAccessors<typename BOOST_PP_CAT(Metadata::TypeOf_, LOCAL_NAME)>:: \
385  template ColumnType<BOOST_PP_CAT(Metadata::ColumnTypeOf_, LOCAL_NAME)>::template AccessType< \
386  cms::soa::SoAAccessType::mutableAccess>::template Alignment<conditionalAlignment>:: \
387  template RestrictQualifier<restrictQualify>::NoParamReturnType \
388  LOCAL_NAME() { \
389  return typename cms::soa::SoAAccessors<typename BOOST_PP_CAT(Metadata::TypeOf_, LOCAL_NAME)>:: \
390  template ColumnType<BOOST_PP_CAT(Metadata::ColumnTypeOf_, LOCAL_NAME)>::template AccessType< \
391  cms::soa::SoAAccessType::mutableAccess>::template Alignment<conditionalAlignment>:: \
392  template RestrictQualifier<restrictQualify>(const_cast_SoAParametersImpl( \
393  base_type:: BOOST_PP_CAT(LOCAL_NAME, Parameters_)))(); \
394  } \
395  SOA_HOST_DEVICE SOA_INLINE \
396  typename cms::soa::SoAAccessors<typename BOOST_PP_CAT(Metadata::TypeOf_, LOCAL_NAME)>:: \
397  template ColumnType<BOOST_PP_CAT(Metadata::ColumnTypeOf_, LOCAL_NAME)>::template AccessType< \
398  cms::soa::SoAAccessType::mutableAccess>::template Alignment<conditionalAlignment>:: \
399  template RestrictQualifier<restrictQualify>::ParamReturnType \
400  LOCAL_NAME(size_type _soa_impl_index) { \
401  if constexpr (rangeChecking == cms::soa::RangeChecking::enabled) { \
402  if (_soa_impl_index >= base_type::elements_ or _soa_impl_index < 0) \
403  SOA_THROW_OUT_OF_RANGE("Out of range index in mutable " #LOCAL_NAME "(size_type index)") \
404  } \
405  return typename cms::soa::SoAAccessors<typename BOOST_PP_CAT(Metadata::TypeOf_, LOCAL_NAME)>:: \
406  template ColumnType<BOOST_PP_CAT(Metadata::ColumnTypeOf_, LOCAL_NAME)>::template AccessType< \
407  cms::soa::SoAAccessType::mutableAccess>::template Alignment<conditionalAlignment>:: \
408  template RestrictQualifier<restrictQualify>(const_cast_SoAParametersImpl( \
409  base_type:: BOOST_PP_CAT(LOCAL_NAME, Parameters_)))(_soa_impl_index); \
410  }
411 // clang-format on
412 
413 #define _DECLARE_VIEW_SOA_ACCESSOR(R, DATA, LAYOUT_MEMBER_NAME) \
414  BOOST_PP_EXPAND(_DECLARE_VIEW_SOA_ACCESSOR_IMPL LAYOUT_MEMBER_NAME)
415 
419 // clang-format off
420 #define _DECLARE_VIEW_SOA_CONST_ACCESSOR_IMPL(LAYOUT_NAME, LAYOUT_MEMBER, LOCAL_NAME) \
421  /* Column or scalar */ \
422  SOA_HOST_DEVICE SOA_INLINE \
423  typename cms::soa::SoAAccessors<typename BOOST_PP_CAT(Metadata::TypeOf_, LOCAL_NAME)>:: \
424  template ColumnType<BOOST_PP_CAT(Metadata::ColumnTypeOf_, LOCAL_NAME)>::template AccessType< \
425  cms::soa::SoAAccessType::constAccess>::template Alignment<conditionalAlignment>:: \
426  template RestrictQualifier<restrictQualify>::NoParamReturnType \
427  LOCAL_NAME() const { \
428  return typename cms::soa::SoAAccessors<typename BOOST_PP_CAT(Metadata::TypeOf_, LOCAL_NAME)>:: \
429  template ColumnType<BOOST_PP_CAT(Metadata::ColumnTypeOf_, LOCAL_NAME)>::template AccessType< \
430  cms::soa::SoAAccessType::constAccess>::template Alignment<conditionalAlignment>:: \
431  template RestrictQualifier<restrictQualify>(BOOST_PP_CAT(LOCAL_NAME, Parameters_))(); \
432  } \
433  SOA_HOST_DEVICE SOA_INLINE \
434  typename cms::soa::SoAAccessors<typename BOOST_PP_CAT(Metadata::TypeOf_, LOCAL_NAME)>:: \
435  template ColumnType<BOOST_PP_CAT(Metadata::ColumnTypeOf_, LOCAL_NAME)>::template AccessType< \
436  cms::soa::SoAAccessType::constAccess>::template Alignment<conditionalAlignment>:: \
437  template RestrictQualifier<restrictQualify>::ParamReturnType \
438  LOCAL_NAME(size_type _soa_impl_index) const { \
439  if constexpr (rangeChecking == cms::soa::RangeChecking::enabled) { \
440  if (_soa_impl_index >= elements_ or _soa_impl_index < 0) \
441  SOA_THROW_OUT_OF_RANGE("Out of range index in const " #LOCAL_NAME "(size_type index)") \
442  } \
443  return typename cms::soa::SoAAccessors<typename BOOST_PP_CAT(Metadata::TypeOf_, LOCAL_NAME)>:: \
444  template ColumnType<BOOST_PP_CAT(Metadata::ColumnTypeOf_, LOCAL_NAME)>::template AccessType< \
445  cms::soa::SoAAccessType::constAccess>::template Alignment<conditionalAlignment>:: \
446  template RestrictQualifier<restrictQualify>(BOOST_PP_CAT(LOCAL_NAME, Parameters_))(_soa_impl_index); \
447  }
448 // clang-format on
449 
450 #define _DECLARE_VIEW_SOA_CONST_ACCESSOR(R, DATA, LAYOUT_MEMBER_NAME) \
451  BOOST_PP_EXPAND(_DECLARE_VIEW_SOA_CONST_ACCESSOR_IMPL LAYOUT_MEMBER_NAME)
452 
456 #define _DECLARE_VIEW_SOA_MEMBER_IMPL(LAYOUT_NAME, LAYOUT_MEMBER, LOCAL_NAME, DATA) \
457  typename BOOST_PP_CAT(Metadata::ParametersTypeOf_, LOCAL_NAME) BOOST_PP_CAT(LOCAL_NAME, Parameters_);
458 
459 #define _DECLARE_VIEW_SOA_MEMBER(R, DATA, LAYOUT_MEMBER_NAME) \
460  BOOST_PP_EXPAND(_DECLARE_VIEW_SOA_MEMBER_IMPL BOOST_PP_TUPLE_PUSH_BACK(LAYOUT_MEMBER_NAME, DATA))
461 
465 #define _DECLARE_CONST_VIEW_SOA_MEMBER_IMPL(LAYOUT_NAME, LAYOUT_MEMBER, LOCAL_NAME, DATA) \
466  typename BOOST_PP_CAT(Metadata::ParametersTypeOf_, LOCAL_NAME)::ConstType BOOST_PP_CAT(LOCAL_NAME, Parameters_);
467 
468 #define _DECLARE_CONST_VIEW_SOA_MEMBER(R, DATA, LAYOUT_MEMBER_NAME) \
469  BOOST_PP_EXPAND(_DECLARE_CONST_VIEW_SOA_MEMBER_IMPL BOOST_PP_TUPLE_PUSH_BACK(LAYOUT_MEMBER_NAME, DATA))
470 
475 // clang-format off
476 #define _TRIVIAL_VIEW_ASSIGN_VALUE_ELEMENT_IMPL(VALUE_TYPE, CPP_TYPE, NAME) \
477  _SWITCH_ON_TYPE(VALUE_TYPE, \
478  /* Scalar (empty) */ \
479  , \
480  /* Column */ \
481  NAME() = _soa_impl_value.NAME; \
482  , \
483  /* Eigen column */ \
484  NAME() = _soa_impl_value.NAME; \
485 )
486 // clang-format on
487 
488 #define _TRIVIAL_VIEW_ASSIGN_VALUE_ELEMENT(R, DATA, TYPE_NAME) _TRIVIAL_VIEW_ASSIGN_VALUE_ELEMENT_IMPL TYPE_NAME
489 
490 /* ---- MUTABLE VIEW ------------------------------------------------------------------------------------------------ */
491 // clang-format off
492 #define _GENERATE_SOA_VIEW_PART_0(CONST_VIEW, VIEW, LAYOUTS_LIST, VALUE_LIST) \
493  template <CMS_SOA_BYTE_SIZE_TYPE VIEW_ALIGNMENT = cms::soa::CacheLineSize::defaultSize, \
494  bool VIEW_ALIGNMENT_ENFORCEMENT = cms::soa::AlignmentEnforcement::relaxed, \
495  bool RESTRICT_QUALIFY = cms::soa::RestrictQualify::enabled, \
496  bool RANGE_CHECKING = cms::soa::RangeChecking::disabled> \
497  struct VIEW : public CONST_VIEW<VIEW_ALIGNMENT, VIEW_ALIGNMENT_ENFORCEMENT, RESTRICT_QUALIFY, RANGE_CHECKING> { \
498  /* Declare the parametrized layouts as the default */ \
499  /*BOOST_PP_SEQ_CAT(_ITERATE_ON_ALL(_DECLARE_VIEW_LAYOUT_PARAMETRIZED_TEMPLATE, ~, LAYOUTS_LIST)) */ \
500  /* these could be moved to an external type trait to free up the symbol names */ \
501  using self_type = VIEW; \
502  using base_type = CONST_VIEW<VIEW_ALIGNMENT, VIEW_ALIGNMENT_ENFORCEMENT, RESTRICT_QUALIFY, RANGE_CHECKING>;
503 // clang-format on
504 
505 // clang-format off
506 #define _GENERATE_SOA_VIEW_PART_0_NO_DEFAULTS(CONST_VIEW, VIEW, LAYOUTS_LIST, VALUE_LIST) \
507  template <CMS_SOA_BYTE_SIZE_TYPE VIEW_ALIGNMENT, \
508  bool VIEW_ALIGNMENT_ENFORCEMENT, \
509  bool RESTRICT_QUALIFY, \
510  bool RANGE_CHECKING> \
511  struct VIEW : public CONST_VIEW<VIEW_ALIGNMENT, VIEW_ALIGNMENT_ENFORCEMENT, RESTRICT_QUALIFY, RANGE_CHECKING> { \
512  /* Declare the parametrized layouts as the default */ \
513  /*BOOST_PP_SEQ_CAT(_ITERATE_ON_ALL(_DECLARE_VIEW_LAYOUT_PARAMETRIZED_TEMPLATE, ~, LAYOUTS_LIST)) */ \
514  /* these could be moved to an external type trait to free up the symbol names */ \
515  using self_type = VIEW; \
516  using base_type = CONST_VIEW<VIEW_ALIGNMENT, VIEW_ALIGNMENT_ENFORCEMENT, RESTRICT_QUALIFY, RANGE_CHECKING>;
517 // clang-format on
518 
523 // clang-format off
524 #define _GENERATE_SOA_VIEW_PART_1(CONST_VIEW, VIEW, LAYOUTS_LIST, VALUE_LIST) \
525  using size_type = cms::soa::size_type; \
526  using byte_size_type = cms::soa::byte_size_type; \
527  using AlignmentEnforcement = cms::soa::AlignmentEnforcement; \
528  \
529  /* For CUDA applications, we align to the 128 bytes of the cache lines. \
530  * See https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#global-memory-3-0 this is still valid \
531  * up to compute capability 8.X. \
532  */ \
533  constexpr static byte_size_type defaultAlignment = cms::soa::CacheLineSize::defaultSize; \
534  constexpr static byte_size_type alignment = VIEW_ALIGNMENT; \
535  constexpr static bool alignmentEnforcement = VIEW_ALIGNMENT_ENFORCEMENT; \
536  constexpr static byte_size_type conditionalAlignment = \
537  alignmentEnforcement == AlignmentEnforcement::enforced ? alignment : 0; \
538  constexpr static bool restrictQualify = RESTRICT_QUALIFY; \
539  constexpr static bool rangeChecking = RANGE_CHECKING; \
540  /* Those typedefs avoid having commas in macros (which is problematic) */ \
541  template <cms::soa::SoAColumnType COLUMN_TYPE, class C> \
542  using SoAValueWithConf = cms::soa::SoAValue<COLUMN_TYPE, C, conditionalAlignment, restrictQualify>; \
543  \
544  template <cms::soa::SoAColumnType COLUMN_TYPE, class C> \
545  using SoAConstValueWithConf = cms::soa::SoAConstValue<COLUMN_TYPE, C, conditionalAlignment, restrictQualify>; \
546  \
547  template <CMS_SOA_BYTE_SIZE_TYPE, bool, bool, bool> \
548  friend struct VIEW; \
549  \
550  \
553  struct Metadata { \
554  friend VIEW; \
555  SOA_HOST_DEVICE SOA_INLINE size_type size() const { return parent_.elements_; } \
556  /* Alias layout or view types to name-derived identifyer to allow simpler definitions */ \
557  _ITERATE_ON_ALL(_DECLARE_VIEW_LAYOUT_TYPE_ALIAS, ~, LAYOUTS_LIST) \
558  \
559  /* Alias member types to name-derived identifyer to allow simpler definitions */ \
560  _ITERATE_ON_ALL(_DECLARE_VIEW_MEMBER_TYPE_ALIAS, const_cast_SoAParametersImpl, VALUE_LIST) \
561  _ITERATE_ON_ALL(_DECLARE_VIEW_MEMBER_POINTERS, ~, VALUE_LIST) \
562  _ITERATE_ON_ALL(_DECLARE_VIEW_MEMBER_CONST_POINTERS, ~, VALUE_LIST) \
563  \
564  /* Forbid copying to avoid const correctness evasion */ \
565  Metadata& operator=(const Metadata&) = delete; \
566  Metadata(const Metadata&) = delete; \
567  \
568  private: \
569  SOA_HOST_DEVICE SOA_INLINE Metadata(const VIEW& _soa_impl_parent) : parent_(_soa_impl_parent) {} \
570  const VIEW& parent_; \
571  }; \
572  \
573  friend Metadata; \
574  SOA_HOST_DEVICE SOA_INLINE const Metadata metadata() const { return Metadata(*this); } \
575  SOA_HOST_DEVICE SOA_INLINE Metadata metadata() { return Metadata(*this); } \
576  \
577  /* Trivial constuctor */ \
578  VIEW() = default; \
579  \
580  /* Constructor relying on user provided layouts or views */ \
581  SOA_HOST_ONLY VIEW(_ITERATE_ON_ALL_COMMA(_DECLARE_VIEW_CONSTRUCTION_PARAMETERS, BOOST_PP_EMPTY(), LAYOUTS_LIST)) \
582  : base_type{_ITERATE_ON_ALL_COMMA(_DECLARE_LAYOUT_LIST, BOOST_PP_EMPTY(), LAYOUTS_LIST)} {} \
583  \
584  /* Constructor relying on individually provided column addresses */ \
585  SOA_HOST_ONLY VIEW(size_type _soa_impl_elements, \
586  _ITERATE_ON_ALL_COMMA(_DECLARE_VIEW_CONSTRUCTION_BYCOLUMN_PARAMETERS, \
587  BOOST_PP_EMPTY(), \
588  VALUE_LIST)) \
589  : base_type{_soa_impl_elements, \
590  _ITERATE_ON_ALL_COMMA(_DECLARE_VIEW_MEMBER_LIST, BOOST_PP_EMPTY(), VALUE_LIST) \
591  } {} \
592  \
593  /* Copiable */ \
594  VIEW(VIEW const&) = default; \
595  VIEW& operator=(VIEW const&) = default; \
596  \
597  /* Copy constructor for other parameters */ \
598  template <CMS_SOA_BYTE_SIZE_TYPE OTHER_VIEW_ALIGNMENT, \
599  bool OTHER_VIEW_ALIGNMENT_ENFORCEMENT, \
600  bool OTHER_RESTRICT_QUALIFY, \
601  bool OTHER_RANGE_CHECKING> \
602  VIEW(VIEW<OTHER_VIEW_ALIGNMENT, OTHER_VIEW_ALIGNMENT_ENFORCEMENT, OTHER_RESTRICT_QUALIFY, \
603  OTHER_RANGE_CHECKING> const& other): base_type{other.elements_, \
604  _ITERATE_ON_ALL_COMMA(_DECLARE_VIEW_OTHER_MEMBER_LIST, BOOST_PP_EMPTY(), VALUE_LIST) \
605  } {} \
606  /* Copy operator for other parameters */ \
607  template <CMS_SOA_BYTE_SIZE_TYPE OTHER_VIEW_ALIGNMENT, \
608  bool OTHER_VIEW_ALIGNMENT_ENFORCEMENT, \
609  bool OTHER_RESTRICT_QUALIFY, \
610  bool OTHER_RANGE_CHECKING> \
611  VIEW& operator=(VIEW<OTHER_VIEW_ALIGNMENT, OTHER_VIEW_ALIGNMENT_ENFORCEMENT, OTHER_RESTRICT_QUALIFY, \
612  OTHER_RANGE_CHECKING> const& other) { static_cast<base_type>(*this) = static_cast<base_type>(other); } \
613  \
614  /* Movable */ \
615  VIEW(VIEW &&) = default; \
616  VIEW& operator=(VIEW &&) = default; \
617  \
618  /* Trivial destuctor */ \
619  ~VIEW() = default; \
620  \
621  /* AoS-like accessor (const) */ \
622  using const_element = typename base_type::const_element; \
623  \
624  using base_type::operator[]; \
625  \
626  /* AoS-like accessor (mutable) */ \
627  struct element { \
628  SOA_HOST_DEVICE SOA_INLINE \
629  element(size_type _soa_impl_index, /* Declare parameters */ \
630  _ITERATE_ON_ALL_COMMA(_DECLARE_VIEW_ELEMENT_VALUE_ARG, BOOST_PP_EMPTY(), VALUE_LIST)) \
631  : _ITERATE_ON_ALL_COMMA(_DECLARE_VIEW_ELEM_MEMBER_INIT, _soa_impl_index, VALUE_LIST) {} \
632  SOA_HOST_DEVICE SOA_INLINE \
633  element& operator=(const element& _soa_impl_other) { \
634  _ITERATE_ON_ALL(_DECLARE_VIEW_ELEMENT_VALUE_COPY, ~, VALUE_LIST) \
635  return *this; \
636  } \
637  SOA_HOST_DEVICE SOA_INLINE \
638  element& operator=(const const_element& _soa_impl_other) { \
639  _ITERATE_ON_ALL(_DECLARE_VIEW_ELEMENT_VALUE_COPY, ~, VALUE_LIST) \
640  return *this; \
641  }
642 // clang-format on
643 
644 // clang-format off
645 #define _GENERATE_SOA_VIEW_PART_2(CONST_VIEW, VIEW, LAYOUTS_LIST, VALUE_LIST) \
646  _ITERATE_ON_ALL(_DECLARE_VIEW_ELEMENT_VALUE_MEMBER, ~, VALUE_LIST) \
647  }; \
648  \
649  SOA_HOST_DEVICE SOA_INLINE \
650  element operator[](size_type _soa_impl_index) { \
651  if constexpr (rangeChecking == cms::soa::RangeChecking::enabled) { \
652  if (_soa_impl_index >= base_type::elements_ or _soa_impl_index < 0) \
653  SOA_THROW_OUT_OF_RANGE("Out of range index in " #VIEW "::operator[]") \
654  } \
655  return element{_soa_impl_index, _ITERATE_ON_ALL_COMMA(_DECLARE_VIEW_ELEMENT_CONSTR_CALL, ~, VALUE_LIST)}; \
656  } \
657  \
658  /* inherit const accessors from ConstView */ \
659  \
660  /* non-const accessors */ \
661  _ITERATE_ON_ALL(_DECLARE_VIEW_SOA_ACCESSOR, ~, VALUE_LIST) \
662  \
663  /* dump the SoA internal structure */ \
664  template <typename T> \
665  SOA_HOST_ONLY friend void dump(); \
666  };
667 // clang-format on
668 
669 /* ---- CONST VIEW -------------------------------------------------------------------------------------------------- */
670 // clang-format off
671 #define _GENERATE_SOA_CONST_VIEW_PART_0(CONST_VIEW, VIEW, LAYOUTS_LIST, VALUE_LIST) \
672  template <CMS_SOA_BYTE_SIZE_TYPE VIEW_ALIGNMENT = cms::soa::CacheLineSize::defaultSize, \
673  bool VIEW_ALIGNMENT_ENFORCEMENT = cms::soa::AlignmentEnforcement::relaxed, \
674  bool RESTRICT_QUALIFY = cms::soa::RestrictQualify::enabled, \
675  bool RANGE_CHECKING = cms::soa::RangeChecking::disabled> \
676  struct CONST_VIEW { \
677  /* these could be moved to an external type trait to free up the symbol names */ \
678  using self_type = CONST_VIEW;
679 // clang-format on
680 
681 // clang-format off
682 #define _GENERATE_SOA_CONST_VIEW_PART_0_NO_DEFAULTS(CONST_VIEW, VIEW, LAYOUTS_LIST, VALUE_LIST) \
683  template <CMS_SOA_BYTE_SIZE_TYPE VIEW_ALIGNMENT, \
684  bool VIEW_ALIGNMENT_ENFORCEMENT, \
685  bool RESTRICT_QUALIFY, \
686  bool RANGE_CHECKING> \
687  struct CONST_VIEW { \
688  /* these could be moved to an external type trait to free up the symbol names */ \
689  using self_type = CONST_VIEW;
690 // clang-format on
691 
696 // clang-format off
697 #define _GENERATE_SOA_CONST_VIEW_PART_1(CONST_VIEW, VIEW, LAYOUTS_LIST, VALUE_LIST) \
698  using size_type = cms::soa::size_type; \
699  using byte_size_type = cms::soa::byte_size_type; \
700  using AlignmentEnforcement = cms::soa::AlignmentEnforcement; \
701  \
702  template <CMS_SOA_BYTE_SIZE_TYPE, bool, bool, bool> \
703  friend struct VIEW; \
704  \
705  template <CMS_SOA_BYTE_SIZE_TYPE, bool, bool, bool> \
706  friend struct CONST_VIEW; \
707  \
708  /* For CUDA applications, we align to the 128 bytes of the cache lines. \
709  * See https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#global-memory-3-0 this is still valid \
710  * up to compute capability 8.X. \
711  */ \
712  constexpr static byte_size_type defaultAlignment = cms::soa::CacheLineSize::defaultSize; \
713  constexpr static byte_size_type alignment = VIEW_ALIGNMENT; \
714  constexpr static bool alignmentEnforcement = VIEW_ALIGNMENT_ENFORCEMENT; \
715  constexpr static byte_size_type conditionalAlignment = \
716  alignmentEnforcement == AlignmentEnforcement::enforced ? alignment : 0; \
717  constexpr static bool restrictQualify = RESTRICT_QUALIFY; \
718  constexpr static bool rangeChecking = RANGE_CHECKING; \
719  /* Those typedefs avoid having commas in macros (which is problematic) */ \
720  template <cms::soa::SoAColumnType COLUMN_TYPE, class C> \
721  using SoAValueWithConf = cms::soa::SoAValue<COLUMN_TYPE, C, conditionalAlignment, restrictQualify>; \
722  \
723  template <cms::soa::SoAColumnType COLUMN_TYPE, class C> \
724  using SoAConstValueWithConf = cms::soa::SoAConstValue<COLUMN_TYPE, C, conditionalAlignment, restrictQualify>; \
725  \
726  \
729  struct Metadata { \
730  friend CONST_VIEW; \
731  SOA_HOST_DEVICE SOA_INLINE size_type size() const { return parent_.elements_; } \
732  /* Alias layout or view types to name-derived identifyer to allow simpler definitions */ \
733  _ITERATE_ON_ALL(_DECLARE_VIEW_LAYOUT_TYPE_ALIAS, ~, LAYOUTS_LIST) \
734  \
735  /* Alias member types to name-derived identifyer to allow simpler definitions */ \
736  _ITERATE_ON_ALL(_DECLARE_VIEW_MEMBER_TYPE_ALIAS, BOOST_PP_EMPTY(), VALUE_LIST) \
737  _ITERATE_ON_ALL(_DECLARE_VIEW_MEMBER_CONST_POINTERS, ~, VALUE_LIST) \
738  \
739  /* Forbid copying to avoid const correctness evasion */ \
740  Metadata& operator=(const Metadata&) = delete; \
741  Metadata(const Metadata&) = delete; \
742  \
743  private: \
744  SOA_HOST_DEVICE SOA_INLINE Metadata(const CONST_VIEW& _soa_impl_parent) : parent_(_soa_impl_parent) {} \
745  const CONST_VIEW& parent_; \
746  }; \
747  \
748  friend Metadata; \
749  SOA_HOST_DEVICE SOA_INLINE const Metadata metadata() const { return Metadata(*this); } \
750  \
751  /* Trivial constuctor */ \
752  CONST_VIEW() = default; \
753  \
754  /* Constructor relying on user provided layouts or views */ \
755  SOA_HOST_ONLY CONST_VIEW(_ITERATE_ON_ALL_COMMA(_DECLARE_VIEW_CONSTRUCTION_PARAMETERS, const, LAYOUTS_LIST)) \
756  : elements_([&]() -> size_type { \
757  bool set = false; \
758  size_type ret = 0; \
759  _ITERATE_ON_ALL(_UPDATE_SIZE_OF_VIEW, BOOST_PP_EMPTY(), LAYOUTS_LIST) \
760  return ret; \
761  }()), \
762  _ITERATE_ON_ALL_COMMA(_DECLARE_VIEW_MEMBER_INITIALIZERS, ~, VALUE_LIST) {} \
763  \
764  /* Constructor relying on individually provided column addresses */ \
765  SOA_HOST_ONLY CONST_VIEW(size_type _soa_impl_elements, \
766  _ITERATE_ON_ALL_COMMA(_DECLARE_VIEW_CONSTRUCTION_BYCOLUMN_PARAMETERS, const, VALUE_LIST)) \
767  : elements_(_soa_impl_elements), \
768  _ITERATE_ON_ALL_COMMA(_DECLARE_VIEW_MEMBER_INITIALIZERS_BYCOLUMN, ~, VALUE_LIST) {} \
769  \
770  /* Copiable */ \
771  CONST_VIEW(CONST_VIEW const&) = default; \
772  CONST_VIEW& operator=(CONST_VIEW const&) = default; \
773  \
774  /* Copy constructor for other parameters */ \
775  template <CMS_SOA_BYTE_SIZE_TYPE OTHER_VIEW_ALIGNMENT, \
776  bool OTHER_VIEW_ALIGNMENT_ENFORCEMENT, \
777  bool OTHER_RESTRICT_QUALIFY, \
778  bool OTHER_RANGE_CHECKING> \
779  CONST_VIEW(CONST_VIEW<OTHER_VIEW_ALIGNMENT, OTHER_VIEW_ALIGNMENT_ENFORCEMENT, OTHER_RESTRICT_QUALIFY, \
780  OTHER_RANGE_CHECKING> const& other): CONST_VIEW{other.elements_, \
781  _ITERATE_ON_ALL_COMMA(_DECLARE_VIEW_OTHER_MEMBER_LIST, BOOST_PP_EMPTY(), VALUE_LIST) \
782  } {} \
783  /* Copy operator for other parameters */ \
784  template <CMS_SOA_BYTE_SIZE_TYPE OTHER_VIEW_ALIGNMENT, \
785  bool OTHER_VIEW_ALIGNMENT_ENFORCEMENT, \
786  bool OTHER_RESTRICT_QUALIFY, \
787  bool OTHER_RANGE_CHECKING> \
788  CONST_VIEW& operator=(CONST_VIEW<OTHER_VIEW_ALIGNMENT, OTHER_VIEW_ALIGNMENT_ENFORCEMENT, OTHER_RESTRICT_QUALIFY, \
789  OTHER_RANGE_CHECKING> const& other) { *this = other; } \
790  \
791  /* Movable */ \
792  CONST_VIEW(CONST_VIEW &&) = default; \
793  CONST_VIEW& operator=(CONST_VIEW &&) = default; \
794  \
795  /* Trivial destuctor */ \
796  ~CONST_VIEW() = default; \
797  \
798  /* AoS-like accessor (const) */ \
799  struct const_element { \
800  SOA_HOST_DEVICE SOA_INLINE \
801  const_element(size_type _soa_impl_index, /* Declare parameters */ \
802  _ITERATE_ON_ALL_COMMA(_DECLARE_CONST_VIEW_ELEMENT_VALUE_ARG, const, VALUE_LIST)) \
803  : _ITERATE_ON_ALL_COMMA(_DECLARE_VIEW_CONST_ELEM_MEMBER_INIT, _soa_impl_index, VALUE_LIST) {} \
804  _ITERATE_ON_ALL(_DECLARE_VIEW_CONST_ELEMENT_ACCESSOR, ~, VALUE_LIST) \
805  \
806  private: \
807  _ITERATE_ON_ALL(_DECLARE_VIEW_CONST_ELEMENT_VALUE_MEMBER, ~, VALUE_LIST) \
808  }; \
809  \
810  SOA_HOST_DEVICE SOA_INLINE \
811  const_element operator[](size_type _soa_impl_index) const { \
812  if constexpr (rangeChecking == cms::soa::RangeChecking::enabled) { \
813  if (_soa_impl_index >= elements_ or _soa_impl_index < 0) \
814  SOA_THROW_OUT_OF_RANGE("Out of range index in " #CONST_VIEW "::operator[]") \
815  } \
816  return const_element{ \
817  _soa_impl_index, _ITERATE_ON_ALL_COMMA(_DECLARE_VIEW_CONST_ELEMENT_CONSTR_CALL, ~, VALUE_LIST) \
818  }; \
819  } \
820  \
821  /* const accessors */ \
822  _ITERATE_ON_ALL(_DECLARE_VIEW_SOA_CONST_ACCESSOR, ~, VALUE_LIST) \
823  \
824  /* dump the SoA internal structure */ \
825  template <typename T> \
826  SOA_HOST_ONLY friend void dump(); \
827  \
828  private: \
829  size_type elements_ = 0; \
830  _ITERATE_ON_ALL(_DECLARE_CONST_VIEW_SOA_MEMBER, const, VALUE_LIST) \
831 };
832 // clang-format on
833 
834 // clang-format off
835 // MAJOR caveat: in order to propagate the LAYOUTS_LIST and VALUE_LIST
836 #define _GENERATE_SOA_CONST_VIEW(CONST_VIEW, VIEW, LAYOUTS_LIST, VALUE_LIST) \
837  _GENERATE_SOA_CONST_VIEW_PART_0(CONST_VIEW, VIEW, \
838  SOA_VIEW_LAYOUT_LIST(LAYOUTS_LIST), SOA_VIEW_VALUE_LIST(VALUE_LIST)) \
839  _GENERATE_SOA_CONST_VIEW_PART_1(CONST_VIEW, VIEW, \
840  SOA_VIEW_LAYOUT_LIST(LAYOUTS_LIST), SOA_VIEW_VALUE_LIST(VALUE_LIST))
841 
842 #define GENERATE_SOA_CONST_VIEW(CONST_VIEW, VIEW, LAYOUTS_LIST, VALUE_LIST) \
843  _GENERATE_SOA_CONST_VIEW(CONST_VIEW, BOOST_PP_CAT(CONST_VIEW, Unused_), \
844  SOA_VIEW_LAYOUT_LIST(LAYOUTS_LIST), SOA_VIEW_VALUE_LIST(VALUE_LIST))
845 
846 #define _GENERATE_SOA_TRIVIAL_CONST_VIEW(CLASS, LAYOUTS_LIST, VALUE_LIST) \
847  _GENERATE_SOA_CONST_VIEW_PART_0_NO_DEFAULTS(ConstViewTemplateFreeParams, ViewTemplateFreeParams, \
848  SOA_VIEW_LAYOUT_LIST(LAYOUTS_LIST), SOA_VIEW_VALUE_LIST(VALUE_LIST)) \
849  using BOOST_PP_CAT(CLASS, _parametrized) = CLASS<VIEW_ALIGNMENT, VIEW_ALIGNMENT_ENFORCEMENT>; \
850  _GENERATE_SOA_CONST_VIEW_PART_1(ConstViewTemplateFreeParams, ViewTemplateFreeParams, \
851  SOA_VIEW_LAYOUT_LIST(LAYOUTS_LIST), SOA_VIEW_VALUE_LIST(VALUE_LIST))
852 
853 #define _GENERATE_SOA_VIEW(CONST_VIEW, VIEW, LAYOUTS_LIST, VALUE_LIST) \
854  _GENERATE_SOA_VIEW_PART_0(CONST_VIEW, VIEW, SOA_VIEW_LAYOUT_LIST(LAYOUTS_LIST), SOA_VIEW_VALUE_LIST(VALUE_LIST)) \
855  _GENERATE_SOA_VIEW_PART_1(CONST_VIEW, VIEW, SOA_VIEW_LAYOUT_LIST(LAYOUTS_LIST), SOA_VIEW_VALUE_LIST(VALUE_LIST)) \
856  _GENERATE_SOA_VIEW_PART_2(CONST_VIEW, VIEW, SOA_VIEW_LAYOUT_LIST(LAYOUTS_LIST), SOA_VIEW_VALUE_LIST(VALUE_LIST))
857 
858 #define GENERATE_SOA_VIEW(CONST_VIEW, VIEW, LAYOUTS_LIST, VALUE_LIST) \
859  _GENERATE_SOA_CONST_VIEW(CONST_VIEW, VIEW, SOA_VIEW_LAYOUT_LIST(LAYOUTS_LIST), SOA_VIEW_VALUE_LIST(VALUE_LIST)) \
860  _GENERATE_SOA_VIEW(CONST_VIEW, VIEW, SOA_VIEW_LAYOUT_LIST(LAYOUTS_LIST), SOA_VIEW_VALUE_LIST(VALUE_LIST))
861 
862 #define _GENERATE_SOA_TRIVIAL_VIEW(CLASS, LAYOUTS_LIST, VALUE_LIST, ...) \
863  _GENERATE_SOA_VIEW_PART_0_NO_DEFAULTS(ConstViewTemplateFreeParams, ViewTemplateFreeParams, \
864  SOA_VIEW_LAYOUT_LIST(LAYOUTS_LIST), SOA_VIEW_VALUE_LIST(VALUE_LIST)) \
865  using BOOST_PP_CAT(CLASS, _parametrized) = CLASS<VIEW_ALIGNMENT, VIEW_ALIGNMENT_ENFORCEMENT>; \
866  _GENERATE_SOA_VIEW_PART_1(ConstViewTemplateFreeParams, ViewTemplateFreeParams, \
867  SOA_VIEW_LAYOUT_LIST(LAYOUTS_LIST), SOA_VIEW_VALUE_LIST(VALUE_LIST)) \
868  \
869  /* Extra operator=() for mutable element to emulate the aggregate initialisation syntax */ \
870  SOA_HOST_DEVICE SOA_INLINE constexpr element & operator=(const typename \
871  BOOST_PP_CAT(CLASS, _parametrized)::Metadata::value_element _soa_impl_value) { \
872  _ITERATE_ON_ALL(_TRIVIAL_VIEW_ASSIGN_VALUE_ELEMENT, ~, __VA_ARGS__) \
873  return *this; \
874  } \
875  \
876  _GENERATE_SOA_VIEW_PART_2(ConstViewTemplateFreeParams, ViewTemplateFreeParams, \
877  SOA_VIEW_LAYOUT_LIST(LAYOUTS_LIST), SOA_VIEW_VALUE_LIST(VALUE_LIST))
878 // clang-format on
879 
883 #define _VIEW_FIELD_FROM_LAYOUT_IMPL(VALUE_TYPE, CPP_TYPE, NAME, DATA) (DATA, NAME, NAME)
884 
885 #define _VIEW_FIELD_FROM_LAYOUT(R, DATA, VALUE_TYPE_NAME) \
886  BOOST_PP_EXPAND((_VIEW_FIELD_FROM_LAYOUT_IMPL BOOST_PP_TUPLE_PUSH_BACK(VALUE_TYPE_NAME, DATA)))
887 
888 #endif // DataFormats_SoATemplate_interface_SoAView_h
cms_int32_t size_type
Definition: SoACommon.h:62
#define SOA_INLINE
Definition: SoACommon.h:28
#define SOA_HOST_DEVICE
Definition: SoACommon.h:27
SoAColumnType
Definition: SoACommon.h:66
double scalar(const CLHEP::HepGenMatrix &m)
Return the matrix as a scalar. Raise an assertion if the matris is not .
Definition: matutil.cc:166