root-project / root

The official repository for ROOT: analyzing, storing and visualizing big data, scientifically
https://root.cern
Other
2.68k stars 1.27k forks source link

Pyroot crashes reading TClonesArray in a TTree #16725

Open AlexFinch opened 4 days ago

AlexFinch commented 4 days ago

Check duplicate issues.

Description

A pyroot python program crashes when reading a TFile containing a TTree containing a TClonesArray. It appears to crash the second time it accesses the TClonesArray. This has started happening since moving to ROOT 6.32 on AlmaLinux 9.4. It worked fine with 6.20.04 running on Centos7. The library for accessing the TTree information was created using MakeProject.

Reproducer

This is the python code that crashes

#!/usr/bin/env python3
import os
import ROOT
import argparse

parser = argparse.ArgumentParser(description='Analyse events.')
parser.add_argument("inputfile")
parser.add_argument("-o","--outputfile",default="Output.root",help="Name of output file")
args = parser.parse_args()

READEVENTANALYSISLIBRARY=ROOT.gSystem.Getenv("READEVENTANALYSISLIBRARY");
ROOT.gSystem.Load(READEVENTANALYSISLIBRARY);

globalRecon = ROOT.TChain("ReconDir/Global")
globalRecon.AddFile(args.inputfile)

OutputFile = ROOT.TFile(args.outputfile,"RECREATE","ND280 Analysis")
hTrackMomenta = ROOT.TH1F("TrackMomenta", "Charged Track Momentum", 100, 0, 1000.0)

entries =  globalRecon.GetEntries()
for entry in range(entries):
    print(" entry = "+str(entry))
    ientry = globalRecon.LoadTree(entry)
    if ientry < 0:
        break
    nb = globalRecon.GetEntry(entry)
    if nb<=0:
        continue

    for pid in globalRecon.PIDs :
        if(pid.Charge != 0) :
            print(" charge is "+str(pid.Charge))
        #   hTrackMomenta.Fill(pid.FrontMomentum)
OutputFile.Write()
OutputFile.Close()

The crash traceback suggest this as the line causing the crash:

7 0x00007fe963a68e9a in TBranchElement::ReadLeavesClones(TBuffer&) () from /home/aleph/ajf/t2k/root/lib/libTree.so

8 0x00007fe963a60899 in TBranch::GetEntry(long long, int) () from /home/aleph/ajf/t2k/root/lib/libTree.so

9 0x00007fe963a7326b in TBranchElement::GetEntry(long long, int) () from /home/aleph/ajf/t2k/root/lib/libTree.so

10 0x00007fe963ad7300 in TTree::GetEntry(long long, int) () from /home/aleph/ajf/t2k/root/lib/libTree.so

ROOT version

6.32.00

Installation method

prebuilt binary root_v6.32.00.Linux-almalinux9.4-x86_64-gcc11.4.tar.gz

Operating system

AlmaLinux 9.4

Additional context

No response

pcanal commented 4 days ago

Can you provide the input file that lead to the crash? Alternatively can you rebuild ROOT in debug mode (-DCMAKE_BUILD_TYPE=Debug) and run with valgrind (valgrind --suppressions=$ROOTSYS/etc/valgrind-root.supp --suppressios=$ROOTSYS/etc/valgrind-root-python.supp python ...)

AlexFinch commented 3 days ago

I've put the file here: hep.lancs.ac.uk/~ajf/pyrootCrash/example.root