Hi! I am trying to shorten a large .root file by cloning its structure (with only some branches) and writing to it only the events for which a parameter numRecCandidates
is >=1. It reads the structure well, then reaches the event passing the requirement, and then I get Segmentation fault
error. The same problem was present when I tried to clone the entire tree. I would be very grateful if you could help me with this problem.
This is my code (excuse me, it contains some irrelevant pieces, but not that much):
import ROOT as r
import argparse
r.PyConfig.IgnoreCommandLineOptions = True
def analysis():
parser = argparse.ArgumentParser(description='Script to makeAnalysis')
parser.add_argument('-g', '--geofile', help='Geometry file to use.')
parser.add_argument('-f', '--inputFile', help='Input file to use.')
parser.add_argument('-F', '--inputFile2', help='Input file 2 to use.')
parser.add_argument('-o', '--outputfile', default='muonDISstudy.root')
parser.add_argument('-J', '--JobNum', type=int, help='Number of job.')
parser.add_argument('-M', '--MuonsPerJob', type=int, help='MuonsPerJob.')
parser.add_argument('-nDISPerMuon', '--nDIS', type=int, default=10000, help='Number of DIS per muon to generate')
parser.add_argument('-scriptdir', '--scrdir', help='Script directory')
args = parser.parse_args()
# Open the input file
f = r.TFile.Open(args.inputFile, 'READ')
t1 = f.Get("cbmsim")
if not t1:
print("Error: Tree 'cbmsim' not found in the input file")
return
f2 = open(args.inputFile2)
sigmadata = f2.readlines()
# Open the output file
o = r.TFile.Open(args.outputfile, 'RECREATE')
t2 = t1.CloneTree(0)
# Disable all branches and enable only the necessary ones
t1.SetBranchStatus('*', 0)
branches_to_keep = ['MCTrack', 'Particles']
for branch in branches_to_keep:
t1.SetBranchStatus(branch, 1)
cross_sections_file = open(f'cross-sections_{args.JobNum}.txt', 'w')
nDISperMuon = args.nDIS
muonsPerJob = args.MuonsPerJob
ev = 0
for i in range(t1.GetEntries()):
t1.GetEntry(i)
evMuonNum = int(ev // nDISperMuon)
evLastSimMuonNum = evMuonNum * nDISperMuon + nDISperMuon - 1
TrueEvMuonNum = int(args.JobNum * muonsPerJob + evMuonNum)
cross = float(sigmadata[evLastSimMuonNum])
ev += 1
numRecCandidates = len(t1.Particles)
if numRecCandidates >= 1:
cross_sections_file.write(f'{cross}\n')
t2.Fill()
cross_sections_file.close()
o.cd()
t2.Write()
o.Close()
f.Close()
if __name__ == '__main__':
analysis()
This is the error:
===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0 0x00007f49148d89fa in wait4 () from /lib64/libc.so.6
#1 0x00007f491484b243 in do_system () from /lib64/libc.so.6
#2 0x00007f49142f939c in TUnixSystem::Exec (shellcmd=<optimized out>, this=0x56432d2aa040) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/core/unix/src/TUnixSystem.cxx:2104
#3 TUnixSystem::StackTrace (this=0x56432d2aa040) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/core/unix/src/TUnixSystem.cxx:2395
#4 0x00007f4914a3cee3 in (anonymous namespace)::do_trace (sig=1) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/bindings/pyroot/cppyy/cppyy-backend/clingwrapper/src/clingwrapper.cxx:182
#5 (anonymous namespace)::TExceptionHandlerImp::HandleException (this=<optimized out>, sig=1) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/bindings/pyroot/cppyy/cppyy-backend/clingwrapper/src/clingwrapper.cxx:195
#6 0x00007f49142f6911 in TUnixSystem::DispatchSignals (this=0x56432d2aa040, sig=kSigSegmentationViolation) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/core/unix/src/TUnixSystem.cxx:3610
#7 <signal handler called>
#8 0x00007f49142934cf in std::__atomic_base<TVirtualStreamerInfo*>::load (__m=std::memory_order_seq_cst, this=0x1d8) at /usr/include/c++/11/bits/atomic_base.h:820
#9 std::__atomic_base<TVirtualStreamerInfo*>::operator TVirtualStreamerInfo* (this=0x1d8) at /usr/include/c++/11/bits/atomic_base.h:694
#10 std::atomic<TVirtualStreamerInfo*>::operator TVirtualStreamerInfo* (this=0x1d8) at /usr/include/c++/11/atomic:433
#11 TClass::GetStreamerInfo (this=0x0, version=version
entry=0, isTransient=isTransient
entry=false) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/core/meta/src/TClass.cxx:4587
#12 0x00007f4912ede374 in TBufferIO::ForceWriteInfoClones (this=0x56433cc91120, a=<optimized out>) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/io/io/src/TBufferIO.cxx:343
#13 0x00007f491424961c in TClonesArray::Streamer (this=0x564333d73670, b=...) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/core/cont/src/TClonesArray.cxx:857
#14 0x00007f48f9c58844 in TBranch::FillLeavesImpl (this=0x564333d9db30, b=...) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/tree/tree/src/TBranch.cxx:2438
#15 0x00007f48f9c5eb7e in TBranch::FillImpl (imtHelper=0x0, this=0x564333d9db30) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/tree/tree/src/TBranch.cxx:893
#16 TBranch::FillImpl (this=0x564333d9db30, imtHelper=0x0) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/tree/tree/src/TBranch.cxx:856
#17 0x00007f48f9cd8f48 in TTree::Fill (this=<optimized out>) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/tree/tree/src/TTree.cxx:4630
#18 0x00007f490b1f8024 in ?? ()
#19 0x0000000000000000 in ?? ()
===========================================================
The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum https://root.cern/forum
Only if you are really convinced it is a bug in ROOT then please submit a
report at https://root.cern/bugs Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#8 0x00007f49142934cf in std::__atomic_base<TVirtualStreamerInfo*>::load (__m=std::memory_order_seq_cst, this=0x1d8) at /usr/include/c++/11/bits/atomic_base.h:820
#9 std::__atomic_base<TVirtualStreamerInfo*>::operator TVirtualStreamerInfo* (this=0x1d8) at /usr/include/c++/11/bits/atomic_base.h:694
#10 std::atomic<TVirtualStreamerInfo*>::operator TVirtualStreamerInfo* (this=0x1d8) at /usr/include/c++/11/atomic:433
#11 TClass::GetStreamerInfo (this=0x0, version=version
entry=0, isTransient=isTransient
entry=false) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/core/meta/src/TClass.cxx:4587
#12 0x00007f4912ede374 in TBufferIO::ForceWriteInfoClones (this=0x56433cc91120, a=<optimized out>) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/io/io/src/TBufferIO.cxx:343
#13 0x00007f491424961c in TClonesArray::Streamer (this=0x564333d73670, b=...) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/core/cont/src/TClonesArray.cxx:857
#14 0x00007f48f9c58844 in TBranch::FillLeavesImpl (this=0x564333d9db30, b=...) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/tree/tree/src/TBranch.cxx:2438
#15 0x00007f48f9c5eb7e in TBranch::FillImpl (imtHelper=0x0, this=0x564333d9db30) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/tree/tree/src/TBranch.cxx:893
#16 TBranch::FillImpl (this=0x564333d9db30, imtHelper=0x0) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/tree/tree/src/TBranch.cxx:856
#17 0x00007f48f9cd8f48 in TTree::Fill (this=<optimized out>) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/tree/tree/src/TTree.cxx:4630
#18 0x00007f490b1f8024 in ?? ()
#19 0x0000000000000000 in ?? ()
===========================================================
*** Break *** segmentation violation
===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0 0x00007f49148d89fa in wait4 () from /lib64/libc.so.6
#1 0x00007f491484b243 in do_system () from /lib64/libc.so.6
#2 0x00007f49142f939c in TUnixSystem::Exec (shellcmd=<optimized out>, this=0x56432d2aa040) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/core/unix/src/TUnixSystem.cxx:2104
#3 TUnixSystem::StackTrace (this=0x56432d2aa040) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/core/unix/src/TUnixSystem.cxx:2395
#4 0x00007f4914a3cd63 in (anonymous namespace)::do_trace (sig=1) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/bindings/pyroot/cppyy/cppyy-backend/clingwrapper/src/clingwrapper.cxx:182
#5 (anonymous namespace)::TExceptionHandlerImp::HandleException (this=<optimized out>, sig=1) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/bindings/pyroot/cppyy/cppyy-backend/clingwrapper/src/clingwrapper.cxx:201
#6 0x00007f49142f6911 in TUnixSystem::DispatchSignals (this=0x56432d2aa040, sig=kSigSegmentationViolation) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/core/unix/src/TUnixSystem.cxx:3610
#7 <signal handler called>
#8 0x00007f49142934cf in std::__atomic_base<TVirtualStreamerInfo*>::load (__m=std::memory_order_seq_cst, this=0x1d8) at /usr/include/c++/11/bits/atomic_base.h:820
#9 std::__atomic_base<TVirtualStreamerInfo*>::operator TVirtualStreamerInfo* (this=0x1d8) at /usr/include/c++/11/bits/atomic_base.h:694
#10 std::atomic<TVirtualStreamerInfo*>::operator TVirtualStreamerInfo* (this=0x1d8) at /usr/include/c++/11/atomic:433
#11 TClass::GetStreamerInfo (this=0x0, version=version
entry=0, isTransient=isTransient
entry=false) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/core/meta/src/TClass.cxx:4587
#12 0x00007f4912ede374 in TBufferIO::ForceWriteInfoClones (this=0x56433cc91120, a=<optimized out>) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/io/io/src/TBufferIO.cxx:343
#13 0x00007f491424961c in TClonesArray::Streamer (this=0x564333d73670, b=...) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/core/cont/src/TClonesArray.cxx:857
#14 0x00007f48f9c58844 in TBranch::FillLeavesImpl (this=0x564333d9db30, b=...) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/tree/tree/src/TBranch.cxx:2438
#15 0x00007f48f9c5eb7e in TBranch::FillImpl (imtHelper=0x0, this=0x564333d9db30) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/tree/tree/src/TBranch.cxx:893
#16 TBranch::FillImpl (this=0x564333d9db30, imtHelper=0x0) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/tree/tree/src/TBranch.cxx:856
#17 0x00007f48f9cd8f48 in TTree::Fill (this=<optimized out>) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/tree/tree/src/TTree.cxx:4630
#18 0x00007f490b1f8024 in ?? ()
#19 0x0000000000000000 in ?? ()
===========================================================
The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum https://root.cern/forum
Only if you are really convinced it is a bug in ROOT then please submit a
report at https://root.cern/bugs Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#8 0x00007f49142934cf in std::__atomic_base<TVirtualStreamerInfo*>::load (__m=std::memory_order_seq_cst, this=0x1d8) at /usr/include/c++/11/bits/atomic_base.h:820
#9 std::__atomic_base<TVirtualStreamerInfo*>::operator TVirtualStreamerInfo* (this=0x1d8) at /usr/include/c++/11/bits/atomic_base.h:694
#10 std::atomic<TVirtualStreamerInfo*>::operator TVirtualStreamerInfo* (this=0x1d8) at /usr/include/c++/11/atomic:433
#11 TClass::GetStreamerInfo (this=0x0, version=version
entry=0, isTransient=isTransient
entry=false) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/core/meta/src/TClass.cxx:4587
#12 0x00007f4912ede374 in TBufferIO::ForceWriteInfoClones (this=0x56433cc91120, a=<optimized out>) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/io/io/src/TBufferIO.cxx:343
#13 0x00007f491424961c in TClonesArray::Streamer (this=0x564333d73670, b=...) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/core/cont/src/TClonesArray.cxx:857
#14 0x00007f48f9c58844 in TBranch::FillLeavesImpl (this=0x564333d9db30, b=...) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/tree/tree/src/TBranch.cxx:2438
#15 0x00007f48f9c5eb7e in TBranch::FillImpl (imtHelper=0x0, this=0x564333d9db30) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/tree/tree/src/TBranch.cxx:893
#16 TBranch::FillImpl (this=0x564333d9db30, imtHelper=0x0) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/tree/tree/src/TBranch.cxx:856
#17 0x00007f48f9cd8f48 in TTree::Fill (this=<optimized out>) at /cvmfs/ship.cern.ch/24.06/sw/SOURCES/ROOT/v6-26-16/v6-26-16/tree/tree/src/TTree.cxx:4630
#18 0x00007f490b1f8024 in ?? ()
#19 0x0000000000000000 in ?? ()
===========================================================
For the given events, I may access these branches and extract the information from them. Could you please tell me what can be a reason?