StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
IO_GenEvent.h
1 //--------------------------------------------------------------------------
2 #ifndef HEPMC_IO_GENEVENT_H
3 #define HEPMC_IO_GENEVENT_H
4 
6 // garren@fnal.gov, July 2007
7 // with input from Gavin Salam, salam@lpthe.jussieu.fr
8 //
9 // event input/output in ascii format for machine reading
10 // This class persists all information found in a GenEvent
12 
13 #include <fstream>
14 #include <string>
15 #include <map>
16 #include <vector>
17 #include "HepMC/IO_BaseClass.h"
18 #include "HepMC/IO_Exception.h"
19 #include "HepMC/Units.h"
20 
21 namespace HepMC {
22 
23 class GenEvent;
24 class GenVertex;
25 class GenParticle;
26 class HeavyIon;
27 class PdfInfo;
28 
30 
63 class IO_GenEvent : public IO_BaseClass {
64 public:
66  IO_GenEvent( const std::string& filename="IO_GenEvent.dat",
67  std::ios::openmode mode=std::ios::out );
69  IO_GenEvent( std::istream & );
71  IO_GenEvent( std::ostream & );
72  virtual ~IO_GenEvent();
73 
75  void write_event( const GenEvent* evt );
77  bool fill_next_event( GenEvent* evt );
81  void write_comment( const std::string comment );
82 
83  int rdstate() const;
84  void clear();
85 
87  void print( std::ostream& ostr = std::cout ) const;
88 
93  void use_input_units( Units::MomentumUnit, Units::LengthUnit );
94 
97  void precision( int );
98 
100  int error_type() const;
102  const std::string & error_message() const;
103 
104 private: // use of copy constructor is not allowed
105  IO_GenEvent( const IO_GenEvent& ) : IO_BaseClass() {}
106 
107 private: // 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;
116 
117 };
118 
120 // Inlines //
122 
123 inline 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();
129  }
130  return state;
131 }
132 
133 inline void IO_GenEvent::clear() {
134  if( m_istr ) {
135  m_istr->clear();
136  } else {
137  m_ostr->clear();
138  }
139 }
140 
141 inline int IO_GenEvent::error_type() const {
142  return m_error_type;
143 }
144 
145 inline const std::string & IO_GenEvent::error_message() const {
146  return m_error_message;
147 }
148 
149 } // HepMC
150 
151 #endif // HEPMC_IO_GENEVENT_H
152 //--------------------------------------------------------------------------
void write_event(const GenEvent *evt)
write this event
Definition: IO_GenEvent.cc:143
IO_GenEvent(const std::string &filename="IO_GenEvent.dat", std::ios::openmode mode=std::ios::out)
constructor requiring a file name and std::ios mode
Definition: IO_GenEvent.cc:16
void clear()
clear the IO stream
Definition: IO_GenEvent.h:133
const std::string & error_message() const
the read error message string
Definition: IO_GenEvent.h:145
The GenEvent class is the core of HepMC.
Definition: GenEvent.h:155
void print(std::ostream &ostr=std::cout) const
write to ostr
Definition: IO_GenEvent.cc:86
IO_GenEvent also deals with HeavyIon and PdfInfo.
Definition: IO_GenEvent.h:63
all input/output classes inherit from IO_BaseClass
Definition: IO_BaseClass.h:34
int error_type() const
integer (enum) associated with read error
Definition: IO_GenEvent.h:141
void precision(int)
Definition: IO_GenEvent.cc:96
int rdstate() const
check the state of the IO stream
Definition: IO_GenEvent.h:123
bool fill_next_event(GenEvent *evt)
get the next event
Definition: IO_GenEvent.cc:109
void write_comment(const std::string comment)
Definition: IO_GenEvent.cc:162
void use_input_units(Units::MomentumUnit, Units::LengthUnit)
Definition: IO_GenEvent.cc:79
ErrorType
IO error types.
Definition: IO_Exception.h:34