37 OutputFile(
const std::string& name,
const std::string& format,
38 const std::string& mode,
bool force =
false);
42 const std::string& name()
const {
return name_; }
50 virtual bool resume(std::unique_ptr<marley::Generator>& gen,
51 long& num_previous_events) = 0;
68 bool mode_is_resume()
const {
return mode_ == Mode::RESUME; }
81 enum class Format { ROOT, HEPEVT,
JSON, ASCII };
93 std::ifstream test_stream( filename );
94 return test_stream.good();
120 enum class Mode { OVERWRITE, APPEND, RESUME };
136 void start_json_output(
bool start_array);
139 std::fstream stream_;
143 bool needs_comma_ =
false;
150 int_fast64_t byte_count_ = 0;
155 double flux_avg_tot_xsec_ = 0.;
159 TextOutputFile(
const std::string& name,
const std::string& format,
160 const std::string& mode,
bool force =
false,
int indent = -1);
164 inline void set_indent(
int indent) { indent_ = indent; }
166 virtual void open()
override;
171 virtual bool resume(std::unique_ptr<marley::Generator>& gen,
172 long& num_previous_events)
override;
Container for ingoing and outgoing momentum 4-vectors from a reaction.
Definition: Event.hh:66
The MARLEY Event generator.
Definition: Generator.hh:42
Abstract base class for objects that deliver output to a file opened by the marley command-line execu...
Definition: OutputFile.hh:29
virtual int_fast64_t bytes_written()=0
The number of bytes that have been written during the current MARLEY session to this file.
virtual void write_flux_avg_tot_xsec(double avg_tot_xsec)=0
If needed (for the HEPEVT and ASCII formats), write the flux-averaged total cross section to the file...
virtual void write_generator_state(const marley::JSON &json_config, const marley::Generator &gen, const long num_events)=0
For the file formats that support it, write metadata containing the generator state and configuration...
virtual void write_event(const marley::Event *event)=0
Write a new marley::Event to this output file.
Format format_
Format to use when writing events to the file.
Definition: OutputFile.hh:123
virtual void open()=0
Open the output file for writing.
virtual void close(const marley::JSON &json_config, const marley::Generator &gen, const long num_events)=0
Close the output file and perform any necessary cleanup.
std::unique_ptr< marley::Generator > restore_generator(const marley::JSON &config)
Helper function for resume() that instantiates a marley::Generator object given the previous JSON con...
Definition: OutputFile.cc:55
virtual bool resume(std::unique_ptr< marley::Generator > &gen, long &num_previous_events)=0
Load a marley::Generator object whose configuration and state were saved to the metadata in a ROOT or...
bool check_if_file_exists(const std::string &filename)
Checks that a given file exists (and is readable)
Definition: OutputFile.hh:92
std::string name_
Name of the file to receive output.
Definition: OutputFile.hh:122
Definition: OutputFile.hh:131
virtual void open() override
Open the output file for writing.
Definition: OutputFile.cc:97
void write_generator_state(const marley::JSON &json_config, const marley::Generator &gen, const long num_events) override
For the file formats that support it, write metadata containing the generator state and configuration...
Definition: OutputFile.cc:289
virtual bool resume(std::unique_ptr< marley::Generator > &gen, long &num_previous_events) override
Load a marley::Generator object whose configuration and state were saved to the metadata in a ROOT or...
Definition: OutputFile.cc:137
virtual void write_event(const marley::Event *event) override
Write a new marley::Event to this output file.
Definition: OutputFile.cc:252
virtual void write_flux_avg_tot_xsec(double avg_tot_xsec) override
If needed (for the HEPEVT and ASCII formats), write the flux-averaged total cross section to the file...
Definition: OutputFile.cc:341
virtual void close(const marley::JSON &json_config, const marley::Generator &gen, const long num_events) override
Close the output file and perform any necessary cleanup.
Definition: OutputFile.cc:318
int_fast64_t bytes_written() override
The number of bytes that have been written during the current MARLEY session to this file.
Definition: OutputFile.cc:242