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 
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
ConstProductRegistry.h
edm::ProductRegistry::callForEachBranch
void callForEachBranch(T const &iFunc)
Definition: ProductRegistry.h:100
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
mps_fire.i
i
Definition: mps_fire.py:428
funct::false
false
Definition: Factorize.h:29
edm::ProducerBase::ModuleToResolverIndicies
std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex > > ModuleToResolverIndicies
Definition: ProducerBase.h:89
edm::ProducerBase::ProducerBase
ProducerBase()
Definition: ProducerBase.cc:16
edm::ProducerBase::putIndicies_
std::array< std::vector< edm::ProductResolverIndex >, edm::NumBranchTypes > putIndicies_
Definition: ProducerBase.h:130
edm::ProducerBase::TypeLabelList
ProductRegistryHelper::TypeLabelList TypeLabelList
Definition: ProducerBase.h:72
edm
HLT enums.
Definition: AlignableModifier.h:19
RawToDigi_Repacked_cff.producer
producer
Definition: RawToDigi_Repacked_cff.py:6
ProductRegistry.h
edm::BranchType
BranchType
Definition: BranchType.h:11
edm::ModuleDescription
Definition: ModuleDescription.h:21
ProducesCollector.h
edm::ProductRegistry
Definition: ProductRegistry.h:37
ModuleDescription.h
Service.h
ProducerBase.h
edm::ProductRegistryHelper::typeLabelList
TypeLabelList const & typeLabelList() const
used by the fwk to register the list of products of this module
Definition: ProductRegistryHelper.cc:20
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::convertToBranchType
constexpr BranchType convertToBranchType(Transition iValue)
Definition: Transition.h:26
edm::ProducerBase::registrationCallback
std::function< void(BranchDescription const &)> registrationCallback() const
used by the fwk to register list of products
Definition: ProducerBase.cc:19
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
edm::Service
Definition: Service.h:30
edm::ProducerBase::putTokenToResolverIndex_
std::vector< edm::ProductResolverIndex > putTokenToResolverIndex_
Definition: ProducerBase.h:131
edm::ProductRegistryHelper::addToRegistry
static void addToRegistry(TypeLabelList::const_iterator const &iBegin, TypeLabelList::const_iterator const &iEnd, ModuleDescription const &iDesc, ProductRegistry &iReg, ProductRegistryHelper *iProd, bool iIsListener=false)
Definition: ProductRegistryHelper.cc:34
edm::ProducerBase::~ProducerBase
~ProducerBase() noexcept(false) override
Definition: ProducerBase.cc:17
edm::ProducesCollector
Definition: ProducesCollector.h:43
edm::ProducerBase::callWhenNewProductsRegistered_
std::function< void(BranchDescription const &)> callWhenNewProductsRegistered_
Definition: ProducerBase.h:129
relativeConstraints.empty
bool empty
Definition: relativeConstraints.py:46
edm::ProducerBase::resolvePutIndicies
void resolvePutIndicies(BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
Definition: ProducerBase.cc:79
HiBiasedCentrality_cfi.function
function
Definition: HiBiasedCentrality_cfi.py:4
funct::void
TEMPL(T2) struct Divides void
Definition: Factorize.h:24
edm::BranchDescription
Definition: BranchDescription.h:32
HerwigMaxPtPartonFilter_cfi.moduleLabel
moduleLabel
Definition: HerwigMaxPtPartonFilter_cfi.py:4
edm::ProducerBase
Definition: ProducerBase.h:70
edm::ProducerBase::registerProducts
void registerProducts(ProducerBase *, ProductRegistry *, ModuleDescription const &)
Definition: ProducerBase.cc:57
edm::ProducerBase::producesCollector
ProducesCollector producesCollector()
Definition: ProducerBase.cc:105
edm::ProductRegistryHelper
Definition: ProductRegistryHelper.h:23
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443