thepeg is hosted by Hepforge, IPPP Durham
ThePEG 2.3.0
HandlerGroup.h
1// -*- C++ -*-
2//
3// HandlerGroup.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_HandlerGroup_H
10#define ThePEG_HandlerGroup_H
11// This is the declaration of the HandlerGroup class.
12
14// #include "HandlerGroup.fh"
15// #include "HandlerGroup.xh"
16
17namespace ThePEG {
18
45
46public:
47
49 typedef pair<StepHdlPtr, HintPtr> StepWithHint;
50
52 typedef vector<StepHdlPtr> StepVector;
53
55 typedef vector<StepWithHint> StepHintVector;
56
58 typedef deque<HintPtr> HintVector;
59
60public:
61
66
71
75 bool empty() const { return isEmpty; }
76
82 void init(const HandlerGroupBase & ext) {
83 clear();
84 refillDefaults(ext);
85 }
86
91
99 const HandlerGroupBase & ext);
100
108 const HandlerGroupBase &);
109
115 void addHint(tHintPtr hint, const HandlerGroupBase & ext);
116
121
125 const StepVector & preHandlers() const { return theDefaultPreHandlers; }
126
130 virtual tStepHdlPtr defaultHandler() const = 0;
131
136
141
145 virtual tStepHdlPtr handler() const = 0;
146
150 virtual void setHandler() = 0;
151
156 virtual bool setHandler(tStepHdlPtr, const HandlerGroupBase & ext) = 0;
157
163
169
173 virtual void clear();
174
178 virtual string handlerClass() const = 0;
179
184
189
194
198 vector<StepHdlPtr> interfaceGetPrehandlers() const;
199
204
209
214
218 vector<StepHdlPtr> interfaceGetPosthandlers() const;
219
223 virtual void write(PersistentOStream &) const;
224
228 virtual void read(PersistentIStream &);
229
230protected:
231
236
241
242private:
243
248 void checkInsert(StepHintVector & current, const StepVector & def);
249
250protected:
251
256
261
266
271
276
277private:
278
283
284};
285
320template <typename HDLR>
322
323public:
324
326 typedef typename Ptr<HDLR>::pointer HdlPtr;
327
330
331public:
332
336 virtual ~HandlerGroup();
337
342 virtual bool setHandler(tStepHdlPtr, const HandlerGroupBase & ext);
343
347 virtual void setHandler() { theHandler = HdlPtr(); }
348
352 virtual tStepHdlPtr handler() const {
353 return dynamic_ptr_cast<tStepHdlPtr>(theHandler);
354 }
355
359 virtual tStepHdlPtr defaultHandler() const {
360 return dynamic_ptr_cast<tStepHdlPtr>(theDefaultHandler);
361 }
362
368
372 virtual void clear();
373
377 virtual string handlerClass() const;
378
383
388
392 virtual void write(PersistentOStream & os) const {
395 }
396
400 virtual void read(PersistentIStream & is) {
403 }
404
405private:
406
407
412
417
418private:
419
424
425};
426
428namespace Group {
429
438 decay
440
442enum Level {
445 after
447}
448
450template <typename HDLR>
452 const HandlerGroup<HDLR> & hg) {
453 hg.write(os);
454 return os;
455}
456
458template <typename HDLR>
460 HandlerGroup<HDLR> & hg) {
461 hg.read(is);
462 return is;
463}
464
465}
466
468#define ThePEG_DECLARE_PREPOST_GROUP(HandlerClass,prepost) \
469 \
470void interfaceSet##prepost##HandlerClass(StepHdlPtr, int); \
471 \
472void interfaceInsert##prepost##HandlerClass(StepHdlPtr, int); \
473 \
474void interfaceErase##prepost##HandlerClass(int); \
475 \
476vector<StepHdlPtr> interfaceGet##prepost##HandlerClass() const
477
479#define ThePEG_DECLARE_GROUPINTERFACE(HandlerClass,ptr) \
480ThePEG_DECLARE_PREPOST_GROUP(HandlerClass,Pre); \
481 \
482void interfaceSet##HandlerClass(ptr); \
483 \
484ptr interfaceGet##HandlerClass() const; \
485ThePEG_DECLARE_PREPOST_GROUP(HandlerClass,Post)
486
488#define ThePEG_IMPLEMENT_PREPOST_GROUP(ThisClass,HandlerClass,member,pp) \
489void ThisClass::interfaceSet##pp##HandlerClass(StepHdlPtr p , int i) { \
490 member.interfaceSet##pp##handler(p,i); \
491} \
492void ThisClass::interfaceInsert##pp##HandlerClass(StepHdlPtr p, int i) { \
493 member.interfaceInsert##pp##handler(p,i); \
494} \
495void ThisClass::interfaceErase##pp##HandlerClass(int i) { \
496 member.interfaceErase##pp##handler(i); \
497} \
498vector<StepHdlPtr> ThisClass::interfaceGet##pp##HandlerClass() const { \
499 return member.interfaceGet##pp##handlers(); \
500}
501
503#define ThePEG_IMPLEMENT_GROUPINTERFACE(ThisClass,HandlerClass,member,ptr) \
504ThePEG_IMPLEMENT_PREPOST_GROUP(ThisClass,HandlerClass,member,Pre) \
505void ThisClass::interfaceSet##HandlerClass(ptr p) { \
506 member.interfaceSetHandler(p); \
507} \
508ptr ThisClass::interfaceGet##HandlerClass() const { \
509 return member.interfaceGetHandler(); \
510} \
511ThePEG_IMPLEMENT_PREPOST_GROUP(ThisClass,HandlerClass,member,Post) \
512
514#define ThePEG_DECLARE_PREPOST_OBJECTS(ThisClass,HandlerClass,pp,ba) \
515static RefVector<ThisClass,StepHandler> interface##pp##HandlerClass \
516(#pp #HandlerClass "s", \
517 "A list of handlers to be called " #ba " the " #HandlerClass ". " \
518 "If handler objects are specified in a EventHandler and " \
519 "the SubProcessHandler chosen in a given collision also specifies some, " \
520 "the latter will caled first.", \
521 0, 0, false, false, true, false, \
522 &ThisClass::interfaceSet##pp##HandlerClass, \
523 &ThisClass::interfaceInsert##pp##HandlerClass, \
524 &ThisClass::interfaceErase##pp##HandlerClass, \
525 &ThisClass::interfaceGet##pp##HandlerClass)
526
528#define ThePEG_DECLARE_GROUPINTERFACE_OBJECTS(ThisClass,HandlerClass) \
529ThePEG_DECLARE_PREPOST_OBJECTS(ThisClass,HandlerClass,Pre, before); \
530static Reference<ThisClass,HandlerClass> interface ## HandlerClass \
531(#HandlerClass, \
532 "The " #HandlerClass " object used in this " #ThisClass ". " \
533 "If a " #HandlerClass " object is specified in a EventHandler and " \
534 "the SubProcessHandler chosen in a given collision also specifies one," \
535 "the latter will be used.", \
536 0, false, false, true, true, \
537 &ThisClass::interfaceSet ## HandlerClass, \
538 &ThisClass::interfaceGet ## HandlerClass); \
539ThePEG_DECLARE_PREPOST_OBJECTS(ThisClass,HandlerClass,Post, after)
540
541#ifndef ThePEG_TEMPLATES_IN_CC_FILE
542#include "HandlerGroup.tcc"
543#endif
544
545#endif /* ThePEG_HandlerGroup_H */
This is the main config header file for ThePEG.
HandlerGroupBase is the base class for the templated HandlerGroup utility class to manage a group of ...
Definition: HandlerGroup.h:44
void interfaceErasePrehandler(int i)
Utility function used for the interface.
void refillDefaults(const HandlerGroupBase &)
Fill main, pre- and post- handlers with the default ones.
StepVector & postHandlers()
Return a reference to the list of default post-handlers.
Definition: HandlerGroup.h:135
StepVector theDefaultPreHandlers
The default pre-handlers with hints.
Definition: HandlerGroup.h:255
virtual void read(PersistentIStream &)
Read from persistent streams.
void addHint(tHintPtr hint, const HandlerGroupBase &ext)
Add a hint to the currently selected main handler.
StepWithHint next()
Return the next step;.
bool isEmpty
True if the current handlers are empty.
Definition: HandlerGroup.h:240
vector< StepHdlPtr > StepVector
A vector of StepHandler objects.
Definition: HandlerGroup.h:52
void interfaceSetPrehandler(StepHdlPtr p, int i)
Utility function used for the interface.
void init(const HandlerGroupBase &ext)
Initialize, taking the default StepHandlers as the current ones, possibly overridden by the default o...
Definition: HandlerGroup.h:82
StepHintVector thePostHandlers
The current post-handlers with hints.
Definition: HandlerGroup.h:275
void interfaceSetPosthandler(StepHdlPtr p, int i)
Utility function used for the interface.
virtual void clear()
Clear all current handlers, but don't touch the default ones.
virtual tStepHdlPtr handler() const =0
Return a pointer to the current main handler.
void checkInsert(StepHintVector &current, const StepVector &def)
Add handlers from the def vector to the current, supplying them with default hints.
HandlerGroupBase(const HandlerGroupBase &)
The copy constructor is only used via subclasses.
deque< HintPtr > HintVector
A vector of Hint objects.
Definition: HandlerGroup.h:58
virtual void setHandler()=0
Unset the current main handler.
bool empty() const
Returns true if current selections in this group is empty.
Definition: HandlerGroup.h:75
virtual bool setHandler(tStepHdlPtr, const HandlerGroupBase &ext)=0
Set the current main handler, but also refill the current pre- and post- handlers with the defaults f...
StepVector & preHandlers()
Return a reference to the list of default pre-handlers.
Definition: HandlerGroup.h:120
const StepVector & preHandlers() const
Return a reference to the list of default pre-handlers.
Definition: HandlerGroup.h:125
HintVector theHints
The current hints for the main handler.
Definition: HandlerGroup.h:270
virtual void write(PersistentOStream &) const
Write to persistent streams.
const StepVector & postHandlers() const
Return a reference to the list of default post-handlers.
Definition: HandlerGroup.h:140
vector< StepWithHint > StepHintVector
A vector of StepHandler objects associated with Hint objects.
Definition: HandlerGroup.h:55
void addPreHandler(tStepHdlPtr sh, tHintPtr hint, const HandlerGroupBase &ext)
Add a step handler, sh to the current list of pre-handlers.
HandlerGroupBase()
Default constructor.
void interfaceInsertPosthandler(StepHdlPtr p, int i)
Utility function used for the interface.
virtual string handlerClass() const =0
Return the base class name of the main handler type.
HandlerGroupBase & operator=(const HandlerGroupBase &)=delete
Assignment is private.
vector< StepHdlPtr > interfaceGetPrehandlers() const
Utility function used for the interface.
StepHintVector thePreHandlers
The current pre-handlers with hints.
Definition: HandlerGroup.h:265
virtual tStepHdlPtr defaultHandler() const =0
Return a pointer to the default main handler.
virtual void refillDefaultHandler(tStepHdlPtr)=0
Set the current main handler.
void interfaceInsertPrehandler(StepHdlPtr p, int i)
Utility function used for the interface.
pair< StepHdlPtr, HintPtr > StepWithHint
Associate a StepHandler with a Hint object.
Definition: HandlerGroup.h:49
void interfaceErasePosthandler(int i)
Utility function used for the interface.
void addPostHandler(tStepHdlPtr sh, tHintPtr hint, const HandlerGroupBase &)
Add a step handler, sh, to the current list of post-handlers.
virtual ~HandlerGroupBase()
Destructor.
vector< StepHdlPtr > interfaceGetPosthandlers() const
Utility function used for the interface.
StepVector theDefaultPostHandlers
The default post-handlers with hints.
Definition: HandlerGroup.h:260
HandlerGroup is a templated utility class to manage a group of StepHandlers.
Definition: HandlerGroup.h:321
HdlPtr theHandler
The current main handler.
Definition: HandlerGroup.h:416
virtual void read(PersistentIStream &is)
Read from persistent streams.
Definition: HandlerGroup.h:400
virtual tStepHdlPtr defaultHandler() const
Return a pointer to the default main handler.
Definition: HandlerGroup.h:359
HdlPtr interfaceGetHandler() const
Utility function used for the interface.
virtual tStepHdlPtr handler() const
Return a pointer to the current main handler.
Definition: HandlerGroup.h:352
virtual bool setHandler(tStepHdlPtr, const HandlerGroupBase &ext)
Set the current main handler.
Ptr< HDLR >::pointer HdlPtr
A pointer to the template argument class.
Definition: HandlerGroup.h:326
virtual void setHandler()
Unset the current main handler.
Definition: HandlerGroup.h:347
Ptr< HDLR >::transient_pointer tHdlPtr
A transient pointer to the template argument class.
Definition: HandlerGroup.h:329
virtual void clear()
Clear all current handlers, but don't touch the default ones.
virtual ~HandlerGroup()
Destructor.
HandlerGroup< HDLR > & operator=(const HandlerGroup< HDLR > &)=delete
Assignment is private.
HdlPtr theDefaultHandler
The default main handler.
Definition: HandlerGroup.h:411
virtual string handlerClass() const
Return the base class name of the main handler type.
void interfaceSetHandler(HdlPtr)
Utility function used for the interface.
virtual void refillDefaultHandler(tStepHdlPtr)
Set the current main handler.
virtual void write(PersistentOStream &os) const
Write to persistent streams.
Definition: HandlerGroup.h:392
PersistentIStream is used to read persistent objects from a stream where they were previously written...
PersistentOStream is used to write objects persistently to a stream from which they can be read in ag...
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
Handler
Enumeration for the type of HandlerGroups.
Definition: HandlerGroup.h:433
@ multi
The MultipleInteractionHandler group.
Definition: HandlerGroup.h:436
@ decay
The DecayHandler group.
Definition: HandlerGroup.h:438
@ hadron
The HadronizationHandler group.
Definition: HandlerGroup.h:437
@ cascade
The CascadeHandler group.
Definition: HandlerGroup.h:435
@ subproc
The sub-process group.
Definition: HandlerGroup.h:434
Level
Enumeration for the type of step handler.
Definition: HandlerGroup.h:442
@ after
A post-handler.
Definition: HandlerGroup.h:445
@ main
The mainhandler.
Definition: HandlerGroup.h:444
@ before
A pre-handler.
Definition: HandlerGroup.h:443
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
vector< T > & operator>>(vector< T > &tv, U &u)
Overload the right shift operator for vector to pop objects from a vector.
Definition: Containers.h:192
vector< T > & operator<<(vector< T > &tv, const U &u)
Overload the left shift operator for vector to push_back objects to a vector.
Definition: Containers.h:179