File indexing completed on 2024-04-06 12:12:15
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #include "FWCore/Framework/interface/SignallingProductRegistry.h"
0017 #include "FWCore/Utilities/interface/Exception.h"
0018
0019 using namespace edm;
0020
0021
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 }
0044
0045 void SignallingProductRegistry::addCalled(BranchDescription const& iProd, bool iFromListener) {
0046
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 }