Hello everyone,
I have a question about how I can make a custom class written in Python known to ROOT so that I can store an object of that class in a ROOT TBranch.
My custom Python class is a simple class that looks like this:
class Event:
def __init___(self):
self.event_data = {} # Python dictionary with 36-64 keys
self.event_num = 0 # Int
def load_data (self, event_num, data):
self.event_data = data
self.event_num = event_num
I then try to load this event into a TBranch as below
with ROOT.TFile("test_tree.root", "RECREATE") as infile:
tree = ROOT.TTree("Event_Tree", "Event_Tree")
for times in range(0, 5):
dummy_event = Event()
dummy_event.load_data(1, {1: [1, 2, 3], 2:[5, 6, 7]})
branch_name = "Event_obj"
tree.Branch(branch_name, dummy_event)
tree.Fill()
tree.Write()
print("Done!")
However, running this code gives me the error “TypeError: Template method resolution failed:
none of the 8 overloaded methods succeeded.” I realize that my custom class “isn’t known to ROOT” as it says on the ROOT CERN TTree documentation page.
How do I make my class known to ROOT so that I can put objects of the Event class in branches of my TTree? For context, I am relatively new to C++ so I would appreciate some pointers here if there is some C++ required!
Thanks!
_ROOT Version: 6.32.02
_Platform: Ubuntu 22.04.5 LTS
_Compiler: linux8664gcc