CMS 3D CMS Logo

FortranInstance.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <typeinfo>
3 
8 
10 
11 // make sure PDFSET is pulled in when linking against the
12 // archive lhapdf library.
13 extern "C" void pdfset_(void);
14 __attribute__((visibility("hidden"))) void dummy() { pdfset_(); }
15 // implementation for the Fortran callbacks from Pythia6/Herwig6
16 
17 void gen::upinit_() { FortranInstance::getInstance<FortranInstance>()->upInit(); }
18 
19 void gen::upevnt_() { FortranInstance::getInstance<FortranInstance>()->upEvnt(); }
20 
21 void gen::upveto_(int *veto) { *veto = FortranInstance::getInstance<FortranInstance>()->upVeto(); }
22 
23 // static FortranInstance members;
24 
26 
27 const std::string gen::FortranInstance::kFortranInstance = "FortranInstance";
28 
29 // FortranInstance methods
30 
32  if (currentInstance == this) {
33  edm::LogWarning("ReentrancyProblem") << edm::friendlyname::friendlyName(typeid(*this).name())
34  << " destroyed while it was the "
35  "current active instance."
36  << std::endl;
37  currentInstance = nullptr;
38  }
39 }
40 
41 // FortranInstance current instance tracking
42 
44  // we should add a boost::mutex here if we care about being
45  // multithread-safe
46  if (currentInstance && currentInstance != this)
48  << "::enter() called from a different "
49  "instance while an instance was already active."
50  << std::endl;
51 
52  if (!currentInstance && instanceNesting != 0)
54  << "::enter() called on an empty "
55  "instance, but instance counter is nonzero."
56  << std::endl;
57 
58  currentInstance = this;
59  instanceNesting++;
60 }
61 
63  if (!currentInstance)
65  << "::leave() called without an "
66  "active instance."
67  << std::endl;
68  else if (currentInstance != this)
70  << "::leave() called from a "
71  "different instance."
72  << std::endl;
73  else if (instanceNesting <= 0)
75  << "::leave() called with a "
76  "nesting level of zero."
77  << std::endl;
78 
79  if (--instanceNesting == 0)
80  currentInstance = nullptr;
81 }
82 
84  throw edm::Exception(edm::errors::LogicError) << "FortranInstance::getInstance() called from "
85  "a Fortran context, but no current instance "
86  "has been registered."
87  << std::endl;
88 }
89 
90 // Herwig callback stubs
91 
93  throw cms::Exception("UnimplementedCallback") << edm::friendlyname::friendlyName(typeid(*this).name())
94  << "::upInit() stub called. "
95  "If user process needs to be generated, please derive "
96  "and implement the upInit() method."
97  << std::endl;
98 }
99 
101  throw cms::Exception("UnimplementedCallback") << edm::friendlyname::friendlyName(typeid(*this).name())
102  << "::upEvnt() stub called. "
103  "If user process needs to be generated, please derive "
104  "and implement the upEvnt() method."
105  << std::endl;
106 }
107 
108 bool gen::FortranInstance::upVeto() { return false; }
__attribute__((visibility("hidden"))) void dummy()
static void throwMissingInstance()
void upinit_()
TEMPL(T2) struct Divides void
Definition: Factorize.h:24
void upevnt_()
virtual void upInit()
std::string friendlyName(std::string const &iFullName)
virtual void enter()
static FortranInstance * currentInstance
static const std::string kFortranInstance
virtual void leave()
void upveto_(int *)
Log< level::Warning, false > LogWarning
void pdfset_(void)
virtual ~FortranInstance() noexcept(false)