Segmentation violation while making TMultiGraph?

Hello-

I’m having an issue running my code, I’ll post it here (data file and a copy of this will be in a link at the end so anyone who wants can try on their own):

#define making_multigraphs_C

#include <TGraph.h>
#include <TH1F.h>
#include <TCanvas.h>
#include <TFile.h>

void making_multigraphs(){

        TFile file_in("./calibration_multigraph_analysis_results_20210803144152.root");

        TMultiGraph *mg_gain[100][3];

        for(int i=1; i<98; i++){

                if(i==2 || i==12 || i==18 || i==20) continue;//skip nonexistent FEBs

                for(int j=2; j<12; j++){

                        string gr_nme = "gr_mac5_" + to_string(i) + "_ch_" + to_string(j);
    
                        TGraph *gr =(TGraph*)file_in.FindObjectAny(gr_nme.c_str());

                        mg_gain[i][0]->Add(gr);
                }

                mg_gain[i][0]->Draw();

        }//end loop over mac5's

}

When I run the above code, I get the following segmentation violation:

root [2] .x making_multigraphs.C 

 *** Break *** segmentation violation



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00007f6257ceadba in __GI___wait4 (pid=72406, stat_loc=stat_loc
entry=0x7fffab5beb18, options=options
entry=0, usage=usage
entry=0x0) at ../sysdeps/unix/sysv/linux/wait4.c:27
#1  0x00007f6257cead7b in __GI___waitpid (pid=<optimized out>, stat_loc=stat_loc
entry=0x7fffab5beb18, options=options
entry=0) at waitpid.c:38
#2  0x00007f6257c5a0e7 in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:172
#3  0x00007f62583747e3 in TUnixSystem::Exec (shellcmd=<optimized out>, this=0x5605c4ec8bc0) at /usr/root_build_directory/root-6.18.00/core/unix/src/TUnixSystem.cxx:2106
#4  TUnixSystem::StackTrace (this=0x5605c4ec8bc0) at /usr/root_build_directory/root-6.18.00/core/unix/src/TUnixSystem.cxx:2400
#5  0x00007f62583771d4 in TUnixSystem::DispatchSignals (this=0x5605c4ec8bc0, sig=kSigSegmentationViolation) at /usr/root_build_directory/root-6.18.00/core/unix/src/TUnixSystem.cxx:3631
#6  <signal handler called>
#7  0x00007f624d8b92a5 in ?? ()
#8  0x00007fff00000000 in ?? ()
#9  0x00007fffab5c1b40 in ?? ()
#10 0x00007fffab5c1a00 in ?? ()
#11 0x00007f6254b6a656 in std::_Rb_tree_node<std::pair<llvm::object::SectionRef const, unsigned int> >* std::_Rb_tree<llvm::object::SectionRef, std::pair<llvm::object::SectionRef const, unsigned int>, std::_Select1st<std::pair<llvm::object::SectionRef const, unsigned int> >, std::less<llvm::object::SectionRef>, std::allocator<std::pair<llvm::object::SectionRef const, unsigned int> > >::_M_copy<std::_Rb_tree<llvm::object::SectionRef, std::pair<llvm::object::SectionRef const, unsigned int>, std::_Select1st<std::pair<llvm::object::SectionRef const, unsigned int> >, std::less<llvm::object::SectionRef>, std::allocator<std::pair<llvm::object::SectionRef const, unsigned int> > >::_Alloc_node>(std::_Rb_tree_node<std::pair<llvm::object::SectionRef const, unsigned int> > const*, std::_Rb_tree_node_base*, std::_Rb_tree<llvm::object::SectionRef, std::pair<llvm::object::SectionRef const, unsigned int>, std::_Select1st<std::pair<llvm::object::SectionRef const, unsigned int> >, std::less<llvm::object::SectionRef>, std::allocator<std::pair<llvm::object::SectionRef const, unsigned int> > >::_Alloc_node&) () from /usr/root_build_directory/root-6.18.00/obj/lib/libCling.so
#12 0x00005605c73e1170 in ?? ()
#13 0x00007f625755f890 in ?? () at /usr/root_build_directory/root-6.18.00/io/io/src/TDirectoryFile.cxx:1174 from /usr/root_build_directory/root-6.18.00/obj/lib/libRIO.so
#14 0x00007f6257f555c0 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#15 0x00007fffab5c2230 in ?? ()
#16 0x00007f62575799b0 in ?? () at /usr/root_build_directory/root-6.18.00/obj/include/TVirtualMutex.h:86 from /usr/root_build_directory/root-6.18.00/obj/lib/libRIO.so
#17 0x00005605c73e1170 in ?? ()
#18 0x00007fffab5c1828 in ?? ()
#19 0x0000000000000001 in ?? ()
#20 0x00007f6257d60032 in __GI_svc_run () at svc_run.c:83
#21 0x5f3563616d5f7200 in ?? ()
#22 0x00007f6257c00031 in ?? () from /lib/x86_64-linux-gnu/libdl.so.2
#23 0x00007fffab5c1878 in ?? ()
#24 0x0000000000000000 in ?? ()
===========================================================


