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