SSO Logout

Subversion Repositories hepmc

Rev

Rev 240 | Rev 443 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
173 garren 1
//--------------------------------------------------------------------------
2
#ifndef HEPMC_TempParticleMap_H
3
#define HEPMC_TempParticleMap_H
4
 
5
//////////////////////////////////////////////////////////////////////////
6
// garren@fnal.gov, October 2007
7
//
8
// Used by IO classes
9
//////////////////////////////////////////////////////////////////////////
10
 
11
#include <map>
12
 
13
namespace HepMC {
14
 
15
    class GenParticle;
16
 
17
    //! TempParticleMap is a temporary GenParticle* container used during input.
18
 
19
    ///
20
    /// \class  TempParticleMap
21
    /// Used by IO classes for recoverable particle ordering.
22
    /// Map GenParticle* against both outgoing vertex and particle order.
23
    ///
24
    class TempParticleMap {
25
    public:
26
        typedef std::map<HepMC::GenParticle*,int> TempMap;
27
        typedef std::map<int,HepMC::GenParticle*> TempOrderMap;
28
        typedef TempMap::iterator     TempMapIterator;
29
        typedef TempOrderMap::iterator  orderIterator;
30
 
31
        TempParticleMap()
240 garren 32
        : m_particle_to_end_vertex(), m_particle_order() {}
173 garren 33
 
34
        ~TempParticleMap() {}
35
 
36
        TempMapIterator begin() { return m_particle_to_end_vertex.begin(); }
37
        TempMapIterator end() { return m_particle_to_end_vertex.end(); }
38
        orderIterator order_begin() { return m_particle_order.begin(); }
39
        orderIterator order_end() { return m_particle_order.end(); }
442 garren 40
        bool empty() const;
173 garren 41
 
42
        int end_vertex( GenParticle* );
43
 
44
        void addEndParticle( GenParticle*, int& );
45
 
442 garren 46
        void clear_temp_map();
47
 
173 garren 48
    private:
49
        TempMap       m_particle_to_end_vertex;
50
        TempOrderMap  m_particle_order;
51
    };
52
 
53
    inline int TempParticleMap::end_vertex( GenParticle* p )
54
    {
55
        //return m_particle_to_end_vertex[p]->second; 
56
        TempMapIterator it = m_particle_to_end_vertex.find(p);
57
        if( it == end() ) return 0;
58
        return m_particle_to_end_vertex[p];
59
    }
60
 
61
    inline void TempParticleMap::addEndParticle( GenParticle* p, int& end_vtx_code )
62
    {
240 garren 63
        m_particle_order[p->barcode()] = p;
173 garren 64
        m_particle_to_end_vertex[p] = end_vtx_code;
65
    }
66
 
442 garren 67
    inline bool TempParticleMap::empty() const {
68
        return (bool)m_particle_to_end_vertex.empty();
69
    }
70
 
71
    inline void TempParticleMap::clear_temp_map() {
72
        // this method is used if corrupt data is encountered when reading an event
73
        // have to be careful, can't just call clear() on the map
74
        while( !empty() ) {
75
            GenParticle* p = m_particle_order.begin()->second;
76
            // empty the maps
77
            m_particle_order.erase( m_particle_order.begin() );
78
            m_particle_to_end_vertex.erase( p );
79
            // delete particles only if they are not already owned by the event
80
            if( p->production_vertex() ) {
81
            } else if( p->parent_event() ) {
82
            } else {
83
                 delete p;
84
            }
85
        }
86
    }
87
 
88
 
173 garren 89
} // HepMC
90
 
91
#endif  // HEPMC_TempParticleMap_H
92
//--------------------------------------------------------------------------