Logo ROOT  
Reference Guide
timeonaxis3.C File Reference

Detailed Description

View in nbviewer Open in SWAN This example compares what the system time function gmtime and localtime give with what gives TGaxis. It can be used as referenced test to check if TGaxis is working properly. The original code was developed by Philippe Gras (CEA Saclay. IRFU/SEDI)

#if defined(G__WIN32) && defined(__CINT__) && !defined(__MAKECINT__)
{
// timeonaxis3.C has to be run in compiled mode on Windows.
// the following code does it.
gSystem->CompileMacro("timeonaxis3.C");
timeonaxis3();
}
#else
#include "TAxis.h"
#include "TGaxis.h"
#include "TCanvas.h"
#include "TString.h"
#include "TLine.h"
#include "TLatex.h"
#include <time.h>
#include <stdio.h>
TString stime(time_t* t, bool utc = false, bool display_time_zone = true) {
struct tm* tt;
if (utc) tt = gmtime(t);
else tt = localtime(t);
char buf[256];
if (display_time_zone) strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S %Z", tt);
else strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tt);
return TString(buf);
}
TCanvas *timeonaxis3() {
double f = 1.8;
TCanvas* c = new TCanvas;
TLatex* tex1 = new TLatex;
tex1->SetNDC();
tex1->SetTextFont(102);
tex1->SetTextSize(0.055*f);
TLatex* tex3 = new TLatex;
tex3->SetNDC();
tex3->SetTextFont(102);
tex3->SetTextSize(0.07*f);
tex3->SetTextColor(kBlue+2);
TLatex* tex2 = new TLatex;
tex2->SetNDC();
tex2->SetTextFont(102);
tex2->SetTextSize(0.07*f);
tex2->SetTextColor(kOrange+3);
time_t offset[] = {0, 0, 1325376000, 1341100800};
time_t t[] = {1331150400, 1336417200, 0, 36000};
c->SetTopMargin(0); c->SetBottomMargin(0);
c->SetLeftMargin(0); c->SetRightMargin(0);
c->Divide(2, 4, -1, -1);
l.DrawLine(0.5, 0, 0.5, 1.);
for(int i = 0; i < 4; ++i){
for(int gmt = 0; gmt < 2; ++gmt){
const char* opt = (gmt ? "gmt" : "local");
TVirtualPad* p = c->cd(2*i + gmt + 1);
p->SetFillStyle(4000);
TGaxis* ga = new TGaxis (.4, .25, 5., .25, t[i], t[i] + 1, 1, "t");
ga->SetTimeFormat("TGaxis label: #color[2]{%Y-%m-%d %H:%M:%S}");
ga->SetLabelFont(102);
ga->SetTimeOffset(offset[i], opt);
ga->SetLabelOffset(0.04*f);
ga->SetLabelSize(0.07*f);
ga->SetLineColor(0);
ga->Draw();
// Get offset string of axis time format: there is not accessor
// to time format in TGaxis.
// Assumes TAxis use the same format.
TAxis a(10, 0, 1600000000);
a.SetTimeOffset(offset[i], opt);
const char* offsettimeformat = a.GetTimeFormat();
char buf[256];
if (offset[i] < t[i]) {
sprintf(buf, "#splitline{%s, %s}{offset: %ld, option %s}",
stime(t+i).Data(), stime(t+i, true).Data(), offset[i], opt);
} else {
int h = t[i] / 3600;
int m = (t[i] - 3600 * h) / 60 ;
int s = (t[i] - h * 3600 - m * 60);
sprintf(buf, "#splitline{%d h %d m %d s}{offset: %s, option %s}",
h, m, s, stime(offset + i, gmt).Data(), opt);
}
tex1->DrawLatex(.01, .75, buf);
tex2->DrawLatex(.01, .50, offsettimeformat);
time_t t_ = t[i] + offset[i];
sprintf(buf, "Expecting: #color[2]{%s}", stime(&t_, gmt, false).Data());
tex3->DrawLatex(.01, .24, buf);
if(i > 0) l.DrawLine(0, 0.95, 1, 0.95);
}
}
return c;
}
#endif
Authors
Philippe Gras, Bertrand Bellenot, Olivier Couet

Definition in file timeonaxis3.C.

c
#define c(i)
Definition: RSha256.hxx:119
l
auto * l
Definition: textangle.C:4
m
auto * m
Definition: textangle.C:8
TAxis
Class to manage histogram axis.
Definition: TAxis.h:30
TAttPad::SetTopMargin
virtual void SetTopMargin(Float_t topmargin)
Set Pad top margin in fraction of the pad height.
Definition: TAttPad.cxx:129
TGaxis::SetTimeOffset
void SetTimeOffset(Double_t toffset, Option_t *option="local")
Change the time offset. If option = "gmt", set display mode to GMT.
Definition: TGaxis.cxx:2745
tt
auto * tt
Definition: textangle.C:16
TLine.h
f
#define f(i)
Definition: RSha256.hxx:122
TLine
Definition: TLine.h:22
TGeant4Unit::s
static constexpr double s
Definition: TGeant4SystemOfUnits.h:168
kOrange
@ kOrange
Definition: Rtypes.h:67
TGaxis::SetLabelOffset
void SetLabelOffset(Float_t labeloffset)
Definition: TGaxis.h:106
TLatex::DrawLatex
TLatex * DrawLatex(Double_t x, Double_t y, const char *text)
Make a copy of this object with the new parameters And copy object attributes.
Definition: TLatex.cxx:1927
TLatex
Definition: TLatex.h:18
TCanvas.h
TString
Definition: TString.h:136
TString.h
TText::SetNDC
virtual void SetNDC(Bool_t isNDC=kTRUE)
Set NDC mode on if isNDC = kTRUE, off otherwise.
Definition: TText.cxx:813
TSystem::CompileMacro
virtual int CompileMacro(const char *filename, Option_t *opt="", const char *library_name="", const char *build_dir="", UInt_t dirmode=0)
This method compiles and loads a shared library containing the code from the file "filename".
Definition: TSystem.cxx:2868
TAttPad::SetBottomMargin
virtual void SetBottomMargin(Float_t bottommargin)
Set Pad bottom margin in fraction of the pad height.
Definition: TAttPad.cxx:99
h
#define h(i)
Definition: RSha256.hxx:124
a
auto * a
Definition: textangle.C:12
TGaxis::SetLabelFont
void SetLabelFont(Int_t labelfont)
Definition: TGaxis.h:105
TGaxis::SetLabelSize
void SetLabelSize(Float_t labelsize)
Definition: TGaxis.h:107
TGaxis::SetLabelColor
void SetLabelColor(Int_t labelcolor)
Definition: TGaxis.h:104
gSystem
R__EXTERN TSystem * gSystem
Definition: TSystem.h:559
TGaxis.h
TAttPad::SetLeftMargin
virtual void SetLeftMargin(Float_t leftmargin)
Set Pad left margin in fraction of the pad width.
Definition: TAttPad.cxx:109
TObject::Draw
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:197
TVirtualPad
Definition: TVirtualPad.h:50
TAttPad::SetRightMargin
virtual void SetRightMargin(Float_t rightmargin)
Set Pad right margin in fraction of the pad width.
Definition: TAttPad.cxx:119
TCanvas
Definition: TCanvas.h:23
TLatex.h
TGaxis
Definition: TGaxis.h:23
TAxis.h
kBlue
@ kBlue
Definition: Rtypes.h:66
TGaxis::SetTimeFormat
void SetTimeFormat(const char *tformat)
Change the format used for time plotting.
Definition: TGaxis.cxx:2721