Logo ROOT   6.14/05
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
24 I/O classes for TreeViewer session handling.
25 */
26 
27 ////////////////////////////////////////////////////////////////////////////////
28 /// TTVRecord default constructor
29 
31 {
32  fName = "";
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;
165  if (fRecords > 1) fViewer->ActivateButtons(kTRUE, kTRUE, kFALSE, kTRUE);
166  else fViewer->ActivateButtons(kTRUE, kFALSE, kFALSE, kTRUE);
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)
193  fViewer->ActivateButtons(kTRUE, kTRUE, kTRUE, kTRUE);
194  if (fCurrent == 0) {
195  if (fRecords > 1) fViewer->ActivateButtons(kTRUE, kFALSE, kTRUE, kTRUE);
196  else fViewer->ActivateButtons(kTRUE, kFALSE, kFALSE, kTRUE);
197  }
198  if (fCurrent == fRecords-1) {
199  if (fRecords > 1) fViewer->ActivateButtons(kTRUE, kTRUE, kFALSE, kTRUE);
200  else fViewer->ActivateButtons(kTRUE, kFALSE, kFALSE, kTRUE);
201  }
202  fViewer->SetCurrentRecord(fCurrent);
203  return (TTVRecord *)fList->UncheckedAt(fCurrent);
204 }
205 
206 ////////////////////////////////////////////////////////////////////////////////
207 /// Set record name
208 
210 {
211  Int_t crt = fCurrent;
212  TTVRecord *current = GetRecord(fCurrent);
213  current->SetName(name);
214  fViewer->UpdateCombo();
215  fCurrent = crt;
216  fViewer->SetCurrentRecord(fCurrent);
217 }
218 
219 ////////////////////////////////////////////////////////////////////////////////
220 /// Remove current record from list
221 
223 {
224  if (!fRecords) return;
225  TTVRecord *rec = (TTVRecord *)fList->UncheckedAt(fRecords);
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) {
233  fViewer->ActivateButtons(kFALSE, kFALSE, kFALSE, kFALSE);
234  return;
235  }
236  GetRecord(fCurrent);
237 }
238 
239 ////////////////////////////////////////////////////////////////////////////////
240 /// Display record rec
241 
243 {
244  rec->PlugIn(fViewer);
245  fViewer->ExecuteDraw();
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 
253 void 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 {
272  TTVRecord *current = (TTVRecord *)fList->UncheckedAt(fCurrent);
273  current->FormFrom(fViewer);
274  SetRecordName(name);
275 }
276 
TString fX
Definition: TTVSession.h:32
const char * GetTrueName()
const char * GetAlias()
TTVRecord()
TTVRecord default constructor.
Definition: TTVSession.cxx:30
TTVSession(TTreeViewer *tv)
Constructor.
Definition: TTVSession.cxx:138
TString fYAlias
Definition: TTVSession.h:33
Bool_t fScanRedirected
Definition: TTVSession.h:37
Basic string class.
Definition: TString.h:131
const char * GetZ() const
Definition: TTVSession.h:50
#define gClient
Definition: TGClient.h:166
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TString fOption
Definition: TTVSession.h:36
#define gInterpreter
Definition: TInterpreter.h:527
TString fY
Definition: TTVSession.h:33
const char * GetX() const
Definition: TTVSession.h:48
void RemoveLastRecord()
Remove current record from list.
Definition: TTVSession.cxx:222
TString fXAlias
Definition: TTVSession.h:32
friend class TClonesArray
Definition: TObject.h:213
void SetRecordName(const char *name)
Set record name.
Definition: TTVSession.cxx:209
TString fCutAlias
Definition: TTVSession.h:35
virtual const char * GetName() const
Returns name of object.
Definition: TTVSession.h:51
A graphic user interface designed to handle ROOT trees and to take advantage of TTree class features...
Definition: TTreeViewer.h:56
const char * GetGrOpt()
Get graph option.
void SaveSource(std::ofstream &out)
Save the TTVSession in a C++ macro file.
Definition: TTVSession.cxx:253
TString fZ
Definition: TTVSession.h:34
~TTVSession()
Destructor.
Definition: TTVSession.cxx:150
TString fUserCode
Definition: TTVSession.h:39
void SetName(const char *name="")
Definition: TTVSession.h:56
Bool_t fAutoexec
Definition: TTVSession.h:40
void SetCutMode(Bool_t enabled=kTRUE)
Definition: TTreeViewer.h:215
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:28
TString fCut
Definition: TTVSession.h:35
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 MustExecuteCode() const
Definition: TTVSession.h:54
Ssiz_t Length() const
Definition: TString.h:405
Bool_t fCutEnabled
Definition: TTVSession.h:38
TString fName
Definition: TTVSession.h:31
void SaveSource(std::ofstream &out)
Save the TTVRecord in a C++ macro file.
Definition: TTVSession.cxx:98
Bool_t IsCutEnabled()
Definition: TTreeViewer.h:203
const Bool_t kFALSE
Definition: RtypesCore.h:88
TString fZAlias
Definition: TTVSession.h:34
Bool_t HasUserCode() const
Definition: TTVSession.h:53
const char * GetY() const
Definition: TTVSession.h:49
#define ClassImp(name)
Definition: Rtypes.h:359
void FormFrom(TTreeViewer *tv)
Populate members from treeviewer tv.
Definition: TTVSession.cxx:55
void SetSmallPic(const TGPicture *spic)
Set small picture.
void PlugIn(TTreeViewer *tv)
Change treeviewer status to this record.
Definition: TTVSession.cxx:74
void SetGrOpt(const char *option)
Set graph option.
void SetScanRedirect(Bool_t mode)
Set the state of Scan check button.
I/O classes for TreeViewer session handling.
Definition: TTVSession.h:69
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
TTVRecord * AddRecord(Bool_t fromFile=kFALSE)
Add a record.
Definition: TTVSession.cxx:159
void ExecuteUserCode()
Execute user-defined code.
Definition: TTVSession.cxx:42
#define snprintf
Definition: civetweb.c:1351
void Show(TTVRecord *rec)
Display record rec.
Definition: TTVSession.cxx:242
Bool_t IsScanRedirected()
Return kTRUE if scan is redirected.
const Bool_t kTRUE
Definition: RtypesCore.h:87
char name[80]
Definition: TGX11.cxx:109
const char * Data() const
Definition: TString.h:364