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
long int m_tree_getEntries
number of processed events
Definition of interface Reader.
std::vector< T > get_vector(PyObject *file_name, const std::string &array_name, std::string desired_type="")
Get arrays.
PyObject * init_python_module(const std::string &)
Init python module.
std::string m_tree_name
Name of TTree.
GenRunInfoData * m_run_info_data
Pointer to structure that holds run info data.
bool failed() override
Get file error state.
Definition of struct GenEventData.
PyObject * get_function(PyObject *, const std::string &)
Get python functions.
PyObject * m_access_function
Python access function for arrays.
int m_events_count
Events count. Needed to read the tree.
GenEventData * m_event_data
Pointer to structure that holds event data.
std::string m_branch_name
Name of TBranch in TTree.
Stores event-related information.
Definition: GenEvent.h:41
Stores serializable event information.
Definition: GenEventData.h:26
bool read_event(GenEvent &evt) override
Read event from file.
ReaderuprootTree.
Stores serializable run information.
bool skip(const int) override
skip events
Definition of class Units.
PyObject * m_file
Python file handler.
void close() override
Close file.
PyObject * m_genruninfo
Python runInfo handler.
Definition of class GenEvent.
Base class for all I/O readers.
Definition: Reader.h:25
bool init(const std::string &filename)
init routine
PyObject * m_python_module
Python module.
Definition of class FourVector.
ReaderuprootTree(const std::string &filename, const std::string &treename="hepmc3_tree", const std::string &branchname="hepmc3_event")
Constructor with tree and branch names.
PyObject * m_tree
Python tree handler.
Definition of struct GenRunInfoData.