TTVSession.cxx

Go to the documentation of this file.
00001 // @(#)root/treeviewer:$Id: TTVSession.cxx 35537 2010-09-21 13:04:28Z brun $
00002 //Author : Andrei Gheata   21/02/01
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 
00013 #include "Riostream.h"
00014 #include "TTVSession.h"
00015 #include "TTreeViewer.h"
00016 #include "TTVLVContainer.h"
00017 #include "TClonesArray.h"
00018 #include "TInterpreter.h"
00019 
00020 
00021 ClassImp(TTVRecord)
00022 
00023 //______________________________________________________________________________
00024 TTVRecord::TTVRecord()
00025 {
00026    // TTVRecord default constructor
00027 
00028    fName = "";
00029    fScanRedirected = kFALSE;
00030    fCutEnabled     = kTRUE;
00031    fUserCode = "";
00032    fAutoexec = kFALSE;
00033 }
00034 //______________________________________________________________________________
00035 void TTVRecord::ExecuteUserCode()
00036 {
00037    // Execute user-defined code
00038 
00039    if (fUserCode.Length()) {
00040       char code[250];
00041       code[0] = 0;
00042       snprintf(code,250, "%s", fUserCode.Data());
00043       gInterpreter->ProcessLine(code);
00044    }
00045 }
00046 //______________________________________________________________________________
00047 void TTVRecord::FormFrom(TTreeViewer *tv)
00048 {
00049    // Populate members from treeviewer tv
00050 
00051    if (!tv)  return;
00052    fX        = tv->ExpressionItem(0)->GetTrueName();
00053    fXAlias   = tv->ExpressionItem(0)->GetAlias();
00054    fY        = tv->ExpressionItem(1)->GetTrueName();
00055    fYAlias   = tv->ExpressionItem(1)->GetAlias();
00056    fZ        = tv->ExpressionItem(2)->GetTrueName();
00057    fZAlias   = tv->ExpressionItem(2)->GetAlias();
00058    fCut      = tv->ExpressionItem(3)->GetTrueName();
00059    fCutAlias = tv->ExpressionItem(3)->GetAlias();
00060    fOption   = tv->GetGrOpt();
00061    fScanRedirected = tv->IsScanRedirected();
00062    fCutEnabled = tv->IsCutEnabled();
00063 }
00064 //______________________________________________________________________________
00065 void TTVRecord::PlugIn(TTreeViewer *tv)
00066 {
00067    // Change treeviewer status to this record
00068 
00069    TTVLVEntry *item;
00070    // change X expression
00071    item = tv->ExpressionItem(0);
00072    item->SetExpression(fX.Data(), fXAlias.Data());
00073    item = tv->ExpressionItem(1);
00074    item->SetExpression(fY.Data(), fYAlias.Data());
00075    item = tv->ExpressionItem(2);
00076    item->SetExpression(fZ.Data(), fZAlias.Data());
00077    item = tv->ExpressionItem(3);
00078    item->SetExpression(fCut.Data(), fCutAlias.Data());
00079    tv->SetGrOpt(fOption.Data());
00080    tv->SetScanRedirect(fScanRedirected);
00081    tv->SetCutMode(fCutEnabled);
00082    if (fCutEnabled)
00083       item->SetSmallPic(gClient->GetPicture("cut_t.xpm"));
00084    else
00085       item->SetSmallPic(gClient->GetPicture("cut-disable_t.xpm"));
00086 }
00087 //______________________________________________________________________________
00088 void TTVRecord::SaveSource(ofstream &out)
00089 {
00090    // Save the TTVRecord in a C++ macro file
00091 
00092    char quote = '"';
00093    out <<"//--- tree viewer record"<<endl;
00094    out <<"   tv_record = tv_session->AddRecord(kTRUE);"<<endl;
00095    out <<"   tv_session->SetRecordName("<<quote<<GetName()<<quote<<");"<<endl;
00096    out <<"   tv_record->fX        = "<<quote<<fX.Data()<<quote<<";"<<endl;
00097    out <<"   tv_record->fY        = "<<quote<<fY.Data()<<quote<<";"<<endl;
00098    out <<"   tv_record->fZ        = "<<quote<<fZ.Data()<<quote<<";"<<endl;
00099    out <<"   tv_record->fCut      = "<<quote<<fCut.Data()<<quote<<";"<<endl;
00100    out <<"   tv_record->fXAlias   = "<<quote<<fXAlias.Data()<<quote<<";"<<endl;
00101    out <<"   tv_record->fYAlias   = "<<quote<<fYAlias.Data()<<quote<<";"<<endl;
00102    out <<"   tv_record->fZAlias   = "<<quote<<fZAlias.Data()<<quote<<";"<<endl;
00103    out <<"   tv_record->fCutAlias = "<<quote<<fCutAlias.Data()<<quote<<";"<<endl;
00104    out <<"   tv_record->fOption   = "<<quote<<fOption.Data()<<quote<<";"<<endl;
00105    if (fScanRedirected)
00106       out <<"   tv_record->fScanRedirected = kTRUE;"<<endl;
00107    else
00108       out <<"   tv_record->fScanRedirected = kFALSE;"<<endl;
00109    if (fCutEnabled)
00110       out <<"   tv_record->fCutEnabled = kTRUE;"<<endl;
00111    else
00112       out <<"   tv_record->fCutEnabled = kFALSE;"<<endl;
00113    if (fUserCode.Length()) {
00114       out <<"   tv_record->SetUserCode(\""<<fUserCode.Data()<<"\");"<<endl;
00115       if (fAutoexec) {
00116          out <<"   tv_record->SetAutoexec();"<<endl;
00117       }
00118    }
00119 }
00120 
00121 ClassImp(TTVSession)
00122 
00123 //______________________________________________________________________________
00124 TTVSession::TTVSession(TTreeViewer *tv)
00125 {
00126    // constructor
00127 
00128    fName    = "";
00129    fList    = new TClonesArray("TTVRecord", 100); // is 100 enough ?
00130    fViewer  = tv;
00131    fCurrent = 0;
00132    fRecords = 0;
00133 }
00134 //______________________________________________________________________________
00135 TTVSession::~TTVSession()
00136 {
00137    // destructor
00138 
00139    fList->Delete();
00140    delete fList;
00141 }
00142 //______________________________________________________________________________
00143 TTVRecord *TTVSession::AddRecord(Bool_t fromFile)
00144 {
00145    // add a record
00146 
00147    TClonesArray &list = *fList;
00148    TTVRecord *newrec = new(list[fRecords++])TTVRecord();
00149    if (!fromFile) newrec->FormFrom(fViewer);
00150    fCurrent = fRecords - 1;
00151    if (fRecords > 1) fViewer->ActivateButtons(kTRUE, kTRUE, kFALSE, kTRUE);
00152    else              fViewer->ActivateButtons(kTRUE, kFALSE, kFALSE, kTRUE);
00153    if (!fromFile) {
00154       TString name = "";
00155       if (strlen(newrec->GetZ())) name += newrec->GetZ();
00156       if (strlen(newrec->GetY())) {
00157          if (name.Length()) name += ":";
00158          name += newrec->GetY();
00159       }
00160       if (strlen(newrec->GetX())) {
00161          if (name.Length()) name += ":";
00162          name += newrec->GetX();
00163       }
00164       SetRecordName(name.Data());
00165    }
00166    return newrec;
00167 }
00168 //______________________________________________________________________________
00169 TTVRecord *TTVSession::GetRecord(Int_t i)
00170 {
00171    // return record at index i
00172 
00173    if (!fRecords) return 0;
00174    fCurrent = i;
00175    if (i < 0)           fCurrent = 0;
00176    if (i > fRecords-1)  fCurrent = fRecords - 1;
00177    if (fCurrent>0 && fCurrent<fRecords-1)
00178       fViewer->ActivateButtons(kTRUE, kTRUE, kTRUE, kTRUE);
00179    if (fCurrent == 0) {
00180       if (fRecords > 1) fViewer->ActivateButtons(kTRUE, kFALSE, kTRUE, kTRUE);
00181       else              fViewer->ActivateButtons(kTRUE, kFALSE, kFALSE, kTRUE);
00182    }
00183    if (fCurrent == fRecords-1) {
00184       if (fRecords > 1) fViewer->ActivateButtons(kTRUE, kTRUE, kFALSE, kTRUE);
00185       else              fViewer->ActivateButtons(kTRUE, kFALSE, kFALSE, kTRUE);
00186    }
00187    fViewer->SetCurrentRecord(fCurrent);
00188    return (TTVRecord *)fList->UncheckedAt(fCurrent);
00189 }
00190 //______________________________________________________________________________
00191 void TTVSession::SetRecordName(const char *name)
00192 {
00193    // Set record name
00194 
00195    Int_t crt = fCurrent;
00196    TTVRecord *current = GetRecord(fCurrent);
00197    current->SetName(name);
00198    fViewer->UpdateCombo();
00199    fCurrent = crt;
00200    fViewer->SetCurrentRecord(fCurrent);
00201 }
00202 //______________________________________________________________________________
00203 void TTVSession::RemoveLastRecord()
00204 {
00205    //--- Remove current record from list
00206 
00207    if (!fRecords) return;
00208    TTVRecord *rec = (TTVRecord *)fList->UncheckedAt(fRecords);
00209    delete rec;
00210    fList->RemoveAt(fRecords--);
00211    if (fCurrent > fRecords-1) fCurrent = fRecords - 1;
00212    Int_t crt = fCurrent;
00213    fViewer->UpdateCombo();
00214    fCurrent = crt;
00215    if (!fRecords) {
00216       fViewer->ActivateButtons(kFALSE, kFALSE, kFALSE, kFALSE);
00217       return;
00218    }
00219    GetRecord(fCurrent);
00220 }
00221 //______________________________________________________________________________
00222 void TTVSession::Show(TTVRecord *rec)
00223 {
00224    // Display record rec
00225 
00226    rec->PlugIn(fViewer);
00227    fViewer->ExecuteDraw();
00228    if (rec->HasUserCode() && rec->MustExecuteCode()) rec->ExecuteUserCode();
00229    fViewer->SetHistogramTitle(rec->GetName());
00230 }
00231 //______________________________________________________________________________
00232 void TTVSession::SaveSource(ofstream &out)
00233 {
00234    // Save the TTVSession in a C++ macro file
00235 
00236    out<<"//--- session object"<<endl;
00237    out<<"   tv_session = new TTVSession(treeview);"<<endl;
00238    out<<"   treeview->SetSession(tv_session);"<<endl;
00239    TTVRecord *record;
00240    for (Int_t i=0; i<fRecords; i++) {
00241       record = GetRecord(i);
00242       record->SaveSource(out);
00243    }
00244    out<<"//--- Connect first record"<<endl;
00245    out<<"   tv_session->First();"<<endl;
00246 }
00247 //______________________________________________________________________________
00248 void TTVSession::UpdateRecord(const char *name)
00249 {
00250    //--- Updates current record according to new X, Y, Z settings
00251 
00252    TTVRecord *current = (TTVRecord *)fList->UncheckedAt(fCurrent);
00253    current->FormFrom(fViewer);
00254    SetRecordName(name);
00255 }
00256 

Generated on Tue Jul 5 15:43:48 2011 for ROOT_528-00b_version by  doxygen 1.5.1