Error in <TRint::HandleTermInput()>: std::bad_alloc caught: std::bad_alloc


Please read tips for efficient and successful posting and posting code

_ROOT Version: 6.18.04
Platform: x86_64-centos7
_Compiler: gcc8-opt


Hi,
I am trying to chain together a number of files and use CopyTree with some cuts to write out a subset of the events to new file. The heart of the code is as follows:

  for(int imode = 1; imode < nModes; imode++){ // Loop over modes
    cout << "Mode = " << imode << endl;
    for(int jrun = 0; jrun < nRun; jrun++){ // Loop over runs
      cout << "  --> Run = " << jrun << endl;
      theChain = new TChain("",treeNameData[imode]);
      for(int ifile = 0; ifile < nFiles[jrun]; ifile++){// Loop  over files
        cout << "-------------> Chaining files, " << ifile << " " << infile_rs[imode][jrun][ifile] << endl;
        if(imode==1 && jrun==1 && ifile>=6){
          theChain->Add(infile_rs[imode][jrun][ifile]+"/Xibm2LbK3pi/mytree");
        }else{
          theChain->Add(infile_rs[imode][jrun][ifile]+XbStarTuple[imode]);
        }
      }      
      rs = Form("_%d_%d",imode,jrun);
      fn_rs = "/data6/sblusk/rsFile"+rs+".root";
      cout << "Copying Tree, Mode, Run, File: " << imode << " , " << jrun << endl;
      fout = new TFile(fn_rs,"RECREATE");
      ch = (TTree*)theChain->CopyTree("K_PT>2000");
      cout << "Done copying tree" << endl;
      ch->Write();
      fout->Write();
      fout->Close(); 
      delete fout;
    }
  }

When I run it I get this:

-----------> Chaining files, 0 /data2/sblusk/XibStarStar/2020/data/XibStarMinus/Lb2Lc3pi/XibStar2LbK_2011_MD_wMS_rS.wMVA.def.root
-------------> Chaining files, 1 /data2/sblusk/XibStarStar/2020/data/XibStarMinus/Lb2Lc3pi/XibStar2LbK_2011_MU_wMS_rS.wMVA.def.root
-------------> Chaining files, 2 /data2/sblusk/XibStarStar/2020/data/XibStarMinus/Lb2Lc3pi/XibStar2LbK_2012_MD_wMS_rS.wMVA.def.root
-------------> Chaining files, 3 /data2/sblusk/XibStarStar/2020/data/XibStarMinus/Lb2Lc3pi/XibStar2LbK_2012_MU_wMS_rS.wMVA.def.root
Copying Tree, Mode, Run, File: 1 , 0
Done copying tree
  --> Run = 1
-------------> Chaining files, 0 /data2/sblusk/XibStarStar/2020/data/XibStarMinus/Lb2Lc3pi/XibStar2LbK_2016_MD_wMS_rS.wMVA.def.root
-------------> Chaining files, 1 /data2/sblusk/XibStarStar/2020/data/XibStarMinus/Lb2Lc3pi/XibStar2LbK_2016_MU_wMS_rS.wMVA.def.root
-------------> Chaining files, 2 /data2/sblusk/XibStarStar/2020/data/XibStarMinus/Lb2Lc3pi/XibStar2LbK_2017_MD_wMS_rS.wMVA.def.root
-------------> Chaining files, 3 /data2/sblusk/XibStarStar/2020/data/XibStarMinus/Lb2Lc3pi/XibStar2LbK_2017_MU_wMS_rS.wMVA.def.root
-------------> Chaining files, 4 /data2/sblusk/XibStarStar/2020/data/XibStarMinus/Lb2Lc3pi/XibStar2LbK_2018_MD_wMS_rS.wMVA.def.root
-------------> Chaining files, 5 /data2/sblusk/XibStarStar/2020/data/XibStarMinus/Lb2Lc3pi/XibStar2LbK_2018_MU_wMS_rS.wMVA.def.root
-------------> Chaining files, 6 /data2/sblusk/XibStarStar/2020/data/XibStarMinus/2015_XibStarm_tuples_MD_wMS_H.root
-------------> Chaining files, 7 /data2/sblusk/XibStarStar/2020/data/XibStarMinus/2015_XibStarm_tuples_MU_wMS_H.root
Copying Tree, Mode, Run, File: 1 , 1
Error in <TRint::HandleTermInput()>: std::bad_alloc caught: std::bad_alloc

It seems to give this error, which I cannot quite figure out why, as I’m opening an output file to write the new tree. Any help would be appreciated!

Thanks!!!
Steve

I think @pcanal can help.

There is nothing ‘obvious’ wrong with the code. Maybe running with valgrind:

valgrind --suppressions=$ROOTSYS/etc/valgrind-root.supp your_exec your_args

and see if it reports the reason for the failure.

Hi @pcanal ,

I think I fixed this small test code, now I have to go back to the larger code, and see why the copytree is not working. Presumably some memory/pointer issues…

Thanks!
Steve

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