18 : m_file(filename), m_stream(0), m_isstream(false)
21 HEPMC3_ERROR(
"ReaderHEPEVT: could not open input file: " << filename)
32 : m_stream(&stream), m_isstream(true)
35 HEPMC3_ERROR(
"ReaderHEPEVT: could not open input stream ")
45 : m_shared_stream(s_stream), m_stream(s_stream.get()), m_isstream(true)
48 HEPMC3_ERROR(
"ReaderHEPEVT: could not open input stream ")
60 const size_t max_buffer_size = 512*512;
61 char buf[max_buffer_size];
67 if ( peek ==
'E' ) nn--;
68 if ( nn < 0 )
return true;
78 const size_t max_e_buffer_size = 512;
79 char buf_e[max_e_buffer_size];
80 bool eventline =
false;
85 if ( strlen(buf_e) == 0 )
return false;
86 std::stringstream st_e(buf_e);
91 if (!(st_e >> attr))
break;
92 if (attr ==
' ')
continue;
93 else eventline =
false;
96 eventline =
static_cast<bool>(st_e >> m_i >> m_p);
108 const size_t max_p_buffer_size = 512;
109 const size_t max_v_buffer_size = 512;
110 char buf_p[max_p_buffer_size];
111 char buf_v[max_v_buffer_size];
116 if ( strlen(buf_p) == 0 )
return false;
120 if ( strlen(buf_v) == 0 )
return false;
122 std::stringstream st_p(buf_p);
123 std::stringstream st_v(buf_v);
126 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;}
127 if (!
static_cast<bool>(st_v >> fltcodes2[0] >> fltcodes2[1] >> fltcodes2[2] >> fltcodes2[3])) {
HEPMC3_ERROR(
"ReaderHEPEVT: HEPMC3_ERROR reading particle vertex");
return false;}
131 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;}
134 fltcodes1[3] = std::sqrt(fltcodes1[0]*fltcodes1[0]+fltcodes1[1]*fltcodes1[1]+fltcodes1[2]*fltcodes1[2]+fltcodes1[4]*fltcodes1[4]);
161 std::shared_ptr<GenRunInfo> g = std::make_shared<GenRunInfo>();
162 std::vector<std::string> weightnames;
163 weightnames.push_back(
"0");
164 std::vector<double> wts;
166 g->set_weight_names(weightnames);
179 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 allocate_internal_storage()
Allocates m_internal_storage storage in smart pointer to hold HEPEVT of fixed size.
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
void set_run_info(std::shared_ptr< GenRunInfo > run)
Set the global GenRunInfo object.