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 = "";
35 fScanRedirected = false;
36 fCutEnabled = true;
37 fUserCode = "";
38 fAutoexec = false;
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(true);"<<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 = true;"<<std::endl;
117 else
118 out <<" tv_record->fScanRedirected = false;"<<std::endl;
119 if (fCutEnabled)
120 out <<" tv_record->fCutEnabled = true;"<<std::endl;
121 else
122 out <<" tv_record->fCutEnabled = false;"<<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;
167 if (fRecords > 1) fViewer->ActivateButtons(true, true, false, true);
168 else fViewer->ActivateButtons(true, false, false, true);
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 nullptr;
191 fCurrent = i;
192 if (i < 0) fCurrent = 0;
193 if (i > fRecords-1) fCurrent = fRecords - 1;
194 if (fCurrent>0 && fCurrent<fRecords-1)
195 fViewer->ActivateButtons(true, true, true, true);
196 if (fCurrent == 0) {
197 if (fRecords > 1) fViewer->ActivateButtons(true, false, true, true);
198 else fViewer->ActivateButtons(true, false, false, true);
199 }
200 if (fCurrent == fRecords-1) {
201 if (fRecords > 1) fViewer->ActivateButtons(true, true, false, true);
202 else fViewer->ActivateButtons(true, false, false, true);
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) {
235 fViewer->ActivateButtons(false, false, false, false);
236 return;
237 }
239}
240
241////////////////////////////////////////////////////////////////////////////////
242/// Display record rec
243
245{
246 rec->PlugIn(fViewer);
248 if (rec->HasUserCode() && rec->MustExecuteCode()) rec->ExecuteUserCode();
249 fViewer->SetHistogramTitle(rec->GetName());
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
#define ClassImp(name)
Definition Rtypes.h:382
#define gClient
Definition TGClient.h:157
char name[80]
Definition TGX11.cxx:110
#define gInterpreter
#define snprintf
Definition civetweb.c:1540
An array of clone (identical) objects.
TObject * RemoveAt(Int_t idx) override
Remove object at index idx.
void Delete(Option_t *option="") override
Clear the clones array.
TObject * UncheckedAt(Int_t i) const
Definition TObjArray.h:84
friend class TClonesArray
Definition TObject.h:240
Basic string class.
Definition TString.h:139
Ssiz_t Length() const
Definition TString.h:417
const char * Data() const
Definition TString.h:376
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 cutType=false)
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
X alias.
Definition TTVSession.h:34
TString fName
Name of this record.
Definition TTVSession.h:32
TString fZ
Z expression.
Definition TTVSession.h:37
TString fCutAlias
Cut alias.
Definition TTVSession.h:40
bool fScanRedirected
Redirect switch.
Definition TTVSession.h:42
TString fX
X expression.
Definition TTVSession.h:33
bool fCutEnabled
True if current cut is active.
Definition TTVSession.h:43
void ExecuteUserCode()
Execute user-defined code.
const char * GetY() const
Definition TTVSession.h:55
void SetName(const char *name="")
Definition TTVSession.h:62
void SaveSource(std::ofstream &out)
Save the TTVRecord in a C++ macro file.
bool fAutoexec
Autoexecute user code command.
Definition TTVSession.h:45
void FormFrom(TTreeViewer *tv)
Populate members from treeviewer tv.
const char * GetX() const
Definition TTVSession.h:54
TString fZAlias
Z alias.
Definition TTVSession.h:38
TString fYAlias
Y alias.
Definition TTVSession.h:36
TString fUserCode
Command executed when record is connected.
Definition TTVSession.h:44
const char * GetName() const override
Returns name of object.
Definition TTVSession.h:57
void PlugIn(TTreeViewer *tv)
Change treeviewer status to this record.
TTVRecord()
Default constructor.
TString fCut
Cut expression.
Definition TTVSession.h:39
TString fOption
Graphic option.
Definition TTVSession.h:41
TString fY
Y expression.
Definition TTVSession.h:35
const char * GetZ() const
Definition TTVSession.h:56
I/O classes for TreeViewer session handling.
Definition TTVSession.h:75
TTVSession(TTreeViewer *tv)
Constructor.
void SaveSource(std::ofstream &out)
Save the TTVSession in a C++ macro file.
TTVRecord * GetRecord(Int_t i)
Return record at index i.
TTreeViewer * fViewer
Associated tree viewer.
Definition TTVSession.h:80
void SetRecordName(const char *name)
Set record name.
void Show(TTVRecord *rec)
Display record rec.
TTVRecord * AddRecord(bool fromFile=false)
Add a record.
TClonesArray * fList
List of TV records.
Definition TTVSession.h:78
Int_t fCurrent
Index of current record.
Definition TTVSession.h:81
TString fName
Name of this session.
Definition TTVSession.h:79
~TTVSession() override
Destructor.
void RemoveLastRecord()
Remove current record from list.
void UpdateRecord(const char *name)
Updates current record according to new X, Y, Z settings.
Int_t fRecords
Number of records.
Definition TTVSession.h:82
A graphic user interface designed to handle ROOT trees and to take advantage of TTree class features.
Definition TTreeViewer.h:54
void SetScanRedirect(bool mode)
void SetCurrentRecord(Long64_t entry)
void SetHistogramTitle(const char *title)
void SetCutMode(bool enabled=true)
TTVLVEntry * ExpressionItem(Int_t index)
void ActivateButtons(bool first, bool previous, bool next, bool last)
void ExecuteDraw()
void UpdateCombo()
const char * GetGrOpt()
void SetGrOpt(const char *option)
bool IsCutEnabled()
bool IsScanRedirected()