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