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  ModuleToResolverIndicies const& iIndicies,
87  std::string const& moduleLabel) {
88  auto const& plist = typeLabelList();
89  if(putTokenToResolverIndex_.size() != plist.size()) {
91  }
92  auto range = iIndicies.equal_range(moduleLabel);
93  putIndicies_[iBranchType].reserve(iIndicies.count(moduleLabel));
94  for(auto it = range.first; it != range.second;++it) {
95  putIndicies_[iBranchType].push_back(std::get<2>(it->second));
96  unsigned int i = 0;
97  for(auto const& tl: plist) {
98  if(convertToBranchType(tl.transition_) == iBranchType and
99  (tl.typeID_ == *std::get<0>(it->second)) and
100  (tl.productInstanceName_ == std::get<1>(it->second)) ) {
101  putTokenToResolverIndex_[i] = std::get<2>(it->second);
102  //NOTE: The ExternalLHEProducer puts the 'same' product in at
103  // both beginRun and endRun. Therefore we can get multiple matches.
104  // When the module is finally fixed, we can use the 'break'
105  //break;
106  }
107  ++i;
108  }
109  }
110  }
111 }
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:81
ProductRegistryHelper::TypeLabelList TypeLabelList
Definition: ProducerBase.h:61
void registerProducts(ProducerBase *, ProductRegistry *, ModuleDescription const &)
Definition: ProducerBase.cc:60
#define noexcept
std::function< void(BranchDescription const &)> callWhenNewProductsRegistered_
Definition: ProducerBase.h:116
std::array< std::vector< edm::ProductResolverIndex >, edm::NumBranchTypes > putIndicies_
Definition: ProducerBase.h:117
BranchType
Definition: BranchType.h:11
void resolvePutIndicies(BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
Definition: ProducerBase.cc:85
void callForEachBranch(T const &iFunc)
std::vector< edm::ProductResolverIndex > putTokenToResolverIndex_
Definition: ProducerBase.h:118
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
constexpr BranchType convertToBranchType(Transition iValue)
Definition: Transition.h:21