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

template<typename T >
T call (T(&fn)())
 
template<typename T , typename A >
T call (T(&fn)(A), A a)
 
template<typename T , typename A1 , typename A2 >
T call (T(&fn)(A1, A2), A1 a1, A2 a2)
 
void call (void(&fn)())
 
template<typename A >
void call (void(&fn)(A), A a)
 
template<typename A1 , typename A2 >
void call (void(&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 = nullptr
 

Friends

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

Detailed Description

Definition at line 15 of file FortranInstance.h.

Constructor & Destructor Documentation

◆ FortranInstance()

gen::FortranInstance::FortranInstance ( )
inline

Definition at line 17 of file FortranInstance.h.

17 : instanceNesting(0) {}

◆ ~FortranInstance()

gen::FortranInstance::~FortranInstance ( )
virtualnoexcept

Definition at line 31 of file FortranInstance.cc.

31  {
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 }

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

Member Function Documentation

◆ call() [1/6]

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

Definition at line 25 of file FortranInstance.h.

25  {
26  InstanceWrapper wrapper(this);
27  return fn();
28  }

References personalPlayback::fn, and wrapper.

◆ call() [2/6]

template<typename T , typename A >
T gen::FortranInstance::call ( T(&)(A fn,
A  a 
)
inline

Definition at line 35 of file FortranInstance.h.

35  {
36  InstanceWrapper wrapper(this);
37  return fn(a);
38  }

References a, personalPlayback::fn, and wrapper.

◆ call() [3/6]

template<typename T , typename A1 , typename A2 >
T gen::FortranInstance::call ( T(&)(A1, A2)  fn,
A1  a1,
A2  a2 
)
inline

Definition at line 45 of file FortranInstance.h.

45  {
46  InstanceWrapper wrapper(this);
47  return fn(a1, a2);
48  }

References testProducerWithPsetDescEmpty_cfi::a2, personalPlayback::fn, and wrapper.

◆ call() [4/6]

void gen::FortranInstance::call ( void(&)()  fn)
inline

◆ call() [5/6]

template<typename A >
void gen::FortranInstance::call ( void(&)(A fn,
A  a 
)
inline

Definition at line 30 of file FortranInstance.h.

30  {
31  InstanceWrapper wrapper(this);
32  fn(a);
33  }

References a, personalPlayback::fn, and wrapper.

◆ call() [6/6]

template<typename A1 , typename A2 >
void gen::FortranInstance::call ( void(&)(A1, A2)  fn,
A1  a1,
A2  a2 
)
inline

Definition at line 40 of file FortranInstance.h.

40  {
41  InstanceWrapper wrapper(this);
42  fn(a1, a2);
43  }

References testProducerWithPsetDescEmpty_cfi::a2, personalPlayback::fn, and wrapper.

◆ enter()

void gen::FortranInstance::enter ( )
virtual

Reimplemented in gen::Pythia6Service.

Definition at line 43 of file FortranInstance.cc.

43  {
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;
60 }

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

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

◆ getInstance()

template<typename T >
static T* gen::FortranInstance::getInstance ( )
inlinestatic

Definition at line 76 of file FortranInstance.h.

76  {
77  T *instance = dynamic_cast<T *>(currentInstance);
78  if (!instance)
80  return instance;
81  }

References currentInstance, instance, and throwMissingInstance().

◆ leave()

void gen::FortranInstance::leave ( )
virtual

Definition at line 62 of file FortranInstance.cc.

62  {
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 }

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

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

◆ throwMissingInstance()

void gen::FortranInstance::throwMissingInstance ( )
staticprivate

Definition at line 83 of file FortranInstance.cc.

83  {
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 }

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

Referenced by getInstance().

◆ upEvnt()

void gen::FortranInstance::upEvnt ( )
virtual

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

Definition at line 100 of file FortranInstance.cc.

100  {
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 }

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

◆ upInit()

void gen::FortranInstance::upInit ( )
virtual

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

Definition at line 92 of file FortranInstance.cc.

92  {
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 }

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

◆ upVeto()

bool gen::FortranInstance::upVeto ( )
virtual

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

Definition at line 108 of file FortranInstance.cc.

108 { return false; }

Friends And Related Function Documentation

◆ gen::upevnt_

void gen::upevnt_ ( )
friend

◆ gen::upinit_

void gen::upinit_ ( )
friend

◆ gen::upveto_

void gen::upveto_ ( int *  )
friend

Member Data Documentation

◆ currentInstance

gen::FortranInstance * gen::FortranInstance::currentInstance = nullptr
staticprivate

Definition at line 107 of file FortranInstance.h.

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

◆ instanceNesting

int gen::FortranInstance::instanceNesting
private

Definition at line 104 of file FortranInstance.h.

◆ kFortranInstance

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

Definition at line 88 of file FortranInstance.h.

Referenced by gen::ExternalDecayDriver::ExternalDecayDriver().

edm::errors::LogicError
Definition: EDMException.h:37
wrapper
static HepMC::HEPEVT_Wrapper wrapper
Definition: BeamHaloProducer.cc:47
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
testProducerWithPsetDescEmpty_cfi.a2
a2
Definition: testProducerWithPsetDescEmpty_cfi.py:35
a
double a
Definition: hdecay.h:119
edm::friendlyname::friendlyName
std::string friendlyName(std::string const &iFullName)
Definition: FriendlyName.cc:278
gen::FortranInstance::instanceNesting
int instanceNesting
Definition: FortranInstance.h:104
gen::FortranInstance::throwMissingInstance
static void throwMissingInstance()
Definition: FortranInstance.cc:83
instance
static PFTauRenderPlugin instance
Definition: PFTauRenderPlugin.cc:70
T
long double T
Definition: Basic3DVectorLD.h:48
Exception
Definition: hltDiff.cc:245
personalPlayback.fn
fn
Definition: personalPlayback.py:515
gen::FortranInstance::currentInstance
static FortranInstance * currentInstance
Definition: FortranInstance.h:107