_ROOT Version:_6.13/08
_Platform:_Ubuntu 16.04
_Compiler:_gcc-5.5.0
Hello,
I have a ROOT file containing a TDirectoryFile
of 18 histograms (TH2S). I want to draw a single one of them on a TCanvas
and then save this as an image to file. I have the following code:
#include "TROOT.h"
#include "TFile.h"
#include "TDirectory.h"
#include "TH2S.h"
#include "TCanvas.h"
int main() {
gROOT->SetBatch(1);
TFile *f = new TFile("raweventdisplay.root");
TDirectory *d = f->GetDirectory("rawdraw");
TH2S *hist = nullptr;
d->GetObject("fTimeChanU0", hist);
TCanvas *c = new TCanvas();
hist->Draw();
c->Print("hist.png");
return 0;
}
It takes 8m11s to execute (compiled, not interpreted) this code on my laptop (Intel Core i7), which seems quite long, considering that the histogram I am trying to draw has {800, 6000, 1} bins (which I found through GetNBins[X,Y,Z]
). I takes about 15 minutes on a POWER8 (remote) machine.
I profiled this code (on my laptop) with Intel VTune to find the following:
The vfprintf
seem to be originating mostly from this callstack:
#0 0x00003fffb5876540 in _IO_default_xsputn () from /opt/at12.0/lib64/power8/libc.so.6
#1 0x00003fffb584130c in vfprintf () from /opt/at12.0/lib64/power8/libc.so.6
#2 0x00003fffb586e434 in vsnprintf () from /opt/at12.0/lib64/power8/libc.so.6
#3 0x00003fffb7c7709c in TString::FormImp (this=0x3fffb7f5f270 <TColor::AsHexString() const::tempbuf>, fmt=<optimized out>, ap=<optimized out>)
at /afs/cern.ch/user/a/ahhesam/root/core/base/src/TString.cxx:2228
#4 0x00003fffb7c77184 in TString::Form (this=<optimized out>, fmt=<optimized out>) at /afs/cern.ch/user/a/ahhesam/root/core/base/src/TString.cxx:2268
#5 0x00003fffb7c068c8 in TColor::AsHexString (this=0x10079e10) at /afs/cern.ch/user/a/ahhesam/root/core/base/src/TColor.cxx:1216
#6 0x00003fffb63cbba4 in TImageDump::DrawPolyMarker (this=0x11ce00f0, n=<optimized out>, xw=0x11d61d50, yw=0x11d7f110)
at /afs/cern.ch/user/a/ahhesam/root/graf2d/postscript/src/TImageDump.cxx:339
#7 0x00003fffb6b4136c in TPad::PaintPolyMarker (this=0x115ebfa0, nn=<optimized out>, x=0x11d61d50, y=0x11d7f110)
at /afs/cern.ch/user/a/ahhesam/root/graf2d/gpad/src/TPad.cxx:4382
#8 0x00003fffa7c26140 in THistPainter::PaintScatterPlot (this=0x11d48d30, option=<optimized out>)
at /afs/cern.ch/user/a/ahhesam/root/hist/histpainter/src/THistPainter.cxx:8049
#9 0x00003fffa7c198a4 in THistPainter::PaintTable (this=0x11d48d30, option=0x11b4bba1 "")
at /afs/cern.ch/user/a/ahhesam/root/hist/histpainter/src/THistPainter.cxx:9192
#10 0x00003fffa7bfa3f0 in THistPainter::Paint (this=0x11d48d30, option=0x11b4bba1 "")
at /afs/cern.ch/user/a/ahhesam/root/hist/histpainter/src/THistPainter.cxx:4172
#11 0x00003fffb7161744 in TH1::Paint (this=0x11b4b820, option=0x11bf4d59 "") at /afs/cern.ch/user/a/ahhesam/root/hist/hist/src/TH1.cxx:5700
#12 0x00003fffb6b55248 in TPad::Paint (this=0x115ebfa0) at /afs/cern.ch/user/a/ahhesam/root/graf2d/gpad/src/TPad.cxx:3432
#13 0x00003fffb6aff6d4 in TCanvas::Paint (this=<optimized out>, option=<optimized out>)
at /afs/cern.ch/user/a/ahhesam/root/graf2d/gpad/src/TCanvas.cxx:1473
#14 0x00003fffb6b5073c in TPad::Print (this=0x115ebfa0, filenam=<optimized out>, option=<optimized out>)
at /afs/cern.ch/user/a/ahhesam/root/graf2d/gpad/src/TPad.cxx:5069
#15 0x00003fffb6b51d68 in TPad::SaveAs (this=0x115ebfa0, filename=<optimized out>) at /afs/cern.ch/user/a/ahhesam/root/graf2d/gpad/src/TPad.cxx:5551
#16 0x00003fffb6b24d30 in TPad::Print (this=<optimized out>, filename=<optimized out>) at /afs/cern.ch/user/a/ahhesam/root/graf2d/gpad/src/TPad.cxx:4619
#17 0x0000000010000ec8 in main ()
Am I doing something in a non-optimal way, or is this how long it should take to export a single histogram to file?
Best,
Ahmad
Edit: the root file can be found here: https://cernbox.cern.ch/index.php/s/rtURqNAIpDgGUXY