[Resolved/Report] Bug / Lack of warning with crash for multiple TCutG object having the same name

_ROOT Version: 6.30/07
Platform: Ubuntu 22
Compiler: CLing

Dear all,

I recently had segmentation violation from root interpreter when using TCutG::IsInside.
Several TCutG object were loaded in a class and stored in a std::map, and TCutG::IsInside was called in a function of that class using a macro.

I noticed that the crash happen after calling different TCutG, though they all have different pointer address.
After several tests, putting a different name to every TCutG solved the issue. I can understand that having a single name for different object may be an issue according to how ROOT works, I was however surprised that no warning were printed in the terminal. Would that be possible to add one?

Here I present a minimal code reproducing the crash. The commented line in Ana.cc are the ones that remove the crashes:

mac.C

#include <cstdlib>
#include "Ana.h"


void Mac(void)
{
    Ana ana;

    ana.CutNuclei(20, 1, 0.17);
    ana.CutNuclei(21, 0, 0.17);
    ana.CutNuclei(22, 0, 56);
    ana.CutNuclei(19, 5000, 21);
}

Ana.h

#ifndef ANA_H_
#define ANA_H_

#include <cstdlib>
#include <map>

#include "TCutG.h"
#include "TString.h"

class Ana
{
        public:
                bool IsS47;
                bool IsS53;

                Ana();
                ~Ana() {};

                bool CutNuclei(int ID, double T, double Q);

        private:
                void Init(void);
                void LoadCut(void);
                std::map<int, TCutG*> fHodoCut;
};

#endif // ANA_H_

Ana.cc

#include "Ana.h"


#include <iostream>

Ana::Ana()
{
    Init();
}

void Ana::Init(void)
{
    LoadCut();
}

bool Ana::CutNuclei(int ID, double T, double Q)
{
        auto cut = fHodoCut[ID];
        if(cut == nullptr || cut == 0) return false;

        std::clog << cut << std::endl;
        if(cut->IsInside(T, Q))
        {
            return true;
        }
    return false;
}

void Ana::LoadCut(void)
{
    //TCutG *ID19 = new TCutG("CUTG0", 15);
    TCutG *ID19 = new TCutG("CUTG", 15);
    ID19->SetTitle("Graph");
    ID19->SetPoint(0 ,4938.91, 24.2989);
    ID19->SetPoint(1 ,4938.22, 22.8966);
    ID19->SetPoint(2 ,4947.84, 21.6947);
    ID19->SetPoint(3 ,4968.47, 20.9435);
    ID19->SetPoint(4 ,5003.53, 20.8433);
    ID19->SetPoint(5 ,5027.6 , 21.3442);
    ID19->SetPoint(6 ,5056.47, 22.0453);
    ID19->SetPoint(7 ,5077.1 , 22.3458);
    ID19->SetPoint(8 ,5069.54, 23.5477);
    ID19->SetPoint(9 ,5042.04, 24.399 );
    ID19->SetPoint(10,4993.22, 25.2504);
    ID19->SetPoint(11,4969.16, 25.7512);
    ID19->SetPoint(12,4949.22, 25.4006);
    ID19->SetPoint(13,4944.41, 24.8998);
    ID19->SetPoint(14,4938.91, 24.2989);

    //TCutG *ID20 = new TCutG("CUTG1", 14);
    TCutG *ID20 = new TCutG("CUTG", 14);
    ID20->SetTitle("Graph");
    ID20->SetPoint(0 ,4945.05, 24.9499);
    ID20->SetPoint(1 ,4940.78, 23.6979);
    ID20->SetPoint(2 ,4945.77, 22.4459);
    ID20->SetPoint(3 ,4959.3 , 21.3442);
    ID20->SetPoint(4 ,4977.82, 21.3942);
    ID20->SetPoint(5 ,5012.01, 21.845 );
    ID20->SetPoint(6 ,5040.5 , 22.3958);
    ID20->SetPoint(7 ,5051.9 , 22.7965);
    ID20->SetPoint(8 ,5048.34, 23.8482);
    ID20->SetPoint(9 ,5032.67, 24.4491);
    ID20->SetPoint(10,4991.35, 25.1002);
    ID20->SetPoint(11,4969.98, 25.5008);
    ID20->SetPoint(12,4951.47, 25.2504);
    ID20->SetPoint(13,4945.05, 24.9499);

    //TCutG *ID21 = new TCutG("CUTG2", 14);
    TCutG *ID21 = new TCutG("CUTG", 14);
    ID21->SetTitle("Graph");
    ID21->SetPoint(0 ,5020.16, 25.1002);
    ID21->SetPoint(1 ,5013.1 , 23.6979);
    ID21->SetPoint(2 ,5015.92, 22.3958);
    ID21->SetPoint(3 ,5027.94, 21.3442);
    ID21->SetPoint(4 ,5049.84, 21.3942);
    ID21->SetPoint(5 ,5089.41, 21.895 );
    ID21->SetPoint(6 ,5107.78, 22.1454);
    ID21->SetPoint(7 ,5124.03, 22.5461);
    ID21->SetPoint(8 ,5123.32, 23.5978);
    ID21->SetPoint(9 ,5074.57, 25     );
    ID21->SetPoint(10,5051.25, 25.5008);
    ID21->SetPoint(11,5034.3 , 25.7512);
    ID21->SetPoint(12,5025.82, 25.4507);
    ID21->SetPoint(13,5020.16, 25.1002);

    //TCutG *ID22 = new TCutG("CUTG3", 12);
    TCutG *ID22 = new TCutG("CUTG", 12);
    ID22->SetTitle("Graph");
    ID22->SetPoint(0 ,5060.38, 26.853 );
    ID22->SetPoint(1 ,5057.82, 25.3005);
    ID22->SetPoint(2 ,5066.02, 24.399 );
    ID22->SetPoint(3 ,5079.34, 23.6478);
    ID22->SetPoint(4 ,5107.51, 23.8982);
    ID22->SetPoint(5 ,5132.62, 24.1987);
    ID22->SetPoint(6 ,5140.82, 25.2003);
    ID22->SetPoint(7 ,5134.16, 26.2019);
    ID22->SetPoint(8 ,5111.61, 26.7528);
    ID22->SetPoint(9 ,5088.05, 27.3037);
    ID22->SetPoint(10,5071.14, 27.1534);
    ID22->SetPoint(11,5060.38, 26.853 );

    fHodoCut[22] = ID22;
    fHodoCut[21] = ID21;
    fHodoCut[20] = ID20;
    fHodoCut[19] = ID19;

}

Welcome to the ROOT forum.

Thanks for your post. I’ll check

I see the seg-fault too. I am looking

IsInside is not the faulty function. Any TCutG function will produce the crash. I just tried with GetTitle. In your code, it you replace Inside by GeTitle you will get the exact same behavior.

ROOT does not allow several cuts with the same name. If you look at the code you will see that if a cut with the same name exist it will be deleted:

   delete gROOT->GetListOfSpecials()->FindObject(name);
   gROOT->GetListOfSpecials()->Add(this);

Dear Couet,

Thank you for looking into the code, this confirm my guess.
Would it be possible to add a warning similar to what we have for TH1 or other objects?
For example as in the function TDirectory::Append on line 206 of TDirectory.cxx

PR here: [graf] Warn user about automatic overwrite of TCutG if same name by ferdymercury · Pull Request #17553 · root-project/root · GitHub

1 Like

@ferhue I approved your PR.

1 Like

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