CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | Static Private Member Functions | Private Attributes | Static Private Attributes | Friends
gen::FortranInstance Class Reference

#include <FortranInstance.h>

Inheritance diagram for gen::FortranInstance:
gen::Herwig6Instance gen::Pythia6Service gen::PomwigHadronizer Herwig6Hadronizer MCatNLOSource gen::Pythia6ServiceWithCallback gen::Pythia6ServiceWithCallback

Classes

struct  InstanceWrapper
 

Public Member Functions

void call (void(&fn)())
 
template<typename T >
T call (T(&fn)())
 
template<typename A >
void call (void(&fn)(A), A a)
 
template<typename T , typename A >
T call (T(&fn)(A), A a)
 
template<typename A1 , typename A2 >
void call (void(&fn)(A1, A2), A1 a1, A2 a2)
 
template<typename T , typename A1 , typename A2 >
T call (T(&fn)(A1, A2), A1 a1, A2 a2)
 
virtual void enter ()
 
 FortranInstance ()
 
virtual void leave ()
 
virtual void upEvnt ()
 
virtual void upInit ()
 
virtual bool upVeto ()
 
virtual ~FortranInstance () noexcept(false)
 

Static Public Member Functions

template<typename T >
static TgetInstance ()
 

Static Public Attributes

static const std::string kFortranInstance = "FortranInstance"
 

Static Private Member Functions

static void throwMissingInstance ()
 

Private Attributes

int instanceNesting
 

Static Private Attributes

static FortranInstancecurrentInstance = 0
 

Friends

void gen::upevnt_ ()
 
void gen::upinit_ ()
 
void gen::upveto_ (int *)
 

Detailed Description

Definition at line 15 of file FortranInstance.h.

Constructor & Destructor Documentation

gen::FortranInstance::FortranInstance ( )
inline

Definition at line 17 of file FortranInstance.h.

References noexcept, and ~FortranInstance().

gen::FortranInstance::~FortranInstance ( )
virtualnoexcept

Definition at line 37 of file FortranInstance.cc.

References currentInstance, and edm::friendlyname::friendlyName().

Referenced by FortranInstance().

38 {
39  if (currentInstance == this) {
40  edm::LogWarning("ReentrancyProblem")
41  << edm::friendlyname::friendlyName(typeid(*this).name())
42  << " destroyed while it was the "
43  "current active instance." << std::endl;
44  currentInstance = nullptr;
45  }
46 }
std::string friendlyName(std::string const &iFullName)
static FortranInstance * currentInstance

Member Function Documentation

void gen::FortranInstance::call ( void(&)()  fn)
inline
template<typename T >
T gen::FortranInstance::call ( T(&)()  fn)
inline

Definition at line 22 of file FortranInstance.h.

References wrapper.

23  { InstanceWrapper wrapper(this); return fn(); }
static HepMC::HEPEVT_Wrapper wrapper
template<typename A >
void gen::FortranInstance::call ( void(&)(A)  fn,
a 
)
inline

Definition at line 24 of file FortranInstance.h.

References wrapper.

25  { InstanceWrapper wrapper(this); fn(a); }
double a
Definition: hdecay.h:121
static HepMC::HEPEVT_Wrapper wrapper
template<typename T , typename A >
T gen::FortranInstance::call ( T(&)(A)  fn,
a 
)
inline

Definition at line 26 of file FortranInstance.h.

References wrapper.

27  { InstanceWrapper wrapper(this); return fn(a); }
double a
Definition: hdecay.h:121
static HepMC::HEPEVT_Wrapper wrapper
template<typename A1 , typename A2 >
void gen::FortranInstance::call ( void(&)(A1, A2)  fn,
A1  a1,
A2  a2 
)
inline

Definition at line 28 of file FortranInstance.h.

References wrapper.

29  { InstanceWrapper wrapper(this); fn(a1, a2); }
static HepMC::HEPEVT_Wrapper wrapper
template<typename T , typename A1 , typename A2 >
T gen::FortranInstance::call ( T(&)(A1, A2)  fn,
A1  a1,
A2  a2 
)
inline

Definition at line 30 of file FortranInstance.h.

References wrapper.

31  { InstanceWrapper wrapper(this); return fn(a1, a2); }
static HepMC::HEPEVT_Wrapper wrapper
void gen::FortranInstance::enter ( )
virtual

Reimplemented in gen::Pythia6Service.

Definition at line 50 of file FortranInstance.cc.

References currentInstance, Exception, edm::friendlyname::friendlyName(), instanceNesting, and edm::errors::LogicError.

Referenced by gen::Pythia6Service::enter(), and gen::FortranInstance::InstanceWrapper::InstanceWrapper().

