Fork me on GitHub

source: svn/trunk/Utilities/HepMC/interface/CommonIO.h@ 444

Last change on this file since 444 was 349, checked in by severine ovyn, 16 years ago

first test

File size: 5.2 KB
Line 
1#ifndef HEPMC_COMMON_IO_H
2#define HEPMC_COMMON_IO_H
3// ----------------------------------------------------------------------
4//
5// CommonIO.h
6// Author: Lynn Garren
7//
8// Allowed keys used at the beginning and end of HepMC data dumps
9//
10// ----------------------------------------------------------------------
11
12#include <fstream>
13#include <string>
14
15#include "GenEvent.h"
16#include "TempParticleMap.h"
17#include "ParticleDataTable.h"
18
19namespace HepMC {
20
21/// The known_io enum is used to track which type of input is being read
22enum known_io { gen=1, ascii, extascii, ascii_pdt, extascii_pdt };
23
24class CommonIO {
25
26public:
27
28 CommonIO();
29 ~CommonIO() {;}
30
31 // input keys - IO_GenEvent is strongly recommended
32 std::string IO_GenEvent_Key() const { return m_io_genevent_start; }
33 std::string IO_GenEvent_End() const { return m_io_genevent_end; }
34 // IO_Ascii is deprecated, but we want to be able to read these files
35 std::string IO_Ascii_Key() const { return m_io_ascii_start; }
36 std::string IO_Ascii_End() const { return m_io_ascii_end; }
37 // IO_ExtendedAscii has been removed, but we want to be able to read these files
38 std::string IO_ExtendedAscii_Key() const { return m_io_extendedascii_start; }
39 std::string IO_ExtendedAscii_End() const { return m_io_extendedascii_end; }
40 /// get IO type
41 int io_type() const { return m_io_type; }
42
43 // write keys
44 void write_IO_GenEvent_Key( std::ostream& );
45 void write_IO_GenEvent_End( std::ostream& );
46 // write keys for deprecated IO methods
47 void write_IO_Ascii_Key( std::ostream& );
48 void write_IO_Ascii_End( std::ostream& );
49 // write keys for deprecated particle data IO methods
50 void write_IO_Ascii_PDT_Key( std::ostream& );
51 void write_IO_Ascii_PDT_End( std::ostream& );
52
53 // methods to read input
54
55 /// look for line type (key)
56 int find_file_type( std::istream& );
57
58 /// look for line type (key)
59 int find_end_key( std::istream& );
60
61 bool read_io_ascii( std::istream* is, GenEvent* evt );
62
63 bool read_io_extendedascii( std::istream* is, GenEvent* evt );
64
65 bool read_io_genevent( std::istream* is, GenEvent* evt );
66
67 bool read_units( std::istream* is, GenEvent* evt );
68
69 /// needed when reading a file without units if those units are
70 /// different than the declared default units
71 /// (e.g., the default units are MeV, but the file was written with GeV)
72 /// This method is not necessary if the units are written in the file
73 void use_input_units( Units::MomentumUnit, Units::LengthUnit );
74
75 /// ParticleDataTable is deprecated.
76 /// We include this method for reading old files which may have ParticleData information.
77 bool read_io_particle_data_table( std::istream*, ParticleDataTable* );
78
79protected:
80 // methods used by the read_io* methods
81 HeavyIon* read_heavy_ion( std::istream* );
82 PdfInfo* read_pdf_info( std::istream* );
83 GenParticle* read_particle( std::istream*, TempParticleMap& );
84 GenVertex* read_vertex( std::istream*, TempParticleMap& );
85 /// ParticleDataTable is deprecated.
86 /// We include this method for reading old files which may have ParticleData information.
87 ParticleData* read_particle_data( std::istream*, ParticleDataTable* );
88
89private:
90 std::string m_io_genevent_start;
91 std::string m_io_ascii_start;
92 std::string m_io_extendedascii_start;
93 std::string m_io_genevent_end;
94 std::string m_io_ascii_end;
95 std::string m_io_extendedascii_end;
96 // particle data method keys
97 std::string m_io_ascii_pdt_start;
98 std::string m_io_extendedascii_pdt_start;
99 std::string m_io_ascii_pdt_end;
100 std::string m_io_extendedascii_pdt_end;
101 // io type
102 int m_io_type;
103 // default io units - used only when reading a file with no units
104 Units::MomentumUnit m_io_momentum_unit;
105 Units::LengthUnit m_io_position_unit;
106
107};
108
109// inline methods
110
111inline CommonIO::CommonIO()
112: m_io_genevent_start("HepMC::IO_GenEvent-START_EVENT_LISTING"),
113 m_io_ascii_start("HepMC::IO_Ascii-START_EVENT_LISTING"),
114 m_io_extendedascii_start("HepMC::IO_ExtendedAscii-START_EVENT_LISTING"),
115 m_io_genevent_end("HepMC::IO_GenEvent-END_EVENT_LISTING"),
116 m_io_ascii_end("HepMC::IO_Ascii-END_EVENT_LISTING"),
117 m_io_extendedascii_end("HepMC::IO_ExtendedAscii-END_EVENT_LISTING"),
118 m_io_ascii_pdt_start("HepMC::IO_Ascii-START_PARTICLE_DATA"),
119 m_io_extendedascii_pdt_start("HepMC::IO_ExtendedAscii-START_PARTICLE_DATA"),
120 m_io_ascii_pdt_end("HepMC::IO_Ascii-END_PARTICLE_DATA"),
121 m_io_extendedascii_pdt_end("HepMC::IO_ExtendedAscii-END_PARTICLE_DATA"),
122 m_io_type(0),
123 m_io_momentum_unit(Units::default_momentum_unit()),
124 m_io_position_unit(Units::default_length_unit())
125 {}
126
127inline void CommonIO::write_IO_GenEvent_Key( std::ostream& os )
128{ os << m_io_genevent_start << "\n"; }
129
130inline void CommonIO::write_IO_GenEvent_End( std::ostream& os )
131{ os << m_io_genevent_end << "\n"; }
132
133inline void CommonIO::write_IO_Ascii_Key( std::ostream& os )
134{ os << m_io_ascii_start << "\n"; }
135
136inline void CommonIO::write_IO_Ascii_End( std::ostream& os )
137{ os << m_io_ascii_end << "\n"; }
138
139inline void CommonIO::write_IO_Ascii_PDT_Key( std::ostream& os )
140{ os << m_io_ascii_pdt_start << "\n"; }
141
142inline void CommonIO::write_IO_Ascii_PDT_End( std::ostream& os )
143{ os << m_io_ascii_pdt_end << "\n"; }
144
145} // HepMC
146
147#endif // HEPMC_COMMON_IO_H
Note: See TracBrowser for help on using the repository browser.