Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:29:38

0001 #include <iostream>
0002 #include <typeinfo>
0003 
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #include "FWCore/Utilities/interface/Exception.h"
0006 #include "FWCore/Utilities/interface/EDMException.h"
0007 #include "FWCore/Utilities/interface/FriendlyName.h"
0008 
0009 #include "GeneratorInterface/Core/interface/FortranInstance.h"
0010 
0011 // make sure PDFSET is pulled in when linking against the
0012 // archive lhapdf library.
0013 extern "C" void pdfset_(void);
0014 __attribute__((visibility("hidden"))) void dummy() { pdfset_(); }
0015 // implementation for the Fortran callbacks from Pythia6/Herwig6
0016 
0017 void gen::upinit_() { FortranInstance::getInstance<FortranInstance>()->upInit(); }
0018 
0019 void gen::upevnt_() { FortranInstance::getInstance<FortranInstance>()->upEvnt(); }
0020 
0021 void gen::upveto_(int *veto) { *veto = FortranInstance::getInstance<FortranInstance>()->upVeto(); }
0022 
0023 // static FortranInstance members;
0024 
0025 gen::FortranInstance *gen::FortranInstance::currentInstance = nullptr;
0026 
0027 const std::string gen::FortranInstance::kFortranInstance = "FortranInstance";
0028 
0029 // FortranInstance methods
0030 
0031 gen::FortranInstance::~FortranInstance() noexcept(false) {
0032   if (currentInstance == this) {
0033     edm::LogWarning("ReentrancyProblem") << edm::friendlyname::friendlyName(typeid(*this).name())
0034                                          << " destroyed while it was the "
0035                                             "current active instance."
0036                                          << std::endl;
0037     currentInstance = nullptr;
0038   }
0039 }
0040 
0041 // FortranInstance current instance tracking
0042 
0043 void gen::FortranInstance::enter() {
0044   // we should add a boost::mutex here if we care about being
0045   // multithread-safe
0046   if (currentInstance && currentInstance != this)
0047     throw edm::Exception(edm::errors::LogicError) << edm::friendlyname::friendlyName(typeid(*this).name())
0048                                                   << "::enter() called from a different "
0049                                                      "instance while an instance was already active."
0050                                                   << std::endl;
0051 
0052   if (!currentInstance && instanceNesting != 0)
0053     throw edm::Exception(edm::errors::LogicError) << edm::friendlyname::friendlyName(typeid(*this).name())
0054                                                   << "::enter() called on an empty "
0055                                                      "instance, but instance counter is nonzero."
0056                                                   << std::endl;
0057 
0058   currentInstance = this;
0059   instanceNesting++;
0060 }
0061 
0062 void gen::FortranInstance::leave() {
0063   if (!currentInstance)
0064     throw edm::Exception(edm::errors::LogicError) << edm::friendlyname::friendlyName(typeid(*this).name())
0065                                                   << "::leave() called without an "
0066                                                      "active instance."
0067                                                   << std::endl;
0068   else if (currentInstance != this)
0069     throw edm::Exception(edm::errors::LogicError) << edm::friendlyname::friendlyName(typeid(*this).name())
0070                                                   << "::leave() called from a "
0071                                                      "different instance."
0072                                                   << std::endl;
0073   else if (instanceNesting <= 0)
0074     throw edm::Exception(edm::errors::LogicError) << edm::friendlyname::friendlyName(typeid(*this).name())
0075                                                   << "::leave() called with a "
0076                                                      "nesting level of zero."
0077                                                   << std::endl;
0078 
0079   if (--instanceNesting == 0)
0080     currentInstance = nullptr;
0081 }
0082 
0083 void gen::FortranInstance::throwMissingInstance() {
0084   throw edm::Exception(edm::errors::LogicError) << "FortranInstance::getInstance() called from "
0085                                                    "a Fortran context, but no current instance "
0086                                                    "has been registered."
0087                                                 << std::endl;
0088 }
0089 
0090 // Herwig callback stubs
0091 
0092 void gen::FortranInstance::upInit() {
0093   throw cms::Exception("UnimplementedCallback") << edm::friendlyname::friendlyName(typeid(*this).name())
0094                                                 << "::upInit() stub called. "
0095                                                    "If user process needs to be generated, please derive "
0096                                                    "and implement the upInit() method."
0097                                                 << std::endl;
0098 }
0099 
0100 void gen::FortranInstance::upEvnt() {
0101   throw cms::Exception("UnimplementedCallback") << edm::friendlyname::friendlyName(typeid(*this).name())
0102                                                 << "::upEvnt() stub called. "
0103                                                    "If user process needs to be generated, please derive "
0104                                                    "and implement the upEvnt() method."
0105                                                 << std::endl;
0106 }
0107 
0108 bool gen::FortranInstance::upVeto() { return false; }