SetHighlightConnect() get segfault

Dear experts

When I try to SetHighLightConnect() to another function I got segfault, please give me some suggestions, thank you in advance! (slot function for the connection is empty)

std::map<int, TH1D*> map_driftTime;
TCanvas* c_pos;
TGraph* g_pos;
void DocaHighlighted(TVirtualPad* pad, TObject* obj, Int_t ihp, Int_t y){}

void checkDriftTime(std::string fileName){
    TCanvas* c_doca = new TCanvas();
    c_doca->SetTitle("Doca distribution");
    c_doca->HighlightConnect("DocaHighlighted(TVirtualPad* pad, TObject* obj, Int_t ihp, Int_t y)");
    TH1D* h_doca = new TH1D("h_doca", "doca distribution", 75, 0., 1.5);
    TGraph* g_doca = new TGraph();
    g_pos = new TGraph();

    std::vector<double>* x0 = nullptr;
    std::vector<double>* y0 = nullptr;
    std::vector<double>* t1 = nullptr;
    TFile* f = new TFile(fileName.c_str(), "READ");
    if(!f){
        std::cerr<<"Can not find input file"<<std::endl;
        exit(1);
    }
    TTree* t = (TTree*)f->Get("t");
    t->SetBranchAddress("x0", &x0);
    t->SetBranchAddress("y0", &y0);
    t->SetBranchAddress("t1", &t1);

    for(int iEvent = 0; iEvent < t->GetEntries(); ++iEvent){
        t->GetEntry(iEvent);
        if(x0->size() > 0){
            double x = x0->at(0);
            double y = y0->at(0);
            TH1D* h = new TH1D(Form("h_%.2f_%.2f", x, y), Form("drift time distribution at (%.2f, %.2f)", x, y), 3000, 0, 3000);
            for(auto itr = t1->begin(); itr != t1->end(); ++itr){
                h_doca->Fill(sqrt(x*x + y*y));
                h->Fill(*itr);
            }
            g_pos->SetPoint(iEvent, x, y);
            map_driftTime[iEvent] = h;
        }
    }

    for(int iBin = 1; iBin < h_doca->GetNbinsX(); ++iBin){
        g_doca->AddPoint(h_doca->GetBinCenter(iBin), h_doca->GetBinContent(iBin));
    }

    g_doca->SetHighlight();
    g_doca->SetMarkerStyle(29);
    g_doca->SetMarkerColor(2);
    g_doca->Draw("AP");
}

error message:

 *** Break *** segmentation violation
[/usr/lib/system/libsystem_platform.dylib] _sigtramp (no debug info)
[/Users/siyuan/Physics/root/install/lib/libCore.so] TQConnection::SetArg(long const*, int) (no debug info)
[/Users/siyuan/Physics/root/install/lib/libGpad.so] void TQObject::EmitVA<long [4]>(char const*, int, long const (&) [4]) (no debug info)
[/Users/siyuan/Physics/root/install/lib/libGpad.so] TCanvas::Highlighted(TVirtualPad*, TObject*, int, int) (no debug info)
[/Users/siyuan/Physics/root/install/lib/libHistPainter.so] TGraphPainter::HighlightPoint(TGraph*, int, int) (no debug info)
[/Users/siyuan/Physics/root/install/lib/libHistPainter.so] TGraphPainter::DistancetoPrimitiveHelper(TGraph*, int, int) (no debug info)
[/Users/siyuan/Physics/root/install/lib/libGpad.so] TPad::Pick(int, int, TObjLink*&) (no debug info)
[/Users/siyuan/Physics/root/install/lib/libGpad.so] TCanvas::Pick(int, int, TObject*) (no debug info)
[/Users/siyuan/Physics/root/install/lib/libGpad.so] TCanvas::HandleInput(EEventType, int, int) (no debug info)
[/Users/siyuan/Physics/root/install/lib/libGui.so] TRootContainer::HandleMotion(Event_t*) (no debug info)
[/Users/siyuan/Physics/root/install/lib/libGui.so] TGFrame::HandleEvent(Event_t*) (no debug info)
[/Users/siyuan/Physics/root/install/lib/libGui.so] TGClient::HandleEvent(Event_t*) (no debug info)
[/Users/siyuan/Physics/root/install/lib/libGui.so] TGClient::ProcessOneEvent() (no debug info)
[/Users/siyuan/Physics/root/install/lib/libGui.so] TGInputHandler::Notify() (no debug info)
[/Users/siyuan/Physics/root/install/lib/libCore.so] TMacOSXSystem::DispatchOneEvent(bool) (no debug info)
[/Users/siyuan/Physics/root/install/lib/libCore.so] TSystem::InnerLoop() (no debug info)
[/Users/siyuan/Physics/root/install/lib/libCore.so] TSystem::Run() (no debug info)
[/Users/siyuan/Physics/root/install/lib/libCore.so] TApplication::Run(bool) (no debug info)
[/Users/siyuan/Physics/root/install/lib/libRint.so] TRint::Run(bool) (no debug info)
[/Users/siyuan/Physics/root/install/bin/root.exe] main (no debug info)
[/usr/lib/dyld] start (no debug info)
Root > .q

 *** Break *** segmentation violation
