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/IO_GenEvent.h

    r349 r572  
    1616#include <vector>
    1717#include "IO_BaseClass.h"
    18 #include "TempParticleMap.h"
    19 #include "CommonIO.h"
     18#include "IO_Exception.h"
    2019#include "Units.h"
    2120
    2221namespace HepMC {
    2322
    24     class GenEvent;
    25     class GenVertex;
    26     class GenParticle;
    27     class ParticleData;
    28     class HeavyIon;
    29     class PdfInfo;
     23class GenEvent;
     24class GenVertex;
     25class GenParticle;
     26class HeavyIon;
     27class PdfInfo;
    3028
    31     //! IO_GenEvent also deals with HeavyIon and PdfInfo
     29//! IO_GenEvent also deals with HeavyIon and PdfInfo
    3230
    33     ///
    34     /// \class  IO_GenEvent
    35     /// event input/output in ascii format for machine reading
    36     /// extended format contains HeavyIon and PdfInfo classes
    37     ///
    38     /// Strategy for reading or writing events using iostreams
    39     /// When instantiating with a file name, the mode of file to be created
    40     ///  must be specified. Options are:
    41     ///      std::ios::in     open file for input
    42     ///      std::ios::out    open file for output
    43     ///      std::ios::trunc  erase old file when opening (i.e. ios::out|ios::trunc
    44     ///                    removes oldfile, and creates a new one for output )
    45     ///      std::ios::app    append output to end of file
    46     ///  for the purposes of this class, simultaneous input and output mode
    47     ///  ( std::ios::in | std::ios::out ) is not allowed.
    48     ///
    49     /// Event listings are preceded by the key:
    50     ///  "HepMC::IO_GenEvent-START_EVENT_LISTING\n"
    51     ///  and terminated by the key:
    52     ///  "HepMC::IO_GenEvent-END_EVENT_LISTING\n"
    53     /// GenParticle Data tables are preceded by the key:
    54     ///  "HepMC::IO_GenEvent-START_PARTICLE_DATA\n"
    55     ///  and terminated by the key:
    56     ///  "HepMC::IO_GenEvent-END_PARTICLE_DATA\n"
    57     /// Comments are allowed. They need not be preceded by anything, though if
    58     ///  a comment is written using write_comment( const string ) then it will be
    59     ///  preceded by "HepMC::IO_GenEvent-COMMENT\n"
    60     /// Each event, vertex, particle, particle data, heavy ion, or pdf info line
    61     ///  is preceded by   "E ","V ","P ","D ","H ","F "    respectively.
    62     /// Comments may appear anywhere in the file -- so long as they do not contain
    63     ///  any of the start/stop keys.
    64     ///
    65     class IO_GenEvent : public IO_BaseClass {
    66     public:
    67         /// constructor requiring a file name and std::ios mode
    68         IO_GenEvent( const std::string& filename="IO_GenEvent.dat",
    69                   std::ios::openmode mode=std::ios::out );
    70         /// constructor requiring an input stream
    71         IO_GenEvent( std::istream & );
    72         /// constructor requiring an output stream
    73         IO_GenEvent( std::ostream & );
    74         virtual       ~IO_GenEvent();
     31///
     32/// \class  IO_GenEvent
     33/// event input/output in ascii format for machine reading
     34/// extended format contains HeavyIon and PdfInfo classes
     35///
     36/// Strategy for reading or writing events using iostreams
     37/// When instantiating with a file name, the mode of file to be created
     38///  must be specified. Options are:
     39///      std::ios::in     open file for input
     40///      std::ios::out    open file for output
     41///      std::ios::trunc  erase old file when opening (i.e. ios::out|ios::trunc
     42///                    removes oldfile, and creates a new one for output )
     43///      std::ios::app    append output to end of file
     44///  for the purposes of this class, simultaneous input and output mode
     45///  ( std::ios::in | std::ios::out ) is not allowed.
     46///
     47/// Event listings are preceded by the key:
     48///  "HepMC::IO_GenEvent-START_EVENT_LISTING\n"
     49///  and terminated by the key:
     50///  "HepMC::IO_GenEvent-END_EVENT_LISTING\n"
     51/// GenParticle Data tables are preceded by the key:
     52///  "HepMC::IO_GenEvent-START_PARTICLE_DATA\n"
     53///  and terminated by the key:
     54///  "HepMC::IO_GenEvent-END_PARTICLE_DATA\n"
     55/// Comments are allowed. They need not be preceded by anything, though if
     56///  a comment is written using write_comment( const string ) then it will be
     57///  preceded by "HepMC::IO_GenEvent-COMMENT\n"
     58/// Each event, vertex, particle, particle data, heavy ion, or pdf info line
     59///  is preceded by   "E ","V ","P ","D ","H ","F "    respectively.
     60/// Comments may appear anywhere in the file -- so long as they do not contain
     61///  any of the start/stop keys.
     62///
     63class IO_GenEvent : public IO_BaseClass {
     64public:
     65    /// constructor requiring a file name and std::ios mode
     66    IO_GenEvent( const std::string& filename="IO_GenEvent.dat",
     67              std::ios::openmode mode=std::ios::out );
     68    /// constructor requiring an input stream
     69    IO_GenEvent( std::istream & );
     70    /// constructor requiring an output stream
     71    IO_GenEvent( std::ostream & );
     72    virtual       ~IO_GenEvent();
    7573
    76         /// write this event
    77         void          write_event( const GenEvent* evt );
    78         /// get the next event
    79         bool          fill_next_event( GenEvent* evt );
    80         void          write_particle_data_table(const ParticleDataTable*);
    81         bool          fill_particle_data_table( ParticleDataTable* );
    82         /// insert a comment directly into the output file --- normally you
    83         ///  only want to do this at the beginning or end of the file. All
    84         ///  comments are preceded with "HepMC::IO_GenEvent-COMMENT\n"
    85         void          write_comment( const std::string comment );
     74    /// write this event
     75    void          write_event( const GenEvent* evt );
     76    /// get the next event
     77    bool          fill_next_event( GenEvent* evt );
     78    /// insert a comment directly into the output file --- normally you
     79    ///  only want to do this at the beginning or end of the file. All
     80    ///  comments are preceded with "HepMC::IO_GenEvent-COMMENT\n"
     81    void          write_comment( const std::string comment );
    8682
    87         int           rdstate() const;  //!< check the state of the IO stream
    88         void          clear();  //!< clear the IO stream
     83    int           rdstate() const;  //!< check the state of the IO stream
     84    void          clear();  //!< clear the IO stream
    8985
    90         /// write to ostr
    91         void          print( std::ostream& ostr = std::cout ) const;
     86    /// write to ostr
     87    void          print( std::ostream& ostr = std::cout ) const;
    9288
    93         /// needed when reading a file without units if those units are
    94         /// different than the declared default units
    95         /// (e.g., the default units are MeV, but the file was written with GeV)
    96         /// This method is not necessary if the units are written in the file
    97         void use_input_units( Units::MomentumUnit, Units::LengthUnit );
     89    /// needed when reading a file without units if those units are
     90    /// different than the declared default units
     91    /// (e.g., the default units are MeV, but the file was written with GeV)
     92    /// This method is not necessary if the units are written in the file
     93    void use_input_units( Units::MomentumUnit, Units::LengthUnit );
    9894
    99     protected: // for internal use only
    100         /// write vertex information
    101         void          write_vertex( GenVertex* );
    102         /// write beam particle information
    103         void          write_beam_particles( std::pair<HepMC::GenParticle *,HepMC::GenParticle *> );
    104         /// write heavy ion information
    105         void          write_heavy_ion( HeavyIon const * );
    106         /// write PDF information
    107         void          write_pdf_info( PdfInfo const * );
    108         /// write units
    109         void          write_unit_info( const GenEvent* evt );
    110         /// write particle information
    111         void          write_particle( GenParticle* p );
    112         /// write particle data information
    113         void          write_particle_data( const ParticleData* d );
    114         /// read vertex information
    115         GenVertex*    read_vertex( TempParticleMap& particle_to_end_vertex );
    116         /// read GenParticle information
    117         GenParticle*  read_particle( TempParticleMap& particle_to_end_vertex );
    118         /// read particle data table information
    119         ParticleData* read_particle_data( ParticleDataTable* );
    120         /// read heavy ion information
    121         HeavyIon*     read_heavy_ion(  );
    122         /// read units
    123         void          read_unit_info( GenEvent* evt );
    124         /// write end tag
    125         bool          write_end_listing();
     95    /// set output precision
     96    /// The default precision is 16.
     97    void precision( int );
     98       
     99    /// integer (enum) associated with read error
     100    int           error_type()    const;
     101    /// the read error message string
     102    const std::string & error_message() const;
    126103
    127         void          output( const double& );  //!< write double
    128         void          output( const float& );  //!< write float
    129         void          output( const int& ); //!< write int
    130         void          output( const long& ); //!< write long
    131         void          output( const char& );  //!< write a single character
    132     private: // use of copy constructor is not allowed
    133         IO_GenEvent( const IO_GenEvent& ) : IO_BaseClass() {}
    134     private: // data members
    135         std::ios::openmode  m_mode;
    136         std::fstream        m_file;
    137         std::ostream *      m_ostr;
    138         std::istream *      m_istr;
    139         std::ios *          m_iostr;
    140         bool                m_finished_first_event_io;
    141         bool                m_have_file;
    142         CommonIO            m_common_io;
    143        
    144     };
     104private: // use of copy constructor is not allowed
     105    IO_GenEvent( const IO_GenEvent& ) : IO_BaseClass() {}
    145106
    146     //////////////
    147     // Inlines  //
    148     //////////////
     107private: // data members
     108    std::ios::openmode  m_mode;
     109    std::fstream        m_file;
     110    std::ostream *      m_ostr;
     111    std::istream *      m_istr;
     112    std::ios *          m_iostr;
     113    bool                m_have_file;
     114    IO_Exception::ErrorType m_error_type;
     115    std::string         m_error_message;
    149116
    150     inline void IO_GenEvent::output( const double& d ) {
    151         if( m_ostr  ) {
    152             if ( d == 0. ) {
    153                 *m_ostr << ' ' << (int)0;
    154             } else {
    155                 *m_ostr << ' ' << d;
    156             }
    157         }
     117};
     118
     119//////////////
     120// Inlines  //
     121//////////////
     122
     123inline int  IO_GenEvent::rdstate() const {
     124    int state;
     125    if( m_istr ) {
     126        state =  (int)m_istr->rdstate();
     127    } else {
     128        state =  (int)m_ostr->rdstate();
    158129    }
    159     inline void IO_GenEvent::output( const float& d ) {
    160         if( m_ostr  ) {
    161             if ( d == 0. ) {
    162                 *m_ostr << ' ' << (int)0;
    163             } else {
    164                 *m_ostr << ' ' << d;
    165             }
    166         }
     130    return state;
     131}
     132
     133inline void IO_GenEvent::clear() {
     134    if( m_istr ) {
     135        m_istr->clear();
     136    } else {
     137        m_ostr->clear();
    167138    }
    168     inline void IO_GenEvent::output( const int& i ) {
    169         if( m_ostr  ) {
    170             if ( i == 0. ) {
    171                 *m_ostr << ' ' << (int)0;
    172             } else {
    173                 *m_ostr << ' ' << i;
    174             }
    175         }
    176     }
    177     inline void IO_GenEvent::output( const long& i ) {
    178         if( m_ostr  ) {
    179             if ( i == 0. ) {
    180                 *m_ostr << ' ' << (int)0;
    181             } else {
    182                 *m_ostr << ' ' << i;
    183             }
    184         }
    185     }
    186     inline void IO_GenEvent::output( const char& c ) {
    187         if( m_ostr  ) {
    188             if ( c ) {
    189                 *m_ostr << c;
    190             } else {
    191                 *m_ostr << ' ' ;
    192             }
    193         }
    194     }
    195     inline int  IO_GenEvent::rdstate() const {
    196         int state;
    197         if( m_istr ) {
    198             state =  (int)m_istr->rdstate();
    199         } else {
    200             state =  (int)m_ostr->rdstate();
    201         }
    202         return state;
    203     }
    204     inline void IO_GenEvent::clear() {
    205         if( m_istr ) {
    206             m_istr->clear();
    207         } else {
    208             m_ostr->clear();
    209         }
    210     }
    211     // these are required by IO_BaseClass, but not used here
    212     inline void IO_GenEvent::write_particle_data_table(const ParticleDataTable*) {;}
    213     inline bool IO_GenEvent::fill_particle_data_table( ParticleDataTable* )
    214     { return false;}
     139}
     140
     141inline int IO_GenEvent::error_type() const {
     142    return m_error_type;
     143}
     144
     145inline const std::string & IO_GenEvent::error_message() const {
     146    return m_error_message;
     147}
    215148
    216149} // HepMC
Note: See TracChangeset for help on using the changeset viewer.