Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:01:09

0001 #ifndef HEPMC_GEN_EVENT_ITERATORS_H
0002 #define HEPMC_GEN_EVENT_ITERATORS_H
0003 
0004 //--------------------------------------------------------------------------
0005 //////////////////////////////////////////////////////////////////////////
0006 // garren@fnal.gov, May 2009
0007 // 
0008 //////////////////////////////////////////////////////////////////////////
0009 //--------------------------------------------------------------------------
0010 
0011 #include <stdexcept>
0012 
0013 #include "HepMC/GenEvent.h"
0014 #include "HepMC/GenVertex.h"
0015 
0016 namespace HepMC {
0017 
0018 //! GenEventVertexRange acts like a collection of vertices
0019 
0020 ///
0021 /// \class  GenEventVertexRange
0022 /// HepMC::GenEventVertexRange is used to mimic a collection of
0023 /// vertices for ease of use - especially with utilities such as 
0024 /// the Boost foreach funtion
0025 ///
0026 class GenEventVertexRange {
0027 
0028 public:
0029 
0030   /// the constructor requires a GenEvent
0031   GenEventVertexRange( GenEvent & e ) : m_event(e) {}
0032   /// 
0033   GenEvent::vertex_iterator begin() { return m_event.vertices_begin(); }
0034   GenEvent::vertex_iterator end()   { return m_event.vertices_end(); }
0035 
0036 private:
0037   /// Because the class contains a reference, assignments are not allowed.
0038   /// However, we need the copy constructor for GenEvent::vertex_range().
0039   GenEventVertexRange& operator=( GenEventVertexRange & );
0040 
0041 private:
0042   GenEvent & m_event;
0043 
0044 };
0045 
0046 //! ConstGenEventVertexRange acts like a collection of vertices
0047 
0048 ///
0049 /// \class  ConstGenEventVertexRange
0050 /// HepMC::ConstGenEventVertexRange is used to mimic a collection of
0051 /// vertices for ease of use - especially with utilities such as 
0052 /// the Boost foreach funtion
0053 /// This is the const partner of GenEventVertexRange
0054 ///
0055 class ConstGenEventVertexRange {
0056 
0057 public:
0058 
0059   /// the constructor requires a const GenEvent
0060   ConstGenEventVertexRange( GenEvent const & e ) : m_event(e) {}
0061   /// 
0062   GenEvent::vertex_const_iterator begin() const { return m_event.vertices_begin(); }
0063   GenEvent::vertex_const_iterator end()   const { return m_event.vertices_end(); }
0064 
0065 private:
0066   /// Because the class contains a reference, assignments are not allowed.
0067   /// However, we need the copy constructor for GenEvent::vertex_range().
0068   ConstGenEventVertexRange& operator=( ConstGenEventVertexRange & );
0069 
0070 private:
0071   GenEvent const & m_event;
0072 
0073 };
0074 
0075 //! GenEventParticleRange acts like a collection of particles
0076 
0077 ///
0078 /// \class  GenEventParticleRange
0079 /// HepMC::GenEventParticleRange is used to mimic a collection of
0080 /// particles for ease of use - especially with utilities such as 
0081 /// the Boost foreach funtion
0082 ///
0083 class GenEventParticleRange {
0084 
0085 public:
0086 
0087   /// the constructor requires a GenEvent
0088   GenEventParticleRange( GenEvent & e ) : m_event(e) {}
0089   /// 
0090   GenEvent::particle_iterator begin() { return m_event.particles_begin(); }
0091   GenEvent::particle_iterator end()   { return m_event.particles_end(); }
0092 
0093 private:
0094   /// Because the class contains a reference, assignments are not allowed.
0095   /// However, we need the copy constructor for GenEvent::particle_range().
0096   GenEventParticleRange& operator=( GenEventParticleRange & );
0097 
0098 private:
0099   GenEvent & m_event;
0100 
0101 };
0102 
0103 //! ConstGenEventParticleRange acts like a collection of particles
0104 
0105 ///
0106 /// \class  ConstGenEventParticleRange
0107 /// HepMC::ConstGenEventParticleRange is used to mimic a collection of
0108 /// particles for ease of use - especially with utilities such as 
0109 /// the Boost foreach funtion
0110 /// This is the const partner of GenEventParticleRange
0111 ///
0112 class ConstGenEventParticleRange {
0113 
0114 public:
0115 
0116   /// the constructor requires a const GenEvent
0117   ConstGenEventParticleRange( GenEvent const & e ) : m_event(e) {}
0118   /// 
0119   GenEvent::particle_const_iterator begin() const { return m_event.particles_begin(); }
0120   GenEvent::particle_const_iterator end()   const { return m_event.particles_end(); }
0121 
0122 private:
0123   /// Because the class contains a reference, assignments are not allowed.
0124   /// However, we need the copy constructor for GenEvent::particle_range().
0125   ConstGenEventParticleRange& operator=( ConstGenEventParticleRange & );
0126 
0127 private:
0128   GenEvent const & m_event;
0129 
0130 };
0131 
0132 //! GenVertexParticleRange acts like a collection of particles
0133 
0134 ///
0135 /// \class  GenVertexParticleRange
0136 /// HepMC::GenVertexParticleRange is used to mimic a collection of
0137 /// particles for ease of use - especially with utilities such as 
0138 /// the Boost foreach funtion
0139 ///
0140 class GenVertexParticleRange {
0141 
0142 public:
0143 
0144   /// the constructor requires a GenVertex
0145   GenVertexParticleRange( GenVertex & v, IteratorRange range = relatives ) 
0146   : m_vertex(v),m_range(range) {}
0147   /// 
0148   GenVertex::particle_iterator begin() { return m_vertex.particles_begin(m_range); }
0149   GenVertex::particle_iterator end()   { return m_vertex.particles_end(m_range); }
0150 
0151 private:
0152   /// Because the class contains a reference, assignments are not allowed.
0153   /// However, we need the copy constructor for GenVertex::particles().
0154   GenVertexParticleRange& operator=( GenVertexParticleRange & );
0155 
0156 private:
0157   GenVertex     & m_vertex;
0158   IteratorRange   m_range;
0159 
0160 };
0161 
0162 //! GenParticleProductionRange acts like a collection of particles
0163 
0164 ///
0165 /// \class  GenParticleProductionRange
0166 /// HepMC::GenParticleProductionRange is used to mimic a collection of
0167 /// particles associated with the particle's production vertex for ease of use 
0168 /// Utilities such as the Boost foreach funtion will want to use this class.
0169 ///
0170 class GenParticleProductionRange {
0171 
0172 public:
0173 
0174   /// the constructor requires a GenParticle
0175   GenParticleProductionRange( GenParticle const & p, IteratorRange range = relatives ) 
0176   : m_particle(p),m_range(range) {}
0177   /// begin iterator throws an error if the particle production_vertex is undefined
0178   GenVertex::particle_iterator begin();
0179   /// end iterator throws an error if the particle production_vertex is undefined
0180   GenVertex::particle_iterator end(); 
0181 
0182 private:
0183   /// Because the class contains a reference, assignments are not allowed.
0184   /// However, we need the copy constructor for GenVertex::particles_in().
0185   GenParticleProductionRange& operator=( GenParticleProductionRange & );
0186 
0187 private:
0188   GenParticle const & m_particle;
0189   IteratorRange       m_range;
0190 
0191 };
0192 
0193 class ConstGenParticleProductionRange {
0194 
0195 public:
0196 
0197   /// the constructor requires a GenParticle
0198   ConstGenParticleProductionRange( GenParticle const & p, IteratorRange range = relatives ) 
0199   : m_particle(p),m_range(range) {}
0200   /// begin iterator throws an error if the particle production_vertex is undefined
0201   GenVertex::particle_iterator begin();
0202   /// end iterator throws an error if the particle production_vertex is undefined
0203   GenVertex::particle_iterator end(); 
0204 
0205 private:
0206   /// Because the class contains a reference, assignments are not allowed.
0207   /// However, we need the copy constructor for GenVertex::particles_in().
0208   ConstGenParticleProductionRange& operator=( ConstGenParticleProductionRange & );
0209 
0210 private:
0211   GenParticle const & m_particle;
0212   IteratorRange       m_range;
0213 
0214 };
0215 
0216 //! GenParticleEndRange acts like a collection of particles
0217 
0218 ///
0219 /// \class  GenParticleEndRange
0220 /// HepMC::GenParticleEndRange is used to mimic a collection of
0221 /// particles associated with the particle's end vertex for ease of use 
0222 /// Utilities such as the Boost foreach funtion will want to use this class.
0223 ///
0224 class GenParticleEndRange {
0225 
0226 public:
0227 
0228   /// the constructor requires a GenParticle
0229   GenParticleEndRange( GenParticle const & p, IteratorRange range = relatives ) 
0230   : m_particle(p),m_range(range) {}
0231   /// begin iterator throws an error if the particle end_vertex is undefined
0232   GenVertex::particle_iterator begin();
0233   /// end iterator throws an error if the particle end_vertex is undefined
0234   GenVertex::particle_iterator end(); 
0235 
0236 private:
0237   /// Because the class contains a reference, assignments are not allowed.
0238   /// However, we need the copy constructor for GenVertex::particles_out().
0239   GenParticleEndRange& operator=( GenParticleEndRange & );
0240 
0241 private:
0242   GenParticle const & m_particle;
0243   IteratorRange       m_range;
0244 
0245 };
0246 
0247 class ConstGenParticleEndRange {
0248 
0249 public:
0250 
0251   /// the constructor requires a GenParticle
0252   ConstGenParticleEndRange( GenParticle const & p, IteratorRange range = relatives ) 
0253   : m_particle(p),m_range(range) {}
0254   /// begin iterator throws an error if the particle end_vertex is undefined
0255   GenVertex::particle_iterator begin();
0256   /// end iterator throws an error if the particle end_vertex is undefined
0257   GenVertex::particle_iterator end(); 
0258 
0259 private:
0260   /// Because the class contains a reference, assignments are not allowed.
0261   /// However, we need the copy constructor for GenVertex::particles_out().
0262   ConstGenParticleEndRange& operator=( ConstGenParticleEndRange & );
0263 
0264 private:
0265   GenParticle const & m_particle;
0266   IteratorRange       m_range;
0267 
0268 };
0269 
0270 
0271 inline GenVertex::particle_iterator GenParticleProductionRange::begin() 
0272 { 
0273     if ( ! m_particle.production_vertex() ) 
0274         throw(std::range_error("GenParticleProductionRange: GenParticle has no production_vertex"));
0275     return m_particle.production_vertex()->particles_begin(m_range); 
0276 }
0277 
0278 inline GenVertex::particle_iterator GenParticleProductionRange::end()
0279 { 
0280     if ( ! m_particle.production_vertex() ) 
0281         throw(std::range_error("GenParticleProductionRange: GenParticle has no production_vertex"));
0282     return m_particle.production_vertex()->particles_end(m_range); 
0283 }
0284 
0285 
0286 inline GenVertex::particle_iterator ConstGenParticleProductionRange::begin() 
0287 { 
0288     if ( ! m_particle.production_vertex() ) 
0289         throw(std::range_error("ConstGenParticleProductionRange: GenParticle has no production_vertex"));
0290     return m_particle.production_vertex()->particles_begin(m_range); 
0291 }
0292 
0293 inline GenVertex::particle_iterator ConstGenParticleProductionRange::end()
0294 { 
0295     if ( ! m_particle.production_vertex() ) 
0296         throw(std::range_error("ConstGenParticleProductionRange: GenParticle has no production_vertex"));
0297     return m_particle.production_vertex()->particles_end(m_range); 
0298 }
0299 
0300 inline GenVertex::particle_iterator GenParticleEndRange::begin() 
0301 { 
0302     if ( ! m_particle.end_vertex() ) 
0303         throw(std::range_error("GenParticleEndRange: GenParticle has no end_vertex"));
0304     return m_particle.end_vertex()->particles_begin(m_range); 
0305 }
0306 inline GenVertex::particle_iterator GenParticleEndRange::end()
0307 { 
0308     if ( ! m_particle.end_vertex() ) 
0309         throw(std::range_error("GenParticleEndRange: GenParticle has no end_vertex"));
0310     return m_particle.end_vertex()->particles_end(m_range); 
0311 }
0312 
0313 inline GenVertex::particle_iterator ConstGenParticleEndRange::begin() 
0314 { 
0315     if ( ! m_particle.end_vertex() ) 
0316         throw(std::range_error("ConstGenParticleEndRange: GenParticle has no end_vertex"));
0317     return m_particle.end_vertex()->particles_begin(m_range); 
0318 }
0319 inline GenVertex::particle_iterator ConstGenParticleEndRange::end()
0320 { 
0321     if ( ! m_particle.end_vertex() ) 
0322         throw(std::range_error("ConstGenParticleEndRange: GenParticle has no end_vertex"));
0323     return m_particle.end_vertex()->particles_end(m_range); 
0324 }
0325 
0326 } // HepMC
0327 
0328 #endif  // HEPMC_GEN_EVENT_ITERATORS_H