Hi, ROOT experts,
I have some custom types that I want to save to TTree branches, and I have done something similar before in C++ with different custom types but I don’t know how to make it work in Python, could you please enlighten me?
parser = argparse.ArgumentParser()
parser.add_argument("inFileName", type=str)
args = parser.parse_args()
inFile = TFile(args.inFileName)
daqstatus = ROOT.mattak.DAQStatus()
header = ROOT.mattak.Header()
waveforms = ROOT.mattak.Waveforms()
inTree = inFile.Get("combined")
inTree.SetBranchAddress("daqstatus", daqstatus)
inTree.SetBranchAddress("header", header)
inTree.SetBranchAddress("waveforms", waveforms)
outFileName = 'filtered_' + args.inFileName
outFile = TFile(outFileName, "recreate" )
outTree = TTree("combined", "combined")
outTree.Branch("daqstatus", daqstatus)
outTree.Branch("header", header)
outTree.Branch("waveforms", waveforms)
nTotalEvents = inTree.GetEntries()
nPassedEvents = 0
hitAll = 4
HF = HitFilter()
nChannels = 24
for i_event in range(nTotalEvents):
inTree.GetEntry(i_event)
wfs = []
for i_channel in range(nChannels):
if i_channel < 4:
wfs.append(waveforms.makeGraph(i_channel).GetY())
else:
break
nHits = HF.scanForHits(np.array(wfs))
if nHits == hitAll:
nPassedEvents += 1
outTree.Fill()
inFile.Close()
outFile.cd()
outTree.Write()
outFile.Close()
Although this script works and the output file can be generated, but when I opened the output file I got errors:
*** Break *** segmentation violation
[/opt/homebrew/Cellar/root/6.26.06_2/lib/root/libCore.so] TUnixSystem::DispatchSignals(ESignals) (no debug info)
[/usr/lib/system/libsystem_platform.dylib] _sigtramp (no debug info)
[/Users/martin/Desktop/RNO-G/software/mattak/build/libmattak.dylib] TGraph* graphImpl<mattak::Waveforms>(mattak::Waveforms const&, int, bool) /Users/martin/Desktop/RNO-G/software/mattak/src/Waveforms.cc:80
[<unknown binary>] (no debug info)
[/opt/homebrew/Cellar/root/6.26.06_2/lib/root/libcppyy_backend3_10.so] WrapperCall(long, unsigned long, void*, void*, void*) (no debug info)
[/opt/homebrew/Cellar/root/6.26.06_2/lib/root/libcppyy_backend3_10.so] Cppyy::CallR(long, void*, unsigned long, void*) (no debug info)
[/opt/homebrew/Cellar/root/6.26.06_2/lib/root/libcppyy3_10.so] CPyCppyy::(anonymous namespace)::InstancePtrExecutor::Execute(long, void*, CPyCppyy::CallContext*) (no debug info)
[/opt/homebrew/Cellar/root/6.26.06_2/lib/root/libcppyy3_10.so] CPyCppyy::CPPMethod::ExecuteFast(void*, long, CPyCppyy::CallContext*) (no debug info)
[/opt/homebrew/Cellar/root/6.26.06_2/lib/root/libcppyy3_10.so] CPyCppyy::CPPMethod::ExecuteProtected(void*, long, CPyCppyy::CallContext*) (no debug info)
[/opt/homebrew/Cellar/root/6.26.06_2/lib/root/libcppyy3_10.so] CPyCppyy::CPPMethod::Call(CPyCppyy::CPPInstance*&, _object*, _object*, CPyCppyy::CallContext*) (no debug info)
[/opt/homebrew/Cellar/root/6.26.06_2/lib/root/libcppyy3_10.so] CPyCppyy::(anonymous namespace)::mp_call(CPyCppyy::CPPOverload*, _object*, _object*) (no debug info)
[/opt/homebrew/Cellar/python@3.10/3.10.10_1/Frameworks/Python.framework/Versions/3.10/Python] _PyObject_MakeTpCall (no debug info)
[/opt/homebrew/Cellar/python@3.10/3.10.10_1/Frameworks/Python.framework/Versions/3.10/Python] call_function (no debug info)
[/opt/homebrew/Cellar/python@3.10/3.10.10_1/Frameworks/Python.framework/Versions/3.10/Python] _PyEval_EvalFrameDefault (no debug info)
[/opt/homebrew/Cellar/python@3.10/3.10.10_1/Frameworks/Python.framework/Versions/3.10/Python] _PyEval_Vector (no debug info)
[/opt/homebrew/Cellar/python@3.10/3.10.10_1/Frameworks/Python.framework/Versions/3.10/Python] PyEval_EvalCode (no debug info)
[/opt/homebrew/Cellar/python@3.10/3.10.10_1/Frameworks/Python.framework/Versions/3.10/Python] run_eval_code_obj (no debug info)
[/opt/homebrew/Cellar/python@3.10/3.10.10_1/Frameworks/Python.framework/Versions/3.10/Python] run_mod (no debug info)
[/opt/homebrew/Cellar/python@3.10/3.10.10_1/Frameworks/Python.framework/Versions/3.10/Python] pyrun_file (no debug info)
[/opt/homebrew/Cellar/python@3.10/3.10.10_1/Frameworks/Python.framework/Versions/3.10/Python] _PyRun_SimpleFileObject (no debug info)
[/opt/homebrew/Cellar/python@3.10/3.10.10_1/Frameworks/Python.framework/Versions/3.10/Python] _PyRun_AnyFileObject (no debug info)
[/opt/homebrew/Cellar/python@3.10/3.10.10_1/Frameworks/Python.framework/Versions/3.10/Python] pymain_run_file_obj (no debug info)
[/opt/homebrew/Cellar/python@3.10/3.10.10_1/Frameworks/Python.framework/Versions/3.10/Python] pymain_run_file (no debug info)
[/opt/homebrew/Cellar/python@3.10/3.10.10_1/Frameworks/Python.framework/Versions/3.10/Python] Py_RunMain (no debug info)
[/opt/homebrew/Cellar/python@3.10/3.10.10_1/Frameworks/Python.framework/Versions/3.10/Python] Py_BytesMain (no debug info)
[/usr/lib/dyld] start (no debug info)
Traceback (most recent call last):
File "/Users/martin/Desktop/NuRadioMC/noise/applyHitFilter.py", line 49, in <module>
wfs.append(waveforms.makeGraph(i_channel).GetY())
cppyy.ll.SegmentationViolation: TGraph* mattak::Waveforms::makeGraph(int chan, bool ns = true) =>
SegmentationViolation: segfault in C++; program state was reset
ROOT Version: 6.26/06
Python Version: 3.10.10