GSI Object Oriented Online Offline (Go4)  GO4-6.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4AbstractInterface.cxx
Go to the documentation of this file.
1 // $Id: TGo4AbstractInterface.cxx 2753 2020-04-16 11:04:26Z linev $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "TGo4AbstractInterface.h"
15 
16 #include <iostream>
17 #include <fstream>
18 
19 #include "TROOT.h"
20 #include "TSystem.h"
21 #include "TInterpreter.h"
22 #include "TObjString.h"
23 
24 #include "TGo4Log.h"
25 #include "TGo4Iter.h"
26 #include "TGo4BrowserProxy.h"
27 #include "TGo4ServerProxy.h"
28 
30 
32 
33 
35 {
36  return fgInstance;
37 }
38 
40 {
41  if (fgInstance!=0) delete fgInstance;
42 }
43 
45 {
46  return ".hotstart";
47 }
48 
50 {
51  return "temporary object to setup viewpanel";
52 }
53 
55 {
56  return 20;
57 }
58 
60 {
61  fInitSharedLibs = libs ? libs : gInterpreter->GetSharedLibs();
62 }
63 
65  TObject(),
66  fOM(0),
67  fBrowser(0),
68  fxCommands()
69 {
70  fgInstance = this;
71 }
72 
74 {
75  fOM = om;
76  fBrowser = br;
77 
78  Int_t error = 0;
79  gROOT->ProcessLineSync("TGo4AbstractInterface* go4 = TGo4AbstractInterface::Instance();", &error);
80  gROOT->ProcessLineSync("TGo4ObjectManager* om = TGo4AbstractInterface::Instance()->OM();", &error);
81  gROOT->ProcessLineSync("TGo4BrowserProxy* br = TGo4AbstractInterface::Instance()->Browser();", &error);
82  gROOT->ProcessLineSync(Form(".x %s", TGo4Log::subGO4SYS("macros/go4macroinit.C").Data()));
83 }
84 
86 {
88 
89  gROOT->ProcessLine(Form(".x %s", TGo4Log::subGO4SYS("macros/go4macroclose.C").Data()));
90 
91  gInterpreter->DeleteGlobal(fBrowser);
92  gInterpreter->DeleteGlobal(fOM);
93  gInterpreter->DeleteGlobal(this);
94 
95  fgInstance = 0;
96 
97 }
98 
100 {
101  return Browser() ? Browser()->FindAnalysis() : 0;
102 }
103 
105 {
106  return Browser() ? Browser()->FindServer() : 0;
107 }
108 
109 void TGo4AbstractInterface::LoadLibrary(const char* fname)
110 {
111  if ((fname==0) || (strlen(fname)==0)) return;
112 
113  TString libs = gInterpreter->GetSharedLibs();
114 
115  const char* token = strtok((char*) libs.Data(), " ,\t\n");
116 
117  while(token != 0) {
118  if (strcmp(token, fname)==0) return;
119  token = strtok(NULL, " ,\t\n");
120  }
121 
122  gSystem->Load(fname);
123 }
124 
125 void TGo4AbstractInterface::OpenFile(const char* fname)
126 {
127  Browser()->OpenFile(fname);
128  ProcessEvents(-1);
129 }
130 
131 
132 
133 Bool_t TGo4AbstractInterface::SaveToFile(const char* itemname,
134  const char* filename,
135  const char* filetitle)
136 {
137  return Browser()->SaveBrowserToFile(filename, kFALSE, itemname, filetitle);
138 }
139 
140 Bool_t TGo4AbstractInterface::ExportToFile(const char* itemname,
141  const char* dirpath,
142  const char* format,
143  const char* filetitle)
144 {
145  TGo4Slot* topslot = Browser()->ItemSlot(itemname);
146  if (topslot==0) return kFALSE;
147 
148  TObjArray items;
149 
150  TGo4Iter iter(topslot, kTRUE);
151 
152  TString buf;
153 
154  while (iter.next())
155  if (Browser()->BrowserItemName(iter.getslot(), buf))
156  items.Add(new TObjString(buf));
157 
158  Browser()->ExportItemsTo(&items, kFALSE, "null", dirpath, format, filetitle);
159 
160  items.Delete();
161 
162  return kTRUE;
163 }
164 
165 
166 void TGo4AbstractInterface::ConnectHServer(const char* servername,
167  Int_t portnumber,
168  const char* basename,
169  const char* userpass,
170  const char* filter)
171 {
172  Browser()->ConnectHServer(servername,
173  portnumber,
174  basename,
175  userpass,
176  filter);
177  ProcessEvents(200);
178 }
179 
180 void TGo4AbstractInterface::ConnectDabc(const char* servername)
181 {
182  Browser()->ConnectDabc(servername);
183 }
184 
186 {
187  return Server()==0 ? kFALSE : Server()->IsConnected();
188 }
189 
190 void TGo4AbstractInterface::ExecuteLine(const char* remotecmd)
191 {
192  TGo4ServerProxy* anal = Server();
193  if ((anal!=0) && (remotecmd!=0)) {
194  anal->ExecuteLine(remotecmd);
195  TGo4Log::Message(1, "Exec: %s", remotecmd);
196  }
197 }
198 
200 {
201  TGo4ServerProxy* anal = Server();
202  if (anal!=0)
203  anal->RequestAnalysisSettings();
204 }
205 
206 void TGo4AbstractInterface::MonitorItem(const char* itemname, Bool_t on)
207 {
208  TGo4Slot* itemslot = Browser()->BrowserSlot(itemname);
209  if (itemslot!=0)
210  Browser()->SetItemMonitored(itemslot, on);
211 }
212 
214 {
215  Browser()->ToggleMonitoring(period*1000);
216 }
217 
219 {
220  Browser()->ToggleMonitoring(-1);
221 }
222 
223 TString TGo4AbstractInterface::FindItem(const char* objname)
224 {
225  // if itemname is specified, return as is
226  if (Browser()->ItemSlot(objname)!=0) return TString(objname);
227 
228  return Browser()->FindItem(objname);
229 }
230 
231 Bool_t TGo4AbstractInterface::CopyItem(const char* itemname)
232 {
233  return Browser()->ProduceExplicitCopy(itemname);
234 }
235 
236 Bool_t TGo4AbstractInterface::DeleteItem(const char* itemname)
237 {
238  return Browser()->DeleteDataSource(Browser()->ItemSlot(itemname));
239 }
240 
241 void TGo4AbstractInterface::FetchItem(const char* itemname, Int_t wait_time)
242 {
243  Browser()->FetchItem(itemname, wait_time);
244 }
245 
246 void TGo4AbstractInterface::RedrawItem(const char* itemname)
247 {
248  Browser()->RedrawItem(itemname);
249 }
250 
251 TObject* TGo4AbstractInterface::GetObject(const char* itemname, Int_t updatelevel)
252 {
253  if ((itemname==0) || (strlen(itemname)==0)) return 0;
254 
255  return Browser()->GetBrowserObject(itemname, updatelevel);
256 }
257 
258 TString TGo4AbstractInterface::SaveToMemory(const char* path, TObject* obj, Bool_t ownership)
259 {
260  TString res = Browser()->SaveToMemory(path, obj, ownership, kTRUE);
261 
262  ProcessEvents();
263 
264  return res;
265 }
266 
267 Bool_t TGo4AbstractInterface::LoadHotStart(const char* filename)
268 {
270 
271  std::ifstream f(filename);
272 
273  if (!f.good()) return kFALSE;
274 
275  char buf[10000];
276 
277  while (!f.eof()) {
278  f.getline(buf, 10000);
279  fxCommands.Add(new TObjString(buf));
280  }
281 
282  if (fxCommands.IsEmpty()) return kFALSE;
283 
284  // Add empty string, which will be deleted first
285  fxCommands.AddFirst(new TObjString(""));
286  return kTRUE;
287 }
288 
290 {
291  return !fxCommands.IsEmpty();
292 }
293 
295 {
296  if (fxCommands.IsEmpty()) return 0;
297  TObject* obj = fxCommands.First();
298  fxCommands.Remove(obj);
299  delete obj;
300  const char* res = 0;
301  do {
302  if (fxCommands.IsEmpty()) return 0;
303  TObjString* str = (TObjString*) fxCommands.First();
304  res = str->GetName();
305  if ((res==0) || (strlen(res)==0)) {
306  res = 0;
307  fxCommands.Remove(str);
308  delete str;
309  }
310 
311  } while (res == 0);
312  return res;
313 }
314 
316 {
317  fxCommands.Delete();
318 }
319 
321 {
322  TString rootsys;
323  if (gSystem->Getenv("ROOTSYS") != 0) {
324  rootsys = gSystem->Getenv("ROOTSYS");
325  if (rootsys[rootsys.Length()-1] != '/') rootsys+="/";
326  }
327 
328  TString go4sys = TGo4Log::GO4SYS();
329 
330  TString libs = gInterpreter->GetSharedLibs();
331  const char* token = strtok((char*) libs.Data(), " ,\t\n");
332  while(token != 0) {
333  if ((fInitSharedLibs.Index(token) == kNPOS)
334 // (strstr(token,"libGX11.")==0) &&
335 // (strstr(token,"libGX11TTF.")==0) &&
336  && (strstr(token,"libHistPainter.")==0)) {
337  fs << "go4->LoadLibrary(\"";
338  if ((go4sys.Length() > 0) && strstr(token, go4sys.Data())==token)
339  fs << "$GO4SYS/" << (token + go4sys.Length());
340  else
341  if ((rootsys.Length() > 0) && strstr(token, rootsys.Data())==token)
342  fs << "$ROOTSYS/" << (token + rootsys.Length());
343  else
344  fs << token;
345 
346  fs << "\");" << std::endl;
347  }
348  token = strtok(NULL, " ,\t\n");
349  }
350 }
351 
static TGo4AbstractInterface * fgInstance
virtual TObject * GetObject(const char *itemname, Int_t updatelevel=1)
void OpenFile(const char *fname)
virtual Bool_t IsConnected()
Bool_t LoadHotStart(const char *filename)
TString FindItem(const char *objname)
TString SaveToMemory(const char *pathname, TObject *obj, Bool_t ownership, Bool_t overwrite=kFALSE)
TObject * GetBrowserObject(const char *name, Int_t update=0)
void ExportItemsTo(TObjArray *items, Bool_t fetchitems, const char *filename, const char *filedir, const char *format, const char *description)
virtual Bool_t ExportToFile(const char *itemname, const char *dirpath, const char *format, const char *filetitle=0)
virtual void FetchItem(const char *itemname, Int_t wait_time=2000)
TGo4BrowserProxy * Browser() const
void Initialize(TGo4ObjectManager *om, TGo4BrowserProxy *br)
list of shared libraries when application is started
virtual void RedrawItem(const char *itemname)
TGo4Slot * getslot() const
Definition: TGo4Iter.cxx:166
Bool_t DeleteDataSource(TGo4Slot *itemslot)
static void SetInitSharedLibs(const char *libs=0)
static const char * FileExtension()
virtual TString SaveToMemory(const char *path, TObject *obj, Bool_t ownership=kFALSE)
virtual void RequestAnalysisSettings()
virtual Bool_t SaveToFile(const char *itemname, const char *filename, const char *filetitle=0)
TGo4ServerProxy * FindServer(const char *itemname=0, Bool_t asanalysis=kTRUE)
Bool_t ConnectHServer(const char *servername, Int_t portnumber, const char *basename, const char *userpass, const char *filter)
virtual void OpenFile(const char *fname)
TGo4AnalysisProxy * Analysis()
Bool_t SaveBrowserToFile(const char *filename, Bool_t prefetch=kFALSE, const char *selectedpath=0, const char *description=0)
virtual void ExecuteLine(const char *line)
virtual Bool_t IsAnalysisConnected()
virtual void ConnectHServer(const char *servername, Int_t portnumber, const char *basename, const char *userpass, const char *filter)
static const char * DefaultPicTitle()
virtual Bool_t DeleteItem(const char *itemname)
virtual void StartMonitoring(Int_t period=10)
virtual void ProcessEvents(Int_t timeout=-1)=0
virtual void ExecuteLine(const char *remotecmd)
static const char * Message(Int_t prio, const char *text,...)
Definition: TGo4Log.cxx:207
void FetchItem(const char *itemname, Int_t wait_time=0)
TGo4BrowserProxy * fBrowser
TGo4Slot * BrowserSlot(const char *item)
void SetItemMonitored(TGo4Slot *slot, Bool_t on=kTRUE)
virtual Bool_t CopyItem(const char *itemname)
Bool_t ProduceExplicitCopy(const char *itemname, const char *tgtpath=0, Bool_t forcerequest=kFALSE)
Bool_t ConnectDabc(const char *nodename)
void RedrawItem(const char *itemname)
TGo4ObjectManager * fOM
TGo4AnalysisProxy * FindAnalysis(const char *itemname=0)
static void ProduceLoadLibs(std::ostream &fs)
virtual void ConnectDabc(const char *servername)
static TString subGO4SYS(const char *subdir)
Definition: TGo4Log.cxx:190
virtual TString FindItem(const char *objname)
virtual void MonitorItem(const char *itemname, Bool_t on=kTRUE)
static TGo4AbstractInterface * Instance()
static const char * GO4SYS()
Definition: TGo4Log.cxx:157
Bool_t BrowserItemName(TGo4Slot *itemslot, TString &res)
TGo4Slot * ItemSlot(const char *itemname)
void ToggleMonitoring(Int_t period)
Bool_t next(Bool_t goesinto=kTRUE)
Definition: TGo4Iter.cxx:44
virtual void LoadLibrary(const char *fname)