Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
timeonaxis3.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_graphics
3/// \notebook
4/// \preview This example compares what the system time function gmtime and localtime give
5/// with what gives TGaxis. It can be used as referenced test to check if TGaxis
6/// is working properly.
7/// The original code was developed by Philippe Gras (CEA Saclay. IRFU/SEDI)
8///
9/// \macro_image
10/// \macro_code
11///
12/// \authors Philippe Gras, Bertrand Bellenot, Olivier Couet
13
14#include "TAxis.h"
15#include "TGaxis.h"
16#include "TCanvas.h"
17#include "TString.h"
18#include "TLine.h"
19#include "TLatex.h"
20#include <ctime>
21#include <cstdio>
22
23TString stime(time_t *t, bool utc = false, bool display_time_zone = true)
24{
25 struct tm *tt;
26 if (utc)
27 tt = gmtime(t);
28 else
29 tt = localtime(t);
30 char buf[256];
32 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S %Z", tt);
33 else
34 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tt);
35 return TString(buf);
36}
37
38void timeonaxis3()
39{
40 double f = 1.8;
41
42 auto c = new TCanvas;
43
45 tex1.SetNDC();
46 tex1.SetTextFont(102);
47 tex1.SetTextSize(0.055 * f);
48
50 tex3.SetNDC();
51 tex3.SetTextFont(102);
52 tex3.SetTextSize(0.07 * f);
53 tex3.SetTextColor(kBlue + 2);
54
56 tex2.SetNDC();
57 tex2.SetTextFont(102);
58 tex2.SetTextSize(0.07 * f);
59 tex2.SetTextColor(kOrange + 3);
60
61 time_t offset[] = {0, 0, 1325376000, 1341100800};
62 time_t t[] = {1331150400, 1336417200, 0, 36000};
63
64 c->SetTopMargin(0);
65 c->SetBottomMargin(0);
66 c->SetLeftMargin(0);
67 c->SetRightMargin(0);
68 c->Divide(2, 4, -1, -1);
69 TLine l;
70 l.DrawLine(0.5, 0, 0.5, 1.);
71
72 for (int i = 0; i < 4; ++i) {
73 for (int gmt = 0; gmt < 2; ++gmt) {
74 const char *opt = (gmt ? "gmt" : "local");
75 TVirtualPad *p = c->cd(2 * i + gmt + 1);
76 p->SetTopMargin(0);
77 p->SetBottomMargin(0);
78 p->SetLeftMargin(0);
79 p->SetRightMargin(0);
80 p->SetFillStyle(4000);
81
82 TGaxis *ga = new TGaxis(.4, .25, 5., .25, t[i], t[i] + 1, 1, "t");
83 ga->SetTimeFormat("TGaxis label: #color[2]{%Y-%m-%d %H:%M:%S}");
84 ga->SetLabelFont(102);
85 ga->SetLabelColor(kBlue + 2);
86
87 ga->SetTimeOffset(offset[i], opt);
88 ga->SetLabelOffset(0.04 * f);
89 ga->SetLabelSize(0.07 * f);
90 ga->SetLineColor(0);
91 ga->Draw();
92
93 // Get offset string of axis time format: there is not accessor
94 // to time format in TGaxis.
95 // Assumes TAxis use the same format.
96 TAxis a(10, 0, 1600000000);
97 a.SetTimeOffset(offset[i], opt);
98 const char *offsettimeformat = a.GetTimeFormat();
99
100 char buf[256];
101 if (offset[i] < t[i]) {
102 snprintf(buf, 256, "#splitline{%s, %s}{offset: %ld, option %s}", stime(t + i).Data(),
103 stime(t + i, true).Data(), offset[i], opt);
104 } else {
105 int h = t[i] / 3600;
106 int m = (t[i] - 3600 * h) / 60;
107 int s = (t[i] - h * 3600 - m * 60);
108 snprintf(buf, 256, "#splitline{%d h %d m %d s}{offset: %s, option %s}", h, m, s,
109 stime(offset + i, gmt).Data(), opt);
110 }
111 tex1.DrawLatex(.01, .75, buf);
112 tex2.DrawLatex(.01, .50, offsettimeformat);
113 time_t t_ = t[i] + offset[i];
114 snprintf(buf, 256, "Expecting: #color[2]{%s}", stime(&t_, gmt, false).Data());
115 tex3.DrawLatex(.01, .24, buf);
116 if (i > 0)
117 l.DrawLine(0, 0.95, 1, 0.95);
118 }
119 }
120}
#define f(i)
Definition RSha256.hxx:104
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
#define h(i)
Definition RSha256.hxx:106
@ kOrange
Definition Rtypes.h:67
@ kBlue
Definition Rtypes.h:66
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
#define snprintf
Definition civetweb.c:1540
Class to manage histogram axis.
Definition TAxis.h:32
The Canvas class.
Definition TCanvas.h:23
The axis painter class.
Definition TGaxis.h:26
To draw Mathematical Formula.
Definition TLatex.h:18
Use the TLine constructor to create a simple line.
Definition TLine.h:22
virtual TLine * DrawLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Draw this line with new coordinates.
Definition TLine.cxx:103
Basic string class.
Definition TString.h:139
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51
TMarker m
Definition textangle.C:8
TLine l
Definition textangle.C:4
auto * tt
Definition textangle.C:16