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 "TTimer.h"
17#include "TObjArray.h"
18#include "TSystem.h"
19
21
22/** \class TGraphTime
23 \ingroup Graphs
24TGraphTime is used to draw a set of objects evolving with nsteps in time between tmin and tmax.
25Each time step has a new list of objects. This list can be identical to
26the list of objects in the previous steps, but with different attributes.
27see example of use in $ROOTSYS/tutorials/graphs/gtime.C
28*/
29
30////////////////////////////////////////////////////////////////////////////////
31/// default constructor.
32
34{
35}
36
37
38////////////////////////////////////////////////////////////////////////////////
39/// Create a TGraphTime with nsteps in range [xmin,xmax][ymin,ymax]
40
42{
43 if (nsteps <= 0) {
44 Warning("TGraphTime", "Number of steps %d changed to 100", nsteps);
45 nsteps = 100;
46 }
47 fSleepTime = 0;
48 fNsteps = nsteps;
49 fXmin = xmin;
50 fXmax = xmax;
51 fYmin = ymin;
52 fYmax = ymax;
53 fSteps = new TObjArray(nsteps+1);
54 fFrame = new TH1D("frame", "", 100, fXmin, fXmax);
57 fFrame->SetStats(false);
58}
59
60
61////////////////////////////////////////////////////////////////////////////////
62/// GraphTime default destructor.
63
65{
67
68 if (fSteps) {
69 fSteps->Delete();
70 delete fSteps;
71 fSteps = nullptr;
72 }
73}
74
75
76////////////////////////////////////////////////////////////////////////////////
77/// copy constructor.
78
80{
81 fSleepTime = gtime.fSleepTime;
82 fNsteps = gtime.fNsteps;
83 fXmin = gtime.fXmin;
84 fXmax = gtime.fXmax;
85 fYmin = gtime.fYmin;
86 fYmax = gtime.fYmax;
87 fSteps = new TObjArray(fNsteps + 1);
88 fFrame = new TH1D("frame", "", 100, fXmin, fXmax);
91 fFrame->SetStats(false);
92}
93
94////////////////////////////////////////////////////////////////////////////////
95/// Add one object to a time slot.
96/// TGraphTime becomes the owner of this object.
97/// object will be drawn with option
98
100{
101 if (!fSteps) {
102 fNsteps = 100;
103 fSteps = new TObjArray(fNsteps+1);
104 }
105 if (slot < 0 || slot >= fNsteps)
106 return -1;
107 TList *list = (TList*)fSteps->UncheckedAt(slot);
108 if (!list) {
109 list = new TList();
110 fSteps->AddAt(list,slot);
111 }
112 list->Add((TObject*)obj, option);
113 return slot;
114}
115
116////////////////////////////////////////////////////////////////////////////////
117/// Start animation of TGraphTime.
118/// Triggers drawing of steps - but does not block macro execution which will continues
119
121{
122 if (!enable) {
123 fAnimateCnt = -1;
124 if (fAnimateTimer) {
126 delete fAnimateTimer;
127 fAnimateTimer = nullptr;
128 }
129 return;
130 }
131
132 if (!gPad) {
133 gROOT->MakeDefCanvas();
134 gPad->SetFillColor(41);
135 gPad->SetFrameFillColor(19);
136 gPad->SetGrid();
137 }
138 if (fFrame)
140
141 fAnimateCnt = 0;
142 if (!fAnimateTimer) {
143 fAnimateTimer = new TTimer(this, fSleepTime > 0 ? fSleepTime : 1);
145 }
146
147 Notify();
148}
149
150////////////////////////////////////////////////////////////////////////////////
151/// Draw this TGraphTime.
152/// for each time step the list of objects added to this step are drawn.
153
155{
156 if (!gPad) {
157 gROOT->MakeDefCanvas();
158 gPad->SetFillColor(41);
159 gPad->SetFrameFillColor(19);
160 gPad->SetGrid();
161 }
162 if (fFrame)
164
165 for (Int_t s = 0; s < fNsteps; s++) {
166 if (DrawStep(s)) {
167 gPad->Update();
168 if (fSleepTime > 0)
170 }
171 }
172}
173
174
175////////////////////////////////////////////////////////////////////////////////
176/// Draw single step
177
179{
180 if (!fSteps)
181 return kFALSE;
182
183 auto list = static_cast<TList *>(fSteps->UncheckedAt(nstep));
184 if (!list)
185 return kFALSE;
186
187 if (fFrame)
189 gPad->GetListOfPrimitives()->Clear();
190 if (fFrame)
191 gPad->Add(fFrame);
192
193 auto lnk = list->FirstLink();
194 while(lnk) {
195 gPad->Add(lnk->GetObject(), lnk->GetAddOption());
196 lnk = lnk->Next();
197 }
198
199 return kTRUE;
200}
201
202
203////////////////////////////////////////////////////////////////////////////////
204/// Method used for implementing animation of TGraphTime
205
207{
208 if ((fAnimateCnt < 0) || !fSteps || !gPad)
209 return kTRUE;
210
211 if (fAnimateCnt > fSteps->GetLast())
212 fAnimateCnt = 0;
213
214 if (DrawStep(fAnimateCnt++))
215 gPad->Update();
216
217 return kTRUE;
218}
219
220
221////////////////////////////////////////////////////////////////////////////////
222/// Paint all objects added to each time step
223
225{
226 Error("Paint", "Not implemented, use Draw() instead");
227}
228
229
230////////////////////////////////////////////////////////////////////////////////
231/// Save this object to filename as an animated gif file
232/// if filename is specified it must be of the form xxx.gif
233/// otherwise a file yyy.gif is produced where yyy is the object name
234
236{
237 if (!gPad) {
238 Error("SaveAnimatedGif", "Not possible to create animated GIF without gPad");
239 return;
240 }
241
242 if (gPad->IsWeb()) {
243 Error("SaveAnimatedGif", "Not possible to create animated GIF with web canvas");
244 return;
245 }
246
247 TString farg = TString::Format("%s+", filename && *filename ? filename : GetName());
248
249 for (Int_t s = 0; s < fNsteps; s++) {
250 if (DrawStep(s))
251 gPad->Print(farg.Data());
252 }
253}
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:382
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:561
#define gPad
TGraphTime is used to draw a set of objects evolving with nsteps in time between tmin and tmax.
Definition TGraphTime.h:30
void Animate(Bool_t enable=kTRUE)
Start animation of TGraphTime.
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
Int_t fAnimateCnt
! counter used in Animate() method
Definition TGraphTime.h:41
~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
TTimer * fAnimateTimer
! timer to implement animation
Definition TGraphTime.h:42
Bool_t DrawStep(Int_t nstep) const
Draw single step.
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
Bool_t HandleTimer(TTimer *) override
Method used for implementing animation of TGraphTime.
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:670
void SetTitle(const char *title) override
Change/set the title.
Definition TH1.cxx:6739
virtual void SetMaximum(Double_t maximum=-1111)
Definition TH1.h:404
virtual void SetMinimum(Double_t minimum=-1111)
Definition TH1.h:405
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition TH1.cxx:9011
A doubly linked list.
Definition TList.h:38
void Add(TObject *obj) override
Definition TList.h:81
TObject * Remove(TObject *obj) override
Remove object from the list.
Definition TList.cxx:820
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
Int_t GetLast() const override
Return index of last object in array.
Mother of all ROOT objects.
Definition TObject.h:41
virtual void Clear(Option_t *="")
Definition TObject.h:119
virtual Bool_t Notify()
This method must be overridden to handle object notification (the base implementation is no-op).
Definition TObject.cxx:611
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:991
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1005
Basic string class.
Definition TString.h:139
const char * Data() const
Definition TString.h:376
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
Handles synchronous and a-synchronous timer events.
Definition TTimer.h:51
virtual void Start(Long_t milliSec=-1, Bool_t singleShot=kFALSE)
Starts the timer with a milliSec timeout.
Definition TTimer.cxx:213
virtual void Stop()
Definition TTimer.h:94