Loading scripts

Hi,

when i try to run this script multiple times from ROOT (not closing the session and reloading it again) i have segfaults.
this doesn’t happen the first time, only the next ones
i’m using ROOT 3.10 :frowning: alas i can’t change it, i have to work with this version)
but at home i have ROOT5 and all works nice.

[code]#include <TFile.h>
#include <TObjArray.h>
#include <TGraph.h>
#include <TObject.h>
#include <TCint.h>
#include <TColor.h>
#include <TGraphErrors.h>
#include <TMultiGraph.h>
#include <TMarker.h>
#include <TTree.h>
#include <TBranch.h>
#include <TFolder.h>
#include <TString.h>
#include <TH1.h>
#include <TLegend.h>
#include <THStack.h>
#include <TCanvas.h>
#include
#include
#include
#include

using namespace std;
int main(){

string titlefile =“mu10GeVtheta30RanPhi”;

const char *titlefile2 =strcat(“mu10GeVtheta30RanPhi”,“Sov.root”);
TFile *myfile =TFile::Open(titlefile2);

TCanvas *c1 =new TCanvas();
c1->SetGridx();
c1->SetGridy();
pmts->Draw(“nostack”);
pmts->SetTitle(titlefile.c_str());

TLegend *leg =new TLegend(0.80,0.55,0.99,0.80,“0”,“brNDC”);
leg->SetHeader(“PMTs”);
leg->AddEntry(pmt1,“pmt1”,“l”);
leg->AddEntry(pmt2,“pmt2”,“l”);
leg->AddEntry(pmt3,“pmt3”,“l”);
leg->AddEntry(tot,“Tot of the 3 pmts”,“l”);
leg->Draw();

TAxis *xaxis =pmts->GetXaxis();
xaxis->SetTitle(“nPE”);
TAxis *yaxis =pmts->GetYaxis();
yaxis->SetTitle(“Freq”);

c1->Modified();
c1->Print(“mu10GeVtheta30RanPhiFin.eps”);
delete c1;
delete myfile;
gROOT->Reset(“a”);
return 0;
}
[/code]

there is a way to reload this script under ROOT 3.10 withouth getting segfaults? i thought deleting the myfile object and calling Reset() was equivalent to restart the ROOT session

Thank you
Amir

Do not use gROOT->Reset from within a function!
Do not call the function within script “main”. Use some other name.

If it still crashes, use valgrind and/or send us a stack trace.

Cheers,
Philippe.

thank you pcanal.

sadly it still crashes :frowning:

[code]using namespace std;
void run(){

string titlefile =“el30MeVtheta0phi0”;

const char *titlefile2 =strcat(“el30MeVtheta0phi0”,“Sov.root”);
TFile *myfile =TFile::Open(titlefile2);

TCanvas *c1 =new TCanvas();
c1->SetGridx();
c1->SetGridy();
pmts->Draw(“nostack”);
pmts->SetTitle(titlefile.c_str());

TLegend *leg =new TLegend(0.80,0.55,0.99,0.80,“0”,“brNDC”);
leg->SetHeader(“PMTs”);
leg->AddEntry(pmt1,“pmt1”,“l”);
leg->AddEntry(pmt2,“pmt2”,“l”);
leg->AddEntry(pmt3,“pmt3”,“l”);
leg->AddEntry(tot,“Tot of the 3 pmts”,“l”);
leg->Draw();

TAxis *xaxis =pmts->GetXaxis();
xaxis->SetTitle(“nPE”);
TAxis *yaxis =pmts->GetYaxis();
yaxis->SetTitle(“Freq”);

c1->Modified();
c1->Print(“el30MeVtheta0phi0Fin.eps”);
delete c1;
delete myfile;

}
[/code]

when i try to reload it, it produces the stack trace:

[code]root [2] .L drawing.cc
reloading /mnt/scratch/AugerOffline/Auger/elettrone/grafici/./drawing.cc 0

