ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
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. More...
 
virtual ~TreeNotifier ()
 Destructor. More...
 
virtual Bool_t Notify () override
 Root notification hook. More...
 
virtual void Clear (Option_t *="") override
 Called when the tree we're attached to is deleted. More...
 

Private Attributes

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

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 }

◆ ~TreeNotifier()

RootUtils::TreeNotifier::~TreeNotifier ( )
virtual

Destructor.

Definition at line 123 of file PyROOTTTreePatch.cxx.

124 {
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 169 of file PyROOTTTreePatch.cxx.

170 {
171  m_tree = nullptr;
172 }

◆ Notify()

Bool_t RootUtils::TreeNotifier::Notify ( )
overridevirtual

Root notification hook.

Definition at line 137 of file PyROOTTTreePatch.cxx.

138 {
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  PyObject* treeobj = PyWeakref_GetObject (m_treeobj_ref);
147  if (treeobj) {
148  PyObject** dictptr = _PyObject_GetDictPtr (treeobj);
149  if (dictptr && *dictptr) {
150  PyObject* notobj = PyObject_GetItem (*dictptr, pynotify_str);
151  if (notobj) {
152  // Got it --- call @c Notify.
153  PyObject* ret =
154  PyObject_CallMethod (notobj, const_cast<char*> ("Notify"), NULL);
155  if (!ret) return 0;
156  Py_DECREF (ret);
157  }
158  else
159  PyErr_Clear();
160  }
161  }
162 
163  if (m_chain) m_chain->Notify();
164  return true;
165 }

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:
tree
TChain * tree
Definition: tile_monitor.h:30
RootUtils::TreeNotifier::m_chain
TObject * m_chain
Notification tree.
Definition: PyROOTTTreePatch.cxx:96
RootUtils::PyGILStateEnsure
Definition: PyAthenaGILStateEnsure.h:20
ret
T ret(T t)
Definition: rootspy.cxx:260
RootUtils::TreeNotifier::m_treeobj_ref
PyObject * m_treeobj_ref
A weak reference to the Python object for the tree.
Definition: PyROOTTTreePatch.cxx:93
RootUtils::TreeNotifier::m_tree
TTree * m_tree
The tree to which we're attached.
Definition: PyROOTTTreePatch.cxx:99
PyObject
_object PyObject
Definition: IPyComponent.h:26