LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
GroupSelector.cc
Go to the documentation of this file.
2 
5 #include "cetlib/container_algorithms.h"
6 #include "range/v3/action/sort.hpp"
7 #include "range/v3/view.hpp"
8 
9 #include <ostream>
10 #include <utility>
11 
12 using namespace art;
13 using namespace cet;
14 using namespace std;
15 
17  ProductDescriptionsByID const& descriptions)
18 {
19  using BranchSelectState = GroupSelectorRules::BranchSelectState;
20 
21  // Get a BranchSelectState for each branch, containing the branch
22  // name, with its 'select bit' set to false.
23  auto branchstates = descriptions | ::ranges::views::values |
24  ::ranges::views::transform(
25  [](auto const& pd) { return BranchSelectState{&pd}; }) |
26  ::ranges::to<std::vector>();
27 
28  // Now apply the rules to the branchstates, in order. Each rule can
29  // override any previous rule, or all previous rules.
30  rules.applyToAll(branchstates);
31 
32  // For each of the BranchSelectStates that indicates the branch is
33  // to be selected, remember the branch. The list of branch pointers
34  // must be sorted for subsequent binary search to work.
35  groupsToSelect_ =
36  branchstates |
37  ::ranges::views::filter([](auto const& state) { return state.selectMe; }) |
38  ::ranges::views::transform([](auto const& state) { return state.desc; }) |
39  ::ranges::to<std::vector>();
40  sort_all(groupsToSelect_);
41 }
42 
43 bool
45 {
46  return binary_search_all(groupsToSelect_, &desc);
47 }
48 
49 void
50 GroupSelector::print(ostream& os) const
51 {
52  os << "GroupSelector at: " << static_cast<void const*>(this) << " has "
53  << groupsToSelect_.size() << " groups to select:\n";
54  for (auto const& bd_ptr : groupsToSelect_) {
55  os << bd_ptr->branchName() << '\n';
56  }
57 }
58 
59 //--------------------------------------------------
60 // Associated free function
61 
62 ostream&
63 art::operator<<(ostream& os, const GroupSelector& gs)
64 {
65  gs.print(os);
66  return os;
67 }
68 
69 // ======================================================================
bool selected(BranchDescription const &desc) const
STL namespace.
void print(std::ostream &os) const
GroupSelector(GroupSelectorRules const &rules, ProductDescriptionsByID const &descriptions)
std::ostream & operator<<(std::ostream &os, const GroupSelector &gs)
void applyToAll(std::vector< BranchSelectState > &branchstates) const
decltype(auto) values(Coll &&coll)
Range-for loop helper iterating across the values of the specified collection.
Definition: MVAAlg.h:12
std::map< ProductID, BranchDescription > ProductDescriptionsByID