CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ProductSelector.cc
Go to the documentation of this file.
1 #include <algorithm>
2 #include <iterator>
3 #include <ostream>
4 #include <cctype>
5 
12 
13 
14 namespace edm {
15 // The following typedef is used only in this implementation file, in
16 // order to shorten several lines of code.
17  typedef std::vector<edm::BranchDescription const*> VCBDP;
18 
19  ProductSelector::ProductSelector() : productsToSelect_(), initialized_(false) {}
20 
21  void
22  ProductSelector::initialize(ProductSelectorRules const& rules, VCBDP const& branchDescriptions) {
23  typedef ProductSelectorRules::BranchSelectState BranchSelectState;
24 
25  // Get a BranchSelectState for each branch, containing the branch
26  // name, with its 'select bit' set to false.
27  std::vector<BranchSelectState> branchstates;
28  {
29  branchstates.reserve(branchDescriptions.size());
30 
31  VCBDP::const_iterator it = branchDescriptions.begin();
32  VCBDP::const_iterator end = branchDescriptions.end();
33  for (; it != end; ++it) branchstates.emplace_back(*it);
34  }
35 
36  // Now apply the rules to the branchstates, in order. Each rule
37  // can override any previous rule, or all previous rules.
38  rules.applyToAll(branchstates);
39 
40  // For each of the BranchSelectStates that indicates the branch is
41  // to be selected, remember the branch name. The list of branch
42  // names must be sorted, for the implementation of 'selected' to
43  // work.
44  {
45  std::vector<BranchSelectState>::const_iterator it = branchstates.begin();
46  std::vector<BranchSelectState>::const_iterator end = branchstates.end();
47  for (; it != end; ++it) {
48  if (it->selectMe) productsToSelect_.push_back(it->desc->branchName());
49  }
51  }
52  initialized_ = true;
53  }
54 
55  bool ProductSelector::selected(BranchDescription const& desc) const {
56  if (!initialized_) {
58  << "ProductSelector::selected() called prematurely\n"
59  << "before the product registry has been frozen.\n";
60  }
61  // We are to select this 'branch' if its name is one of the ones we
62  // have been told to select.
64  }
65 
66  void
67  ProductSelector::print(std::ostream& os) const {
68  os << "ProductSelector at: "
69  << static_cast<void const*>(this)
70  << " has "
71  << productsToSelect_.size()
72  << " products to select:\n";
73  copy_all(productsToSelect_, std::ostream_iterator<std::string>(os, "\n"));
74  }
75 
76  void
78  std::map<BranchID, BranchDescription const*>& trueBranchIDToKeptBranchDesc) {
79  // Check if an equivalent branch has already been selected due to an EDAlias.
80  // We only need the check for products produced in this process.
81  if(desc.produced()) {
82  BranchID const& trueBranchID = desc.originalBranchID();
83  std::map<BranchID, BranchDescription const*>::const_iterator iter = trueBranchIDToKeptBranchDesc.find(trueBranchID);
84  if(iter != trueBranchIDToKeptBranchDesc.end()) {
85  throw edm::Exception(errors::Configuration, "Duplicate Output Selection")
86  << "Two (or more) equivalent branches have been selected for output.\n"
87  << "#1: " << BranchKey(desc) << "\n"
88  << "#2: " << BranchKey(*iter->second) << "\n"
89  << "Please drop at least one of them.\n";
90  }
91  trueBranchIDToKeptBranchDesc.insert(std::make_pair(trueBranchID, &desc));
92  }
93  }
94 
95  // Fills in a mapping needed in the case that a branch was dropped while its EDAlias was kept.
96  void
98  std::map<BranchID, BranchDescription const*> const& trueBranchIDToKeptBranchDesc,
99  std::map<BranchID::value_type, BranchID::value_type>& droppedBranchIDToKeptBranchID_) {
100  for(auto const& it : preg.productList()) {
101  BranchDescription const& desc = it.second;
102  if(!desc.produced() || desc.isAlias()) continue;
103  BranchID const& branchID = desc.branchID();
104  std::map<BranchID, BranchDescription const*>::const_iterator iter = trueBranchIDToKeptBranchDesc.find(branchID);
105  if(iter != trueBranchIDToKeptBranchDesc.end()) {
106  // This branch, produced in this process, or an alias of it, was persisted.
107  BranchID const& keptBranchID = iter->second->branchID();
108  if(keptBranchID != branchID) {
109  // An EDAlias branch was persisted.
110  droppedBranchIDToKeptBranchID_.insert(std::make_pair(branchID.id(), keptBranchID.id()));
111  }
112  }
113  }
114  }
115 
116 
117  //--------------------------------------------------
118  //
119  // Associated free functions
120  //
121  std::ostream&
122  operator<< (std::ostream& os, const ProductSelector& gs)
123  {
124  gs.print(os);
125  return os;
126  }
127 
128 }
std::string const & branchName() const
bool selected(BranchDescription const &desc) const
static void fillDroppedToKept(ProductRegistry const &preg, std::map< BranchID, BranchDescription const * > const &trueBranchIDToKeptBranchDesc, std::map< BranchID::value_type, BranchID::value_type > &droppedBranchIDToKeptBranchID_)
std::vector< std::string > productsToSelect_
void applyToAll(std::vector< BranchSelectState > &branchstates) const
unsigned int id() const
Definition: BranchID.h:23
ProductList const & productList() const
BranchID const & branchID() const
#define end
Definition: vmac.h:37
void sort_all(RandomAccessSequence &s)
wrappers for std::sort
Definition: Algorithms.h:120
std::vector< edm::BranchDescription const * > VCBDP
string const
Definition: compareJSON.py:14
Func copy_all(ForwardSequence &s, Func f)
wrappers for copy
Definition: Algorithms.h:24
void initialize(ProductSelectorRules const &rules, std::vector< BranchDescription const * > const &branchDescriptions)
bool binary_search_all(ForwardSequence const &s, Datum const &d)
wrappers for std::binary_search
Definition: Algorithms.h:76
BranchID const & originalBranchID() const
void print(std::ostream &os) const
volatile std::atomic< bool > shutdown_flag false
preg
Definition: Schedule.cc:369
std::ostream & operator<<(std::ostream &ost, const HLTGlobalStatus &hlt)
Formatted printout of trigger tbale.
static void checkForDuplicateKeptBranch(BranchDescription const &desc, std::map< BranchID, BranchDescription const * > &trueBranchIDToKeptBranchDesc)