GroupSelector.cc
Go to the documentation of this file.
2 
6 
7 #include <ostream>
8 #include <utility>
9 
10 using namespace art;
11 using namespace cet;
12 using namespace std;
13 
15  ProductDescriptionsByID const& descriptions)
16 {
17  using BranchSelectState = GroupSelectorRules::BranchSelectState;
18 
19  // Get a BranchSelectState for each branch, containing the branch
20  // name, with its 'select bit' set to false.
21  vector<BranchSelectState> branchstates;
22  branchstates.reserve(descriptions.size());
23  for (auto const& pr : descriptions) {
24  branchstates.push_back(BranchSelectState{&pr.second});
25  }
26 
27  // Now apply the rules to the branchstates, in order. Each rule
28  // can override any previous rule, or all previous rules.
29  rules.applyToAll(branchstates);
30 
31  // For each of the BranchSelectStates that indicates the branch is
32  // to be selected, remember the branch. The list of branch pointers
33  // must be sorted for subsequent binary search to work.
34  for (auto const& state : branchstates) {
35  if (state.selectMe) {
36  groupsToSelect_.push_back(state.desc);
37  }
38  }
39  sort_all(groupsToSelect_);
40 }
41 
42 bool
44 {
45  return binary_search_all(groupsToSelect_, &desc);
46 }
47 
48 void
49 GroupSelector::print(ostream& os) const
50 {
51  os << "GroupSelector at: " << static_cast<void const*>(this) << " has "
52  << groupsToSelect_.size() << " groups to select:\n";
53  for (auto const& bd_ptr : groupsToSelect_) {
54  os << bd_ptr->branchName() << '\n';
55  }
56 }
57 
58 //--------------------------------------------------
59 // Associated free function
60 
61 ostream&
62 art::operator<<(ostream& os, const GroupSelector& gs)
63 {
64  gs.print(os);
65  return os;
66 }
67 
68 // ======================================================================
bool selected(BranchDescription const &desc) const
STL namespace.
void print(std::ostream &os) const
GroupSelector(GroupSelectorRules const &rules, ProductDescriptionsByID const &descriptions)
void sort_all(RandCont &)
std::ostream & operator<<(std::ostream &os, const GroupSelector &gs)
void applyToAll(std::vector< BranchSelectState > &branchstates) const
bool binary_search_all(FwdCont const &, Datum const &)
std::map< ProductID, BranchDescription > ProductDescriptionsByID