1 #ifndef HEPMC_GEN_EVENT_ITERATORS_H
2 #define HEPMC_GEN_EVENT_ITERATORS_H
4 //--------------------------------------------------------------------------
5 //////////////////////////////////////////////////////////////////////////
6 // garren@fnal.gov, May 2009
8 //////////////////////////////////////////////////////////////////////////
9 //--------------------------------------------------------------------------
13 #include "HepMC/GenEvent.h"
14 #include "HepMC/GenVertex.h"
18 //! GenEventVertexRange acts like a collection of vertices
21 /// \class GenEventVertexRange
22 /// HepMC::GenEventVertexRange is used to mimic a collection of
23 /// vertices for ease of use - especially with utilities such as
24 /// the Boost foreach funtion
26 class GenEventVertexRange {
30 /// the constructor requires a GenEvent
31 GenEventVertexRange( GenEvent & e ) : m_event(e) {}
33 GenEvent::vertex_iterator begin() { return m_event.vertices_begin(); }
34 GenEvent::vertex_iterator end() { return m_event.vertices_end(); }
37 /// Because the class contains a reference, assignments are not allowed.
38 /// However, we need the copy constructor for GenEvent::vertex_range().
39 GenEventVertexRange& operator=( GenEventVertexRange & );
46 //! ConstGenEventVertexRange acts like a collection of vertices
49 /// \class ConstGenEventVertexRange
50 /// HepMC::ConstGenEventVertexRange is used to mimic a collection of
51 /// vertices for ease of use - especially with utilities such as
52 /// the Boost foreach funtion
53 /// This is the const partner of GenEventVertexRange
55 class ConstGenEventVertexRange {
59 /// the constructor requires a const GenEvent
60 ConstGenEventVertexRange( GenEvent const & e ) : m_event(e) {}
62 GenEvent::vertex_const_iterator begin() const { return m_event.vertices_begin(); }
63 GenEvent::vertex_const_iterator end() const { return m_event.vertices_end(); }
66 /// Because the class contains a reference, assignments are not allowed.
67 /// However, we need the copy constructor for GenEvent::vertex_range().
68 ConstGenEventVertexRange& operator=( ConstGenEventVertexRange & );
71 GenEvent const & m_event;
75 //! GenEventParticleRange acts like a collection of particles
78 /// \class GenEventParticleRange
79 /// HepMC::GenEventParticleRange is used to mimic a collection of
80 /// particles for ease of use - especially with utilities such as
81 /// the Boost foreach funtion
83 class GenEventParticleRange {
87 /// the constructor requires a GenEvent
88 GenEventParticleRange( GenEvent & e ) : m_event(e) {}
90 GenEvent::particle_iterator begin() { return m_event.particles_begin(); }
91 GenEvent::particle_iterator end() { return m_event.particles_end(); }
94 /// Because the class contains a reference, assignments are not allowed.
95 /// However, we need the copy constructor for GenEvent::particle_range().
96 GenEventParticleRange& operator=( GenEventParticleRange & );
103 //! ConstGenEventParticleRange acts like a collection of particles
106 /// \class ConstGenEventParticleRange
107 /// HepMC::ConstGenEventParticleRange is used to mimic a collection of
108 /// particles for ease of use - especially with utilities such as
109 /// the Boost foreach funtion
110 /// This is the const partner of GenEventParticleRange
112 class ConstGenEventParticleRange {
116 /// the constructor requires a const GenEvent
117 ConstGenEventParticleRange( GenEvent const & e ) : m_event(e) {}
119 GenEvent::particle_const_iterator begin() const { return m_event.particles_begin(); }
120 GenEvent::particle_const_iterator end() const { return m_event.particles_end(); }
123 /// Because the class contains a reference, assignments are not allowed.
124 /// However, we need the copy constructor for GenEvent::particle_range().
125 ConstGenEventParticleRange& operator=( ConstGenEventParticleRange & );
128 GenEvent const & m_event;
132 //! GenVertexParticleRange acts like a collection of particles
135 /// \class GenVertexParticleRange
136 /// HepMC::GenVertexParticleRange is used to mimic a collection of
137 /// particles for ease of use - especially with utilities such as
138 /// the Boost foreach funtion
140 class GenVertexParticleRange {
144 /// the constructor requires a GenVertex
145 GenVertexParticleRange( GenVertex & v, IteratorRange range = relatives )
146 : m_vertex(v),m_range(range) {}
148 GenVertex::particle_iterator begin() { return m_vertex.particles_begin(m_range); }
149 GenVertex::particle_iterator end() { return m_vertex.particles_end(m_range); }
152 /// Because the class contains a reference, assignments are not allowed.
153 /// However, we need the copy constructor for GenVertex::particles().
154 GenVertexParticleRange& operator=( GenVertexParticleRange & );
157 GenVertex & m_vertex;
158 IteratorRange m_range;
162 //! GenParticleProductionRange acts like a collection of particles
165 /// \class GenParticleProductionRange
166 /// HepMC::GenParticleProductionRange is used to mimic a collection of
167 /// particles associated with the particle's production vertex for ease of use
168 /// Utilities such as the Boost foreach funtion will want to use this class.
170 class GenParticleProductionRange {
174 /// the constructor requires a GenParticle
175 GenParticleProductionRange( GenParticle const & p, IteratorRange range = relatives )
176 : m_particle(p),m_range(range) {}
177 /// begin iterator throws an error if the particle production_vertex is undefined
178 GenVertex::particle_iterator begin();
179 /// end iterator throws an error if the particle production_vertex is undefined
180 GenVertex::particle_iterator end();
183 /// Because the class contains a reference, assignments are not allowed.
184 /// However, we need the copy constructor for GenVertex::particles_in().
185 GenParticleProductionRange& operator=( GenParticleProductionRange & );
188 GenParticle const & m_particle;
189 IteratorRange m_range;
193 class ConstGenParticleProductionRange {
197 /// the constructor requires a GenParticle
198 ConstGenParticleProductionRange( GenParticle const & p, IteratorRange range = relatives )
199 : m_particle(p),m_range(range) {}
200 /// begin iterator throws an error if the particle production_vertex is undefined
201 GenVertex::particle_iterator begin();
202 /// end iterator throws an error if the particle production_vertex is undefined
203 GenVertex::particle_iterator end();
206 /// Because the class contains a reference, assignments are not allowed.
207 /// However, we need the copy constructor for GenVertex::particles_in().
208 ConstGenParticleProductionRange& operator=( ConstGenParticleProductionRange & );
211 GenParticle const & m_particle;
212 IteratorRange m_range;
216 //! GenParticleEndRange acts like a collection of particles
219 /// \class GenParticleEndRange
220 /// HepMC::GenParticleEndRange is used to mimic a collection of
221 /// particles associated with the particle's end vertex for ease of use
222 /// Utilities such as the Boost foreach funtion will want to use this class.
224 class GenParticleEndRange {
228 /// the constructor requires a GenParticle
229 GenParticleEndRange( GenParticle const & p, IteratorRange range = relatives )
230 : m_particle(p),m_range(range) {}
231 /// begin iterator throws an error if the particle end_vertex is undefined
232 GenVertex::particle_iterator begin();
233 /// end iterator throws an error if the particle end_vertex is undefined
234 GenVertex::particle_iterator end();
237 /// Because the class contains a reference, assignments are not allowed.
238 /// However, we need the copy constructor for GenVertex::particles_out().
239 GenParticleEndRange& operator=( GenParticleEndRange & );
242 GenParticle const & m_particle;
243 IteratorRange m_range;
247 class ConstGenParticleEndRange {
251 /// the constructor requires a GenParticle
252 ConstGenParticleEndRange( GenParticle const & p, IteratorRange range = relatives )
253 : m_particle(p),m_range(range) {}
254 /// begin iterator throws an error if the particle end_vertex is undefined
255 GenVertex::particle_iterator begin();
256 /// end iterator throws an error if the particle end_vertex is undefined
257 GenVertex::particle_iterator end();
260 /// Because the class contains a reference, assignments are not allowed.
261 /// However, we need the copy constructor for GenVertex::particles_out().
262 ConstGenParticleEndRange& operator=( ConstGenParticleEndRange & );
265 GenParticle const & m_particle;
266 IteratorRange m_range;
271 inline GenVertex::particle_iterator GenParticleProductionRange::begin()
273 if ( ! m_particle.production_vertex() )
274 throw(std::range_error("GenParticleProductionRange: GenParticle has no production_vertex"));
275 return m_particle.production_vertex()->particles_begin(m_range);
278 inline GenVertex::particle_iterator GenParticleProductionRange::end()
280 if ( ! m_particle.production_vertex() )
281 throw(std::range_error("GenParticleProductionRange: GenParticle has no production_vertex"));
282 return m_particle.production_vertex()->particles_end(m_range);
286 inline GenVertex::particle_iterator ConstGenParticleProductionRange::begin()
288 if ( ! m_particle.production_vertex() )
289 throw(std::range_error("ConstGenParticleProductionRange: GenParticle has no production_vertex"));
290 return m_particle.production_vertex()->particles_begin(m_range);
293 inline GenVertex::particle_iterator ConstGenParticleProductionRange::end()
295 if ( ! m_particle.production_vertex() )
296 throw(std::range_error("ConstGenParticleProductionRange: GenParticle has no production_vertex"));
297 return m_particle.production_vertex()->particles_end(m_range);
300 inline GenVertex::particle_iterator GenParticleEndRange::begin()
302 if ( ! m_particle.end_vertex() )
303 throw(std::range_error("GenParticleEndRange: GenParticle has no end_vertex"));
304 return m_particle.end_vertex()->particles_begin(m_range);
306 inline GenVertex::particle_iterator GenParticleEndRange::end()
308 if ( ! m_particle.end_vertex() )
309 throw(std::range_error("GenParticleEndRange: GenParticle has no end_vertex"));
310 return m_particle.end_vertex()->particles_end(m_range);
313 inline GenVertex::particle_iterator ConstGenParticleEndRange::begin()
315 if ( ! m_particle.end_vertex() )
316 throw(std::range_error("ConstGenParticleEndRange: GenParticle has no end_vertex"));
317 return m_particle.end_vertex()->particles_begin(m_range);
319 inline GenVertex::particle_iterator ConstGenParticleEndRange::end()
321 if ( ! m_particle.end_vertex() )
322 throw(std::range_error("ConstGenParticleEndRange: GenParticle has no end_vertex"));
323 return m_particle.end_vertex()->particles_end(m_range);
328 #endif // HEPMC_GEN_EVENT_ITERATORS_H