30 TTVRecord::TTVRecord()
33 fScanRedirected = kFALSE;
42 void TTVRecord::ExecuteUserCode()
44 if (fUserCode.Length()) {
47 snprintf(code,250,
"%s", fUserCode.Data());
48 gInterpreter->ProcessLine(code);
55 void TTVRecord::FormFrom(TTreeViewer *tv)
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();
67 fScanRedirected = tv->IsScanRedirected();
68 fCutEnabled = tv->IsCutEnabled();
74 void TTVRecord::PlugIn(TTreeViewer *tv)
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());
87 tv->SetScanRedirect(fScanRedirected);
88 tv->SetCutMode(fCutEnabled);
90 item->SetSmallPic(gClient->GetPicture(
"cut_t.xpm"));
92 item->SetSmallPic(gClient->GetPicture(
"cut-disable_t.xpm"));
98 void TTVRecord::SaveSource(std::ofstream &out)
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;
114 out <<
" tv_record->fScanRedirected = kTRUE;"<<std::endl;
116 out <<
" tv_record->fScanRedirected = kFALSE;"<<std::endl;
118 out <<
" tv_record->fCutEnabled = kTRUE;"<<std::endl;
120 out <<
" tv_record->fCutEnabled = kFALSE;"<<std::endl;
121 if (fUserCode.Length()) {
122 out <<
" tv_record->SetUserCode(\""<<fUserCode.Data()<<
"\");"<<std::endl;
124 out <<
" tv_record->SetAutoexec();"<<std::endl;
129 ClassImp(TTVSession);
138 TTVSession::TTVSession(TTreeViewer *tv)
141 fList =
new TClonesArray(
"TTVRecord", 100);
150 TTVSession::~TTVSession()
159 TTVRecord *TTVSession::AddRecord(Bool_t fromFile)
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);
169 if (strlen(newrec->GetZ())) name += newrec->GetZ();
170 if (strlen(newrec->GetY())) {
171 if (name.Length()) name +=
":";
172 name += newrec->GetY();
174 if (strlen(newrec->GetX())) {
175 if (name.Length()) name +=
":";
176 name += newrec->GetX();
178 SetRecordName(name.Data());
186 TTVRecord *TTVSession::GetRecord(Int_t i)
188 if (!fRecords)
return 0;
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);
195 if (fRecords > 1) fViewer->ActivateButtons(kTRUE, kFALSE, kTRUE, kTRUE);
196 else fViewer->ActivateButtons(kTRUE, kFALSE, kFALSE, kTRUE);
198 if (fCurrent == fRecords-1) {
199 if (fRecords > 1) fViewer->ActivateButtons(kTRUE, kTRUE, kFALSE, kTRUE);
200 else fViewer->ActivateButtons(kTRUE, kFALSE, kFALSE, kTRUE);
202 fViewer->SetCurrentRecord(fCurrent);
203 return (TTVRecord *)fList->UncheckedAt(fCurrent);
209 void TTVSession::SetRecordName(
const char *name)
211 Int_t crt = fCurrent;
212 TTVRecord *current = GetRecord(fCurrent);
213 current->SetName(name);
214 fViewer->UpdateCombo();
216 fViewer->SetCurrentRecord(fCurrent);
222 void TTVSession::RemoveLastRecord()
224 if (!fRecords)
return;
225 TTVRecord *rec = (TTVRecord *)fList->UncheckedAt(fRecords);
227 fList->RemoveAt(fRecords--);
228 if (fCurrent > fRecords-1) fCurrent = fRecords - 1;
229 Int_t crt = fCurrent;
230 fViewer->UpdateCombo();
233 fViewer->ActivateButtons(kFALSE, kFALSE, kFALSE, kFALSE);
242 void TTVSession::Show(TTVRecord *rec)
244 rec->PlugIn(fViewer);
245 fViewer->ExecuteDraw();
246 if (rec->HasUserCode() && rec->MustExecuteCode()) rec->ExecuteUserCode();
247 fViewer->SetHistogramTitle(rec->GetName());
253 void TTVSession::SaveSource(std::ofstream &out)
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);
263 out<<
"//--- Connect first record"<<std::endl;
264 out<<
" tv_session->First();"<<std::endl;
270 void TTVSession::UpdateRecord(
const char *name)
272 TTVRecord *current = (TTVRecord *)fList->UncheckedAt(fCurrent);
273 current->FormFrom(fViewer);