The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum http://root.cern.ch/forum
Only if you are really convinced it is a bug in ROOT then please submit a
report at http://root.cern.ch/bugs Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#7  0x00007f624d8b92a5 in ?? ()
#8  0x00007fff00000000 in ?? ()
#9  0x00007fffab5c1b40 in ?? ()
#10 0x00007fffab5c1a00 in ?? ()
#11 0x00007f6254b6a656 in std::_Rb_tree_node<std::pair<llvm::object::SectionRef const, unsigned int> >* std::_Rb_tree<llvm::object::SectionRef, std::pair<llvm::object::SectionRef const, unsigned int>, std::_Select1st<std::pair<llvm::object::SectionRef const, unsigned int> >, std::less<llvm::object::SectionRef>, std::allocator<std::pair<llvm::object::SectionRef const, unsigned int> > >::_M_copy<std::_Rb_tree<llvm::object::SectionRef, std::pair<llvm::object::SectionRef const, unsigned int>, std::_Select1st<std::pair<llvm::object::SectionRef const, unsigned int> >, std::less<llvm::object::SectionRef>, std::allocator<std::pair<llvm::object::SectionRef const, unsigned int> > >::_Alloc_node>(std::_Rb_tree_node<std::pair<llvm::object::SectionRef const, unsigned int> > const*, std::_Rb_tree_node_base*, std::_Rb_tree<llvm::object::SectionRef, std::pair<llvm::object::SectionRef const, unsigned int>, std::_Select1st<std::pair<llvm::object::SectionRef const, unsigned int> >, std::less<llvm::object::SectionRef>, std::allocator<std::pair<llvm::object::SectionRef const, unsigned int> > >::_Alloc_node&) () from /usr/root_build_directory/root-6.18.00/obj/lib/libCling.so
#12 0x00005605c73e1170 in ?? ()
#13 0x00007f625755f890 in ?? () at /usr/root_build_directory/root-6.18.00/io/io/src/TDirectoryFile.cxx:1174 from /usr/root_build_directory/root-6.18.00/obj/lib/libRIO.so
#14 0x00007f6257f555c0 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#15 0x00007fffab5c2230 in ?? ()
#16 0x00007f62575799b0 in ?? () at /usr/root_build_directory/root-6.18.00/obj/include/TVirtualMutex.h:86 from /usr/root_build_directory/root-6.18.00/obj/lib/libRIO.so
#17 0x00005605c73e1170 in ?? ()
#18 0x00007fffab5c1828 in ?? ()
#19 0x0000000000000001 in ?? ()
#20 0x00007f6257d60032 in __GI_svc_run () at svc_run.c:83
#21 0x5f3563616d5f7200 in ?? ()
#22 0x00007f6257c00031 in ?? () from /lib/x86_64-linux-gnu/libdl.so.2
#23 0x00007fffab5c1878 in ?? ()
#24 0x0000000000000000 in ?? ()
===========================================================


Root > 

Any idea how what is going on? If you look at the drive link below, you can find the data file and see it has the appropriate TGraphs to source from as I do, I’m not sure why it’s not working. I was initially trying to make these while also making the TGraph file but was getting similar errors, I’m not sure what to do at this point since it doesn’t appear to be a memory issue…

https://drive.google.com/drive/folders/1ldXBbcpb4Xyv_WPD7Ndm6JgnZZ_q3CHx?usp=sharing

ROOT Version: 6.18.00
Platform: Ubuntu 20.04.2
Compiler: Not Provided


You have not created the multigraphs mg_gain[][]. Maybe add something like this just before the loop over j:

    mg_gain[i][0] = new TMultiGraph();

and you also need to draw at least the axes when drawing graphs or multigraphs:

    mg_gain[i][0]->Draw("A");

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.