CMS 3D CMS Logo

SignallingProductRegistry.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Framework
4 // Class : SignallingProductRegistry
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Fri Sep 23 16:52:50 CEST 2005
11 //
12 
13 // system include files
14 
15 // user include files
18 
19 using namespace edm;
20 //
21 // member functions
22 //
23 namespace {
24  struct StackGuard {
25  StackGuard(std::string const& iTypeName, std::map<std::string, unsigned int>& ioStack, bool iFromListener)
26  : numType_(++ioStack[iTypeName]), itr_(ioStack.find(iTypeName)), fromListener_(iFromListener) {
27  if (iFromListener) {
28  ++(itr_->second);
29  }
30  }
31 
32  ~StackGuard() {
33  --(itr_->second);
34  if (fromListener_) {
35  --(itr_->second);
36  }
37  }
38 
39  unsigned int numType_;
40  std::map<std::string, unsigned int>::iterator itr_;
41  bool fromListener_;
42  };
43 } // namespace
44 
45 void SignallingProductRegistry::addCalled(BranchDescription const& iProd, bool iFromListener) {
46  // Call only for present branches (part of avoiding adding type information for dropped branches)
47  if (iProd.dropped())
48  return;
49  StackGuard guard(iProd.className(), typeAddedStack_, iFromListener);
50  if (guard.numType_ > 2) {
51  throw cms::Exception("CircularReference")
52  << "Attempted to register the production of " << iProd.className() << " from module " << iProd.moduleLabel()
53  << " with product instance \"" << iProd.productInstanceName() << "\"\n"
54  << "However, this was in reaction to a registration of a production for the same type \n"
55  << "from another module who was also listening to product registrations.\n"
56  << "This can lead to circular Event::get* calls.\n"
57  << "Please reconfigure job so it does not contain both of the modules.";
58  }
59  productAddedSignal_(iProd);
60 }
signalslot::Signal< void(BranchDescription const &)> productAddedSignal_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
std::string const & className() const
std::string const & productInstanceName() const
HLT enums.
void addCalled(BranchDescription const &, bool) override
std::map< std::string, unsigned int > typeAddedStack_
std::string const & moduleLabel() const