thepeg is hosted by Hepforge, IPPP Durham
ThePEG  2.1.5
Interfaced.h
1 // -*- C++ -*-
2 //
3 // Interfaced.h is a part of ThePEG - Toolkit for HEP Event Generation
4 // Copyright (C) 1999-2017 Leif Lonnblad
5 //
6 // ThePEG is licenced under version 3 of the GPL, see COPYING for details.
7 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
8 //
9 #ifndef ThePEG_Interfaced_H
10 #define ThePEG_Interfaced_H
11 // This is the declaration of the Interfaced class.
12 
13 #include "ThePEG/Config/ThePEG.h"
14 #include "InterfacedBase.h"
15 #include "ThePEG/PDT/PID.h"
16 
17 namespace ThePEG {
18 
38 class Interfaced: public InterfacedBase {
39 
41  friend class Repository;
42 
44  friend class EventGenerator;
45 
46 public:
47 
51  virtual ~Interfaced();
52 
57 public:
58 
68  virtual bool defaultInit();
69 
76  PPtr getParticle(PID) const;
77 
82  PDPtr getParticleData(PID) const;
83 
87  bool used() const { return theUseFlag; }
88 
93  void useMe() const { if ( !used() ) setUsed(); }
94 
99  tEGPtr generator() const { return theGenerator; }
101 
102 public:
103 
110  void persistentOutput(PersistentOStream & os) const;
111 
117  void persistentInput(PersistentIStream & is, int version);
119 
123  static void Init();
124 
125 protected:
126 
130  static void registerRepository(IBPtr);
131 
136  static void registerRepository(IBPtr, string newName);
137 
145  void reporeg(IBPtr object, string name) const;
146 
153  template <typename PtrT>
154  bool setDefaultReference(PtrT & ptr, string classname, string objectname) {
155  if ( ptr ) return true;
156  const ClassDescriptionBase * db = DescriptionList::find(classname);
157  if ( !db ) return false;
158  ptr = dynamic_ptr_cast<PtrT>(db->create());
159  if ( !ptr ) return false;
160  reporeg(ptr, objectname);
161  if ( !ptr->defaultInit() ) return false;
162  return true;
163  }
164 
168  Interfaced() : theUseFlag(false) {}
169 
173  Interfaced(const string & newName)
174  : InterfacedBase(newName), theUseFlag(false) {}
175 
181 
182 protected:
183 
189 
190 private:
191 
195  void setUsed() const;
196 
201 
205  mutable bool theUseFlag;
206 
210  string doDefaultInit(string);
211 
212 private:
213 
218 
222  Interfaced & operator=(const Interfaced &) = delete;
223 
224 };
225 
232 template <>
233 struct BaseClassTrait<Interfaced,1>: public ClassTraitsType {
235  typedef InterfacedBase NthBase;
236 };
237 
242 template <>
243 struct ClassTraits<Interfaced>: public ClassTraitsBase<Interfaced> {
245  static string className() { return "ThePEG::Interfaced"; }
246 };
247 
250 }
251 
252 #endif /* ThePEG_Interfaced_H */
bool used() const
Returns true if this object has actally been used.
Definition: Interfaced.h:87
PID is a helper class implementing the type of PDG particle ids.
Definition: PID.h:23
PersistentIStream is used to read persistent objects from a stream where they were previously written...
virtual BPtr create() const =0
Create an object of the described class.
Interfaced()
Protected default constructor.
Definition: Interfaced.h:168
ClassDescriptionBase is the base class for all class description classes.
tEGPtr theGenerator
A pointer to the EventGenerator controlling the run.
Definition: Interfaced.h:200
static void Init()
Standard Init function.
static const ClassDescriptionBase * find(const type_info &ti)
Get the description of a class giving its type_info object.
ClassTraitsType is an empty, non-polymorphic, base class.
Definition: ClassTraits.h:30
PersistentOStream is used to write objects persistently to a stream from which they can be read in ag...
A concreate implementation of ClassDescriptionBase describing an abstract class with persistent data...
void persistentInput(PersistentIStream &is, int version)
Function used to read in object persistently.
virtual bool defaultInit()
Functions which are to be used during the actual event generation, after the setup is complete...
static AbstractClassDescription< Interfaced > initInterfaced
Standard Initialization object.
Definition: Interfaced.h:217
TransientRCPtr is a simple wrapper around a bare pointer which can be assigned to and from an RCPtr a...
Definition: RCPtr.h:519
void setGenerator(tEGPtr generator)
Protected function to reset the generator pointer, required for automatic decayer generation in Herwi...
Definition: Interfaced.h:188
Repository inherits from the BaseRepository class.
Definition: Repository.h:45
bool setDefaultReference(PtrT &ptr, string classname, string objectname)
If the pointer, ptr, to an object is not set, create an object of class classname and register it wit...
Definition: Interfaced.h:154
T1 dynamic_ptr_cast(const T2 &t2)
Replacement for the standard dynamic_cast.
Definition: PtrTraits.h:168
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
This is the main config header file for ThePEG.
Interfaced & operator=(const Interfaced &)=delete
Private and non-existent assignment operator.
void persistentOutput(PersistentOStream &os) const
Function used to write out object persistently.
void useMe() const
Should be called to indicate that this object has actually been used.
Definition: Interfaced.h:93
virtual ~Interfaced()
Empty virtual destructor.
bool theUseFlag
Flag to tell whether this object has been used or not.
Definition: Interfaced.h:205
tEGPtr generator() const
Return a pointer to the EventGenerator controlling the run.
Definition: Interfaced.h:99
PDPtr getParticleData(PID) const
Return a pointer to the ParticleData object corresponding to the given id number. ...
string doDefaultInit(string)
Command interface function which calls defaultInit().
InterfacedBase is the base class of all Interfaced objects to be handled by the BaseRepository class...
RCPtr is a reference counted (smart) pointer.
Definition: RCPtr.h:60
void reporeg(IBPtr object, string name) const
Register the given object in the Repository with the given name in a subdirectory with the same name ...
The Interfaced class is derived from the InterfacedBase class adding a couple of things particular to...
Definition: Interfaced.h:38
Interfaced(const Interfaced &i)
Protected copy-constructor.
Definition: Interfaced.h:179
The default concrete implementation of ClassTraitsBase.
Definition: ClassTraits.h:134
string name() const
Returns the name of this object, without the path.
void setUsed() const
Used internally by &#39;useMe&#39;.
BaseClassTraits describes the base classes of the templated class.
Definition: ClassTraits.h:156
static void registerRepository(IBPtr)
Register an Interfaced object with the Repository.
Interfaced(const string &newName)
Protected constructor taking a name as argument.
Definition: Interfaced.h:173
The EventGenerator class manages a whole event generator run.
The templated ClassTraitsBase class defines a set of default information about classes used by ThePEG...
Definition: ClassTraits.h:52
PPtr getParticle(PID) const
Create a new Particle instance given a id number.