source: HiSusy/trunk/hepmc/x86_64-slc5-gcc41-opt/include/HepMC/IO_AsciiParticles.h @ 1

Last change on this file since 1 was 1, checked in by zerwas, 11 years ago

first import of structure, PYTHIA8 and DELPHES

File size: 3.8 KB
Line 
1//--------------------------------------------------------------------------
2#ifndef HEPMC_IO_ASCIIPARTICLES_H
3#define HEPMC_IO_ASCIIPARTICLES_H
4
5//////////////////////////////////////////////////////////////////////////
6// Mikhail.Kirsanov@Cern.CH, 2006
7// event input/output in ascii format for eye and machine reading
8//////////////////////////////////////////////////////////////////////////
9//
10// Strategy for reading or writing events as machine readable
11//  ascii to a file. When instantiating, the mode of file to be created
12//  must be specified. Options are:
13//      std::ios::in     open file for input
14//      std::ios::out    open file for output
15//      std::ios::trunc  erase old file when opening (i.e. ios::out|ios::trunc
16//                    removes oldfile, and creates a new one for output )
17//      std::ios::app    append output to end of file
18//  for the purposes of this class, simultaneous input and output mode
19//  ( std::ios::in | std::ios::out ) is not allowed.
20//
21// Event listings are preceded by the key:
22//  "HepMC::IO_AsciiParticles-START_EVENT_LISTING\n"
23//  and terminated by the key:
24//  "HepMC::IO_AsciiParticles-END_EVENT_LISTING\n"
25// Comments are allowed. They need not be preceded by anything, though if
26//  a comment is written using write_comment( const string ) then it will be
27//  preceded by "HepMC::IO_AsciiParticles-COMMENT\n"
28// Each event, vertex, particle, particle data is preceded by
29//  "E ","V ","P ","D "    respectively.
30// Comments may appear anywhere in the file -- so long as they do not contain
31//  any of the 4 start/stop keys.
32//
33
34#include <fstream>
35#include <string>
36#include <map>
37#include <vector>
38#include "HepMC/IO_BaseClass.h"
39
40namespace HepMC {
41
42    class GenEvent;
43    class GenVertex;
44    class GenParticle;
45
46    //! event input/output in ascii format for eye and machine reading
47
48    ///
49    /// \class IO_AsciiParticles
50    /// Strategy for reading or writing events as machine readable
51    ///  ascii to a file. When instantiating, the mode of file to be created
52    ///  must be specified.
53    ///
54    class IO_AsciiParticles : public IO_BaseClass {
55    public:
56        /// constructor requiring a file name and std::ios mode
57        IO_AsciiParticles( const char* filename="IO_AsciiParticles.dat", 
58                  std::ios::openmode mode=std::ios::out );
59        virtual       ~IO_AsciiParticles();
60
61        /// write this event
62        void          write_event( const GenEvent* evt );
63        /// get the next event
64        bool          fill_next_event( GenEvent* evt );
65        /// insert a comment directly into the output file --- normally you
66        ///  only want to do this at the beginning or end of the file. All
67        ///  comments are preceded with "HepMC::IO_AsciiParticles-COMMENT\n"
68        void          write_comment( const std::string comment );
69
70        /// set output precision
71        void          setPrecision(int iprec);
72
73        int           rdstate() const;  //!< check the state of the IO stream
74        void          clear();  //!< clear the IO stream
75
76        /// write to ostr
77        void          print( std::ostream& ostr = std::cout ) const;
78
79    protected: // for internal use only
80        /// write end tag
81        bool          write_end_listing();
82    private: // use of copy constructor is not allowed
83        IO_AsciiParticles( const IO_AsciiParticles& ) : IO_BaseClass() {}
84    private: // data members
85    int                 m_precision;
86        std::ios::openmode  m_mode;
87        std::fstream*       m_file;
88    std::ostream*       m_outstream;
89        bool                m_finished_first_event_io;
90    };
91
92    //////////////
93    // Inlines  //
94    //////////////
95
96    inline int  IO_AsciiParticles::rdstate() const { return (int)m_file->rdstate(); }
97    inline void IO_AsciiParticles::clear() { m_file->clear(); }
98    inline void IO_AsciiParticles::setPrecision(int iprec) { m_precision=iprec; }
99
100} // HepMC
101
102#endif  // HEPMC_IO_ASCIIPARTICLES_H
103//--------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.