HepMC3 event record library: WriterRoot Class Reference

HepMC3 event record library

Public Member Functions | Protected Attributes | Private Attributes
WriterRoot Class Reference

## Detailed Description

GenEvent I/O serialization for root files.

If HepMC was compiled with path to ROOT available, this class can be used for root writing in the same manner as with HepMC::WriterAscii class.

Examples
  rootIO_example_write.cc.

Definition at line 37 of file WriterRoot.h.

`#include <WriterRoot.h>`

Inheritance diagram for WriterRoot:
[legend]
Collaboration diagram for WriterRoot:
[legend]

## Public Member Functions
| WriterRoot (const std::string &filename, std::shared_ptr< GenRunInfo > run=std::shared_ptr< GenRunInfo >())
| Default constructor.
void | write_event (const GenEvent &evt) override
| Write event to file.
void | write_run_info ()
| Write the GenRunInfo object to file.
void | close () override
| Close file stream.
bool | failed () override
| Get stream error state flag.
virtual void | set_run_info (std::shared_ptr< GenRunInfo > run)
| Set the global GenRunInfo object.
virtual std::shared_ptr< GenRunInfo > | run_info () const
| Get the global GenRunInfo object.
virtual void | set_options (const std::map< std::string, std::string > &options)
| Set options.
virtual std::map< std::string, std::string > | get_options () const
| Set options.

## Protected Attributes
std::map< std::string, std::string > | m_options
| options

## Private Attributes
TFile * | m_file
| File handler.
int | m_events_count
| Events count. Needed to generate unique object name.
std::shared_ptr< GenRunInfo > | m_run_info
| The global GenRunInfo object.

## Constructor & Destructor Documentation

## ◆ WriterRoot()

WriterRoot | ( | const std::string & | filename,
|  | std::shared_ptr< GenRunInfo > | run = std::shared_ptr<GenRunInfo>() )

Default constructor.

Warning
  If file exists, it will be overwritten

Definition at line 22 of file WriterRoot.cc.

References HEPMC3_ERROR_LEVEL, m_events_count, m_file, Writer::run_info(), Writer::set_run_info(), write_run_info(), and WriterRoot().

## Member Function Documentation

## ◆ close()

void close | ( |  | ) |
| overridevirtual

Close file stream.

Implements Writer.

Examples
  rootIO_example_write.cc.

Definition at line 75 of file WriterRoot.cc.

References m_file.

## ◆ failed()

bool failed | ( |  | ) |
| overridevirtual

Get stream error state flag.

Implements Writer.

Definition at line 79 of file WriterRoot.cc.

References m_file.

## ◆ get_options()

virtual std::map< std::string, std::string > get_options | ( |  | ) | const
| inlinevirtualinherited

Set options.

Reimplemented in WriterPlugin.

Definition at line 54 of file Writer.h.

References m_options.

## ◆ run_info()

virtual std::shared_ptr< GenRunInfo > run_info | ( |  | ) | const
| inlinevirtualinherited

Get the global GenRunInfo object.

Reimplemented in WriterGZ< T, C >, and WriterPlugin.

Definition at line 45 of file Writer.h.

References m_run_info.

## ◆ set_options()

virtual void set_options | ( | const std::map< std::string, std::string > & | options | ) |
| inlinevirtualinherited

Set options.

Reimplemented in WriterPlugin.

Definition at line 52 of file Writer.h.

References m_options.

## ◆ set_run_info()

virtual void set_run_info | ( | std::shared_ptr< GenRunInfo > | run | ) |
| inlinevirtualinherited

Set the global GenRunInfo object.

Reimplemented in WriterGZ< T, C >, and WriterPlugin.

Definition at line 42 of file Writer.h.

References m_run_info.

## ◆ write_event()

void write_event | ( | const GenEvent & | evt | ) |
| overridevirtual

Write event to file.

Parameters

  [in] | evt | Event to be serialized

Implements Writer.

Examples
  rootIO_example_write.cc.

Definition at line 35 of file WriterRoot.cc.

References HEPMC3_ERROR_LEVEL, HEPMC3_WARNING_LEVEL, m_events_count, m_file, GenEvent::run_info(), Writer::run_info(), Writer::set_run_info(), GenEvent::write_data(), and write_run_info().

## ◆ write_run_info()

void write_run_info | ( |  | ) |

Write the GenRunInfo object to file.

Definition at line 61 of file WriterRoot.cc.

References HEPMC3_ERROR_LEVEL, m_file, and Writer::run_info().

## Field Documentation

## ◆ m_events_count

int m_events_count
| private

Events count. Needed to generate unique object name.

Definition at line 71 of file WriterRoot.h.

## ◆ m_file

TFile* m_file
| private

File handler.

Definition at line 70 of file WriterRoot.h.

## ◆ m_options

std::map<std::string, std::string> m_options
| protectedinherited

options

Definition at line 59 of file Writer.h.

## ◆ m_run_info

std::shared_ptr<GenRunInfo> m_run_info
| privateinherited

The global GenRunInfo object.

Definition at line 64 of file Writer.h.

The documentation for this class was generated from the following files:

- WriterRoot.h
- WriterRoot.cc