HepMC3 event record library
WriterPlugin.h
Go to the documentation of this file.
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_WRITERPLUGIN_H
7#define HEPMC3_WRITERPLUGIN_H
8/**
9 * @file WriterPlugin.h
10 * @brief Definition of \b class WriterPlugin
11 *
12 * @class HepMC3::WriterPlugin
13 * @brief GenEvent I/O parsing and serialization using external plugin
14 *
15 *
16 * @ingroup IO
17 *
18 */
19#include "HepMC3/Writer.h"
20#include "HepMC3/GenEvent.h"
21namespace HepMC3
22{
23class WriterPlugin : public Writer
24{
25public:
26
27 /** @brief Constructor to write to stream */
28 WriterPlugin(std::shared_ptr<std::ostream> stream, const std::string &libname, const std::string &newwriter, std::shared_ptr<HepMC3::GenRunInfo> run = std::shared_ptr<GenRunInfo>());
29
30 /** @brief Constructor to write to stream */
31 WriterPlugin(std::ostream & stream, const std::string &libname, const std::string &newwriter, std::shared_ptr<HepMC3::GenRunInfo> run = std::shared_ptr<GenRunInfo>());
32
33 /** @brief Constructor to write to file */
34 WriterPlugin(const std::string& filename, const std::string &libname, const std::string &newwriter, std::shared_ptr<HepMC3::GenRunInfo> run = std::shared_ptr<GenRunInfo>());
35
36 /** @brief Reading event */
37 void write_event(const GenEvent& ev) override {if (!m_writer) return; return m_writer->write_event(ev);};
38 /** @brief Close */
39 void close() override { if (!m_writer) return; m_writer->close();};
40 /** @brief State */
41 bool failed() override {if (!m_writer) return true; return m_writer->failed();};
42 /** @brief Get the global GenRunInfo object. */
43 std::shared_ptr<GenRunInfo> run_info() const override { return m_writer?m_writer->run_info():nullptr; }
44 /** @brief Set options */
45 void set_options(const std::map<std::string, std::string>& options) override { if (!m_writer) return; else m_writer->set_options(options); }
46 /** @brief Get options */
47 std::map<std::string, std::string> get_options() const override { return m_writer?m_writer->get_options(): std::map<std::string, std::string>(); }
48 /// Set the global GenRunInfo object.
49 void set_run_info(std::shared_ptr<GenRunInfo> run) override { if (!m_writer) return; else m_writer->set_run_info(run); }
50 /** @brief Destructor */
51 ~WriterPlugin() override;
52private:
53 Writer* m_writer = nullptr; ///< The actual writer
54 void* dll_handle = nullptr; ///< library handler
55};
56}
57#endif
Definition of class GenEvent.
Definition of interface Writer.
Stores event-related information.
Definition GenEvent.h:47
std::map< std::string, std::string > get_options() const override
Get options.
void set_run_info(std::shared_ptr< GenRunInfo > run) override
Set the global GenRunInfo object.
~WriterPlugin() override
Destructor.
bool failed() override
State.
Writer * m_writer
The actual writer.
void set_options(const std::map< std::string, std::string > &options) override
Set options.
void close() override
Close.
WriterPlugin(std::shared_ptr< std::ostream > stream, const std::string &libname, const std::string &newwriter, std::shared_ptr< HepMC3::GenRunInfo > run=std::shared_ptr< GenRunInfo >())
Constructor to write to stream.
void write_event(const GenEvent &ev) override
Reading event.
std::shared_ptr< GenRunInfo > run_info() const override
Get the global GenRunInfo object.
void * dll_handle
library handler
Writer()
Constructor.
Definition Writer.h:29
HepMC3 main namespace.