CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/FWCore/Framework/src/SignallingProductRegistry.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Framework
00004 // Class  :     SignallingProductRegistry
00005 //
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Chris Jones
00010 //         Created:  Fri Sep 23 16:52:50 CEST 2005
00011 //
00012 
00013 // system include files
00014 
00015 // user include files
00016 #include "FWCore/Framework/src/SignallingProductRegistry.h"
00017 #include "FWCore/Utilities/interface/Exception.h"
00018 
00019 using namespace edm;
00020 //
00021 // member functions
00022 //
00023 namespace {
00024    struct StackGuard {
00025       StackGuard(std::string const& iTypeName, std::map<std::string, unsigned int>& ioStack, bool iFromListener) :
00026           numType_(++ioStack[iTypeName]), itr_(ioStack.find(iTypeName)), fromListener_(iFromListener) {
00027         if(iFromListener) {++(itr_->second);}
00028       }
00029 
00030       ~StackGuard() {
00031          --(itr_->second);
00032          if(fromListener_) {
00033             --(itr_->second);
00034          }
00035       }
00036 
00037       unsigned int numType_;
00038       std::map<std::string, unsigned int>::iterator itr_;
00039       bool fromListener_;
00040    };
00041 }
00042 
00043 void SignallingProductRegistry::addCalled(BranchDescription const& iProd, bool iFromListener) {
00044    StackGuard guard(iProd.className(), typeAddedStack_, iFromListener);
00045    if(guard.numType_ > 2) {
00046      throw cms::Exception("CircularReference")
00047        << "Attempted to register the production of "
00048        << iProd.className()
00049        << " from module "
00050        << iProd.moduleLabel()
00051        << " with product instance \""
00052        << iProd.productInstanceName()
00053        << "\"\n"
00054        << "However, this was in reaction to a registration of a production for the same type \n"
00055        << "from another module who was also listening to product registrations.\n"
00056        << "This can lead to circular Event::get* calls.\n"
00057        << "Please reconfigure job so it does not contain both of the modules.";
00058    }
00059    productAddedSignal_(iProd);
00060 }