thepeg is hosted by Hepforge, IPPP Durham
ThePEG  2.2.1
CurrentGenerator.h
1 // -*- C++ -*-
2 //
3 // CurrentGenerator.h is a part of ThePEG - Toolkit for HEP Event Generation
4 // Copyright (C) 1999-2019 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_CurrentGenerator_H
10 #define ThePEG_CurrentGenerator_H
11 // This is the declaration of the CurrentGenerator class.
12 
13 #include "ThePEG/Repository/EventGenerator.h"
14 #include "CurrentGenerator.fh"
15 
16 namespace ThePEG {
17 
34 
35 public:
36 
41 
46  : generatorPushed(false) {}
47 
52  CurrentGenerator(const EGPtr & eg) : generatorPushed(false) {
53  if ( eg ) {
54  theGeneratorStack.push_back(eg);
55  generatorPushed = true;
56  }
57  }
58 
64  if ( generatorPushed ) theGeneratorStack.pop_back();
65  }
66 
67 public:
68 
73  static bool isVoid() {
74  return theGeneratorStack.empty() || !(theGeneratorStack.back());
75  }
76 
80  static EventGenerator & current() {
81  return *theGeneratorStack.back();
82  }
83 
88  return *theGeneratorStack.back();
89  }
90 
95  return theGeneratorStack.back();
96  }
97 
101  static EventGenerator * ptr() {
102  return theGeneratorStack.back();
103  }
104 
108  operator bool() const {
109  return ptr();
110  }
111 
115  bool operator!() const {
116  return !ptr();
117  }
118 
124  return current().standardModel();
125  }
126 
131  static tStrategyPtr strategy() { return current().strategy(); }
132 
139  static ostream & out() { return current().out(); }
140 
147  static ostream & log() { return current().log(); }
148 
155  static ostream & ref() { return current().ref(); }
156 
162  template <typename T>
163  static typename Ptr<T>::pointer getPtr(const T & t) {
164  return current().getPtr(t);
165  }
166 
172  static IBPtr getPointer(string name) {
173  return current().getPointer(name);
174  }
175 
181  template <typename T>
182  static typename Ptr<T>::pointer getObject(string name) {
183  return current().getObject<T>(name);
184  }
185 
190  template <typename T>
191  static typename Ptr<T>::pointer getDefault() {
192  return current().getDefault<T>();
193  }
194 
195 public:
196 
201  class Redirect {
202 
203  public:
204 
213  Redirect(ostream & os, bool internal = false)
214  : theStream(&os), theBuffer(os.rdbuf()) {
215  if ( internal ) theStream->rdbuf(intStream.rdbuf());
216  else if ( !current().useStdOut() )
217  theStream->rdbuf(current().misc().rdbuf());
218  }
219 
225  theStream->rdbuf(theBuffer);
226  }
227 
232  string str() const {
233  return intStream.str();
234  }
235 
239  ostream * theStream;
240 
244  std::streambuf * theBuffer;
245 
250  ostringstream intStream;
251 
252  };
253 
254 private:
255 
259  static vector<EGPtr> theGeneratorStack;
260 
266 
267 private:
268 
272  CurrentGenerator & operator=(const CurrentGenerator &) = delete;
273 
274 };
275 
276 }
277 
278 #endif /* ThePEG_CurrentGenerator_H */
static IBPtr getPointer(string name)
Get object.
Ptr< T >::pointer getObject(string name) const
Return a pointer to an object of type T present in this run given its full name.
ostream & out()
This stream should be used for output of information and statistics of an EventGenerator run in the f...
static ostream & out()
Get the current standard output stream.
static Ptr< T >::pointer getObject(string name)
Get object.
bool useStdOut() const
Has the generator been asked to redirect everything to standard output?
CurrentGenerator(const CurrentGenerator &)
Copy-constructor does nothing.
string str() const
If output is stored internally, acces what has been written so far.
TransientRCPtr is a simple wrapper around a bare pointer which can be assigned to and from an RCPtr a...
Definition: RCPtr.h:519
ostream & log()
Return a reference to the stream connected to the file for logging information.
static vector< EGPtr > theGeneratorStack
The stack of EventGenerators requested.
~Redirect()
The destructor which restores the original destination of the stream.
ostream * theStream
The stream which is redirected.
ostringstream intStream
An internal buffer, the content of which will be discarded when the this object is destructed...
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
static EventGenerator * ptr()
Pointer to the stack.
static tSMPtr standardModel()
Return a pointer to the standard model parameters used by the current generator.
bool operator!() const
Test for existance.
static ostream & log()
Get the current standard log stream.
CurrentGenerator & operator=(const CurrentGenerator &)=delete
Private and non-existent assignment operator.
ostream & ref()
Return a reference to the stream connected to the filea for references from used objects.
IBPtr getPointer(string name) const
Return a pointer to an object present in this run given its full name.
EventGenerator & operator*() const
Return a reference to the currently chosen object.
std::streambuf * theBuffer
The original buffer of the redirected stream.
EventGenerator * operator->() const
Return a pointer to the currently chosen object.
Class used to temporarily redirect a given ostream to the misc() stream of the current EventGenerator...
tStrategyPtr strategy() const
Return a pointer to the strategy object containing a set of non-default particles to use...
RCPtr is a reference counted (smart) pointer.
Definition: RCPtr.h:60
static EventGenerator & current()
Return a reference to the currently chosen EventGenerator object.
CurrentGenerator()
Default constructor does nothing.
static Ptr< T >::pointer getPtr(const T &t)
Get object.
Ptr< T >::pointer getDefault() const
Return the default object for class T.
This CurrentGenerator class keeps a static stack of EventGenerators which can be used anywhere by any...
~CurrentGenerator()
The destructor removing the EventGenerator specified in the constructor from the stack.
Ptr< T >::pointer getPtr(const T &) const
Return a garbage collected pointer to a given object.
static tStrategyPtr strategy()
Return a pointer to the strategy object containing eg.
static bool isVoid()
Returns true if there is no currently chosen EventGenerator object.
CurrentGenerator(const EGPtr &eg)
Construct a new object specifying a new EventGenerator, eg, to be used during this objects lifetime...
bool generatorPushed
True if this object is responsible for pushing a EventGenerator onto the stack.
static ostream & ref()
Get the current standard ref stream.
tSMPtr standardModel() const
Return a pointer to the standard model parameters.
Redirect(ostream &os, bool internal=false)
Constructor taking the stream to be redirected as input.
static Ptr< T >::pointer getDefault()
Get default object.
The EventGenerator class manages a whole event generator run.