GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4AbstractInterface.cxx
Go to the documentation of this file.
1 // $Id: TGo4AbstractInterface.cxx 1597 2015-06-19 16:28:25Z 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 für 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 <string.h>
17 
18 #include "TROOT.h"
19 #include "TSystem.h"
20 #include "TInterpreter.h"
21 #include "TObjString.h"
22 #include "Riostream.h"
23 
24 #include "TGo4Log.h"
25 #include "TGo4Iter.h"
26 #include "TGo4Slot.h"
27 #include "TGo4ObjectManager.h"
28 #include "TGo4BrowserProxy.h"
29 #include "TGo4ServerProxy.h"
30 
32 
34 
35 
37 {
38  return fgInstance;
39 }
40 
42 {
43  if (fgInstance!=0) delete fgInstance;
44 }
45 
47 {
48  return ".hotstart";
49 }
50 
52 {
53  return "temporary object to setup viewpanel";
54 }
55 
57 {
58  return 20;
59 }
60 
62 {
63  fInitSharedLibs = libs ? libs : gInterpreter->GetSharedLibs();
64 }
65 
67  TObject(),
68  fOM(0),
69  fBrowser(0),
70  fxCommands()
71 {
72  fgInstance = this;
73 }
74 
76 {
77  fOM = om;
78  fBrowser = br;
79 
80  Int_t error = 0;
81  gROOT->ProcessLineSync("TGo4AbstractInterface* go4 = TGo4AbstractInterface::Instance();", &error);
82  gROOT->ProcessLineSync("TGo4ObjectManager* om = TGo4AbstractInterface::Instance()->OM();", &error);
83  gROOT->ProcessLineSync("TGo4BrowserProxy* br = TGo4AbstractInterface::Instance()->Browser();", &error);
84  gROOT->ProcessLineSync(Form(".x %s", TGo4Log::subGO4SYS("macros/go4macroinit.C").Data()));
85 }
86 
88 {
90 
91  gROOT->ProcessLine(Form(".x %s", TGo4Log::subGO4SYS("macros/go4macroclose.C").Data()));
92 
93  gInterpreter->DeleteGlobal(fBrowser);
94  gInterpreter->DeleteGlobal(fOM);
95  gInterpreter->DeleteGlobal(this);
96 
97  fgInstance = 0;
98 
99 }
100 
102 {
103  return Browser() ? Browser()->FindAnalysis() : 0;
104 }
105 
107 {
108  return Browser() ? Browser()->FindServer() : 0;
109 }
110 
111 void TGo4AbstractInterface::LoadLibrary(const char* fname)
112 {
113  if ((fname==0) || (strlen(fname)==0)) return;
114 
115  TString libs = gInterpreter->GetSharedLibs();
116 
117  const char* token = strtok((char*) libs.Data(), " ,\t\n");
118 
119  while(token != 0) {
120  if (strcmp(token, fname)==0) return;
121  token = strtok(NULL, " ,\t\n");
122  }
123 
124  gSystem->Load(fname);
125 }
126 
127 void TGo4AbstractInterface::OpenFile(const char* fname)
128 {
129  Browser()->OpenFile(fname);
130  ProcessEvents(-1);
131 }
132 
133 
134 
135 Bool_t TGo4AbstractInterface::SaveToFile(const char* itemname,
136  const char* filename,
137  const char* filetitle)
138 {
139  return Browser()->SaveBrowserToFile(filename, kFALSE, itemname, filetitle);
140 }
141 
142 Bool_t TGo4AbstractInterface::ExportToFile(const char* itemname,
143  const char* dirpath,
144  const char* format,
145  const char* filetitle)
146 {
147  TGo4Slot* topslot = Browser()->ItemSlot(itemname);
148  if (topslot==0) return kFALSE;
149 
150  TObjArray items;
151 
152  TGo4Iter iter(topslot, kTRUE);
153 
154  TString buf;
155 
156  while (iter.next())
157  if (Browser()->BrowserItemName(iter.getslot(), buf))
158  items.Add(new TObjString(buf));
159 
160  Browser()->ExportItemsTo(&items, kFALSE, "null", dirpath, format, filetitle);
161 
162  items.Delete();
163 
164  return kTRUE;
165 }
166 
167 
168 void TGo4AbstractInterface::ConnectHServer(const char* servername,
169  Int_t portnumber,
170  const char* basename,
171  const char* userpass,
172  const char* filter)
173 {
174  Browser()->ConnectHServer(servername,
175  portnumber,
176  basename,
177  userpass,
178  filter);
179  ProcessEvents(200);
180 }
181 
182 void TGo4AbstractInterface::ConnectDabc(const char* servername)
183 {
184  Browser()->ConnectDabc(servername);
185 }
186 
188 {
189  return Server()==0 ? kFALSE : Server()->IsConnected();
190 }
191 
192 void TGo4AbstractInterface::ExecuteLine(const char* remotecmd)
193 {
194  TGo4ServerProxy* anal = Server();
195  if ((anal!=0) && (remotecmd!=0)) {
196  anal->ExecuteLine(remotecmd);
197  TGo4Log::Message(1, "Exec: %s", remotecmd);
198  }
199 }
200 
202 {
203  TGo4ServerProxy* anal = Server();
204  if (anal!=0)
205  anal->RequestAnalysisSettings();
206 }
207 
208 void TGo4AbstractInterface::MonitorItem(const char* itemname, Bool_t on)
209 {
210  TGo4Slot* itemslot = Browser()->BrowserSlot(itemname);
211  if (itemslot!=0)
212  Browser()->SetItemMonitored(itemslot, on);
213 }
214 
216 {
217  Browser()->ToggleMonitoring(period*1000);
218 }
219 
221 {
222  Browser()->ToggleMonitoring(-1);
223 }
224 
225 TString TGo4AbstractInterface::FindItem(const char* objname)
226 {
227  // if itemname is specified, return as is
228  if (Browser()->ItemSlot(objname)!=0) return TString(objname);
229 
230  return Browser()->FindItem(objname);
231 }
232 
233 Bool_t TGo4AbstractInterface::CopyItem(const char* itemname)
234 {
235  return Browser()->ProduceExplicitCopy(itemname);
236 }
237 
238 Bool_t TGo4AbstractInterface::DeleteItem(const char* itemname)
239 {
240  return Browser()->DeleteDataSource(Browser()->ItemSlot(itemname));
241 }
242 
243 void TGo4AbstractInterface::FetchItem(const char* itemname, Int_t wait_time)
244 {
245  Browser()->FetchItem(itemname, wait_time);
246 }
247 
248 void TGo4AbstractInterface::RedrawItem(const char* itemname)
249 {
250  Browser()->RedrawItem(itemname);
251 }
252 
253 TObject* TGo4AbstractInterface::GetObject(const char* itemname, Int_t updatelevel)
254 {
255  if ((itemname==0) || (strlen(itemname)==0)) return 0;
256 
257  return Browser()->GetBrowserObject(itemname, updatelevel);
258 }
259 
260 TString TGo4AbstractInterface::SaveToMemory(const char* path, TObject* obj, Bool_t ownership)
261 {
262  TString res = Browser()->SaveToMemory(path, obj, ownership, kTRUE);
263 
264  ProcessEvents();
265 
266  return res;
267 }
268 
269 Bool_t TGo4AbstractInterface::LoadHotStart(const char* filename)
270 {
272 
273  std::ifstream f(filename);
274 
275  if (!f.good()) return kFALSE;
276 
277  char buf[10000];
278 
279  while (!f.eof()) {
280  f.getline(buf, 10000);
281  fxCommands.Add(new TObjString(buf));
282  }
283 
284  if (fxCommands.IsEmpty()) return kFALSE;
285 
286  // Add empty string, which will be deleted first
287  fxCommands.AddFirst(new TObjString(""));
288  return kTRUE;
289 }
290 
292 {
293  return !fxCommands.IsEmpty();
294 }
295 
297 {
298  if (fxCommands.IsEmpty()) return 0;
299  TObject* obj = fxCommands.First();
300  fxCommands.Remove(obj);
301  delete obj;
302  const char* res = 0;
303  do {
304  if (fxCommands.IsEmpty()) return 0;
305  TObjString* str = (TObjString*) fxCommands.First();
306  res = str->GetName();
307  if ((res==0) || (strlen(res)==0)) {
308  res = 0;
309  fxCommands.Remove(str);
310  delete str;
311  }
312 
313  } while (res == 0);
314  return res;
315 }
316 
318 {
319  fxCommands.Delete();
320 }
321 
323 {
324  TString rootsys;
325  if (gSystem->Getenv("ROOTSYS") != 0) {
326  rootsys = gSystem->Getenv("ROOTSYS");
327  if (rootsys[rootsys.Length()-1] != '/') rootsys+="/";
328  }
329 
330  TString go4sys = TGo4Log::GO4SYS();
331 
332  TString libs = gInterpreter->GetSharedLibs();
333  const char* token = strtok((char*) libs.Data(), " ,\t\n");
334  while(token != 0) {
335  if ((fInitSharedLibs.Index(token) == kNPOS)
336 // (strstr(token,"libGX11.")==0) &&
337 // (strstr(token,"libGX11TTF.")==0) &&
338  && (strstr(token,"libHistPainter.")==0)) {
339  fs << "go4->LoadLibrary(\"";
340  if ((go4sys.Length() > 0) && strstr(token, go4sys.Data())==token)
341  fs << "$GO4SYS/" << (token + go4sys.Length());
342  else
343  if ((rootsys.Length() > 0) && strstr(token, rootsys.Data())==token)
344  fs << "$ROOTSYS/" << (token + rootsys.Length());
345  else
346  fs << token;
347 
348  fs << "\");" << std::endl;
349  }
350  token = strtok(NULL, " ,\t\n");
351  }
352 }
353 
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:167
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:209
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:192
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:158
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:45
virtual void LoadLibrary(const char *fname)