HepMC3 event record library: WriterRootTree Class Reference

HepMC3 event record library

Public Member Functions | Data Fields | Protected Attributes | Private Member Functions | Private Attributes
WriterRootTree Class Reference

## Detailed Description

GenEvent I/O serialization for root files based on root TTree.

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.

Definition at line 40 of file WriterRootTree.h.

`#include <WriterRootTree.h>`

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

## Public Member Functions
| WriterRootTree (const std::string &filename, std::shared_ptr< GenRunInfo > run=std::shared_ptr< GenRunInfo >())
| Default constructor.
| WriterRootTree (const std::string &filename, const std::string &treename, const std::string &branchname, std::shared_ptr< GenRunInfo > run=std::shared_ptr< GenRunInfo >())
| Constructor with tree name.
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.

## Data Fields
TTree * | m_tree = nullptr
| Tree handler. Public to allow simple access, e.g. custom branches.

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

## Private Member Functions
bool | init (std::shared_ptr< GenRunInfo > run)
| init routine

## Private Attributes
TFile * | m_file = nullptr
| File handler.
int | m_events_count = 0
| Events count. Needed to read the tree.
GenEventData * | m_event_data = nullptr
| Pointer to structure that holds event data.
GenRunInfoData * | m_run_info_data = nullptr
| Pointer to structure that holds run info data.
std::string | m_tree_name
| Name of TTree.
std::string | m_branch_name
| Name of TBranch in TTree.
std::shared_ptr< GenRunInfo > | m_run_info
| The global GenRunInfo object.

## Constructor & Destructor Documentation

## ◆ WriterRootTree() [1/2]

WriterRootTree | ( | 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 WriterRootTree.cc.

References init(), m_branch_name, m_file, m_tree_name, and WriterRootTree().

## ◆ WriterRootTree() [2/2]

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

Constructor with tree name.

Definition at line 30 of file WriterRootTree.cc.

References init(), m_branch_name, m_file, and m_tree_name.

## Member Function Documentation

## ◆ close()

void close | ( |  | ) |
| overridevirtual

Close file stream.

Implements Writer.

Definition at line 89 of file WriterRootTree.cc.

References m_event_data, m_file, m_run_info_data, and m_tree.

## ◆ failed()

bool failed | ( |  | ) |
| overridevirtual

Get stream error state flag.

Implements Writer.

Definition at line 97 of file WriterRootTree.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.

## ◆ init()

bool init | ( | std::shared_ptr< GenRunInfo > | run | ) |
| private

init routine

Definition at line 38 of file WriterRootTree.cc.

References HEPMC3_ERROR_LEVEL, m_branch_name, m_event_data, m_file, m_run_info_data, m_tree, m_tree_name, Writer::run_info(), and Writer::set_run_info().

## ◆ 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.

Reimplemented in WriterRootTreeOPAL.

Definition at line 55 of file WriterRootTree.cc.

References m_event_data, m_events_count, m_file, m_run_info_data, m_tree, GenEvent::run_info(), Writer::run_info(), Writer::set_run_info(), and GenEvent::write_data().

## ◆ write_run_info()

void write_run_info | ( |  | ) |

Write the GenRunInfo object to file.

Definition at line 87 of file WriterRootTree.cc.

## Field Documentation

## ◆ m_branch_name

std::string m_branch_name
| private

Name of TBranch in TTree.

Definition at line 88 of file WriterRootTree.h.

## ◆ m_event_data

GenEventData* m_event_data = nullptr
| private

Pointer to structure that holds event data.

Definition at line 85 of file WriterRootTree.h.

## ◆ m_events_count

int m_events_count = 0
| private

Events count. Needed to read the tree.

Definition at line 84 of file WriterRootTree.h.

## ◆ m_file

TFile* m_file = nullptr
| private

File handler.

Definition at line 80 of file WriterRootTree.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.

## ◆ m_run_info_data

GenRunInfoData* m_run_info_data = nullptr
| private

Pointer to structure that holds run info data.

Definition at line 86 of file WriterRootTree.h.

## ◆ m_tree

TTree* m_tree = nullptr

Tree handler. Public to allow simple access, e.g. custom branches.

Definition at line 82 of file WriterRootTree.h.

## ◆ m_tree_name

std::string m_tree_name
| private

Name of TTree.

Definition at line 87 of file WriterRootTree.h.

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

- WriterRootTree.h
- WriterRootTree.cc