Version: SMASH-3.1
rivetoutput.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2021 Christian Holm Christensen
4  * Copyright (c) 2021-2022
5  * SMASH Team
6  *
7  * GNU General Public License (GPLv3 or later)
8  *
9  */
10 
11 #ifndef SRC_INCLUDE_SMASH_RIVETOUTPUT_H_
12 #define SRC_INCLUDE_SMASH_RIVETOUTPUT_H_
13 
14 #include <filesystem>
15 #include <memory>
16 #include <string>
17 #include <utility>
18 
19 #include "Rivet/AnalysisHandler.hh"
20 
21 #include "smash/fpenvironment.h"
22 #include "smash/hepmcinterface.h"
23 
24 namespace smash {
25 
37 class RivetOutput : public HepMcInterface {
38  public:
48  RivetOutput(const std::filesystem::path& path, std::string name,
49  const bool full_event, const RivetOutputParameters& rivet_par);
53  ~RivetOutput();
62  void at_eventend(const Particles& particles, const int32_t event_number,
63  const EventInfo& event) override;
69  void add_analysis(const std::string& name);
73  void add_path(const std::string& path);
77  void add_preload(const std::string& file);
81  void set_ignore_beams(bool ignore = true);
85  void set_log_level(const std::string& name, const std::string& level);
92  void set_cross_section(double xs, double xserr);
93 
94  private:
101  void setup(const RivetOutputParameters& params);
102 
107  struct Proxy {
109  using Handler = std::shared_ptr<Rivet::AnalysisHandler>;
111  explicit Proxy(Handler h) : h_(h), g_(0) {}
113  Proxy(Proxy&& p) : h_(p.h_), g_(std::move(p.g_)) {}
115  Handler operator->() { return h_; }
120  };
123 
125  std::shared_ptr<Rivet::AnalysisHandler> handler_;
127  std::filesystem::path filename_;
130 };
131 
132 } // namespace smash
133 
134 #endif // SRC_INCLUDE_SMASH_RIVETOUTPUT_H_
Guard type that safely disables floating point traps for the scope in which it is placed.
Definition: fpenvironment.h:79
Base class for output handlers that need the HepMC3 structure.
The Particles class abstracts the storage and manipulation of particles.
Definition: particles.h:33
SMASH output to Rivet analyses.
Definition: rivetoutput.h:37
Proxy analysis_handler_proxy()
Return a proxy that temporarily disables FP exceptions.
Definition: rivetoutput.h:122
void add_path(const std::string &path)
Add a load path to the Rivet handler.
Definition: rivetoutput.cc:130
void add_analysis(const std::string &name)
Add an analysis or analyses to Rivet.
Definition: rivetoutput.cc:126
std::filesystem::path filename_
Output file.
Definition: rivetoutput.h:127
std::shared_ptr< Rivet::AnalysisHandler > handler_
Rivet analysis handler.
Definition: rivetoutput.h:125
bool need_init_
Whether we need initialisation.
Definition: rivetoutput.h:129
~RivetOutput()
Destructor.
Definition: rivetoutput.cc:102
void set_cross_section(double xs, double xserr)
Set X-section.
Definition: rivetoutput.cc:165
void add_preload(const std::string &file)
Add preload to Rivet handler.
Definition: rivetoutput.cc:135
void setup(const RivetOutputParameters &params)
Setup Rivet using SMASH configuration parameters.
Definition: rivetoutput.cc:169
void set_log_level(const std::string &name, const std::string &level)
Set log level in Rivet.
Definition: rivetoutput.cc:145
void at_eventend(const Particles &particles, const int32_t event_number, const EventInfo &event) override
Add the final particles information of an event to the central vertex.
Definition: rivetoutput.cc:109
RivetOutput(const std::filesystem::path &path, std::string name, const bool full_event, const RivetOutputParameters &rivet_par)
Create Rivet output.
Definition: rivetoutput.cc:91
void set_ignore_beams(bool ignore=true)
Do not insist on appropriate beams for analyses.
Definition: rivetoutput.cc:139
constexpr int p
Proton.
Definition: action.h:24
Structure to contain custom data for output.
Helper structure for OutputParameters in order to store and hand over Rivet parameters.
A proxy object that wraps all Rivet::AnalysisHandler calls in an environment where FP errors are disa...
Definition: rivetoutput.h:107
DisableFloatTraps g_
FP traps temporaryly disabled.
Definition: rivetoutput.h:119
Proxy(Proxy &&p)
Move construct.
Definition: rivetoutput.h:113
std::shared_ptr< Rivet::AnalysisHandler > Handler
Type of handler.
Definition: rivetoutput.h:109
Handler operator->()
Forward calls to handler.
Definition: rivetoutput.h:115
Proxy(Handler h)
Construct proxy.
Definition: rivetoutput.h:111