LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
ParallelData.h
Go to the documentation of this file.
1 
11 #ifndef LARDATA_RECOBASEPROXY_PROXYBASE_PARALLELDATA_H
12 #define LARDATA_RECOBASEPROXY_PROXYBASE_PARALLELDATA_H
13 
14 // LArSoft libraries
15 #include "larcorealg/CoreUtils/ContainerMeta.h" // util::collection_value_t, ...
16 #include "lardata/Utilities/TupleLookupByTag.h" // util::makeTagged(), ...
17 
18 // C/C++ standard
19 #include <cstdlib> // std::size_t
20 #include <type_traits> // std::is_convertible<>, ...
21 #include <utility> // std::declval()
22 
23 namespace proxy {
24 
25  // --- BEGIN LArSoftProxiesParallelData --------------------------------------
28 
52  template <typename AuxColl, typename Aux = util::collection_value_t<AuxColl>, typename Tag = Aux>
53  auto makeParallelData(AuxColl const& data);
54 
55  //----------------------------------------------------------------------------
56  namespace details {
57 
70  template <typename AuxColl,
71  typename Aux /* = util::collection_value_t<AuxColl> */,
72  typename Tag /* = Aux */
73  >
74  class ParallelData {
76 
78  using parallel_data_t = AuxColl;
79 
81  using aux_t = Aux; // unused
82 
85 
87 
88  public:
89  using tag = Tag;
90 
92  using auxiliary_data_t = decltype(util::makeTagged<tag>(std::declval<aux_element_t>()));
93 
95  ParallelData(parallel_data_t const& data) : fData(&data) {}
96 
98  auto begin() const -> decltype(auto) { return fData->begin(); }
99 
101  auto end() const -> decltype(auto) { return fData->end(); }
102 
104  auto operator[](std::size_t index) const -> decltype(auto)
105  {
106  static_assert(std::is_convertible<decltype(getElement(index)), auxiliary_data_t>(),
107  "Inconsistent data types.");
108  return getElement(index);
109  }
110 
112  template <typename TestTag>
113  static constexpr bool hasTag()
114  {
115  return std::is_same<TestTag, tag>();
116  }
117 
119  parallel_data_t const* data() const { return fData; }
120 
122  parallel_data_t const& dataRef() const { return *(data()); }
123 
124  private:
126 
127  auto getElement(std::size_t index) const -> decltype(auto)
128  {
129  return util::makeTagged<tag>(fData->operator[](index));
130  }
131 
132  }; // class ParallelData<>
133 
134  //--------------------------------------------------------------------------
135 
136  } // namespace details
137 
139  // --- END LArSoftProxiesParallelData ----------------------------------------
140 
141 } // namespace proxy
142 
143 //------------------------------------------------------------------------------
144 //--- template implementation
145 //------------------------------------------------------------------------------
146 namespace proxy {
147 
148  //----------------------------------------------------------------------------
149  //--- makeParallelData() implementations
150  //----------------------------------------------------------------------------
151  template <typename AuxColl,
152  typename Aux /* = util::collection_value_t<AuxColl>*/,
153  typename Tag /* = Aux */
154  >
155  auto makeParallelData(AuxColl const& data)
156  {
157 
158  // Ahh, simplicity.
160 
161  } // makeParallelData(AuxColl)
162 
163  //----------------------------------------------------------------------------
164 
165 } // namespace proxy
166 
167 #endif // LARDATA_RECOBASEPROXY_PROXYBASE_PARALLELDATA_H
Object to draft parallel data interface.
Definition: ParallelData.h:74
auto begin() const -> decltype(auto)
Returns an iterator pointing to the first data element.
Definition: ParallelData.h:98
parallel_data_t const * data() const
Returns a pointer to the whole data collection.
Definition: ParallelData.h:119
parallel_data_t const * fData
Reference to the original data product.
Definition: ParallelData.h:125
util::collection_value_constant_access_t< AuxProxyColl > aux_element_t
Type returned when accessing an auxiliary collection element.
Definition: ParallelData.h:84
static constexpr bool hasTag()
Returns whether this data is labeled with the specified tag.
Definition: ParallelData.h:113
auto operator[](std::size_t index) const -> decltype(auto)
Returns the element with the specified index (no check performed).
Definition: ParallelData.h:104
intermediate_table::const_iterator const_iterator
AuxColl parallel_data_t
Type of auxiliary collection.
Definition: ParallelData.h:78
Encloses LArSoft data product proxy objects and utilities.See this doxygen module for an introduction...
auto makeParallelData(AuxColl const &data)
Wraps a collection into a parallel data collection object.
Definition: ParallelData.h:155
parallel_data_t const & dataRef() const
Returns a reference to the whole data collection.
Definition: ParallelData.h:122
auto end() const -> decltype(auto)
Returns an iterator pointing past the last data element.
Definition: ParallelData.h:101
Aux aux_t
Type of the value of auxiliary collection element.
Definition: ParallelData.h:81
ParallelData(parallel_data_t const &data)
Constructor: points to the specified data collection.
Definition: ParallelData.h:95
Utilities to address elements of a tuple-like class by tag.
decltype(util::makeTagged< tag >(std::declval< aux_element_t >())) auxiliary_data_t
Type returned when accessing auxiliary data.
Definition: ParallelData.h:92
typename parallel_data_t::const_iterator parallel_data_iterator_t
Definition: ParallelData.h:86
C++ metaprogramming utilities for dealing with containers.
auto getElement(std::size_t index) const -> decltype(auto)
Definition: ParallelData.h:127
typename collection_value_constant_access_type< Coll >::type collection_value_constant_access_t
Type obtained by constant access to element of collection Coll.
Definition: ContainerMeta.h:81