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