WithProxyAsAuxStructBase.h
Go to the documentation of this file.
1 /**
2  * @file lardata/RecoBaseProxy/ProxyBase/WithProxyAsAuxStructBase.h
3  * @brief Infrastructure for a collection proxy as auxiliary data for a proxy.
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date July 27, 2017
6  * @see lardata/RecoBaseProxy/ProxyBase/withCollectionProxy.h
7  *
8  * This library is header-only.
9  */
10 
11 #ifndef LARDATA_RECOBASEPROXY_PROXYBASE_WITHPROXYASAUXSTRUCTBASE_H
12 #define LARDATA_RECOBASEPROXY_PROXYBASE_WITHPROXYASAUXSTRUCTBASE_H
13 
14 // LArSoft libraries
16 
17 // framework libraries
19 
20 // C/C++ standard
21 #include <tuple> // std::tuple_element_t<>, std::get(), ...
22 #include <utility> // std::forward(), std::move(), std::make_index_sequence()...
23 #include <type_traits> // std::is_convertible<>, std::decay_t<>, ...
24 #include <cstdlib> // std::size_t
25 
26 
27 namespace proxy {
28 
29  namespace details {
30 
31  /// --- BEGIN LArSoftProxiesAuxProxy ---------------------------------------
32  /// @addtogroup LArSoftProxiesAuxProxy
33  /// @{
34 
35  //--------------------------------------------------------------------------
36  /**
37  * @brief Helper to create a proxy as auxiliary data for another proxy.
38  * @tparam AuxProxy type of collection proxy associated to the main one
39  * @tparam ArgTuple type of arguments required for the creation of proxy
40  * @tparam AuxTag tag for the associated data (default: as `Aux`)
41  *
42  * This class stores user arguments for the construction of a collection
43  * proxy to be used as auxiliary data for another proxy.
44  * It can use those arguments plus some additional one to create the
45  * collection proxy data itself. This additional information is provided by
46  * `getCollection()`.
47  *
48  * The auxiliary data will be identified by type `AuxTag`.
49  *
50  * This is not a customization point: to have a custom associated data
51  * produced, choose and then specialize the `ProxyAsAuxProxyMaker` class.
52  */
53  template <
54  typename AuxProxy,
55  typename ArgTuple,
56  typename AuxTag = AuxProxy
57  >
59 
60  static_assert(
61  std::is_convertible
62  <std::decay_t<std::tuple_element_t<0U, ArgTuple>>, art::InputTag>(),
63  "The first argument of WithProxyAsAuxStructBase must be art::InputTag."
64  );
65 
66  /// Type of main data product element from a proxy of type `CollProxy`.
67  template <typename CollProxy>
68  using main_t = typename CollProxy::main_element_t;
69 
70  /// Type of auxiliary proxy.
71  using aux_proxy_t = AuxProxy;
72 
73  /// Tag for the associated data (same as the data type itself).
74  using tag = AuxTag;
75 
76  /// Class to create the data proxy associated to a `CollProxy`.
77  template <typename CollProxy>
78  using proxy_maker_t
80 
81  public:
82 
83  /// Constructor: steals the arguments, to be used by
84  /// `createAuxProxyMaker()`.
86 
87  /// Creates the associated data proxy by means of `ProxyAsAuxProxyMaker`.
88  template
89  <typename CollProxy, typename Event, typename Handle, typename MainArgs>
91  (Event const& event, Handle&& mainHandle, MainArgs const& mainArgs)
92  {
93  return createAuxProxyImpl<CollProxy>(
94  event, std::forward<Handle>(mainHandle), mainArgs,
95  std::make_index_sequence<NArgs>()
96  );
97  } // construct()
98 
99 
100  protected:
101 
102  ArgTuple args; ///< Argument construction storage as tuple.
103 
104  /// Number of arguments stored.
105  static constexpr std::size_t NArgs = std::tuple_size<ArgTuple>();
106 
107  // this method allows unpacking the arguments from the tuple
108  template<
109  typename CollProxy, typename Event, typename Handle, typename MainArgs,
110  std::size_t... I
111  >
113  Event const& event, Handle&& mainHandle, MainArgs const& mainArgs,
114  std::index_sequence<I...>
115  )
116  {
118  event, mainHandle, mainArgs,
119  std::get<I>(std::forward<ArgTuple>(args))...
120  );
121  }
122 
123  }; // struct WithProxyAsAuxStructBase
124 
125 
126  /// @}
127  /// --- END LArSoftProxiesAuxProxy -----------------------------------------
128 
129  } // namespace details
130 
131 } // namespace proxy
132 
133 
134 #endif // LARDATA_RECOBASEPROXY_PROXYBASE_WITHPROXYASAUXSTRUCTBASE_H
AuxProxy aux_proxy_t
Type of auxiliary proxy.
static constexpr std::size_t NArgs
Number of arguments stored.
auto createAuxProxyMaker(Event const &event, Handle &&mainHandle, MainArgs const &mainArgs)
Creates the associated data proxy by means of ProxyAsAuxProxyMaker.
ArgTuple args
Argument construction storage as tuple.
STL namespace.
auto createAuxProxyImpl(Event const &event, Handle &&mainHandle, MainArgs const &mainArgs, std::index_sequence< I... >)
typename CollProxy::main_element_t main_t
Type of main data product element from a proxy of type CollProxy.
def move(depos, offset)
Definition: depos.py:107
Creates an auxiliary proxy wrapper for the specified proxy.
Infrastructure for a collection proxy as auxiliary data for a proxy.
static auto make(Event const &event, Handle &&, MainArgs const &, art::InputTag const &auxProxyTag, AuxArgs &&...args)
Create a parallel data proxy collection using the specified tag.
Definition: types.h:32
Helper to create a proxy as auxiliary data for another proxy.
Event finding and building.