LArSoft  v06_85_00
Liquid Argon Software toolkit - http://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 "lardata/Utilities/TupleLookupByTag.h" // util::makeTagged(), ...
16 #include "larcorealg/CoreUtils/ContainerMeta.h" // util::collection_value_t, ...
17 
18 // C/C++ standard
19 #include <utility> // std::declval()
20 #include <type_traits> // std::is_convertible<>, ...
21 #include <cstdlib> // std::size_t
22 
23 
24 
25 namespace proxy {
26 
27  // --- BEGIN LArSoftProxiesParallelData --------------------------------------
30 
54  template <
55  typename AuxColl,
56  typename Aux = util::collection_value_t<AuxColl>,
57  typename Tag = Aux
58  >
59  auto makeParallelData(AuxColl const& data);
60 
61 
62  //----------------------------------------------------------------------------
63  namespace details {
64 
77  template <
78  typename AuxColl,
79  typename Aux /* = util::collection_value_t<AuxColl> */,
80  typename Tag /* = Aux */
81  >
82  class ParallelData {
84 
86  using parallel_data_t = AuxColl;
87 
89  using aux_t = Aux; // unused
90 
93 
95 
96  public:
97  using tag = Tag;
98 
100  using auxiliary_data_t
101  = decltype(util::makeTagged<tag>(std::declval<aux_element_t>()));
102 
105  : fData(&data)
106  {}
107 
109  auto begin() const -> decltype(auto)
110  { return fData->begin(); }
111 
113  auto end() const -> decltype(auto)
114  { return fData->end(); }
115 
117  auto operator[] (std::size_t index) const -> decltype(auto)
118  {
119  static_assert(
120  std::is_convertible<decltype(getElement(index)), auxiliary_data_t>(),
121  "Inconsistent data types."
122  );
123  return getElement(index);
124  }
125 
127  template <typename TestTag>
128  static constexpr bool hasTag() { return std::is_same<TestTag, tag>(); }
129 
131  parallel_data_t const* data() const { return fData; }
132 
134  parallel_data_t const& dataRef() const { return *(data()); }
135 
136  private:
137 
139 
140  auto getElement(std::size_t index) const -> decltype(auto)
141  { return util::makeTagged<tag>(fData->operator[](index)); }
142 
143  }; // class ParallelData<>
144 
145 
146  //--------------------------------------------------------------------------
147 
148  } // namespace details
149 
150 
152  // --- END LArSoftProxiesParallelData ----------------------------------------
153 
154 } // namespace proxy
155 
156 
157 //------------------------------------------------------------------------------
158 //--- template implementation
159 //------------------------------------------------------------------------------
160 namespace proxy {
161 
162  //----------------------------------------------------------------------------
163  //--- makeParallelData() implementations
164  //----------------------------------------------------------------------------
165  template <
166  typename AuxColl,
167  typename Aux /* = util::collection_value_t<AuxColl>*/,
168  typename Tag /* = Aux */
169  >
170  auto makeParallelData(AuxColl const& data) {
171 
172  // Ahh, simplicity.
174 
175  } // makeParallelData(AuxColl)
176 
177 
178  //----------------------------------------------------------------------------
179 
180 } // namespace proxy
181 
182 
183 #endif // LARDATA_RECOBASEPROXY_PROXYBASE_PARALLELDATA_H
auto operator[](std::size_t index) const -> decltype(auto)
Returns the element with the specified index (no check performed).
Definition: ParallelData.h:117
Object to draft parallel data interface.
Definition: ParallelData.h:82
parallel_data_t const * data() const
Returns a pointer to the whole data collection.
Definition: ParallelData.h:131
parallel_data_t const * fData
Reference to the original data product.
Definition: ParallelData.h:138
util::collection_value_constant_access_t< AuxProxyColl > aux_element_t
Type returned when accessing an auxiliary collection element.
Definition: ParallelData.h:92
static constexpr bool hasTag()
Returns whether this data is labeled with the specified tag.
Definition: ParallelData.h:128
AuxColl parallel_data_t
Type of auxiliary collection.
Definition: ParallelData.h:86
auto begin() const -> decltype(auto)
Returns an iterator pointing to the first data element.
Definition: ParallelData.h:109
intermediate_table::const_iterator const_iterator
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:170
parallel_data_t const & dataRef() const
Returns a reference to the whole data collection.
Definition: ParallelData.h:134
Aux aux_t
Type of the value of auxiliary collection element.
Definition: ParallelData.h:89
ParallelData(parallel_data_t const &data)
Constructor: points to the specified data collection.
Definition: ParallelData.h:104
Utilities to address elements of a tuple-like class by tag.
auto getElement(std::size_t index) const -> decltype(auto)
Definition: ParallelData.h:140
decltype(util::makeTagged< tag >(std::declval< aux_element_t >())) auxiliary_data_t
Type returned when accessing auxiliary data.
Definition: ParallelData.h:101
typename parallel_data_t::const_iterator parallel_data_iterator_t
Definition: ParallelData.h:94
typename collection_value_type< Coll >::type collection_value_t
Type contained in the collection Coll.
Definition: ContainerMeta.h:65
C++ metaprogramming utilities for dealing with containers.
typename collection_value_constant_access_type< Coll >::type collection_value_constant_access_t
Type obtained by constant access to element of collection Coll.
auto end() const -> decltype(auto)
Returns an iterator pointing past the last data element.
Definition: ParallelData.h:113