CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GroupSelector.cc
Go to the documentation of this file.
1 #include <algorithm>
2 #include <iterator>
3 #include <ostream>
4 #include <cctype>
5 
11 
12 
13 namespace edm {
14 // The following typedef is used only in this implementation file, in
15 // order to shorten several lines of code.
16  typedef std::vector<edm::BranchDescription const*> VCBDP;
17 
18  GroupSelector::GroupSelector() : groupsToSelect_(), initialized_(false) {}
19 
20  void
21  GroupSelector::initialize(GroupSelectorRules const& rules, VCBDP const& branchDescriptions) {
22  typedef GroupSelectorRules::BranchSelectState BranchSelectState;
23 
24  // Get a BranchSelectState for each branch, containing the branch
25  // name, with its 'select bit' set to false.
26  std::vector<BranchSelectState> branchstates;
27  {
28  branchstates.reserve(branchDescriptions.size());
29 
30  VCBDP::const_iterator it = branchDescriptions.begin();
31  VCBDP::const_iterator end = branchDescriptions.end();
32  for (; it != end; ++it) branchstates.push_back(BranchSelectState(*it));
33  }
34 
35  // Now apply the rules to the branchstates, in order. Each rule
36  // can override any previous rule, or all previous rules.
37  rules.applyToAll(branchstates);
38 
39  // For each of the BranchSelectStates that indicates the branch is
40  // to be selected, remember the branch name. The list of branch
41  // names must be sorted, for the implementation of 'selected' to
42  // work.
43  {
44  std::vector<BranchSelectState>::const_iterator it = branchstates.begin();
45  std::vector<BranchSelectState>::const_iterator end = branchstates.end();
46  for (; it != end; ++it) {
47  if (it->selectMe) groupsToSelect_.push_back(it->desc->branchName());
48  }
50  }
51  initialized_ = true;
52  }
53 
54  bool GroupSelector::selected(BranchDescription const& desc) const {
55  if (!initialized_) {
57  << "GroupSelector::selected() called prematurely\n"
58  << "before the product registry has been frozen.\n";
59  }
60  // We are to select this 'branch' if its name is one of the ones we
61  // have been told to select.
63  }
64 
65  void
66  GroupSelector::print(std::ostream& os) const {
67  os << "GroupSelector at: "
68  << static_cast<void const*>(this)
69  << " has "
70  << groupsToSelect_.size()
71  << " groups to select:\n";
72  copy_all(groupsToSelect_, std::ostream_iterator<std::string>(os, "\n"));
73  }
74 
75 
76  //--------------------------------------------------
77  //
78  // Associated free functions
79  //
80  std::ostream&
81  operator<< (std::ostream& os, const GroupSelector& gs)
82  {
83  gs.print(os);
84  return os;
85  }
86 
87 }
std::string & branchName() const
#define end
Definition: vmac.h:38
std::vector< std::string > groupsToSelect_
Definition: GroupSelector.h:47
void print(std::ostream &os) const
void sort_all(RandomAccessSequence &s)
wrappers for std::sort
Definition: Algorithms.h:120
void applyToAll(std::vector< BranchSelectState > &branchstates) const
std::vector< edm::BranchDescription const * > VCBDP
string const
Definition: compareJSON.py:14
bool selected(BranchDescription const &desc) const
Func copy_all(ForwardSequence &s, Func f)
wrappers for copy
Definition: Algorithms.h:24
bool binary_search_all(ForwardSequence const &s, Datum const &d)
wrappers for std::binary_search
Definition: Algorithms.h:76
void initialize(GroupSelectorRules const &rules, std::vector< BranchDescription const * > const &branchDescriptions)
std::ostream & operator<<(std::ostream &ost, const HLTGlobalStatus &hlt)
Formatted printout of trigger tbale.