*** Break *** segmentation violation
Generating stack trace…
0x4061ac84 in G__TypeInfo::TrueName() + 0x2a from /mnt/scratch/AugerOffline/Offline/External/ROOT/3.10.02/lib/libCint.so.3.10
0x4016b008 in TDataType::GetTypeName() const + 0x38 from /mnt/scratch/AugerOffline/Offline/External/ROOT/3.10.02/lib/libCore.so.3.10
0x401218f3 in TROOT::GetClass(char const*, bool) const + 0xa1 from /mnt/scratch/AugerOffline/Offline/External/ROOT/3.10.02/lib/libCore.so.3.10
0x4012303b in TROOT::IgnoreInclude(char const*, char const*) + 0xb1 from /mnt/scratch/AugerOffline/Offline/External/ROOT/3.10.02/lib/libCore.so.3.10
0x4015ca9a in IgnoreInclude + 0x26 from /mnt/scratch/AugerOffline/Offline/External/ROOT/3.10.02/lib/libCore.so.3.10
0x405a4d2a in G__loadfile + 0xd6f from /mnt/scratch/AugerOffline/Offline/External/ROOT/3.10.02/lib/libCint.so.3.10
0x405a2d35 in G__include_file + 0x237 from /mnt/scratch/AugerOffline/Offline/External/ROOT/3.10.02/lib/libCint.so.3.10
0x405c4569 in G__exec_statement + 0x1713 from /mnt/scratch/AugerOffline/Offline/External/ROOT/3.10.02/lib/libCint.so.3.10
0x405a5450 in G__loadfile + 0x1495 from /mnt/scratch/AugerOffline/Offline/External/ROOT/3.10.02/lib/libCint.so.3.10
0x405c74b7 in G__reloadfile + 0x2e4 from /mnt/scratch/AugerOffline/Offline/External/ROOT/3.10.02/lib/libCint.so.3.10
0x405cabe6 in G__process_cmd + 0x2231 from /mnt/scratch/AugerOffline/Offline/External/ROOT/3.10.02/lib/libCint.so.3.10
0x4015d417 in TCint::ProcessLine(char const*, TInterpreter::EErrorCode*) + 0x9b from /mnt/scratch/AugerOffline/Offline/External/ROOT/3.10.02/lib/libCore.so.3.10
0x400e3a7b in TApplication::ProcessLine(char const*, bool, int*) + 0x421 from /mnt/scratch/AugerOffline/Offline/External/ROOT/3.10.02/lib/libCore.so.3.10
0x40d3feae in TRint::HandleTermInput() + 0x1b2 from /mnt/scratch/AugerOffline/Offline/External/ROOT/3.10.02/lib/libRint.so.3.10
0x40d3ede0 in TTermInputHandler::Notify() + 0x24 from /mnt/scratch/AugerOffline/Offline/External/ROOT/3.10.02/lib/libRint.so.3.10
0x40d406f4 in TTermInputHandler::ReadNotify() + 0x12 from /mnt/scratch/AugerOffline/Offline/External/ROOT/3.10.02/lib/libRint.so.3.10
0x401bd1cb in TUnixSystem::CheckDescriptors() + 0xed from /mnt/scratch/AugerOffline/Offline/External/ROOT/3.10.02/lib/libCore.so.3.10
0x401bc9a0 in TUnixSystem::DispatchOneEvent(bool) + 0x10a from /mnt/scratch/AugerOffline/Offline/External/ROOT/3.10.02/lib/libCore.so.3.10
0x4013023d in TSystem::InnerLoop() + 0x1b from /mnt/scratch/AugerOffline/Offline/External/ROOT/3.10.02/lib/libCore.so.3.10
0x401301d6 in TSystem::Run() + 0x78 from /mnt/scratch/AugerOffline/Offline/External/ROOT/3.10.02/lib/libCore.so.3.10
0x400e461f in TApplication::Run(bool) + 0x2d from /mnt/scratch/AugerOffline/Offline/External/ROOT/3.10.02/lib/libCore.so.3.10
0x40d3f9da in TRint::Run(bool) + 0x2e4 from /mnt/scratch/AugerOffline/Offline/External/ROOT/3.10.02/lib/libRint.so.3.10
0x08048889 in main + 0x71 from /mnt/scratch/AugerOffline/Offline/External/ROOT/3.10.02/bin/root.exe
0x42015704 in __libc_start_main + 0xe4 from /lib/tls/libc.so.6
0x08048789 in _Unwind_Resume + 0x31 from /mnt/scratch/AugerOffline/Offline/External/ROOT/3.10.02/bin/root.exe
Root > [/code]

i’ll install Valgrind on monday…for now there is only the stack trace

Hi,
you misuse strcat. Check its syntax definition, esp its first argument. Maybe that will fix it.
Axel.

thank you Axel.

i fixed the code but the problem still remained.
So i’ve installed ROOT 5 at home, copied all the root files, done the job and copied the results back in place.

Not clean, but effective :slight_smile:

Thank you to you all