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  StackGuard guard(iProd.className(), typeAddedStack_, iFromListener);
47  if (guard.numType_ > 2) {
48  throw cms::Exception("CircularReference")
49  << "Attempted to register the production of " << iProd.className() << " from module " << iProd.moduleLabel()
50  << " with product instance \"" << iProd.productInstanceName() << "\"\n"
51  << "However, this was in reaction to a registration of a production for the same type \n"
52  << "from another module who was also listening to product registrations.\n"
53  << "This can lead to circular Event::get* calls.\n"
54  << "Please reconfigure job so it does not contain both of the modules.";
55  }
56  productAddedSignal_(iProd);
57 }
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