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
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 gr017_time.C
27*/
28
29////////////////////////////////////////////////////////////////////////////////
30/// default constructor.
31
35
36
37////////////////////////////////////////////////////////////////////////////////
38/// Create a TGraphTime with nsteps in range [xmin,xmax][ymin,ymax]
39
41{
42 if (nsteps <= 0) {
43 Warning("TGraphTime", "Number of steps %d changed to 100", nsteps);
44 nsteps = 100;
45 }
46 fSleepTime = 0;
48 fXmin = xmin;
49 fXmax = xmax;
50 fYmin = ymin;
51 fYmax = ymax;
52 fSteps = new TObjArray(nsteps+1);
53 fFrame = new TH1D("frame", "", 100, fXmin, fXmax);
56 fFrame->SetStats(false);
57}
58
59
60////////////////////////////////////////////////////////////////////////////////
61/// GraphTime default destructor.
62
64{
66
67 if (fSteps) {
68 fSteps->Delete();
69 delete fSteps;
70 fSteps = nullptr;
71 }
72}
73
74
75////////////////////////////////////////////////////////////////////////////////
76/// copy constructor.
77
79{
80 fSleepTime = gtime.fSleepTime;
81 fNsteps = gtime.fNsteps;
82 fXmin = gtime.fXmin;
83 fXmax = gtime.fXmax;
84 fYmin = gtime.fYmin;
85 fYmax = gtime.fYmax;
86 fSteps = new TObjArray(fNsteps + 1);
87 fFrame = new TH1D("frame", "", 100, fXmin, fXmax);
90 fFrame->SetStats(false);
91}
92
93////////////////////////////////////////////////////////////////////////////////
94/// Add one object to a time slot.
95/// TGraphTime becomes the owner of this object.
96/// object will be drawn with option
97
99{
100 if (!fSteps) {
101 fNsteps = 100;
102 fSteps = new TObjArray(fNsteps+1);
103 }
105 return -1;
106 TList *list = (TList*)fSteps->UncheckedAt(slot);
107 if (!list) {
108 list = new TList();
109 fSteps->AddAt(list,slot);
110 }
111 list->Add((TObject*)obj, option);
112 return slot;
113}
114
115////////////////////////////////////////////////////////////////////////////////
116/// Start animation of TGraphTime.
117/// Triggers drawing of steps - but does not block macro execution which will continues
118
120{
121 if (!enable) {
122 fAnimateCnt = -1;
123 if (fAnimateTimer) {
125 delete fAnimateTimer;
126 fAnimateTimer = nullptr;
127 }
128 return;
129 }
130
131 if (!gPad) {
132 gROOT->MakeDefCanvas();
133 gPad->SetFillColor(41);
134 gPad->SetFrameFillColor(19);
135 gPad->SetGrid();
136 }
137 if (fFrame)
139
140 fAnimateCnt = 0;
141 if (!fAnimateTimer) {
142 fAnimateTimer = new TTimer(this, fSleepTime > 0 ? fSleepTime : 1);
144 }
145
146 Notify();
147}
148
149////////////////////////////////////////////////////////////////////////////////
150/// Draw this TGraphTime.
151/// for each time step the list of objects added to this step are drawn.
152
154{
155 if (!gPad) {
156 gROOT->MakeDefCanvas();
157 gPad->SetFillColor(41);
158 gPad->SetFrameFillColor(19);
159 gPad->SetGrid();
160 }
161 if (fFrame)
163
164 for (Int_t s = 0; s < fNsteps; s++) {
165 if (DrawStep(s)) {
166 gPad->Update();
167 if (fSleepTime > 0)
169 }
170 }
171}
172
173
174////////////////////////////////////////////////////////////////////////////////
175/// Draw single step
176
178{
179 if (!fSteps)
180 return kFALSE;
181
182 auto list = static_cast<TList *>(fSteps->UncheckedAt(nstep));
183 if (!list)
184 return kFALSE;
185
186 if (fFrame)
187 gPad->Remove(fFrame);
188 gPad->GetListOfPrimitives()->Clear();
189 if (fFrame)
190 gPad->Add(fFrame);
191
192 auto lnk = list->FirstLink();
193 while(lnk) {
194 gPad->Add(lnk->GetObject(), lnk->GetAddOption());
195 lnk = lnk->Next();
196 }
197
198 return kTRUE;
199}
200
201
202////////////////////////////////////////////////////////////////////////////////
203/// Method used for implementing animation of TGraphTime
204
206{
207 if ((fAnimateCnt < 0) || !fSteps || !gPad)
208 return kTRUE;
209
210 if (fAnimateCnt > fSteps->GetLast())
211 fAnimateCnt = 0;
212
213 if (DrawStep(fAnimateCnt++))
214 gPad->Update();
215
216 return kTRUE;
217}
218
219
220////////////////////////////////////////////////////////////////////////////////
221/// Paint all objects added to each time step
222
224{
225 Error("Paint", "Not implemented, use Draw() instead");
226}
227
228
229////////////////////////////////////////////////////////////////////////////////
230/// Save this object to filename as an animated gif file
231/// if filename is specified it must be of the form xxx.gif
232/// otherwise a file yyy.gif is produced where yyy is the object name
233
235{
236 if (!gPad) {
237 Error("SaveAnimatedGif", "Not possible to create animated GIF without gPad");
238 return;
239 }
240
241 if (gPad->IsWeb()) {
242 Error("SaveAnimatedGif", "Not possible to create animated GIF with web canvas");
243 return;
244 }
245
247
248 for (Int_t s = 0; s < fNsteps; s++) {
249 if (DrawStep(s))
250 gPad->Print(farg.Data());
251 }
252}
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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:411
R__EXTERN TSystem * gSystem
Definition TSystem.h:572
#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:927
void SetTitle(const char *title) override
Change/set the title.
Definition TH1.cxx:6753
virtual void SetMaximum(Double_t maximum=-1111)
Definition TH1.h:653
virtual void SetMinimum(Double_t minimum=-1111)
Definition TH1.h:654
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition TH1.cxx:9018
A doubly linked list.
Definition TList.h:38
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:49
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:50
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 Bool_t Notify()
This method must be overridden to handle object notification (the base implementation is no-op).
Definition TObject.cxx:612
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1057
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
Basic string class.
Definition TString.h:138
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:2384
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
Definition TSystem.cxx:435
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:216
virtual void Stop()
Definition TTimer.h:94