Fork me on GitHub

source: svn/trunk/Utilities/HepMC/interface/IO_GenEvent.h@ 654

Last change on this file since 654 was 572, checked in by cp3-support, 13 years ago

upgrade HepMC to version 2.06.05

File size: 5.0 KB
Line 
1//--------------------------------------------------------------------------
2#ifndef HEPMC_IO_GENEVENT_H
3#define HEPMC_IO_GENEVENT_H
4
5//////////////////////////////////////////////////////////////////////////
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
11//////////////////////////////////////////////////////////////////////////
12
13#include <fstream>
14#include <string>
15#include <map>
16#include <vector>
17#include "IO_BaseClass.h"
18#include "IO_Exception.h"
19#include "Units.h"
20
21namespace HepMC {
22
23class GenEvent;
24class GenVertex;
25class GenParticle;
26class HeavyIon;
27class PdfInfo;
28
29//! IO_GenEvent also deals with HeavyIon and PdfInfo
30
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();
73
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 );
82
83 int rdstate() const; //!< check the state of the IO stream
84 void clear(); //!< clear the IO stream
85
86 /// write to ostr
87 void print( std::ostream& ostr = std::cout ) const;
88
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 );
94
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;
103
104private: // use of copy constructor is not allowed
105 IO_GenEvent( const IO_GenEvent& ) : IO_BaseClass() {}
106
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;
116
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();
129 }
130 return state;
131}
132
133inline void IO_GenEvent::clear() {
134 if( m_istr ) {
135 m_istr->clear();
136 } else {
137 m_ostr->clear();
138 }
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}
148
149} // HepMC
150
151#endif // HEPMC_IO_GENEVENT_H
152//--------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.