CMS 3D CMS Logo

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