CMS 3D CMS Logo

ProducerBase.cc
Go to the documentation of this file.
1 /*----------------------------------------------------------------------
2 
3 ----------------------------------------------------------------------*/
4 
8 
11 
12 #include <sstream>
13 
14 namespace edm {
15  ProducerBase::ProducerBase() : ProductRegistryHelper(), callWhenNewProductsRegistered_() {}
17 
18  std::function<void(BranchDescription const&)> ProducerBase::registrationCallback() const {
20  }
21 
22  namespace {
23  class CallbackWrapper {
24  public:
25  CallbackWrapper(ProductRegistryHelper* iProd,
26  std::function<void(BranchDescription const&)> iCallback,
27  ProductRegistry* iReg,
28  const ModuleDescription& iDesc)
29  : prod_(iProd), callback_(iCallback), reg_(iReg), mdesc_(iDesc), lastSize_(iProd->typeLabelList().size()) {}
30 
31  void operator()(BranchDescription const& iDesc) {
32  callback_(iDesc);
33  addToRegistry();
34  }
35 
36  void addToRegistry() {
37  ProducerBase::TypeLabelList const& plist = prod_->typeLabelList();
38 
39  if (lastSize_ != plist.size()) {
40  ProducerBase::TypeLabelList::const_iterator pStart = plist.begin();
41  advance(pStart, lastSize_);
42  ProductRegistryHelper::addToRegistry(pStart, plist.end(), mdesc_, *reg_, prod_);
43  lastSize_ = plist.size();
44  }
45  }
46 
47  private:
48  ProductRegistryHelper* prod_;
49  std::function<void(BranchDescription const&)> callback_;
50  ProductRegistry* reg_;
51  ModuleDescription mdesc_;
52  unsigned int lastSize_;
53  };
54  } // namespace
55 
58  return;
59  }
60  //If we have a callback, first tell the callback about all the entries already in the
61  // product registry, then add any items this producer wants to add to the registry
62  // and only after that do we register the callback. This is done so the callback does not
63  // get called for items registered by this producer (avoids circular reference problems)
64  bool isListener = false;
65  if (registrationCallback()) {
66  isListener = true;
68  }
69  TypeLabelList const& plist = typeLabelList();
70 
71  ProductRegistryHelper::addToRegistry(plist.begin(), plist.end(), md, *(iReg), this, isListener);
72  if (registrationCallback()) {
74  regService->watchProductAdditions(CallbackWrapper(producer, registrationCallback(), iReg, md));
75  }
76  }
77 
79  ModuleToResolverIndicies const& iIndicies,
80  std::string const& moduleLabel) {
81  auto const& plist = typeLabelList();
82  if (putTokenToResolverIndex_.size() != plist.size()) {
84  }
85  auto range = iIndicies.equal_range(moduleLabel);
86  putIndicies_[iBranchType].reserve(iIndicies.count(moduleLabel));
87  for (auto it = range.first; it != range.second; ++it) {
88  putIndicies_[iBranchType].push_back(std::get<2>(it->second));
89  unsigned int i = 0;
90  for (auto const& tl : plist) {
91  if (convertToBranchType(tl.transition_) == iBranchType and (tl.typeID_ == *std::get<0>(it->second)) and
92  (tl.productInstanceName_ == std::get<1>(it->second))) {
93  putTokenToResolverIndex_[i] = std::get<2>(it->second);
94  //NOTE: The ExternalLHEProducer puts the 'same' product in at
95  // both beginRun and endRun. Therefore we can get multiple matches.
96  // When the module is finally fixed, we can use the 'break'
97  //break;
98  }
99  ++i;
100  }
101  }
102  }
103 } // namespace edm
TypeLabelList const & typeLabelList() const
used by the fwk to register the list of products of this module
std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex >> ModuleToResolverIndicies
Definition: ProducerBase.h:84
ProductRegistryHelper::TypeLabelList TypeLabelList
Definition: ProducerBase.h:66
void registerProducts(ProducerBase *, ProductRegistry *, ModuleDescription const &)
Definition: ProducerBase.cc:56
static void addToRegistry(TypeLabelList::const_iterator const &iBegin, TypeLabelList::const_iterator const &iEnd, ModuleDescription const &iDesc, ProductRegistry &iReg, ProductRegistryHelper *iProd, bool iIsListener=false)
std::function< void(BranchDescription const &)> callWhenNewProductsRegistered_
Definition: ProducerBase.h:120
std::array< std::vector< edm::ProductResolverIndex >, edm::NumBranchTypes > putIndicies_
Definition: ProducerBase.h:121
BranchType
Definition: BranchType.h:11
void resolvePutIndicies(BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
Definition: ProducerBase.cc:78
~ProducerBase() noexcept(false) override
Definition: ProducerBase.cc:16
void callForEachBranch(T const &iFunc)
std::vector< edm::ProductResolverIndex > putTokenToResolverIndex_
Definition: ProducerBase.h:122
#define noexcept
HLT enums.
std::function< void(BranchDescription const &)> registrationCallback() const
used by the fwk to register list of products
Definition: ProducerBase.cc:18
constexpr BranchType convertToBranchType(Transition iValue)
Definition: Transition.h:15