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 read from stream */
28 WriterPlugin(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 read from file */
31 WriterPlugin(const std::string& filename,const std::string &libname, const std::string &newwriter, std::shared_ptr<HepMC3::GenRunInfo> run = std::shared_ptr<GenRunInfo>());
32
33 /** @brief Reading event */
34 void write_event(const GenEvent& ev) override {if (!m_writer) return; return m_writer->write_event(ev);};
35 /** @brief Close */
36 void close() override { if (!m_writer) return; m_writer->close();};
37 /** @brief State */
38 bool failed() override {if (!m_writer) return true; return m_writer->failed();};
39 /** @brief Get the global GenRunInfo object. */
40 std::shared_ptr<GenRunInfo> run_info() const override { return m_writer?m_writer->run_info():nullptr; }
41 /** @brief Set options */
42 void set_options(const std::map<std::string, std::string>& options) override { if (!m_writer) return; else m_writer->set_options(options); }
43 /** @brief Get options */
44 std::map<std::string, std::string> get_options() const override { return m_writer?m_writer->get_options(): std::map<std::string, std::string>(); }
45 /// Set the global GenRunInfo object.
46 void set_run_info(std::shared_ptr<GenRunInfo> run) override { if (!m_writer) return; else m_writer->set_run_info(run); }
47 /** @brief Destructor */
48 ~WriterPlugin() override;
49private:
50 Writer* m_writer = nullptr; ///< The actual writer
51 void* dll_handle = nullptr; ///< library handler
52};
53}
54#endif
Definition of class GenEvent.
Definition of interface Writer.
Stores event-related information.
Definition: GenEvent.h:41
GenEvent I/O parsing and serialization using external plugin.
Definition: WriterPlugin.h:24
std::map< std::string, std::string > get_options() const override
Get options
Definition: WriterPlugin.h:44
void set_run_info(std::shared_ptr< GenRunInfo > run) override
Set the global GenRunInfo object.
Definition: WriterPlugin.h:46
~WriterPlugin() override
Destructor.
Definition: WriterPlugin.cc:70
bool failed() override
State.
Definition: WriterPlugin.h:38
Writer * m_writer
The actual writer.
Definition: WriterPlugin.h:50
void set_options(const std::map< std::string, std::string > &options) override
Set options.
Definition: WriterPlugin.h:42
void close() override
Close.
Definition: WriterPlugin.h:36
void write_event(const GenEvent &ev) override
Reading event.
Definition: WriterPlugin.h:34
std::shared_ptr< GenRunInfo > run_info() const override
Get the global GenRunInfo object.
Definition: WriterPlugin.h:40
void * dll_handle
library handler
Definition: WriterPlugin.h:51
Base class for all I/O writers.
Definition: Writer.h:25
virtual void set_run_info(std::shared_ptr< GenRunInfo > run)
Set the global GenRunInfo object.
Definition: Writer.h:42
virtual std::shared_ptr< GenRunInfo > run_info() const
Get the global GenRunInfo object.
Definition: Writer.h:45
virtual void write_event(const GenEvent &evt)=0
Write event evt to output target.
virtual void set_options(const std::map< std::string, std::string > &options)
Set options.
Definition: Writer.h:52
virtual bool failed()=0
Get file and/or stream error state.
virtual std::map< std::string, std::string > get_options() const
Set options.
Definition: Writer.h:54
virtual void close()=0
Close file and/or stream.
HepMC3 main namespace.