MARLEY (Model of Argon Reaction Low Energy Yields) v2.0.0
A Monte Carlo event generator for tens-of-MeV neutrino interactions
Loading...
Searching...
No Matches
WriterAscii.h
1// -*- C++ -*-
2//
3// This file is part of HepMC
4// Copyright (C) 2014-2023 The HepMC collaboration (see AUTHORS for details)
5//
6#ifndef HEPMC3_WRITERASCII_H
7#define HEPMC3_WRITERASCII_H
17#include "HepMC3/Writer.h"
18#include "HepMC3/GenEvent.h"
19#include "HepMC3/GenRunInfo.h"
20#include <string>
21#include <fstream>
22
23namespace HepMC3 {
24
25class WriterAscii : public Writer {
26public:
27
30 WriterAscii(const std::string& filename,
31 std::shared_ptr<GenRunInfo> run = std::shared_ptr<GenRunInfo>());
32
34 WriterAscii(std::ostream& stream,
35 std::shared_ptr<GenRunInfo> run = std::shared_ptr<GenRunInfo>());
37 WriterAscii(std::shared_ptr<std::ostream> s_stream,
38 std::shared_ptr<GenRunInfo> run = std::shared_ptr<GenRunInfo>());
39
42
46 void write_event(const GenEvent& evt) override;
47
49 void write_run_info();
50
52 bool failed() override;
53
55 void close() override;
56
60 void set_precision(const int& prec );
62 int precision() const;
63private:
64
67
75 void allocate_buffer();
76
81 void set_buffer_size(const size_t& size );
82
84 static std::string escape(const std::string& s);
85
87 void flush();
88
90 void forced_flush();
91
93
94
97
102 void write_string( const std::string &str );
103
107 void write_vertex(const ConstGenVertexPtr& v);
108
112 void write_particle(const ConstGenParticlePtr& p, int second_field);
113
115
116private:
117
118 std::ofstream m_file;
119 std::shared_ptr<std::ostream> m_shared_stream = nullptr;
120 std::ostream* m_stream = nullptr;
121
122 int m_precision = 16;
123 char* m_buffer = nullptr;
124 char* m_cursor = nullptr;
125 unsigned long m_buffer_size = 262144;
126 std::string m_float_printf_specifier;
127 std::string m_particle_printf_specifier;
128 std::string m_vertex_short_printf_specifier;
129 std::string m_vertex_long_printf_specifier;
130};
131
132
133} // namespace HepMC3
134
135#endif
Stores event-related information.
Definition GenEvent.h:47
bool failed() override
Return status of the stream.
int precision() const
Return output precision.
~WriterAscii()
Destructor.
void write_event(const GenEvent &evt) override
Write event to file.
WriterAscii(const std::string &filename, std::shared_ptr< GenRunInfo > run=std::shared_ptr< GenRunInfo >())
Constructor.
void close() override
Close file stream.
void write_run_info()
Write the GenRunInfo object to file.
void set_precision(const int &prec)
Set output precision.
Writer()
Constructor.
Definition Writer.h:29