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