@@ -164,18 +164,6 @@ class CombineHarvester {
164164 */
165165 /* *@{*/
166166 // Set generation
167- template <typename T>
168- std::set<T> GenerateSetFromProcs (
169- std::function<T(ch::Process const *)> func);
170-
171- template <typename T>
172- std::set<T> GenerateSetFromObs (
173- std::function<T(ch::Observation const *)> func);
174-
175- template <typename T>
176- std::set<T> GenerateSetFromSysts (
177- std::function<T(ch::Systematic const *)> func);
178-
179167 std::set<std::string> bin_set ();
180168 std::set<int > bin_id_set ();
181169 std::set<std::string> process_set ();
@@ -185,18 +173,55 @@ class CombineHarvester {
185173 std::set<std::string> mass_set ();
186174 std::set<std::string> syst_name_set ();
187175 std::set<std::string> syst_type_set ();
188- /* *@}*/
189176
190- // An alternative way to do the set generation
191- // template<typename T>
192- // T unwind(T const& x) { return x; }
177+ /* *
178+ * Fill an std::set with the return values from an arbitrary function
179+ *
180+ * This method will loop through all ch::Observation, ch::Process and
181+ * ch::Systematic entries and call the user-supplied function `func`. The
182+ * return value is then inserted into the set.
183+ *
184+ * @tparam T A function (or other callable) that must have a single
185+ * `ch::Object const*` argument.
186+ * @tparam R The return type of the function, which is deduced by using
187+ * `std::result_of`, then `std::decay`. The latter is needed to handle
188+ * functions that return by reference, i.e. turning a type R& into a type R.
189+ */
190+ template <typename T,
191+ typename R = typename std::decay<
192+ typename std::result_of<T(Object const *)>::type>::type>
193+ std::set<R> SetFromAll (T func);
194+
195+ /* *
196+ * Fill an std::set using only the Observation entries
197+ *
198+ * \sa SetFromAll
199+ */
200+ template <typename T,
201+ typename R = typename std::decay<
202+ typename std::result_of<T(Observation const *)>::type>::type>
203+ std::set<R> SetFromObs (T func);
204+
205+ /* *
206+ * Fill an std::set using only the Process entries
207+ *
208+ * \sa SetFromAll
209+ */
210+ template <typename T,
211+ typename R = typename std::decay<
212+ typename std::result_of<T(Process const *)>::type>::type>
213+ std::set<R> SetFromProcs (T func);
193214
194- // template<typename T>
195- // auto SetFromProcs(T func) -> std::set<decltype(unwind(func(nullptr)))> {
196- // std::set<decltype(unwind(func(nullptr)))> ret;
197- // for (auto const& item : procs_) ret.insert(func(item.get()));
198- // return ret;
199- // };
215+ /* *
216+ * Fill an std::set using only the Systematic entries
217+ *
218+ * \sa SetFromAll
219+ */
220+ template <typename T,
221+ typename R = typename std::decay<
222+ typename std::result_of<T(Systematic const *)>::type>::type>
223+ std::set<R> SetFromSysts (T func);
224+ /* *@}*/
200225
201226 /* *
202227 * \name Modification
@@ -446,29 +471,35 @@ void FillHistMappings(std::vector<HistMapping> & mappings);
446471// ---------------------------------------------------------------
447472// Template method implementation
448473// ---------------------------------------------------------------
449- template <typename T>
450- std::set<T > CombineHarvester::GenerateSetFromProcs (
451- std::function<T (ch::Process const *)> func) {
452- std::set<T> ret;
474+ template <typename T, typename R >
475+ std::set<R > CombineHarvester::SetFromAll (T func) {
476+ std::set<R> ret;
477+ for ( auto const & item : obs_) ret. insert ( func (item. get ())) ;
453478 for (auto const & item : procs_) ret.insert (func (item.get ()));
479+ for (auto const & item : systs_) ret.insert (func (item.get ()));
454480 return ret;
455- }
481+ };
456482
457- template <typename T>
458- std::set<T> CombineHarvester::GenerateSetFromObs (
459- std::function<T (ch::Observation const *)> func) {
460- std::set<T> ret;
483+ template <typename T, typename R>
484+ std::set<R> CombineHarvester::SetFromObs (T func) {
485+ std::set<R> ret;
461486 for (auto const & item : obs_) ret.insert (func (item.get ()));
462487 return ret;
463- }
488+ };
489+
490+ template <typename T, typename R>
491+ std::set<R> CombineHarvester::SetFromProcs (T func) {
492+ std::set<R> ret;
493+ for (auto const & item : procs_) ret.insert (func (item.get ()));
494+ return ret;
495+ };
464496
465- template <typename T>
466- std::set<T> CombineHarvester::GenerateSetFromSysts (
467- std::function<T (ch::Systematic const *)> func) {
468- std::set<T> ret;
497+ template <typename T, typename R>
498+ std::set<R> CombineHarvester::SetFromSysts (T func) {
499+ std::set<R> ret;
469500 for (auto const & item : systs_) ret.insert (func (item.get ()));
470501 return ret;
471- }
502+ };
472503
473504template <typename Function>
474505void CombineHarvester::ForEachObj (Function func) {
0 commit comments