Fork me on GitHub

Ignore:
Timestamp:
Nov 2, 2011, 5:39:26 PM (13 years ago)
Author:
cp3-support
Message:

upgrade HepMC to version 2.06.05

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Utilities/HepMC/interface/WeightContainer.h

    r349 r572  
    99//
    1010// Container for the Weights associated with an event or vertex.
    11 // Basically just an interface to STL vector.
     11//
     12// This implementation adds a map-like interface in addition to the
     13// vector-like interface.
    1214//////////////////////////////////////////////////////////////////////////
    1315
    1416#include <iostream>
    1517#include <vector>
     18#include <string>
     19#include <map>
    1620
    1721namespace HepMC {
     
    2125    ///
    2226    /// \class  WeightContainer
    23     /// Basically just an interface to STL vector.
     27    /// This class has both map-like and vector-like functionality.
     28    /// Named weights are now supported.
    2429    class WeightContainer {
     30        friend class GenEvent;
    2531
    2632    public:
     33        /// defining the size type used by vector and map
     34        typedef std::size_t size_type;
     35        /// iterator for the weight container
     36        typedef std::vector<double>::iterator iterator;
     37        /// const iterator for the weight container
     38        typedef std::vector<double>::const_iterator const_iterator;
     39       
    2740        /// default constructor
    28         WeightContainer( unsigned int n = 0, const double& value = 0. );
     41        explicit WeightContainer( size_type n = 0, double value = 0. );
    2942        /// construct from a vector of weights
    3043        WeightContainer( const std::vector<double>& weights );
    3144        /// copy
    3245        WeightContainer( const WeightContainer& in );
    33         virtual ~WeightContainer();
     46        ~WeightContainer();
    3447
    3548        /// swap
    3649        void swap( WeightContainer & other);
    37         /// copy
     50        /// copy assignment
    3851        WeightContainer& operator=( const WeightContainer& );
    39         /// copy
     52        /// alternate assignment using a vector of doubles
    4053        WeightContainer& operator=( const std::vector<double>& in );
    4154
    4255        /// print weights
    4356        void          print( std::ostream& ostr = std::cout ) const;
     57        /// write weights in a readable table
     58        void          write( std::ostream& ostr = std::cout ) const;
    4459
    4560        /// size of weight container
    46         int           size() const;
     61        size_type     size() const;
    4762        /// return true if weight container is empty
    4863        bool          empty() const;
     
    5469        void          clear();
    5570
    56         /// access the weight container
    57         double&       operator[]( unsigned int n );  // unchecked access
    58         /// access the weight container
    59         const double& operator[]( unsigned int n ) const;
    60        
     71        /// check to see if a name exists in the map
     72        bool          has_key( const std::string& s ) const;
     73
     74        /// access the weight container
     75        double&       operator[]( size_type n );  // unchecked access
     76        /// access the weight container
     77        const double& operator[]( size_type n ) const;
     78        /// access the weight container
     79        double&       operator[]( const std::string& s );  // unchecked access
     80        /// access the weight container
     81        const double& operator[]( const std::string& s ) const;
     82
     83        /// equality
     84        bool operator==( const WeightContainer & ) const;
     85        /// inequality
     86        bool operator!=( const WeightContainer & ) const;
     87       
    6188        /// returns the first element
    6289        double&       front();
     
    6895        const double& back() const;
    6996
    70         /// iterator for the weight container
    71         typedef std::vector<double>::iterator iterator;
     97        /// begining of the weight container
     98        iterator            begin();
     99        /// end of the weight container
     100        iterator            end();
     101        /// begining of the weight container
     102        const_iterator      begin() const;
     103        /// end of the weight container
     104        const_iterator      end() const;
     105
     106    private:
     107        // for internal use only
     108
     109        /// maplike iterator for the weight container
     110        /// for internal use only
     111        typedef std::map<std::string,size_type>::iterator       map_iterator;
    72112        /// const iterator for the weight container
    73         typedef std::vector<double>::const_iterator const_iterator;
    74         /// begining of the weight container
    75         iterator            begin();
    76         /// end of the weight container
    77         iterator            end();
    78         /// begining of the weight container
    79         const_iterator      begin() const;
    80         /// end of the weight container
    81         const_iterator      end() const;
     113        /// for internal use only
     114        typedef std::map<std::string,size_type>::const_iterator const_map_iterator;
     115        /// begining of the weight container
     116        /// for internal use only
     117        map_iterator            map_begin();
     118        /// end of the weight container
     119        /// for internal use only
     120        map_iterator            map_end();
     121        /// begining of the weight container
     122        /// for internal use only
     123        const_map_iterator      map_begin() const;
     124        /// end of the weight container
     125        /// for internal use only
     126        const_map_iterator      map_end() const;
     127       
     128        /// used by the constructors to set initial names
     129        /// for internal use only
     130        void set_default_names( size_type n );
    82131       
    83132    private:
    84         std::vector<double>  m_weights;
     133        std::vector<double>          m_weights;
     134        std::map<std::string,size_type> m_names;
    85135    };
    86136
     
    89139    ///////////////////////////
    90140
    91     inline WeightContainer::WeightContainer( unsigned int n,
    92                                              const double& value )
    93         : m_weights(n,value)
     141    inline WeightContainer::WeightContainer( const WeightContainer& in )
     142        : m_weights(in.m_weights), m_names(in.m_names)
    94143    {}
    95144
    96     inline WeightContainer::WeightContainer( const std::vector<double>& wgts )
    97         : m_weights(wgts)
    98     {}
    99 
    100     inline WeightContainer::WeightContainer( const WeightContainer& in )
    101         : m_weights(in.m_weights)
    102     {}
    103 
    104145    inline WeightContainer::~WeightContainer() {}
    105146
    106147    inline void WeightContainer::swap( WeightContainer & other)
    107     { m_weights.swap( other.m_weights ); }
     148    {
     149        m_weights.swap( other.m_weights );
     150        m_names.swap( other.m_names );
     151    }
    108152
    109153    inline WeightContainer& WeightContainer::operator=
     
    123167    }
    124168
    125     inline void WeightContainer::print( std::ostream& ostr ) const
     169    inline WeightContainer::size_type WeightContainer::size() const { return m_weights.size(); }
     170
     171    inline bool WeightContainer::empty() const { return m_weights.empty(); }
     172
     173    inline void WeightContainer::clear()
    126174    {
    127         for ( const_iterator w = begin(); w != end(); ++w )
    128         {
    129             ostr << *w << " ";
    130         }
    131         ostr << std::endl;
    132     }
    133 
    134     inline int WeightContainer::size() const { return m_weights.size(); }
    135 
    136     inline bool WeightContainer::empty() const { return m_weights.empty(); }
    137 
    138     inline void WeightContainer::push_back( const double& value)
    139     { m_weights.push_back(value); }
    140 
    141     inline void WeightContainer::pop_back() { m_weights.pop_back(); }
    142 
    143     inline void WeightContainer::clear() { m_weights.clear(); }
    144 
    145     inline double& WeightContainer::operator[]( unsigned int n )
    146     { return m_weights[(int)n]; }
    147 
    148     inline const double& WeightContainer::operator[]( unsigned int n ) const
    149     { return m_weights[(int)n]; }
     175        m_weights.clear();
     176        m_names.clear();
     177    }
     178
     179    inline double& WeightContainer::operator[]( size_type n )
     180    { return m_weights[n]; }
     181
     182    inline const double& WeightContainer::operator[]( size_type n ) const
     183    { return m_weights[n]; }
    150184
    151185    inline double& WeightContainer::front() { return m_weights.front(); }
     
    171205    { return m_weights.end(); }
    172206
     207    inline WeightContainer::map_iterator WeightContainer::map_begin()
     208    { return m_names.begin(); }
     209
     210    inline WeightContainer::map_iterator WeightContainer::map_end()
     211    { return m_names.end(); }
     212
     213    inline WeightContainer::const_map_iterator WeightContainer::map_begin() const
     214    { return m_names.begin(); }
     215
     216    inline WeightContainer::const_map_iterator WeightContainer::map_end() const
     217    { return m_names.end(); }
     218
    173219} // HepMC
    174220
Note: See TracChangeset for help on using the changeset viewer.