17#include "HepMC3/Version.h" 
   33    HEPMC3_WARNING(
"WriterAsciiHepMC2::WriterAsciiHepMC2: HepMC2 IO_GenEvent format is outdated. Please use HepMC3 Asciiv3 format instead.")
 
   38        HEPMC3_ERROR(
"WriterAsciiHepMC2: could not open output file: " << filename )
 
   42        const std::string header = 
"HepMC::Version " + 
version() + 
"\nHepMC::IO_GenEvent-START_EVENT_LISTING\n";
 
   43        m_file.write(header.data(), header.length());
 
 
   56    HEPMC3_WARNING(
"WriterAsciiHepMC2::WriterAsciiHepMC2: HepMC2 IO_GenEvent format is outdated. Please use HepMC3 Asciiv3 format instead.")
 
   59    const std::string header = 
"HepMC::Version " + 
version() + 
"\nHepMC::IO_GenEvent-START_EVENT_LISTING\n";
 
   60    m_stream->write(header.data(), header.length());
 
 
   73    HEPMC3_WARNING(
"WriterAsciiHepMC2::WriterAsciiHepMC2: HepMC2 IO_GenEvent format is outdated. Please use HepMC3 Asciiv3 format instead.")
 
   76    const std::string header = 
"HepMC::Version " + 
version() + 
"\nHepMC::IO_GenEvent-START_EVENT_LISTING\n";
 
   77    m_stream->write(header.data(), header.length());
 
 
   93    auto float_printf_specifier_option = 
m_options.find(
"float_printf_specifier");
 
   94    std::string  letter=(float_printf_specifier_option != 
m_options.end())?float_printf_specifier_option->second.substr(0,2):
"e";
 
   95    if (letter != 
"e" && letter != 
"E" && letter != 
"G" && letter != 
"g" && letter != 
"f" && letter != 
"F" ) letter = 
"e";
 
  107    std::shared_ptr<IntAttribute> A_signal_process_id = evt.
attribute<
IntAttribute>(
"signal_process_id");
 
  109    std::shared_ptr<IntAttribute> A_signal_process_vertex = evt.
