Fork me on GitHub

source: svn/trunk/Utilities/HepMC/interface/IO_AsciiParticles.h@ 349

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

first test

File size: 4.3 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/particleData 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 "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/particleData 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 inline void write_particle_data_table(const ParticleDataTable*);
66 inline bool fill_particle_data_table( ParticleDataTable* );
67 /// insert a comment directly into the output file --- normally you
68 /// only want to do this at the beginning or end of the file. All
69 /// comments are preceded with "HepMC::IO_AsciiParticles-COMMENT\n"
70 void write_comment( const std::string comment );
71
72 /// set output precision
73 void setPrecision(int iprec);
74
75 int rdstate() const; //!< check the state of the IO stream
76 void clear(); //!< clear the IO stream
77
78 /// write to ostr
79 void print( std::ostream& ostr = std::cout ) const;
80
81 protected: // for internal use only
82 /// write end tag
83 bool write_end_listing();
84 private: // use of copy constructor is not allowed
85 IO_AsciiParticles( const IO_AsciiParticles& ) : IO_BaseClass() {}
86 private: // data members
87 int m_precision;
88 std::ios::openmode m_mode;
89 std::fstream* m_file;
90 std::ostream* m_outstream;
91 bool m_finished_first_event_io;
92 };
93
94 //////////////
95 // Inlines //
96 //////////////
97
98 inline int IO_AsciiParticles::rdstate() const { return (int)m_file->rdstate(); }
99 inline void IO_AsciiParticles::clear() { m_file->clear(); }
100 inline void IO_AsciiParticles::setPrecision(int iprec) { m_precision=iprec; }
101
102 /////////////////////
103 // Inline dummies //
104 /////////////////////
105
106 void IO_AsciiParticles::write_particle_data_table(const ParticleDataTable*) {;}
107 bool IO_AsciiParticles::fill_particle_data_table( ParticleDataTable* ) {return false;}
108
109} // HepMC
110
111#endif // HEPMC_IO_ASCIIPARTICLES_H
112//--------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.