Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <iostream>
#include "Event/HepMCEventList.hh"
#include "ErrLogger/ErrLogger.hh"
#include "HepMC/GenEvent.h"
#include "HepMC/IO_GenEvent.h"
HepMCEventList::HepMCEventList()
{
}
HepMCEventList::HepMCEventList(const std::vector<std::string>& files)
{
fillFromFiles(files);
}
HepMCEventList::HepMCEventList(const std::string& file){
fillFromFile(file);
}
HepMCEventList::~HepMCEventList()
{
for (currentEvent = eventList.begin();
currentEvent != eventList.end();
++currentEvent)
delete *currentEvent;
}
void HepMCEventList::add(HepMC::GenEvent* newEvent)
{
if (0 != newEvent)
eventList.push_back(newEvent);
else {
Alert << "can not add 0 pointer to event list" << endmsg;
exit(1);
}
return;
}
void HepMCEventList::removeEvents(unsigned int nBegin, unsigned int nEnd)
{
if ( nBegin < nEnd || eventList.size()>nEnd) {
Alert << "can not remove event no " << nBegin << " - " << nEnd
<< " from list" << endmsg;
exit(1);
}
eventList.erase(eventList.begin()+nBegin, eventList.begin()+nEnd);
}
bool HepMCEventList::fillFromFile(const std::string& file){
bool result=true;
std::ifstream* currentStream= new std::ifstream(file.c_str(), std::ios::in);
if (!currentStream) {
Alert << "can not open " << file << endmsg;
result=false;
exit(1);
}
HepMC::IO_GenEvent* hepIOin=new HepMC::IO_GenEvent(*currentStream);
hepIOin->use_input_units( HepMC::Units::GEV, HepMC::Units::MM );
HepMC::GenEvent* evt = hepIOin->read_next_event();
while ( evt ){
// if( evt->is_valid() ) {
// evt->print(std::cout);
// }
add(evt);
(*hepIOin) >> evt;
}
delete hepIOin;
delete currentStream;
return result;
}
bool HepMCEventList::fillFromFiles(const std::vector<std::string>& files){
bool result=true;
std::vector<std::string>::const_iterator iter = files.begin();
for (; iter != files.end(); ++iter){
if (fillFromFile(*iter)==false) result=false;
}
return result;
}
HepMC::GenEvent* HepMCEventList::nextEvent()
{
if (currentEvent != eventList.end()) {
HepMC::GenEvent* result = *currentEvent;
++currentEvent;
return result;
} else
return 0;
}
void HepMCEventList::rewind()
{
currentEvent = eventList.begin();
return;
}
int HepMCEventList::size()
{
return eventList.size();
}