HepMC3 event record library: WriterPlugin.h Source File

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{
23 class 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
GenEvent.h
Definition of class GenEvent.
Writer.h
Definition of interface Writer.
HepMC3::GenEvent
Stores event-related information.
Definition GenEvent.h:47
HepMC3::WriterPlugin::get_options
std::map< std::string, std::string > get_options() const override
Get options.
Definition WriterPlugin.h:47
HepMC3::WriterPlugin::set_run_info
void set_run_info(std::shared_ptr< GenRunInfo > run) override
Set the global GenRunInfo object.
Definition WriterPlugin.h:49
HepMC3::WriterPlugin::~WriterPlugin
~WriterPlugin() override
Destructor.
Definition WriterPlugin.cc:91
HepMC3::WriterPlugin::failed
bool failed() override
State.
Definition WriterPlugin.h:41
HepMC3::WriterPlugin::m_writer
Writer * m_writer
The actual writer.
Definition WriterPlugin.h:53
HepMC3::WriterPlugin::set_options
void set_options(const std::map< std::string, std::string > &options) override
Set options.
Definition WriterPlugin.h:45
HepMC3::WriterPlugin::close
void close() override
Close.
Definition WriterPlugin.h:39
HepMC3::WriterPlugin::WriterPlugin
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.
Definition WriterPlugin.cc:31
HepMC3::WriterPlugin::write_event
void write_event(const GenEvent &ev) override
Reading event.
Definition WriterPlugin.h:37
HepMC3::WriterPlugin::run_info
std::shared_ptr< GenRunInfo > run_info() const override
Get the global GenRunInfo object.
Definition WriterPlugin.h:43
HepMC3::WriterPlugin::dll_handle
void * dll_handle
library handler
Definition WriterPlugin.h:54
HepMC3::Writer::Writer
Writer()
Constructor.
Definition Writer.h:29
HepMC3
HepMC3 main namespace.
Definition AnalysisExample.h:24