attribute<
IntAttribute>(
"signal_process_vertex");
 
  111    double event_scale = A_event_scale?(A_event_scale->value()):0.0;
 
  112    double alphaQED = A_alphaQED?(A_alphaQED->value()):0.0;
 
  113    double alphaQCD = A_alphaQCD?(A_alphaQCD->value()):0.0;
 
  114    int signal_process_id = A_signal_process_id?(A_signal_process_id->value()):0;
 
  115    int mpi = A_mpi?(A_mpi->value()):0;
 
  116    int signal_process_vertex = A_signal_process_vertex?(A_signal_process_vertex->value()):0;
 
  118    std::vector<long> m_random_states;
 
  120    if (random_states_a) {
 
  121        m_random_states = random_states_a->value();
 
  123        m_random_states.reserve(100);
 
  124        for (
int i = 0; i < 100; i++)
 
  126            std::shared_ptr<LongAttribute> rs = evt.
attribute<
LongAttribute>(
"random_states"+std::to_string((
long long unsigned int)i));
 
  128            m_random_states.emplace_back(rs->value());
 
  133    std::vector<int> beams;
 
  136    for (
const ConstGenVertexPtr& v: evt.
vertices())
 
  138        for (
const ConstGenParticlePtr& p: v->particles_in())
 
  140            if (!p->production_vertex())                { 
if (p->status() == 4) beams.emplace_back(idbeam); idbeam++; }
 
  141            else {
if (p->production_vertex()->id() == 0) { 
if (p->status() == 4) beams.emplace_back(idbeam); idbeam++; }}
 
  143        for (
const ConstGenParticlePtr& p: v->particles_out()) { 
if (p->status() == 4) beams.push_back(idbeam); idbeam++; }
 
  148    if (!beams.empty()) idbeam1 += beams[0] + 1;
 
  149    if (beams.size() > 1) idbeam2 += beams[1] + 1;
 
  157                        signal_process_vertex,
 
  164    for (
size_t q = 0; q < m_random_states.size(); q++)
 
  173        for (
const double& w: evt.
weights()) {
 
  180        const std::vector<std::string> names = 
run_info()->weight_names();
 
  181        for (
size_t q = 0; q < evt.
weights().size(); q++)
 
  183            if (q < names.size()) {
 
  209                            hi->spectator_neutrons,
 
  210                            hi->spectator_protons,
 
  211                            hi->N_Nwounded_collisions,
 
  212                            hi->Nwounded_N_collisions,
 
  213                            hi->Nwounded_Nwounded_collisions,
 
  214                            hi->impact_parameter,
 
  215                            hi->event_plane_angle,
 
  225        bool status = pi->to_string(st);
 
  228            HEPMC3_WARNING(
"WriterAsciiHepMC2::write_event: problem serializing GenPdfInfo attribute")
 
  240    for (
const ConstGenVertexPtr& v: evt.
vertices() )
 
  242        int production_vertex = 0;
 
  243        production_vertex = v->id();
 
  245        for (
const ConstGenParticlePtr& p: v->particles_in())
 
  247            if (!p->production_vertex()) { 
write_particle( p, production_vertex ); }
 
  250                if (p->production_vertex()->id() == 0) 
write_particle( p, production_vertex );
 
  253        for (
const ConstGenParticlePtr& p: v->particles_out()) {
 
 
  269        } 
catch (
const std::bad_alloc& e) {
 
  272            HEPMC3_WARNING(
"WriterAsciiHepMC2::allocate_buffer:" << e.what() << 
" buffer size too large. Dividing by 2. New size: " << 
m_buffer_size)
 
  278        HEPMC3_ERROR(
"WriterAsciiHepMC2::allocate_buffer: could not allocate buffer!")
 
 
  289    ret.reserve(s.length()*2);
 
  290    for ( std::string::const_iterator it = s.begin(); it != s.end(); ++it )
 
 
  309    std::vector<double> weights;
 
  312        weights = weights_a->value();
 
  314        weights.reserve(100);
 
  315        for (
int i = 0; i < 100; i++)
 
  317            std::shared_ptr<DoubleAttribute> rs = v->attribute<
DoubleAttribute>(
"weight"+std::to_string((
long long unsigned int)i));
 
  319            weights.emplace_back(rs->value());
 
  325    for (
const ConstGenParticlePtr& p: v->particles_in())
 
  327        if (!p->production_vertex()) { orph++;}
 
  330            if (p->production_vertex()->id() == 0) orph++;
 
  345    m_cursor += sprintf(
m_cursor, 
" %i %zu %zu", orph, v->particles_out().size(), weights.size());
 
 
  390    if (p->end_vertex()) {
 
  391        if (p->end_vertex()->id() != 0)
 
  392        { ev = p->end_vertex()->id(); }
 
  394    std::shared_ptr<DoubleAttribute> A_theta = p->attribute<
DoubleAttribute>(
"theta");
 
  395    std:: shared_ptr<DoubleAttribute> A_phi = p->attribute<
DoubleAttribute>(
"phi");
 
  402    std::shared_ptr<VectorIntAttribute> A_flows = p->attribute<
VectorIntAttribute>(
"flows");
 
  405        std::vector<int> flowsv = A_flows->value();
 
  406        std::string flowss = 
" " + std::to_string(flowsv.size());
 
  407        for (
size_t k = 0; k < flowsv.size(); k++) { flowss += ( 
" " + std::to_string(k+1) + 
" " + std::to_string(flowsv.at(k))); }
 
  411        std::shared_ptr<IntAttribute> A_flow1 = p->attribute<
IntAttribute>(
"flow1");
 
  412        std::shared_ptr<IntAttribute> A_flow2 = p->attribute<
IntAttribute>(
"flow2");
 
  413        std::shared_ptr<IntAttribute> A_flow3 = p->attribute<
IntAttribute>(
"flow3");
 
  415        if (A_flow1) flowsize++;
 
  416        if (A_flow2) flowsize++;
 
  417        if (A_flow3) flowsize++;
 
  418        std::string flowss = 
" " + std::to_string(flowsize);
 
  419        if (A_flow1) flowss += ( 
" 1 " + std::to_string(A_flow1->value()));
 
  420        if (A_flow2) flowss += ( 
" 2 " + std::to_string(A_flow2->value()));
 
  421        if (A_flow3) flowss += ( 
" 3 " + std::to_string(A_flow3->value()));
 
 
  434        strncpy(
m_cursor, str.data(), str.length());
 
  442        m_stream->write(str.data(), str.length());
 
 
  449    auto* ofs = 
dynamic_cast<std::ofstream*
>(
m_stream);
 
  450    if (ofs && !ofs->is_open()) 
return;
 
  452    const std::string footer(
"HepMC::IO_GenEvent-END_EVENT_LISTING\n\n");
 
  454    if (ofs) ofs->close();
 
 
  459    if (prec < 2 || prec > 24) 
return;
 
 
  469    if (size < 1024) 
return;
 
 
#define HEPMC3_WARNING(MESSAGE)
Macro for printing HEPMC3_HEPMC3_WARNING messages.
#define HEPMC3_ERROR(MESSAGE)
Macro for printing error messages.
Definition of class GenEvent.
Definition of class GenParticle.
Definition of class GenVertex.
Definition of class Units.
Definition of class WriterAsciiHepMC2.
Attribute that holds a real number as a double.
double t() const
Time component of position/displacement.
bool is_zero() const
Check if the length of this vertex is zero.
double x() const
x-component of position/displacement
double y() const
y-component of position/displacement
double z() const
z-component of position/displacement
Stores additional information about cross-section.
Stores event-related information.
std::shared_ptr< T > attribute(const std::string &name, const int &id=0) const
Get attribute of type T.
int event_number() const
Get event number.
std::shared_ptr< GenRunInfo > run_info() const
Get a pointer to the the GenRunInfo object.
const std::vector< ConstGenVertexPtr > & vertices() const
Get list of vertices (const)
const Units::MomentumUnit & momentum_unit() const
Get momentum unit.
const Units::LengthUnit & length_unit() const
Get length unit.
const std::vector< double > & weights() const
Get event weight values as a vector.
Stores additional information about Heavy Ion generator.
Stores additional information about PDFs.
Attribute that holds an Integer implemented as an int.
Attribute that holds an Integer implemented as a long int.
static std::string name(MomentumUnit u)
Get name of momentum unit.
Attribute that holds a vector of real numbers of type double.
Attribute that holds a vector of integers of type int.
Attribute that holds a vector of integers of type long int.
void set_buffer_size(const size_t &size)
Set buffer size (in bytes)
void set_precision(const int &prec)
Set output precision.
std::string escape(const std::string &s) const
Escape '\' and ' ' characters in string.
void allocate_buffer()
Attempts to allocate buffer of the chosen size.
char * m_cursor
Cursor inside stream buffer.
bool failed() override
Return status of the stream.
char * m_buffer
Stream buffer.
std::string m_float_printf_specifier
the specifier of printf used for floats
void close() override
Close file stream.
int precision() const
Return output precision.
int m_precision
Output precision.
WriterAsciiHepMC2(const std::string &filename, std::shared_ptr< GenRunInfo > run=std::shared_ptr< GenRunInfo >())
Constructor.
void write_particle(const ConstGenParticlePtr &p, int second_field)
Write particle.
void write_vertex(const ConstGenVertexPtr &v)
Write vertex.
std::shared_ptr< std::ostream > m_shared_stream
Output temp. stream.
std::ofstream m_file
Output file.
~WriterAsciiHepMC2()
Destructor.
unsigned long m_particle_counter
Used to set bar codes.
void write_string(const std::string &str)
Inline function for writing strings.
unsigned long m_buffer_size
Buffer size.
void write_event(const GenEvent &evt) override
Write event to file.
void flush()
Inline function flushing buffer to output stream when close to buffer capacity.
void write_run_info()
Write the GenRunInfo object to file.
void forced_flush()
Inline function forcing flush to the output stream.
std::ostream * m_stream
Output stream.
virtual void set_run_info(std::shared_ptr< GenRunInfo > run)
Set the global GenRunInfo object.
virtual std::shared_ptr< GenRunInfo > run_info() const
Get the global GenRunInfo object.
std::map< std::string, std::string > m_options
options
std::string version()
Get the HepMC library version string.