CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Attributes
edm::ProductSelector Class Reference

#include <ProductSelector.h>

Public Member Functions

void initialize (ProductSelectorRules const &rules, std::vector< BranchDescription const * > const &branchDescriptions)
 
bool initialized () const
 
void print (std::ostream &os) const
 
 ProductSelector ()
 
bool selected (BranchDescription const &desc) const
 

Static Public Member Functions

static void checkForDuplicateKeptBranch (BranchDescription const &desc, std::map< BranchID, BranchDescription const * > &trueBranchIDToKeptBranchDesc)
 
static void fillDroppedToKept (ProductRegistry const &preg, std::map< BranchID, BranchDescription const * > const &trueBranchIDToKeptBranchDesc, std::map< BranchID::value_type, BranchID::value_type > &droppedBranchIDToKeptBranchID_)
 

Private Attributes

bool initialized_
 
std::vector< std::string > productsToSelect_
 

Detailed Description

Definition at line 26 of file ProductSelector.h.

Constructor & Destructor Documentation

edm::ProductSelector::ProductSelector ( )

Definition at line 18 of file ProductSelector.cc.

18 : productsToSelect_(), initialized_(false) {}
std::vector< std::string > productsToSelect_

Member Function Documentation

void edm::ProductSelector::checkForDuplicateKeptBranch ( BranchDescription const &  desc,
std::map< BranchID, BranchDescription const * > &  trueBranchIDToKeptBranchDesc 
)
static

Definition at line 71 of file ProductSelector.cc.

References edm::check(), edm::errors::Configuration, Exception, edm::BranchDescription::isSwitchAlias(), edm::BranchDescription::originalBranchID(), edm::BranchDescription::produced(), and edm::BranchDescription::switchAliasForBranchID().

Referenced by initialized(), edm::OutputModule::keepThisBranch(), edm::SubProcess::keepThisBranch(), edm::one::OutputModuleBase::keepThisBranch(), edm::global::OutputModuleBase::keepThisBranch(), and edm::limited::OutputModuleBase::keepThisBranch().

72  {
73  // Check if an equivalent branch has already been selected due to an EDAlias.
74  // We only need the check for products produced in this process.
75  if (desc.produced()) {
76  auto check = [&](BranchID const& branchID) {
77  auto iter = trueBranchIDToKeptBranchDesc.find(branchID);
78  if (iter != trueBranchIDToKeptBranchDesc.end()) {
79  throw edm::Exception(errors::Configuration, "Duplicate Output Selection")
80  << "Two (or more) equivalent branches have been selected for output.\n"
81  << "#1: " << BranchKey(desc) << "\n"
82  << "#2: " << BranchKey(*iter->second) << "\n"
83  << "Please drop at least one of them.\n";
84  }
85  };
86  BranchID const& trueBranchID = desc.originalBranchID();
87  check(trueBranchID);
88  // In case of SwitchProducer, we have to check also the
89  // aliased-for BranchID for the case that the chosen case is an EDAlias
90  if (desc.isSwitchAlias()) {
91  check(desc.switchAliasForBranchID());
92  }
93 
94  trueBranchIDToKeptBranchDesc.insert(std::make_pair(trueBranchID, &desc));
95  }
96  }
static void check(T const &p, std::string const &id, SelectedProducts const &iProducts)
void edm::ProductSelector::fillDroppedToKept ( ProductRegistry const &  preg,
std::map< BranchID, BranchDescription const * > const &  trueBranchIDToKeptBranchDesc,
std::map< BranchID::value_type, BranchID::value_type > &  droppedBranchIDToKeptBranchID_ 
)
static

Definition at line 99 of file ProductSelector.cc.

References edm::BranchDescription::branchID(), edm::BranchID::id(), edm::BranchDescription::isAlias(), edm::BranchDescription::produced(), and edm::ProductRegistry::productList().

Referenced by initialized(), edm::SubProcess::selectProducts(), edm::OutputModule::selectProducts(), edm::global::OutputModuleBase::selectProducts(), edm::limited::OutputModuleBase::selectProducts(), and edm::one::OutputModuleBase::selectProducts().

