Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGraphTime.cxx
Go to the documentation of this file.
1// @(#)root/hist:$Id$
2// Author: Rene Brun 14/07/2009
3
4/*************************************************************************
5 * Copyright (C) 1995-2009, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include "TGraphTime.h"
13#include "TVirtualPad.h"
14#include "TH1.h"
15#include "TROOT.h"
16#include "TObjArray.h"
17#include "TSystem.h"
18
20
21/** \class TGraphTime
22 \ingroup Graphs
23TGraphTime is used to draw a set of objects evolving with nsteps in time between tmin and tmax.
24Each time step has a new list of objects. This list can be identical to
25the list of objects in the previous steps, but with different attributes.
26see example of use in $ROOTSYS/tutorials/graphs/gtime.C
27*/
28
29////////////////////////////////////////////////////////////////////////////////
30/// default constructor.
31
33{
34 fSleepTime = 0;
35 fNsteps = 0;
36 fXmin = 0;
37 fXmax = 1;
38 fYmin = 0;
39 fYmax = 1;
40 fSteps = nullptr;
41 fFrame = nullptr;
42}
43
44
45////////////////////////////////////////////////////////////////////////////////
46/// Create a TGraphTime with nsteps in range [xmin,xmax][ymin,ymax]
47
49 :TNamed()
50{
51 if (nsteps <= 0) {
52 Warning("TGraphTime", "Number of steps %d changed to 100",nsteps);
53 nsteps = 100;
54 }
55 fSleepTime = 0;
56 fNsteps = nsteps;
57 fXmin = xmin;
58 fXmax = xmax;
59 fYmin = ymin;
60 fYmax = ymax;
61 fSteps = new TObjArray(nsteps+1);
62 fFrame = new TH1D("frame","",100,fXmin,fXmax);
65 fFrame->SetStats(false);
66}
67
68
69////////////////////////////////////////////////////////////////////////////////
70/// GraphTime default destructor.
71
73{
74 if (!fSteps) return;
75 fSteps->Delete();
76 delete fSteps; fSteps=nullptr;
77}
78
79
80////////////////////////////////////////////////////////////////////////////////
81/// copy constructor.
82
84{
85 fSleepTime = gtime.fSleepTime;
86 fNsteps = gtime.fNsteps;
87 fXmin = gtime.fXmin;
88 fXmax = gtime.fXmax;
89 fYmin = gtime.fYmin;
90 fYmax = gtime.fYmax;
91 fSteps = new TObjArray(fNsteps+1);
92 fFrame = new TH1D("frame","",100,fXmin,fXmax);
95 fFrame->SetStats(false);
96}
97
98////////////////////////////////////////////////////////////////////////////////
99/// Add one object to a time slot.
100/// TGraphTime becomes the owner of this object.
101/// object will be drawn with option
102
104{
105 if (!fSteps) {
106 fNsteps = 100;
107 fSteps = new TObjArray(fNsteps+1);
108 }
109 if (slot < 0 || slot >= fNsteps) return -1;
110 TList *list = (TList*)fSteps->UncheckedAt(slot);
111 if (!list) {
112 list = new TList();
113 fSteps->AddAt(list,slot);
114 }
115 list->Add((TObject*)obj, option);
116 return slot;
117}
118
119
120////////////////////////////////////////////////////////////////////////////////
121/// Draw this TGraphTime.
122/// for each time step the list of objects added to this step are drawn.
123
125{
126 if (!gPad) {
127 gROOT->MakeDefCanvas();
128 gPad->SetFillColor(41);
129 gPad->SetFrameFillColor(19);
130 gPad->SetGrid();
131 }
132 if (fFrame) {
134 fFrame->Draw();
135 }
136 Paint(option);
137
138}
139
140////////////////////////////////////////////////////////////////////////////////
141/// Paint all objects added to each time step
142
144{
145 TString opt = option;
146 opt.ToLower();
147 TObject *frame = gPad->GetPrimitive("frame");
148 TList *list = nullptr;
149 TObjLink *lnk;
150
151 for (Int_t s=0;s<fNsteps;s++) {
152 list = (TList*)fSteps->UncheckedAt(s);
153 if (list) {
154 gPad->GetListOfPrimitives()->Remove(frame);
155 gPad->GetListOfPrimitives()->Clear();
156 if (frame) gPad->GetListOfPrimitives()->Add(frame);
157 lnk = list->FirstLink();
158 while(lnk) {
159 TObject *obj = lnk->GetObject();
160 obj->Draw(lnk->GetAddOption());
161 lnk = lnk->Next();
162 }
163 gPad->Update();
165 }
166 }
167}
168
169////////////////////////////////////////////////////////////////////////////////
170/// Save this object to filename as an animated gif file
171/// if filename is specified it must be of the form xxx.gif
172/// otherwise a file yyy.gif is produced where yyy is the object name
173
175{
176 TObject *frame = gPad->GetPrimitive("frame");
177 TList *list = nullptr;
178 TObjLink *lnk;
179
180 for (Int_t s=0;s<fNsteps;s++) {
181 list = (TList*)fSteps->UncheckedAt(s);
182 if (list) {
183 gPad->GetListOfPrimitives()->Remove(frame);
184 gPad->GetListOfPrimitives()->Clear();
185 if (frame) gPad->GetListOfPrimitives()->Add(frame);
186 lnk = list->FirstLink();
187 while(lnk) {
188 TObject *obj = lnk->GetObject();
189 obj->Draw(lnk->GetAddOption());
190 lnk = lnk->Next();
191 }
192 gPad->Update();
193 if (filename && strlen(filename) > 0)
194 gPad->Print(TString::Format("%s+", filename));
195 else
196 gPad->Print(TString::Format("%s+", GetName()));
197 if (fSleepTime > 0)
199 }
200 }
201}
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
Option_t Option_t option
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 filename
float xmin
float ymin
float xmax
float ymax
#define gROOT
Definition TROOT.h:406
R__EXTERN TSystem * gSystem
Definition TSystem.h:555
#define gPad
TGraphTime is used to draw a set of objects evolving with nsteps in time between tmin and tmax.
Definition TGraphTime.h:29
virtual Int_t Add(const TObject *obj, Int_t slot, Option_t *option="")
Add one object to a time slot.
Double_t fXmin
Minimum for X axis.
Definition TGraphTime.h:35
void Paint(Option_t *chopt="") override
Paint all objects added to each time step.
Int_t fSleepTime
Time (msec) to wait between time steps.
Definition TGraphTime.h:33
~TGraphTime() override
GraphTime default destructor.
TH1 * fFrame
TH1 object used for the pad range.
Definition TGraphTime.h:40
Double_t fYmin
Minimum for Y axis.
Definition TGraphTime.h:37
virtual void SaveAnimatedGif(const char *filename="") const
Save this object to filename as an animated gif file if filename is specified it must be of the form ...
Double_t fXmax
Maximum for X axis.
Definition TGraphTime.h:36
TGraphTime()
default constructor.
Double_t fYmax
Maximum for Y axis.
Definition TGraphTime.h:38
TObjArray * fSteps
Array of TLists for each time step.
Definition TGraphTime.h:39
void Draw(Option_t *chopt="") override
Draw this TGraphTime.
Int_t fNsteps
Number of time steps.
Definition TGraphTime.h:34
1-D histogram with a double per channel (see TH1 documentation)
Definition TH1.h:669
void SetTitle(const char *title) override
Change/set the title.
Definition TH1.cxx:6686
virtual void SetMaximum(Double_t maximum=-1111)
Definition TH1.h:403
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3066
virtual void SetMinimum(Double_t minimum=-1111)
Definition TH1.h:404
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition TH1.cxx:8958
A doubly linked list.
Definition TList.h:38
void Add(TObject *obj) override
Definition TList.h:83
virtual TObjLink * FirstLink() const
Definition TList.h:104
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:48
An array of TObjects.
Definition TObjArray.h:31
void AddAt(TObject *obj, Int_t idx) override
Add object at position ids.
void Delete(Option_t *option="") override
Remove all objects from the array AND delete all heap based objects.
TObject * UncheckedAt(Int_t i) const
Definition TObjArray.h:84
Mother of all ROOT objects.
Definition TObject.h:41
virtual void Clear(Option_t *="")
Definition TObject.h:119
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:973
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition TObject.cxx:274
Basic string class.
Definition TString.h:139
void ToLower()
Change string to lower-case.
Definition TString.cxx:1182
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2378
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
Definition TSystem.cxx:437