All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ProxyAsAuxProxyMaker.h
Go to the documentation of this file.
1 /**
2  * @file lardata/RecoBaseProxy/ProxyBase/ProxyAsAuxProxyMaker.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_PROXYASAUXPROXYMAKER_H
12 #define LARDATA_RECOBASEPROXY_PROXYBASE_PROXYASAUXPROXYMAKER_H
13 
14 // LArSoft libraries
17 #include "larcorealg/CoreUtils/ContainerMeta.h" // util::collection_value_t, ...
18 
19 // framework libraries
20 #include "canvas/Utilities/InputTag.h"
21 
22 // C/C++ standard
23 #include <utility> // std::forward(), std::move()
24 
25 
26 namespace proxy {
27 
28  /// --- BEGIN LArSoftProxiesAuxProxy -----------------------------------------
29  /// @addtogroup LArSoftProxiesAuxProxy
30  /// @{
31 
32  /**
33  * @brief Creates a proxy wrapper for merging into another proxy ("main").
34  * @tparam Main type of main datum (element) of the main proxy
35  * @tparam AuxProxy type ("proxy name") of the proxy being wrapped
36  * @tparam AuxTag tag of the auxiliary proxy in the context of the main one
37  *
38  * By default, `AuxTag` is the same as the proxy name.
39  *
40  * This class works as a base class for `ProxyAsAuxProxyMaker` so that
41  * the specializations of the latter can still inherit from this one if they
42  * its facilities.
43  */
44  template <
45  typename Main,
46  typename AuxProxy,
47  typename AuxTag = AuxProxy
48  >
50 
51  /// Tag labelling the associated data we are going to produce.
52  using data_tag = AuxTag;
53 
54  /// Type of the main datum.
55  using main_element_t = Main;
56 
57  /// Tag-type of the auxiliary proxy (not the type of the proxy!).
58  using aux_proxy_t = AuxProxy;
59 
60  /**
61  * @brief Create a parallel data proxy collection using the specified tag.
62  * @tparam Event type of the event to read data from
63  * @tparam Handle (_unused_) type of handle to the main data product
64  * @tparam MainArgs (_unused_) any type convertible to `art::InputTag`
65  * @tparam AuxArgs type of arguments for the creation of the auxiliary proxy
66  * @param event event to create the proxy from
67  * @param auxProxyTag tag for the creation of the auxiliary collection proxy
68  * @param args other arguments for the creation of the auxiliary proxy
69  * @return a auxiliary proxy data object
70  *
71  * The returned object exposes a random access container interface, with
72  * data indexed by the index of the corresponding object in the main
73  * collection.
74  *
75  * The tag of the main collection proxy is ignored even if present, and
76  * the caller must specify it.
77  */
78  template
79  <typename Event, typename Handle, typename MainArgs, typename... AuxArgs>
80  static auto make(
81  Event const& event, Handle&&, MainArgs const&,
82  art::InputTag const& auxProxyTag, AuxArgs&&... args
83  )
84  {
85  auto auxProxy = makeAuxiliaryProxy
86  (event, auxProxyTag, std::forward<AuxArgs>(args)...);
89  (std::move(auxProxy));
90  }
91 
92 
93  private:
94 
95  /// Creates the proxy to be used as parallel data.
96  template <typename Event, typename... AuxArgs>
97  static auto makeAuxiliaryProxy(
98  Event const& event,
99  art::InputTag const& auxProxyTag,
100  AuxArgs&&... args
101  )
102  {
103  return getCollection<aux_proxy_t>
104  (event, auxProxyTag, std::forward<AuxArgs>(args)...);
105  }
106 
107 
108  }; // struct ProxyAsAuxProxyMakerBase<>
109 
110 
111  //--------------------------------------------------------------------------
112  /**
113  * @brief Creates an auxiliary proxy wrapper for the specified proxy.
114  * @tparam Main type of main datum (element) to associate from ("left")
115  * @tparam AuxProxy type of proxy collection to be associated
116  * @tparam CollProxy type of proxy this associated data works for
117  * @tparam Tag tag for the association proxy to be created
118  * @see `withCollectionProxy()`
119  *
120  * This class is (indirectly) called when using `proxy::withCollectionProxy()`
121  * in `getCollection()`.
122  * Its task is to supervise the creation of the collection proxy that is used
123  * as auxiliary data for the main data type.
124  * The interface required by `withCollectionProxy()` includes:
125  * * a static `make()` method creating and returning the auxiliary data
126  * proxy with arguments an event, the main data product handle, a template
127  * argument representing the main collection information, and all the
128  * arguments required for the creation of the auxiliary collection proxy
129  * (coming from `withCollectionProxy()`); equivalent to the signature:
130  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
131  * template <typename Event, typename Handle, typename MainArg, typename... Args>
132  * auto make(Event const&, Handle&&, MainArg const&, Args&&...);
133  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
134  *
135  * This class can be specialized.
136  * The default implementation just uses `getCollection()` to create the
137  * auxiliary proxy, and merges it to the main collection proxy in a fashion
138  * similar to parallel data.
139  *
140  * The template argument `CollProxy` is designed for specialization of
141  * auxiliary data in the context of a specific proxy type.
142  */
143  template <
144  typename Main,
145  typename AuxProxy,
146  typename CollProxy,
148  >
150  : public ProxyAsAuxProxyMakerBase<Main, AuxProxy, Tag>
151  {};
152 
153 
154  /// @}
155  /// --- END LArSoftProxiesAuxProxy -------------------------------------------
156 
157 
158 } // namespace proxy
159 
160 
161 #endif // LARDATA_RECOBASEPROXY_PROXYBASE_PROXYASAUXPROXYMAKER_H
Tag data_tag
Tag labelling the associated data we are going to produce.
AuxProxy aux_proxy_t
Tag-type of the auxiliary proxy (not the type of the proxy!).
static auto makeAuxiliaryProxy(Event const &event, art::InputTag const &auxProxyTag, AuxArgs &&...args)
Creates the proxy to be used as parallel data.
Creates an auxiliary proxy wrapper for the specified proxy.
Data encapsulating a collection proxy as auxiliary data.
Creates a proxy wrapper for merging into another proxy (&quot;main&quot;).
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.
Creation of a collection proxy.
auto makeProxyAsParallelData(AuxProxyColl &&auxProxy)
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.