00001 // -*- C++ -*- 00002 // 00003 // SelectorBase.h is a part of ThePEG - Toolkit for HEP Event Generation 00004 // Copyright (C) 1999-2007 Leif Lonnblad 00005 // 00006 // ThePEG is licenced under version 2 of the GPL, see COPYING for details. 00007 // Please respect the MCnet academic guidelines, see GUIDELINES for details. 00008 // 00009 #ifndef ThePEG_SelectorBase_H 00010 #define ThePEG_SelectorBase_H 00011 // This is the declaration of the SelectorBase class. 00012 00013 00014 #include "EventConfig.h" 00015 00016 namespace ThePEG { 00017 00045 class SelectorBase { 00046 00047 public: 00048 00052 virtual ~SelectorBase() {} 00053 00057 static bool Check(const Particle &) { return true; } 00058 00062 static bool Intermediate() { return true; } 00063 00067 static bool FinalState() { return true; } 00068 00072 static bool AllSteps() { return true; } 00073 00077 static bool AllCollisions() { return true; } 00078 00082 virtual bool check(const Particle & p) const { return Check(p); } 00083 00087 virtual bool finalState() const { return FinalState(); } 00088 00092 virtual bool intermediate() const { return Intermediate(); } 00093 00098 virtual bool allSteps() const { return AllSteps(); } 00099 00104 virtual bool allCollisions() const { return AllCollisions(); } 00105 00106 }; 00107 00117 template <class T> 00118 struct ParticleSelector: public SelectorBase { 00119 00123 static bool Check(const Particle & p) { return T::Check(p); } 00124 00128 static bool Intermediate() { return T::Intermediate(); } 00129 00133 static bool FinalState() { return T::FinalState(); } 00134 00138 static bool AllSteps() { return T::AllSteps(); } 00139 00143 static bool AllCollisions() { return T::AllCollisions(); } 00144 00148 virtual bool check(const Particle & p) const { return Check(p); } 00149 00153 virtual bool finalState() const { return FinalState(); } 00154 00158 virtual bool intermediate() const { return Intermediate(); } 00159 00164 virtual bool allSteps() const { return AllSteps(); } 00165 00170 virtual bool allCollisions() const { return AllCollisions(); } 00171 00172 }; 00173 00178 class SelectIfNot: public SelectorBase { 00179 00180 public: 00181 00183 explicit SelectIfNot(const SelectorBase & S) : s(S) {} 00184 00188 virtual bool check(const Particle & p) const { return !s.check(p); } 00189 00193 virtual bool finalState() const { return !s.finalState(); } 00194 00198 virtual bool intermediate() const { return !s.intermediate(); } 00199 00204 virtual bool allSteps() const { return !s.allSteps(); } 00205 00210 virtual bool allCollisions() const { return !s.allCollisions(); } 00211 00212 private: 00213 00217 const SelectorBase & s; 00218 }; 00219 00225 class SelectIfBoth: public SelectorBase { 00226 00227 public: 00228 00232 SelectIfBoth(const SelectorBase & S1, const SelectorBase & S2) 00233 : s1(S1), s2(S2) {} 00234 00238 virtual bool check(const Particle & p) const { 00239 return s1.check(p) && s2.check(p); 00240 } 00241 00245 virtual bool finalState() const { 00246 return s1.finalState() && s2.finalState(); 00247 } 00248 00252 virtual bool intermediate() const { 00253 return s1.intermediate() && s2.intermediate(); 00254 } 00255 00260 virtual bool allSteps() const { 00261 return s1.allSteps() && s2.allSteps(); 00262 } 00263 00268 virtual bool allCollisions() const { 00269 return s1.allCollisions() && s2.allCollisions(); 00270 } 00271 00272 private: 00273 00277 const SelectorBase & s1; 00278 00282 const SelectorBase & s2; 00283 00284 }; 00285 00291 class SelectIfEither: public SelectorBase { 00292 00293 public: 00294 00298 SelectIfEither(const SelectorBase & S1, const SelectorBase & S2) 00299 : s1(S1), s2(S2) {} 00300 00304 virtual bool check(const Particle & p) const { 00305 return s1.check(p) || s2.check(p); 00306 } 00307 00311 virtual bool finalState() const { 00312 return s1.finalState() || s2.finalState(); 00313 } 00314 00318 virtual bool intermediate() const { 00319 return s1.intermediate() || s2.intermediate(); 00320 } 00321 00326 virtual bool allSteps() const { 00327 return s1.allSteps() || s2.allSteps(); 00328 } 00329 00334 virtual bool allCollisions() const { 00335 return s1.allCollisions() || s2.allCollisions(); 00336 } 00337 00338 private: 00339 00343 const SelectorBase & s1; 00344 00348 const SelectorBase & s2; 00349 00350 }; 00351 00353 template <typename OutputIterator, typename Container> 00354 inline void copyIfCheck(OutputIterator r, const Container & c, 00355 const SelectorBase & s) { 00356 for ( typename Container::const_iterator it = c.begin(); 00357 it != c.end(); ++it ) 00358 if ( s.check(**it) ) *r++ = *it; 00359 } 00360 00361 } 00362 00363 #endif /* ThePEG_SelectorBase_H */