ATLAS Offline Software
Loading...
Searching...
No Matches
RootUtils::TreeNotifier Class Reference

Tree notification handler. More...

Inheritance diagram for RootUtils::TreeNotifier:
Collaboration diagram for RootUtils::TreeNotifier:

Public Member Functions

 TreeNotifier (TTree *tree, PyObject *treeobj_ref)
 Constructor.
virtual ~TreeNotifier ()
 Destructor.
virtual Bool_t Notify () override
 Root notification hook.
virtual void Clear (Option_t *="") override
 Called when the tree we're attached to is deleted.

Private Attributes

PyObjectm_treeobj_ref
 A weak reference to the Python object for the tree.
TObject * m_chain
 Notification tree.
TTree * m_tree
 The tree to which we're attached.

Detailed Description

Tree notification handler.

This is the tree notification handler. When it's Notify method is called, we need to do two things. First, clear the cached branches/leaves. Second, call any Python notification handler.

Definition at line 67 of file PyROOTTTreePatch.cxx.

Constructor & Destructor Documentation

◆ TreeNotifier()

RootUtils::TreeNotifier::TreeNotifier ( TTree * tree,
PyObject * treeobj_ref )

Constructor.

Parameters
treeThe tree for which we're creating the notification.
treeobj_refA weak reference to the tree for which we're creating the notification. We take ownership of the reference object.

Definition at line 110 of file PyROOTTTreePatch.cxx.

112 : m_treeobj_ref (treeobj_ref),
113 m_chain (tree->GetNotify()),
114 m_tree (tree)
115{
116 // We acquire ownership of treeobj_ref.
117}
TObject * m_chain
Notification tree.
TTree * m_tree
The tree to which we're attached.
PyObject * m_treeobj_ref
A weak reference to the Python object for the tree.
TChain * tree

◆ ~TreeNotifier()

RootUtils::TreeNotifier::~TreeNotifier ( )
virtual

Destructor.

Definition at line 123 of file PyROOTTTreePatch.cxx.

124{
125 RootUtils::PyGILStateEnsure gil;
126 if (m_tree) {
127 // Clear the reference from the tree to this object.
128 m_tree->SetNotify (m_chain);
129 }
130 Py_XDECREF (m_treeobj_ref);
131}

Member Function Documentation

◆ Clear()

void RootUtils::TreeNotifier::Clear ( Option_t * = "")
overridevirtual

Called when the tree we're attached to is deleted.

Definition at line 180 of file PyROOTTTreePatch.cxx.

181{
182 m_tree = nullptr;
183}

◆ Notify()

Bool_t RootUtils::TreeNotifier::Notify ( )
overridevirtual

Root notification hook.

Definition at line 137 of file PyROOTTTreePatch.cxx.

138{
139 RootUtils::PyGILStateEnsure gil;
140
141 // Intern __pynotify__ if needed.
142 if (pynotify_str == 0)
143 pynotify_str = PyUnicode_InternFromString("__pynotify__");
144
145 // Look for a notification object.
146#if PY_VERSION_HEX >= 0x030d0000
147 PyObject* treeobj = nullptr;
148 (void)PyWeakref_GetRef (m_treeobj_ref, &treeobj);
149#else
150 PyObject* treeobj = PyWeakref_GetObject (m_treeobj_ref);
151#endif
152 if (treeobj) {
153 PyObject** dictptr = _PyObject_GetDictPtr (treeobj);
154 if (dictptr && *dictptr) {
155 PyObject* notobj = PyObject_GetItem (*dictptr, pynotify_str);
156#if PY_VERSION_HEX >= 0x030d0000
157 Py_DECREF(treeobj);
158#endif
159 if (notobj) {
160 // Got it --- call @c Notify.
161 PyObject* ret =
162 PyObject_CallMethod (notobj, const_cast<char*> ("Notify"), NULL);
163#if PY_VERSION_HEX >= 0x030d0000
164 Py_DECREF (notobj);
165#endif
166 if (!ret) return 0;
167 Py_DECREF (ret);
168 }
169 else
170 PyErr_Clear();
171 }
172 }
173
174 if (m_chain) m_chain->Notify();
175 return true;
176}
_object PyObject
static PyObject * pynotify_str

Member Data Documentation

◆ m_chain

TObject* RootUtils::TreeNotifier::m_chain
private

Notification tree.

Definition at line 96 of file PyROOTTTreePatch.cxx.

◆ m_tree

TTree* RootUtils::TreeNotifier::m_tree
private

The tree to which we're attached.

Definition at line 99 of file PyROOTTTreePatch.cxx.

◆ m_treeobj_ref

PyObject* RootUtils::TreeNotifier::m_treeobj_ref
private

A weak reference to the Python object for the tree.

Making it a reference prevents a reference cycle.

Definition at line 93 of file PyROOTTTreePatch.cxx.


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