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 
23  namespace {
24  class CallbackWrapper {
25  public:
26  CallbackWrapper(ProducerBase* iProd,
27  std::function<void(BranchDescription const&)> iCallback,
28  ProductRegistry* iReg,
29  const ModuleDescription& iDesc):
30  prod_(iProd), callback_(iCallback), reg_(iReg), mdesc_(iDesc),
31  lastSize_(iProd->typeLabelList().size()) {}
32 
33  void operator()(BranchDescription const& iDesc) {
34  callback_(iDesc);
35  addToRegistry();
36  }
37 
38  void addToRegistry() {
39  ProducerBase::TypeLabelList const& plist = prod_->typeLabelList();
40 
41  if(lastSize_!=plist.size()){
42  ProducerBase::TypeLabelList::const_iterator pStart = plist.begin();
43  advance(pStart, lastSize_);
44  ProductRegistryHelper::addToRegistry(pStart, plist.end() ,mdesc_, *reg_);
45  lastSize_ = plist.size();
46  }
47  }
48 
49  private:
50  ProducerBase* prod_;
51  std::function<void(BranchDescription const&)> callback_;
52  ProductRegistry* reg_;
53  ModuleDescription mdesc_;
54  unsigned int lastSize_;
55 
56  };
57  }
58 
59 
61  ProductRegistry* iReg,
62  ModuleDescription const& md)
63  {
65  return;
66  }
67  //If we have a callback, first tell the callback about all the entries already in the
68  // product registry, then add any items this producer wants to add to the registry
69  // and only after that do we register the callback. This is done so the callback does not
70  // get called for items registered by this producer (avoids circular reference problems)
71  bool isListener = false;
72  if(registrationCallback()) {
73  isListener=true;
75  }
76  TypeLabelList const& plist = typeLabelList();
77 
78  ProductRegistryHelper::addToRegistry(plist.begin(), plist.end(), md, *(iReg), isListener);
79  if(registrationCallback()) {
81  regService->watchProductAdditions(CallbackWrapper(producer, registrationCallback(), iReg, md));
82  }
83  }
84 
86  std::unordered_multimap<std::string, edm::ProductResolverIndex> const& iIndicies,
87  std::string const& moduleLabel) {
88  auto range = iIndicies.equal_range(moduleLabel);
89  putIndicies_[iBranchType].reserve(iIndicies.count(moduleLabel));
90  for(auto it = range.first; it != range.second;++it) {
91  putIndicies_[iBranchType].push_back(it->second);
92  }
93  }
94 }
ProductRegistryHelper::TypeLabelList TypeLabelList
Definition: ProducerBase.h:57
void registerProducts(ProducerBase *, ProductRegistry *, ModuleDescription const &)
Definition: ProducerBase.cc:60
#define noexcept
std::function< void(BranchDescription const &)> callWhenNewProductsRegistered_
Definition: ProducerBase.h:101
std::array< std::vector< edm::ProductResolverIndex >, edm::NumBranchTypes > putIndicies_
Definition: ProducerBase.h:102
BranchType
Definition: BranchType.h:11
TypeLabelList & typeLabelList()
used by the fwk to register the list of products of this module
void resolvePutIndicies(BranchType iBranchType, std::unordered_multimap< std::string, edm::ProductResolverIndex > const &iIndicies, std::string const &moduleLabel)
Definition: ProducerBase.cc:85
void callForEachBranch(T const &iFunc)
HLT enums.
std::function< void(BranchDescription const &)> registrationCallback() const
used by the fwk to register list of products
Definition: ProducerBase.cc:18
static void addToRegistry(TypeLabelList::const_iterator const &iBegin, TypeLabelList::const_iterator const &iEnd, ModuleDescription const &iDesc, ProductRegistry &iReg, bool iIsListener=false)
virtual ~ProducerBase() noexcept(false)
Definition: ProducerBase.cc:16