102  {
103  for (auto const& it : preg.productList()) {
104  BranchDescription const& desc = it.second;
105  if (!desc.produced() || desc.isAlias())
106  continue;
107  BranchID const& branchID = desc.branchID();
108  std::map<BranchID, BranchDescription const*>::const_iterator iter = trueBranchIDToKeptBranchDesc.find(branchID);
109  if (iter != trueBranchIDToKeptBranchDesc.end()) {
110  // This branch, produced in this process, or an alias of it, was persisted.
111  BranchID const& keptBranchID = iter->second->branchID();
112  if (keptBranchID != branchID) {
113  // An EDAlias branch was persisted.
114  droppedBranchIDToKeptBranchID_.insert(std::make_pair(branchID.id(), keptBranchID.id()));
115  }
116  }
117  }
118  }
void edm::ProductSelector::initialize ( ProductSelectorRules const &  rules,
std::vector< BranchDescription const * > const &  branchDescriptions 
)

Definition at line 20 of file ProductSelector.cc.

References edm::ProductSelectorRules::applyToAll(), end, initialized_, productsToSelect_, and edm::sort_all().

Referenced by edm::RootFile::dropOnInput(), edm::SubProcess::selectProducts(), edm::OutputModule::selectProducts(), edm::global::OutputModuleBase::selectProducts(), edm::limited::OutputModuleBase::selectProducts(), edm::one::OutputModuleBase::selectProducts(), and ShallowTree::ShallowTree().

20  {
21  typedef ProductSelectorRules::BranchSelectState BranchSelectState;
22 
23  // Get a BranchSelectState for each branch, containing the branch
24  // name, with its 'select bit' set to false.
25  std::vector<BranchSelectState> branchstates;
26  {
27  branchstates.reserve(branchDescriptions.size());
28 
29  VCBDP::const_iterator it = branchDescriptions.begin();
30  VCBDP::const_iterator end = branchDescriptions.end();
31  for (; it != end; ++it)
32  branchstates.emplace_back(*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)
48  productsToSelect_.push_back(it->desc->branchName());
49  }
51  }
52  initialized_ = true;
53  }
std::vector< std::string > productsToSelect_
#define end
Definition: vmac.h:39
void sort_all(RandomAccessSequence &s)
wrappers for std::sort
Definition: Algorithms.h:92
bool edm::ProductSelector::initialized ( ) const
inline
void edm::ProductSelector::print ( std::ostream &  os) const

Definition at line 65 of file ProductSelector.cc.

References edm::copy_all(), and productsToSelect_.

Referenced by edm::operator<<().

65  {
66  os << "ProductSelector at: " << static_cast<void const*>(this) << " has " << productsToSelect_.size()
67  << " products to select:\n";
68  copy_all(productsToSelect_, std::ostream_iterator<std::string>(os, "\n"));
69  }
std::vector< std::string > productsToSelect_
Func copy_all(ForwardSequence &s, Func f)
wrappers for copy
Definition: Algorithms.h:20
bool edm::ProductSelector::selected ( BranchDescription const &  desc) const

Definition at line 55 of file ProductSelector.cc.

References edm::binary_search_all(), edm::BranchDescription::branchName(), Exception, initialized_, edm::errors::LogicError, and productsToSelect_.

Referenced by edm::RootFile::dropOnInput(), edm::OutputModule::selected(), edm::global::OutputModuleBase::selected(), edm::limited::OutputModuleBase::selected(), edm::one::OutputModuleBase::selected(), edm::SubProcess::selectProducts(), and ShallowTree::ShallowTree().

55  {
56  if (!initialized_) {
57  throw edm::Exception(edm::errors::LogicError) << "ProductSelector::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.
62  return binary_search_all(productsToSelect_, desc.branchName());
63  }
std::vector< std::string > productsToSelect_
bool binary_search_all(ForwardSequence const &s, Datum const &d)
wrappers for std::binary_search
Definition: Algorithms.h:58

Member Data Documentation

bool edm::ProductSelector::initialized_
private

Definition at line 58 of file ProductSelector.h.

Referenced by initialize(), initialized(), and selected().

std::vector<std::string> edm::ProductSelector::productsToSelect_
private

Definition at line 57 of file ProductSelector.h.

Referenced by initialize(), print(), and selected().