CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Member Functions | Static Public Member Functions | 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

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 ()
 

Static Public Member Functions

template<typename T >
static TgetInstance ()
 

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 13 of file FortranInstance.h.

Constructor & Destructor Documentation

gen::FortranInstance::FortranInstance ( )
inline

Definition at line 15 of file FortranInstance.h.

gen::FortranInstance::~FortranInstance ( )
virtual

Definition at line 28 of file FortranInstance.cc.

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

29 {
30  if (currentInstance == this) {
31  edm::LogWarning("ReentrancyProblem")
32  << edm::friendlyname::friendlyName(typeid(*this).name())
33  << " destroyed while it was the "
34  "current active instance." << std::endl;
35  currentInstance = 0;
36  }
37 }
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 20 of file FortranInstance.h.

References wrapper.

21  { 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 22 of file FortranInstance.h.

References wrapper.

23  { 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 24 of file FortranInstance.h.

References wrapper.

25  { 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 26 of file FortranInstance.h.

References wrapper.

27  { 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 28 of file FortranInstance.h.

References wrapper.

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

Reimplemented in gen::Pythia6Service.

Definition at line 41 of file FortranInstance.cc.

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

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

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

Definition at line 56 of file FortranInstance.h.

References currentInstance, and throwMissingInstance().

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

Definition at line 63 of file FortranInstance.cc.

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

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

64 {
65  if (!currentInstance)
67  << edm::friendlyname::friendlyName(typeid(*this).name())
68  << "::leave() called without an "
69  "active instance." << std::endl;
70  else if (currentInstance != this)
72  << edm::friendlyname::friendlyName(typeid(*this).name())
73  << "::leave() called from a "
74  "different instance." << std::endl;
75  else if (instanceNesting <= 0)
77  << edm::friendlyname::friendlyName(typeid(*this).name())
78  << "::leave() called with a "
79  "nesting level of zero." << std::endl;
80 
81  if (--instanceNesting == 0)
82  currentInstance = 0;
83 }
std::string friendlyName(std::string const &iFullName)
static FortranInstance * currentInstance
void gen::FortranInstance::throwMissingInstance ( )
staticprivate

Definition at line 85 of file FortranInstance.cc.

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

Referenced by getInstance().

86 {
88  << "FortranInstance::getInstance() called from "
89  "a Fortran context, but no current instance "
90  "has been registered." << std::endl;
91 }
void gen::FortranInstance::upEvnt ( )
virtual

Reimplemented in Herwig6Hadronizer, and gen::Pythia6ServiceWithCallback.

Definition at line 104 of file FortranInstance.cc.

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

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

Reimplemented in Herwig6Hadronizer, and gen::Pythia6ServiceWithCallback.

Definition at line 95 of file FortranInstance.cc.

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

96 {
97  throw cms::Exception("UnimplementedCallback")
98  << edm::friendlyname::friendlyName(typeid(*this).name())
99  << "::upInit() stub called. "
100  "If user process needs to be generated, please derive "
101  "and implement the upInit() method." << std::endl;
102 }
std::string friendlyName(std::string const &iFullName)
bool gen::FortranInstance::upVeto ( )
virtual

Reimplemented in gen::Pythia6ServiceWithCallback.

Definition at line 113 of file FortranInstance.cc.

114 {
115  return false;
116 }

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 86 of file FortranInstance.h.

Referenced by getInstance(), and ~FortranInstance().

int gen::FortranInstance::instanceNesting
private

Definition at line 83 of file FortranInstance.h.