[/usr/lib/system/libsystem_platform.dylib] _sigtramp (no debug info)
[/Users/siyuan/Physics/root/install/lib/libCore.so] TList::FindObject(TObject const*) const (no debug info)
[/Users/siyuan/Physics/root/install/lib/libCore.so] THashTable::FindObject(TObject const*) const (no debug info)
[/Users/siyuan/Physics/root/install/lib/libCore.so] THashList::RecursiveRemove(TObject*) (no debug info)
[/Users/siyuan/Physics/root/install/lib/libCore.so] TROOT::RecursiveRemove(TObject*) (no debug info)
[/Users/siyuan/Physics/root/install/lib/libCore.so] TNamed::~TNamed() (no debug info)
[/Users/siyuan/Physics/root/install/lib/libHist.so] TH1D::~TH1D() (no debug info)
[/Users/siyuan/Physics/root/install/lib/libCore.so] THashList::Delete(char const*) (no debug info)
[/Users/siyuan/Physics/root/install/lib/libCore.so] TROOT::EndOfProcessCleanups() (no debug info)
[/Users/siyuan/Physics/root/install/lib/libCore.so] TUnixSystem::Exit(int, bool) (no debug info)
[/Users/siyuan/Physics/root/install/lib/libCore.so] TApplication::Terminate(int) (no debug info)
[/Users/siyuan/Physics/root/install/lib/libCore.so] TApplication::ProcessLine(char const*, bool, int*) (no debug info)
[/Users/siyuan/Physics/root/install/lib/libRint.so] TRint::ProcessLineNr(char const*, char const*, int*) (no debug info)
[/Users/siyuan/Physics/root/install/lib/libRint.so] TRint::HandleTermInput() (no debug info)
[/Users/siyuan/Physics/root/install/lib/libCore.so] TUnixSystem::CheckDescriptors() (no debug info)
[/Users/siyuan/Physics/root/install/lib/libCore.so] TMacOSXSystem::DispatchOneEvent(bool) (no debug info)
[/Users/siyuan/Physics/root/install/lib/libCore.so] TSystem::InnerLoop() (no debug info)

Can you provide a reproducer we can run?

Here is a simple reproducer
test.cxx (1.3 KB)

Thanks, try with this syntax:

    c_doca->HighlightConnect("DocaHighlighted(TVirtualPad*,TObject*,Int_t,Int_t)");

Thank you! This fixed the problem.

I got another question, can I connect the slot function to another slot function with another signal? I tried to do it but failed doing it…in the reproducer below the 3rd canvas is not created, why?
test.cxx (1.8 KB)

In your code:

    c_pos = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("c_pos");
    if (!c_pos) {
        c_pos = new TCanvas("c_pos", "start position", 200, 0, 600, 400);
        c_pos->HighlightConnect("PosHighlighted(TVirtualPad*, TObject*, Int_t, Int_t)");
    }

gROOT->GetListOfCanvases()->FindObject("c_pos"); finds the canvas, hence c_pos->HighlightConnect("PosHighlighted(TVirtualPad*, TObject*, Int_t, Int_t)"); is never called. If you move it outside the if statement, it works:

    c_pos = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("c_pos");
    if (!c_pos) {
        c_pos = new TCanvas("c_pos", "start position", 200, 0, 600, 400);
    }
    c_pos->HighlightConnect("PosHighlighted(TVirtualPad*, TObject*, Int_t, Int_t)");

(and then it crashes because of map_driftTime.at(ihp)->Draw();)

Thank you that fixed the problem! But I thought I only need to set the connection when I instantiate the TCanvas, why I need to set connection even the TCanvas already exists?

You create the canvas in the test() function, so you can also keep the c_pos->HighlightConnect("PosHighlighted(TVirtualPad*, TObject*, Int_t, Int_t)"); function right after its creation, at both places.

Ah, I understood why it didn’t work, I created the canvas in the test() so the SetHighlightConnect will never be called as you said, that’s why I need to move it out of if. And if I connect the canvas in the test() then I can move it in the if, thanks a lot!

1 Like

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