00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4AbstractInterface.h"
00015
00016 #include <string.h>
00017
00018 #include "TROOT.h"
00019 #include "TSystem.h"
00020 #include "TInterpreter.h"
00021 #include "TObjString.h"
00022 #include "Riostream.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 TString TGo4AbstractInterface::fInitSharedLibs = "";
00034
00035
00036 TGo4AbstractInterface* TGo4AbstractInterface::Instance()
00037 {
00038 return fgInstance;
00039 }
00040
00041 void TGo4AbstractInterface::DeleteInstance()
00042 {
00043 if (fgInstance!=0) delete fgInstance;
00044 }
00045
00046 const char* TGo4AbstractInterface::FileExtension()
00047 {
00048 return ".hotstart";
00049 }
00050
00051 const char* TGo4AbstractInterface::DefaultPicTitle()
00052 {
00053 return "temporary object to setup viewpanel";
00054 }
00055
00056 Int_t TGo4AbstractInterface::DelayMillisec()
00057 {
00058 return 20;
00059 }
00060
00061 void TGo4AbstractInterface::SetInitSharedLibs(const char* libs)
00062 {
00063 fInitSharedLibs = libs ? libs : gInterpreter->GetSharedLibs();
00064 }
00065
00066 TGo4AbstractInterface::TGo4AbstractInterface() :
00067 TObject(),
00068 fOM(0),
00069 fBrowser(0),
00070 fxCommands()
00071 {
00072 fgInstance = this;
00073 }
00074
00075 void TGo4AbstractInterface::Initialize(TGo4ObjectManager* om, TGo4BrowserProxy* br)
00076 {
00077 fOM = om;
00078 fBrowser = br;
00079
00080 Int_t error = 0;
00081 gROOT->ProcessLineSync("TGo4AbstractInterface* go4 = TGo4AbstractInterface::Instance();", &error);
00082 gROOT->ProcessLineSync("TGo4ObjectManager* om = TGo4AbstractInterface::Instance()->OM();", &error);
00083 gROOT->ProcessLineSync("TGo4BrowserProxy* br = TGo4AbstractInterface::Instance()->Browser();", &error);
00084 gROOT->ProcessLineSync(Form(".x %s", TGo4Log::subGO4SYS("macros/go4macroinit.C").Data()));
00085 }
00086
00087 TGo4AbstractInterface::~TGo4AbstractInterface()
00088 {
00089 FreeHotStartCmds();
00090
00091 gROOT->ProcessLine(Form(".x %s", TGo4Log::subGO4SYS("macros/go4macroclose.C").Data()));
00092
00093 gInterpreter->DeleteGlobal(fBrowser);
00094 gInterpreter->DeleteGlobal(fOM);
00095 gInterpreter->DeleteGlobal(this);
00096
00097 fgInstance = 0;
00098
00099 }
00100
00101 TGo4AnalysisProxy* TGo4AbstractInterface::Analysis()
00102 {
00103 return Browser() ? Browser()->FindAnalysis() : 0;
00104 }
00105
00106 void TGo4AbstractInterface::LoadLibrary(const char* fname)
00107 {
00108 if ((fname==0) || (strlen(fname)==0)) return;
00109
00110 TString libs = gInterpreter->GetSharedLibs();
00111
00112 const char* token = strtok((char*) libs.Data(), " ,\t\n");
00113
00114 while(token != 0) {
00115 if (strcmp(token, fname)==0) return;
00116 token = strtok(NULL, " ,\t\n");
00117 }
00118
00119 gSystem->Load(fname);
00120 }
00121
00122 void TGo4AbstractInterface::OpenFile(const char* fname)
00123 {
00124 Browser()->OpenFile(fname);
00125 ProcessEvents(-1);
00126 }
00127
00128
00129
00130 Bool_t TGo4AbstractInterface::SaveToFile(const char* itemname,
00131 const char* filename,
00132 const char* filetitle)
00133 {
00134 return Browser()->SaveBrowserToFile(filename, kFALSE, itemname, filetitle);
00135 }
00136
00137 Bool_t TGo4AbstractInterface::ExportToFile(const char* itemname,
00138 const char* dirpath,
00139 const char* format,
00140 const char* filetitle)
00141 {
00142 TGo4Slot* topslot = Browser()->ItemSlot(itemname);
00143 if (topslot==0) return kFALSE;
00144
00145 TObjArray items;
00146
00147 TGo4Iter iter(topslot, kTRUE);
00148
00149 TString buf;
00150
00151 while (iter.next())
00152 if (Browser()->BrowserItemName(iter.getslot(), buf))
00153 items.Add(new TObjString(buf));
00154
00155 Browser()->ExportItemsTo(&items, kFALSE, "null", dirpath, format, filetitle);
00156
00157 items.Delete();
00158
00159 return kTRUE;
00160 }
00161
00162
00163 void TGo4AbstractInterface::ConnectHServer(const char* servername,
00164 Int_t portnumber,
00165 const char* basename,
00166 const char* userpass,
00167 const char* filter)
00168 {
00169 Browser()->ConnectHServer(servername,
00170 portnumber,
00171 basename,
00172 userpass,
00173 filter);
00174 ProcessEvents(200);
00175 }
00176
00177
00178 void TGo4AbstractInterface::ConnectDabc(const char* servername)
00179 {
00180 Browser()->ConnectDabc(servername);
00181 }
00182
00183
00184 Bool_t TGo4AbstractInterface::IsAnalysisConnected()
00185 {
00186 return Analysis()==0 ? kFALSE : Analysis()->IsConnected();
00187 }
00188
00189
00190 void TGo4AbstractInterface::ExecuteLine(const char* remotecmd)
00191 {
00192 TGo4AnalysisProxy* anal = Analysis();
00193 if ((anal!=0) && (remotecmd!=0)) {
00194 anal->ExecuteLine(remotecmd);
00195 TGo4Log::Message(1, "Exec: %s", remotecmd);
00196 }
00197 }
00198
00199 void TGo4AbstractInterface::RequestAnalysisConfig()
00200 {
00201 TGo4AnalysisProxy* anal = Analysis();
00202 if (anal!=0)
00203 anal->RequestAnalysisSettings();
00204 }
00205
00206 void TGo4AbstractInterface::MonitorItem(const char* itemname, Bool_t on)
00207 {
00208 TGo4Slot* itemslot = Browser()->BrowserSlot(itemname);
00209 if (itemslot!=0)
00210 Browser()->SetItemMonitored(itemslot, on);
00211 }
00212
00213 void TGo4AbstractInterface::StartMonitoring(Int_t period)
00214 {
00215 Browser()->ToggleMonitoring(period*1000);
00216 }
00217
00218 void TGo4AbstractInterface::StopMonitoring()
00219 {
00220 Browser()->ToggleMonitoring(-1);
00221 }
00222
00223 TString TGo4AbstractInterface::FindItem(const char* objname)
00224 {
00225
00226 if (Browser()->ItemSlot(objname)!=0) return TString(objname);
00227
00228 return Browser()->FindItem(objname);
00229 }
00230
00231 Bool_t TGo4AbstractInterface::CopyItem(const char* itemname)
00232 {
00233 return Browser()->ProduceExplicitCopy(itemname);
00234 }
00235
00236 Bool_t TGo4AbstractInterface::DeleteItem(const char* itemname)
00237 {
00238 return Browser()->DeleteDataSource(Browser()->ItemSlot(itemname));
00239 }
00240
00241 void TGo4AbstractInterface::FetchItem(const char* itemname, Int_t wait_time)
00242 {
00243 Browser()->FetchItem(itemname, wait_time);
00244 }
00245
00246 void TGo4AbstractInterface::RedrawItem(const char* itemname)
00247 {
00248 Browser()->RedrawItem(itemname);
00249 }
00250
00251 TObject* TGo4AbstractInterface::GetObject(const char* itemname, Int_t updatelevel)
00252 {
00253 if ((itemname==0) || (strlen(itemname)==0)) return 0;
00254
00255 return Browser()->GetBrowserObject(itemname, updatelevel);
00256 }
00257
00258 TString TGo4AbstractInterface::SaveToMemory(const char* path, TObject* obj, Bool_t ownership)
00259 {
00260 TString res = Browser()->SaveToMemory(path, obj, ownership, kTRUE);
00261
00262 ProcessEvents();
00263
00264 return res;
00265 }
00266
00267 Bool_t TGo4AbstractInterface::LoadHotStart(const char* filename)
00268 {
00269 FreeHotStartCmds();
00270
00271 std::ifstream f(filename);
00272
00273 if (!f.good()) return kFALSE;
00274
00275 char buf[10000];
00276
00277 while (!f.eof()) {
00278 f.getline(buf, 10000);
00279 fxCommands.Add(new TObjString(buf));
00280 }
00281
00282 if (fxCommands.IsEmpty()) return kFALSE;
00283
00284
00285 fxCommands.AddFirst(new TObjString(""));
00286 return kTRUE;
00287 }
00288
00289 Bool_t TGo4AbstractInterface::IsHotStart()
00290 {
00291 return !fxCommands.IsEmpty();
00292 }
00293
00294 const char* TGo4AbstractInterface::NextHotStartCmd()
00295 {
00296 if (fxCommands.IsEmpty()) return 0;
00297 TObject* obj = fxCommands.First();
00298 fxCommands.Remove(obj);
00299 delete obj;
00300 const char* res = 0;
00301 do {
00302 if (fxCommands.IsEmpty()) return 0;
00303 TObjString* str = (TObjString*) fxCommands.First();
00304 res = str->GetName();
00305 if ((res==0) || (strlen(res)==0)) {
00306 res = 0;
00307 fxCommands.Remove(str);
00308 delete str;
00309 }
00310
00311 } while (res == 0);
00312 return res;
00313 }
00314
00315 void TGo4AbstractInterface::FreeHotStartCmds()
00316 {
00317 fxCommands.Delete();
00318 }
00319
00320 void TGo4AbstractInterface::ProduceLoadLibs(std::ostream& fs)
00321 {
00322 TString rootsys;
00323 if (gSystem->Getenv("ROOTSYS") != 0) {
00324 rootsys = gSystem->Getenv("ROOTSYS");
00325 if (rootsys[rootsys.Length()-1] != '/') rootsys+="/";
00326 }
00327
00328 TString go4sys = TGo4Log::GO4SYS();
00329
00330 TString libs = gInterpreter->GetSharedLibs();
00331 const char* token = strtok((char*) libs.Data(), " ,\t\n");
00332 while(token != 0) {
00333 if ((fInitSharedLibs.Index(token) == kNPOS)
00334
00335
00336 && (strstr(token,"libHistPainter.")==0)) {
00337 fs << "go4->LoadLibrary(\"";
00338 if ((go4sys.Length() > 0) && strstr(token, go4sys.Data())==token)
00339 fs << "$GO4SYS/" << (token + go4sys.Length());
00340 else
00341 if ((rootsys.Length() > 0) && strstr(token, rootsys.Data())==token)
00342 fs << "$ROOTSYS/" << (token + rootsys.Length());
00343 else
00344 fs << token;
00345
00346 fs << "\");" << std::endl;
00347 }
00348 token = strtok(NULL, " ,\t\n");
00349 }
00350 }
00351