Crash when running over root files, using a C++ macro

Dear all,

I’m getting a crash when running a C++ code on root ATLAS files that I don’t understand and I would like your help to solve this.
Below I copy paste the message that I get.
I’m using ROOT version 6.14.04.
I also attach the code I’m using in case you want to check inside.
The weird thing is that don’t get the crash all the times, only when I use certain root files. The files are heavy, so I will send them to you only if you need them, let me know.

Thanks so much in advance for your help !
Best,
Narei Lorenzo Martinez

===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0 0x00007f0a8aaea41c in waitpid () from /lib64/libc.so.6
#1 0x00007f0a8aa67f12 in do_system () from /lib64/libc.so.6
#2 0x00007f0a8bbe7ebd in TUnixSystem::StackTrace() () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libCore.so
#3 0x00007f0a8bbea624 in TUnixSystem::DispatchSignals(ESignals) () from /cvmfs/sft.cern.ch/lcg/releases/LCG_94/ROOT/6.14.04/x86_64-slc6-gcc62-opt/lib/libCore.so
#4 <signal handler called>
#5 0x00007f0a8c31bb8f in ?? ()
#6 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.
===========================================================
#5 0x00007f0a8c31bb8f in ?? ()
#6 0x0000000000000000 in ?? ()
===========================================================

ROOT Version: 6.14.04. Built for linuxx8664gcc. From tags/v6-14-04@v6-14-04, Aug 23 2018, 17:00:44
Compiler: gcc (GCC) 6.2.0

Since I’m a new user, it does allow me to attach a file apparently
TemplatesMaker.C (26.8 KB)

Fix problems reported by:
root [0] .L TemplateMaker.C++O

Then run (you will get a better crash report):
root [0] .x TemplateMaker.C++g("someRegion", "someSampleType", ...)

1 Like

Thanks so much for your reply !
So running the first command I just get a warning an histogram may be used uninitialized. I think this is ok.
Running the second command, I get this below, that I don’t understand, can you help me ?
Thanks !
N. LM

sh: -c: ligne0: Caractère de fin de fichier (EOF) prématuré lors de la recherche du « " » correspondant
sh: -c: ligne1: Erreur de syntaxe : fin de fichier prématurée
Error in <ACLiC>: Compilation failed!

You should protect your source code against usage of “uninitialized” variables.

Yes, this is now done, but I still get the crash, with the detailed error I put above.
do you know to which file this is making reference ?
Thanks !
Best,
NLM

In fact I’m not even sure this error makes sense, because running with another file that run properly when I just do:

.L TemplateMaker.C
TemplateMaker(...)

I get the same error:

sh: -c: ligne0: Caractère de fin de fichier (EOF) prématuré lors de la recherche du « " » correspondant
sh: -c: ligne1: Erreur de syntaxe : fin de fichier prématurée
Error in <ACLiC>: Compilation failed!

when running the commands you suggested

I would be grateful for any suggestion here !
Best,
NLM

Hi,
can you post the current version of the script? Seems like there is a starting " without a corresponding closing "?

1 Like

Thanks for having looked at my script !!
Really ? in which line do you see that ?
I attach again the script.

Thanks !
Best,
NLM
TemplatesMaker.C (26.3 KB)

I was just trying to interpret the error message (and probably failed). But actually, loading your script into ROOT this is what I get:

