Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

TGo4AbstractInterface.cxx

Go to the documentation of this file.
00001 //-------------------------------------------------------------
00002 //        Go4 Release Package v3.04-01 (build 30401)
00003 //                      28-November-2008
00004 //---------------------------------------------------------------
00005 //   The GSI Online Offline Object Oriented (Go4) Project
00006 //   Experiment Data Processing at EE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
00015 //----------------------------------------------------------------
00016 #include "TGo4AbstractInterface.h"
00017 
00018 #include "TROOT.h"
00019 #include "TSystem.h"
00020 #include "TInterpreter.h"
00021 #include "Riostream.h"
00022 #include "TObjString.h"
00023 
00024 #include "TGo4Log.h"
00025 #include "TGo4Iter.h"
00026 #include "TGo4Slot.h"
00027 #include "TGo4ObjectManager.h"
00028 #include "TGo4BrowserProxy.h"
00029 #include "TGo4AnalysisProxy.h"
00030 
00031 TGo4AbstractInterface* TGo4AbstractInterface::fgInstance = 0;
00032 
00033 TGo4AbstractInterface* TGo4AbstractInterface::Instance()
00034 {
00035    return fgInstance;
00036 }
00037 
00038 void TGo4AbstractInterface::DeleteInstance()
00039 {
00040    if (fgInstance!=0) delete fgInstance;
00041 }
00042 
00043 TGo4AbstractInterface::TGo4AbstractInterface() :
00044    TObject(),
00045    fOM(0),
00046    fBrowser(0),
00047    fxCommands()
00048 {
00049    fgInstance = this;
00050 }
00051 
00052 void TGo4AbstractInterface::Initialize(TGo4ObjectManager* om, TGo4BrowserProxy* br)
00053 {
00054    fOM = om;
00055    fBrowser = br;
00056 
00057    Int_t error = 0;
00058    gROOT->ProcessLine("TGo4AbstractInterface* go4 = TGo4AbstractInterface::Instance();", &error);
00059    gROOT->ProcessLine("TGo4ObjectManager* om = TGo4AbstractInterface::Instance()->OM();", &error);
00060    gROOT->ProcessLine("TGo4BrowserProxy* br = TGo4AbstractInterface::Instance()->Browser();", &error);
00061    gROOT->ProcessLine(".x $GO4SYS/etc/go4macroinit.C");
00062 }
00063 
00064 TGo4AbstractInterface::~TGo4AbstractInterface()
00065 {
00066    FreeHotStartCmds();
00067 
00068    gROOT->ProcessLine(".x $GO4SYS/etc/go4macroclose.C");
00069 
00070    gInterpreter->DeleteGlobal(fBrowser);
00071    gInterpreter->DeleteGlobal(fOM);
00072    gInterpreter->DeleteGlobal(this);
00073 
00074    fgInstance = 0;
00075 
00076 }
00077 
00078 TGo4AnalysisProxy* TGo4AbstractInterface::Analysis()
00079 {
00080    return Browser() ? Browser()->FindAnalysis() : 0;
00081 }
00082 
00083 void TGo4AbstractInterface::LoadLibrary(const char* fname)
00084 {
00085    if ((fname==0) || (strlen(fname)==0)) return;
00086 
00087    TString libs = gInterpreter->GetSharedLibs();
00088 
00089    const char* token = strtok((char*) libs.Data(), " ,\t\n");
00090 
00091    while(token != 0) {
00092       if (strcmp(token, fname)==0) return;
00093       token = strtok(NULL, " ,\t\n");
00094    }
00095 
00096    gSystem->Load(fname);
00097 }
00098 
00099 void TGo4AbstractInterface::OpenFile(const char* fname)
00100 {
00101    Browser()->OpenFile(fname);
00102    ProcessEvents(-1);
00103 }
00104 
00105 Bool_t TGo4AbstractInterface::SaveToFile(const char* itemname,
00106                                          const char* filename,
00107                                          const char* filetitle)
00108 {
00109     return Browser()->SaveBrowserToFile(filename, kFALSE, itemname, filetitle);
00110 }
00111 
00112 Bool_t TGo4AbstractInterface::ExportToFile(const char* itemname,
00113                                            const char* dirpath,
00114                                            const char* format,
00115                                            const char* filetitle)
00116 {
00117     TGo4Slot* topslot = Browser()->ItemSlot(itemname);
00118     if (topslot==0) return kFALSE;
00119 
00120     TObjArray items;
00121 
00122     TGo4Iter iter(topslot, kTRUE);
00123 
00124     TString buf;
00125 
00126     while (iter.next())
00127        if (Browser()->BrowserItemName(iter.getslot(), buf))
00128           items.Add(new TObjString(buf));
00129 
00130     Browser()->ExportItemsTo(&items, kFALSE, "null", dirpath, format, filetitle);
00131 
00132     items.Delete();
00133 
00134     return kTRUE;
00135 }
00136 
00137 
00138 void TGo4AbstractInterface::ConnectHServer(const char* servername,
00139                                        Int_t portnumber,
00140                                        const char* basename,
00141                                        const char* userpass,
00142                                        const char* filter)
00143 {
00144    Browser()->ConnectHServer(servername,
00145                              portnumber,
00146                              basename,
00147                              userpass,
00148                              filter);
00149    ProcessEvents(200);
00150 }
00151 
00152 Bool_t TGo4AbstractInterface::IsAnalysisConnected()
00153 {
00154    return Analysis()==0 ? kFALSE : Analysis()->IsConnected();
00155 }
00156 
00157 
00158 void TGo4AbstractInterface::ExecuteLine(const char* remotecmd)
00159 {
00160    TGo4AnalysisProxy* anal = Analysis();
00161    if ((anal!=0) && (remotecmd!=0)) {
00162       anal->ExecuteLine(remotecmd);
00163       TGo4Log::Message(1, "Exec: %s", remotecmd);
00164    }
00165 }
00166 
00167 void TGo4AbstractInterface::RequestAnalysisConfig()
00168 {
00169    TGo4AnalysisProxy* anal = Analysis();
00170    if (anal!=0)
00171      anal->RequestAnalysisSettings();
00172 }
00173 
00174 void TGo4AbstractInterface::MonitorItem(const char* itemname, Bool_t on)
00175 {
00176    TGo4Slot* itemslot = Browser()->BrowserSlot(itemname);
00177    if (itemslot!=0)
00178      Browser()->SetItemMonitored(itemslot, on);
00179 }
00180 
00181 void TGo4AbstractInterface::StartMonitoring(Int_t period)
00182 {
00183    Browser()->ToggleMonitoring(period*1000);
00184 }
00185 
00186 void TGo4AbstractInterface::StopMonitoring()
00187 {
00188    Browser()->ToggleMonitoring(-1);
00189 }
00190 
00191 TString TGo4AbstractInterface::FindItem(const char* objname)
00192 {
00193    // if itemname is specified, return as is
00194    if (Browser()->ItemSlot(objname)!=0) return TString(objname);
00195 
00196    return Browser()->FindItem(objname);
00197 }
00198 
00199 Bool_t TGo4AbstractInterface::CopyItem(const char* itemname)
00200 {
00201    return Browser()->ProduceExplicitCopy(itemname);
00202 }
00203 
00204 Bool_t TGo4AbstractInterface::DeleteItem(const char* itemname)
00205 {
00206    return Browser()->DeleteDataSource(Browser()->ItemSlot(itemname));
00207 }
00208 
00209 void TGo4AbstractInterface::FetchItem(const char* itemname, Int_t wait_time)
00210 {
00211    Browser()->FetchItem(itemname, wait_time);
00212 }
00213 
00214 void TGo4AbstractInterface::RedrawItem(const char* itemname)
00215 {
00216    Browser()->RedrawItem(itemname);
00217 }
00218 
00219 TObject* TGo4AbstractInterface::GetObject(const char* itemname, Int_t updatelevel)
00220 {
00221    if ((itemname==0) || (strlen(itemname)==0)) return 0;
00222 
00223    return Browser()->GetBrowserObject(itemname, updatelevel);
00224 }
00225 
00226 TString TGo4AbstractInterface::SaveToMemory(const char* path, TObject* obj, Bool_t ownership)
00227 {
00228    TString res = Browser()->SaveToMemory(path, obj, ownership, kTRUE);
00229 
00230    ProcessEvents();
00231 
00232    return res;
00233 }
00234 
00235 Bool_t TGo4AbstractInterface::LoadHotStart(const char* filename)
00236 {
00237    FreeHotStartCmds();
00238 
00239    ifstream f(filename);
00240 
00241    char buf[10000];
00242 
00243    while (!f.eof()) {
00244       f.getline(buf, 10000);
00245       fxCommands.Add(new TObjString(buf));
00246    }
00247 
00248    if (fxCommands.IsEmpty()) return kFALSE;
00249 
00250    // Add empty string, which will be deleted first
00251    fxCommands.AddFirst(new TObjString(""));
00252    return kTRUE;
00253 }
00254 
00255 Bool_t TGo4AbstractInterface::IsHotStart()
00256 {
00257    return !fxCommands.IsEmpty();
00258 }
00259 
00260 const char* TGo4AbstractInterface::NextHotStartCmd()
00261 {
00262    if (fxCommands.IsEmpty()) return 0;
00263    TObject* obj = fxCommands.First();
00264    fxCommands.Remove(obj);
00265    delete obj;
00266    const char* res = 0;
00267    do {
00268       if (fxCommands.IsEmpty()) return 0;
00269       TObjString* str = (TObjString*) fxCommands.First();
00270       res = str->GetName();
00271       if ((res==0) || (strlen(res)==0)) {
00272          res = 0;
00273          fxCommands.Remove(str);
00274          delete str;
00275       }
00276 
00277    } while (res == 0);
00278    return res;
00279 }
00280 
00281 void TGo4AbstractInterface::FreeHotStartCmds()
00282 {
00283    fxCommands.Delete();
00284 }
00285 
00286 
00287 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Fri Nov 28 12:59:27 2008 for Go4-v3.04-1 by  doxygen 1.4.2