ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
24 I/O classes for TreeViewer session handling.
25 */
26 
27 ////////////////////////////////////////////////////////////////////////////////
28 /// TTVRecord default constructor
29 
31 {
32  fName = "";
33  fScanRedirected = kFALSE;
34  fCutEnabled = kTRUE;
35  fUserCode = "";
36  fAutoexec = kFALSE;
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();
59  fXAlias = tv->ExpressionItem(0)->GetAlias();
60  fY = tv->ExpressionItem(1)->GetTrueName();
61  fYAlias = tv->ExpressionItem(1)->GetAlias();
62  fZ = tv->ExpressionItem(2)->GetTrueName();
63  fZAlias = tv->ExpressionItem(2)->GetAlias();
64  fCut = tv->ExpressionItem(3)->GetTrueName();
65  fCutAlias = tv->ExpressionItem(3)->GetAlias();
66  fOption = tv->GetGrOpt();
68  fCutEnabled = tv->IsCutEnabled();
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);
85  item->SetExpression(fCut.Data(), fCutAlias.Data());
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 
98 void 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
132 I/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  }
203  return (TTVRecord *)fList->UncheckedAt(fCurrent);
204 }
205 
206 ////////////////////////////////////////////////////////////////////////////////
207 /// Set record name
208 
210 {
211  Int_t crt = fCurrent;
213  current->SetName(name);
214  fViewer->UpdateCombo();
215  fCurrent = crt;
217 }
218 
219 ////////////////////////////////////////////////////////////////////////////////
220 /// Remove current record from list
221 
223 {
224  if (!fRecords) return;
226  delete rec;
227  fList->RemoveAt(fRecords--);
228  if (fCurrent > fRecords-1) fCurrent = fRecords - 1;
229  Int_t crt = fCurrent;
230  fViewer->UpdateCombo();
231  fCurrent = crt;
232  if (!fRecords) {
234  return;
235  }
237 }
238 
239 ////////////////////////////////////////////////////////////////////////////////
240 /// Display record rec
241 
243 {
244  rec->PlugIn(fViewer);
245  fViewer->ExecuteDraw();
246  if (rec->HasUserCode() && rec->MustExecuteCode()) rec->ExecuteUserCode();
248 }
249 
250 ////////////////////////////////////////////////////////////////////////////////
251 /// Save the TTVSession in a C++ macro file
252 
253 void TTVSession::SaveSource(std::ofstream &out)
254 {
255  out<<"//--- session object"<<std::endl;
256  out<<" 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);
274  SetRecordName(name);
275 }
276 
TString fX
Definition: TTVSession.h:34
const char * GetTrueName()
const char * GetAlias()
void ExecuteDraw()
Called when the DRAW button is executed.
Ssiz_t Length() const
Definition: TString.h:390
const char * current
Definition: demos.C:12
TString fYAlias
Definition: TTVSession.h:35
void UpdateCombo()
Updates combo box to current session entries.
Bool_t fScanRedirected
Definition: TTVSession.h:39
void ActivateButtons(Bool_t first, Bool_t previous, Bool_t next, Bool_t last)
Enable/disable session buttons.
Basic string class.
Definition: TString.h:137
#define gClient
Definition: TGClient.h:174
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
TString fOption
Definition: TTVSession.h:38
#define gInterpreter
Definition: TInterpreter.h:502
Int_t fRecords
Definition: TTVSession.h:78
TString fY
Definition: TTVSession.h:35
void RemoveLastRecord()
Remove current record from list.
Definition: TTVSession.cxx:222
const char * Data() const
Definition: TString.h:349
void SetCurrentRecord(Long64_t entry)
Set current record.
TString fXAlias
Definition: TTVSession.h:34
void SetRecordName(const char *name)
Set record name.
Definition: TTVSession.cxx:209
Bool_t MustExecuteCode() const
Definition: TTVSession.h:56
TString fCutAlias
Definition: TTVSession.h:37
A graphic user interface designed to handle ROOT trees and to take advantage of TTree class features...
Definition: TTreeViewer.h:60
const char * GetGrOpt()
Get graph option.
void SaveSource(std::ofstream &out)
Save the TTVSession in a C++ macro file.
Definition: TTVSession.cxx:253
virtual TObject * RemoveAt(Int_t idx)
Remove object at index idx.
const char * GetZ() const
Definition: TTVSession.h:52
char * out
Definition: TBase64.cxx:29
TString fZ
Definition: TTVSession.h:36
~TTVSession()
Destructor.
Definition: TTVSession.cxx:150
TObject * UncheckedAt(Int_t i) const
Definition: TObjArray.h:91
TString fUserCode
Definition: TTVSession.h:41
void SetName(const char *name="")
Definition: TTVSession.h:58
Bool_t fAutoexec
Definition: TTVSession.h:42
void SetCutMode(Bool_t enabled=kTRUE)
Definition: TTreeViewer.h:219
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.
I/O classes for TreeViewer session handling.
Definition: TTVSession.h:30
virtual void Delete(Option_t *option="")
Clear the clones array.
TString fCut
Definition: TTVSession.h:37
TTVRecord * GetRecord(Int_t i)
Return record at index i.
Definition: TTVSession.cxx:186
TTVLVEntry * ExpressionItem(Int_t index)
Get the item from a specific position.
This class represent entries that goes into the TreeViewer listview container.
Bool_t fCutEnabled
Definition: TTVSession.h:40
void SaveSource(std::ofstream &out)
Save the TTVRecord in a C++ macro file.
Definition: TTVSession.cxx:98
void SetHistogramTitle(const char *title)
Set title of Histogram.
Bool_t IsCutEnabled()
Definition: TTreeViewer.h:207
TString fZAlias
Definition: TTVSession.h:36
virtual const char * GetName() const
Returns name of object.
Definition: TTVSession.h:53
#define ClassImp(name)
Definition: Rtypes.h:279
void FormFrom(TTreeViewer *tv)
Populate members from treeviewer tv.
Definition: TTVSession.cxx:55
void SetSmallPic(const TGPicture *spic)
Set small picture.
const char * GetX() const
Definition: TTVSession.h:50
void PlugIn(TTreeViewer *tv)
Change treeviewer status to this record.
Definition: TTVSession.cxx:74
#define name(a, b)
Definition: linkTestLib0.cpp:5
void SetGrOpt(const char *option)
Set graph option.
Bool_t HasUserCode() const
Definition: TTVSession.h:55
void SetScanRedirect(Bool_t mode)
Set the state of Scan check button.
I/O classes for TreeViewer session handling.
Definition: TTVSession.h:71
void UpdateRecord(const char *name)
Updates current record according to new X, Y, Z settings.
Definition: TTVSession.cxx:270
An array of clone (identical) objects.
Definition: TClonesArray.h:32
const char * GetY() const
Definition: TTVSession.h:51
TTreeViewer * fViewer
Definition: TTVSession.h:76
TTVRecord * AddRecord(Bool_t fromFile=kFALSE)
Add a record.
Definition: TTVSession.cxx:159
void ExecuteUserCode()
Execute user-defined code.
Definition: TTVSession.cxx:42
Int_t fCurrent
Definition: TTVSession.h:77
void Show(TTVRecord *rec)
Display record rec.
Definition: TTVSession.cxx:242
const Bool_t kTRUE
Definition: Rtypes.h:91
Bool_t IsScanRedirected()
Return kTRUE if scan is redirected.
TClonesArray * fList
Definition: TTVSession.h:74