All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
WithAssociatedStructBase.h
Go to the documentation of this file.
1 /**
2  * @file lardata/RecoBaseProxy/ProxyBase/WithAssociatedStructBase.h
3  * @brief Template class to declare addition of associated data to a proxy.
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date July 27, 2017
6  * @see lardata/RecoBaseProxy/ProxyBase.h
7  *
8  * This library is header-only.
9  */
10 
11 #ifndef LARDATA_RECOBASEPROXY_PROXYBASE_WITHASSOCIATEDSTRUCTBASE_H
12 #define LARDATA_RECOBASEPROXY_PROXYBASE_WITHASSOCIATEDSTRUCTBASE_H
13 
14 
15 // C/C++ standard
16 #include <tuple> // std::tuple_size(), std::get()
17 #include <utility> // std::forward(), std::move(), std::index_sequence<>...
18 #include <cstdlib> // std::size_t
19 
20 
21 /**
22  * @defgroup LArSoftProxiesAssociatedData Associated data infrastructure
23  * @ingroup LArSoftProxyCustom
24  * @brief Infrastructure for support of associated data.
25  *
26  * Associated data is auxiliary data connected to the main data via _art_
27  * associations.
28  * The following associated data are currently supported:
29  * * @ref LArSoftProxyDefinitionOneToManySeqAssn "one-to-many sequential association"
30  * implicitly supporting also one-to-any (one-to-one, one-to-zero/or/one) in
31  * a non-optimized way
32  * * @ref LArSoftProxyDefinitionOneToZeroOrOneSeqAssn "one-to-(zero-or-one) sequential association"
33  * * @ref LArSoftProxyDefinitionParallelData "parallel data product", implicit
34  * one-to-one associations
35  *
36  */
37 
38 
39 namespace proxy {
40 
41  //----------------------------------------------------------------------------
42  namespace details {
43 
44  //--------------------------------------------------------------------------
45  /**
46  * @brief Helper to create associated data proxy.
47  * @tparam Aux type of data associated to the main one
48  * @tparam Metadata type of metadata of the association
49  * @tparam ArgTuple type of arguments required for the creation of proxy
50  * @tparam ProxyMaker template type of the proxy maker class
51  * @tparam AuxTag tag for the associated data (default: as `Aux`)
52  *
53  * This class stores user arguments for the construction of a proxy to
54  * associated data of type `Aux`.
55  * It can use that information plus some additional one to create the
56  * associated data itself. This additional information is provided by
57  * `getCollection()`.
58  *
59  * The association will be identified by type `AuxTag`.
60  *
61  * This is not a customization point: to have a custom associated data
62  * produced, choose and then specialize the `ProxyMaker` class.
63  */
64  template <
65  typename Aux,
66  typename Metadata,
67  typename ArgTuple,
68  template <typename CollProxy> class ProxyMaker,
69  typename AuxTag /* = Aux */
70  >
72 
73  /// Type of main data product element from a proxy of type `CollProxy`.
74  template <typename CollProxy>
75  using main_t = typename CollProxy::main_element_t;
76 
77  /// Type of associated data.
78  using aux_t = Aux;
79 
80  /// Type of associated metadata.
81  using metadata_t = Metadata;
82 
83  /// Tag for the associated data (same as the data type itself).
84  using tag = AuxTag;
85 
86  /// Class to create the data proxy associated to a `CollProxy`.
87  template <typename CollProxy>
88  using proxy_maker_t = ProxyMaker<CollProxy>;
89 
90  public:
91 
92  /// Type of association proxy created for the specified `CollProxy`.
93  template <typename CollProxy>
96 
97  /// Constructor: steals the arguments, to be used by
98  /// `createAuxProxyMaker()`.
99  WithAssociatedStructBase(ArgTuple&& args): args(std::move(args)) {}
100 
101  /// Creates the associated data proxy by means of `ProxyMaker`.
102  template
103  <typename CollProxy, typename Event, typename Handle, typename MainArgs>
105  (Event const& event, Handle&& mainHandle, MainArgs const& mainArgs)
106  {
107  return createAssnProxyMaker<CollProxy>(
108  event, std::forward<Handle>(mainHandle), mainArgs,
109  std::make_index_sequence<NArgs>()
110  );
111  } // construct()
112 
113 
114  protected:
115 
116  ArgTuple args; ///< Argument construction storage as tuple.
117 
118  /// Number of arguments stored.
119  static constexpr std::size_t NArgs = std::tuple_size<ArgTuple>();
120 
121  // this method allows unpacking the arguments from the tuple
122  template<
123  typename CollProxy, typename Event, typename Handle, typename MainArgs,
124  std::size_t... I
125  >
127  Event const& event, Handle&& mainHandle, MainArgs const& mainArgs,
128  std::index_sequence<I...>
129  )
130  {
132  event, mainHandle, mainArgs,
133  std::get<I>(std::forward<ArgTuple>(args))...
134  );
135  }
136 
137  }; // struct WithAssociatedStructBase<>
138 
139 
140  //--------------------------------------------------------------------------
141 
142  } // namespace details
143 
144 } // namespace proxy
145 
146 
147 #endif // LARDATA_RECOBASEPROXY_PROXYBASE_WITHASSOCIATEDSTRUCTBASE_H
ProxyMaker< CollProxy > proxy_maker_t
Class to create the data proxy associated to a CollProxy.
auto createAssnProxyMaker(Event const &event, Handle &&mainHandle, MainArgs const &mainArgs, std::index_sequence< I...>)
see a below echo or echo I(indirect symbol).'echo" If the symbol is local (non-external)
typename proxy_maker_t< CollProxy >::aux_collection_proxy_t aux_collection_proxy_t
Type of association proxy created for the specified CollProxy.
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
Helper to create associated data proxy.
AuxTag tag
Tag for the associated data (same as the data type itself).
ArgTuple args
Argument construction storage as tuple.
static constexpr std::size_t NArgs
Number of arguments stored.
Metadata metadata_t
Type of associated metadata.
typename CollProxy::main_element_t main_t
Type of main data product element from a proxy of type CollProxy.
auto createAuxProxyMaker(Event const &event, Handle &&mainHandle, MainArgs const &mainArgs)
Creates the associated data proxy by means of ProxyMaker.