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 Hist
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 = 0;
41 fFrame = 0;
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(0);
66}
67
68
69////////////////////////////////////////////////////////////////////////////////
70/// GraphTime default destructor.
71
73{
74 if (!fSteps) return;
75 fSteps->Delete();
76 delete fSteps; fSteps=0;
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(0);
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
103Int_t TGraphTime::Add(const TObject *obj, Int_t slot, Option_t *option)
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 = 0;
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
174void TGraphTime::SaveAnimatedGif(const char *filename) const
175{
176 TObject *frame = gPad->GetPrimitive("frame");
177 TList *list = 0;
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 (strlen(filename) > 0) gPad->Print(Form("%s+",filename));
194 else gPad->Print(Form("%s+",GetName()));
196 }
197 }
198}
double Double_t
Definition RtypesCore.h:59
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:364
float xmin
float ymin
float xmax
float ymax
#define gROOT
Definition TROOT.h:406
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
Definition TSystem.h:559
#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 void Paint(Option_t *chopt="")
Paint all objects added to each time step.
virtual Int_t Add(const TObject *obj, Int_t slot, Option_t *option="")
Add one object to a time slot.
Double_t fXmin
Definition TGraphTime.h:35
Int_t fSleepTime
Definition TGraphTime.h:33
TH1 * fFrame
Definition TGraphTime.h:40
Double_t fYmin
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
Definition TGraphTime.h:36
virtual ~TGraphTime()
GraphTime default destructor.
TGraphTime()
default constructor.
Double_t fYmax
Definition TGraphTime.h:38
TObjArray * fSteps
Definition TGraphTime.h:39
Int_t fNsteps
Definition TGraphTime.h:34
virtual void Draw(Option_t *chopt="")
Draw this TGraphTime.
1-D histogram with a double per channel (see TH1 documentation)}
Definition TH1.h:618
virtual void SetTitle(const char *title)
See GetStatOverflows for more information.
Definition TH1.cxx:6678
virtual void SetMaximum(Double_t maximum=-1111)
Definition TH1.h:398
virtual void SetMinimum(Double_t minimum=-1111)
Definition TH1.h:399
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition TH1.cxx:3073
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition TH1.cxx:8830
A doubly linked list.
Definition TList.h:44
virtual void Add(TObject *obj)
Definition TList.h:87
virtual TObjLink * FirstLink() const
Definition TList.h:108
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
virtual const char * GetTitle() const
Returns title of object.
Definition TNamed.h:48
virtual const char * GetName() const
Returns name of object.
Definition TNamed.h:47
An array of TObjects.
Definition TObjArray.h:37
TObject * UncheckedAt(Int_t i) const
Definition TObjArray.h:90
virtual void Delete(Option_t *option="")
Remove all objects from the array AND delete all heap based objects.
virtual void AddAt(TObject *obj, Int_t idx)
Add object at position ids.
Mother of all ROOT objects.
Definition TObject.h:37
virtual void Clear(Option_t *="")
Definition TObject.h:115
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:879
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition TObject.cxx:197
Basic string class.
Definition TString.h:136
void ToLower()
Change string to lower-case.
Definition TString.cxx:1145
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
Definition TSystem.cxx:438