All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
makeParallelDataFrom.h
Go to the documentation of this file.
1 /**
2  * @file lardata/RecoBaseProxy/ProxyBase/makeParallelDataFrom.h
3  * @brief Helper functions to create `proxy::ParallelData` objects.
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date July 27, 2017
6  * @see lardata/RecoBaseProxy/ProxyBase/withParallelData.h
7  *
8  * This library is header-only.
9  */
10 
11 #ifndef LARDATA_RECOBASEPROXY_PROXYBASE_MAKEPARALLELDATAFROM_H
12 #define LARDATA_RECOBASEPROXY_PROXYBASE_MAKEPARALLELDATAFROM_H
13 
14 // LArSoft libraries
16 #include "larcorealg/CoreUtils/ContainerMeta.h" // util::collection_value_t, ...
17 
18 // framework libraries
19 #include "canvas/Utilities/InputTag.h"
20 
21 
22 
23 namespace proxy {
24 
25 
26  // -- BEGIN Parallel data infrastructure -------------------------------------
27  /// @addtogroup LArSoftProxiesParallelData
28  /// @{
29 
30  /**
31  * @brief Wraps a collection into a parallel data collection object.
32  * @tparam AuxColl type of parallel data data product container
33  * @tparam Aux type of parallel data to be associated to the main objects
34  * (if omitted: `AuxColl::value_type`)
35  * @tparam Tag the tag labelling this associated data (if omitted: as `Aux`)
36  * @param data data collection to be wrapped
37  * @return a new `ParallelData` wrapping the information in `data`
38  *
39  * The data collection must be non-temporary and it is treated as fulfilling
40  * @ref LArSoftProxyDefinitionParallelData "parallel data product"
41  * requirements.
42  *
43  * Example:
44  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
45  * std::vector<recob::TrackFitHitInfo> trackData;
46  * // ...
47  * auto auxData = makeParallelDataFrom(trackData);
48  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
49  * where the tag of the parallel data is now `recob::TrackFitHitInfo` and
50  * `auxData` behaviour becomes undefined as soon as `trackData` falls out of
51  * scope.
52  */
53  template <
54  typename AuxColl,
55  typename Aux = util::collection_value_t<AuxColl>,
56  typename Tag = Aux
57  >
58  auto makeParallelDataFrom(AuxColl const& data)
59  { return proxy::makeParallelData<AuxColl, Aux, Tag>(data); }
60 
61 
62  /**
63  * @brief Creates and returns a parallel data collection object.
64  * @tparam AuxColl type of parallel data data product container
65  * @tparam Aux type of parallel data to be associated to the main objects
66  * (if omitted: `AuxColl::value_type`)
67  * @tparam Tag the tag labelling this associated data (if omitted: as `Aux`)
68  * @tparam Event type of event to read the data product from
69  * @param event event to read the data product from
70  * @param tag input tag of the parallel data product
71  * @return a new `ParallelData` filled with data from `tag`
72  *
73  * The data product being retrieved must fulfill the requirements of
74  * @ref LArSoftProxyDefinitionParallelData "parallel data product".
75  *
76  * At least one template type must be explicitly specified, e.g.
77  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
78  * auto auxData
79  * = makeParallelDataFrom<std::vector<recob::TrackFitHitInfo>>(event, tag);
80  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
81  * In this case, the `Aux` type is defined as `recob::TrackFitHitInfo`, as is
82  * the tag.
83  */
84  template <typename AuxColl, typename Aux, typename Tag, typename Event>
85  auto makeParallelDataFrom(Event const& event, art::InputTag const& tag);
86 
87  template <typename AuxColl, typename Aux, typename Event>
88  auto makeParallelDataFrom(Event const& event, art::InputTag const& tag)
89  { return makeParallelDataFrom<AuxColl, Aux, Aux, Event>(event, tag); }
90 
91  template <typename AuxColl, typename Event>
92  auto makeParallelDataFrom(Event const& event, art::InputTag const& tag)
93  {
94  return
95  makeParallelDataFrom<AuxColl, util::collection_value_t<AuxColl>, Event>
96  (event, tag);
97  }
98 
99 
100  /// @}
101  // -- END Parallel data infrastructure ---------------------------------------
102 
103 
104 } // namespace proxy
105 
106 
107 //------------------------------------------------------------------------------
108 //--- template implementation
109 //------------------------------------------------------------------------------
110 namespace proxy {
111 
112  //----------------------------------------------------------------------------
113  //--- makeParallelDataFrom() implementations
114  //----------------------------------------------------------------------------
115  template <typename AuxColl, typename Aux, typename Tag, typename Event>
116  auto makeParallelDataFrom(Event const& event, art::InputTag const& tag) {
117  return makeParallelDataFrom<AuxColl, Aux, Tag>
118  (*(event.template getValidHandle<AuxColl>(tag)));
119  } // makeParallelDataFrom()
120 
121 } // namespace proxy
122 
123 
124 #endif // LARDATA_RECOBASEPROXY_PROXYBASE_MAKEPARALLELDATAFROM_H
Auxiliary data from parallel data products.
auto makeParallelDataFrom(AuxColl const &data)
Wraps a collection into a parallel data collection object.
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.