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_() {}
17  ProducerBase::~ProducerBase() noexcept(false) {}
18 
19  std::function<void(BranchDescription const&)> ProducerBase::registrationCallback() const {
20  return callWhenNewProductsRegistered_;
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 
57  void ProducerBase::registerProducts(ProducerBase* producer, ProductRegistry* iReg, ModuleDescription const& md) {
58  if (typeLabelList().empty() && !registrationCallback()) {
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;
68  iReg->callForEachBranch(registrationCallback());
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 
79  void ProducerBase::resolvePutIndicies(BranchType iBranchType,
80  ModuleToResolverIndicies const& iIndicies,
81  std::string const& moduleLabel) {
82  auto const& plist = typeLabelList();
83  if (putTokenToResolverIndex_.size() != plist.size()) {
84  putTokenToResolverIndex_.resize(plist.size(), std::numeric_limits<unsigned int>::max());
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 
105  ProducesCollector ProducerBase::producesCollector() { return ProducesCollector{this}; }
106 
107 } // namespace edm
size
Write out results.
ProductRegistryHelper::TypeLabelList TypeLabelList
Definition: ProducerBase.h:72
BranchType
Definition: BranchType.h:11
void callForEachBranch(T const &iFunc)
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