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_MEMBER_INITIALIZERS_FROM_OTHER_IMPL(LAYOUT, MEMBER, LOCAL_NAME, DATA) \
238  (BOOST_PP_CAT(MEMBER, Parameters_){DATA.BOOST_PP_CAT(MEMBER, Parameters_)})
239 
240 #define _DECLARE_VIEW_MEMBER_INITIALIZERS_FROM_OTHER(R, DATA, LAYOUT_MEMBER_NAME) \
241  BOOST_PP_EXPAND(_DECLARE_VIEW_MEMBER_INITIALIZERS_FROM_OTHER_IMPL BOOST_PP_TUPLE_PUSH_BACK(LAYOUT_MEMBER_NAME, DATA))
242 
246 #define _DECLARE_VIEW_MEMBER_ASSIGNMENT_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_ASSIGNMENT_FROM_OTHER(R, DATA, LAYOUT_MEMBER_NAME) \
250  BOOST_PP_EXPAND(_DECLARE_VIEW_MEMBER_ASSIGNMENT_FROM_OTHER_IMPL BOOST_PP_TUPLE_PUSH_BACK(LAYOUT_MEMBER_NAME, DATA))
251 
255 #define _DECLARE_VIEW_ELEM_MEMBER_INIT_IMPL(LAYOUT, MEMBER, LOCAL_NAME, DATA) (LOCAL_NAME(DATA, LOCAL_NAME))
256 
257 #define _DECLARE_VIEW_ELEM_MEMBER_INIT(R, DATA, LAYOUT_MEMBER_NAME) \
258  BOOST_PP_EXPAND(_DECLARE_VIEW_ELEM_MEMBER_INIT_IMPL BOOST_PP_TUPLE_PUSH_BACK(LAYOUT_MEMBER_NAME, DATA))
259 
263 #define _COLUMN_TYPE(LAYOUT_NAME, LAYOUT_MEMBER) \
264  typename std::remove_pointer<decltype(BOOST_PP_CAT(LAYOUT_NAME, Type)()::LAYOUT_MEMBER())>::type
265 
269 #define _DECLARE_VIEW_ELEMENT_VALUE_ARG_IMPL(LAYOUT_NAME, LAYOUT_MEMBER, LOCAL_NAME, DATA) \
270  (DATA typename BOOST_PP_CAT(Metadata::ParametersTypeOf_, LOCAL_NAME) LOCAL_NAME)
271 
272 #define _DECLARE_VIEW_ELEMENT_VALUE_ARG(R, DATA, LAYOUT_MEMBER_NAME) \
273  _DECLARE_VIEW_ELEMENT_VALUE_ARG_IMPL BOOST_PP_TUPLE_PUSH_BACK(LAYOUT_MEMBER_NAME, DATA)
274 
278 #define _DECLARE_CONST_VIEW_ELEMENT_VALUE_ARG_IMPL(LAYOUT_NAME, LAYOUT_MEMBER, LOCAL_NAME, DATA) \
279  (DATA typename BOOST_PP_CAT(Metadata::ParametersTypeOf_, LOCAL_NAME)::ConstType LOCAL_NAME)
280 
281 #define _DECLARE_CONST_VIEW_ELEMENT_VALUE_ARG(R, DATA, LAYOUT_MEMBER_NAME) \
282  _DECLARE_CONST_VIEW_ELEMENT_VALUE_ARG_IMPL BOOST_PP_TUPLE_PUSH_BACK(LAYOUT_MEMBER_NAME, DATA)
283 
287 #define _DECLARE_VIEW_CONST_ELEM_MEMBER_INIT_IMPL(LAYOUT_NAME, LAYOUT_MEMBER, LOCAL_NAME, DATA) \
288  (BOOST_PP_CAT(LOCAL_NAME, _)(DATA, LOCAL_NAME))
289 
290 /* declare AoS-like element value args for contructor; these should expand,for columns only */
291 #define _DECLARE_VIEW_CONST_ELEM_MEMBER_INIT(R, DATA, LAYOUT_MEMBER_NAME) \
292  BOOST_PP_EXPAND(_DECLARE_VIEW_CONST_ELEM_MEMBER_INIT_IMPL BOOST_PP_TUPLE_PUSH_BACK(LAYOUT_MEMBER_NAME, DATA))
293 
297 // clang-format off
298 #define _DECLARE_VIEW_CONST_ELEMENT_ACCESSOR_IMPL(LAYOUT_NAME, LAYOUT_MEMBER, LOCAL_NAME) \
299  SOA_HOST_DEVICE SOA_INLINE \
300  const typename SoAConstValueWithConf<BOOST_PP_CAT(Metadata::ColumnTypeOf_, LOCAL_NAME), \
301  const typename BOOST_PP_CAT(Metadata::TypeOf_, LOCAL_NAME)>::RefToConst \
302  LOCAL_NAME() const { \
303  return BOOST_PP_CAT(LOCAL_NAME, _)(); \
304  }
305 // clang-format on
306 
307 #define _DECLARE_VIEW_CONST_ELEMENT_ACCESSOR(R, DATA, LAYOUT_MEMBER_NAME) \
308  _DECLARE_VIEW_CONST_ELEMENT_ACCESSOR_IMPL LAYOUT_MEMBER_NAME
309 
313 // clang-format off
314 #define _DECLARE_VIEW_CONST_ELEMENT_VALUE_MEMBER_IMPL(LAYOUT_NAME, LAYOUT_MEMBER, LOCAL_NAME) \
315  const cms::soa::ConstValueTraits<SoAConstValueWithConf<BOOST_PP_CAT(Metadata::ColumnTypeOf_, LOCAL_NAME), \
316  typename BOOST_PP_CAT(Metadata::TypeOf_, LOCAL_NAME)>, \
317  BOOST_PP_CAT(Metadata::ColumnTypeOf_, LOCAL_NAME)> \
318  BOOST_PP_CAT(LOCAL_NAME, _);
319 // clang-format on
320 
321 #define _DECLARE_VIEW_CONST_ELEMENT_VALUE_MEMBER(R, DATA, LAYOUT_MEMBER_NAME) \
322  _DECLARE_VIEW_CONST_ELEMENT_VALUE_MEMBER_IMPL LAYOUT_MEMBER_NAME
323 
327 #define _DECLARE_VIEW_ELEMENT_VALUE_COPY_IMPL(LAYOUT_NAME, LAYOUT_MEMBER, LOCAL_NAME) \
328  if constexpr (Metadata::BOOST_PP_CAT(ColumnTypeOf_, LOCAL_NAME) != cms::soa::SoAColumnType::scalar) \
329  LOCAL_NAME() = other.LOCAL_NAME();
330 
331 #define _DECLARE_VIEW_ELEMENT_VALUE_COPY(R, DATA, LAYOUT_MEMBER_NAME) \
332  BOOST_PP_EXPAND(_DECLARE_VIEW_ELEMENT_VALUE_COPY_IMPL LAYOUT_MEMBER_NAME)
333 
337 // clang-format off
338 #define _DECLARE_VIEW_ELEMENT_VALUE_MEMBER_IMPL(LAYOUT_NAME, LAYOUT_MEMBER, LOCAL_NAME) \
339  SoAValueWithConf<BOOST_PP_CAT(Metadata::ColumnTypeOf_, LOCAL_NAME), \
340  typename BOOST_PP_CAT(Metadata::TypeOf_, LOCAL_NAME)> \
341  LOCAL_NAME;
342 // clang-format on
343 
344 #define _DECLARE_VIEW_ELEMENT_VALUE_MEMBER(R, DATA, LAYOUT_MEMBER_NAME) \
345  _DECLARE_VIEW_ELEMENT_VALUE_MEMBER_IMPL LAYOUT_MEMBER_NAME
346 
350 #define _DECLARE_VIEW_CONST_ELEMENT_CONSTR_CALL_IMPL(LAYOUT_NAME, LAYOUT_MEMBER, LOCAL_NAME) \
351  (BOOST_PP_CAT(LOCAL_NAME, Parameters_))
352 
353 #define _DECLARE_VIEW_CONST_ELEMENT_CONSTR_CALL(R, DATA, LAYOUT_MEMBER_NAME) \
354  BOOST_PP_EXPAND(_DECLARE_VIEW_CONST_ELEMENT_CONSTR_CALL_IMPL LAYOUT_MEMBER_NAME)
355 
362 #define _DECLARE_VIEW_ELEMENT_CONSTR_CALL_IMPL(LAYOUT_NAME, LAYOUT_MEMBER, LOCAL_NAME) \
363  (const_cast_SoAParametersImpl(base_type::BOOST_PP_CAT(LOCAL_NAME, Parameters_)))
364 
365 #define _DECLARE_VIEW_ELEMENT_CONSTR_CALL(R, DATA, LAYOUT_MEMBER_NAME) \
366  BOOST_PP_EXPAND(_DECLARE_VIEW_ELEMENT_CONSTR_CALL_IMPL LAYOUT_MEMBER_NAME)
367 
371 // clang-format off
372 #define _DECLARE_VIEW_SOA_ACCESSOR_IMPL(LAYOUT_NAME, LAYOUT_MEMBER, LOCAL_NAME) \
373  /* Column or scalar */ \
374  SOA_HOST_DEVICE SOA_INLINE \
375  typename cms::soa::SoAAccessors<typename BOOST_PP_CAT(Metadata::TypeOf_, LOCAL_NAME)>:: \
376  template ColumnType<BOOST_PP_CAT(Metadata::ColumnTypeOf_, LOCAL_NAME)>::template AccessType< \
377  cms::soa::SoAAccessType::mutableAccess>::template Alignment<conditionalAlignment>:: \
378  template RestrictQualifier<restrictQualify>::NoParamReturnType \
379  LOCAL_NAME() { \
380  return typename cms::soa::SoAAccessors<typename BOOST_PP_CAT(Metadata::TypeOf_, LOCAL_NAME)>:: \
381  template ColumnType<BOOST_PP_CAT(Metadata::ColumnTypeOf_, LOCAL_NAME)>::template AccessType< \
382  cms::soa::SoAAccessType::mutableAccess>::template Alignment<conditionalAlignment>:: \
383  template RestrictQualifier<restrictQualify>(const_cast_SoAParametersImpl( \
384  base_type:: BOOST_PP_CAT(LOCAL_NAME, Parameters_)))(); \
385  } \
386  SOA_HOST_DEVICE SOA_INLINE \
387  typename cms::soa::SoAAccessors<typename BOOST_PP_CAT(Metadata::TypeOf_, LOCAL_NAME)>:: \
388  template ColumnType<BOOST_PP_CAT(Metadata::ColumnTypeOf_, LOCAL_NAME)>::template AccessType< \
389  cms::soa::SoAAccessType::mutableAccess>::template Alignment<conditionalAlignment>:: \
390  template RestrictQualifier<restrictQualify>::ParamReturnType \
391  LOCAL_NAME(size_type index) { \
392  if constexpr (rangeChecking == cms::soa::RangeChecking::enabled) { \
393  if (index >= base_type::elements_) \
394  SOA_THROW_OUT_OF_RANGE("Out of range index in mutable " #LOCAL_NAME "(size_type index)") \
395  } \
396  return 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>(const_cast_SoAParametersImpl( \
400  base_type:: BOOST_PP_CAT(LOCAL_NAME, Parameters_)))(index); \
401  }
402 // clang-format on
403 
404 #define _DECLARE_VIEW_SOA_ACCESSOR(R, DATA, LAYOUT_MEMBER_NAME) \
405  BOOST_PP_EXPAND(_DECLARE_VIEW_SOA_ACCESSOR_IMPL LAYOUT_MEMBER_NAME)
406 
410 // clang-format off
411 #define _DECLARE_VIEW_SOA_CONST_ACCESSOR_IMPL(LAYOUT_NAME, LAYOUT_MEMBER, LOCAL_NAME) \
412  /* Column or scalar */ \
413  SOA_HOST_DEVICE SOA_INLINE \
414  typename cms::soa::SoAAccessors<typename BOOST_PP_CAT(Metadata::TypeOf_, LOCAL_NAME)>:: \
415  template ColumnType<BOOST_PP_CAT(Metadata::ColumnTypeOf_, LOCAL_NAME)>::template AccessType< \
416  cms::soa::SoAAccessType::constAccess>::template Alignment<conditionalAlignment>:: \
417  template RestrictQualifier<restrictQualify>::NoParamReturnType \
418  LOCAL_NAME() const { \
419  return typename cms::soa::SoAAccessors<typename BOOST_PP_CAT(Metadata::TypeOf_, LOCAL_NAME)>:: \
420  template ColumnType<BOOST_PP_CAT(Metadata::ColumnTypeOf_, LOCAL_NAME)>::template AccessType< \
421  cms::soa::SoAAccessType::constAccess>::template Alignment<conditionalAlignment>:: \
422  template RestrictQualifier<restrictQualify>(BOOST_PP_CAT(LOCAL_NAME, Parameters_))(); \
423  } \
424  SOA_HOST_DEVICE SOA_INLINE \
425  typename cms::soa::SoAAccessors<typename BOOST_PP_CAT(Metadata::TypeOf_, LOCAL_NAME)>:: \
426  template ColumnType<BOOST_PP_CAT(Metadata::ColumnTypeOf_, LOCAL_NAME)>::template AccessType< \
427  cms::soa::SoAAccessType::constAccess>::template Alignment<conditionalAlignment>:: \
428  template RestrictQualifier<restrictQualify>::ParamReturnType \
429  LOCAL_NAME(size_type index) const { \
430  if constexpr (rangeChecking == cms::soa::RangeChecking::enabled) { \
431  if (index >= elements_) \
432  SOA_THROW_OUT_OF_RANGE("Out of range index in const " #LOCAL_NAME "(size_type index)") \
433  } \
434  return 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>(BOOST_PP_CAT(LOCAL_NAME, Parameters_))(index); \
438  }
439 // clang-format on
440 
441 #define _DECLARE_VIEW_SOA_CONST_ACCESSOR(R, DATA, LAYOUT_MEMBER_NAME) \
442  BOOST_PP_EXPAND(_DECLARE_VIEW_SOA_CONST_ACCESSOR_IMPL LAYOUT_MEMBER_NAME)
443 
447 #define _DECLARE_VIEW_SOA_MEMBER_IMPL(LAYOUT_NAME, LAYOUT_MEMBER, LOCAL_NAME, DATA) \
448  typename BOOST_PP_CAT(Metadata::ParametersTypeOf_, LOCAL_NAME) BOOST_PP_CAT(LOCAL_NAME, Parameters_);
449 
450 #define _DECLARE_VIEW_SOA_MEMBER(R, DATA, LAYOUT_MEMBER_NAME) \
451  BOOST_PP_EXPAND(_DECLARE_VIEW_SOA_MEMBER_IMPL BOOST_PP_TUPLE_PUSH_BACK(LAYOUT_MEMBER_NAME, DATA))
452 
456 #define _DECLARE_CONST_VIEW_SOA_MEMBER_IMPL(LAYOUT_NAME, LAYOUT_MEMBER, LOCAL_NAME, DATA) \
457  typename BOOST_PP_CAT(Metadata::ParametersTypeOf_, LOCAL_NAME)::ConstType BOOST_PP_CAT(LOCAL_NAME, Parameters_);
458 
459 #define _DECLARE_CONST_VIEW_SOA_MEMBER(R, DATA, LAYOUT_MEMBER_NAME) \
460  BOOST_PP_EXPAND(_DECLARE_CONST_VIEW_SOA_MEMBER_IMPL BOOST_PP_TUPLE_PUSH_BACK(LAYOUT_MEMBER_NAME, DATA))
461 
466 // clang-format off
467 #define _TRIVIAL_VIEW_ASSIGN_VALUE_ELEMENT_IMPL(VALUE_TYPE, CPP_TYPE, NAME) \
468  _SWITCH_ON_TYPE(VALUE_TYPE, \
469  /* Scalar (empty) */ \
470  , \
471  /* Column */ \
472  NAME() = value.NAME; \
473  , \
474  /* Eigen column */ \
475  NAME() = value.NAME; \
476 )
477 // clang-format on
478 
479 #define _TRIVIAL_VIEW_ASSIGN_VALUE_ELEMENT(R, DATA, TYPE_NAME) _TRIVIAL_VIEW_ASSIGN_VALUE_ELEMENT_IMPL TYPE_NAME
480 
481 /* ---- MUTABLE VIEW ------------------------------------------------------------------------------------------------ */
482 // clang-format off
483 #define _GENERATE_SOA_VIEW_PART_0(CONST_VIEW, VIEW, LAYOUTS_LIST, VALUE_LIST) \
484  template <CMS_SOA_BYTE_SIZE_TYPE VIEW_ALIGNMENT = cms::soa::CacheLineSize::defaultSize, \
485  bool VIEW_ALIGNMENT_ENFORCEMENT = cms::soa::AlignmentEnforcement::relaxed, \
486  bool RESTRICT_QUALIFY = cms::soa::RestrictQualify::enabled, \
487  bool RANGE_CHECKING = cms::soa::RangeChecking::disabled> \
488  struct VIEW : public CONST_VIEW<VIEW_ALIGNMENT, VIEW_ALIGNMENT_ENFORCEMENT, RESTRICT_QUALIFY, RANGE_CHECKING> { \
489  /* Declare the parametrized layouts as the default */ \
490  /*BOOST_PP_SEQ_CAT(_ITERATE_ON_ALL(_DECLARE_VIEW_LAYOUT_PARAMETRIZED_TEMPLATE, ~, LAYOUTS_LIST)) */ \
491  /* these could be moved to an external type trait to free up the symbol names */ \
492  using self_type = VIEW; \
493  using base_type = CONST_VIEW<VIEW_ALIGNMENT, VIEW_ALIGNMENT_ENFORCEMENT, RESTRICT_QUALIFY, RANGE_CHECKING>;
494 // clang-format on
495 
496 // clang-format off
497 #define _GENERATE_SOA_VIEW_PART_0_NO_DEFAULTS(CONST_VIEW, VIEW, LAYOUTS_LIST, VALUE_LIST) \
498  template <CMS_SOA_BYTE_SIZE_TYPE VIEW_ALIGNMENT, \
499  bool VIEW_ALIGNMENT_ENFORCEMENT, \
500  bool RESTRICT_QUALIFY, \
501  bool RANGE_CHECKING> \
502  struct VIEW : public CONST_VIEW<VIEW_ALIGNMENT, VIEW_ALIGNMENT_ENFORCEMENT, RESTRICT_QUALIFY, RANGE_CHECKING> { \
503  /* Declare the parametrized layouts as the default */ \
504  /*BOOST_PP_SEQ_CAT(_ITERATE_ON_ALL(_DECLARE_VIEW_LAYOUT_PARAMETRIZED_TEMPLATE, ~, LAYOUTS_LIST)) */ \
505  /* these could be moved to an external type trait to free up the symbol names */ \
506  using self_type = VIEW; \
507  using base_type = CONST_VIEW<VIEW_ALIGNMENT, VIEW_ALIGNMENT_ENFORCEMENT, RESTRICT_QUALIFY, RANGE_CHECKING>;
508 // clang-format on
509 
514 // clang-format off
515 #define _GENERATE_SOA_VIEW_PART_1(CONST_VIEW, VIEW, LAYOUTS_LIST, VALUE_LIST) \
516  using size_type = cms::soa::size_type; \
517  using byte_size_type = cms::soa::byte_size_type; \
518  using AlignmentEnforcement = cms::soa::AlignmentEnforcement; \
519  \
520  /* For CUDA applications, we align to the 128 bytes of the cache lines. \
521  * See https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#global-memory-3-0 this is still valid \
522  * up to compute capability 8.X. \
523  */ \
524  constexpr static byte_size_type defaultAlignment = cms::soa::CacheLineSize::defaultSize; \
525  constexpr static byte_size_type alignment = VIEW_ALIGNMENT; \
526  constexpr static bool alignmentEnforcement = VIEW_ALIGNMENT_ENFORCEMENT; \
527  constexpr static byte_size_type conditionalAlignment = \
528  alignmentEnforcement == AlignmentEnforcement::enforced ? alignment : 0; \
529  constexpr static bool restrictQualify = RESTRICT_QUALIFY; \
530  constexpr static bool rangeChecking = RANGE_CHECKING; \
531  /* Those typedefs avoid having commas in macros (which is problematic) */ \
532  template <cms::soa::SoAColumnType COLUMN_TYPE, class C> \
533  using SoAValueWithConf = cms::soa::SoAValue<COLUMN_TYPE, C, conditionalAlignment, restrictQualify>; \
534  \
535  template <cms::soa::SoAColumnType COLUMN_TYPE, class C> \
536  using SoAConstValueWithConf = cms::soa::SoAConstValue<COLUMN_TYPE, C, conditionalAlignment, restrictQualify>; \
537  \
538  \
541  struct Metadata { \
542  friend VIEW; \
543  SOA_HOST_DEVICE SOA_INLINE size_type size() const { return parent_.elements_; } \
544  /* Alias layout or view types to name-derived identifyer to allow simpler definitions */ \
545  _ITERATE_ON_ALL(_DECLARE_VIEW_LAYOUT_TYPE_ALIAS, ~, LAYOUTS_LIST) \
546  \
547  /* Alias member types to name-derived identifyer to allow simpler definitions */ \
548  _ITERATE_ON_ALL(_DECLARE_VIEW_MEMBER_TYPE_ALIAS, const_cast_SoAParametersImpl, VALUE_LIST) \
549  _ITERATE_ON_ALL(_DECLARE_VIEW_MEMBER_POINTERS, ~, VALUE_LIST) \
550  _ITERATE_ON_ALL(_DECLARE_VIEW_MEMBER_CONST_POINTERS, ~, VALUE_LIST) \
551  \
552  /* Forbid copying to avoid const correctness evasion */ \
553  Metadata& operator=(const Metadata&) = delete; \
554  Metadata(const Metadata&) = delete; \
555  \
556  private: \
557  SOA_HOST_DEVICE SOA_INLINE Metadata(const VIEW& parent) : parent_(parent) {} \
558  const VIEW& parent_; \
559  }; \
560  \
561  friend Metadata; \
562  SOA_HOST_DEVICE SOA_INLINE const Metadata metadata() const { return Metadata(*this); } \
563  SOA_HOST_DEVICE SOA_INLINE Metadata metadata() { return Metadata(*this); } \
564  \
565  /* Trivial constuctor */ \
566  VIEW() = default; \
567  \
568  /* Constructor relying on user provided layouts or views */ \
569  SOA_HOST_ONLY VIEW(_ITERATE_ON_ALL_COMMA(_DECLARE_VIEW_CONSTRUCTION_PARAMETERS, BOOST_PP_EMPTY(), LAYOUTS_LIST)) \
570  : base_type{_ITERATE_ON_ALL_COMMA(_DECLARE_LAYOUT_LIST, BOOST_PP_EMPTY(), LAYOUTS_LIST)} {} \
571  \
572  /* Constructor relying on individually provided column addresses */ \
573  SOA_HOST_ONLY VIEW(size_type elements, \
574  _ITERATE_ON_ALL_COMMA(_DECLARE_VIEW_CONSTRUCTION_BYCOLUMN_PARAMETERS, \
575  BOOST_PP_EMPTY(), \
576  VALUE_LIST)) \
577  : base_type{elements, _ITERATE_ON_ALL_COMMA(_DECLARE_VIEW_MEMBER_LIST, BOOST_PP_EMPTY(), VALUE_LIST)} {} \
578  \
579  /* Copiable */ \
580  VIEW(VIEW const&) = default; \
581  VIEW& operator=(VIEW const&) = default; \
582  \
583  /* Movable */ \
584  VIEW(VIEW &&) = default; \
585  VIEW& operator=(VIEW &&) = default; \
586  \
587  /* Trivial destuctor */ \
588  ~VIEW() = default; \
589  \
590  /* AoS-like accessor (const) */ \
591  using const_element = typename base_type::const_element; \
592  \
593  using base_type::operator[]; \
594  \
595  /* AoS-like accessor (mutable) */ \
596  struct element { \
597  SOA_HOST_DEVICE SOA_INLINE \
598  element(size_type index, /* Declare parameters */ \
599  _ITERATE_ON_ALL_COMMA(_DECLARE_VIEW_ELEMENT_VALUE_ARG, BOOST_PP_EMPTY(), VALUE_LIST)) \
600  : _ITERATE_ON_ALL_COMMA(_DECLARE_VIEW_ELEM_MEMBER_INIT, index, VALUE_LIST) {} \
601  SOA_HOST_DEVICE SOA_INLINE \
602  element& operator=(const element& other) { \
603  _ITERATE_ON_ALL(_DECLARE_VIEW_ELEMENT_VALUE_COPY, ~, VALUE_LIST) \
604  return *this; \
605  }
606 // clang-format on
607 
608 // clang-format off
609 #define _GENERATE_SOA_VIEW_PART_2(CONST_VIEW, VIEW, LAYOUTS_LIST, VALUE_LIST) \
610  _ITERATE_ON_ALL(_DECLARE_VIEW_ELEMENT_VALUE_MEMBER, ~, VALUE_LIST) \
611  }; \
612  \
613  SOA_HOST_DEVICE SOA_INLINE \
614  element operator[](size_type index) { \
615  if constexpr (rangeChecking == cms::soa::RangeChecking::enabled) { \
616  if (index >= base_type::elements_) \
617  SOA_THROW_OUT_OF_RANGE("Out of range index in " #VIEW "::operator[]") \
618  } \
619  return element{index, _ITERATE_ON_ALL_COMMA(_DECLARE_VIEW_ELEMENT_CONSTR_CALL, ~, VALUE_LIST)}; \
620  } \
621  \
622  /* inherit const accessors from ConstView */ \
623  \
624  /* non-const accessors */ \
625  _ITERATE_ON_ALL(_DECLARE_VIEW_SOA_ACCESSOR, ~, VALUE_LIST) \
626  \
627  /* dump the SoA internal structure */ \
628  template <typename T> \
629  SOA_HOST_ONLY friend void dump(); \
630  };
631 // clang-format on
632 
633 /* ---- CONST VIEW -------------------------------------------------------------------------------------------------- */
634 // clang-format off
635 #define _GENERATE_SOA_CONST_VIEW_PART_0(CONST_VIEW, VIEW, LAYOUTS_LIST, VALUE_LIST) \
636  template <CMS_SOA_BYTE_SIZE_TYPE VIEW_ALIGNMENT = cms::soa::CacheLineSize::defaultSize, \
637  bool VIEW_ALIGNMENT_ENFORCEMENT = cms::soa::AlignmentEnforcement::relaxed, \
638  bool RESTRICT_QUALIFY = cms::soa::RestrictQualify::enabled, \
639  bool RANGE_CHECKING = cms::soa::RangeChecking::disabled> \
640  struct CONST_VIEW { \
641  /* these could be moved to an external type trait to free up the symbol names */ \
642  using self_type = CONST_VIEW;
643 // clang-format on
644 
645 // clang-format off
646 #define _GENERATE_SOA_CONST_VIEW_PART_0_NO_DEFAULTS(CONST_VIEW, VIEW, LAYOUTS_LIST, VALUE_LIST) \
647  template <CMS_SOA_BYTE_SIZE_TYPE VIEW_ALIGNMENT, \
648  bool VIEW_ALIGNMENT_ENFORCEMENT, \
649  bool RESTRICT_QUALIFY, \
650  bool RANGE_CHECKING> \
651  struct CONST_VIEW { \
652  /* these could be moved to an external type trait to free up the symbol names */ \
653  using self_type = CONST_VIEW;
654 // clang-format on
655 
660 // clang-format off
661 #define _GENERATE_SOA_CONST_VIEW_PART_1(CONST_VIEW, VIEW, LAYOUTS_LIST, VALUE_LIST) \
662  using size_type = cms::soa::size_type; \
663  using byte_size_type = cms::soa::byte_size_type; \
664  using AlignmentEnforcement = cms::soa::AlignmentEnforcement; \
665  \
666  template <CMS_SOA_BYTE_SIZE_TYPE, bool, bool, bool> \
667  friend struct VIEW; \
668  \
669  /* For CUDA applications, we align to the 128 bytes of the cache lines. \
670  * See https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#global-memory-3-0 this is still valid \
671  * up to compute capability 8.X. \
672  */ \
673  constexpr static byte_size_type defaultAlignment = cms::soa::CacheLineSize::defaultSize; \
674  constexpr static byte_size_type alignment = VIEW_ALIGNMENT; \
675  constexpr static bool alignmentEnforcement = VIEW_ALIGNMENT_ENFORCEMENT; \
676  constexpr static byte_size_type conditionalAlignment = \
677  alignmentEnforcement == AlignmentEnforcement::enforced ? alignment : 0; \
678  constexpr static bool restrictQualify = RESTRICT_QUALIFY; \
679  constexpr static bool rangeChecking = RANGE_CHECKING; \
680  /* Those typedefs avoid having commas in macros (which is problematic) */ \
681  template <cms::soa::SoAColumnType COLUMN_TYPE, class C> \
682  using SoAValueWithConf = cms::soa::SoAValue<COLUMN_TYPE, C, conditionalAlignment, restrictQualify>; \
683  \
684  template <cms::soa::SoAColumnType COLUMN_TYPE, class C> \
685  using SoAConstValueWithConf = cms::soa::SoAConstValue<COLUMN_TYPE, C, conditionalAlignment, restrictQualify>; \
686  \
687  \
690  struct Metadata { \
691  friend CONST_VIEW; \
692  SOA_HOST_DEVICE SOA_INLINE size_type size() const { return parent_.elements_; } \
693  /* Alias layout or view types to name-derived identifyer to allow simpler definitions */ \
694  _ITERATE_ON_ALL(_DECLARE_VIEW_LAYOUT_TYPE_ALIAS, ~, LAYOUTS_LIST) \
695  \
696  /* Alias member types to name-derived identifyer to allow simpler definitions */ \
697  _ITERATE_ON_ALL(_DECLARE_VIEW_MEMBER_TYPE_ALIAS, BOOST_PP_EMPTY(), VALUE_LIST) \
698  _ITERATE_ON_ALL(_DECLARE_VIEW_MEMBER_CONST_POINTERS, ~, VALUE_LIST) \
699  \
700  /* Forbid copying to avoid const correctness evasion */ \
701  Metadata& operator=(const Metadata&) = delete; \
702  Metadata(const Metadata&) = delete; \
703  \
704  private: \
705  SOA_HOST_DEVICE SOA_INLINE Metadata(const CONST_VIEW& parent) : parent_(parent) {} \
706  const CONST_VIEW& parent_; \
707  }; \
708  \
709  friend Metadata; \
710  SOA_HOST_DEVICE SOA_INLINE const Metadata metadata() const { return Metadata(*this); } \
711  \
712  /* Trivial constuctor */ \
713  CONST_VIEW() = default; \
714  \
715  /* Constructor relying on user provided layouts or views */ \
716  SOA_HOST_ONLY CONST_VIEW(_ITERATE_ON_ALL_COMMA(_DECLARE_VIEW_CONSTRUCTION_PARAMETERS, const, LAYOUTS_LIST)) \
717  : elements_([&]() -> size_type { \
718  bool set = false; \
719  size_type ret = 0; \
720  _ITERATE_ON_ALL(_UPDATE_SIZE_OF_VIEW, BOOST_PP_EMPTY(), LAYOUTS_LIST) \
721  return ret; \
722  }()), \
723  _ITERATE_ON_ALL_COMMA(_DECLARE_VIEW_MEMBER_INITIALIZERS, ~, VALUE_LIST) {} \
724  \
725  /* Constructor relying on individually provided column addresses */ \
726  SOA_HOST_ONLY CONST_VIEW(size_type elements, \
727  _ITERATE_ON_ALL_COMMA(_DECLARE_VIEW_CONSTRUCTION_BYCOLUMN_PARAMETERS, const, VALUE_LIST)) \
728  : elements_(elements), _ITERATE_ON_ALL_COMMA(_DECLARE_VIEW_MEMBER_INITIALIZERS_BYCOLUMN, ~, VALUE_LIST) {} \
729  \
730  /* Copiable */ \
731  CONST_VIEW(CONST_VIEW const&) = default; \
732  CONST_VIEW& operator=(CONST_VIEW const&) = default; \
733  \
734  /* Movable */ \
735  CONST_VIEW(CONST_VIEW &&) = default; \
736  CONST_VIEW& operator=(CONST_VIEW &&) = default; \
737  \
738  /* Trivial destuctor */ \
739  ~CONST_VIEW() = default; \
740  \
741  /* AoS-like accessor (const) */ \
742  struct const_element { \
743  SOA_HOST_DEVICE SOA_INLINE \
744  const_element(size_type index, /* Declare parameters */ \
745  _ITERATE_ON_ALL_COMMA(_DECLARE_CONST_VIEW_ELEMENT_VALUE_ARG, const, VALUE_LIST)) \
746  : _ITERATE_ON_ALL_COMMA(_DECLARE_VIEW_CONST_ELEM_MEMBER_INIT, index, VALUE_LIST) {} \
747  _ITERATE_ON_ALL(_DECLARE_VIEW_CONST_ELEMENT_ACCESSOR, ~, VALUE_LIST) \
748  \
749  private: \
750  _ITERATE_ON_ALL(_DECLARE_VIEW_CONST_ELEMENT_VALUE_MEMBER, ~, VALUE_LIST) \
751  }; \
752  \
753  SOA_HOST_DEVICE SOA_INLINE \
754  const_element operator[](size_type index) const { \
755  if constexpr (rangeChecking == cms::soa::RangeChecking::enabled) { \
756  if (index >= elements_) \
757  SOA_THROW_OUT_OF_RANGE("Out of range index in " #CONST_VIEW "::operator[]") \
758  } \
759  return const_element{index, _ITERATE_ON_ALL_COMMA(_DECLARE_VIEW_CONST_ELEMENT_CONSTR_CALL, ~, VALUE_LIST)}; \
760  } \
761  \
762  /* const accessors */ \
763  _ITERATE_ON_ALL(_DECLARE_VIEW_SOA_CONST_ACCESSOR, ~, VALUE_LIST) \
764  \
765  /* dump the SoA internal structure */ \
766  template <typename T> \
767  SOA_HOST_ONLY friend void dump(); \
768  \
769  private: \
770  size_type elements_ = 0; \
771  _ITERATE_ON_ALL(_DECLARE_CONST_VIEW_SOA_MEMBER, const, VALUE_LIST) \
772 };
773 // clang-format on
774 
775 // clang-format off
776 // MAJOR caveat: in order to propagate the LAYOUTS_LIST and VALUE_LIST
777 #define _GENERATE_SOA_CONST_VIEW(CONST_VIEW, VIEW, LAYOUTS_LIST, VALUE_LIST) \
778  _GENERATE_SOA_CONST_VIEW_PART_0(CONST_VIEW, VIEW, \
779  SOA_VIEW_LAYOUT_LIST(LAYOUTS_LIST), SOA_VIEW_VALUE_LIST(VALUE_LIST)) \
780  _GENERATE_SOA_CONST_VIEW_PART_1(CONST_VIEW, VIEW, \
781  SOA_VIEW_LAYOUT_LIST(LAYOUTS_LIST), SOA_VIEW_VALUE_LIST(VALUE_LIST))
782 
783 #define GENERATE_SOA_CONST_VIEW(CONST_VIEW, VIEW, LAYOUTS_LIST, VALUE_LIST) \
784  _GENERATE_SOA_CONST_VIEW(CONST_VIEW, BOOST_PP_CAT(CONST_VIEW, Unused_), \
785  SOA_VIEW_LAYOUT_LIST(LAYOUTS_LIST), SOA_VIEW_VALUE_LIST(VALUE_LIST))
786 
787 #define _GENERATE_SOA_TRIVIAL_CONST_VIEW(CLASS, LAYOUTS_LIST, VALUE_LIST) \
788  _GENERATE_SOA_CONST_VIEW_PART_0_NO_DEFAULTS(ConstViewTemplateFreeParams, ViewTemplateFreeParams, \
789  SOA_VIEW_LAYOUT_LIST(LAYOUTS_LIST), SOA_VIEW_VALUE_LIST(VALUE_LIST)) \
790  using BOOST_PP_CAT(CLASS, _parametrized) = CLASS<VIEW_ALIGNMENT, VIEW_ALIGNMENT_ENFORCEMENT>; \
791  _GENERATE_SOA_CONST_VIEW_PART_1(ConstViewTemplateFreeParams, ViewTemplateFreeParams, \
792  SOA_VIEW_LAYOUT_LIST(LAYOUTS_LIST), SOA_VIEW_VALUE_LIST(VALUE_LIST))
793 
794 #define _GENERATE_SOA_VIEW(CONST_VIEW, VIEW, LAYOUTS_LIST, VALUE_LIST) \
795  _GENERATE_SOA_VIEW_PART_0(CONST_VIEW, VIEW, SOA_VIEW_LAYOUT_LIST(LAYOUTS_LIST), SOA_VIEW_VALUE_LIST(VALUE_LIST)) \
796  _GENERATE_SOA_VIEW_PART_1(CONST_VIEW, VIEW, SOA_VIEW_LAYOUT_LIST(LAYOUTS_LIST), SOA_VIEW_VALUE_LIST(VALUE_LIST)) \
797  _GENERATE_SOA_VIEW_PART_2(CONST_VIEW, VIEW, SOA_VIEW_LAYOUT_LIST(LAYOUTS_LIST), SOA_VIEW_VALUE_LIST(VALUE_LIST))
798 
799 #define GENERATE_SOA_VIEW(CONST_VIEW, VIEW, LAYOUTS_LIST, VALUE_LIST) \
800  _GENERATE_SOA_CONST_VIEW(CONST_VIEW, VIEW, SOA_VIEW_LAYOUT_LIST(LAYOUTS_LIST), SOA_VIEW_VALUE_LIST(VALUE_LIST)) \
801  _GENERATE_SOA_VIEW(CONST_VIEW, VIEW, SOA_VIEW_LAYOUT_LIST(LAYOUTS_LIST), SOA_VIEW_VALUE_LIST(VALUE_LIST))
802 
803 #define _GENERATE_SOA_TRIVIAL_VIEW(CLASS, LAYOUTS_LIST, VALUE_LIST, ...) \
804  _GENERATE_SOA_VIEW_PART_0_NO_DEFAULTS(ConstViewTemplateFreeParams, ViewTemplateFreeParams, \
805  SOA_VIEW_LAYOUT_LIST(LAYOUTS_LIST), SOA_VIEW_VALUE_LIST(VALUE_LIST)) \
806  using BOOST_PP_CAT(CLASS, _parametrized) = CLASS<VIEW_ALIGNMENT, VIEW_ALIGNMENT_ENFORCEMENT>; \
807  _GENERATE_SOA_VIEW_PART_1(ConstViewTemplateFreeParams, ViewTemplateFreeParams, \
808  SOA_VIEW_LAYOUT_LIST(LAYOUTS_LIST), SOA_VIEW_VALUE_LIST(VALUE_LIST)) \
809  \
810  /* Extra operator=() for mutable element to emulate the aggregate initialisation syntax */ \
811  SOA_HOST_DEVICE SOA_INLINE constexpr element & operator=(const typename \
812  BOOST_PP_CAT(CLASS, _parametrized)::Metadata::value_element value) { \
813  _ITERATE_ON_ALL(_TRIVIAL_VIEW_ASSIGN_VALUE_ELEMENT, ~, __VA_ARGS__) \
814  return *this; \
815  } \
816  \
817  _GENERATE_SOA_VIEW_PART_2(ConstViewTemplateFreeParams, ViewTemplateFreeParams, \
818  SOA_VIEW_LAYOUT_LIST(LAYOUTS_LIST), SOA_VIEW_VALUE_LIST(VALUE_LIST))
819 // clang-format on
820 
824 #define _VIEW_FIELD_FROM_LAYOUT_IMPL(VALUE_TYPE, CPP_TYPE, NAME, DATA) (DATA, NAME, NAME)
825 
826 #define _VIEW_FIELD_FROM_LAYOUT(R, DATA, VALUE_TYPE_NAME) \
827  BOOST_PP_EXPAND((_VIEW_FIELD_FROM_LAYOUT_IMPL BOOST_PP_TUPLE_PUSH_BACK(VALUE_TYPE_NAME, DATA)))
828 
829 #endif // DataFormats_SoATemplate_interface_SoAView_h
cms_int32_t size_type
Definition: SoACommon.h:60
#define SOA_INLINE
Definition: SoACommon.h:28
#define SOA_HOST_DEVICE
Definition: SoACommon.h:27
SoAColumnType
Definition: SoACommon.h:64
double scalar(const CLHEP::HepGenMatrix &m)
Return the matrix as a scalar. Raise an assertion if the matris is not .
Definition: matutil.cc:166