19 : m_file(filename), m_stream(nullptr), m_isstream(false)
22 HEPMC3_ERROR(
"ReaderHEPEVT: could not open input file: " << filename)
26 set_run_info(std::make_shared<GenRunInfo>());
27 m_hepevt_interface.allocate_internal_storage();
33 : m_stream(&stream), m_isstream(true)
36 HEPMC3_ERROR(
"ReaderHEPEVT: could not open input stream ")
40 set_run_info(std::make_shared<GenRunInfo>());
41 m_hepevt_interface.allocate_internal_storage();
46 : m_shared_stream(s_stream), m_stream(s_stream.get()), m_isstream(true)
49 HEPMC3_ERROR(
"ReaderHEPEVT: could not open input stream ")
53 set_run_info(std::make_shared<GenRunInfo>());
54 m_hepevt_interface.allocate_internal_storage();
61 std::array<char, 262144> buf;
67 if ( peek ==
'E' ) nn--;
68 if ( nn < 0 ) {
return true; }
78 std::array<char, 512> buf_e;
79 bool eventline =
false;
85 if ( strlen(buf_e.data()) == 0 )
return false;
86 std::stringstream st_e(buf_e.data());
91 if (!(st_e >> attr))
break;
92 if (attr ==
' ') {
continue; }
96 eventline =
static_cast<bool>(st_e >> m_i >> m_p);
108 std::array<char, 512> buf_p;
109 std::array<char, 512> buf_v;
110 std::array<int, 6> intcodes;
111 std::array<double, 5> fltcodes1;
112 std::array<double, 5> fltcodes2;
114 if ( strlen(buf_p.data()) == 0 )
return false;
115 if (
m_options.count(
"vertices_positions_are_absent") == 0)
118 if ( strlen(buf_v.data()) == 0 )
return false;
120 std::stringstream st_p(buf_p.data());
121 std::stringstream st_v(buf_v.data());
122 if (
m_options.count(
"vertices_positions_are_absent") == 0)
124 if (!
static_cast<bool>(st_p >> intcodes[0] >> intcodes[1] >> intcodes[2] >> intcodes[3] >> intcodes[4] >> intcodes[5] >> fltcodes1[0] >> fltcodes1[1] >> fltcodes1[2] >> fltcodes1[3] >> fltcodes1[4])) {
HEPMC3_ERROR(
"ReaderHEPEVT: HEPMC3_ERROR reading particle momenta");
return false;}
125 if (!
static_cast<bool>(st_v >> fltcodes2[0] >> fltcodes2[1] >> fltcodes2[2] >> fltcodes2[3])) {
HEPMC3_ERROR(
"ReaderHEPEVT: HEPMC3_ERROR reading particle vertex");
return false;}
129 if (!
static_cast<bool>(st_p>> intcodes[0]>> intcodes[1] >> intcodes[4] >> intcodes[5] >> fltcodes1[0] >> fltcodes1[1] >> fltcodes1[2] >> fltcodes1[4])) {
HEPMC3_ERROR(
"ReaderHEPEVT: HEPMC3_ERROR reading particle momenta");
return false;}
132 fltcodes1[3] = std::sqrt(fltcodes1[0]*fltcodes1[0]+fltcodes1[1]*fltcodes1[1]+fltcodes1[2]*fltcodes1[2]+fltcodes1[4]*fltcodes1[4]);
160 std::shared_ptr<GenRunInfo> g = std::make_shared<GenRunInfo>();
161 std::vector<std::string> weightnames(1,
"0");
162 std::vector<double> wts(1,1.0);
163 g->set_weight_names(weightnames);
176 if ( !
m_file.is_open())
return;
#define HEPMC3_ERROR(MESSAGE)
Macro for printing error messages.
Definition of class ReaderHEPEVT.
Stores event-related information.
void set_run_info(std::shared_ptr< GenRunInfo > run)
Set the GenRunInfo object by smart pointer.
const std::vector< double > & weights() const
Get event weight values as a vector.
void clear()
Remove contents of this event.
void set_id(const int index, const int id)
Set PDG particle id.
bool HEPEVT_to_GenEvent(GenEvent *evt) const
Convert HEPEVT to GenEvent.
void zero_everything()
Set all entries in HEPEVT to zero.
void set_parents(const int index, const int firstparent, const int lastparent)
Set parents.
void set_momentum(const int index, const double px, const double py, const double pz, const double e)
Set 4-momentum.
void set_children(const int index, const int firstchild, const int lastchild)
Set children.
void set_position(const int index, const double x, const double y, const double z, const double t)
Set position in time-space.
int number_entries() const
Get number of entries.
void set_mass(const int index, double mass)
Set mass.
void set_event_number(const int evtno)
Set event number.
void set_status(const int index, const int status)
Set status code.
void set_number_entries(const int noentries)
Set number of entries.
bool m_isstream
toggles usage of m_file or m_stream
bool read_event(GenEvent &evt) override
Read event from file.
ReaderHEPEVT(const std::string &filename)
Default constructor.
HEPEVT_Wrapper_Template< 100000 > m_hepevt_interface
Templated HEPEVT interface.
bool failed() override
Get stream error state.
bool skip(const int) override
skip events
std::ifstream m_file
Input file.
virtual bool read_hepevt_particle(int i)
read particle from file
virtual bool read_hepevt_event_header()
Find and read event header line from file.
void close() override
Close file stream.
std::istream * m_stream
For ctor when reading from stream.
std::map< std::string, std::string > m_options
Options.