Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 <iostream>
14#include <fstream>
15#include "TTVSession.h"
16#include "TTreeViewer.h"
17#include "TTVLVContainer.h"
18#include "TClonesArray.h"
19#include "TInterpreter.h"
20#include "snprintf.h"
21
22
24
25/** \class TTVRecord
26I/O classes for TreeViewer session handling.
27*/
28
29////////////////////////////////////////////////////////////////////////////////
30/// TTVRecord default constructor
31
33{
34 fName = "";
37 fUserCode = "";
39}
40
41////////////////////////////////////////////////////////////////////////////////
42/// Execute user-defined code
43
45{
46 if (fUserCode.Length()) {
47 char code[250];
48 code[0] = 0;
49 snprintf(code,250, "%s", fUserCode.Data());
50 gInterpreter->ProcessLine(code);
51 }
52}
53
54////////////////////////////////////////////////////////////////////////////////
55/// Populate members from treeviewer tv
56
58{
59 if (!tv) return;
60 fX = tv->ExpressionItem(0)->GetTrueName();
62 fY = tv->ExpressionItem(1)->GetTrueName();
64 fZ = tv->ExpressionItem(2)->GetTrueName();
68 fOption = tv->GetGrOpt();
71}
72
73////////////////////////////////////////////////////////////////////////////////
74/// Change treeviewer status to this record
75
77{
78 TTVLVEntry *item;
79 // change X expression
80 item = tv->ExpressionItem(0);
81 item->SetExpression(fX.Data(), fXAlias.Data());
82 item = tv->ExpressionItem(1);
83 item->SetExpression(fY.Data(), fYAlias.Data());
84 item = tv->ExpressionItem(2);
85 item->SetExpression(fZ.Data(), fZAlias.Data());
86 item = tv->ExpressionItem(3);
88 tv->SetGrOpt(fOption.Data());
91 if (fCutEnabled)
92 item->SetSmallPic(gClient->GetPicture("cut_t.xpm"));
93 else
94 item->SetSmallPic(gClient->GetPicture("cut-disable_t.xpm"));
95}
96
97////////////////////////////////////////////////////////////////////////////////
98/// Save the TTVRecord in a C++ macro file
99
100void TTVRecord::SaveSource(std::ofstream &out)
101{
102 char quote = '"';
103 out <<"//--- tree viewer record"<<std::endl;
104 out <<" tv_record = tv_session->AddRecord(kTRUE);"<<std::endl;
105 out <<" tv_session->SetRecordName("<<quote<<GetName()<<quote<<");"<<std::endl;
106 out <<" tv_record->fX = "<<quote<<fX.Data()<<quote<<";"<<std::endl;
107 out <<" tv_record->fY = "<<quote<<fY.Data()<<quote<<";"<<std::endl;
108 out <<" tv_record->fZ = "<<quote<<fZ.Data()<<quote<<";"<<std::endl;
109 out <<" tv_record->fCut = "<<quote<<fCut.Data()<<quote<<";"<<std::endl;
110 out <<" tv_record->fXAlias = "<<quote<<fXAlias.Data()<<quote<<";"<<std::endl;
111 out <<" tv_record->fYAlias = "<<quote<<fYAlias.Data()<<quote<<";"<<std::endl;
112 out <<" tv_record->fZAlias = "<<quote<<fZAlias.Data()<<quote<<";"<<std::endl;
113 out <<" tv_record->fCutAlias = "<<quote<<fCutAlias.Data()<<quote<<";"<<std::endl;
114 out <<" tv_record->fOption = "<<quote<<fOption.Data()<<quote<<";"<<std::endl;
115 if (fScanRedirected)
116 out <<" tv_record->fScanRedirected = kTRUE;"<<std::endl;
117 else
118 out <<" tv_record->fScanRedirected = kFALSE;"<<std::endl;
119 if (fCutEnabled)
120 out <<" tv_record->fCutEnabled = kTRUE;"<<std::endl;
121 else
122 out <<" tv_record->fCutEnabled = kFALSE;"<<std::endl;
123 if (fUserCode.Length()) {
124 out <<" tv_record->SetUserCode(\""<<fUserCode.Data()<<"\");"<<std::endl;
125 if (fAutoexec) {
126 out <<" tv_record->SetAutoexec();"<<std::endl;
127 }
128 }
129}
130
132
133/** \class TTVSession
134I/O classes for TreeViewer session handling.
135*/
136
137////////////////////////////////////////////////////////////////////////////////
138/// Constructor
139
141{
142 fName = "";
143 fList = new TClonesArray("TTVRecord", 100); // is 100 enough ?
144 fViewer = tv;
145 fCurrent = 0;
146 fRecords = 0;
147}
148
149////////////////////////////////////////////////////////////////////////////////
150/// Destructor
151
153{
154 fList->Delete();
155 delete fList;
156}
157
158////////////////////////////////////////////////////////////////////////////////
159/// Add a record
160
162{
163 TClonesArray &list = *fList;
164 TTVRecord *newrec = new(list[fRecords++])TTVRecord();
165 if (!fromFile) newrec->FormFrom(fViewer);
166 fCurrent = fRecords - 1;
169 if (!fromFile) {
170 TString name = "";
171 if (strlen(newrec->GetZ())) name += newrec->GetZ();
172 if (strlen(newrec->GetY())) {
173 if (name.Length()) name += ":";
174 name += newrec->GetY();
175 }
176 if (strlen(newrec->GetX())) {
177 if (name.Length()) name += ":";
178 name += newrec->GetX();
179 }
180 SetRecordName(name.Data());
181 }
182 return newrec;
183}
184
185////////////////////////////////////////////////////////////////////////////////
186/// Return record at index i
187
189{
190 if (!fRecords) return 0;
191 fCurrent = i;
192 if (i < 0) fCurrent = 0;
193 if (i > fRecords-1) fCurrent = fRecords - 1;
194 if (fCurrent>0 && fCurrent<fRecords-1)
196 if (fCurrent == 0) {
199 }
200 if (fCurrent == fRecords-1) {
203 }
206}
207
208////////////////////////////////////////////////////////////////////////////////
209/// Set record name
210
212{
213 Int_t crt = fCurrent;
214 TTVRecord *current = GetRecord(fCurrent);
215 current->SetName(name);
217 fCurrent = crt;
219}
220
221////////////////////////////////////////////////////////////////////////////////
222/// Remove current record from list
223
225{
226 if (!fRecords) return;
228 delete rec;
230 if (fCurrent > fRecords-1) fCurrent = fRecords - 1;
231 Int_t crt = fCurrent;
233 fCurrent = crt;
234 if (!fRecords) {
236 return;
237 }
239}
240
241////////////////////////////////////////////////////////////////////////////////
242/// Display record rec
243
245{
246 rec->PlugIn(fViewer);
248 if (rec->HasUserCode() && rec->MustExecuteCode()) rec->ExecuteUserCode();
250}
251
252////////////////////////////////////////////////////////////////////////////////
253/// Save the TTVSession in a C++ macro file
254
255void TTVSession::SaveSource(std::ofstream &out)
256{
257 out<<"//--- session object"<<std::endl;
258 out<<" TTVSession* tv_session = new TTVSession(treeview);"<<std::endl;
259 out<<" treeview->SetSession(tv_session);"<<std::endl;
260 TTVRecord *record;
261 for (Int_t i=0; i<fRecords; i++) {
262 record = GetRecord(i);
263 record->SaveSource(out);
264 }
265 out<<"//--- Connect first record"<<std::endl;
266 out<<" tv_session->First();"<<std::endl;
267}
268
269////////////////////////////////////////////////////////////////////////////////
270/// Updates current record according to new X, Y, Z settings
271
273{
275 current->FormFrom(fViewer);
277}
278
const Bool_t kFALSE
Definition RtypesCore.h:92
const Bool_t kTRUE
Definition RtypesCore.h:91
#define ClassImp(name)
Definition Rtypes.h:364
#define gClient
Definition TGClient.h:166
char name[80]
Definition TGX11.cxx:110
#define gInterpreter
#define snprintf
Definition civetweb.c:1540
An array of clone (identical) objects.
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:90
friend class TClonesArray
Definition TObject.h:228
Basic string class.
Definition TString.h:136
Ssiz_t Length() const
Definition TString.h:410
const char * Data() const
Definition TString.h:369
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:29
TString fXAlias
Definition TTVSession.h:33
Bool_t MustExecuteCode() const
Definition TTVSession.h:55
Bool_t fScanRedirected
Definition TTVSession.h:38
TString fName
Definition TTVSession.h:32
TString fZ
Definition TTVSession.h:35
Bool_t fCutEnabled
Definition TTVSession.h:39
TString fCutAlias
Definition TTVSession.h:36
TString fX
Definition TTVSession.h:33
void ExecuteUserCode()
Execute user-defined code.
const char * GetY() const
Definition TTVSession.h:50
Bool_t HasUserCode() const
Definition TTVSession.h:54
void SetName(const char *name="")
Definition TTVSession.h:57
void SaveSource(std::ofstream &out)
Save the TTVRecord in a C++ macro file.
Bool_t fAutoexec
Definition TTVSession.h:41
void FormFrom(TTreeViewer *tv)
Populate members from treeviewer tv.
const char * GetX() const
Definition TTVSession.h:49
virtual const char * GetName() const
Returns name of object.
Definition TTVSession.h:52
TString fZAlias
Definition TTVSession.h:35
TString fYAlias
Definition TTVSession.h:34
TString fUserCode
Definition TTVSession.h:40
void PlugIn(TTreeViewer *tv)
Change treeviewer status to this record.
TTVRecord()
TTVRecord default constructor.
TString fCut
Definition TTVSession.h:36
TString fOption
Definition TTVSession.h:37
TString fY
Definition TTVSession.h:34
const char * GetZ() const
Definition TTVSession.h:51
I/O classes for TreeViewer session handling.
Definition TTVSession.h:70
TTVSession(TTreeViewer *tv)
Constructor.
void SaveSource(std::ofstream &out)
Save the TTVSession in a C++ macro file.
~TTVSession()
Destructor.
TTVRecord * GetRecord(Int_t i)
Return record at index i.
TTreeViewer * fViewer
Definition TTVSession.h:75
void SetRecordName(const char *name)
Set record name.
void Show(TTVRecord *rec)
Display record rec.
TClonesArray * fList
Definition TTVSession.h:73
Int_t fCurrent
Definition TTVSession.h:76
TString fName
Definition TTVSession.h:74
void RemoveLastRecord()
Remove current record from list.
TTVRecord * AddRecord(Bool_t fromFile=kFALSE)
Add a record.
void UpdateRecord(const char *name)
Updates current record according to new X, Y, Z settings.
Int_t fRecords
Definition TTVSession.h:77
A graphic user interface designed to handle ROOT trees and to take advantage of TTree class features.
Definition TTreeViewer.h:54
void SetCurrentRecord(Long64_t entry)
void SetHistogramTitle(const char *title)
Bool_t IsScanRedirected()
TTVLVEntry * ExpressionItem(Int_t index)
void SetScanRedirect(Bool_t mode)
void ExecuteDraw()
void UpdateCombo()
const char * GetGrOpt()
void ActivateButtons(Bool_t first, Bool_t previous, Bool_t next, Bool_t last)
void SetGrOpt(const char *option)
void SetCutMode(Bool_t enabled=kTRUE)
Bool_t IsCutEnabled()