root [0] .L TemplatesMaker.C 
In file included from input_line_11:1:
/home/blue/Downloads/TemplatesMaker.C:636:76: error: use of overloaded operator '+' is ambiguous (with operand types 'basic_string<char,
      std::char_traits<char>, std::allocator<char> >' and 'TString')
  ...outFile="Templates/templZgVBS_"+SampleType+"_"+Region+"_Region"+RegionABCD+"_"...
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
/home/blue/Work/ROOT/dbg/include/TString.h:137:16: note: candidate function
friend TString operator+(const TString &s1, const TString &s2);
               ^
/home/blue/Work/ROOT/dbg/include/TEveUtil.h:117:15: note: candidate function
TEveException operator+(const TEveException &s1, const TString &s2);
              ^
/home/blue/Work/ROOT/dbg/include/TString.h:138:16: note: candidate function
friend TString operator+(const TString &s,  const char *cs);
               ^
/home/blue/Work/ROOT/dbg/include/TEveUtil.h:118:15: note: candidate function
TEveException operator+(const TEveException &s1, const char    *s2);

so there seem to still be some C++ issues.

Cheers,
Enrico

1 Like

Thanks !
How do you manage to get these details ? I don’t get them when compiling.
For the problem you quote, do you know how I could solve this ? Since I don’t get the error when compiling, I cannot make any try.
Thanks again !
NLM

To solve them, make the first string a std::string: std::string("Templates/templZgVBS_").

I am not sure why you don’t get these errors.

Ok I see, I had both string and TString to be added in the final fine name.
I now converted all to TString. I attach the new version, do you still see an error ?
For me there is no error after .L TemplateMaker.C but this still crash after TemplateMaker(...)
TemplatesMaker.C (26.3 KB)

I don’t know if this can help, but trying line by line to track down from where is coming the crash, I see this is coming from the moment I try to get the jet variable values. When I comment the first block below, I don’t get anymore the crash. This corresponds to these lines:

ptj1 = v_jetpt[0]*1e-3;
ptj2 = v_jetpt[1]*1e-3;
etaJet1 = v_jeteta[0];
etaJet2 = v_jeteta[1];
phiJet1 = v_jetphi[0];
phiJet2 = v_jetphi[1];

with

 v_jetpt = *jetpt; 
 v_jeteta = *jeteta; 
 v_jetphi = *jetphi;

and

TTreeReaderValue< vector<float> > jetpt(reader, "HGamAntiKt4EMTopoJetsAuxDyn.pt");
TTreeReaderValue< vector<float> > jeteta(reader, "HGamAntiKt4EMTopoJetsAuxDyn.eta");
TTreeReaderValue< vector<float> > jetphi(reader, "HGamAntiKt4EMTopoJetsAuxDyn.phi");

and
TTreeReader reader("CollectionTree", f0);

Dear @eguiraud,

Do you still see c++ errors when loading my macro into root ?
Thanks so much for your help !
Cheers
N.Lorenzo

Hi,
your code compiles fine although it generates some warnings with the -Wall -Wextra -Wpedantic flags.
I suggest to compile it and run it within gdb to figure out where and why the crash happens.

Cheers,
Enrico

The warnings:

$ g++ -Wall -Wextra -Wpedantic -g -c TemplatesMaker.C $(root-config --libs --cflags)
TemplatesMaker.C: In function ‘void TemplatesMaker(TString, TString, TString, TString, TString, bool)’:
TemplatesMaker.C:60:10: warning: ISO C++ forbids variable length array ‘binning’ [-Wvla]
   60 |   double binning[bins+1];
      |          ^~~~~~~
TemplatesMaker.C:473:11: warning: unused variable ‘i’ [-Wunused-variable]
  473 |       int i = reader.GetCurrentEntry();
      |           ^
TemplatesMaker.C:359:33: warning: unused variable ‘deltaYjj’ [-Wunused-variable]
  359 |     float mjj,weight2,weightXS, deltaYjj,Zgcentr, ptg, ptcone20g,etag, phig, ptj1, ptj2, etaJet1, etaJet2, phiJet1, phiJet2, BDTout, ptllg, mll, mlly;
      |                                 ^~~~~~~~
TemplatesMaker.C:359:108: warning: unused variable ‘phiJet1’ [-Wunused-variable]
  359 | ,Zgcentr, ptg, ptcone20g,etag, phig, ptj1, ptj2, etaJet1, etaJet2, phiJet1, phiJet2, BDTout, ptllg, mll, mlly;
      |                                                                    ^~~~~~~

TemplatesMaker.C:359:117: warning: unused variable ‘phiJet2’ [-Wunused-variable]
  359 |  ptg, ptcone20g,etag, phig, ptj1, ptj2, etaJet1, etaJet2, phiJet1, phiJet2, BDTout, ptllg, mll, mlly;
      |                                                                    ^~~~~~~

TemplatesMaker.C:359:126: warning: unused variable ‘BDTout’ [-Wunused-variable]
  359 | one20g,etag, phig, ptj1, ptj2, etaJet1, etaJet2, phiJet1, phiJet2, BDTout, ptllg, mll, mlly;
      |                                                                    ^~~~~~

TemplatesMaker.C:359:134: warning: unused variable ‘ptllg’ [-Wunused-variable]
  359 | etag, phig, ptj1, ptj2, etaJet1, etaJet2, phiJet1, phiJet2, BDTout, ptllg, mll, mlly;
      |                                                                     ^~~~~

TemplatesMaker.C:360:23: warning: unused variable ‘l1Type’ [-Wunused-variable]
  360 |     int ngj, nBJets,  l1Type, isIso, isTight, isPass, Ne, Nmu;
      |                       ^~~~~~
TemplatesMaker.C:439:12: warning: unused variable ‘nEvents’ [-Wunused-variable]
  439 |     Long_t nEvents = reader.GetEntries(true);
      |            ^~~~~~~
TemplatesMaker.C:41:137: warning: unused parameter ‘debug’ [-Wunused-parameter]
   41 | LeptonType="elec", TString SliceType="1", TString RegionABCD= "A", bool debug=false){
      |                                                                    ~~~~~^~~~~~~~~~~

TemplatesMaker.C:541:38: warning: ‘ptj2’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  541 |  if(ngj>=2 && mjj>500 && ptj1>JETcut && ptj2>JETcut && nBJets==0 && fabs(Zgcentr)<=5 && fabs(etaJet1-etaJet2)>dYcut){
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
TemplatesMaker.C:541:93: warning: ‘etaJet1’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  541 | ptj1>JETcut && ptj2>JETcut && nBJets==0 && fabs(Zgcentr)<=5 && fabs(etaJet1-etaJet2)>dYcut){
      |                                                                ~~~~^~~~~~~~~~~~~~~~~

TemplatesMaker.C:541:93: warning: ‘etaJet2’ may be used uninitialized in this function [-Wmaybe-uninitialized]

Hello,

Thanks so much I will try to compile with these flags.

Sorry, what is gdb ?

Thanks !
N. Lorenzo

gdb is the debugger for C++ programs, see e.g. http://www.gdbtutorial.com.

Alternatively, ROOT should print out a stacktrace at the moment of the crash that should point to the offending line of code.

If all else fails, you can provide to us a simple recipe to reproduce the problem (e.g. at the moment I don’t know how to invoke TemplateMaker and I don’t have access to the files in /nfs/dust/atlas/user/...).

Cheers,
Enrico

Dear @eguiraud

Thanks for the suggestions !

Ok I tried it, here is what I did:
g++ -g -c MakeTemplates.C $(root-config --libs --cflags)
It creates a MakeTemplates.o file, then I do
gdb MakeTemplates.o
I get the usual gdb message with at the end:

Reading symbols from /afs/desy.de/user/n/nlorenzo/ZgVBSFullRun2/MakeTemplates.o...done.

And then:

(gdb) run

Starting program: /afs/desy.de/user/n/nlorenzo/ZgVBSFullRun2/MakeTemplates.o

zsh:1: permission denied: /afs/desy.de/user/n/nlorenzo/ZgVBSFullRun2/MakeTemplates.o

During startup program exited with code 126.

I don’t really understand this error. Do you have an idea ?

Yes, here is what is printed:

===========================================================

There was a crash.

This is the entire stack trace of all threads:

===========================================================

gdb.printing.register_pretty_printer(gdb.current_objfile(),

gdb.printing.register_pretty_printer(gdb.current_objfile(),

#0 0x00007f488b16241c in waitpid () from /lib64/libc.so.6

#1 0x00007f488b0dff12 in do_system () from /lib64/libc.so.6

#2 0x00007f488bc3f0cc in TUnixSystem::StackTrace() () from /usr/lib64/root/libCore.so.6.20

#3 0x00007f488bc41a9c in TUnixSystem::DispatchSignals(ESignals) () from /usr/lib64/root/libCore.so.6.20

#4 <signal handler called>

#5 0x00007f488c3ea3f6 in ?? ()

#6 0x0000005b00000031 in ?? ()

#7 0x00007ffdd3548720 in ?? ()

#8 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.

===========================================================

#5 0x00007f488c3ea3f6 in ?? ()

#6 0x0000005b00000031 in ?? ()

#7 0x00007ffdd3548720 in ?? ()

#8 0x0000000000000000 in ?? ()

===========================================================

So I attach a new file, that I simplified.
The problem is I don’t know how to send to you the root files. Do you have a cern account so that you could see them in my cern public area ?
To run the macro and get the crash, you just need to do, when you will have the root file:

root.exe
.L MakeTemplates.C
MakeTemplates("BDT", "QCD_aMCAtNLO", "elec", "1")

Of course, first you need to correct the root file path in line 34 and 46.
And in order not to get anymore the crash, you just need to comment l.275
ptj1 = v_jetpt[0]*1e-3;
I really don’t know why this is the case.

Thanks a lot in advance for your help !
Best,
N. Lorenzo

MakeTemplates.C (12.7 KB)

in order not to get anymore the crash, you just need to comment l.275
ptj1 = v_jetpt[0]*1e-3;

Could it be that v_jetpt is empty and does not have an element to access for certain events?

Do you have a cern account so that you could see them in my cern public area ?

Indeed I do. You can also share the files via cernbox with eguiraud.

Cheers,
Enrico

1 Like