GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
MainGo4GUI.cpp
Go to the documentation of this file.
1 // $Id: MainGo4GUI.cpp 2162 2018-10-10 14:16:24Z adamczew $
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 <stdlib.h>
15 #include <stdio.h>
16 #include <string.h>
17 #include <qglobal.h>
18 #include <locale.h>
19 #include <QDir>
20 #include <QStringList>
21 
22 #include "TSystem.h"
23 #include "RVersion.h"
24 #include "TEnv.h"
25 #include "TApplication.h"
26 #include "QRootApplication.h"
27 #include "TInterpreter.h"
28 
29 #include "TGo4Log.h"
30 #include "TGo4Version.h"
31 #include "TGo4MainWindow.h"
32 #include "TGo4BrowserProxy.h"
33 #include "TGo4DabcProxy.h"
34 #include "TGo4BufferQueue.h"
35 #include "TGo4QSettings.h"
36 #include "TGo4AbstractInterface.h"
37 
38 #include "TROOT.h"
39 #include "Riostream.h"
40 
41 
42 #ifndef WIN32
43 #include "TGX11.h"
44 //extern void qt_x11_set_global_double_buffer(bool);
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;
70  std::cout << " go4 dabc://server[:port] - connect with DABC server" << std::endl;
71  std::cout << " go4 http://server[:port] - connect with ROOT-based HTTP server" << std::endl;
72  std::cout << " go4 -debug - enable GUI debug output" << std::endl;
73  std::cout << " go4 -gdebug [lvl] - set ROOT gDebug value (default 1)" << std::endl;
74  std::cout << " go4 -help - show this help information" << std::endl;
75 
76  return 0;
77 }
78 
79 int main(int argc, char **argv)
80 {
81  if ((argc==2) && (!strcmp(argv[1],"?") || !strcmp(argv[1],"-h") || !strcmp(argv[1],"-help") || !strcmp(argv[1],"--help"))) return go4_usage();
82 
83  setlocale(LC_ALL, "C");
84 
85 #ifndef WIN32
86  gEnv->SetValue("X11.XInitThread", 0); // required to avoid conflicts with Qt4
87  // qt_x11_set_global_double_buffer(false); // improves qtroot canvas update
88  bool iswin32 = false;
89 #else
90  bool iswin32 = true;
91  {
92  // work around for client connection problem in windows
93  // One should create several buffers and call WriteObjects before
94  // any kind of connection will be done
95  TGo4BufferQueue dummy("dummyQueue");
96  }
97 
98 #endif
99 
101  std::cerr << "Please configure your system correctly and restart go4 again" << std::endl;
102  return -1;
103  }
104 
105  int dologin = -1;
106  const char* loghost = "localhost";
107  int logport = 5000;
108  const char* logpass = 0;
109 
110  bool prepare_for_client = false;
111 
112  bool traceon = false;
113  QString hotstart(""), dabcnode("");
114  QStringList files, httpnodes;
115 
116  for(int narg=1;narg<argc;narg++) {
117  if (strlen(argv[narg])==0) continue;
118 
119  if (argv[narg][0]=='-') {
120  if(!strcmp(argv[narg], "-debug")) {
121  std::cout << "G-OOOO-> MainGo4GUI switched on debug output" << std::endl;
122  traceon = true;
123  } else
124  if(strcmp(argv[narg],"-gdebug")==0) {
125  if ((narg+1 < argc) && (strlen(argv[narg+1]) > 0) && (argv[narg+1][0]!='-'))
126  gDebug = TString(argv[++narg]).Atoi();
127  else
128  gDebug = 1;
129  } else
130  if((strcmp(argv[narg], "-observer")==0) ||
131  (strcmp(argv[narg], "-controller")==0) ||
132  (strcmp(argv[narg], "-admin")==0)) {
133 
134  if(strcmp(argv[narg], "-observer")==0) dologin = 0;
135  if(strcmp(argv[narg], "-controller")==0) dologin = 1;
136  if(strcmp(argv[narg], "-admin")==0) dologin = 2;
137 
138  if ((narg+1<argc) && (argv[narg+1][0]!='-'))
139  loghost = argv[++narg];
140 
141  if ((narg+1<argc) && (argv[narg+1][0]!='-') && (argv[narg+1][0]>='0') && (argv[narg+1][0]<='9'))
142  logport = QString(argv[++narg]).toInt();
143 
144  if ((narg+1<argc) && (argv[narg+1][0]!='-')) logpass = argv[++narg];
145  } else
146  if (strcmp(argv[narg], "-prepare")==0) {
147  prepare_for_client = true;
148  }
149  } else
150  if (QString(argv[narg]).contains(".root")) {
151  files.append(argv[narg]);
152  } else
153  if (QString(argv[narg]).contains("dabc://")) {
154  dabcnode = argv[narg];
155  } else
156  if (QString(argv[narg]).contains("http://") || QString(argv[narg]).contains("https://")) {
157  httpnodes.append(argv[narg]);
158  } else
159  if (hotstart.length()==0) {
160  hotstart = argv[narg];
161  if(!QString(argv[narg]).contains(".hotstart")) hotstart.append(".hotstart");
162  }
163  }
164 
165  argc = 1; // hide all additional parameters from ROOT and Qt
166 
167 
169  // has to be done here, since mainwindow components have local
170  // settings access before mainwindow init is executed!
171  // Default is to use current directory. Environment variable
172  // GO4SETTINGS can be set to a certain go4 setup location
173  // if GO4SETTINGS contains the "ACCOUNT" keyword, we use the
174  // qt default to have the settings in $HOME/.config/GSI
176  // we may store window geometries to local folder (or into user path, or into account path),
177  // the rest is in the account settings since we cannot specify user path anymore
178  // (will be in $HOME/.config/GSI/go4.conf)
179 
180  const char* _env = gSystem->Getenv("GO4SETTINGS");
181 
182  QString settfile;
183  if (_env!=0) settfile = _env;
184 
185  if(iswin32 || settfile.isEmpty() || settfile.contains("ACCOUNT")) {
186  settfile = "";
187  // do nothing, it is default location in .config/GSI/go4.conf
188  } else {
189  if (settfile.contains("LOCAL")) settfile = QDir::currentPath() + "/go4.conf";
190  QString subdir = QFileInfo(settfile).absolutePath();
191  // if there is no write access to directory where setting file should be placed,
192  // default directory will be used
193  if (gSystem->AccessPathName(subdir.toLatin1().constData(),kWritePermission))
194  settfile = "";
195  }
196 
197  go4sett = new TGo4QSettings(settfile);
198 
200  if(traceon) TGo4Log::SetIgnoreLevel(0);
201  else TGo4Log::SetIgnoreLevel(1);
202 
204 
205 
206 #if QT_VERSION >= QT_VERSION_CHECK(5,6,0)
207  // first thing to set is screen scale factor for Qt>5.6
208  double scalefactor=go4sett->getScreenScaleFactor();
209 
210  std::cout << "Use Screen scale factor "<<scalefactor<<" from settings." << std::endl;
211  gSystem->Setenv("QT_SCALE_FACTOR",QString("%1").arg(scalefactor).toLatin1 ().constData ());
212 #endif
213 
214 
215 
216  TApplication app("uno", &argc, argv); // ROOT application
217 
218 #if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
219 
220  QApplication::setColorSpec( QApplication::ManyColor );
221 #else
222  // JAM for qt4 option "many color" will cause empty ROOT canvas
223  QApplication::setColorSpec( QApplication::NormalColor);
224 #endif
225 
226  Q_INIT_RESOURCE(go4icons);
227 
228  QRootApplication myapp(argc, argv); // Qt application
229 
230 
231 
232  // qt4.4 sets local settings not to "C", but to system-depended values
233  ::setlocale(LC_ALL, "C");
234 
236 
237  TGo4Log::LogfileEnable(kFALSE); // will enable or disable logging all messages
238  TGo4Log::Instance(); // init logger object
239  TGo4Log::SetIgnoreLevel(1); // set this to 1 to suppress detailed debug output
240  // set this to 2 to get warnings and errors only
241  // set this to 3 to get errors only
242 
243 
244 
245 #if ROOT_VERSION_CODE < ROOT_VERSION(6,12,0)
246  gInterpreter->SetProcessLineLock(kFALSE);
247  // disable cint locking when called via process line
248  // makes problem in multi-threaded environment, where CINT lock
249  // also used for object streaming
250 #else
251  gInterpreter->SetProcessLineLock(kTRUE); // changed for root 6 problems JAM 9-10-2018
252 #endif
253 
254 
255  TString go4inc = TGo4Log::GO4INCPATH();
256  if (go4inc.Length()==0) go4inc = TGo4Log::subGO4SYS("include");
257  if (go4inc.Length()>0)
258  gInterpreter->AddIncludePath(go4inc.Data());
259 
260  // ShowGuideLines cases crashes - it has stored gpad in static variable
261  gEnv->SetValue("Canvas.ShowGuideLines", 0);
262 
263 
264 
265  // create instance, which should be used everywhere
266  TGo4MainWindow* Go4MainGUI = new TGo4MainWindow(&myapp);
267 
268  myapp.connect(&myapp, SIGNAL(lastWindowClosed()), &myapp, SLOT(quit()));
269 
270  Go4MainGUI->ensurePolished();
271  Go4MainGUI->show();
272 
273  //myapp.connect( &myapp, SIGNAL( lastWindowClosed() ), &myapp, SLOT( quit() ) );
274  QApplication::setDoubleClickInterval(400); //ms, for Qt>=3.3 avoid very fast defaults!
275  QApplication::setStartDragTime(150); // ms
276 
277  for (int i = 0; i < files.size(); ++i)
278  Go4MainGUI->Browser()->OpenFile(files.at(i).toLatin1().constData());
279 
280  if (dabcnode.length()>0)
281  Go4MainGUI->Browser()->ConnectDabc(dabcnode.toLatin1().constData());
282 
283  for (int i = 0; i < httpnodes.size(); ++i)
284  Go4MainGUI->ConnectHttpSlot(httpnodes.at(i).toLatin1().constData());
285 
286  if (hotstart.length()>0)
287  Go4MainGUI->HotStart(hotstart.toLatin1().constData());
288 
289  if (dologin>=0) {
290  go4sett->setClientNode(loghost);
291  go4sett->setClientPort(logport);
292  go4sett->setClientDefaultPass(logpass==0);
294  Go4MainGUI->ConnectServerSlot(false, logpass);
295  } else
296  if (prepare_for_client) {
297  Go4MainGUI->PrepareForClientConnectionSlot(false);
298  }
299 
300  int res = myapp.exec();
301  delete go4sett;
302  return res;
303 }
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:322
void ConnectServerSlot(bool interactive=true, const char *password="")
TGo4BrowserProxy * Browser()
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:369
int main(int argc, char **argv)
Definition: MainGo4GUI.cpp:79