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