ClusterParamsImportWrapper.h
Go to the documentation of this file.
1 /** ****************************************************************************
2  * @file ClusterParamsImportWrapper.h
3  * @brief Wrapper for ClusterParamsAlgBase objects to accept arbitrary input
4  * @author petrillo@fnal.gov
5  * @date January 22, 2015
6  * @see ClusterParamsAlgBase.h
7  *
8  * ****************************************************************************/
9 
10 #ifndef CLUSTERPARAMSARTWRAPPER_H
11 #define CLUSTERPARAMSARTWRAPPER_H
12 
13 // C/C++ standard libraries
14 #include <stdexcept> // std::logic_error
15 #include <utility> // std::forward()
16 
17 // LArSoft libraries
18 #include "lardata/Utilities/Dereference.h" // util::make_pointer()
19 
20 namespace util {
21  class GeometryUtilities;
22 }
23 
24 namespace recob {
25  class Hit;
26 }
27 
28 /// Cluster reconstruction namespace
29 namespace cluster {
30 
31  /**
32  * @brief Wrapper for ClusterParamsAlgBase objects to accept diverse input
33  * @tparam Algo the ClusterParamsAlgBase-derived class to be wrapped
34  * @see ClusterParamsAlgBase
35  *
36  * This simple wrapper class adds a non-virtual ImportHits() method that can
37  * import Hits from different formats than std::vector<recob::Hit const*>.
38  *
39  * This also allows the algorithms derived from ClusterParamsAlgBase to stay
40  * framework-agnostic.
41  *
42  */
43  template <class Algo>
44  class ClusterParamsImportWrapper : public Algo {
45  public:
46  using ClusterParamsAlg_t = Algo; ///< type of wrapped class
47 
48  /// Constructor: just forwards all the stuff to the wrapped class
49  template <typename... Args>
51  {}
52 
53  /// @{
54  /// @name Hit import functions
55  ///
56  /// Methods to import hits int the algorithm.
57  ///
58 
59  /**
60  * @brief Calls SetHits() with the hits in the sequence
61  * @tparam Iter type of iterator to source hits
62  * @param begin iterator to the first hit source
63  * @param end iterator to after-the-last hit source
64  *
65  * The type in the sequence should contain either recob::Hit or some sort
66  * of pointer to it.
67  */
68  template <typename Iter>
69  void
70  ImportHits(util::GeometryUtilities const& gser, Iter begin, Iter end)
71  {
72  std::vector<recob::Hit const*> hits;
73  std::transform(begin, end, std::back_inserter(hits), [](auto value) {
75  });
76  ClusterParamsAlg_t::SetHits(gser, hits);
77  } // ImportHits()
78 
79  /**
80  * @brief Calls SetHits() with the result of converted hits
81  * @tparam Iter type of iterator to source hits
82  * @tparam Convert type of operation to convert to recob::Hit const*
83  * @param begin iterator to the first hit source
84  * @param end iterator to after-the-last hit source
85  * @param converter predicate to convert the pointed values to recob::Hit
86  *
87  * The converter should respect either of the forms:
88  *
89  * recob::Hit converter(typename Iter::value_type)
90  * recob::Hit const* converter(typename Iter::value_type)
91  *
92  * The hit produced by the converter will be moved into a vector, and the
93  * complete vector will be used to initialize the algorithm.
94  */
95  template <typename Iter, typename Convert>
96  void
97  ImportHits(Iter begin, Iter end, Convert converter)
98  {
99  std::vector<recob::Hit const*> hits;
100  std::transform(begin, end, std::back_inserter(hits), [converter](auto value) {
101  return lar::util::make_pointer(converter(value));
102  });
103  ClusterParamsAlg_t::SetHits(hits);
104  } // ImportHits()
105 
106  /**
107  * @brief Calls SetHits() with the hits in the sequence
108  * @tparam Cont type of container to source hits
109  * @param cont container of source hits
110  *
111  * The type in the container should contain either recob::Hit or some sort
112  * of pointer to it.
113  */
114  template <typename Cont>
115  void
116  ImportHits(util::GeometryUtilities const& gser, Cont cont)
117  {
118  ImportHits(gser, std::begin(cont), std::end(cont));
119  }
120 
121  /**
122  * @brief Calls SetHits() with the result of converted hits
123  * @tparam Cont type of container to source hits
124  * @tparam Convert type of operation to convert to recob::Hit const*
125  * @param cont container of source hits
126  * @param converter predicate to convert the pointed values to recob::Hit
127  *
128  * The converter should respect either of the forms:
129  *
130  * recob::Hit converter(typename Iter::value_type)
131  * recob::Hit const* converter(typename Iter::value_type)
132  *
133  * The hit produced by the converter will be moved into a vector, and the
134  * complete vector will be used to initialize the algorithm.
135  */
136  template <typename Cont, typename Convert>
137  void
138  ImportHits(util::GeometryUtilities const& gser, Cont cont, Convert converter)
139  {
140  ImportHits(gser, std::begin(cont), std::end(cont), converter);
141  }
142 
143  /// @}
144 
145  }; //class ClusterParamsImportWrapper
146 
147 } //namespace cluster
148 
149 #endif // CLUSTERPARAMSARTWRAPPER_H
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
Namespace for general, non-LArSoft-specific utilities.
Reconstruction base classes.
details::make_pointer_class< T, details::has_dereference_class< T >::value >::pointer_type make_pointer(T &v)
Returns a pointer to the value of argument, or the argument itself.
Definition: Dereference.h:293
void ImportHits(util::GeometryUtilities const &gser, Cont cont)
Calls SetHits() with the hits in the sequence.
STL namespace.
Cluster finding and building.
static QCString args
Definition: declinfo.cpp:674
void ImportHits(util::GeometryUtilities const &gser, Iter begin, Iter end)
Calls SetHits() with the hits in the sequence.
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
Wrapper for ClusterParamsAlgBase objects to accept diverse input.
bool Convert(const vector< std::string > &input, std::vector< T > &v)
void ImportHits(util::GeometryUtilities const &gser, Cont cont, Convert converter)
Calls SetHits() with the result of converted hits.
void ImportHits(Iter begin, Iter end, Convert converter)
Calls SetHits() with the result of converted hits.
ClusterParamsImportWrapper(Args...args)
Constructor: just forwards all the stuff to the wrapped class.
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72