Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:15

0001 // -*- C++ -*-
0002 //
0003 // Package:     Framework
0004 // Class  :     SignallingProductRegistry
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  Chris Jones
0010 //         Created:  Fri Sep 23 16:52:50 CEST 2005
0011 //
0012 
0013 // system include files
0014 
0015 // user include files
0016 #include "FWCore/Framework/interface/SignallingProductRegistry.h"
0017 #include "FWCore/Utilities/interface/Exception.h"
0018 
0019 using namespace edm;
0020 //
0021 // member functions
0022 //
0023 namespace {
0024   struct StackGuard {
0025     StackGuard(std::string const& iTypeName, std::map<std::string, unsigned int>& ioStack, bool iFromListener)
0026         : numType_(++ioStack[iTypeName]), itr_(ioStack.find(iTypeName)), fromListener_(iFromListener) {
0027       if (iFromListener) {
0028         ++(itr_->second);
0029       }
0030     }
0031 
0032     ~StackGuard() {
0033       --(itr_->second);
0034       if (fromListener_) {
0035         --(itr_->second);
0036       }
0037     }
0038 
0039     unsigned int numType_;
0040     std::map<std::string, unsigned int>::iterator itr_;
0041     bool fromListener_;
0042   };
0043 }  // namespace
0044 
0045 void SignallingProductRegistry::addCalled(BranchDescription const& iProd, bool iFromListener) {
0046   // Call only for present branches (part of avoiding adding type information for dropped branches)
0047   if (iProd.dropped())
0048     return;
0049   StackGuard guard(iProd.className(), typeAddedStack_, iFromListener);
0050   if (guard.numType_ > 2) {
0051     throw cms::Exception("CircularReference")
0052         << "Attempted to register the production of " << iProd.className() << " from module " << iProd.moduleLabel()
0053         << " with product instance \"" << iProd.productInstanceName() << "\"\n"
0054         << "However, this was in reaction to a registration of a production for the same type \n"
0055         << "from another module who was also listening to product registrations.\n"
0056         << "This can lead to circular Event::get* calls.\n"
0057         << "Please reconfigure job so it does not contain both of the modules.";
0058   }
0059   productAddedSignal_(iProd);
0060 }