|
||||
File indexing completed on 2025-01-18 10:01:10
0001 //-------------------------------------------------------------------------- 0002 #ifndef HEPMC_IO_BASECLASS_H 0003 #define HEPMC_IO_BASECLASS_H 0004 0005 ////////////////////////////////////////////////////////////////////////// 0006 // Matt.Dobbs@Cern.CH, November 1999, refer to: 0007 // M. Dobbs and J.B. Hansen, "The HepMC C++ Monte Carlo Event Record for 0008 // High Energy Physics", Computer Physics Communications (to be published). 0009 // 0010 // event input/output base class 0011 ////////////////////////////////////////////////////////////////////////// 0012 // 0013 // class from which all input/output classes shall inherit from. 0014 // i.e.: if you want to write events to hbook ntuples, 0015 // then inherit from this class and re-define read_event() 0016 // and write_event() 0017 // 0018 // (Possible extension: Could make this an input iterator) 0019 // 0020 0021 #include <iostream> 0022 #include "HepMC/GenEvent.h" 0023 0024 namespace HepMC { 0025 0026 //! all input/output classes inherit from IO_BaseClass 0027 0028 /// 0029 /// \class IO_BaseClass 0030 /// If you want to write a new IO class, 0031 /// then inherit from this class and re-define read_event() 0032 /// and write_event() 0033 /// 0034 class IO_BaseClass { 0035 public: 0036 virtual ~IO_BaseClass() {} 0037 0038 /// write this GenEvent 0039 virtual void write_event( const GenEvent* ) =0; 0040 /// fill this GenEvent 0041 virtual bool fill_next_event( GenEvent* ) =0; 0042 /// write output to ostr 0043 virtual void print( std::ostream& ostr = std::cout ) const; 0044 // 0045 // the read_next_event() differs from 0046 // the fill_***() methods in that it creates a new event 0047 // before calling the corresponding fill_*** method 0048 // (they are not intended to be over-ridden) 0049 GenEvent* read_next_event(); //!< do not over-ride 0050 // 0051 // The overloaded stream operators >>,<< are identical to 0052 // read_next_event and write_event methods respectively. 0053 // (or read_particle_data_table and write_particle_data_table) 0054 // the event argument for the overloaded stream operators is a pointer, 0055 // which is passed by reference. 0056 // i.e. GenEvent* evt; 0057 // io >> evt; 0058 // will give the expected result. 0059 // (note: I don't see any reason to have separate const and non-const 0060 // versions of operator<<, but the pedantic ansi standard insists 0061 // on it) 0062 /// the same as read_next_event 0063 virtual GenEvent*& operator>>( GenEvent*& ); 0064 /// the same as write_event 0065 virtual const GenEvent*& operator<<( const GenEvent*& ); 0066 /// the same as write_event 0067 virtual GenEvent*& operator<<( GenEvent*& ); 0068 }; 0069 0070 ////////////// 0071 // Inlines // 0072 ////////////// 0073 0074 inline GenEvent* IO_BaseClass::read_next_event() { 0075 /// creates a new event and fills it by calling 0076 /// the sister method read_next_event( GenEvent* ) 0077 // 0078 // 1. create an empty event container 0079 GenEvent* evt = new GenEvent(); 0080 // 2. fill the evt container - if the read is successful, return the 0081 // pointer, otherwise return null and delete the evt 0082 if ( fill_next_event( evt ) ) return evt; 0083 // note: the below delete is only reached if read fails 0084 // ... thus there is not much overhead in new then delete 0085 // since this statement is rarely reached 0086 delete evt; 0087 return 0; 0088 } 0089 0090 inline void IO_BaseClass::print( std::ostream& ostr ) const { 0091 ostr << "IO_BaseClass: abstract parent I/O class. " << std::endl; 0092 } 0093 0094 inline GenEvent*& IO_BaseClass::operator>>( GenEvent*& evt ){ 0095 evt = read_next_event(); 0096 return evt; 0097 } 0098 0099 inline const GenEvent*& IO_BaseClass::operator<<( 0100 const GenEvent*& evt ) { 0101 write_event( evt ); 0102 return evt; 0103 } 0104 0105 inline GenEvent*& IO_BaseClass::operator<<( GenEvent*& evt ) { 0106 write_event( evt ); 0107 return evt; 0108 } 0109 0110 } // HepMC 0111 0112 #endif // HEPMC_IO_BASECLASS_H 0113 //-------------------------------------------------------------------------- 0114 0115 0116
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |