HepMC3 event record library
ReaderuprootTree.h
1 #ifndef READERUPROOTTREE_H
2 #define READERUPROOTTREE_H
3 #include "HepMC3/GenEvent.h"
4 #include "HepMC3/FourVector.h"
5 #include "HepMC3/Print.h"
6 #include "HepMC3/Reader.h"
9 #include <iostream>
10 #include "HepMC3/Units.h"
11 #include "HepMC3/Version.h"
12 #include "Python.h"
13 #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
14 #include "numpy/arrayobject.h"
15 
16 namespace HepMC3
17 {
18 /** @brief ReaderuprootTree */
19 class ReaderuprootTree : public Reader
20 {
21 public:
22  /** @brief Constructor with tree and branch names*/
23  ReaderuprootTree(const std::string &filename,const std::string &treename="hepmc3_tree",const std::string &branchname="hepmc3_event");
24 
25  /// @brief skip events
26  bool skip(const int) override;
27 
28  /** @brief Read event from file
29  *
30  * @param[out] evt Contains parsed event
31  */
32  bool read_event(GenEvent &evt) override;
33 
34  /** @brief Close file */
35  void close() override;
36 
37  /** @brief Get file error state */
38  bool failed() override;
39 
41 private:
42  /** @brief init routine */
43  bool init(const std::string &filename);
44 
45  int m_events_count; //!< Events count. Needed to read the tree
46  GenEventData* m_event_data; //!< Pointer to structure that holds event data
47  GenRunInfoData* m_run_info_data; //!< Pointer to structure that holds run info data
48  std::string m_tree_name; //!< Name of TTree
49  std::string m_branch_name; //!< Name of TBranch in TTree
50 
51  //PyThreadState* m_thread_state;
52  PyObject* m_file; //!< Python file handler
53 
54  PyObject* m_tree; //!< Python tree handler.
55 
56  PyObject* m_genruninfo; //!< Python runInfo handler.
57 
58  PyObject* m_access_function; //!< Python access function for arrays
59 
60  PyObject* m_python_module; //!< Python module
61 
62  long int m_tree_getEntries; //!< number of processed events
63 
64  PyObject* get_function(PyObject*, const std::string& ); //!< Get python functions
65 
66  PyObject* init_python_module(const std::string&); //!< Init python module
67 
68  template <class T> std::vector<T> get_vector(PyObject * file_name,const std::string& array_name,std::string desired_type=""); //!< Get arrays
69 };
70 
71 }
72 #endif
HepMC3::ReaderuprootTree::init
bool init(const std::string &filename)
init routine
Definition: ReaderuprootTree.cc:106
GenEvent.h
Definition of class GenEvent.
HepMC3::ReaderuprootTree::m_run_info_data
GenRunInfoData * m_run_info_data
Pointer to structure that holds run info data.
Definition: ReaderuprootTree.h:47
HepMC3::ReaderuprootTree::m_file
PyObject * m_file
Python file handler.
Definition: ReaderuprootTree.h:52
HepMC3::GenEvent
Stores event-related information.
Definition: GenEvent.h:41
HepMC3::ReaderuprootTree::read_event
bool read_event(GenEvent &evt) override
Read event from file.
Definition: ReaderuprootTree.cc:193
HepMC3::ReaderuprootTree
ReaderuprootTree.
Definition: ReaderuprootTree.h:20
HepMC3::ReaderuprootTree::close
void close() override
Close file.
Definition: ReaderuprootTree.cc:295
HepMC3::ReaderuprootTree::get_vector
std::vector< T > get_vector(PyObject *file_name, const std::string &array_name, std::string desired_type="")
Get arrays.
Definition: ReaderuprootTree.cc:9
HepMC3
HepMC3 main namespace.
Definition: AnalysisExample.h:19
HepMC3::GenEventData
Stores serializable event information.
Definition: GenEventData.h:26
HepMC3::ReaderuprootTree::ReaderuprootTree
ReaderuprootTree(const std::string &filename, const std::string &treename="hepmc3_tree", const std::string &branchname="hepmc3_event")
Constructor with tree and branch names.
Definition: ReaderuprootTree.cc:100
HepMC3::ReaderuprootTree::init_python_module
PyObject * init_python_module(const std::string &)
Init python module.
Definition: ReaderuprootTree.cc:79
FourVector.h
Definition of class FourVector.
HepMC3::ReaderuprootTree::m_access_function
PyObject * m_access_function
Python access function for arrays.
Definition: ReaderuprootTree.h:58
HepMC3::ReaderuprootTree::m_tree_name
std::string m_tree_name
Name of TTree.
Definition: ReaderuprootTree.h:48
HepMC3::ReaderuprootTree::m_genruninfo
PyObject * m_genruninfo
Python runInfo handler.
Definition: ReaderuprootTree.h:56
HepMC3::Reader
Base class for all I/O readers.
Definition: Reader.h:25
HepMC3::ReaderuprootTree::m_tree_getEntries
long int m_tree_getEntries
number of processed events
Definition: ReaderuprootTree.h:62
HepMC3::GenRunInfoData
Stores serializable run information.
Definition: GenRunInfoData.h:23
Print.h
Definition of static class Print.
HepMC3::ReaderuprootTree::m_branch_name
std::string m_branch_name
Name of TBranch in TTree.
Definition: ReaderuprootTree.h:49
HepMC3::ReaderuprootTree::failed
bool failed() override
Get file error state.
Definition: ReaderuprootTree.cc:312
Units.h
Definition of class Units.
HepMC3::ReaderuprootTree::m_events_count
int m_events_count
Events count. Needed to read the tree.
Definition: ReaderuprootTree.h:45
HepMC3::ReaderuprootTree::skip
bool skip(const int) override
skip events
Definition: ReaderuprootTree.cc:184
HepMC3::ReaderuprootTree::get_function
PyObject * get_function(PyObject *, const std::string &)
Get python functions.
Definition: ReaderuprootTree.cc:66
GenRunInfoData.h
Definition of struct GenRunInfoData.
Reader.h
Definition of interface Reader.
HepMC3::ReaderuprootTree::m_tree
PyObject * m_tree
Python tree handler.
Definition: ReaderuprootTree.h:54
GenEventData.h
Definition of struct GenEventData.
HepMC3::ReaderuprootTree::m_event_data
GenEventData * m_event_data
Pointer to structure that holds event data.
Definition: ReaderuprootTree.h:46
HepMC3::ReaderuprootTree::m_python_module
PyObject * m_python_module
Python module.
Definition: ReaderuprootTree.h:60