51 {
52  // we should add a boost::mutex here if we care about being
53  // multithread-safe
54  if (currentInstance && currentInstance != this)
56  << edm::friendlyname::friendlyName(typeid(*this).name())
57  << "::enter() called from a different "
58  "instance while an instance was already active."
59  << std::endl;
60 
61  if (!currentInstance && instanceNesting != 0)
63  << edm::friendlyname::friendlyName(typeid(*this).name())
64  << "::enter() called on an empty "
65  "instance, but instance counter is nonzero."
66  << std::endl;
67 
68  currentInstance = this;
70 }
std::string friendlyName(std::string const &iFullName)
static FortranInstance * currentInstance
template<typename T >
static T* gen::FortranInstance::getInstance ( )
inlinestatic

Definition at line 58 of file FortranInstance.h.

References currentInstance, gen::FortranInstance::InstanceWrapper::instance, throwMissingInstance(), upEvnt(), upInit(), and upVeto().

59  {
60  T *instance = dynamic_cast<T*>(currentInstance);
61  if (!instance)
63  return instance;
64  }
static PFTauRenderPlugin instance
static void throwMissingInstance()
static FortranInstance * currentInstance
long double T
void gen::FortranInstance::leave ( )
virtual

Definition at line 72 of file FortranInstance.cc.

References currentInstance, Exception, edm::friendlyname::friendlyName(), instanceNesting, and edm::errors::LogicError.

Referenced by gen::FortranInstance::InstanceWrapper::~InstanceWrapper().

73 {
74  if (!currentInstance)
76  << edm::friendlyname::friendlyName(typeid(*this).name())
77  << "::leave() called without an "
78  "active instance." << std::endl;
79  else if (currentInstance != this)
81  << edm::friendlyname::friendlyName(typeid(*this).name())
82  << "::leave() called from a "
83  "different instance." << std::endl;
84  else if (instanceNesting <= 0)
86  << edm::friendlyname::friendlyName(typeid(*this).name())
87  << "::leave() called with a "
88  "nesting level of zero." << std::endl;
89 
90  if (--instanceNesting == 0)
91  currentInstance = nullptr;
92 }
std::string friendlyName(std::string const &iFullName)
static FortranInstance * currentInstance
void gen::FortranInstance::throwMissingInstance ( )
staticprivate

Definition at line 94 of file FortranInstance.cc.

References Exception, and edm::errors::LogicError.

Referenced by getInstance().

95 {
97  << "FortranInstance::getInstance() called from "
98  "a Fortran context, but no current instance "
99  "has been registered." << std::endl;
100 }
void gen::FortranInstance::upEvnt ( )
virtual

Reimplemented in Herwig6Hadronizer, gen::Pythia6ServiceWithCallback, and gen::Pythia6ServiceWithCallback.

Definition at line 113 of file FortranInstance.cc.

References Exception, and edm::friendlyname::friendlyName().

Referenced by getInstance().

114 {
115  throw cms::Exception("UnimplementedCallback")
116  << edm::friendlyname::friendlyName(typeid(*this).name())
117  << "::upEvnt() stub called. "
118  "If user process needs to be generated, please derive "
119  "and implement the upEvnt() method." << std::endl;
120 }
std::string friendlyName(std::string const &iFullName)
void gen::FortranInstance::upInit ( )
virtual

Reimplemented in Herwig6Hadronizer, gen::Pythia6ServiceWithCallback, and gen::Pythia6ServiceWithCallback.

Definition at line 104 of file FortranInstance.cc.

References Exception, and edm::friendlyname::friendlyName().

Referenced by getInstance().

105 {
106  throw cms::Exception("UnimplementedCallback")
107  << edm::friendlyname::friendlyName(typeid(*this).name())
108  << "::upInit() stub called. "
109  "If user process needs to be generated, please derive "
110  "and implement the upInit() method." << std::endl;
111 }
std::string friendlyName(std::string const &iFullName)
bool gen::FortranInstance::upVeto ( )
virtual

Reimplemented in gen::Pythia6ServiceWithCallback, and gen::Pythia6ServiceWithCallback.

Definition at line 122 of file FortranInstance.cc.

Referenced by getInstance().

123 {
124  return false;
125 }

Friends And Related Function Documentation

void gen::upevnt_ ( )
friend
void gen::upinit_ ( )
friend
void gen::upveto_ ( int *  )
friend

Member Data Documentation

gen::FortranInstance * gen::FortranInstance::currentInstance = 0
staticprivate

Definition at line 90 of file FortranInstance.h.

Referenced by enter(), getInstance(), leave(), gen::upveto_(), and ~FortranInstance().

int gen::FortranInstance::instanceNesting
private

Definition at line 87 of file FortranInstance.h.

Referenced by enter(), and leave().

const std::string gen::FortranInstance::kFortranInstance = "FortranInstance"
static