Logo ROOT   6.16/01
Reference Guide
TTVSession.cxx
Go to the documentation of this file.
1// @(#)root/treeviewer:$Id$
2//Author : Andrei Gheata 21/02/01
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, 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
13#include "Riostream.h"
14#include "TTVSession.h"
15#include "TTreeViewer.h"
16#include "TTVLVContainer.h"
17#include "TClonesArray.h"
18#include "TInterpreter.h"
19
20
22
23/** \class TTVRecord
24I/O classes for TreeViewer session handling.
25*/
26
27////////////////////////////////////////////////////////////////////////////////
28/// TTVRecord default constructor
29
31{
32 fName = "";
35 fUserCode = "";
37}
38
39////////////////////////////////////////////////////////////////////////////////
40/// Execute user-defined code
41
43{
44 if (fUserCode.Length()) {
45 char code[250];
46 code[0] = 0;
47 snprintf(code,250, "%s", fUserCode.Data());
48 gInterpreter->ProcessLine(code);
49 }
50}
51
52////////////////////////////////////////////////////////////////////////////////
53/// Populate members from treeviewer tv
54
56{
57 if (!tv) return;
58 fX = tv->ExpressionItem(0)->GetTrueName();
60 fY = tv->ExpressionItem(1)->GetTrueName();
62 fZ = tv->ExpressionItem(2)->GetTrueName();
66 fOption = tv->GetGrOpt();
69}
70
71////////////////////////////////////////////////////////////////////////////////
72/// Change treeviewer status to this record
73
75{
76 TTVLVEntry *item;
77 // change X expression
78 item = tv->ExpressionItem(0);
79 item->SetExpression(fX.Data(), fXAlias.Data());
80 item = tv->ExpressionItem(1);
81 item->SetExpression(fY.Data(), fYAlias.Data());
82 item = tv->ExpressionItem(2);
83 item->SetExpression(fZ.Data(), fZAlias.Data());
84 item = tv->ExpressionItem(3);
86 tv->SetGrOpt(fOption.Data());
89 if (fCutEnabled)
90 item->SetSmallPic(gClient->GetPicture("cut_t.xpm"));
91 else
92 item->SetSmallPic(gClient->GetPicture("cut-disable_t.xpm"));
93}
94
95////////////////////////////////////////////////////////////////////////////////
96/// Save the TTVRecord in a C++ macro file
97
98void TTVRecord::SaveSource(std::ofstream &out)
99{
100 char quote = '"';
101 out <<"//--- tree viewer record"<<std::endl;
102 out <<" tv_record = tv_session->AddRecord(kTRUE);"<<std::endl;
103 out <<" tv_session->SetRecordName("<<quote<<GetName()<<quote<<");"<<std::endl;
104 out <<" tv_record->fX = "<<quote<<fX.Data()<<quote<<";"<<std::endl;
105 out <<" tv_record->fY = "<<quote<<fY.Data()<<quote<<";"<<std::endl;
106 out <<" tv_record->fZ = "<<quote<<fZ.Data()<<quote<<";"<<std::endl;
107 out <<" tv_record->fCut = "<<quote<<fCut.Data()<<quote<<";"<<std::endl;
108 out <<" tv_record->fXAlias = "<<quote<<fXAlias.Data()<<quote<<";"<<std::endl;
109 out <<" tv_record->fYAlias = "<<quote<<fYAlias.Data()<<quote<<";"<<std::endl;
110 out <<" tv_record->fZAlias = "<<quote<<fZAlias.Data()<<quote<<";"<<std::endl;
111 out <<" tv_record->fCutAlias = "<<quote<<fCutAlias.Data()<<quote<<";"<<std::endl;
112 out <<" tv_record->fOption = "<<quote<<fOption.Data()<<quote<<";"<<std::endl;
113 if (fScanRedirected)
114 out <<" tv_record->fScanRedirected = kTRUE;"<<std::endl;
115 else
116 out <<" tv_record->fScanRedirected = kFALSE;"<<std::endl;
117 if (fCutEnabled)
118 out <<" tv_record->fCutEnabled = kTRUE;"<<std::endl;
119 else
120 out <<" tv_record->fCutEnabled = kFALSE;"<<std::endl;
121 if (fUserCode.Length()) {
122 out <<" tv_record->SetUserCode(\""<<fUserCode.Data()<<"\");"<<std::endl;
123 if (fAutoexec) {
124 out <<" tv_record->SetAutoexec();"<<std::endl;
125 }
126 }
127}
128
130
131/** \class TTVSession
132I/O classes for TreeViewer session handling.
133*/
134
135////////////////////////////////////////////////////////////////////////////////
136/// Constructor
137
139{
140 fName = "";
141 fList = new TClonesArray("TTVRecord", 100); // is 100 enough ?
142 fViewer = tv;
143 fCurrent = 0;
144 fRecords = 0;
145}
146
147////////////////////////////////////////////////////////////////////////////////
148/// Destructor
149
151{
152 fList->Delete();
153 delete fList;
154}
155
156////////////////////////////////////////////////////////////////////////////////
157/// Add a record
158
160{
161 TClonesArray &list = *fList;
162 TTVRecord *newrec = new(list[fRecords++])TTVRecord();
163 if (!fromFile) newrec->FormFrom(fViewer);
164 fCurrent = fRecords - 1;
167 if (!fromFile) {
168 TString name = "";
169 if (strlen(newrec->GetZ())) name += newrec->GetZ();
170 if (strlen(newrec->GetY())) {
171 if (name.Length()) name += ":";
172 name += newrec->GetY();
173 }
174 if (strlen(newrec->GetX())) {
175 if (name.Length()) name += ":";
176 name += newrec->GetX();
177 }
178 SetRecordName(name.Data());
179 }
180 return newrec;
181}
182
183////////////////////////////////////////////////////////////////////////////////
184/// Return record at index i
185
187{
188 if (!fRecords) return 0;
189 fCurrent = i;
190 if (i < 0) fCurrent = 0;
191 if (i > fRecords-1) fCurrent = fRecords - 1;
192 if (fCurrent>0 && fCurrent<fRecords-1)
194 if (fCurrent == 0) {
197 }
198 if (fCurrent == fRecords-1) {
201 }
204}
205
206////////////////////////////////////////////////////////////////////////////////
207/// Set record name
208
210{
211 Int_t crt = fCurrent;
212 TTVRecord *current = GetRecord(fCurrent);
213 current->SetName(name);
215 fCurrent = crt;
217}
218
219////////////////////////////////////////////////////////////////////////////////
220/// Remove current record from list
221
223{
224 if (!fRecords) return;
226 delete rec;
228 if (fCurrent > fRecords-1) fCurrent = fRecords - 1;
229 Int_t crt = fCurrent;
231 fCurrent = crt;
232 if (!fRecords) {
234 return;
235 }
237}
238
239////////////////////////////////////////////////////////////////////////////////
240/// Display record rec
241
243{
244 rec->PlugIn(fViewer);
246 if (rec->HasUserCode() && rec->MustExecuteCode()) rec->ExecuteUserCode();
248}
249
250////////////////////////////////////////////////////////////////////////////////
251/// Save the TTVSession in a C++ macro file
252
253void TTVSession::SaveSource(std::ofstream &out)
254{
255 out<<"//--- session object"<<std::endl;
256 out<<" TTVSession* tv_session = new TTVSession(treeview);"<<std::endl;
257 out<<" treeview->SetSession(tv_session);"<<std::endl;
258 TTVRecord *record;
259 for (Int_t i=0; i<fRecords; i++) {
260 record = GetRecord(i);
261 record->SaveSource(out);
262 }
263 out<<"//--- Connect first record"<<std::endl;
264 out<<" tv_session->First();"<<std::endl;
265}
266
267////////////////////////////////////////////////////////////////////////////////
268/// Updates current record according to new X, Y, Z settings
269
271{
273 current->FormFrom(fViewer);
275}
276
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:363
#define gClient
Definition: TGClient.h:166
#define gInterpreter
Definition: TInterpreter.h:538
#define snprintf
Definition: civetweb.c:1540
An array of clone (identical) objects.
Definition: TClonesArray.h:32
virtual void Delete(Option_t *option="")
Clear the clones array.
virtual TObject * RemoveAt(Int_t idx)
Remove object at index idx.
TObject * UncheckedAt(Int_t i) const
Definition: TObjArray.h:89
friend class TClonesArray
Definition: TObject.h:213
Basic string class.
Definition: TString.h:131
Ssiz_t Length() const
Definition: TString.h:405
const char * Data() const
Definition: TString.h:364
This class represent entries that goes into the TreeViewer listview container.
void SetSmallPic(const TGPicture *spic)
Set small picture.
void SetExpression(const char *name, const char *alias, Bool_t cutType=kFALSE)
Set the true name, alias and type of the expression, then refresh it.
const char * GetAlias()
const char * GetTrueName()
I/O classes for TreeViewer session handling.
Definition: TTVSession.h:28
TString fXAlias
Definition: TTVSession.h:32
Bool_t MustExecuteCode() const
Definition: TTVSession.h:54
Bool_t fScanRedirected
Definition: TTVSession.h:37
TString fName
Definition: TTVSession.h:31
TString fZ
Definition: TTVSession.h:34
Bool_t fCutEnabled
Definition: TTVSession.h:38
TString fCutAlias
Definition: TTVSession.h:35
TString fX
Definition: TTVSession.h:32
void ExecuteUserCode()
Execute user-defined code.
Definition: TTVSession.cxx:42
const char * GetY() const
Definition: TTVSession.h:49
Bool_t HasUserCode() const
Definition: TTVSession.h:53
void SetName(const char *name="")
Definition: TTVSession.h:56
void SaveSource(std::ofstream &out)
Save the TTVRecord in a C++ macro file.
Definition: TTVSession.cxx:98
Bool_t fAutoexec
Definition: TTVSession.h:40
void FormFrom(TTreeViewer *tv)
Populate members from treeviewer tv.
Definition: TTVSession.cxx:55
const char * GetX() const
Definition: TTVSession.h:48
virtual const char * GetName() const
Returns name of object.
Definition: TTVSession.h:51
TString fZAlias
Definition: TTVSession.h:34
TString fYAlias
Definition: TTVSession.h:33
TString fUserCode
Definition: TTVSession.h:39
void PlugIn(TTreeViewer *tv)
Change treeviewer status to this record.
Definition: TTVSession.cxx:74
TTVRecord()
TTVRecord default constructor.
Definition: TTVSession.cxx:30
TString fCut
Definition: TTVSession.h:35
TString fOption
Definition: TTVSession.h:36
TString fY
Definition: TTVSession.h:33
const char * GetZ() const
Definition: TTVSession.h:50
I/O classes for TreeViewer session handling.
Definition: TTVSession.h:69
TTVSession(TTreeViewer *tv)
Constructor.
Definition: TTVSession.cxx:138
void SaveSource(std::ofstream &out)
Save the TTVSession in a C++ macro file.
Definition: TTVSession.cxx:253
~TTVSession()
Destructor.
Definition: TTVSession.cxx:150
TTVRecord * GetRecord(Int_t i)
Return record at index i.
Definition: TTVSession.cxx:186
TTreeViewer * fViewer
Definition: TTVSession.h:74
void SetRecordName(const char *name)
Set record name.
Definition: TTVSession.cxx:209
void Show(TTVRecord *rec)
Display record rec.
Definition: TTVSession.cxx:242
TClonesArray * fList
Definition: TTVSession.h:72
Int_t fCurrent
Definition: TTVSession.h:75
TString fName
Definition: TTVSession.h:73
void RemoveLastRecord()
Remove current record from list.
Definition: TTVSession.cxx:222
TTVRecord * AddRecord(Bool_t fromFile=kFALSE)
Add a record.
Definition: TTVSession.cxx:159
void UpdateRecord(const char *name)
Updates current record according to new X, Y, Z settings.
Definition: TTVSession.cxx:270
Int_t fRecords
Definition: TTVSession.h:76
A graphic user interface designed to handle ROOT trees and to take advantage of TTree class features.
Definition: TTreeViewer.h:56
void SetCurrentRecord(Long64_t entry)
Set current record.
void SetHistogramTitle(const char *title)
Set title of Histogram.
Bool_t IsScanRedirected()
Return kTRUE if scan is redirected.
TTVLVEntry * ExpressionItem(Int_t index)
Get the item from a specific position.
void SetScanRedirect(Bool_t mode)
Set the state of Scan check button.
void ExecuteDraw()
Called when the DRAW button is executed.
void UpdateCombo()
Updates combo box to current session entries.
const char * GetGrOpt()
Get graph option.
void ActivateButtons(Bool_t first, Bool_t previous, Bool_t next, Bool_t last)
Enable/disable session buttons.
void SetGrOpt(const char *option)
Set graph option.
void SetCutMode(Bool_t enabled=kTRUE)
Definition: TTreeViewer.h:215
Bool_t IsCutEnabled()
Definition: TTreeViewer.h:203