|
|
|||
File indexing completed on 2026-08-06 09:38:26
0001 // -*- C++ -*- 0002 // 0003 // Interfaced.h is a part of ThePEG - Toolkit for HEP Event Generation 0004 // Copyright (C) 1999-2019 Leif Lonnblad 0005 // 0006 // ThePEG is licenced under version 3 of the GPL, see COPYING for details. 0007 // Please respect the MCnet academic guidelines, see GUIDELINES for details. 0008 // 0009 #ifndef ThePEG_Interfaced_H 0010 #define ThePEG_Interfaced_H 0011 // This is the declaration of the Interfaced class. 0012 0013 #include "ThePEG/Config/ThePEG.h" 0014 #include "InterfacedBase.h" 0015 #include "ThePEG/PDT/PID.h" 0016 0017 namespace ThePEG { 0018 0019 /** 0020 * The Interfaced class is derived from the InterfacedBase class 0021 * adding a couple of things particular to ThePEG, in an attempt to 0022 * keep the InterfacedBase class as generic as possible. 0023 * 0024 * The main addition is that the Interfaced class has a pointer to an 0025 * EventGenerator object. During the run-phase this points to the 0026 * EventGenerator controlling the run in which the Interfaced object 0027 * is used. Through this EventGenerator there is quick access to 0028 * eg. the set of ParticleData objects used, and the default 0029 * RandomGenerator for the run. Note that no EventGenerator object is 0030 * available to the Interfaced object during the setup 0031 * phase. 0032 * 0033 * @see InterfacedBase 0034 * @see EventGenerator 0035 * @see ParticleData 0036 * @see RandomGenerator 0037 */ 0038 class Interfaced: public InterfacedBase { 0039 0040 /** Repository is a friend. */ 0041 friend class Repository; 0042 0043 /** EventGenerator is a friend. */ 0044 friend class EventGenerator; 0045 0046 public: 0047 0048 /** 0049 * Empty virtual destructor 0050 */ 0051 virtual ~Interfaced(); 0052 0053 /** 0054 * Functions which are to be used during the actual event 0055 * generation, after the setup is complete. 0056 */ 0057 public: 0058 0059 /** 0060 * A sub class can implement this function to implement some default 0061 * initialization for this object during the setup phase. A typical 0062 * example is if this object need some references to other objects 0063 * and if these can be easily created. In this case the objects can 0064 * be added to the repository in a sub-directory with the same name 0065 * as this object. 0066 * @return false if the initialization failed. 0067 */ 0068 virtual bool defaultInit(); 0069 0070 /** @name Functions used during the actual event generation, after 0071 the setup is complete. */ 0072 //@{ 0073 /** 0074 * Create a new Particle instance given a id number. 0075 */ 0076 PPtr getParticle(PID) const; 0077 0078 /** 0079 * Return a pointer to the ParticleData object corresponding to the 0080 * given id number. 0081 */ 0082 PDPtr getParticleData(PID) const; 0083 0084 /** 0085 * Returns true if this object has actally been used. 0086 */ 0087 bool used() const { return theUseFlag; } 0088 0089 /** 0090 * Should be called to indicate that this object has actually been 0091 * used. 0092 */ 0093 void useMe() const { if ( !used() ) setUsed(); } 0094 0095 /** 0096 * Return a pointer to the EventGenerator controlling the run. 0097 * During the setup phase this returns a null pointer. 0098 */ 0099 tEGPtr generator() const { return theGenerator; } 0100 //@} 0101 0102 public: 0103 0104 /** @name Functions used by the persistent I/O system. */ 0105 //@{ 0106 /** 0107 * Function used to write out object persistently. 0108 * @param os the persistent output stream written to. 0109 */ 0110 void persistentOutput(PersistentOStream & os) const; 0111 0112 /** 0113 * Function used to read in object persistently. 0114 * @param is the persistent input stream read from. 0115 * @param version the version number of the object when written. 0116 */ 0117 void persistentInput(PersistentIStream & is, int version); 0118 //@} 0119 0120 /** 0121 * Standard Init function. 0122 */ 0123 static void Init(); 0124 0125 protected: 0126 0127 /** 0128 * Register an Interfaced object with the Repository. 0129 */ 0130 static void registerRepository(IBPtr); 0131 0132 /** 0133 * Register an Interfaced object with the Repository, giving it a 0134 * name. 0135 */ 0136 static void registerRepository(IBPtr, string newName); 0137 0138 /** 0139 * Register the given \a object in the Repository with the given \a 0140 * name in a subdirectory with the same name as this object. If an 0141 * object with that name already exists it will be removed unless 0142 * there are other objects referring to it, in which case it will be 0143 * renamed. 0144 */ 0145 void reporeg(IBPtr object, string name) const; 0146 0147 /** 0148 * If the pointer, \a ptr, to an object is not set, create an object 0149 * of class \a classname and register it with the Repository with 0150 * the given \a objectname in a sib-directory with the same name as 0151 * this object. 0152 */ 0153 template <typename PtrT> 0154 bool setDefaultReference(PtrT & ptr, string classname, string objectname) { 0155 if ( ptr ) return true; 0156 const ClassDescriptionBase * db = DescriptionList::find(classname); 0157 if ( !db ) return false; 0158 ptr = dynamic_ptr_cast<PtrT>(db->create()); 0159 if ( !ptr ) return false; 0160 reporeg(ptr, objectname); 0161 if ( !ptr->defaultInit() ) return false; 0162 return true; 0163 } 0164 0165 /** 0166 * Protected default constructor. 0167 */ 0168 Interfaced() : theUseFlag(false) {} 0169 0170 /** 0171 * Protected constructor taking a name as argument. 0172 */ 0173 Interfaced(const string & newName) 0174 : InterfacedBase(newName), theUseFlag(false) {} 0175 0176 /** 0177 * Protected copy-constructor. 0178 */ 0179 Interfaced(const Interfaced & i) 0180 : InterfacedBase(i), theGenerator(i.theGenerator), theUseFlag(false) {} 0181 0182 protected: 0183 0184 /** 0185 * Protected function to reset the generator pointer, required 0186 * for automatic decayer generation in Herwig++ BSM models 0187 */ 0188 void setGenerator(tEGPtr generator) { theGenerator=generator; } 0189 0190 private: 0191 0192 /** 0193 * Used internally by 'useMe' 0194 */ 0195 void setUsed() const; 0196 0197 /** 0198 * A pointer to the EventGenerator controlling the run. 0199 */ 0200 tEGPtr theGenerator; 0201 0202 /** 0203 * Flag to tell whether this object has been used or not. 0204 */ 0205 mutable bool theUseFlag; 0206 0207 /** 0208 * Command interface function which calls defaultInit(). 0209 */ 0210 string doDefaultInit(string); 0211 0212 private: 0213 0214 /** 0215 * Standard Initialization object. 0216 */ 0217 static AbstractClassDescription<Interfaced> initInterfaced; 0218 0219 /** 0220 * Private and non-existent assignment operator. 0221 */ 0222 Interfaced & operator=(const Interfaced &) = delete; 0223 0224 }; 0225 0226 /** @cond TRAITSPECIALIZATIONS */ 0227 0228 /** 0229 * This template specialization informs ThePEG about the 0230 * base class of Interfaced. 0231 */ 0232 template <> 0233 struct BaseClassTrait<Interfaced,1>: public ClassTraitsType { 0234 /** Typedef of the base class of Interfaced. */ 0235 typedef InterfacedBase NthBase; 0236 }; 0237 0238 /** 0239 * This template specialization informs ThePEG about the name of the 0240 * Interfaced class. 0241 */ 0242 template <> 0243 struct ClassTraits<Interfaced>: public ClassTraitsBase<Interfaced> { 0244 /** Return the class name. */ 0245 static string className() { return "ThePEG::Interfaced"; } 0246 }; 0247 0248 /** @endcond */ 0249 0250 } 0251 0252 #endif /* ThePEG_Interfaced_H */
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|