Class Reference for E1039 Core & Analysis Software
PHGenEventv1.cc
Go to the documentation of this file.
1 #include "PHGenEventv1.h"
2 
3 #include <HepMC/GenEvent.h>
4 
5 #include <sstream>
6 
8 
9 using namespace std;
10 
12  : _id(0),
13  _event_record(),
14  _stale(true),
15  _event(NULL)
16 {}
17 
18 PHGenEventv1::PHGenEventv1(const unsigned int id, HepMC::GenEvent& event)
19  : _id(id),
20  _event_record(),
21  _stale(true),
22  _event(NULL) {
23  set_event(event);
24  }
25 
27  : _id(phevent.get_id()),
28  _event_record(phevent.get_event_record()),
29  _stale(true),
30  _event(NULL)
31 {}
32 
34  : _id(phevent->get_id()),
35  _event_record(phevent->get_event_record()),
36  _stale(true),
37  _event(NULL)
38 {}
39 
41  if (_event) delete _event;
42 }
43 
44 const HepMC::GenEvent* PHGenEventv1::get_event() const {
45  if (stale()) refresh();
46  return (const HepMC::GenEvent*)_event;
47 }
48 
49 HepMC::GenEvent* PHGenEventv1::get_event() {
50  if (stale()) refresh();
51  return _event;
52 }
53 
54 void PHGenEventv1::set_event(HepMC::GenEvent& event) {
55 
56  _event_record.Clear();
57  if (_event) {
58  delete _event;
59  _event = NULL;
60  }
61 
62  std::stringstream streamer;
63  event.write(streamer);
64  _event_record = streamer.str();
65 
66  refresh();
67 }
68 
69 void PHGenEventv1::set_event(HepMC::GenEvent* event) {
70 
71  _event_record.Clear();
72  if (_event) {
73  delete _event;
74  _event = NULL;
75  }
76 
77  std::stringstream streamer;
78  event->write(streamer);
79  _event_record = streamer.str();
80 
81  refresh();
82 }
83 
85  if (stale()) refresh();
86  return _event->particles_size();
87 }
88 
90  if (stale()) refresh();
91  return _event->vertices_size();
92 }
93 
95  _id = 0;
96  _event_record.Clear();
97  _stale = true;
98  if (_event) {
99  delete _event;
100  _event = NULL;
101  }
102 }
103 
104 void PHGenEventv1::print(std::ostream& out) const {
105  if (stale()) refresh();
106  identify(out);
107  out << " id = " << _id << endl;
108  _event->print(out);
109 }
110 
111 void PHGenEventv1::refresh() const {
112 
113  if (_event) {
114  delete _event;
115  _event = NULL;
116  }
117 
118  _event = new HepMC::GenEvent();
119 
120  std::stringstream streamer;
121  streamer << _event_record;
122  _event->read(streamer);
123  _stale = false;
124 }
ClassImp(PHGenEventv1) using namespace std
#define NULL
Definition: Pdb.h:9
void set_event(HepMC::GenEvent &event)
Definition: PHGenEventv1.cc:54
void print(std::ostream &out=std::cout) const
void Reset()
Clear Event.
Definition: PHGenEventv1.cc:94
const HepMC::GenEvent * get_event() const
Definition: PHGenEventv1.cc:44
size_t particles_size() const
Definition: PHGenEventv1.cc:84
size_t vertices_size() const
Definition: PHGenEventv1.cc:89
void identify(std::ostream &out=std::cout) const
Definition: PHGenEventv1.h:38
virtual ~PHGenEventv1()
Definition: PHGenEventv1.cc:40