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
23
24/** \class TTVRecord
25I/O classes for TreeViewer session handling.
26*/
27
28////////////////////////////////////////////////////////////////////////////////
29/// TTVRecord default constructor
30
32{
33 fName = "";
34 fScanRedirected = false;
35 fCutEnabled = true;
36 fUserCode = "";
37 fAutoexec = false;
38}
39
40////////////////////////////////////////////////////////////////////////////////
41/// Execute user-defined code
42
44{
45 if (fUserCode.Length()) {
46 char code[250];
47 code[0] = 0;
48 snprintf(code,250, "%s", fUserCode.Data());
49 gInterpreter->ProcessLine(code);
50 }
51}
52
53////////////////////////////////////////////////////////////////////////////////
54/// Populate members from treeviewer tv
55
57{
58 if (!tv) return;
59 fX = tv->ExpressionItem(0)->GetTrueName();
60 fXAlias = tv->ExpressionItem(0)->GetAlias();
61 fY = tv->ExpressionItem(1)->GetTrueName();
62 fYAlias = tv->ExpressionItem(1)->GetAlias();
63 fZ = tv->ExpressionItem(2)->GetTrueName();
64 fZAlias = tv->ExpressionItem(2)->GetAlias();
65 fCut = tv->ExpressionItem(3)->GetTrueName();
66 fCutAlias = tv->ExpressionItem(3)->GetAlias();
67 fOption = tv->GetGrOpt();
68 fScanRedirected = tv->IsScanRedirected();
69 fCutEnabled = tv->IsCutEnabled();
70}
71
72////////////////////////////////////////////////////////////////////////////////
73/// Change treeviewer status to this record
74
76{
78 // change X expression
79 item = tv->ExpressionItem(0);
80 item->SetExpression(fX.Data(), fXAlias.Data());
81 item = tv->ExpressionItem(1);
82 item->SetExpression(fY.Data(), fYAlias.Data());
83 item = tv->ExpressionItem(2);
84 item->SetExpression(fZ.Data(), fZAlias.Data());
85 item = tv->ExpressionItem(3);
86 item->SetExpression(fCut.Data(), fCutAlias.Data());
87 tv->SetGrOpt(fOption.Data());
88 tv->SetScanRedirect(fScanRedirected);
89 tv->SetCutMode(fCutEnabled);
90 if (fCutEnabled)
91 item->SetSmallPic(gClient->GetPicture("cut_t.xpm"));
92 else
93 item->SetSmallPic(gClient->GetPicture("cut-disable_t.xpm"));
94}
95
96////////////////////////////////////////////////////////////////////////////////
97/// Save the TTVRecord in a C++ macro file
98
99void TTVRecord::SaveSource(std::ofstream &out)
100{
101 char quote = '"';
102 out <<"//--- tree viewer record"<<std::endl;
103 out <<" tv_record = tv_session->AddRecord(true);"<<std::endl;
104 out <<" tv_session->SetRecordName("<<quote<<GetName()<<quote<<");"<<std::endl;
105 out <<" tv_record->fX = "<<quote<<fX.Data()<<quote<<";"<<std::endl;
106 out <<" tv_record->fY = "<<quote<<fY.Data()<<quote<<";"<<std::endl;
107 out <<" tv_record->fZ = "<<quote<<fZ.Data()<<quote<<";"<<std::endl;
108 out <<" tv_record->fCut = "<<quote<<fCut.Data()<<quote<<";"<<std::endl;
109 out <<" tv_record->fXAlias = "<<quote<<fXAlias.Data()<<quote<<";"<<std::endl;
110 out <<" tv_record->fYAlias = "<<quote<<fYAlias.Data()<<quote<<";"<<std::endl;
111 out <<" tv_record->fZAlias = "<<quote<<fZAlias.Data()<<quote<<";"<<std::endl;
112 out <<" tv_record->fCutAlias = "<<quote<<fCutAlias.Data()<<quote<<";"<<std::endl;
113 out <<" tv_record->fOption = "<<quote<<fOption.Data()<<quote<<";"<<std::endl;
114 if (fScanRedirected)
115 out <<" tv_record->fScanRedirected = true;"<<std::endl;
116 else
117 out <<" tv_record->fScanRedirected = false;"<<std::endl;
118 if (fCutEnabled)
119 out <<" tv_record->fCutEnabled = true;"<<std::endl;
120 else
121 out <<" tv_record->fCutEnabled = false;"<<std::endl;
122 if (fUserCode.Length()) {
123 out <<" tv_record->SetUserCode(\""<<fUserCode.Data()<<"\");"<<std::endl;
124 if (fAutoexec) {
125 out <<" tv_record->SetAutoexec();"<<std::endl;
126 }
127 }
128}
129
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;
165 if (fRecords > 1) fViewer->ActivateButtons(true, true, false, true);
166 else fViewer->ActivateButtons(true, false, false, true);
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 nullptr;
189 fCurrent = i;
190 if (i < 0) fCurrent = 0;
191 if (i > fRecords-1) fCurrent = fRecords - 1;
192 if (fCurrent>0 && fCurrent<fRecords-1)
193 fViewer->ActivateButtons(true, true, true, true);
194 if (fCurrent == 0) {
195 if (fRecords > 1) fViewer->ActivateButtons(true, false, true, true);
196 else fViewer->ActivateButtons(true, false, false, true);
197 }
198 if (fCurrent == fRecords-1) {
199 if (fRecords > 1) fViewer->ActivateButtons(true, true, false, true);
200 else fViewer->ActivateButtons(true, false, false, true);
201 }
204}
205
206////////////////////////////////////////////////////////////////////////////////
207/// Set record name
208
210{
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;
231 fCurrent = crt;
232 if (!fRecords) {
233 fViewer->ActivateButtons(false, false, false, false);
234 return;
235 }
237}
238
239////////////////////////////////////////////////////////////////////////////////
240/// Display record rec
241
243{
244 rec->PlugIn(fViewer);
246 if (rec->HasUserCode() && rec->MustExecuteCode()) rec->ExecuteUserCode();
247 fViewer->SetHistogramTitle(rec->GetName());
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;
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
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define gClient
Definition TGClient.h:157
char name[80]
Definition TGX11.cxx:110
#define gInterpreter
TTVSession and TTVRecord - I/O classes for TreeViewer session handling.
#define snprintf
Definition civetweb.c:1579
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:243
Basic string class.
Definition TString.h:138
Ssiz_t Length() const
Definition TString.h:425
const char * Data() const
Definition TString.h:384
This class represent entries that goes into the TreeViewer listview container.
I/O classes for TreeViewer session handling.
Definition TTVSession.h:25
TString fXAlias
X alias.
Definition TTVSession.h:30
TString fName
Name of this record.
Definition TTVSession.h:28
TString fZ
Z expression.
Definition TTVSession.h:33
TString fCutAlias
Cut alias.
Definition TTVSession.h:36
bool fScanRedirected
Redirect switch.
Definition TTVSession.h:38
TString fX
X expression.
Definition TTVSession.h:29
bool fCutEnabled
True if current cut is active.
Definition TTVSession.h:39
void ExecuteUserCode()
Execute user-defined code.
void SetName(const char *name="")
Definition TTVSession.h:58
void SaveSource(std::ofstream &out)
Save the TTVRecord in a C++ macro file.
bool fAutoexec
Autoexecute user code command.
Definition TTVSession.h:41
void FormFrom(TTreeViewer *tv)
Populate members from treeviewer tv.
TString fZAlias
Z alias.
Definition TTVSession.h:34
TString fYAlias
Y alias.
Definition TTVSession.h:32
TString fUserCode
Command executed when record is connected.
Definition TTVSession.h:40
const char * GetName() const override
Returns name of object.
Definition TTVSession.h:53
void PlugIn(TTreeViewer *tv)
Change treeviewer status to this record.
TTVRecord()
Default constructor.
TString fCut
Cut expression.
Definition TTVSession.h:35
TString fOption
Graphic option.
Definition TTVSession.h:37
TString fY
Y expression.
Definition TTVSession.h:31
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:76
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:74
Int_t fCurrent
Index of current record.
Definition TTVSession.h:77
TString fName
Name of this session.
Definition TTVSession.h:75
~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:78
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)
void ActivateButtons(bool first, bool previous, bool next, bool last)
void ExecuteDraw()
void UpdateCombo()