CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 }
ProductRegistryHelper::TypeLabelList TypeLabelList
Definition: ProducerBase.h:36
void registerProducts(ProducerBase *, ProductRegistry *, ModuleDescription const &)
Definition: ProducerBase.cc:60
std::function< void(BranchDescription const &)> callWhenNewProductsRegistered_
Definition: ProducerBase.h:73
TypeLabelList & typeLabelList()
used by the fwk to register the list of products of this module
helper::RootFunctionHelper< F, args >::root_function function(F &f)
Definition: rootFunction.h:14
void callForEachBranch(T const &iFunc)
virtual ~ProducerBase()
Definition: ProducerBase.cc:16
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)
tuple size
Write out results.