ThePEG  1.8.0
HandlerGroup.h
1 // -*- C++ -*-
2 //
3 // HandlerGroup.h is a part of ThePEG - Toolkit for HEP Event Generation
4 // Copyright (C) 1999-2011 Leif Lonnblad
5 //
6 // ThePEG is licenced under version 2 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 
13 #include "ThePEG/Config/ThePEG.h"
14 // #include "HandlerGroup.fh"
15 // #include "HandlerGroup.xh"
16 
17 namespace ThePEG {
18 
45 
46 public:
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 
60 public:
61 
66 
70  virtual ~HandlerGroupBase();
71 
75  bool empty() const { return isEmpty; }
76 
82  void init(const HandlerGroupBase & ext) {
83  clear();
84  refillDefaults(ext);
85  }
86 
90  StepWithHint next();
91 
98  void addPreHandler(tStepHdlPtr sh, tHintPtr hint,
99  const HandlerGroupBase & ext);
100 
107  void addPostHandler(tStepHdlPtr sh, tHintPtr hint,
108  const HandlerGroupBase &);
109 
115  void addHint(tHintPtr hint, const HandlerGroupBase & ext);
116 
120  StepVector & preHandlers() { return theDefaultPreHandlers; }
121 
125  const StepVector & preHandlers() const { return theDefaultPreHandlers; }
126 
130  virtual tStepHdlPtr defaultHandler() const = 0;
131 
135  StepVector & postHandlers() { return theDefaultPostHandlers; }
136 
140  const StepVector & postHandlers() const { return theDefaultPostHandlers; }
141 
145  virtual tStepHdlPtr handler() const = 0;
146 
150  virtual void setHandler() = 0;
151 
156  virtual bool setHandler(tStepHdlPtr, const HandlerGroupBase & ext) = 0;
157 
162  virtual void refillDefaultHandler(tStepHdlPtr) = 0;
163 
168  void refillDefaults(const HandlerGroupBase &);
169 
173  virtual void clear();
174 
178  virtual string handlerClass() const = 0;
179 
183  void interfaceSetPrehandler(StepHdlPtr p, int i);
184 
188  void interfaceInsertPrehandler(StepHdlPtr p, int i);
189 
193  void interfaceErasePrehandler(int i);
194 
198  vector<StepHdlPtr> interfaceGetPrehandlers() const;
199 
203  void interfaceSetPosthandler(StepHdlPtr p, int i);
204 
208  void interfaceInsertPosthandler(StepHdlPtr p, int i);
209 
213  void interfaceErasePosthandler(int i);
214 
218  vector<StepHdlPtr> interfaceGetPosthandlers() const;
219 
223  virtual void write(PersistentOStream &) const;
224 
228  virtual void read(PersistentIStream &);
229 
230 protected:
231 
236 
240  bool isEmpty;
241 
242 private:
243 
248  void checkInsert(StepHintVector & current, const StepVector & def);
249 
250 protected:
251 
256 
261 
265  StepHintVector thePreHandlers;
266 
270  HintVector theHints;
271 
275  StepHintVector thePostHandlers;
276 
277 private:
278 
283 
284 };
285 
320 template <typename HDLR>
322 
323 public:
324 
326  typedef typename Ptr<HDLR>::pointer HdlPtr;
327 
330 
331 public:
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 {
354  }
355 
359  virtual tStepHdlPtr defaultHandler() const {
361  }
362 
367  virtual void refillDefaultHandler(tStepHdlPtr);
368 
372  virtual void clear();
373 
377  virtual string handlerClass() const;
378 
382  void interfaceSetHandler(HdlPtr);
383 
387  HdlPtr interfaceGetHandler() const;
388 
392  virtual void write(PersistentOStream & os) const {
393  os << theDefaultHandler << theHandler;
395  }
396 
400  virtual void read(PersistentIStream & is) {
401  is >> theDefaultHandler >> theHandler;
403  }
404 
405 private:
406 
407 
412 
416  HdlPtr theHandler;
417 
418 private:
419 
424 
425 };
426 
428 namespace Group {
429 
433 enum Handler {
439 };
440 
442 enum Level {
446 };
447 }
448 
450 template <typename HDLR>
452  const HandlerGroup<HDLR> & hg) {
453  hg.write(os);
454  return os;
455 }
456 
458 template <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  \
470 void interfaceSet##prepost##HandlerClass(StepHdlPtr, int); \
471  \
472 void interfaceInsert##prepost##HandlerClass(StepHdlPtr, int); \
473  \
474 void interfaceErase##prepost##HandlerClass(int); \
475  \
476 vector<StepHdlPtr> interfaceGet##prepost##HandlerClass() const
477 
479 #define ThePEG_DECLARE_GROUPINTERFACE(HandlerClass,ptr) \
480 ThePEG_DECLARE_PREPOST_GROUP(HandlerClass,Pre); \
481  \
482 void interfaceSet##HandlerClass(ptr); \
483  \
484 ptr interfaceGet##HandlerClass() const; \
485 ThePEG_DECLARE_PREPOST_GROUP(HandlerClass,Post)
486 
488 #define ThePEG_IMPLEMENT_PREPOST_GROUP(ThisClass,HandlerClass,member,pp) \
489 void ThisClass::interfaceSet##pp##HandlerClass(StepHdlPtr p , int i) { \
490  member.interfaceSet##pp##handler(p,i); \
491 } \
492 void ThisClass::interfaceInsert##pp##HandlerClass(StepHdlPtr p, int i) { \
493  member.interfaceInsert##pp##handler(p,i); \
494 } \
495 void ThisClass::interfaceErase##pp##HandlerClass(int i) { \
496  member.interfaceErase##pp##handler(i); \
497 } \
498 vector<StepHdlPtr> ThisClass::interfaceGet##pp##HandlerClass() const { \
499  return member.interfaceGet##pp##handlers(); \
500 }
501 
503 #define ThePEG_IMPLEMENT_GROUPINTERFACE(ThisClass,HandlerClass,member,ptr) \
504 ThePEG_IMPLEMENT_PREPOST_GROUP(ThisClass,HandlerClass,member,Pre) \
505 void ThisClass::interfaceSet##HandlerClass(ptr p) { \
506  member.interfaceSetHandler(p); \
507 } \
508 ptr ThisClass::interfaceGet##HandlerClass() const { \
509  return member.interfaceGetHandler(); \
510 } \
511 ThePEG_IMPLEMENT_PREPOST_GROUP(ThisClass,HandlerClass,member,Post) \
512 
513 
514 #define ThePEG_DECLARE_PREPOST_OBJECTS(ThisClass,HandlerClass,pp,ba) \
515 static 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) \
529 ThePEG_DECLARE_PREPOST_OBJECTS(ThisClass,HandlerClass,Pre, before); \
530 static 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); \
539 ThePEG_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 */
PersistentIStream is used to read persistent objects from a stream where they were previously written...
void addPostHandler(tStepHdlPtr sh, tHintPtr hint, const HandlerGroupBase &)
Add a step handler, sh, to the current list of post-handlers.
virtual void write(PersistentOStream &) const
Write to persistent streams.
StepVector & preHandlers()
Return a reference to the list of default pre-handlers.
Definition: HandlerGroup.h:120
void interfaceSetHandler(HdlPtr)
Utility function used for the interface.
HdlPtr theDefaultHandler
The default main handler.
Definition: HandlerGroup.h:411
void interfaceErasePrehandler(int i)
Utility function used for the interface.
StepVector & postHandlers()
Return a reference to the list of default post-handlers.
Definition: HandlerGroup.h:135
deque< HintPtr > HintVector
A vector of Hint objects.
Definition: HandlerGroup.h:58
void init(const HandlerGroupBase &ext)
Initialize, taking the default StepHandlers as the current ones, possibly overridden by the default o...
Definition: HandlerGroup.h:82
HandlerGroupBase & operator=(const HandlerGroupBase &)
Assignment is private.
bool empty() const
Returns true if current selections in this group is empty.
Definition: HandlerGroup.h:75
PersistentOStream is used to write objects persistently to a stream from which they can be read in ag...
virtual void write(PersistentOStream &os) const
Write to persistent streams.
Definition: HandlerGroup.h:392
The sub-process group.
Definition: HandlerGroup.h:434
The CascadeHandler group.
Definition: HandlerGroup.h:435
void interfaceSetPosthandler(StepHdlPtr p, int i)
Utility function used for the interface.
virtual tStepHdlPtr handler() const =0
Return a pointer to the current main handler.
TransientRCPtr is a simple wrapper around a bare pointer which can be assigned to and from an RCPtr a...
Definition: RCPtr.h:509
void interfaceSetPrehandler(StepHdlPtr p, int i)
Utility function used for the interface.
const StepVector & preHandlers() const
Return a reference to the list of default pre-handlers.
Definition: HandlerGroup.h:125
virtual void setHandler()=0
Unset the current main handler.
HdlPtr interfaceGetHandler() const
Utility function used for the interface.
vector< StepWithHint > StepHintVector
A vector of StepHandler objects associated with Hint objects.
Definition: HandlerGroup.h:55
void checkInsert(StepHintVector &current, const StepVector &def)
Add handlers from the def vector to the current, supplying them with default hints.
virtual tStepHdlPtr handler() const
Return a pointer to the current main handler.
Definition: HandlerGroup.h:352
T1 dynamic_ptr_cast(const T2 &t2)
Replacement for the standard dynamic_cast.
Definition: PtrTraits.h:168
The HadronizationHandler group.
Definition: HandlerGroup.h:437
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
void addHint(tHintPtr hint, const HandlerGroupBase &ext)
Add a hint to the currently selected main handler.
void interfaceErasePosthandler(int i)
Utility function used for the interface.
virtual tStepHdlPtr defaultHandler() const
Return a pointer to the default main handler.
Definition: HandlerGroup.h:359
virtual void read(PersistentIStream &)
Read from persistent streams.
Level
Enumeration for the type of step handler.
Definition: HandlerGroup.h:442
pair< StepHdlPtr, HintPtr > StepWithHint
Associate a StepHandler with a Hint object.
Definition: HandlerGroup.h:49
vector< StepHdlPtr > interfaceGetPosthandlers() const
Utility function used for the interface.
virtual string handlerClass() const
Return the base class name of the main handler type.
StepWithHint next()
Return the next step;.
virtual string handlerClass() const =0
Return the base class name of the main handler type.
virtual void clear()
Clear all current handlers, but don't touch the default ones.
void interfaceInsertPrehandler(StepHdlPtr p, int i)
Utility function used for the interface.
HdlPtr theHandler
The current main handler.
Definition: HandlerGroup.h:416
virtual void refillDefaultHandler(tStepHdlPtr)
Set the current main handler.
HandlerGroupBase is the base class for the templated HandlerGroup utility class to manage a group of ...
Definition: HandlerGroup.h:44
virtual void setHandler()
Unset the current main handler.
Definition: HandlerGroup.h:347
StepVector theDefaultPostHandlers
The default post-handlers with hints.
Definition: HandlerGroup.h:260
StepHintVector thePostHandlers
The current post-handlers with hints.
Definition: HandlerGroup.h:275
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
HintVector theHints
The current hints for the main handler.
Definition: HandlerGroup.h:270
A post-handler.
Definition: HandlerGroup.h:445
Handler
Enumeration for the type of HandlerGroups.
Definition: HandlerGroup.h:433
The mainhandler.
Definition: HandlerGroup.h:444
RCPtr is a reference counted (smart) pointer.
Definition: RCPtr.h:60
virtual void read(PersistentIStream &is)
Read from persistent streams.
Definition: HandlerGroup.h:400
A pre-handler.
Definition: HandlerGroup.h:443
Ptr< HDLR >::pointer HdlPtr
A pointer to the template argument class.
Definition: HandlerGroup.h:326
virtual ~HandlerGroupBase()
Destructor.
const StepVector & postHandlers() const
Return a reference to the list of default post-handlers.
Definition: HandlerGroup.h:140
vector< StepHdlPtr > interfaceGetPrehandlers() const
Utility function used for the interface.
HandlerGroup is a templated utility class to manage a group of StepHandlers.
Definition: HandlerGroup.h:321
Ptr is a templated class to provide typedefs for pointers types ThePEG should use for a given type...
Definition: Ptr.h:35
The DecayHandler group.
Definition: HandlerGroup.h:438
virtual ~HandlerGroup()
Destructor.
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
virtual void refillDefaultHandler(tStepHdlPtr)=0
Set the current main handler.
void refillDefaults(const HandlerGroupBase &)
Fill main, pre- and post- handlers with the default ones.
virtual tStepHdlPtr defaultHandler() const =0
Return a pointer to the default main handler.
StepVector theDefaultPreHandlers
The default pre-handlers with hints.
Definition: HandlerGroup.h:255
bool isEmpty
True if the current handlers are empty.
Definition: HandlerGroup.h:240
HandlerGroupBase()
Default constructor.
virtual void clear()
Clear all current handlers, but don't touch the default ones.
HandlerGroup< HDLR > & operator=(const HandlerGroup< HDLR > &)
Assignment is private.
The MultipleInteractionHandler group.
Definition: HandlerGroup.h:436
vector< StepHdlPtr > StepVector
A vector of StepHandler objects.
Definition: HandlerGroup.h:52
Ptr< HDLR >::transient_pointer tHdlPtr
A transient pointer to the template argument class.
Definition: HandlerGroup.h:329
StepHintVector thePreHandlers
The current pre-handlers with hints.
Definition: HandlerGroup.h:265
void interfaceInsertPosthandler(StepHdlPtr p, int i)
Utility function used for the interface.
void addPreHandler(tStepHdlPtr sh, tHintPtr hint, const HandlerGroupBase &ext)
Add a step handler, sh to the current list of pre-handlers.