00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TGo4TreeViewerSlots.h"
00017 #include "TCut.h"
00018 #include "TTree.h"
00019
00020 #include "qlistview.h"
00021 #include "qtabwidget.h"
00022 #include "TH1.h"
00023
00024 #include "Go4LockGuard/TGo4LockGuard.h"
00025 #include "Go4GUIRegistry/TGo4GUIRegistry.h"
00026 #include "Go4CommandsAnalysis/TGo4ComAddTreeHistogram.h"
00027 #include "Go4QtBaseWidgets/TGo4QTHItem.h"
00028 #include "TGo4DiskFileBrowserSlots.h"
00029 #include "TGo4DiskFileBrowserStatus.h"
00030 #include "TGo4DiskFileBrowser.h"
00031 #include "TGo4RemoteBrowserStatus.h"
00032 #include "TGo4RemoteBrowserSlots.h"
00033 #include "TGo4RemoteBrowser.h"
00034 #include "TGo4BrowserSlots.h"
00035 #include "TGo4Browser.h"
00036 #include "TGo4TreeViewerStatus.h"
00037 #include "TGo4TreeViewer.h"
00038 #include "TGo4MainWindow.h"
00039
00040 TGo4TreeViewerSlots::TGo4TreeViewerSlots(const char * name, const char * title, TGo4TreeViewer * p)
00041 :TGo4SlotsBaseClass(name , title), fxTGo4TreeViewer(p)
00042 {
00043
00044 fxTGo4GUIRegistry = TGo4GUIRegistry::Instance();
00045 fxTGo4TreeViewerStatus= new TGo4TreeViewerStatus("TGo4TreeViewertatus", "Test Status 1");
00046 fxTGo4GUIRegistry->RegisterSlotClass(this, fxTGo4TreeViewerStatus, p);
00047 }
00048
00049 void TGo4TreeViewerSlots::TreeDraw(const char *X,const char*Y,const char*Z,const char*Cut, const char *HisName)
00050 {
00051 TGo4LockGuard Global;
00052 Int_t drawdim=0;
00053 TString varexp;
00054 TString cutexp=Cut;
00055 TGo4DiskFileBrowserSlots *fxTGo4DiskFileBrowserSlots =
00056 dynamic_cast<TGo4DiskFileBrowserSlots *> (fxTGo4GUIRegistry->GetSlotClass("TGo4DiskFileBrowserSlots"));
00057
00058 TGo4DiskFileBrowserStatus *fxTGo4DiskFileBrowserStatus = 0;
00059 if (fxTGo4DiskFileBrowserSlots!=0)
00060 fxTGo4DiskFileBrowserStatus = (TGo4DiskFileBrowserStatus *)fxTGo4DiskFileBrowserSlots->GetStatus();
00061
00062 TGo4BrowserSlots *fxTGo4BrowserSlots =
00063 dynamic_cast <TGo4BrowserSlots *>(fxTGo4GUIRegistry->GetSlotClass("TGo4BrowserSlots"));
00064
00065 TGo4Browser *fxTGo4Browser =
00066 dynamic_cast <TGo4Browser *>(fxTGo4GUIRegistry->GetGUIClass(fxTGo4BrowserSlots));
00067
00068 TTree *SelectedTree = fxTGo4DiskFileBrowserStatus->GetActiveTree();
00069 if((fxTGo4DiskFileBrowserSlots==0) || (fxTGo4Browser==0) ||
00070 (fxTGo4Browser->ListViewLocal==0) || (SelectedTree==0))
00071 {
00072
00073 TGo4MainWindow *MW= dynamic_cast<TGo4MainWindow *>(fxTGo4GUIRegistry->GetMainWindow());
00074 if(MW) MW->StatusMessage("Treeviewer without tree reference, please drop leave icons from browser");
00075 return;
00076 }
00077 drawdim=BuildVarExp(X,Y,Z,varexp);
00078 if(drawdim<=0) return;
00079 varexp += ">>+";
00080 varexp += HisName;
00081 TGo4QTHItem *HisItem = dynamic_cast<TGo4QTHItem*>
00082 (fxTGo4Browser->ListViewLocal->findItem(HisName,0));
00083 TH1* histo = HisItem ? dynamic_cast<TH1*> (HisItem->GetWorkObject()) : 0;
00084 TDirectory* oldhisdir = histo ? histo->GetDirectory() : 0;
00085 TDirectory* savdir = gDirectory;
00086 gDirectory = 0;
00087 TDirectory dummydir("DummyTreeDraw","Dummy directory to call tree draw");
00088 dummydir.cd();
00089 if (histo!=0)
00090 {
00091
00092 if(drawdim!=histo->GetDimension())
00093 {
00094
00095 Text_t buf[256];
00096 snprintf(buf,255,"Treeviewer: dimension mismatch: expression dim=%d, histogram dim=%d",drawdim,histo->GetDimension());
00097 TGo4MainWindow *MW= dynamic_cast<TGo4MainWindow *>(fxTGo4GUIRegistry->GetMainWindow());
00098 if(MW) MW->StatusMessage(buf);
00099 dummydir.Clear();
00100 savdir->cd();
00101 return;
00102 }
00103 histo->SetDirectory(&dummydir);
00104 }
00105 SelectedTree->Draw(varexp, cutexp, "goff", 10000000, 0);
00106 if (histo==0)
00107 {
00108 histo = dynamic_cast<TH1*> (dummydir.FindObject(HisName));
00109 if(histo)
00110 {
00111 histo->SetDirectory(0);
00112 fxTGo4BrowserSlots->AddLocalObject(histo);
00113 delete histo;
00114
00115
00116 }
00117 }
00118 else
00119 {
00120 histo->SetDirectory(oldhisdir);
00121 }
00122 dummydir.Clear();
00123 savdir->cd();
00124 }
00125
00126 void TGo4TreeViewerSlots::RemoteTreeDraw(const char *tree, const char *X,const char*Y,const char*Z,const char*Cut, const char *HisName)
00127 {
00128 TString treename=tree;
00129 if(treename.IsNull())
00130 {
00131
00132 TGo4MainWindow *MW= dynamic_cast<TGo4MainWindow *>(fxTGo4GUIRegistry->GetMainWindow());
00133 if(MW) MW->StatusMessage("Treeviewer without tree reference, please drop leave icons from browser");
00134 return;
00135 }
00136 TString varexp;
00137 TCut cut=Cut;
00138 if(BuildVarExp(X,Y,Z,varexp)>0)
00139 fxTGo4GUIRegistry->SubmitCommand(new TGo4ComAddTreeHistogram(HisName, treename, varexp, cut));
00140 }
00141
00142
00143 Int_t TGo4TreeViewerSlots::BuildVarExp(const char* X ,const char* Y ,const char* Z , TString& varexp)
00144 {
00145 Int_t drawdim=0;
00146 if(strlen(X)==0)
00147 {
00148
00149 TGo4MainWindow *MW= dynamic_cast<TGo4MainWindow *>(fxTGo4GUIRegistry->GetMainWindow());
00150 if(MW) MW->StatusMessage("Treedraw without x coordinate expression");
00151 drawdim=0;
00152 }
00153 else
00154 {
00155 varexp=X;
00156 if(strlen(Y)==0)
00157 {
00158 drawdim=1;
00159 }
00160 else
00161 {
00162 varexp+=":";
00163 varexp+=Y;
00164 if(strlen(Z)==0)
00165 {
00166 drawdim=2;
00167 }
00168 else
00169 {
00170 varexp+=":";
00171 varexp+=Z;
00172 drawdim=3;
00173 }
00174 }
00175 }
00176 return drawdim;
00177
00178 }
00179
00180
00181 void TGo4TreeViewerSlots::SetGUI(TGo4TreeViewer *GUI )
00182 {
00183
00184 fxTGo4TreeViewer= GUI;
00185 fxTGo4GUIRegistry->GuiIsChanged(this, GUI);
00186 }
00187
00188 TGo4Status * TGo4TreeViewerSlots::GetStatus()
00189 {
00190 return fxTGo4TreeViewerStatus;
00191 }
00192 TGo4TreeViewerSlots::~TGo4TreeViewerSlots()
00193 {
00194 delete fxTGo4TreeViewerStatus;
00195 }
00196
00197
00198
00199
00200