HepMC3 event record library
ReaderAscii.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // This file is part of HepMC
4 // Copyright (C) 2014-2021 The HepMC collaboration (see AUTHORS for details)
5 //
6 ///
7 /// @file ReaderAscii.cc
8 /// @brief Implementation of \b class ReaderAscii
9 ///
10 #include <cstring>
11 #include <sstream>
12 
13 #include "HepMC3/ReaderAscii.h"
14 
15 #include "HepMC3/GenEvent.h"
16 #include "HepMC3/GenParticle.h"
17 #include "HepMC3/GenVertex.h"
18 #include "HepMC3/Units.h"
19 
20 namespace HepMC3 {
21 
22 
23 ReaderAscii::ReaderAscii(const std::string &filename)
24  : m_file(filename), m_stream(0), m_isstream(false)
25 {
26  if ( !m_file.is_open() ) {
27  HEPMC3_ERROR("ReaderAscii: could not open input file: " << filename)
28  }
29  set_run_info(std::make_shared<GenRunInfo>());
30 }
31 
32 ReaderAscii::ReaderAscii(std::istream & stream)
33  : m_stream(&stream), m_isstream(true)
34 {
35  if ( !m_stream->good() ) {
36  HEPMC3_ERROR("ReaderAscii: could not open input stream ")
37  }
38  set_run_info(std::make_shared<GenRunInfo>());
39 }
40 
41 
42 ReaderAscii::ReaderAscii(std::shared_ptr<std::istream> s_stream)
43  : m_shared_stream(s_stream), m_stream(s_stream.get()), m_isstream(true)
44 {
45  if ( !m_stream->good() ) {
46  HEPMC3_ERROR("ReaderAscii: could not open input stream ")
47  }
48  set_run_info(std::make_shared<GenRunInfo>());
49 }
50 
52 
53 bool ReaderAscii::skip(const int n)
54 {
55  const size_t max_buffer_size = 512*512;
56  char buf[max_buffer_size];
57  bool event_context = false;
58  bool run_info_context = false;
59  int nn = n;
60  while (!failed()) {
61  char peek;
62  if ( (!m_file.is_open()) && (!m_isstream) ) return false;
63  m_isstream ? peek = m_stream->peek() : peek = m_file.peek();
64  if ( peek == 'E' ) { event_context = true; nn--; }
65  //We have to read each run info.
66  if ( !event_context && ( peek == 'W' || peek == 'A' || peek == 'T' ) ) {
67  m_isstream ? m_stream->getline(buf, max_buffer_size) : m_file.getline(buf, max_buffer_size);
68  if (!run_info_context) {
69  set_run_info(std::make_shared<GenRunInfo>());
70  run_info_context = true;
71  }
72  if ( peek == 'W' ) {
73  parse_weight_names(buf);
74  }
75  if ( peek == 'T' ) {
76  parse_tool(buf);
77  }
78  if ( peek == 'A' ) {
80  }
81  }
82  if ( event_context && ( peek == 'V' || peek == 'P' ) ) event_context=false;
83  if (nn < 0) return true;
84  m_isstream ? m_stream->getline(buf, max_buffer_size) : m_file.getline(buf, max_buffer_size);
85  }
86  return true;
87 }
88 
89 
91  if ( (!m_file.is_open()) && (!m_isstream) ) return false;
92 
93  char peek;
94  const size_t max_buffer_size = 512*512;
95  char buf[max_buffer_size];
96  bool event_context = false;
97  bool parsed_weights = false;
98  bool parsed_particles_or_vertices = false;
99  bool run_info_context = false;
100  bool is_parsing_successful = true;
101  std::pair<int, int> vertices_and_particles(0, 0);
102 
103  evt.clear();
104  evt.set_run_info(run_info());
105  m_forward_daughters.clear();
106  m_forward_mothers.clear();
107  //
108  // Parse event, vertex and particle information
109  //
110  while (!failed()) {
111  m_isstream ? m_stream->getline(buf, max_buffer_size) : m_file.getline(buf, max_buffer_size);
112 
113  if ( strlen(buf) == 0 ) continue;
114 
115  // Check for ReaderAscii header/footer
116  if ( strncmp(buf, "HepMC", 5) == 0 ) {
117  if ( strncmp(buf, "HepMC::Version", 14) != 0 && strncmp(buf, "HepMC::Asciiv3", 14) != 0 )
118  {
119  HEPMC3_WARNING("ReaderAscii: found unsupported expression in header. Will close the input.")
120  std::cout << buf << std::endl;
121  m_isstream ? m_stream->clear(std::ios::eofbit) : m_file.clear(std::ios::eofbit);
122  }
123  if (event_context) {
124  is_parsing_successful = true;
125  break;
126  }
127  continue;
128  }
129 
130  switch (buf[0]) {
131  case 'E':
132  vertices_and_particles = parse_event_information(evt, buf);
133  if (vertices_and_particles.second < 0) {
134  is_parsing_successful = false;
135  } else {
136  is_parsing_successful = true;
137  event_context = true;
138  parsed_weights = false;
139  parsed_particles_or_vertices = false;
140  }
141  run_info_context = false;
142  break;
143  case 'V':
144  is_parsing_successful = parse_vertex_information(evt, buf);
145  parsed_particles_or_vertices = true;
146  break;
147  case 'P':
148  is_parsing_successful = parse_particle_information(evt, buf);
149  parsed_particles_or_vertices = true;
150  break;
151  case 'W':
152  if ( event_context ) {
153  is_parsing_successful = parse_weight_values(evt, buf);
154  parsed_weights=true;
155  } else {
156  if ( !run_info_context ) {
157  set_run_info(std::make_shared<GenRunInfo>());
158  evt.set_run_info(run_info());
159  }
160  run_info_context = true;
161  is_parsing_successful = parse_weight_names(buf);
162  }
163  break;
164  case 'U':
165  is_parsing_successful = parse_units(evt, buf);
166  break;
167  case 'T':
168  if ( event_context ) {
169  //We ignore T in the event context
170  } else {
171  if ( !run_info_context ) {
172  set_run_info(std::make_shared<GenRunInfo>());
173  evt.set_run_info(run_info());
174  }
175  run_info_context = true;
176  is_parsing_successful = parse_tool(buf);
177  }
178  break;
179  case 'A':
180  if ( event_context ) {
181  is_parsing_successful = parse_attribute(evt, buf);
182  } else {
183  if ( !run_info_context ) {
184  set_run_info(std::make_shared<GenRunInfo>());
185  evt.set_run_info(run_info());
186  }
187  run_info_context = true;
188  is_parsing_successful = parse_run_attribute(buf);
189  }
190  break;
191  default:
192  HEPMC3_WARNING("ReaderAscii: skipping unrecognised prefix: " << buf[0])
193  is_parsing_successful = true;
194  break;
195  }
196 
197  if ( !is_parsing_successful ) break;
198 
199  // Check for next event or run info
200  m_isstream ? peek = m_stream->peek() : peek = m_file.peek();
201  //End of event. The next entry is event.
202  if ( event_context && peek == 'E' ) break;
203 
204  //End of event. The next entry is run info which starts from weight name.
205  if ( event_context && peek == 'W' && parsed_weights ) break;
206 
207  //End of event. The next entry is run info which starts from attribute.
208  if ( event_context && peek == 'A' && parsed_particles_or_vertices ) break;
209 
210  //End of event. The next entry is run info which starts from tool.
211  if ( event_context && peek == 'T' ) break;
212 
213 
214  }
215 
216 
217  // Check if all particles and vertices were parsed
218  if ((int)evt.particles().size() > vertices_and_particles.second) {
219  HEPMC3_ERROR("ReaderAscii: too many particles were parsed")
220  printf("%zu vs %i expected\n", evt.particles().size(), vertices_and_particles.second);
221  is_parsing_successful = false;
222  }
223  if ((int)evt.particles().size() < vertices_and_particles.second) {
224  HEPMC3_ERROR("ReaderAscii: too few particles were parsed")
225  printf("%zu vs %i expected\n", evt.particles().size(), vertices_and_particles.second);
226  is_parsing_successful = false;
227  }
228 
229  if ((int)evt.vertices().size() > vertices_and_particles.first) {
230  HEPMC3_ERROR("ReaderAscii: too many vertices were parsed")
231  printf("%zu vs %i expected\n", evt.vertices().size(), vertices_and_particles.first);
232  is_parsing_successful = false;
233  }
234 
235  if ((int)evt.vertices().size() < vertices_and_particles.first) {
236  HEPMC3_ERROR("ReaderAscii: too few vertices were parsed")
237  printf("%zu vs %i expected\n", evt.vertices().size(), vertices_and_particles.first);
238  is_parsing_successful = false;
239  }
240  // Check if there were HEPMC3_ERRORs during parsing
241  if ( !is_parsing_successful ) {
242  HEPMC3_ERROR("ReaderAscii: event parsing failed. Returning empty event")
243  HEPMC3_DEBUG(1, "Parsing failed at line:" << std::endl << buf)
244 
245  evt.clear();
246  m_isstream ? m_stream->clear(std::ios::badbit) : m_file.clear(std::ios::badbit);
247 
248  return false;
249  }
250  for ( auto p : m_forward_daughters )
251  for (auto v: evt.vertices())
252  if (p.second == v->id())
253  v->add_particle_out(p.first);
254  for ( auto v : m_forward_mothers ) for ( auto idpm : v.second ) v.first->add_particle_in(evt.particles()[idpm-1]);
255 
256  /* restore ids of vertices using a bank of available ids*/
257  std::vector<int> all_ids;
258  std::vector<int> filled_ids;
259  std::vector<int> diff;
260  for (auto v: evt.vertices()) if (v->id() != 0) filled_ids.push_back(v->id());
261  for (int i = -((long)evt.vertices().size()); i < 0; i++) all_ids.push_back(i);
262  std::sort(all_ids.begin(), all_ids.end());
263  std::sort(filled_ids.begin(), filled_ids.end());
264  //The bank of available ids is created as a difference between all range of ids and the set of used ids
265  std::set_difference(all_ids.begin(), all_ids.end(), filled_ids.begin(), filled_ids.end(), std::inserter(diff, diff.begin()));
266  auto it = diff.rbegin();
267  //Set available ids to vertices sequentially.
268  for (auto v: evt.vertices()) if (v->id() == 0) { v->set_id(*it); it++;}
269 
270  return true;
271 }
272 
273 
274 std::pair<int, int> ReaderAscii::parse_event_information(GenEvent &evt, const char *buf) {
275  static const std::pair<int, int> err(-1, -1);
276  std::pair<int, int> ret(-1, -1);
277  const char *cursor = buf;
278  int event_no = 0;
279  FourVector position;
280 
281  // event number
282  if ( !(cursor = strchr(cursor+1, ' ')) ) return err;
283  event_no = atoi(cursor);
284  evt.set_event_number(event_no);
285 
286  // num_vertices
287  if ( !(cursor = strchr(cursor+1, ' ')) ) return err;
288  ret.first = atoi(cursor);
289 
290  // num_particles
291  if ( !(cursor = strchr(cursor+1, ' ')) ) return err;
292  ret.second = atoi(cursor);
293 
294  // check if there is position information
295  if ( (cursor = strchr(cursor+1, '@')) ) {
296  // x
297  if ( !(cursor = strchr(cursor+1, ' ')) ) return err;
298  position.setX(atof(cursor));
299 
300  // y
301  if ( !(cursor = strchr(cursor+1, ' ')) ) return err;
302  position.setY(atof(cursor));
303 
304  // z
305  if ( !(cursor = strchr(cursor+1, ' ')) ) return err;
306  position.setZ(atof(cursor));
307 
308  // t
309  if ( !(cursor = strchr(cursor+1, ' ')) ) return err;
310  position.setT(atof(cursor));
311  evt.shift_position_to(position);
312  }
313 
314  HEPMC3_DEBUG(10, "ReaderAscii: E: " << event_no << " (" <<ret.first << "V, " << ret.second << "P)")
315 
316  return ret;
317 }
318 
319 
320 bool ReaderAscii::parse_weight_values(GenEvent &evt, const char *buf) {
321  std::istringstream iss(buf + 1);
322  std::vector<double> wts;
323  double w;
324  while (iss >> w) wts.push_back(w);
325  if ( run_info() && run_info()->weight_names().size()
326  && run_info()->weight_names().size() != wts.size() )
327  throw std::logic_error("ReaderAscii::parse_weight_values: "
328  "The number of weights ("+std::to_string((long long int)(wts.size()))+") does not match "
329  "the number weight names("+std::to_string((long long int)(run_info()->weight_names().size()))+") in the GenRunInfo object");
330  evt.weights() = wts;
331 
332  return true;
333 }
334 
335 
336 bool ReaderAscii::parse_units(GenEvent &evt, const char *buf) {
337  const char *cursor = buf;
338 
339  // momentum
340  if ( !(cursor = strchr(cursor+1, ' ')) ) return false;
341  ++cursor;
342  Units::MomentumUnit momentum_unit = Units::momentum_unit(cursor);
343 
344  // length
345  if ( !(cursor = strchr(cursor+1, ' ')) ) return false;
346  ++cursor;
347  Units::LengthUnit length_unit = Units::length_unit(cursor);
348 
349  evt.set_units(momentum_unit, length_unit);
350 
351  HEPMC3_DEBUG(10, "ReaderAscii: U: " << Units::name(evt.momentum_unit()) << " " << Units::name(evt.length_unit()))
352 
353  return true;
354 }
355 
356 
357 bool ReaderAscii::parse_vertex_information(GenEvent &evt, const char *buf) {
358  GenVertexPtr data = std::make_shared<GenVertex>();
359  FourVector position;
360  const char *cursor = buf;
361  const char *cursor2 = nullptr;
362  int id = 0;
363  int highest_id = evt.particles().size();
364 
365  // id
366  if ( !(cursor = strchr(cursor+1, ' ')) ) return false;
367  id = atoi(cursor);
368 
369  // status
370  if ( !(cursor = strchr(cursor+1, ' ')) ) return false;
371  data->set_status(atoi(cursor));
372 
373  // skip to the list of particles
374  if ( !(cursor = strchr(cursor+1, '[')) ) return false;
375 
376  while (true) {
377  ++cursor; // skip the '[' or ',' character
378  cursor2 = cursor; // save cursor position
379  int particle_in = atoi(cursor);
380 
381  // add incoming particle to the vertex
382  if (particle_in > 0) {
383  //Particles are always ordered, so id==position in event.
384  if (particle_in <= highest_id) {
385  data->add_particle_in(evt.particles()[particle_in-1]);
386  } else {
387  //If the particle has not been red yet, we store its id to add the particle later.
388  m_forward_mothers[data].insert(particle_in);
389  }
390  }
391 
392  // check for next particle or end of particle list
393  if ( !(cursor = strchr(cursor+1, ',')) ) {
394  if ( !(cursor = strchr(cursor2+1, ']')) ) return false;
395  break;
396  }
397  }
398 
399  // check if there is position information
400  if ( (cursor = strchr(cursor+1, '@')) ) {
401  // x
402  if ( !(cursor = strchr(cursor+1, ' ')) ) return false;
403  position.setX(atof(cursor));
404 
405  // y
406  if ( !(cursor = strchr(cursor+1, ' ')) ) return false;
407  position.setY(atof(cursor));
408 
409  // z
410  if ( !(cursor = strchr(cursor+1, ' ')) ) return false;
411  position.setZ(atof(cursor));
412 
413  // t
414  if ( !(cursor = strchr(cursor+1, ' ')) ) return false;
415  position.setT(atof(cursor));
416  data->set_position(position);
417  }
418 
419  HEPMC3_DEBUG(10, "ReaderAscii: V: " << id << " with "<< data->particles_in().size() << " particles)")
420 
421  evt.add_vertex(data);
422  //Restore vertex id, as it is used to build connections inside event.
423  data->set_id(id);
424 
425  return true;
426 }
427 
428 
430  GenParticlePtr data = std::make_shared<GenParticle>();
431  FourVector momentum;
432  const char *cursor = buf;
433  int mother_id = 0;
434 
435  // verify id
436  if ( !(cursor = strchr(cursor+1, ' ')) ) return false;
437 
438  if ( atoi(cursor) != (int)evt.particles().size() + 1 ) {
439  /// @todo Should be an exception
440  HEPMC3_ERROR("ReaderAscii: particle ID mismatch")
441  return false;
442  }
443 
444  // mother id
445  if ( !(cursor = strchr(cursor+1, ' ')) ) return false;
446  mother_id = atoi(cursor);
447 
448  // Parent object is a particle. Particleas are always ordered id==position in event.
449  if ( mother_id > 0 && mother_id <= (int)evt.particles().size() ) {
450  GenParticlePtr mother = evt.particles()[ mother_id-1 ];
451  GenVertexPtr vertex = mother->end_vertex();
452 
453  // create new vertex if needed
454  if ( !vertex ) {
455  vertex = std::make_shared<GenVertex>();
456  vertex->add_particle_in(mother);
457  }
458 
459  vertex->add_particle_out(data);
460  evt.add_vertex(vertex);
461  //ID of this vertex is not explicitely set in the input. We set it to zero to prevent overlap with other ids. It will be restored later.
462  vertex->set_id(0);
463  }
464  // Parent object is vertex
465  else if ( mother_id < 0 )
466  {
467  //Vertices are not always ordered, e.g. when one reads HepMC2 event, so we check their ids.
468  bool found = false;
469  for (auto v: evt.vertices()) if (v->id() == mother_id) {v->add_particle_out(data); found = true; break; }
470  if (!found)
471  {
472  //This should happen in case of unordered event.
473  // WARNING("ReaderAscii: Unordered event, id of mother vertex is out of range of known ids: " <<mother_id<<" evt.vertices().size()="<<evt.vertices().size() )
474  //Save the mother id to reconnect later.
475  m_forward_daughters[data] = mother_id;
476  }
477  }
478 
479  // pdg id
480  if ( !(cursor = strchr(cursor+1, ' ')) ) return false;
481  data->set_pid(atoi(cursor));
482 
483  // px
484  if ( !(cursor = strchr(cursor+1, ' ')) ) return false;
485  momentum.setPx(atof(cursor));
486 
487  // py
488  if ( !(cursor = strchr(cursor+1, ' ')) ) return false;
489  momentum.setPy(atof(cursor));
490 
491  // pz
492  if ( !(cursor = strchr(cursor+1, ' ')) ) return false;
493  momentum.setPz(atof(cursor));
494 
495  // pe
496  if ( !(cursor = strchr(cursor+1, ' ')) ) return false;
497  momentum.setE(atof(cursor));
498  data->set_momentum(momentum);
499 
500  // m
501  if ( !(cursor = strchr(cursor+1, ' ')) ) return false;
502  data->set_generated_mass(atof(cursor));
503 
504  // status
505  if ( !(cursor = strchr(cursor+1, ' ')) ) return false;
506  data->set_status(atoi(cursor));
507 
508  evt.add_particle(data);
509 
510  HEPMC3_DEBUG(10, "ReaderAscii: P: " << data->id() << " ( mother: " << mother_id << ", pid: " << data->pid() << ")")
511 
512  return true;
513 }
514 
515 
516 bool ReaderAscii::parse_attribute(GenEvent &evt, const char *buf) {
517  const char *cursor = buf;
518  const char *cursor2 = buf;
519  char name[512];
520  int id = 0;
521 
522  if ( !(cursor = strchr(cursor+1, ' ')) ) return false;
523  id = atoi(cursor);
524 
525  if ( !(cursor = strchr(cursor+1, ' ')) ) return false;
526  ++cursor;
527 
528  if ( !(cursor2 = strchr(cursor, ' ')) ) return false;
529  snprintf(name, 512, "%.*s", (int)(cursor2-cursor), cursor);
530 
531  cursor = cursor2+1;
532 
533  std::shared_ptr<Attribute> att =
534  std::make_shared<StringAttribute>(StringAttribute(unescape(cursor)));
535 
536  evt.add_attribute(std::string(name), att, id);
537 
538  return true;
539 }
540 
541 bool ReaderAscii::parse_run_attribute(const char *buf) {
542  const char *cursor = buf;
543  const char *cursor2 = buf;
544  char name[512];
545 
546  if ( !(cursor = strchr(cursor+1, ' ')) ) return false;
547  ++cursor;
548 
549  if ( !(cursor2 = strchr(cursor, ' ')) ) return false;
550  snprintf(name, 512, "%.*s", (int)(cursor2-cursor), cursor);
551 
552  cursor = cursor2+1;
553 
554  std::shared_ptr<StringAttribute> att =
555  std::make_shared<StringAttribute>(StringAttribute(unescape(cursor)));
556 
557  run_info()->add_attribute(std::string(name), att);
558 
559  return true;
560 }
561 
562 
563 bool ReaderAscii::parse_weight_names(const char *buf) {
564  const char *cursor = buf;
565 
566  if ( !(cursor = strchr(cursor+1, ' ')) ) return false;
567  ++cursor;
568 
569  std::istringstream iss(unescape(cursor));
570  std::vector<std::string> names;
571  std::string name;
572  while (iss >> name) names.push_back(name);
573 
574  run_info()->set_weight_names(names);
575 
576  return true;
577 }
578 
579 bool ReaderAscii::parse_tool(const char *buf) {
580  const char *cursor = buf;
581 
582  if ( !(cursor = strchr(cursor+1, ' ')) ) return false;
583  ++cursor;
584  std::string line = unescape(cursor);
586  std::string::size_type pos = line.find("\n");
587  tool.name = line.substr(0, pos);
588  line = line.substr(pos + 1);
589  pos = line.find("\n");
590  tool.version = line.substr(0, pos);
591  tool.description = line.substr(pos + 1);
592  run_info()->tools().push_back(tool);
593 
594  return true;
595 }
596 
597 
598 std::string ReaderAscii::unescape(const std::string& s) {
599  std::string ret;
600  ret.reserve(s.length());
601  for ( std::string::const_iterator it = s.begin(); it != s.end(); ++it ) {
602  if ( *it == '\\' ) {
603  ++it;
604  if ( *it == '|' )
605  ret += '\n';
606  else
607  ret += *it;
608  } else
609  ret += *it;
610  }
611 
612  return ret;
613 }
614 
615 bool ReaderAscii::failed() { return m_isstream ? (bool)m_stream->rdstate() :(bool)m_file.rdstate(); }
616 
618  if ( !m_file.is_open()) return;
619  m_file.close();
620 }
621 
622 
623 } // namespace HepMC3
std::string version
The version of the tool.
Definition: GenRunInfo.h:44
bool parse_run_attribute(const char *buf)
Parse run-level attribute.
Definition: ReaderAscii.cc:541
const Units::MomentumUnit & momentum_unit() const
Get momentum unit.
Definition: GenEvent.h:153
HepMC3 main namespace.
const Units::LengthUnit & length_unit() const
Get length unit.
Definition: GenEvent.h:155
ReaderAscii(const std::string &filename)
Constructor.
Definition: ReaderAscii.cc:23
bool parse_units(GenEvent &evt, const char *buf)
Parse units.
Definition: ReaderAscii.cc:336
#define HEPMC3_WARNING(MESSAGE)
Macro for printing HEPMC3_HEPMC3_WARNING messages.
Definition: Errors.h:27
void add_vertex(GenVertexPtr v)
Add vertex.
Definition: GenEvent.cc:96
static LengthUnit length_unit(const std::string &name)
Get length unit based on its name.
Definition: Units.h:46
bool parse_tool(const char *buf)
Parse run-level tool information.
Definition: ReaderAscii.cc:579
bool read_event(GenEvent &evt) override
Load event from file.
Definition: ReaderAscii.cc:90
Definition of class GenParticle.
const std::vector< ConstGenVertexPtr > & vertices() const
Get list of vertices (const)
Definition: GenEvent.cc:43
std::ifstream m_file
Input file.
Definition: ReaderAscii.h:158
std::map< GenVertexPtr, std::set< int > > m_forward_mothers
Temp storage for outgoing particle ids.
Definition: ReaderAscii.h:168
Definition of class GenVertex.
std::string description
Other information about how the tool was used in the run.
Definition: GenRunInfo.h:48
#define HEPMC3_DEBUG(LEVEL, MESSAGE)
Macro for printing debug messages with appropriate debug level.
Definition: Errors.h:33
Attribute that holds a string.
Definition: Attribute.h:335
void add_particle(GenParticlePtr p)
Add particle.
Definition: GenEvent.cc:48
static std::string name(MomentumUnit u)
Get name of momentum unit.
Definition: Units.h:56
void add_attribute(const std::string &name, const std::shared_ptr< Attribute > &att, const int &id=0)
Definition: GenEvent.cc:806
std::pair< int, int > parse_event_information(GenEvent &evt, const char *buf)
Parse event.
Definition: ReaderAscii.cc:274
bool parse_weight_names(const char *buf)
Parse run-level weight names.
Definition: ReaderAscii.cc:563
bool parse_attribute(GenEvent &evt, const char *buf)
Parse attribute.
Definition: ReaderAscii.cc:516
const std::vector< double > & weights() const
Get event weight values as a vector.
Definition: GenEvent.h:98
LengthUnit
Position units.
Definition: Units.h:32
void setY(double yy)
Definition: FourVector.h:92
MomentumUnit
Momentum units.
Definition: Units.h:29
void setZ(double zz)
Definition: FourVector.h:99
Stores event-related information.
Definition: GenEvent.h:41
std::istream * m_stream
For ctor when reading from stream.
Definition: ReaderAscii.h:160
Generic 4-vector.
Definition: FourVector.h:36
bool failed() override
Return status of the stream.
Definition: ReaderAscii.cc:615
std::string unescape(const std::string &s)
Unsecape &#39;\&#39; and &#39; &#39; characters in string.
Definition: ReaderAscii.cc:598
void setT(double tt)
Definition: FourVector.h:106
Interrnal struct for keeping track of tools.
Definition: GenRunInfo.h:38
Definition of class ReaderAscii.
const std::vector< ConstGenParticlePtr > & particles() const
Get list of particles (const)
Definition: GenEvent.cc:39
Definition of class Units.
bool skip(const int) override
skip events
Definition: ReaderAscii.cc:53
std::shared_ptr< GenRunInfo > run_info() const
Get the global GenRunInfo object.
Definition: Reader.h:44
static MomentumUnit momentum_unit(const std::string &name)
Get momentum unit based on its name.
Definition: Units.h:36
std::map< GenParticlePtr, int > m_forward_daughters
Temp storage for prod vertex ids.
Definition: ReaderAscii.h:170
void set_run_info(std::shared_ptr< GenRunInfo > run)
Set the GenRunInfo object by smart pointer.
Definition: GenEvent.h:141
bool m_isstream
toggles usage of m_file or m_stream
Definition: ReaderAscii.h:161
void set_units(Units::MomentumUnit new_momentum_unit, Units::LengthUnit new_length_unit)
Change event units Converts event from current units to new ones.
Definition: GenEvent.cc:391
bool parse_vertex_information(GenEvent &evt, const char *buf)
Parse vertex.
Definition: ReaderAscii.cc:357
void set_run_info(std::shared_ptr< GenRunInfo > run)
Set the global GenRunInfo object.
Definition: Reader.h:64
#define HEPMC3_ERROR(MESSAGE)
Macro for printing error messages.
Definition: Errors.h:24
std::string name
The name of the tool.
Definition: GenRunInfo.h:41
Definition of class GenEvent.
bool parse_particle_information(GenEvent &evt, const char *buf)
Parse particle.
Definition: ReaderAscii.cc:429
void setX(double xx)
Definition: FourVector.h:85
~ReaderAscii()
Destructor.
Definition: ReaderAscii.cc:51
void close() override
Close file stream.
Definition: ReaderAscii.cc:617
void clear()
Remove contents of this event.
Definition: GenEvent.cc:599
bool parse_weight_values(GenEvent &evt, const char *buf)
Parse weight value lines.
Definition: ReaderAscii.cc:320
void set_event_number(const int &num)
Set event number.
Definition: GenEvent.h:150
void shift_position_to(const FourVector &newpos)
Shift position of all vertices in the event to op.
Definition: GenEvent.h:200