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