Fork me on GitHub

source: svn/trunk/Utilities/HepMC/interface/IO_BaseClass.h@ 493

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

first test

File size: 5.4 KB
Line 
1//--------------------------------------------------------------------------
2#ifndef HEPMC_IO_BASECLASS_H
3#define HEPMC_IO_BASECLASS_H
4
5//////////////////////////////////////////////////////////////////////////
6// Matt.Dobbs@Cern.CH, November 1999, refer to:
7// M. Dobbs and J.B. Hansen, "The HepMC C++ Monte Carlo Event Record for
8// High Energy Physics", Computer Physics Communications (to be published).
9//
10// event input/output base class
11//////////////////////////////////////////////////////////////////////////
12//
13// class from which all input/output classes shall inherit from.
14// i.e.: if you want to write events to hbook ntuples,
15// then inherit from this class and re-define read_event()
16// and write_event()
17//
18// (Possible extension: Could make this an input iterator)
19//
20
21#include <iostream>
22#include "ParticleDataTable.h"
23#include "GenEvent.h"
24
25namespace HepMC {
26
27 //! all input/output classes inherit from IO_BaseClass
28
29 ///
30 /// \class IO_BaseClass
31 /// If you want to write a new IO class,
32 /// then inherit from this class and re-define read_event()
33 /// and write_event()
34 ///
35 class IO_BaseClass {
36 public:
37 virtual ~IO_BaseClass() {}
38
39 /// write this GenEvent
40 virtual void write_event( const GenEvent* ) =0;
41 /// fill this GenEvent
42 virtual bool fill_next_event( GenEvent* ) =0;
43 /// write this ParticleDataTable
44 virtual void write_particle_data_table( const ParticleDataTable* ) =0;
45 /// fill this ParticleDataTable
46 virtual bool fill_particle_data_table( ParticleDataTable* ) =0;
47 /// write output to ostr
48 virtual void print( std::ostream& ostr = std::cout ) const;
49 //
50 // the read_next_event() and read_particle_data_table() differ from
51 // the fill_***() methods in that they create a new event or pdt
52 // before calling the corresponding fill_*** method
53 // (they are not intended to be over-ridden)
54 GenEvent* read_next_event(); //!< do not over-ride
55 ParticleDataTable* read_particle_data_table(); //!< do not over-ride
56 //
57 // The overloaded stream operators >>,<< are identical to
58 // read_next_event and write_event methods respectively.
59 // (or read_particle_data_table and write_particle_data_table)
60 // the event argument for the overloaded stream operators is a pointer,
61 // which is passed by reference.
62 // i.e. GenEvent* evt;
63 // io >> evt;
64 // will give the expected result.
65 // (note: I don't see any reason to have separate const and non-const
66 // versions of operator<<, but the pedantic ansi standard insists
67 // on it)
68 /// the same as read_next_event
69 virtual GenEvent*& operator>>( GenEvent*& );
70 /// the same as write_event
71 virtual const GenEvent*& operator<<( const GenEvent*& );
72 /// the same as write_event
73 virtual GenEvent*& operator<<( GenEvent*& );
74 /// the same as read_particle_data_table
75 virtual ParticleDataTable*& operator>>( ParticleDataTable*& );
76 /// the same as write_particle_data_table
77 virtual const ParticleDataTable*& operator<<( const
78 ParticleDataTable*& );
79 /// the same as write_particle_data_table
80 virtual ParticleDataTable*& operator<<( ParticleDataTable*& );
81 };
82
83 //////////////
84 // Inlines //
85 //////////////
86
87 inline GenEvent* IO_BaseClass::read_next_event() {
88 /// creates a new event and fills it by calling
89 /// the sister method read_next_event( GenEvent* )
90 //
91 // 1. create an empty event container
92 GenEvent* evt = new GenEvent();
93 // 2. fill the evt container - if the read is successful, return the
94 // pointer, otherwise return null and delete the evt
95 if ( fill_next_event( evt ) ) return evt;
96 // note: the below delete is only reached if read fails
97 // ... thus there is not much overhead in new then delete
98 // since this statement is rarely reached
99 delete evt;
100 return 0;
101 }
102
103 inline ParticleDataTable* IO_BaseClass::read_particle_data_table() {
104 /// creates a new particle data table and fills it by calling
105 /// the sister method read_particle_data_table( ParticleDataTable* )
106 //
107 // 1. create an empty pdt
108 ParticleDataTable* pdt = new ParticleDataTable();
109 // 2. fill the pdt container - if the read is successful, return the
110 // pointer, otherwise return null and delete the evt
111 if ( fill_particle_data_table( pdt ) ) return pdt;
112 // next statement is only reached if read fails
113 delete pdt;
114 return 0;
115 }
116
117 inline void IO_BaseClass::print( std::ostream& ostr ) const {
118 ostr << "IO_BaseClass: abstract parent I/O class. " << std::endl;
119 }
120
121 inline GenEvent*& IO_BaseClass::operator>>( GenEvent*& evt ){
122 evt = read_next_event();
123 return evt;
124 }
125
126 inline const GenEvent*& IO_BaseClass::operator<<(
127 const GenEvent*& evt ) {
128 write_event( evt );
129 return evt;
130 }
131
132 inline GenEvent*& IO_BaseClass::operator<<( GenEvent*& evt ) {
133 write_event( evt );
134 return evt;
135 }
136
137 inline ParticleDataTable*& IO_BaseClass::operator>>(
138 ParticleDataTable*& pdt ){
139 pdt = read_particle_data_table();
140 return pdt;
141 }
142
143 inline const ParticleDataTable*& IO_BaseClass::operator<<(
144 const ParticleDataTable*& pdt ) {
145 write_particle_data_table( pdt );
146 return pdt;
147 }
148
149 inline ParticleDataTable*& IO_BaseClass::operator<<(
150 ParticleDataTable*& pdt ) {
151 write_particle_data_table( pdt );
152 return pdt;
153 }
154
155} // HepMC
156
157#endif // HEPMC_IO_BASECLASS_H
158//--------------------------------------------------------------------------
159
160
161
Note: See TracBrowser for help on using the repository browser.