GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
MainGo4GUI.cpp
Go to the documentation of this file.
1 // $Id$
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 <QDir>
15 #include <QStringList>
16 #include <iostream>
17 
18 #include "TSystem.h"
19 #include "TEnv.h"
20 #include "TApplication.h"
21 #include "TInterpreter.h"
22 
23 #include "QRootApplication.h"
24 #include "TGo4Log.h"
25 #include "TGo4Version.h"
26 #include "TGo4MainWindow.h"
27 #include "TGo4BrowserProxy.h"
28 #include "TGo4DabcProxy.h"
29 #include "TGo4QSettings.h"
30 #include "TGo4AbstractInterface.h"
31 
32 #ifndef _MSC_VER
33 #ifdef __GO4X11__
34 #include "TGX11.h"
35 //extern void qt_x11_set_global_double_buffer(bool);
36 #endif
37 #else
38 #include "TGo4BufferQueue.h"
39 #endif
40 
41 
42 #ifdef __GO4WEB__
43 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
44 #include <QtWebEngine>
45 #endif
46 #endif
47 
49 {
50  const char *dabc_vers = TGo4DabcProxy::GetDabcVersion();
51  std::cout << " Go4 " << __GO4RELEASE__ << ", build with ROOT " << ROOT_RELEASE;
52  if (dabc_vers) std::cout << ", DABC " << dabc_vers;
53  std::cout << " and Qt " << QT_VERSION_STR << std::endl;
54  return 0;
55 }
56 
57 
58 int go4_usage() {
59 
61 
62  std::cout << "Usage: " << std::endl;
63  std::cout << " go4 [args] - start go4 GUI" << std::endl;
64  std::cout << " go4 file1.root - load ROOT file(s) at start" << std::endl;
65  std::cout << " go4 filename[.hotstart] - process hotstart file" << std::endl;
66  std::cout << " go4 -observer hostname port - connect with running analysis server" << std::endl;
67  std::cout << " go4 -controller hostname port" << std::endl;
68  std::cout << " go4 -admin hostname port" << std::endl;
69  std::cout << " go4 -prepare - prepare for analysis client connection" << std::endl;
70  std::cout << " go4 -usergui - activate usergui" << std::endl;
71 #ifdef __GO4WEB__
72  std::cout << " go4 -web - activate web-based canvas" << std::endl;
73 #endif
75  std::cout << " go4 dabc://server[:port] - connect with DABC server" << std::endl;
76  std::cout << " go4 http://server[:port] - connect with ROOT-based HTTP server" << std::endl;
77  std::cout << " go4 -debug - enable GUI debug output" << std::endl;
78  std::cout << " go4 -gdebug [lvl] - set ROOT gDebug value (default 1)" << std::endl;
79  std::cout << " go4 -help - show this help information" << std::endl;
80 
81  return 0;
82 }
83 
84 int main(int argc, char **argv)
85 {
86  if ((argc==2) && (!strcmp(argv[1],"?") || !strcmp(argv[1],"-h") || !strcmp(argv[1],"-help") || !strcmp(argv[1],"--help"))) return go4_usage();
87 
88  setlocale(LC_ALL, "C");
89 
90 #ifndef _MSC_VER
91 #ifdef __GO4X11__
92  gEnv->SetValue("X11.XInitThread", 0); // required to avoid conflicts with Qt4
93 #endif
94  // qt_x11_set_global_double_buffer(false); // improves qtroot canvas update
95  bool iswin32 = false;
96 #else
97  bool iswin32 = true;
98  {
99  // work around for client connection problem in windows
100  // One should create several buffers and call WriteObjects before
101  // any kind of connection will be done
102  TGo4BufferQueue dummy("dummyQueue");
103  }
104 
105 #endif
106 
108  std::cerr << "Please configure your system correctly and restart go4 again" << std::endl;
109  return -1;
110  }
111 
112  int dologin = -1;
113  const char *loghost = "localhost";
114  int logport = 5000;
115  const char *logpass = nullptr;
116 
117  bool prepare_for_client = false, traceon = false, usergui = false;
118 
119 #ifdef __GO4WEB__
120  bool useweb = false;
121 #endif
122 
123 #ifndef __GO4X11__
124 #ifdef __GO4WEB__
125  useweb = true;
126 #else
127  std::cerr << "Failure, go4 build without x11 and without web support" << std::endl;
128  return -1;
129 #endif
130 #endif
131 
132  QString hotstart, dabcnode;
133  QStringList files, httpnodes;
134 
135  for (int narg = 1; narg < argc; narg++) {
136  if (strlen(argv[narg]) == 0)
137  continue;
138 
139  QString curr(argv[narg]);
140 
141  if (argv[narg][0]=='-') {
142  if ((curr == "--web") || (curr == "-web")) {
143 #ifdef __GO4WEB__
144  useweb = true;
145 #endif
146  } else if (curr == "-debug") {
147  std::cout << "G-OOOO-> MainGo4GUI switched on debug output" << std::endl;
148  traceon = true;
149  } else if (curr == "-gdebug") {
150  if ((narg+1 < argc) && (strlen(argv[narg+1]) > 0) && (argv[narg+1][0]!='-'))
151  gDebug = TString(argv[++narg]).Atoi();
152  else
153  gDebug = 1;
154  } else if ((curr == "-observer") || (curr == "-controller") || (curr == "-admin")) {
155 
156  if (curr == "-observer") dologin = 0;
157  if (curr == "-controller") dologin = 1;
158  if (curr == "-admin") dologin = 2;
159 
160  if ((narg+1<argc) && (argv[narg+1][0]!='-'))
161  loghost = argv[++narg];
162 
163  if ((narg+1<argc) && (argv[narg+1][0]!='-') && (argv[narg+1][0]>='0') && (argv[narg+1][0]<='9'))
164  logport = QString(argv[++narg]).toInt();
165 
166  if ((narg+1<argc) && (argv[narg+1][0]!='-')) logpass = argv[++narg];
167  } else if (curr == "-prepare") {
168  prepare_for_client = true;
169  } else if (curr == "-usergui") {
170  usergui = true;
171  }
172  } else if (curr.contains(".root")) {
173  files.append(argv[narg]);
174  } else if (curr.contains("dabc://")) {
175  dabcnode = argv[narg];
176  } else if (curr.contains("http://") || curr.contains("https://")) {
177  httpnodes.append(argv[narg]);
178  } else if (hotstart.isEmpty()) {
179  hotstart = argv[narg];
180  if(!curr.contains(".hotstart")) hotstart.append(".hotstart");
181  }
182  }
183 
184  argc = 1; // hide all additional parameters from ROOT and Qt
185 
187  // has to be done here, since mainwindow components have local
188  // settings access before mainwindow init is executed!
189  // Default is to use current directory. Environment variable
190  // GO4SETTINGS can be set to a certain go4 setup location
191  // if GO4SETTINGS contains the "ACCOUNT" keyword, we use the
192  // qt default to have the settings in $HOME/.config/GSI
194  // we may store window geometries to local folder (or into user path, or into account path),
195  // the rest is in the account settings since we cannot specify user path anymore
196  // (will be in $HOME/.config/GSI/go4.conf)
197 
198  const char *_env = gSystem->Getenv("GO4SETTINGS");
199 
200  QString settfile;
201  if (_env) settfile = _env;
202 
203  if(iswin32 || settfile.isEmpty() || settfile.contains("ACCOUNT")) {
204  settfile = "";
205  // do nothing, it is default location in .config/GSI/go4.conf
206  } else {
207  if (settfile.contains("LOCAL")) settfile = QDir::currentPath() + "/go4.conf";
208  QString subdir = QFileInfo(settfile).absolutePath();
209  // if there is no write access to directory where setting file should be placed,
210  // default directory will be used
211  if (gSystem->AccessPathName(subdir.toLatin1().constData(),kWritePermission))
212  settfile = "";
213  }
214 
215  go4sett = new TGo4QSettings(settfile);
216 #ifdef __GO4WEB__
217  go4sett->setWebBasedCanvas(useweb);
218 #endif
219 
221  if(traceon) TGo4Log::SetIgnoreLevel(0);
222  else TGo4Log::SetIgnoreLevel(1);
223 
225 
226  // first thing to set is screen scale factor for Qt>5.6
227  double scalefactor = go4sett->getScreenScaleFactor();
228 
229  std::cout << "Use Screen scale factor " << scalefactor << " from settings." << std::endl;
230  gSystem->Setenv("QT_SCALE_FACTOR",QString("%1").arg(scalefactor).toLatin1 ().constData ());
231 
232  TApplication app("uno", &argc, argv); // ROOT application
233 
234  char *argv2[3];
235  argv2[0] = argv[0];
236 #ifdef __GO4WEB__
237  argv2[argc++] = (char *) "--ignore-gpu-blacklist";
238 #endif
239  argv2[argc] = nullptr;
240 
241  Q_INIT_RESOURCE(go4icons);
242 
243 #ifdef __GO4WEB__
244 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
245 #if QT_VERSION >= QT_VERSION_CHECK(5,13,0)
246  // must be called before creating QApplication, from Qt 5.13
247  if (useweb) QtWebEngine::initialize();
248 #endif
249 #endif
250 #endif
251 
252  QRootApplication myapp(argc, argv2); // Qt application
253 
254 #ifdef __GO4WEB__
255 #if QT_VERSION < QT_VERSION_CHECK(5,13,0)
256  // must be called after creating QApplication, until Qt 5.12
257  if (useweb) QtWebEngine::initialize();
258 #endif
259 #endif
260 
261  // qt4.4 sets local settings not to "C", but to system-depended values
262  ::setlocale(LC_ALL, "C");
263 
265 
266  TGo4Log::LogfileEnable(kFALSE); // will enable or disable logging all messages
267  TGo4Log::Instance(); // init logger object
268  TGo4Log::SetIgnoreLevel(1); // set this to 1 to suppress detailed debug output
269  // set this to 2 to get warnings and errors only
270  // set this to 3 to get errors only
271 
272  // SL 11.01.2018 Disable of interpreter locking makes strange problems with other ROOT components, try to keep it enabled
273 
274  gInterpreter->SetProcessLineLock(kTRUE); // changed for root 6 problems JAM 9-10-2018
275 
276  TString go4inc = TGo4Log::GO4INCPATH();
277  if (go4inc.IsNull())
278  go4inc = TGo4Log::subGO4SYS("include");
279  if (!go4inc.IsNull())
280  gInterpreter->AddIncludePath(go4inc.Data());
281 
282  // ShowGuideLines cases crashes - it has stored gpad in static variable
283  gEnv->SetValue("Canvas.ShowGuideLines", 0);
284 
285  // create instance, which should be used everywhere
286  TGo4MainWindow* Go4MainGUI = new TGo4MainWindow(&myapp);
287 
288  myapp.connect(&myapp, &QRootApplication::lastWindowClosed, &myapp, &QRootApplication::quit);
289 
290  Go4MainGUI->ensurePolished();
291  Go4MainGUI->show();
292 
293  QApplication::setDoubleClickInterval(400); //ms, for Qt>=3.3 avoid very fast defaults!
294  QApplication::setStartDragTime(150); // ms
295 
296  for (int i = 0; i < files.size(); ++i)
297  Go4MainGUI->Browser()->OpenFile(files.at(i).toLatin1().constData());
298 
299  if (dabcnode.length() > 0)
300  Go4MainGUI->Browser()->ConnectDabc(dabcnode.toLatin1().constData());
301 
302  for (int i = 0; i < httpnodes.size(); ++i)
303  Go4MainGUI->ConnectHttpServer(httpnodes.at(i).toLatin1().constData());
304 
305  if (hotstart.length() > 0)
306  Go4MainGUI->HotStart(hotstart.toLatin1().constData());
307 
308  if (usergui)
309  Go4MainGUI->UserPanelSlot();
310 
311  if (dologin >= 0) {
312  go4sett->setClientNode(loghost);
313  go4sett->setClientPort(logport);
314  go4sett->setClientDefaultPass(!logpass);
316  Go4MainGUI->ConnectServer(false, logpass);
317  } else if (prepare_for_client) {
318  Go4MainGUI->PrepareForClientConnection(false);
319  }
320 
321  int res = myapp.exec();
322  delete go4sett;
323  return res;
324 }
void setClientControllerMode(int)
TGo4ServerProxy * ConnectHttpServer(const char *addr=nullptr, const char *user=nullptr, const char *pass=nullptr, bool with_qt_process=false, bool get_analysis_config=false)
void OpenFile(const char *fname)
static TGo4Log * Instance()
Definition: TGo4Log.cxx:85
void HotStart(const char *fname)
void PrepareForClientConnection(bool interactive=true)
double getScreenScaleFactor()
void ConnectServer(bool interactive=true, const char *password="")
static Bool_t CheckVersion(Int_t version)
Definition: TGo4Version.cxx:42
static void SetIgnoreLevel(Int_t level)
Definition: TGo4Log.cxx:332
static void SetInitSharedLibs(const char *libs=nullptr)
TGo4BrowserProxy * Browser()
void setWebBasedCanvas(bool on=true)
void setClientPort(int)
#define __GO4RELEASE__
Definition: TGo4Version.h:25
static const char * GO4INCPATH()
Definition: TGo4Log.cxx:179
TGo4QSettings * go4sett
#define __GO4BUILDVERSION__
Definition: TGo4Version.h:24
int go4_usage()
Definition: MainGo4GUI.cpp:58
Bool_t ConnectDabc(const char *nodename)
int print_go4_version()
Definition: MainGo4GUI.cpp:48
static TString subGO4SYS(const char *subdir)
Definition: TGo4Log.cxx:189
void setClientNode(const QString &)
static const char * GetDabcVersion()
void setClientDefaultPass(bool)
static void LogfileEnable(Bool_t on=kTRUE)
Definition: TGo4Log.cxx:363
int main(int argc, char **argv)
Definition: MainGo4GUI.cpp:84