21 : m_file(filename), m_stream(0), m_isstream(false)
24 HEPMC3_ERROR(
"ReaderHEPEVT: could not open input file: " << filename)
36 : m_stream(&stream), m_isstream(true)
39 HEPMC3_ERROR(
"ReaderHEPEVT: could not open input stream ")
51 const size_t max_buffer_size = 512*512;
52 char buf[max_buffer_size];
58 if ( peek ==
'E' ) nn--;
59 if ( nn < 0 )
return true;
69 const size_t max_e_buffer_size = 512;
70 char buf_e[max_e_buffer_size];
71 bool eventline =
false;
76 if ( strlen(buf_e) == 0 )
return false;
77 std::stringstream st_e(buf_e);
82 if (!(st_e >> attr))
break;
83 if (attr ==
' ')
continue;
84 else eventline =
false;
87 eventline =
static_cast<bool>(st_e >> m_i >> m_p);
99 const size_t max_p_buffer_size = 512;
100 const size_t max_v_buffer_size = 512;
101 char buf_p[max_p_buffer_size];
102 char buf_v[max_v_buffer_size];
107 if ( strlen(buf_p) == 0 )
return false;
111 if ( strlen(buf_v) == 0 )
return false;
113 std::stringstream st_p(buf_p);
114 std::stringstream st_v(buf_v);
117 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;}
118 if (!
static_cast<bool>(st_v >> fltcodes2[0] >> fltcodes2[1] >> fltcodes2[2] >> fltcodes2[3])) {
HEPMC3_ERROR(
"ReaderHEPEVT: HEPMC3_ERROR reading particle vertex");
return false;}
122 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;}
125 fltcodes1[3] = std::sqrt(fltcodes1[0]*fltcodes1[0]+fltcodes1[1]*fltcodes1[1]+fltcodes1[2]*fltcodes1[2]+fltcodes1[4]*fltcodes1[4]);
152 std::shared_ptr<GenRunInfo> g = std::make_shared<GenRunInfo>();
153 std::vector<std::string> weightnames;
154 weightnames.push_back(
"0");
155 std::vector<double> wts;
157 g->set_weight_names(weightnames);
171 if ( !
m_file.is_open())
return;
#define HEPMC3_ERROR(MESSAGE)
Macro for printing error messages.
Definition of class HEPEVT_Wrapper.
Definition of class ReaderHEPEVT.
Stores event-related information.
void set_run_info(std::shared_ptr< GenRunInfo > run)
Set the GenRunInfo object by smart pointer.
void clear()
Remove contents of this event.
const std::vector< double > & weights() const
Get event weight values as a vector.
static void set_mass(const int &index, double mass)
Set mass.
static void set_momentum(const int &index, const double &px, const double &py, const double &pz, const double &e)
Set 4-momentum.
static void set_number_entries(const int &noentries)
Set number of entries.
static void zero_everything()
Check for problems with HEPEVT common block.
static void set_id(const int &index, const int &id)
Set PDG particle id.
static void set_status(const int &index, const int &status)
Set status code.
static void set_hepevt_address(char *c)
Set Fortran block address.
static bool HEPEVT_to_GenEvent(GenEvent *evt)
Convert HEPEVT to GenEvent.
static void set_parents(const int &index, const int &firstparent, const int &lastparent)
Set parents.
static void set_position(const int &index, const double &x, const double &y, const double &z, const double &t)
Set position in time-space.
static void set_children(const int &index, const int &firstchild, const int &lastchild)
Set children.
static int number_entries()
Get number of entries.
static void set_event_number(const int &evtno)
Set event number.
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.
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.
char * hepevtbuffer
Pointer to HEPEVT Fortran common block/C struct.
std::istream * m_stream
For ctor when reading from stdin.
std::map< std::string, std::string > m_options
options
void set_run_info(std::shared_ptr< GenRunInfo > run)
Set the global GenRunInfo object.
Fortran common block HEPEVT.