MARLEY (Model of Argon Reaction Low Energy Yields)  v1.2.0
A Monte Carlo event generator for tens-of-MeV neutrino interactions
EventFileReader.hh
1 //
5 // This file is part of MARLEY (Model of Argon Reaction Low Energy Yields)
6 //
7 // MARLEY is free software: you can redistribute it and/or modify it under the
8 // terms of version 3 of the GNU General Public License as published by the
9 // Free Software Foundation.
10 //
11 // For the full text of the license please see COPYING or
12 // visit http://opensource.org/licenses/GPL-3.0
13 //
14 // Please respect the MCnet academic usage guidelines. See GUIDELINES
15 // or visit https://www.montecarlonet.org/GUIDELINES for details.
16 
17 #pragma once
18 #include <deque>
19 #include <fstream>
20 #include <string>
21 
22 #include "marley/JSON.hh"
23 #include "marley/OutputFile.hh"
24 
25 namespace marley {
26 
27  // Forward-declare the Event class
28  class Event;
29 
35 
36  public:
37 
38  EventFileReader( const std::string& file_name );
39 
40  virtual ~EventFileReader() = default;
41 
48  virtual bool next_event( marley::Event& ev );
49 
58  double flux_averaged_xsec( bool natural_units = false );
59 
62  next_event( ev );
63  return *this;
64  }
65 
69  virtual operator bool() const;
70 
71  protected:
72 
75  std::string file_name_;
76 
80  OutputFile::Format format_;
81 
83  std::ifstream in_;
84 
91  std::deque<marley::JSON>::iterator json_event_iter_;
92 
97  double flux_avg_tot_xs_ = 0.;
98 
103  bool initialized_ = false;
104 
107  virtual bool deduce_file_format();
108 
110  virtual void initialize();
111 
117  void ensure_initialized();
118  };
119 
120 }
Object that parses MARLEY output files written in any of the available formats, except for ROOT forma...
Definition: EventFileReader.hh:34
marley::JSON json_event_array_
Used to parse events from JSON-format files.
Definition: EventFileReader.hh:86
virtual void initialize()
Prepares the file for reading the events.
Definition: EventFileReader.cc:109
virtual bool deduce_file_format()
Helper function that auto-detects which of the available output formats is appropriate for the reques...
Definition: EventFileReader.cc:37
EventFileReader & operator>>(marley::Event &ev)
Stream operator for reading in the next event.
Definition: EventFileReader.hh:61
bool initialized_
Flag that indicates whether initialize() has been called or not.
Definition: EventFileReader.hh:103
marley::JSON::JSONWrapper< std::deque< marley::JSON > > json_event_array_wrapper_
Used to iterate over events from JSON-format files.
Definition: EventFileReader.hh:89
double flux_avg_tot_xs_
Flux-averaged total cross section (MeV -2) used to produce the events in the file,...
Definition: EventFileReader.hh:97
void ensure_initialized()
This function should be called at the beginning of all public member functions of EventFileReader tha...
Definition: EventFileReader.cc:223
std::string file_name_
Name of the file (with any needed path specification) to be read.
Definition: EventFileReader.hh:75
double flux_averaged_xsec(bool natural_units=false)
Returns the flux-averaged total cross section used to produce the events in the file.
Definition: EventFileReader.cc:233
OutputFile::Format format_
Format of the output file being read.
Definition: EventFileReader.hh:80
std::ifstream in_
Input stream used to read from textual output formats.
Definition: EventFileReader.hh:83
std::deque< marley::JSON >::iterator json_event_iter_
Iterator to the next JSON event in json_event_array.
Definition: EventFileReader.hh:91
virtual bool next_event(marley::Event &ev)
Read the next MARLEY event record from the file.
Definition: EventFileReader.cc:160
Container for ingoing and outgoing momentum 4-vectors from a reaction.
Definition: Event.hh:66
Definition: JSON.hh:89
Definition: JSON.hh:62