CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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) {++(itr_->second);}
28  }
29 
30  ~StackGuard() {
31  --(itr_->second);
32  if(fromListener_) {
33  --(itr_->second);
34  }
35  }
36 
37  unsigned int numType_;
38  std::map<std::string, unsigned int>::iterator itr_;
39  bool fromListener_;
40  };
41 }
42 
43 void SignallingProductRegistry::addCalled(BranchDescription const& iProd, bool iFromListener) {
44  StackGuard guard(iProd.className(), typeAddedStack_, iFromListener);
45  if(guard.numType_ > 2) {
46  throw cms::Exception("CircularReference")
47  << "Attempted to register the production of "
48  << iProd.className()
49  << " from module "
50  << iProd.moduleLabel()
51  << " with product instance \""
52  << iProd.productInstanceName()
53  << "\"\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 }
virtual void addCalled(BranchDescription const &, bool)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
std::string const & className() const
std::string const & moduleLabel() const
std::string const & productInstanceName() const
sigc::signal< void, BranchDescription const & > productAddedSignal_
std::map< std::string, unsigned int > typeAddedStack_