Newer
Older
//************************************************************************//
// //
// Copyright 2013 Bertram Kopf (bertram@ep1.rub.de) //
// Julian Pychy (julian@ep1.rub.de) //
// - Ruhr-Universität Bochum //
// //
// This file is part of Pawian. //
// //
// Pawian is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// (at your option) any later version. //
// //
// Pawian is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with Pawian. If not, see <http://www.gnu.org/licenses/>. //
// //
//************************************************************************//
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#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();
}