thepeg is hosted by Hepforge, IPPP Durham
ThePEG 2.3.0
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
16namespace ThePEG {
17
34
35public:
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
67public:
68
73 static bool isVoid() {
74 return theGeneratorStack.empty() || !(theGeneratorStack.back());
75 }
76
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
195public:
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
254private:
255
259 static vector<EGPtr> theGeneratorStack;
260
266
267private:
268
273
274};
275
276}
277
278#endif /* ThePEG_CurrentGenerator_H */
Class used to temporarily redirect a given ostream to the misc() stream of the current EventGenerator...
ostringstream intStream
An internal buffer, the content of which will be discarded when the this object is destructed.
ostream * theStream
The stream which is redirected.
~Redirect()
The destructor which restores the original destination of the stream.
string str() const
If output is stored internally, acces what has been written so far.
std::streambuf * theBuffer
The original buffer of the redirected stream.
Redirect(ostream &os, bool internal=false)
Constructor taking the stream to be redirected as input.
This CurrentGenerator class keeps a static stack of EventGenerators which can be used anywhere by any...
static IBPtr getPointer(string name)
Get object.
static vector< EGPtr > theGeneratorStack
The stack of EventGenerators requested.
bool generatorPushed
True if this object is responsible for pushing a EventGenerator onto the stack.
EventGenerator & operator*() const
Return a reference to the currently chosen object.
static tStrategyPtr strategy()
Return a pointer to the strategy object containing eg.
static EventGenerator * ptr()
Pointer to the stack.
EventGenerator * operator->() const
Return a pointer to the currently chosen object.
static ostream & ref()
Get the current standard ref stream.
bool operator!() const
Test for existance.
~CurrentGenerator()
The destructor removing the EventGenerator specified in the constructor from the stack.
static bool isVoid()
Returns true if there is no currently chosen EventGenerator object.
static tSMPtr standardModel()
Return a pointer to the standard model parameters used by the current generator.
static Ptr< T >::pointer getPtr(const T &t)
Get object.
static ostream & log()
Get the current standard log stream.
CurrentGenerator(const CurrentGenerator &)
Copy-constructor does nothing.
CurrentGenerator()
Default constructor does nothing.
static EventGenerator & current()
Return a reference to the currently chosen EventGenerator object.
static Ptr< T >::pointer getDefault()
Get default object.
static Ptr< T >::pointer getObject(string name)
Get object.
CurrentGenerator(const EGPtr &eg)
Construct a new object specifying a new EventGenerator, eg, to be used during this objects lifetime.
CurrentGenerator & operator=(const CurrentGenerator &)=delete
Private and non-existent assignment operator.
static ostream & out()
Get the current standard output stream.
The EventGenerator class manages a whole event generator run.
Ptr< T >::pointer getPtr(const T &) const
Return a garbage collected pointer to a given 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...
ostream & ref()
Return a reference to the stream connected to the filea for references from used objects.
tStrategyPtr strategy() const
Return a pointer to the strategy object containing a set of non-default particles to use.
IBPtr getPointer(string name) const
Return a pointer to an object present in this run given its full name.
tSMPtr standardModel() const
Return a pointer to the standard model parameters.
Ptr< T >::pointer getDefault() const
Return the default object for class T.
ostream & log()
Return a reference to the stream connected to the file for logging information.
RCPtr is a reference counted (smart) pointer.
Definition: RCPtr.h:60
TransientRCPtr is a simple wrapper around a bare pointer which can be assigned to and from an RCPtr a...
Definition: RCPtr.h:519
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28