CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 19 of file ProductSelector.cc.

19 : 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 77 of file ProductSelector.cc.

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

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

78  {
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  }
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 97 of file ProductSelector.cc.

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

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

99  {
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  }
preg
Definition: Schedule.cc:369
void edm::ProductSelector::initialize ( ProductSelectorRules const &  rules,
std::vector< BranchDescription const * > const &  branchDescriptions 
)

Definition at line 22 of file ProductSelector.cc.

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

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

22  {
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  }
std::vector< std::string > productsToSelect_
#define end
Definition: vmac.h:37
void sort_all(RandomAccessSequence &s)
wrappers for std::sort
Definition: Algorithms.h:120
bool edm::ProductSelector::initialized ( ) const
inline
void edm::ProductSelector::print ( std::ostream &  os) const

Definition at line 67 of file ProductSelector.cc.

References compareJSON::const, edm::copy_all(), and productsToSelect_.

Referenced by edm::operator<<().

67  {
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  }
std::vector< std::string > productsToSelect_
string const
Definition: compareJSON.py:14
Func copy_all(ForwardSequence &s, Func f)
wrappers for copy
Definition: Algorithms.h:24
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 ShallowTree::beginJob(), edm::RootFile::dropOnInput(), edm::OutputModule::selected(), edm::global::OutputModuleBase::selected(), and edm::one::OutputModuleBase::selected().

55  {
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.
63  return binary_search_all(productsToSelect_, desc.branchName());
64  }
std::vector< std::string > productsToSelect_
bool binary_search_all(ForwardSequence const &s, Datum const &d)
wrappers for std::binary_search
Definition: Algorithms.h:76

Member Data Documentation

bool edm::ProductSelector::initialized_
private

Definition at line 60 of file ProductSelector.h.

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

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

Definition at line 59 of file ProductSelector.h.

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