diff --git a/DataFormats/SoATemplate/README.md b/DataFormats/SoATemplate/README.md index c2d7f14461ef7..9af697b0aa449 100644 --- a/DataFormats/SoATemplate/README.md +++ b/DataFormats/SoATemplate/README.md @@ -80,16 +80,14 @@ and `SOA_CONST_ELEMENT_METHODS` macros. Each of these macros can be called only `SoABlocks` is a macro-generated templated class that enables structured composition of multiple `SoALayouts` into a single container, referred to as "blocks". Each block is a Layout, and the structure itself looks like multiple contigous memory -buffers of different sizes. The alignment is ensured to be the same for every block. -`SoABlocks` also supports `View` and `ConstView` classes, mirroring the structure of the underlying structs. The blocks -are built via composition and access to individual layouts and views is provided by name. - -It is also possible to generate methods inside `View` and `ConstView` using the `SOA_VIEW_METHODS` and -`SOA_CONST_VIEW_METHODS` in the same way as described in [Customized methods](#customized-methods). +buffers of different sizes. The alignment is ensured to be the same for every block. `SoABlocks` also supports +`View` and `ConstView` classes. In addition to those fully parametrized templates, two further levels of parametrization are provided: +`ViewTemplate`, `ViewTemplateFreeParams` and respectively `ConstViewTemplate`, `ConstViewTemplateFreeParams`, +mirroring the structure of the underlying structs. The blocks are built via composition and access to individual layouts +and views is provided by name. TODOs: - Add introspection utilities to print the structure and layout of a `SoABlocks` instance. -- Extend support for fully templated `View`/`ConstView` classes beyond the default parameters. - Implement support for heterogeneous `deepCopy()` operations between different but compatible `SoABlocks` configurations. [An example of utilization is showed below.](#examples) diff --git a/DataFormats/SoATemplate/interface/SoABlocks.h b/DataFormats/SoATemplate/interface/SoABlocks.h index 3bb87da8a71cc..236f504014069 100644 --- a/DataFormats/SoATemplate/interface/SoABlocks.h +++ b/DataFormats/SoATemplate/interface/SoABlocks.h @@ -12,8 +12,8 @@ * Declare accessors for the View of each block */ #define _DECLARE_ACCESSORS_VIEW_BLOCKS_IMPL(VALUE_TYPE, NAME, LAYOUT_NAME) \ - SOA_HOST_DEVICE SOA_INLINE LAYOUT_NAME::View NAME() { \ - return LAYOUT_NAME::const_cast_View(base_type::BOOST_PP_CAT(NAME, View_)); \ + SOA_HOST_DEVICE SOA_INLINE ViewFor> NAME() { \ + return LayoutFor::const_cast_View(base_type::BOOST_PP_CAT(NAME, View_)); \ } #define _DECLARE_ACCESSORS_VIEW_BLOCKS(R, DATA, NAME) \ @@ -25,7 +25,7 @@ * Declare parameters for contructing the View of an SoA by blocks * using different views for each block */ -#define _DECLARE_VIEW_CONSTRUCTOR_BLOCKS_IMPL(VALUE_TYPE, NAME, LAYOUT_NAME) (LAYOUT_NAME::View NAME) +#define _DECLARE_VIEW_CONSTRUCTOR_BLOCKS_IMPL(VALUE_TYPE, NAME, LAYOUT_NAME) (ViewFor> NAME) #define _DECLARE_VIEW_CONSTRUCTOR_BLOCKS(R, DATA, NAME) \ BOOST_PP_IF(BOOST_PP_GREATER(BOOST_PP_TUPLE_ELEM(0, NAME), _VALUE_TYPE_BLOCK), \ @@ -61,8 +61,10 @@ /* * Declare accessors for the ConstView of each block */ -#define _DECLARE_ACCESSORS_CONST_VIEW_BLOCKS_IMPL(VALUE_TYPE, NAME, LAYOUT_NAME) \ - SOA_HOST_DEVICE SOA_INLINE const LAYOUT_NAME::ConstView NAME() const { return BOOST_PP_CAT(NAME, View_); } +#define _DECLARE_ACCESSORS_CONST_VIEW_BLOCKS_IMPL(VALUE_TYPE, NAME, LAYOUT_NAME) \ + SOA_HOST_DEVICE SOA_INLINE const ConstViewFor> NAME() const { \ + return BOOST_PP_CAT(NAME, View_); \ + } #define _DECLARE_ACCESSORS_CONST_VIEW_BLOCKS(R, DATA, NAME) \ BOOST_PP_IF(BOOST_PP_GREATER(BOOST_PP_TUPLE_ELEM(0, NAME), _VALUE_TYPE_BLOCK), \ @@ -85,7 +87,7 @@ * using different const views for each block */ #define _DECLARE_CONST_VIEW_CONSTRUCTOR_BLOCKS_IMPL(VALUE_TYPE, NAME, LAYOUT_NAME) \ - (LAYOUT_NAME::ConstView NAME) + (ConstViewFor> NAME) #define _DECLARE_CONST_VIEW_CONSTRUCTOR_BLOCKS(R, DATA, NAME) \ BOOST_PP_IF(BOOST_PP_GREATER(BOOST_PP_TUPLE_ELEM(0, NAME), _VALUE_TYPE_BLOCK), \ @@ -116,7 +118,7 @@ * Declare the data members for the ConstView of the SoA by blocks */ #define _DECLARE_MEMBERS_CONST_VIEW_BLOCKS_IMPL(VALUE_TYPE, NAME, LAYOUT_NAME) \ - LAYOUT_NAME::ConstView BOOST_PP_CAT(NAME, View_); + ConstViewFor> BOOST_PP_CAT(NAME, View_); #define _DECLARE_MEMBERS_CONST_VIEW_BLOCKS(R, DATA, NAME) \ BOOST_PP_IF(BOOST_PP_GREATER(BOOST_PP_TUPLE_ELEM(0, NAME), _VALUE_TYPE_BLOCK), \ @@ -127,7 +129,7 @@ * Declare accessors for the Layout of each block */ #define _DECLARE_LAYOUTS_ACCESSORS_IMPL(VALUE_TYPE, NAME, LAYOUT_NAME) \ - LAYOUT_NAME NAME() { return BOOST_PP_CAT(NAME, _); } + LayoutFor NAME() { return BOOST_PP_CAT(NAME, _); } #define _DECLARE_LAYOUTS_ACCESSORS(R, DATA, NAME) \ BOOST_PP_IF(BOOST_PP_GREATER(BOOST_PP_TUPLE_ELEM(0, NAME), _VALUE_TYPE_BLOCK), \ @@ -138,7 +140,7 @@ * Computation of the size for each block */ #define _ACCUMULATE_SOA_BLOCKS_SIZE_IMPL(VALUE_TYPE, NAME, LAYOUT_NAME) \ - _soa_impl_ret += LAYOUT_NAME::computeDataSize(sizes[index]); \ + _soa_impl_ret += LayoutFor::computeDataSize(sizes[index]); \ index++; #define _ACCUMULATE_SOA_BLOCKS_SIZE(R, DATA, NAME) \ @@ -150,8 +152,8 @@ * Computation of the block location in the memory layout (at SoA by blocks construction time) */ #define _DECLARE_MEMBER_CONSTRUCTION_BLOCKS_IMPL(VALUE_TYPE, NAME, LAYOUT_NAME) \ - BOOST_PP_CAT(NAME, _) = LAYOUT_NAME(mem + offset, sizes_[index]); \ - offset += LAYOUT_NAME::computeDataSize(sizes_[index]); \ + BOOST_PP_CAT(NAME, _) = LayoutFor(mem + offset, sizes_[index]); \ + offset += LayoutFor::computeDataSize(sizes_[index]); \ index++; #define _DECLARE_MEMBER_CONSTRUCTION_BLOCKS(R, DATA, NAME) \ @@ -247,7 +249,7 @@ BOOST_PP_EMPTY(), \ BOOST_PP_EXPAND(_ROOT_FREE_SOA_BLOCK_COLUMN_OR_SCALAR_IMPL NAME)) -#define _DECLARE_MEMBERS_BLOCKS_IMPL(VALUE_TYPE, NAME, LAYOUT_NAME) LAYOUT_NAME BOOST_PP_CAT(NAME, _); +#define _DECLARE_MEMBERS_BLOCKS_IMPL(VALUE_TYPE, NAME, LAYOUT_NAME) LayoutFor BOOST_PP_CAT(NAME, _); /* * Declare the data members for the SoA by blocks @@ -265,12 +267,19 @@ template \ struct CLASS { \ + template