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