HepMC3 event record library
ReaderPlugin.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_READERPLUGIN_H
7#define HEPMC3_READERPLUGIN_H
8/**
9 * @file ReaderPlugin.h
10 * @brief Definition of \b class ReaderPlugin
11 *
12 * @class HepMC3::ReaderPlugin
13 * @brief GenEvent I/O parsing and serialization using external plugin
14 *
15 *
16 * @ingroup IO
17 *
18 */
19#include "HepMC3/Reader.h"
20#include "HepMC3/GenEvent.h"
21namespace HepMC3
22{
23class ReaderPlugin : public Reader
24{
25public:
26 /** @brief Constructor to read from stream*/
27 ReaderPlugin(std::istream & stream,const std::string &libname, const std::string &newreader);
28 /** @brief Constructor to read from file*/
29 ReaderPlugin(const std::string& filename,const std::string &libname, const std::string &newreader);
30 /** @brief Skip or fast forward reading of some events*/
31 bool skip(const int n) override { if (!m_reader) return false; return m_reader->skip(n); }
32 /** @brief Reading event */
33 bool read_event(GenEvent& ev) override {if (!m_reader) return false; return m_reader->read_event(ev);};
34 /** @brief Close */
35 void close() override { if (!m_reader) return; m_reader->close(); };
36 /** @brief State */
37 bool failed() override {if (!m_reader) return true; return m_reader->failed();};
38 /** @brief Get the global GenRunInfo object. */
39 std::shared_ptr<GenRunInfo> run_info() const override { return m_reader?m_reader->run_info():nullptr; }
40 /** @brief Set options */
41 void set_options(const std::map<std::string, std::string>& options) override { if (!m_reader) return; else m_reader->set_options(options); }
42 /** @brief Get options */
43 std::map<std::string, std::string> get_options() const override { return m_reader?m_reader->get_options(): std::map<std::string, std::string>(); }
44 /** @brief Destructor */
45 ~ReaderPlugin() override;
46 /// Set the global GenRunInfo object.
47 void set_run_info(std::shared_ptr<GenRunInfo> run) override { if (!m_reader) return; else m_reader->set_run_info(run); }
48private:
49 Reader* m_reader = nullptr; ///< The actual reader
50 void* dll_handle = nullptr; ///< library handler
51};
52}
53#endif
Definition of class GenEvent.
Definition of interface Reader.
Stores event-related information.
Definition: GenEvent.h:41
GenEvent I/O parsing and serialization using external plugin.
Definition: ReaderPlugin.h:24
std::map< std::string, std::string > get_options() const override
Get options
Definition: ReaderPlugin.h:43
void set_run_info(std::shared_ptr< GenRunInfo > run) override
Set the global GenRunInfo object.
Definition: ReaderPlugin.h:47
bool failed() override
State.
Definition: ReaderPlugin.h:37
bool read_event(GenEvent &ev) override
Reading event.
Definition: ReaderPlugin.h:33
~ReaderPlugin() override
Destructor.
Definition: ReaderPlugin.cc:67
bool skip(const int n) override
Skip or fast forward reading of some events.
Definition: ReaderPlugin.h:31
void set_options(const std::map< std::string, std::string > &options) override
Set options.
Definition: ReaderPlugin.h:41
void close() override
Close.
Definition: ReaderPlugin.h:35
Reader * m_reader
The actual reader.
Definition: ReaderPlugin.h:49
std::shared_ptr< GenRunInfo > run_info() const override
Get the global GenRunInfo object.
Definition: ReaderPlugin.h:39
void * dll_handle
library handler
Definition: ReaderPlugin.h:50
Base class for all I/O readers.
Definition: Reader.h:25
virtual bool read_event(GenEvent &evt)=0
Fill next event from input into evt.
virtual bool skip(const int)
skip or fast forward reading of some events
Definition: Reader.h:34
virtual void set_run_info(std::shared_ptr< GenRunInfo > run)
Set the global GenRunInfo object.
Definition: Reader.h:56
virtual std::shared_ptr< GenRunInfo > run_info() const
Get the global GenRunInfo object.
Definition: Reader.h:44
virtual void set_options(const std::map< std::string, std::string > &options)
Set options.
Definition: Reader.h:51
virtual bool failed()=0
Get file and/or stream error state.
virtual std::map< std::string, std::string > get_options() const
Get options
Definition: Reader.h:53
virtual void close()=0
Close file and/or stream.
HepMC3 main namespace.