14 #ifndef DD4HEP_DDG4_GEANT4ACTION_H
15 #define DD4HEP_DDG4_GEANT4ACTION_H
29 class G4EventGenerator;
31 class G4TrackingManager;
42 namespace Simulation {
45 class Geant4UIMessenger;
48 template <
typename TO,
typename FROM> TO
fast_cast(FROM from) {
50 return static_cast<TO
>(from);
52 return dynamic_cast<TO
>(from);
62 class TypeName :
public std::pair<std::string, std::string> {
69 TypeName(
const std::pair<std::string, std::string>& c)
70 : std::pair<std::string, std::string>(c) { }
72 TypeName(
const std::string& typ,
const std::string& nam)
73 : std::pair<std::string, std::string>(typ, nam) { }
79 static TypeName split(
const std::string& type_name,
const std::string& delim);
148 typedef typename std::vector<T*>
_V;
155 operator const _V&()
const {
return m_v; }
159 typename _V::iterator
begin() {
return m_v.begin(); }
160 typename _V::iterator
end() {
return m_v.end(); }
161 typename _V::const_iterator
begin()
const {
return m_v.begin(); }
162 typename _V::const_iterator
end()
const {
return m_v.end(); }
166 (*this)(&T::updateContext,ctxt);
169 template <
typename F>
typename _V::value_type
get(
const F& f)
const {
171 typename _V::const_iterator i=std::find_if(
m_v.begin(),
m_v.end(),f);
172 return i==
m_v.end() ? 0 : (*i);
177 template <
typename R,
typename Q>
void operator()(R (Q::*pmf)()) {
180 for (
typename _V::iterator i =
m_v.begin(); i !=
m_v.end(); ++i)
183 template <
typename R,
typename Q,
typename A0>
void operator()(R (Q::*pmf)(A0), A0 a0) {
186 for (
typename _V::iterator i =
m_v.begin(); i !=
m_v.end(); ++i)
189 template <
typename R,
typename Q,
typename A0,
typename A1>
void operator()(R (Q::*pmf)(A0, A1), A0 a0, A1 a1) {
192 for (
typename _V::iterator i =
m_v.begin(); i !=
m_v.end(); ++i)
193 ((*i)->*pmf)(a0, a1);
196 template <
typename R,
typename Q>
void operator()(R (Q::*pmf)()
const)
const {
199 for (
typename _V::const_iterator i =
m_v.begin(); i !=
m_v.end(); ++i)
202 template <
typename R,
typename Q,
typename A0>
void operator()(R (Q::*pmf)(A0)
const, A0 a0)
const {
205 for (
typename _V::const_iterator i =
m_v.begin(); i !=
m_v.end(); ++i)
208 template <
typename R,
typename Q,
typename A0,
typename A1>
void operator()(R (Q::*pmf)(A0, A1)
const, A0 a0,
212 for (
typename _V::const_iterator i =
m_v.begin(); i !=
m_v.end(); ++i)
213 ((*i)->*pmf)(a0, a1);
216 template <
typename Q>
bool filter(
bool (Q::*pmf)()
const)
const {
219 for (
typename _V::const_iterator i =
m_v.begin(); i !=
m_v.end(); ++i)
224 template <
typename Q,
typename A0>
bool filter(
bool (Q::*pmf)(A0)
const, A0 a0)
const {
227 for (
typename _V::const_iterator i =
m_v.begin(); i !=
m_v.end(); ++i)
228 if (!((*i)->*pmf)(a0))
232 template <
typename Q,
typename A0,
typename A1>
bool filter(
bool (Q::*pmf)(A0, A1)
const, A0 a0, A1 a1)
const {
235 for (
typename _V::const_iterator i =
m_v.begin(); i !=
m_v.end(); ++i)
236 if (!((*i)->*pmf)(a0, a1))
271 const std::string&
name()
const {
315 void print(
const char* fmt, ...)
const;
317 void printM1(
const char* fmt, ...)
const;
319 void printM2(
const char* fmt, ...)
const;
321 void printP1(
const char* fmt, ...)
const;
323 void printP2(
const char* fmt, ...)
const;
326 void debug(
const char* fmt, ...)
const;
328 void info(
const char* fmt, ...)
const;
330 void warning(
const char* fmt, ...)
const;
332 void error(
const char* fmt, ...)
const;
334 bool return_error(
bool return_value,
const char* fmt, ...)
const;
336 void fatal(
const char* fmt, ...)
const;
338 void except(
const char* fmt, ...)
const;
341 void abortRun(
const std::string& exception,
const char* fmt, ...)
const;
371 #endif // DD4HEP_DDG4_GEANT4ACTION_H
Functor to access elements by name.
void add(const std::string &name, const Property &property)
Add a new property.
virtual void enableUI()
Enable and install UI messenger.
PrintLevel outputLevel() const
Access the output level.
long m_refCount
Reference count. Initial value: 1.
The property class to assign options to actions.
void printM1(const char *fmt,...) const
Support for messages with variable output level using output level-1.
Concrete implementation of the Geant4 stepping action sequence.
long release()
Decrease reference count. Implicit destruction.
bool filter(bool(Q::*pmf)(A0) const, A0 a0) const
_V::const_iterator end() const
Geant4TrackingActionSequence & trackingAction() const
Access to the main tracking action sequence from the kernel object.
TypeName(const std::pair< std::string, std::string > &c)
Copy constructor from pair.
void operator()(R(Q::*pmf)(A0, A1), A0 a0, A1 a1)
Geant4Context * context
reference to the context;
void operator()(R(Q::*pmf)(A0) const, A0 a0) const
Helper class to handle strings of the format "type/name".
Geant4GeneratorActionSequence & generatorAction() const
Access to the main generator action sequence from the kernel object.
virtual void installPropertyMessenger()
Install property control messenger if wanted.
Geant4UIMessenger * control() const
Access to the UI messenger.
void warning(const char *fmt,...) const
Support of warning messages.
Concrete implementation of the Geant4 event action sequence.
ContextSwap(Geant4Action *a, Geant4Context *c)
Constructor.
void error(const char *fmt,...) const
Support of error messages.
const char * c_name() const
Access name of the action.
Geant4Context * context() const
Access the context.
Concrete implementation of the Geant4 tracking action sequence.
TO fast_cast(FROM from)
Cast operator.
void printP2(const char *fmt,...) const
Support for messages with variable output level using output level+2.
const std::string & name() const
Access name of the action.
Geant4Context * m_context
Reference to the Geant4 context.
void print(const char *fmt,...) const
Support for messages with variable output level using output level.
void except(const char *fmt,...) const
Support of exceptions: Print fatal message and throw runtime_error.
int m_outputLevel
Default property: Output level.
Concrete implementation of the Geant4 stacking action sequence.
PropertyManager & properties()
Access to the properties of the object.
Geant4Action & setProperties(PropertyConfigurator &setup)
Set object properties.
bool hasProperty(const std::string &name) const
Check property for existence.
void setName(const std::string &new_name)
Set the object name.
virtual void updateContext(Geant4Context *ctxt)
Set or update client context.
virtual void configureFiber(Geant4Context *thread_context)
Set or update client for the use in a new thread fiber.
long addRef()
Increase reference count.
Property & property(const std::string &name)
Access single property.
~ContextSwap()
Destructor.
Geant4StackingActionSequence & stackingAction() const
Access to the main stacking action sequence from the kernel object.
Geant4SteppingActionSequence & steppingAction() const
Access to the main stepping action sequence from the kernel object.
bool return_error(bool return_value, const char *fmt,...) const
Action to support error messages.
virtual void installCommandMessenger()
Install command control messenger if wanted.
virtual ~Geant4Action()
Default destructor.
bool operator()(const Geant4Action *a)
Concrete implementation of the Geant4 generator action sequence.
bool m_needsControl
Default property: Flag to create control instance.
Concrete basic implementation of the Geant4 run action sequencer.
Geant4Action & operator=(const Geant4Action ©)=delete
Inhibit assignment operator.
Heler class to configure properties.
Functor to update the context of a Geant4Action object.
PrintLevel setOutputLevel(PrintLevel new_level)
Set the output level; returns previous value.
static TypeName split(const std::string &type_name)
Split string pair according to default delimiter ('/')
Geant4Action()=default
Inhibit default constructor.
virtual void installMessengers()
Install property control messenger if wanted.
Geant4RunActionSequence & runAction() const
Access to the main run action sequence from the kernel object.
void operator()(R(Q::*pmf)() const) const
CONST actions.
TypeName & operator=(const TypeName ©)=default
Assignment operator.
void fatal(const char *fmt,...) const
Support of fatal messages. Throws exception.
Generic context to extend user, run and event information.
TypeName(const std::string &typ, const std::string &nam)
Initializing constructor.
PropertyManager m_properties
Property pool.
std::string m_name
Action name.
void abortRun(const std::string &exception, const char *fmt,...) const
Abort Geant4 Run by throwing a G4Exception with type RunMustBeAborted.
void info(const char *fmt,...) const
Support of info messages.
void operator()(R(Q::*pmf)(A0), A0 a0)
Geant4EventActionSequence & eventAction() const
Access to the main event action sequence from the kernel object.
void operator()(R(Q::*pmf)())
NON-CONST actions.
Generic implementation to export properties and actions to the Geant4 command prompt.
void operator()(R(Q::*pmf)(A0, A1) const, A0 a0, A1 a1) const
FindByName(const std::string &n)
bool filter(bool(Q::*pmf)(A0, A1) const, A0 a0, A1 a1) const
void updateContext(Geant4Context *ctxt)
Context updates.
Geant4Action & declareProperty(const std::string &nam, T &val)
Declare property.
Manager to ease the handling of groups of properties.
_V::const_iterator begin() const
Default base class for all Geant 4 actions and derivates thereof.
void printP1(const char *fmt,...) const
Support for messages with variable output level using output level+1.
const _V * operator->() const
void debug(const char *fmt,...) const
Support of debug messages.
bool filter(bool(Q::*pmf)() const) const
CONST filters.
Geant4UIMessenger * m_control
Control directory of this action.
TypeName()=default
Default constructor.
void printM2(const char *fmt,...) const
Support for messages with variable output level using output level-2.
Actor class to manipulate action groups.