StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
IO_AsciiParticles.h
1 //--------------------------------------------------------------------------
2 #ifndef HEPMC_IO_ASCIIPARTICLES_H
3 #define HEPMC_IO_ASCIIPARTICLES_H
4 
6 // Mikhail.Kirsanov@Cern.CH, 2006
7 // event input/output in ascii format for eye and machine reading
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 
40 namespace HepMC {
41 
42  class GenEvent;
43  class GenVertex;
44  class GenParticle;
45 
47 
55  public:
57  IO_AsciiParticles( const char* filename="IO_AsciiParticles.dat",
58  std::ios::openmode mode=std::ios::out );
59  virtual ~IO_AsciiParticles();
60 
62  void write_event( const GenEvent* evt );
64  bool fill_next_event( GenEvent* evt );
68  void write_comment( const std::string comment );
69 
71  void setPrecision(int iprec);
72 
73  int rdstate() const;
74  void clear();
75 
77  void print( std::ostream& ostr = std::cout ) const;
78 
79  protected: // for internal use only
81  bool write_end_listing();
82  private: // use of copy constructor is not allowed
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 
93  // Inlines //
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 //--------------------------------------------------------------------------
IO_AsciiParticles(const char *filename="IO_AsciiParticles.dat", std::ios::openmode mode=std::ios::out)
constructor requiring a file name and std::ios mode
bool fill_next_event(GenEvent *evt)
get the next event
bool write_end_listing()
write end tag
The GenEvent class is the core of HepMC.
Definition: GenEvent.h:155
int rdstate() const
check the state of the IO stream
void clear()
clear the IO stream
void write_event(const GenEvent *evt)
write this event
all input/output classes inherit from IO_BaseClass
Definition: IO_BaseClass.h:34
void write_comment(const std::string comment)
void setPrecision(int iprec)
set output precision
event input/output in ascii format for eye and machine reading
void print(std::ostream &ostr=std::cout) const
write to ostr