HepMC3 event record library
ReaderRootTree.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // This file is part of HepMC
4 // Copyright (C) 2014-2020 The HepMC collaboration (see AUTHORS for details)
5 //
6 #ifndef HEPMC3_READERROOTTREE_H
7 #define HEPMC3_READERROOTTREE_H
8 /**
9  * @file ReaderRootTree.h
10  * @brief Definition of \b class ReaderRootTree
11  *
12  * @class HepMC3::ReaderRootTree
13  * @brief GenEvent I/O parsing and serialization for root files based on root TTree
14  *
15  * If HepMC was compiled with path to ROOT available, this class can be used
16  * for root file I/O in the same manner as with HepMC::ReaderAscii class.
17  *
18  * @ingroup IO
19  *
20  */
21 #include <string>
22 #include "HepMC3/Reader.h"
23 #include "HepMC3/GenEvent.h"
26 
27 // ROOT header files
28 #include "TFile.h"
29 #include "TTree.h"
30 #include "TBranch.h"
31 
32 namespace HepMC3
33 {
34 
35 class ReaderRootTree : public Reader
36 {
37 //
38 // Constructors
39 //
40 public:
41  /** @brief Default constructor */
42  ReaderRootTree(const std::string &filename);
43  /** @brief Constructor with tree name*/
44  ReaderRootTree(const std::string &filename, const std::string &treename, const std::string &branchname);
45 
46 //
47 // Functions
48 //
49 public:
50  /// @brief skip events
51  bool skip(const int) override;
52 
53  /** @brief Read event from file
54  *
55  * @param[out] evt Contains parsed event
56  */
57  bool read_event(GenEvent &evt) override;
58 
59  /** @brief Close file */
60  void close() override;
61 
62  /** @brief Get file error state */
63  bool failed() override;
64 
65 private:
66  /** @brief init routine */
67  bool init();
68 //
69 // Fields
70 //
71 private:
72  TFile* m_file; //!< File handler
73 public:
74  TTree* m_tree;//!< Tree handler. Public to allow simple access, e.g. custom branches.
75 private:
76  int m_events_count; //!< Events count. Needed to read the tree
77  GenEventData* m_event_data; //!< Pointer to structure that holds event data
78  GenRunInfoData* m_run_info_data; //!< Pointer to structure that holds run info data
79  std::string m_tree_name; //!< Name of TTree
80  std::string m_branch_name; //!< Name of TBranch in TTree
81 };
82 
83 } // namespace HepMC3
84 
85 #endif
GenEvent.h
Definition of class GenEvent.
HepMC3::ReaderRootTree::skip
bool skip(const int) override
skip events
Definition: ReaderRootTree.cc:76
HepMC3::ReaderRootTree::m_tree
TTree * m_tree
Tree handler. Public to allow simple access, e.g. custom branches.
Definition: ReaderRootTree.h:74
HepMC3::GenEvent
Stores event-related information.
Definition: GenEvent.h:41
HepMC3::ReaderRootTree::m_file
TFile * m_file
File handler.
Definition: ReaderRootTree.h:72
HepMC3::ReaderRootTree::m_tree_name
std::string m_tree_name
Name of TTree.
Definition: ReaderRootTree.h:79
HepMC3::ReaderRootTree::m_branch_name
std::string m_branch_name
Name of TBranch in TTree.
Definition: ReaderRootTree.h:80
HepMC3::ReaderRootTree::m_events_count
int m_events_count
Events count. Needed to read the tree.
Definition: ReaderRootTree.h:76
HepMC3
HepMC3 main namespace.
Definition: AnalysisExample.h:19
HepMC3::GenEventData
Stores serializable event information.
Definition: GenEventData.h:26
HepMC3::ReaderRootTree::read_event
bool read_event(GenEvent &evt) override
Read event from file.
Definition: ReaderRootTree.cc:85
HepMC3::Reader
Base class for all I/O readers.
Definition: Reader.h:25
HepMC3::ReaderRootTree::failed
bool failed() override
Get file error state.
Definition: ReaderRootTree.cc:118
HepMC3::ReaderRootTree::close
void close() override
Close file.
Definition: ReaderRootTree.cc:113
HepMC3::GenRunInfoData
Stores serializable run information.
Definition: GenRunInfoData.h:23
HepMC3::ReaderRootTree::ReaderRootTree
ReaderRootTree(const std::string &filename)
Default constructor.
Definition: ReaderRootTree.cc:18
HepMC3::ReaderRootTree::init
bool init()
init routine
Definition: ReaderRootTree.cc:33
HepMC3::ReaderRootTree
GenEvent I/O parsing and serialization for root files based on root TTree.
Definition: ReaderRootTree.h:36
HepMC3::ReaderRootTree::m_run_info_data
GenRunInfoData * m_run_info_data
Pointer to structure that holds run info data.
Definition: ReaderRootTree.h:78
HepMC3::ReaderRootTree::m_event_data
GenEventData * m_event_data
Pointer to structure that holds event data.
Definition: ReaderRootTree.h:77
GenRunInfoData.h
Definition of struct GenRunInfoData.
Reader.h
Definition of interface Reader.
GenEventData.h
Definition of struct GenEventData.