Logo ROOT  
Reference Guide
TApplication.cxx
Go to the documentation of this file.
1 // @(#)root/base:$Id$
2 // Author: Fons Rademakers 22/12/95
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 /** \class TApplication
13 \ingroup Base
14 
15 This class creates the ROOT Application Environment that interfaces
16 to the windowing system eventloop and eventhandlers.
17 This class must be instantiated exactly once in any given
18 application. Normally the specific application class inherits from
19 TApplication (see TRint).
20 */
21 
22 #include "RConfigure.h"
23 #include "TApplication.h"
24 #include "TException.h"
25 #include "TGuiFactory.h"
26 #include "TVirtualX.h"
27 #include "TROOT.h"
28 #include "TSystem.h"
29 #include "TString.h"
30 #include "TError.h"
31 #include "TObjArray.h"
32 #include "TObjString.h"
33 #include "TTimer.h"
34 #include "TInterpreter.h"
35 #include "TStyle.h"
36 #include "TVirtualPad.h"
37 #include "TEnv.h"
38 #include "TColor.h"
39 #include "TPluginManager.h"
40 #include "TClassTable.h"
41 #include "TBrowser.h"
42 #include "TUrl.h"
43 #include "TVirtualMutex.h"
44 #include "TClassEdit.h"
45 #include "TMethod.h"
46 #include "TDataMember.h"
47 #include "TApplicationCommandLineOptionsHelp.h"
48 #include "TPRegexp.h"
49 #include <cstdlib>
50 #include <iostream>
51 #include <fstream>
52 
56 TList *TApplication::fgApplications = nullptr; // List of available applications
57 
58 ////////////////////////////////////////////////////////////////////////////////
59 
60 class TIdleTimer : public TTimer {
61 public:
63  Bool_t Notify();
64 };
65 
66 ////////////////////////////////////////////////////////////////////////////////
67 /// Notify handler.
68 
70 {
72  Reset();
73  return kFALSE;
74 }
75 
76 
78 
80 {
81  // Insure that the files, canvases and sockets are closed.
82 
83  // If we get here, the tear down has started. We have no way to know what
84  // has or has not yet been done. In particular on Ubuntu, this was called
85  // after the function static in TSystem.cxx has been destructed. So we
86  // set gROOT in its end-of-life mode which prevents executing code, like
87  // autoloading libraries (!) that is pointless ...
88  if (gROOT) {
89  gROOT->SetBit(kInvalidObject);
90  gROOT->EndOfProcessCleanups();
91  }
92 }
93 
94 ////////////////////////////////////////////////////////////////////////////////
95 /// Default ctor. Can be used by classes deriving from TApplication.
96 
98  fArgc(0), fArgv(nullptr), fAppImp(nullptr), fIsRunning(kFALSE), fReturnFromRun(kFALSE),
99  fNoLog(kFALSE), fNoLogo(kFALSE), fQuit(kFALSE), fUseMemstat(kFALSE),
100  fFiles(nullptr), fIdleTimer(nullptr), fSigHandler(nullptr), fExitOnException(kDontExit),
101  fAppRemote(nullptr)
102 {
104 }
105 
106 ////////////////////////////////////////////////////////////////////////////////
107 /// Create an application environment. The application environment
108 /// provides an interface to the graphics system and eventloop
109 /// (be it X, Windows, MacOS or BeOS). After creating the application
110 /// object start the eventloop by calling its Run() method. The command
111 /// line options recognized by TApplication are described in the GetOptions()
112 /// method. The recognized options are removed from the argument array.
113 /// The original list of argument options can be retrieved via the Argc()
114 /// and Argv() methods. The appClassName "proofserv" is reserved for the
115 /// PROOF system. The "options" and "numOptions" arguments are not used,
116 /// except if you want to by-pass the argv processing by GetOptions()
117 /// in which case you should specify numOptions<0. All options will
118 /// still be available via the Argv() method for later use.
119 
120 TApplication::TApplication(const char *appClassName, Int_t *argc, char **argv,
121  void * /*options*/, Int_t numOptions) :
122  fArgc(0), fArgv(nullptr), fAppImp(nullptr), fIsRunning(kFALSE), fReturnFromRun(kFALSE),
123  fNoLog(kFALSE), fNoLogo(kFALSE), fQuit(kFALSE), fUseMemstat(kFALSE),
124  fFiles(nullptr), fIdleTimer(nullptr), fSigHandler(nullptr), fExitOnException(kDontExit),
125  fAppRemote(nullptr)
126 {
128 
129  // Create the list of applications the first time
130  if (!fgApplications)
131  fgApplications = new TList;
132 
133  // Add the new TApplication early, so that the destructor of the
134  // default TApplication (if it is called in the block of code below)
135  // will not destroy the files, socket or TColor that have already been
136  // created.
137  fgApplications->Add(this);
138 
140  // allow default TApplication to be replaced by a "real" TApplication
141  delete gApplication;
142  gApplication = nullptr;
143  gROOT->SetBatch(kFALSE);
145  }
146 
147  if (gApplication) {
148  Error("TApplication", "only one instance of TApplication allowed");
149  fgApplications->Remove(this);
150  return;
151  }
152 
153  if (!gROOT)
154  ::Fatal("TApplication::TApplication", "ROOT system not initialized");
155 
156  if (!gSystem)
157  ::Fatal("TApplication::TApplication", "gSystem not initialized");
158 
159  static Bool_t hasRegisterAtExit(kFALSE);
160  if (!hasRegisterAtExit) {
161  // If we are the first TApplication register the atexit)
162  atexit(CallEndOfProcessCleanups);
163  hasRegisterAtExit = kTRUE;
164  }
165  gROOT->SetName(appClassName);
166 
167  // copy command line arguments, can be later accessed via Argc() and Argv()
168  if (argc && *argc > 0) {
169  fArgc = *argc;
170  fArgv = (char **)new char*[fArgc];
171  }
172 
173  for (int i = 0; i < fArgc; i++)
174  fArgv[i] = StrDup(argv[i]);
175 
176  if (numOptions >= 0)
177  GetOptions(argc, argv);
178 
179  if (fArgv)
181 
182  // Tell TSystem the TApplication has been created
184 
185  fAppImp = gGuiFactory->CreateApplicationImp(appClassName, argc, argv);
187 
188  // Initialize the graphics environment
189  if (gClassTable->GetDict("TPad")) {
192  }
193 
194  // Save current interpreter context
195  gInterpreter->SaveContext();
196  gInterpreter->SaveGlobalsContext();
197 
198  // to allow user to interact with TCanvas's under WIN32
199  gROOT->SetLineHasBeenProcessed();
200 
201  // activate TMemStat
202  if (fUseMemstat || gEnv->GetValue("Root.TMemStat", 0)) {
203  fUseMemstat = kTRUE;
204  Int_t buffersize = gEnv->GetValue("Root.TMemStat.buffersize", 100000);
205  Int_t maxcalls = gEnv->GetValue("Root.TMemStat.maxcalls", 5000000);
206  const char *ssystem = gEnv->GetValue("Root.TMemStat.system","gnubuiltin");
207  if (maxcalls > 0) {
208  gROOT->ProcessLine(Form("new TMemStat(\"%s\",%d,%d);",ssystem,buffersize,maxcalls));
209  }
210  }
211 
212  //Needs to be done last
213  gApplication = this;
214  gROOT->SetApplication(this);
215 
216 }
217 
218 ////////////////////////////////////////////////////////////////////////////////
219 /// TApplication dtor.
220 
222 {
223  for (int i = 0; i < fArgc; i++)
224  if (fArgv[i]) delete [] fArgv[i];
225  delete [] fArgv;
226 
227  if (fgApplications)
228  fgApplications->Remove(this);
229 
230  //close TMemStat
231  if (fUseMemstat) {
232  ProcessLine("TMemStat::Close()");
234  }
235 
236  // Reduce the risk of the files or sockets being closed after the
237  // end of 'main' (or more exactly before the library start being
238  // unloaded).
239  if (fgApplications == nullptr || fgApplications->FirstLink() == nullptr ) {
240  TROOT::ShutDown();
241  }
242 
243  // Now that all the canvases and files have been closed we can
244  // delete the implementation.
246 }
247 
248 ////////////////////////////////////////////////////////////////////////////////
249 /// Static method. This method should be called from static library
250 /// initializers if the library needs the low level graphics system.
251 
253 {
255 }
256 
257 ////////////////////////////////////////////////////////////////////////////////
258 /// Initialize the graphics environment.
259 
261 {
262  if (fgGraphInit || !fgGraphNeeded) return;
263 
264  // Load the graphics related libraries
266 
267  // Try to load TrueType font renderer. Only try to load if not in batch
268  // mode and Root.UseTTFonts is true and Root.TTFontPath exists. Abort silently
269  // if libttf or libGX11TTF are not found in $ROOTSYS/lib or $ROOTSYS/ttf/lib.
270  const char *ttpath = gEnv->GetValue("Root.TTFontPath",
272  char *ttfont = gSystem->Which(ttpath, "arialbd.ttf", kReadPermission);
273  // Check for use of DFSG - fonts
274  if (!ttfont)
275  ttfont = gSystem->Which(ttpath, "FreeSansBold.ttf", kReadPermission);
276 
277 #if !defined(R__WIN32)
278  if (!gROOT->IsBatch() && !strcmp(gVirtualX->GetName(), "X11") &&
279  ttfont && gEnv->GetValue("Root.UseTTFonts", 1)) {
280  if (gClassTable->GetDict("TGX11TTF")) {
281  // in principle we should not have linked anything against libGX11TTF
282  // but with ACLiC this can happen, initialize TGX11TTF by hand
283  // (normally this is done by the static library initializer)
284  ProcessLine("TGX11TTF::Activate();");
285  } else {
286  TPluginHandler *h;
287  if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualX", "x11ttf")))
288  if (h->LoadPlugin() == -1)
289  Info("InitializeGraphics", "no TTF support");
290  }
291  }
292 #endif
293  delete [] ttfont;
294 
295  // Create WM dependent application environment
296  if (fAppImp)
297  delete fAppImp;
299  if (!fAppImp) {
300  MakeBatch();
302  }
303 
304  // Create the canvas colors early so they are allocated before
305  // any color table expensive bitmaps get allocated in GUI routines (like
306  // creation of XPM bitmaps).
308 
309  // Hook for further initializing the WM dependent application environment
310  Init();
311 
312  // Set default screen factor (if not disabled in rc file)
313  if (gEnv->GetValue("Canvas.UseScreenFactor", 1)) {
314  Int_t x, y;
315  UInt_t w, h;
316  if (gVirtualX) {
317  gVirtualX->GetGeometry(-1, x, y, w, h);
318  if (h > 0 && h < 1000) gStyle->SetScreenFactor(0.0011*h);
319  }
320  }
321 }
322 
323 ////////////////////////////////////////////////////////////////////////////////
324 /// Clear list containing macro files passed as program arguments.
325 /// This method is called from TRint::Run() to ensure that the macro
326 /// files are only executed the first time Run() is called.
327 
329 {
330  if (fFiles) {
331  fFiles->Delete();
333  }
334 }
335 
336 ////////////////////////////////////////////////////////////////////////////////
337 /// Return specified argument.
338 
339 char *TApplication::Argv(Int_t index) const
340 {
341  if (fArgv) {
342  if (index >= fArgc) {
343  Error("Argv", "index (%d) >= number of arguments (%d)", index, fArgc);
344  return nullptr;
345  }
346  return fArgv[index];
347  }
348  return nullptr;
349 }
350 
351 ////////////////////////////////////////////////////////////////////////////////
352 /// Get and handle command line options. Arguments handled are removed
353 /// from the argument array. See CommandLineOptionsHelp.h for options.
354 
355 void TApplication::GetOptions(Int_t *argc, char **argv)
356 {
357  static char null[1] = { "" };
358 
359  fNoLog = kFALSE;
360  fQuit = kFALSE;
361  fFiles = nullptr;
362 
363  if (!argc)
364  return;
365 
366  int i, j;
367  TString pwd;
368 
369  for (i = 1; i < *argc; i++) {
370  if (!strcmp(argv[i], "-?") || !strncmp(argv[i], "-h", 2) ||
371  !strncmp(argv[i], "--help", 6)) {
372  fprintf(stderr, kCommandLineOptionsHelp);
373  Terminate(0);
374  } else if (!strncmp(argv[i], "--version", 9)) {
375  fprintf(stderr, "ROOT Version: %s\n", gROOT->GetVersion());
376  fprintf(stderr, "Built for %s on %s\n",
378  gROOT->GetGitDate());
379 
380  fprintf(stderr, "From %s@%s\n",
381  gROOT->GetGitBranch(),
382  gROOT->GetGitCommit());
383 
384  Terminate(0);
385  } else if (!strcmp(argv[i], "-config")) {
386  fprintf(stderr, "ROOT ./configure options:\n%s\n", gROOT->GetConfigOptions());
387  Terminate(0);
388  } else if (!strcmp(argv[i], "-memstat")) {
389  fUseMemstat = kTRUE;
390  argv[i] = null;
391  } else if (!strcmp(argv[i], "-b")) {
392  MakeBatch();
393  argv[i] = null;
394  } else if (!strcmp(argv[i], "-n")) {
395  fNoLog = kTRUE;
396  argv[i] = null;
397  } else if (!strcmp(argv[i], "-t")) {
399  // EnableImplicitMT() only enables thread safety if IMT was configured;
400  // enable thread safety even with IMT off:
402  argv[i] = null;
403  } else if (!strcmp(argv[i], "-q")) {
404  fQuit = kTRUE;
405  argv[i] = null;
406  } else if (!strcmp(argv[i], "-l")) {
407  // used by front-end program to not display splash screen
408  fNoLogo = kTRUE;
409  argv[i] = null;
410  } else if (!strcmp(argv[i], "-x")) {
412  argv[i] = null;
413  } else if (!strcmp(argv[i], "-splash")) {
414  // used when started by front-end program to signal that
415  // splash screen can be popped down (TRint::PrintLogo())
416  argv[i] = null;
417  } else if (strncmp(argv[i], "--web", 5) == 0) {
418  // the web mode is requested
419  const char *opt = argv[i] + 5;
420  argv[i] = null;
421  TString argw;
422  if (gROOT->IsBatch()) argw = "batch";
423  if (*opt == '=') argw.Append(opt+1);
424  if (gSystem->Load("libROOTWebDisplay") >= 0) {
425  gROOT->SetWebDisplay(argw.Data());
426  gEnv->SetValue("Gui.Factory", "web");
427  } else {
428  Error("GetOptions", "--web option not supported, ROOT should be built with at least c++14 enabled");
429  }
430  } else if (!strcmp(argv[i], "-e")) {
431  argv[i] = null;
432  ++i;
433 
434  if ( i < *argc ) {
435  if (!fFiles) fFiles = new TObjArray;
436  TObjString *expr = new TObjString(argv[i]);
437  expr->SetBit(kExpression);
438  fFiles->Add(expr);
439  argv[i] = null;
440  } else {
441  Warning("GetOptions", "-e must be followed by an expression.");
442  }
443  } else if (!strcmp(argv[i], "--")) {
444  TObjString* macro = nullptr;
445  bool warnShown = false;
446 
447  if (fFiles) {
448  for (auto f: *fFiles) {
449  TObjString *file = dynamic_cast<TObjString *>(f);
450  if (!file) {
451  if (!dynamic_cast<TNamed*>(f)) {
452  Error("GetOptions()", "Inconsistent file entry (not a TObjString)!");
453  if (f)
454  f->Dump();
455  } // else we did not find the file.
456  continue;
457  }
458 
459  if (file->TestBit(kExpression))
460  continue;
461  if (file->String().EndsWith(".root"))
462  continue;
463  if (file->String().Contains('('))
464  continue;
465 
466  if (macro && !warnShown && (warnShown = true))
467  Warning("GetOptions", "-- is used with several macros. "
468  "The arguments will be passed to the last one.");
469 
470  macro = file;
471  }
472  }
473 
474  if (macro) {
475  argv[i] = null;
476  ++i;
477  TString& str = macro->String();
478 
479  str += '(';
480  for (; i < *argc; i++) {
481  str += argv[i];
482  str += ',';
483  argv[i] = null;
484  }
485  str.EndsWith(",") ? str[str.Length() - 1] = ')' : str += ')';
486  } else {
487  Warning("GetOptions", "no macro to pass arguments to was provided. "
488  "Everything after the -- will be ignored.");
489  for (; i < *argc; i++)
490  argv[i] = null;
491  }
492  } else if (argv[i][0] != '-' && argv[i][0] != '+') {
493  Long64_t size;
494  Long_t id, flags, modtime;
495  char *arg = strchr(argv[i], '(');
496  if (arg) *arg = '\0';
497  char *dir = gSystem->ExpandPathName(argv[i]);
498  // ROOT-9959: we do not continue if we could not expand the path
499  if (!dir) continue;
500  TUrl udir(dir, kTRUE);
501  // remove options and anchor to check the path
502  TString sfx = udir.GetFileAndOptions();
503  TString fln = udir.GetFile();
504  sfx.Replace(sfx.Index(fln), fln.Length(), "");
505  TString path = udir.GetFile();
506  if (strcmp(udir.GetProtocol(), "file")) {
507  path = udir.GetUrl();
508  path.Replace(path.Index(sfx), sfx.Length(), "");
509  }
510  // 'path' is the full URL without suffices (options and/or anchor)
511  if (arg) *arg = '(';
512  if (!arg && !gSystem->GetPathInfo(path.Data(), &id, &size, &flags, &modtime)) {
513  if ((flags & 2)) {
514  // if directory set it in fWorkDir
515  if (pwd == "") {
516  pwd = gSystem->WorkingDirectory();
517  fWorkDir = dir;
518  gSystem->ChangeDirectory(dir);
519  argv[i] = null;
520  } else if (!strcmp(gROOT->GetName(), "Rint")) {
521  Warning("GetOptions", "only one directory argument can be specified (%s)", dir);
522  }
523  } else if (size > 0) {
524  // if file add to list of files to be processed
525  if (!fFiles) fFiles = new TObjArray;
526  fFiles->Add(new TObjString(path.Data()));
527  argv[i] = null;
528  } else {
529  Warning("GetOptions", "file %s has size 0, skipping", dir);
530  }
531  } else {
532  if (TString(udir.GetFile()).EndsWith(".root")) {
533  if (!strcmp(udir.GetProtocol(), "file")) {
534  // file ending on .root but does not exist, likely a typo
535  // warn user if plain root...
536  if (!strcmp(gROOT->GetName(), "Rint"))
537  Warning("GetOptions", "file %s not found", dir);
538  } else {
539  // remote file, give it the benefit of the doubt and add it to list of files
540  if (!fFiles) fFiles = new TObjArray;
541  fFiles->Add(new TObjString(argv[i]));
542  argv[i] = null;
543  }
544  } else {
545  TString mode,fargs,io;
546  TString fname = gSystem->SplitAclicMode(dir,mode,fargs,io);
547  char *mac;
548  if (!fFiles) fFiles = new TObjArray;
549  if ((mac = gSystem->Which(TROOT::GetMacroPath(), fname,
550  kReadPermission))) {
551  // if file add to list of files to be processed
552  fFiles->Add(new TObjString(argv[i]));
553  argv[i] = null;
554  delete [] mac;
555  } else {
556  // if file add an invalid entry to list of files to be processed
557  fFiles->Add(new TNamed("NOT FOUND!", argv[i]));
558  // only warn if we're plain root,
559  // other progs might have their own params
560  if (!strcmp(gROOT->GetName(), "Rint"))
561  Warning("GetOptions", "macro %s not found", fname.Data());
562  }
563  }
564  }
565  delete [] dir;
566  }
567  // ignore unknown options
568  }
569 
570  // go back to startup directory
571  if (pwd != "")
572  gSystem->ChangeDirectory(pwd);
573 
574  // remove handled arguments from argument array
575  j = 0;
576  for (i = 0; i < *argc; i++) {
577  if (strcmp(argv[i], "")) {
578  argv[j] = argv[i];
579  j++;
580  }
581  }
582 
583  *argc = j;
584 }
585 
586 ////////////////////////////////////////////////////////////////////////////////
587 /// Handle idle timeout. When this timer expires the registered idle command
588 /// will be executed by this routine and a signal will be emitted.
589 
591 {
592  if (!fIdleCommand.IsNull())
594 
595  Emit("HandleIdleTimer()");
596 }
597 
598 ////////////////////////////////////////////////////////////////////////////////
599 /// Handle exceptions (kSigBus, kSigSegmentationViolation,
600 /// kSigIllegalInstruction and kSigFloatingException) trapped in TSystem.
601 /// Specific TApplication implementations may want something different here.
602 
604 {
605  if (TROOT::Initialized()) {
606  if (gException) {
607  gInterpreter->RewindDictionary();
608  gInterpreter->ClearFileBusy();
609  }
610  if (fExitOnException == kExit)
611  gSystem->Exit(128 + sig);
612  else if (fExitOnException == kAbort)
613  gSystem->Abort();
614  else
615  Throw(sig);
616  }
617  gSystem->Exit(128 + sig);
618 }
619 
620 ////////////////////////////////////////////////////////////////////////////////
621 /// Set the exit on exception option. Setting this option determines what
622 /// happens in HandleException() in case an exception (kSigBus,
623 /// kSigSegmentationViolation, kSigIllegalInstruction or kSigFloatingException)
624 /// is trapped. Choices are: kDontExit (default), kExit or kAbort.
625 /// Returns the previous value.
626 
628 {
630  fExitOnException = opt;
631  return old;
632 }
633 
634 /////////////////////////////////////////////////////////////////////////////////
635 /// The function generates and executes a command that loads the Doxygen URL in
636 /// a browser. It works for Mac, Windows and Linux. In the case of Linux, the
637 /// function also checks if the DISPLAY is set. If it isn't, a warning message
638 /// and the URL will be displayed on the terminal.
639 ///
640 /// \param[in] url web page to be displayed in a browser
641 
643 {
644  // We check what operating system the user has.
645 #ifdef R__MACOSX
646  // Command for opening a browser on Mac.
647  TString cMac("open ");
648  // We generate the full command and execute it.
649  cMac.Append(url);
650  gSystem->Exec(cMac);
651 #elif defined(R__WIN32)
652  // Command for opening a browser on Windows.
653  TString cWindows("start ");
654  cWindows.Append(url);
655  gSystem->Exec(cWindows);
656 #else
657  // Command for opening a browser in Linux.
658  TString cLinux("xdg-open ");
659  // For Linux we check if the DISPLAY is set.
660  if (gSystem->Getenv("DISPLAY")) {
661  // If the DISPLAY is set it will open the browser.
662  cLinux.Append(url);
663  gSystem->Exec(cLinux);
664  } else {
665  // Else the user will have a warning and the URL in the terminal.
666  Warning("OpenInBrowser", "The $DISPLAY is not set! Please open (e.g. Ctrl-click) %s\n", url.Data());
667  }
668 #endif
669 }
670 
671 namespace {
672 enum EUrl { kURLforClass, kURLforNameSpace, kURLforStruct };
673 ////////////////////////////////////////////////////////////////////////////////
674 /// The function generates a URL address for class or namespace (scopeName).
675 /// This is the URL to the online reference guide, generated by Doxygen.
676 /// With the enumeration "EUrl" we pick which case we need - the one for
677 /// class (kURLforClass) or the one for namespace (kURLforNameSpace).
678 ///
679 /// \param[in] scopeName the name of the class or the namespace
680 /// \param[in] scopeType the enumerator for class or namespace
681 
682 static TString UrlGenerator(TString scopeName, EUrl scopeType)
683 {
684  // We start the URL with a static part, the same for all scopes and members.
685  TString url = "https://root.cern/doc/";
686  // Then we check the ROOT version used.
687  TPRegexp re4(R"(.*/(v\d)-(\d\d)-00-patches)");
688  const char *branchName = gROOT->GetGitBranch();
689  TObjArray *objarr = re4.MatchS(branchName);
690  TString version;
691  // We extract the correct version name for the URL.
692  if (objarr && objarr->GetEntries() == 3) {
693  // We have a valid version of ROOT and we will extract the correct name for the URL.
694  version = ((TObjString *)objarr->At(1))->GetString() + ((TObjString *)objarr->At(2))->GetString();
695  } else {
696  // If it's not a supported version, we will go to "master" branch.
697  version = "master";
698  }
699  delete objarr;
700  url.Append(version);
701  url.Append("/");
702  // We will replace all "::" with "_1_1" and all "_" with "__" in the
703  // classes definitions, due to Doxygen syntax requirements.
704  scopeName.ReplaceAll("_", "__");
705  scopeName.ReplaceAll("::", "_1_1");
706  // We build the URL for the correct scope type and name.
707  if (scopeType == kURLforClass) {
708  url.Append("class");
709  } else if (scopeType == kURLforStruct) {
710  url.Append("struct");
711  } else {
712  url.Append("namespace");
713  }
714  url.Append(scopeName);
715  url.Append(".html");
716  return url;
717 }
718 } // namespace
719 
720 namespace {
721 ////////////////////////////////////////////////////////////////////////////////
722 /// The function returns a TString with the arguments of a method from the
723 /// scope (scopeName), but modified with respect to Doxygen syntax - spacing
724 /// around special symbols and adding the missing scopes ("std::").
725 /// "FormatMethodArgsForDoxygen" works for functions defined inside namespaces
726 /// as well. We avoid looking up twice for the TFunction by passing "func".
727 ///
728 /// \param[in] scopeName the name of the class/namespace/struct
729 /// \param[in] func pointer to the method
730 
731 static TString FormatMethodArgsForDoxygen(const TString &scopeName, TFunction *func)
732 {
733  // With "GetSignature" we get the arguments of the method and put them in a TString.
734  TString methodArguments = func->GetSignature();
735  // "methodArguments" is modified with respect of Doxygen requirements.
736  methodArguments.ReplaceAll(" = ", "=");
737  methodArguments.ReplaceAll("* ", " *");
738  methodArguments.ReplaceAll("*=", " *=");
739  methodArguments.ReplaceAll("*)", " *)");
740  methodArguments.ReplaceAll("*,", " *,");
741  methodArguments.ReplaceAll("*& ", " *&");
742  methodArguments.ReplaceAll("& ", " &");
743  // TODO: prepend "std::" to all stdlib classes!
744  methodArguments.ReplaceAll("ostream", "std::ostream");
745  methodArguments.ReplaceAll("istream", "std::istream");
746  methodArguments.ReplaceAll("map", "std::map");
747  methodArguments.ReplaceAll("vector", "std::vector");
748  // We need to replace the "currentClass::foo" with "foo" in the arguments.
749  // TODO: protect the global functions.
750  TString scopeNameRE("\\b");
751  scopeNameRE.Append(scopeName);
752  scopeNameRE.Append("::\\b");
753  TPRegexp argFix(scopeNameRE);
754  argFix.Substitute(methodArguments, "");
755  return methodArguments;
756 }
757 } // namespace
758 
759 namespace {
760 ////////////////////////////////////////////////////////////////////////////////
761 /// The function checks if a member function of a scope is defined as inline.
762 /// If so, it also checks if it is virtual. Then the return type of "func" is
763 /// modified for the need of Doxygen and with respect to the function
764 /// definition. We pass pointer to the method (func) to not re-do the
765 /// TFunction lookup.
766 ///
767 /// \param[in] scopeName the name of the class/namespace/struct
768 /// \param[in] func pointer to the method
769 
770 static TString FormatReturnTypeForDoxygen(const TString &scopeName, TFunction *func)
771 {
772  // We put the return type of "func" in a TString "returnType".
773  TString returnType = func->GetReturnTypeName();
774  // If the return type is a type nested in the current class, it will appear scoped (Class::Enumeration).
775  // Below we make sure to remove the current class, because the syntax of Doxygen requires it.
776  TString scopeNameRE("\\b");
777  scopeNameRE.Append(scopeName);
778  scopeNameRE.Append("::\\b");
779  TPRegexp returnFix(scopeNameRE);
780  returnFix.Substitute(returnType, "");
781  // We check is if the method is defined as inline.
782  if (func->ExtraProperty() & kIsInlined) {
783  // We check if the function is defined as virtual.
784  if (func->Property() & kIsVirtual) {
785  // If the function is virtual, we append "virtual" before the return type.
786  returnType.Prepend("virtual ");
787  }
788  returnType.ReplaceAll(" *", "*");
789  } else {
790  // If the function is not inline we only change the spacing in "returnType"
791  returnType.ReplaceAll("*", " *");
792  }
793  // In any case (with no respect to virtual/inline check) we need to change
794  // the return type as following.
795  // TODO: prepend "std::" to all stdlib classes!
796  returnType.ReplaceAll("istream", "std::istream");
797  returnType.ReplaceAll("ostream", "std::ostream");
798  returnType.ReplaceAll("map", "std::map");
799  returnType.ReplaceAll("vector", "std::vector");
800  returnType.ReplaceAll("&", " &");
801  return returnType;
802 }
803 } // namespace
804 
805 namespace {
806 ////////////////////////////////////////////////////////////////////////////////
807 /// The function generates a URL for "dataMemberName" defined in "scopeName".
808 /// It returns a TString with the URL used in the online reference guide,
809 /// generated with Doxygen. For data members the URL consist of 2 parts -
810 /// URL for "scopeName" and a part for "dataMemberName".
811 /// For enumerator, the URL could be separated into 3 parts - URL for
812 /// "scopeName", part for the enumeration and a part for the enumerator.
813 ///
814 /// \param[in] scopeName the name of the class/namespace/struct
815 /// \param[in] dataMemberName the name of the data member/enumerator
816 /// \param[in] dataMember pointer to the data member/enumerator
817 /// \param[in] scopeType enumerator to the scope type
818 
819 static TString
820 GetUrlForDataMember(const TString &scopeName, const TString &dataMemberName, TDataMember *dataMember, EUrl scopeType)
821 {
822  // We first check if the data member is not enumerator.
823  if (!dataMember->IsEnum()) {
824  // If we work with data members, we have to append a hashed with MD5 text, consisting of:
825  // "Type ClassName::DataMemberNameDataMemberName(arguments)".
826  // We first get the type of the data member.
827  TString md5DataMember(dataMember->GetFullTypeName());
828  md5DataMember.Append(" ");
829  // We append the scopeName and "::".
830  md5DataMember.Append(scopeName);
831  md5DataMember.Append("::");
832  // We append the dataMemberName twice.
833  md5DataMember.Append(dataMemberName);
834  md5DataMember.Append(dataMemberName);
835  // We call UrlGenerator for the scopeName.
836  TString urlForDataMember = UrlGenerator(scopeName, scopeType);
837  // Then we append "#a" and the hashed text.
838  urlForDataMember.Append("#a");
839  urlForDataMember.Append(md5DataMember.MD5());
840  return urlForDataMember;
841  }
842  // If the data member is enumerator, then we first have to check if the enumeration is anonymous.
843  // Doxygen requires different syntax for anonymous enumeration ("scopeName::@1@1").
844  // We create a TString with the name of the scope and the enumeration from which the enumerator is.
845  TString scopeEnumeration = dataMember->GetTrueTypeName();
846  TString md5EnumClass;
847  if (scopeEnumeration.Contains("(anonymous)")) {
848  // FIXME: need to investigate the numbering scheme.
849  md5EnumClass.Append(scopeName);
850  md5EnumClass.Append("::@1@1");
851  } else {
852  // If the enumeration is not anonymous we put "scopeName::Enumeration" in a TString,
853  // which will be hashed with MD5 later.
854  md5EnumClass.Append(scopeEnumeration);
855  // We extract the part after "::" (this is the enumerator name).
856  TString enumOnlyName = TClassEdit::GetUnqualifiedName(scopeEnumeration);
857  // The syntax is "Class::EnumeratorEnumerator
858  md5EnumClass.Append(enumOnlyName);
859  }
860  // The next part of the URL is hashed "@ scopeName::EnumeratorEnumerator".
861  TString md5Enumerator("@ ");
862  md5Enumerator.Append(scopeName);
863  md5Enumerator.Append("::");
864  md5Enumerator.Append(dataMemberName);
865  md5Enumerator.Append(dataMemberName);
866  // We make the URL for the "scopeName".
867  TString url = UrlGenerator(scopeName, scopeType);
868  // Then we have to append the hashed text for the enumerator.
869  url.Append("#a");
870  url.Append(md5EnumClass.MD5());
871  // We append "a" and then the next hashed text.
872  url.Append("a");
873  url.Append(md5Enumerator.MD5());
874  return url;
875 }
876 } // namespace
877 
878 namespace {
879 ////////////////////////////////////////////////////////////////////////////////
880 /// The function generates URL for enumeration. The hashed text consist of:
881 /// "Class::EnumerationEnumeration".
882 ///
883 /// \param[in] scopeName the name of the class/namespace/struct
884 /// \param[in] enumeration the name of the enumeration
885 /// \param[in] scopeType enumerator for class/namespace/struct
886 
887 static TString GetUrlForEnumeration(TString scopeName, const TString &enumeration, EUrl scopeType)
888 {
889  // The URL consists of URL for the "scopeName", "#a" and hashed as MD5 text.
890  // The text is "Class::EnumerationEnumeration.
891  TString md5Enumeration(scopeName);
892  md5Enumeration.Append("::");
893  md5Enumeration.Append(enumeration);
894  md5Enumeration.Append(enumeration);
895  // We make the URL for the scope "scopeName".
896  TString url(UrlGenerator(scopeName, scopeType));
897  // Then we have to append "#a" and the hashed text.
898  url.Append("#a");
899  url.Append(md5Enumeration.MD5());
900  return url;
901 }
902 } // namespace
903 
904 namespace {
905 enum EMethodKind { kURLforMethod, kURLforStructor };
906 ////////////////////////////////////////////////////////////////////////////////
907 /// The function generates URL for any member function (including Constructor/
908 /// Destructor) of "scopeName". Doxygen first generates the URL for the scope.
909 /// We do that with the help of "UrlGenerator". Then we append "#a" and a
910 /// hashed with MD5 text. It consists of:
911 /// "ReturnType ScopeName::MethodNameMethodName(Method arguments)".
912 /// For constructor/destructor of a class, the return type is not appended.
913 ///
914 /// \param[in] scopeName the name of the class/namespace/struct
915 /// \param[in] methodName the name of the method from the scope
916 /// \param[in] func pointer to the method
917 /// \param[in] methodType enumerator for method or constructor
918 /// \param[in] scopeType enumerator for class/namespace/struct
919 
920 static TString GetUrlForMethod(const TString &scopeName, const TString &methodName, TFunction *func,
921  EMethodKind methodType, EUrl scopeType)
922 {
923  TString md5Text;
924  if (methodType == kURLforMethod) {
925  // In the case of method, we append the return type too.
926  // "FormatReturnTypeForDoxygen" modifies the return type with respect to Doxygen's requirement.
927  md5Text.Append((FormatReturnTypeForDoxygen(scopeName, func)));
928  if (scopeType == kURLforNameSpace) {
929  // We need to append "constexpr" if we work with constexpr functions in namespaces.
930  if (func->Property() & kIsConstexpr) {
931  md5Text.Prepend("constexpr ");
932  }
933  }
934  md5Text.Append(" ");
935  }
936  // We append ScopeName::MethodNameMethodName.
937  md5Text.Append(scopeName);
938  md5Text.Append("::");
939  md5Text.Append(methodName);
940  md5Text.Append(methodName);
941  // We use "FormatMethodArgsForDoxygen" to modify the arguments of Method with respect of Doxygen.
942  md5Text.Append(FormatMethodArgsForDoxygen(scopeName, func));
943  // We generate the URL for the class/namespace/struct.
944  TString url = UrlGenerator(scopeName, scopeType);
945  url.Append("#a");
946  // We append the hashed text.
947  url.Append(md5Text.MD5());
948  return url;
949 }
950 } // namespace
951 
952 
953 ////////////////////////////////////////////////////////////////////////////////
954 /// It opens the online reference guide, generated with Doxygen, for the
955 /// chosen scope (class/namespace/struct) or member (method/function/
956 /// data member/enumeration/enumerator. If the user types incorrect value,
957 /// it will return an error or warning.
958 ///
959 /// \param[in] strippedClass the scope or scope::member
960 
962 {
963  // We check if the user is searching for a scope and if the scope exists.
964  if (TClass *clas = TClass::GetClass(strippedClass)) {
965  // We check what scope he is searching for (class/namespace/struct).
966  // Enumerators will switch between the possible cases.
967  EUrl scopeType;
968  if (clas->Property() & kIsNamespace) {
969  scopeType = kURLforNameSpace;
970  } else if (clas->Property() & kIsStruct) {
971  scopeType = kURLforStruct;
972  } else {
973  scopeType = kURLforClass;
974  }
975  // If the user search directly for a scope we open the URL for him with OpenInBrowser.
976  OpenInBrowser(UrlGenerator(strippedClass, scopeType));
977  return;
978  }
979  // Else we subtract the name of the method and remove it from the command.
980  TString memberName = TClassEdit::GetUnqualifiedName(strippedClass);
981  // Error out if "strippedClass" is un-scoped (and it's not a class, see `TClass::GetClass(strippedClass)` above).
982  // TODO: Global functions.
983  if (strippedClass == memberName) {
984  Error("OpenReferenceGuideFor", "Unknown entity \"%s\" - global variables / functions not supported yet!",
985  strippedClass.Data());
986  return;
987  }
988  // Else we remove the member name to be left with the scope.
989  TString scopeName = strippedClass(0, strippedClass.Length() - memberName.Length() - 2);
990  // We check if the scope exists in ROOT.
991  TClass *cl = TClass::GetClass(scopeName);
992  if (!cl) {
993  // That's a member of something ROOT doesn't know.
994  Warning("OpenReferenceGuideFor", "\"%s\" does not exist in ROOT!", scopeName.Data());
995  return;
996  }
997  // We have enumerators for the three available cases - class, namespace and struct.
998  EUrl scopeType;
999  if (cl->Property() & kIsNamespace) {
1000  scopeType = kURLforNameSpace;
1001  } else if (cl->Property() & kIsStruct) {
1002  scopeType = kURLforStruct;
1003  } else {
1004  scopeType = kURLforClass;
1005  }
1006  // If the user wants to search for a method, we take its name (memberName) and
1007  // modify it - we delete everything starting at the first "(" so the user won't have to
1008  // do it by hand when they use Tab.
1009  int bracket = memberName.First("(");
1010  if (bracket > 0) {
1011  memberName.Remove(bracket);
1012  }
1013  // We check if "memberName" is a member function of "cl" or any of its base classes.
1014  if (TFunction *func = cl->GetMethodAllAny(memberName)) {
1015  // If so we find the name of the class that it belongs to.
1016  TString baseClName = ((TMethod *)func)->GetClass()->GetName();
1017  // We define an enumerator to distinguish between structor and method.
1018  EMethodKind methodType;
1019  // We check if "memberName" is a constructor.
1020  if (baseClName == memberName) {
1021  methodType = kURLforStructor;
1022  // We check if "memberName" is a destructor.
1023  } else if (memberName[0] == '~') {
1024  methodType = kURLforStructor;
1025  // We check if "memberName" is a method.
1026  } else {
1027  methodType = kURLforMethod;
1028  }
1029  // We call "GetUrlForMethod" for the correct class and scope.
1030  OpenInBrowser(GetUrlForMethod(baseClName, memberName, func, methodType, scopeType));
1031  return;
1032  }
1033  // We check if "memberName" is an enumeration.
1034  if (cl->GetListOfEnums()->FindObject(memberName)) {
1035  // If so with OpenInBrowser we open the URL generated with GetUrlForEnumeration
1036  // with respect to the "scopeType".
1037  OpenInBrowser(GetUrlForEnumeration(scopeName, memberName, scopeType));
1038  return;
1039  }
1040 
1041  // We check if "memberName" is enumerator defined in one the base classes of "scopeName".
1042  if (auto enumerator = (TDataMember *)cl->GetListOfAllPublicDataMembers()->FindObject(memberName)) {
1043  // We find the actual scope (might be in a base) and open the URL in a browser.
1044  TString baseClName = ((TMethod *)enumerator->GetClass())->GetName();
1045  OpenInBrowser(GetUrlForDataMember(baseClName, memberName, enumerator, scopeType));
1046  return;
1047  }
1048 
1049  // Warning message will appear if the user types the function name incorrectly
1050  // or the function is not a member function of "cl" or any of its base classes.
1051  Warning("Help", "cannot find \"%s\" as member of %s or its base classes! Check %s\n", memberName.Data(),
1052  scopeName.Data(), UrlGenerator(scopeName, scopeType).Data());
1053 }
1054 
1055 ////////////////////////////////////////////////////////////////////////////////
1056 /// The function lists useful commands (".help") or opens the online reference
1057 /// guide, generated with Doxygen (".help scope" or ".help scope::member").
1058 ///
1059 /// \param[in] line command from the command line
1060 
1061 void TApplication::Help(const char *line)
1062 {
1063  // We first check if the user wants to print the help on the interpreter.
1064  TString strippedCommand = TString(line).Strip(TString::kBoth);
1065  // If the user chooses ".help" or ".?".
1066  if ((strippedCommand == ".help") || (strippedCommand == ".?")) {
1067  gInterpreter->ProcessLine(line);
1068  Printf("\nROOT special commands.");
1069  Printf("==========================================================================");
1070  Printf(" .pwd : show current directory, pad and style");
1071  Printf(" .ls : list contents of current directory");
1072  Printf(" .which [file] : shows path of macro file");
1073  Printf(" .help Class : opens the reference guide for that class");
1074  Printf(" .help Class::Member : opens the reference guide for function/member");
1075  return;
1076  } else {
1077  // If the user wants to use the extended ".help scopeName" command to access
1078  // the online reference guide, we first check if the command starts correctly.
1079  if ((!strippedCommand.BeginsWith(".help ")) && (!strippedCommand.BeginsWith(".? "))) {
1080  Error("Help", "Unknown command!");
1081  return;
1082  }
1083  // We remove the command ".help" or ".?" from the TString.
1084  if (strippedCommand.BeginsWith(".? ")) {
1085  strippedCommand.Remove(0, 3);
1086  } else {
1087  strippedCommand.Remove(0, 5);
1088  }
1089  // We strip the command line after removing ".help" or ".?".
1090  strippedCommand = strippedCommand.Strip(TString::kBoth);
1091  // We call the function what handles the extended ".help scopeName" command.
1092  OpenReferenceGuideFor(strippedCommand);
1093  }
1094 }
1095 
1096 /// Load shared libs necessary for graphics. These libraries are only
1097 /// loaded when gROOT->IsBatch() is kFALSE.
1098 
1100 {
1101  if (gROOT->IsBatch()) return;
1102 
1103  TPluginHandler *h;
1104  if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualPad")))
1105  if (h->LoadPlugin() == -1)
1106  return;
1107 
1108  TString name;
1109  TString title1 = "ROOT interface to ";
1110  TString nativex, title;
1111  TString nativeg = "root";
1112 
1113 #ifdef R__WIN32
1114  nativex = "win32gdk";
1115  name = "Win32gdk";
1116  title = title1 + "Win32gdk";
1117 #elif defined(R__HAS_COCOA)
1118  nativex = "quartz";
1119  name = "quartz";
1120  title = title1 + "Quartz";
1121 #else
1122  nativex = "x11";
1123  name = "X11";
1124  title = title1 + "X11";
1125 #endif
1126 
1127  TString guiBackend(gEnv->GetValue("Gui.Backend", "native"));
1128  guiBackend.ToLower();
1129  if (guiBackend == "native") {
1130  guiBackend = nativex;
1131  } else {
1132  name = guiBackend;
1133  title = title1 + guiBackend;
1134  }
1135  TString guiFactory(gEnv->GetValue("Gui.Factory", "native"));
1136  guiFactory.ToLower();
1137  if (guiFactory == "native")
1138  guiFactory = nativeg;
1139 
1140  if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualX", guiBackend))) {
1141  if (h->LoadPlugin() == -1) {
1142  gROOT->SetBatch(kTRUE);
1143  return;
1144  }
1145  gVirtualX = (TVirtualX *) h->ExecPlugin(2, name.Data(), title.Data());
1146  fgGraphInit = kTRUE;
1147  }
1148  if ((h = gROOT->GetPluginManager()->FindHandler("TGuiFactory", guiFactory))) {
1149  if (h->LoadPlugin() == -1) {
1150  gROOT->SetBatch(kTRUE);
1151  return;
1152  }
1153  gGuiFactory = (TGuiFactory *) h->ExecPlugin(0);
1154  }
1155 }
1156 
1157 ////////////////////////////////////////////////////////////////////////////////
1158 /// Switch to batch mode.
1159 
1161 {
1162  gROOT->SetBatch();
1163  if (gGuiFactory != gBatchGuiFactory) delete gGuiFactory;
1165 #ifndef R__WIN32
1166  if (gVirtualX != gGXBatch) delete gVirtualX;
1167 #endif
1168  gVirtualX = gGXBatch;
1169 }
1170 
1171 ////////////////////////////////////////////////////////////////////////////////
1172 /// Parse the content of a line starting with ".R" (already stripped-off)
1173 /// The format is
1174 /// ~~~ {.cpp}
1175 /// [user@]host[:dir] [-l user] [-d dbg] [script]
1176 /// ~~~
1177 /// The variable 'dir' is the remote directory to be used as working dir.
1178 /// The username can be specified in two ways, "-l" having the priority
1179 /// (as in ssh).
1180 /// A 'dbg' value > 0 gives increasing verbosity.
1181 /// The last argument 'script' allows to specify an alternative script to
1182 /// be executed remotely to startup the session.
1183 
1185  TString &hostdir, TString &user,
1186  Int_t &dbg, TString &script)
1187 {
1188  if (!ln || strlen(ln) <= 0)
1189  return 0;
1190 
1191  Int_t rc = 0;
1192  Bool_t isHostDir = kTRUE;
1193  Bool_t isScript = kFALSE;
1194  Bool_t isUser = kFALSE;
1195  Bool_t isDbg = kFALSE;
1196 
1197  TString line(ln);
1198  TString tkn;
1199  Int_t from = 0;
1200  while (line.Tokenize(tkn, from, " ")) {
1201  if (tkn == "-l") {
1202  // Next is a user name
1203  isUser = kTRUE;
1204  } else if (tkn == "-d") {
1205  isDbg = kTRUE;
1206  } else if (tkn == "-close") {
1207  rc = 1;
1208  } else if (tkn.BeginsWith("-")) {
1209  ::Warning("TApplication::ParseRemoteLine","unknown option: %s", tkn.Data());
1210  } else {
1211  if (isUser) {
1212  user = tkn;
1213  isUser = kFALSE;
1214  } else if (isDbg) {
1215  dbg = tkn.Atoi();
1216  isDbg = kFALSE;
1217  } else if (isHostDir) {
1218  hostdir = tkn;
1219  hostdir.ReplaceAll(":","/");
1220  isHostDir = kFALSE;
1221  isScript = kTRUE;
1222  } else if (isScript) {
1223  // Add everything left
1224  script = tkn;
1225  script.Insert(0, "\"");
1226  script += "\"";
1227  // isScript = kFALSE; // [clang-tidy] never read
1228  break;
1229  }
1230  }
1231  }
1232 
1233  // Done
1234  return rc;
1235 }
1236 
1237 ////////////////////////////////////////////////////////////////////////////////
1238 /// Process the content of a line starting with ".R" (already stripped-off)
1239 /// The format is
1240 /// ~~~ {.cpp}
1241 /// [user@]host[:dir] [-l user] [-d dbg] [script] | [host] -close
1242 /// ~~~
1243 /// The variable 'dir' is the remote directory to be used as working dir.
1244 /// The username can be specified in two ways, "-l" having the priority
1245 /// (as in ssh).
1246 /// A 'dbg' value > 0 gives increasing verbosity.
1247 /// The last argument 'script' allows to specify an alternative script to
1248 /// be executed remotely to startup the session.
1249 
1251 {
1252  if (!line) return 0;
1253 
1254  if (!strncmp(line, "-?", 2) || !strncmp(line, "-h", 2) ||
1255  !strncmp(line, "--help", 6)) {
1256  Info("ProcessRemote", "remote session help:");
1257  Printf(".R [user@]host[:dir] [-l user] [-d dbg] [[<]script] | [host] -close");
1258  Printf("Create a ROOT session on the specified remote host.");
1259  Printf("The variable \"dir\" is the remote directory to be used as working dir.");
1260  Printf("The username can be specified in two ways, \"-l\" having the priority");
1261  Printf("(as in ssh). A \"dbg\" value > 0 gives increasing verbosity.");
1262  Printf("The last argument \"script\" allows to specify an alternative script to");
1263  Printf("be executed remotely to startup the session, \"roots\" being");
1264  Printf("the default. If the script is preceded by a \"<\" the script will be");
1265  Printf("sourced, after which \"roots\" is executed. The sourced script can be ");
1266  Printf("used to change the PATH and other variables, allowing an alternative");
1267  Printf("\"roots\" script to be found.");
1268  Printf("To close down a session do \".R host -close\".");
1269  Printf("To switch between sessions do \".R host\", to switch to the local");
1270  Printf("session do \".R\".");
1271  Printf("To list all open sessions do \"gApplication->GetApplications()->Print()\".");
1272  return 0;
1273  }
1274 
1275  TString hostdir, user, script;
1276  Int_t dbg = 0;
1277  Int_t rc = ParseRemoteLine(line, hostdir, user, dbg, script);
1278  if (hostdir.Length() <= 0) {
1279  // Close the remote application if required
1280  if (rc == 1) {
1282  delete fAppRemote;
1283  }
1284  // Return to local run
1285  fAppRemote = nullptr;
1286  // Done
1287  return 1;
1288  } else if (rc == 1) {
1289  // close an existing remote application
1290  TApplication *ap = TApplication::Open(hostdir, 0, nullptr);
1291  if (ap) {
1292  TApplication::Close(ap);
1293  delete ap;
1294  }
1295  }
1296  // Attach or start a remote application
1297  if (user.Length() > 0)
1298  hostdir.Insert(0,Form("%s@", user.Data()));
1299  const char *sc = (script.Length() > 0) ? script.Data() : nullptr;
1300  TApplication *ap = TApplication::Open(hostdir, dbg, sc);
1301  if (ap) {
1302  fAppRemote = ap;
1303  }
1304 
1305  // Done
1306  return 1;
1307 }
1308 
1309 namespace {
1310  static int PrintFile(const char* filename) {
1311  TString sFileName(filename);
1312  gSystem->ExpandPathName(sFileName);
1313  if (gSystem->AccessPathName(sFileName)) {
1314  Error("ProcessLine()", "Cannot find file %s", filename);
1315  return 1;
1316  }
1317  std::ifstream instr(sFileName);
1318  TString content;
1319  content.ReadFile(instr);
1320  Printf("%s", content.Data());
1321  return 0;
1322  }
1323  } // namespace
1324 
1325 ////////////////////////////////////////////////////////////////////////////////
1326 /// Process a single command line, either a C++ statement or an interpreter
1327 /// command starting with a ".".
1328 /// Return the return value of the command cast to a long.
1329 
1330 Longptr_t TApplication::ProcessLine(const char *line, Bool_t sync, Int_t *err)
1331 {
1332  if (!line || !*line) return 0;
1333 
1334  // If we are asked to go remote do it
1335  if (!strncmp(line, ".R", 2)) {
1336  Int_t n = 2;
1337  while (*(line+n) == ' ')
1338  n++;
1339  return ProcessRemote(line+n, err);
1340  }
1341 
1342  // Redirect, if requested
1345  return fAppRemote->ProcessLine(line, err);
1346  }
1347 
1348  if (!strncasecmp(line, ".qqqqqqq", 7)) {
1349  gSystem->Abort();
1350  } else if (!strncasecmp(line, ".qqqqq", 5)) {
1351  Info("ProcessLine", "Bye... (try '.qqqqqqq' if still running)");
1352  gSystem->Exit(1);
1353  } else if (!strncasecmp(line, ".exit", 4) || !strncasecmp(line, ".quit", 2)) {
1354  Terminate(0);
1355  return 0;
1356  }
1357 
1358  if (!strncmp(line, ".?", 2) || !strncmp(line, ".help", 5)) {
1359  Help(line);
1360  return 1;
1361  }
1362 
1363  if (!strncmp(line, ".demo", 5)) {
1364  if (gROOT->IsBatch()) {
1365  Error("ProcessLine", "Cannot show demos in batch mode!");
1366  return 1;
1367  }
1368  ProcessLine(".x " + TROOT::GetTutorialDir() + "/demos.C");
1369  return 0;
1370  }
1371 
1372  if (!strncmp(line, ".license", 8)) {
1373  return PrintFile(TROOT::GetDocDir() + "/LICENSE");
1374  }
1375 
1376  if (!strncmp(line, ".credits", 8)) {
1377  TString credits = TROOT::GetDocDir() + "/CREDITS";
1378  if (gSystem->AccessPathName(credits, kReadPermission))
1379  credits = TROOT::GetDocDir() + "/README/CREDITS";
1380  return PrintFile(credits);
1381  }
1382 
1383  if (!strncmp(line, ".pwd", 4)) {
1384  if (gDirectory)
1385  Printf("Current directory: %s", gDirectory->GetPath());
1386  if (gPad)
1387  Printf("Current pad: %s", gPad->GetName());
1388  if (gStyle)
1389  Printf("Current style: %s", gStyle->GetName());
1390  return 1;
1391  }
1392 
1393  if (!strncmp(line, ".ls", 3)) {
1394  const char *opt = nullptr;
1395  if (line[3]) opt = &line[3];
1396  if (gDirectory) gDirectory->ls(opt);
1397  return 1;
1398  }
1399 
1400  if (!strncmp(line, ".which", 6)) {
1401  char *fn = Strip(line+7);
1402  char *s = strtok(fn, "+("); // this method does not need to be reentrant
1404  if (!mac)
1405  Printf("No macro %s in path %s", s, TROOT::GetMacroPath());
1406  else
1407  Printf("%s", mac);
1408  delete [] fn;
1409  delete [] mac;
1410  return mac ? 1 : 0;
1411  }
1412 
1413  if (!strncmp(line, ".L", 2) || !strncmp(line, ".U", 2)) {
1414  TString aclicMode;
1415  TString arguments;
1416  TString io;
1417  TString fname = gSystem->SplitAclicMode(line+3, aclicMode, arguments, io);
1418 
1419  char *mac = gSystem->Which(TROOT::GetMacroPath(), fname, kReadPermission);
1420  if (arguments.Length()) {
1421  Warning("ProcessLine", "argument(s) \"%s\" ignored with .%c", arguments.Data(),
1422  line[1]);
1423  }
1424  Longptr_t retval = 0;
1425  if (!mac)
1426  Error("ProcessLine", "macro %s not found in path %s", fname.Data(),
1428  else {
1429  TString cmd(line+1);
1430  Ssiz_t posSpace = cmd.Index(' ');
1431  if (posSpace == -1) cmd.Remove(1);
1432  else cmd.Remove(posSpace);
1433  TString tempbuf;
1434  if (sync) {
1435  tempbuf.Form(".%s %s%s%s", cmd.Data(), mac, aclicMode.Data(),io.Data());
1436  retval = gInterpreter->ProcessLineSynch(tempbuf,
1437  (TInterpreter::EErrorCode*)err);
1438  } else {
1439  tempbuf.Form(".%s %s%s%s", cmd.Data(), mac, aclicMode.Data(),io.Data());
1440  retval = gInterpreter->ProcessLine(tempbuf,
1441  (TInterpreter::EErrorCode*)err);
1442  }
1443  }
1444 
1445  delete [] mac;
1446 
1448 
1449  return retval;
1450  }
1451 
1452  if (!strncmp(line, ".X", 2) || !strncmp(line, ".x", 2)) {
1453  return ProcessFile(line+3, err, line[2] == 'k');
1454  }
1455 
1456  if (!strcmp(line, ".reset")) {
1457  // Do nothing, .reset disabled in CINT because too many side effects
1458  Printf("*** .reset not allowed, please use gROOT->Reset() ***");
1459  return 0;
1460 
1461 #if 0
1462  // delete the ROOT dictionary since CINT will destroy all objects
1463  // referenced by the dictionary classes (TClass et. al.)
1464  gROOT->GetListOfClasses()->Delete();
1465  // fall through
1466 #endif
1467  }
1468 
1469  if (sync)
1470  return gInterpreter->ProcessLineSynch(line, (TInterpreter::EErrorCode*)err);
1471  else
1472  return gInterpreter->ProcessLine(line, (TInterpreter::EErrorCode*)err);
1473 }
1474 
1475 ////////////////////////////////////////////////////////////////////////////////
1476 /// Process a file containing a C++ macro.
1477 
1478 Longptr_t TApplication::ProcessFile(const char *file, Int_t *error, Bool_t keep)
1479 {
1480  return ExecuteFile(file, error, keep);
1481 }
1482 
1483 ////////////////////////////////////////////////////////////////////////////////
1484 /// Execute a file containing a C++ macro (static method). Can be used
1485 /// while TApplication is not yet created.
1486 
1487 Longptr_t TApplication::ExecuteFile(const char *file, Int_t *error, Bool_t keep)
1488 {
1489  static const Int_t kBufSize = 1024;
1490 
1491  if (!file || !*file) return 0;
1492 
1493  TString aclicMode;
1494  TString arguments;
1495  TString io;
1496  TString fname = gSystem->SplitAclicMode(file, aclicMode, arguments, io);
1497 
1498  char *exnam = gSystem->Which(TROOT::GetMacroPath(), fname, kReadPermission);
1499  if (!exnam) {
1500  ::Error("TApplication::ExecuteFile", "macro %s not found in path %s", fname.Data(),
1502  delete [] exnam;
1503  if (error)
1505  return 0;
1506  }
1507 
1508  ::std::ifstream macro(exnam, std::ios::in);
1509  if (!macro.good()) {
1510  ::Error("TApplication::ExecuteFile", "%s no such file", exnam);
1511  if (error)
1513  delete [] exnam;
1514  return 0;
1515  }
1516 
1517  char currentline[kBufSize];
1518  char dummyline[kBufSize];
1519  int tempfile = 0;
1520  int comment = 0;
1521  int ifndefc = 0;
1522  int ifdef = 0;
1523  char *s = nullptr;
1524  Bool_t execute = kFALSE;
1525  Longptr_t retval = 0;
1526 
1527  while (1) {
1528  bool res = (bool)macro.getline(currentline, kBufSize);
1529  if (macro.eof()) break;
1530  if (!res) {
1531  // Probably only read kBufSize, let's ignore the remainder of
1532  // the line.
1533  macro.clear();
1534  while (!macro.getline(dummyline, kBufSize) && !macro.eof()) {
1535  macro.clear();
1536  }
1537  }
1538  s = currentline;
1539  while (s && (*s == ' ' || *s == '\t')) s++; // strip-off leading blanks
1540 
1541  // very simple minded pre-processor parsing, only works in case macro file
1542  // starts with "#ifndef __CINT__". In that case everything till next
1543  // "#else" or "#endif" will be skipped.
1544  if (*s == '#') {
1545  char *cs = Compress(currentline);
1546  if (strstr(cs, "#ifndef__CINT__") ||
1547  strstr(cs, "#if!defined(__CINT__)"))
1548  ifndefc = 1;
1549  else if (ifndefc && (strstr(cs, "#ifdef") || strstr(cs, "#ifndef") ||
1550  strstr(cs, "#ifdefined") || strstr(cs, "#if!defined")))
1551  ifdef++;
1552  else if (ifndefc && strstr(cs, "#endif")) {
1553  if (ifdef)
1554  ifdef--;
1555  else
1556  ifndefc = 0;
1557  } else if (ifndefc && !ifdef && strstr(cs, "#else"))
1558  ifndefc = 0;
1559  delete [] cs;
1560  }
1561  if (!*s || *s == '#' || ifndefc || !strncmp(s, "//", 2)) continue;
1562 
1563  if (!comment && (!strncmp(s, ".X", 2) || !strncmp(s, ".x", 2))) {
1564  retval = ExecuteFile(s+3);
1565  execute = kTRUE;
1566  continue;
1567  }
1568 
1569  if (!strncmp(s, "/*", 2)) comment = 1;
1570  if (comment) {
1571  // handle slightly more complex cases like: /* */ /*
1572 again:
1573  s = strstr(s, "*/");
1574  if (s) {
1575  comment = 0;
1576  s += 2;
1577 
1578  while (s && (*s == ' ' || *s == '\t')) s++; // strip-off leading blanks
1579  if (!*s) continue;
1580  if (!strncmp(s, "//", 2)) continue;
1581  if (!strncmp(s, "/*", 2)) {
1582  comment = 1;
1583  goto again;
1584  }
1585  }
1586  }
1587  if (!comment && *s == '{') tempfile = 1;
1588  if (!comment) break;
1589  }
1590  macro.close();
1591 
1592  if (!execute) {
1593  TString exname = exnam;
1594  if (!tempfile) {
1595  // We have a script that does NOT contain an unnamed macro,
1596  // so we can call the script compiler on it.
1597  exname += aclicMode;
1598  }
1599  exname += arguments;
1600  exname += io;
1601 
1602  TString tempbuf;
1603  if (tempfile) {
1604  tempbuf.Form(".x %s", exname.Data());
1605  } else {
1606  tempbuf.Form(".X%s %s", keep ? "k" : " ", exname.Data());
1607  }
1608  retval = gInterpreter->ProcessLineSynch(tempbuf,(TInterpreter::EErrorCode*)error);
1609  }
1610 
1611  delete [] exnam;
1612  return retval;
1613 }
1614 
1615 ////////////////////////////////////////////////////////////////////////////////
1616 /// Main application eventloop. Calls system dependent eventloop via gSystem.
1617 
1618 void TApplication::Run(Bool_t retrn)
1619 {
1620  SetReturnFromRun(retrn);
1621 
1622  fIsRunning = kTRUE;
1623 
1624  gSystem->Run();
1625  fIsRunning = kFALSE;
1626 }
1627 
1628 ////////////////////////////////////////////////////////////////////////////////
1629 /// Set the command to be executed after the system has been idle for
1630 /// idleTimeInSec seconds. Normally called via TROOT::Idle(...).
1631 
1632 void TApplication::SetIdleTimer(UInt_t idleTimeInSec, const char *command)
1633 {
1634  if (fIdleTimer) RemoveIdleTimer();
1635  fIdleCommand = command;
1636  fIdleTimer = new TIdleTimer(idleTimeInSec*1000);
1638 }
1639 
1640 ////////////////////////////////////////////////////////////////////////////////
1641 /// Remove idle timer. Normally called via TROOT::Idle(0).
1642 
1644 {
1645  if (fIdleTimer) {
1646  // timers are removed from the gSystem timer list by their dtor
1648  }
1649 }
1650 
1651 ////////////////////////////////////////////////////////////////////////////////
1652 /// Called when system starts idleing.
1653 
1655 {
1656  if (fIdleTimer) {
1657  fIdleTimer->Reset();
1659  }
1660 }
1661 
1662 ////////////////////////////////////////////////////////////////////////////////
1663 /// Called when system stops idleing.
1664 
1666 {
1667  if (fIdleTimer)
1669 }
1670 
1671 ////////////////////////////////////////////////////////////////////////////////
1672 /// What to do when tab is pressed. Re-implemented by TRint.
1673 /// See TTabCom::Hook() for meaning of return values.
1674 
1675 Int_t TApplication::TabCompletionHook(char* /*buf*/, int* /*pLoc*/, std::ostream& /*out*/)
1676 {
1677  return -1;
1678 }
1679 
1680 
1681 ////////////////////////////////////////////////////////////////////////////////
1682 /// Terminate the application by call TSystem::Exit() unless application has
1683 /// been told to return from Run(), by a call to SetReturnFromRun().
1684 
1685 void TApplication::Terminate(Int_t status)
1686 {
1687  Emit("Terminate(Int_t)", status);
1688 
1689  if (fReturnFromRun)
1690  gSystem->ExitLoop();
1691  else {
1692  //close TMemStat
1693  if (fUseMemstat) {
1694  ProcessLine("TMemStat::Close()");
1695  fUseMemstat = kFALSE;
1696  }
1697 
1698  gSystem->Exit(status);
1699  }
1700 }
1701 
1702 ////////////////////////////////////////////////////////////////////////////////
1703 /// Emit signal when a line has been processed.
1704 
1705 void TApplication::LineProcessed(const char *line)
1706 {
1707  Emit("LineProcessed(const char*)", line);
1708 }
1709 
1710 ////////////////////////////////////////////////////////////////////////////////
1711 /// Emit signal when console keyboard key was pressed.
1712 
1714 {
1715  Emit("KeyPressed(Int_t)", key);
1716 }
1717 
1718 ////////////////////////////////////////////////////////////////////////////////
1719 /// Emit signal when return key was pressed.
1720 
1721 void TApplication::ReturnPressed(char *text )
1722 {
1723  Emit("ReturnPressed(char*)", text);
1724 }
1725 
1726 ////////////////////////////////////////////////////////////////////////////////
1727 /// Set console echo mode:
1728 ///
1729 /// - mode = kTRUE - echo input symbols
1730 /// - mode = kFALSE - noecho input symbols
1731 
1733 {
1734 }
1735 
1736 ////////////////////////////////////////////////////////////////////////////////
1737 /// Static function used to create a default application environment.
1738 
1740 {
1742  // gApplication is set at the end of 'new TApplication.
1743  if (!gApplication) {
1744  char *a = StrDup("RootApp");
1745  char *b = StrDup("-b");
1746  char *argv[2];
1747  Int_t argc = 2;
1748  argv[0] = a;
1749  argv[1] = b;
1750  new TApplication("RootApp", &argc, argv, nullptr, 0);
1751  if (gDebug > 0)
1752  Printf("<TApplication::CreateApplication>: "
1753  "created default TApplication");
1754  delete [] a; delete [] b;
1756  }
1757 }
1758 
1759 ////////////////////////////////////////////////////////////////////////////////
1760 /// Static function used to attach to an existing remote application
1761 /// or to start one.
1762 
1763 TApplication *TApplication::Open(const char *url,
1764  Int_t debug, const char *script)
1765 {
1766  TApplication *ap = nullptr;
1767  TUrl nu(url);
1768  Int_t nnew = 0;
1769 
1770  // Look among the existing ones
1771  if (fgApplications) {
1772  TIter nxa(fgApplications);
1773  while ((ap = (TApplication *) nxa())) {
1774  TString apn(ap->ApplicationName());
1775  if (apn == url) {
1776  // Found matching application
1777  return ap;
1778  } else {
1779  // Check if same machine and user
1780  TUrl au(apn);
1781  if (strlen(au.GetUser()) > 0 && strlen(nu.GetUser()) > 0 &&
1782  !strcmp(au.GetUser(), nu.GetUser())) {
1783  if (!strncmp(au.GetHost(), nu.GetHost(), strlen(nu.GetHost())))
1784  // New session on a known machine
1785  nnew++;
1786  }
1787  }
1788  }
1789  } else {
1790  ::Error("TApplication::Open", "list of applications undefined - protocol error");
1791  return ap;
1792  }
1793 
1794  // If new session on a known machine pass the number as option
1795  if (nnew > 0) {
1796  nnew++;
1797  nu.SetOptions(Form("%d", nnew));
1798  }
1799 
1800  // Instantiate the TApplication object to be run
1801  TPluginHandler *h = nullptr;
1802  if ((h = gROOT->GetPluginManager()->FindHandler("TApplication","remote"))) {
1803  if (h->LoadPlugin() == 0) {
1804  ap = (TApplication *) h->ExecPlugin(3, nu.GetUrl(), debug, script);
1805  } else {
1806  ::Error("TApplication::Open", "failed to load plugin for TApplicationRemote");
1807  }
1808  } else {
1809  ::Error("TApplication::Open", "failed to find plugin for TApplicationRemote");
1810  }
1811 
1812  // Add to the list
1813  if (ap && !(ap->TestBit(kInvalidObject))) {
1814  fgApplications->Add(ap);
1815  gROOT->GetListOfBrowsables()->Add(ap, ap->ApplicationName());
1816  TIter next(gROOT->GetListOfBrowsers());
1817  TBrowser *b;
1818  while ((b = (TBrowser*) next()))
1819  b->Add(ap, ap->ApplicationName());
1820  gROOT->RefreshBrowsers();
1821  } else {
1822  SafeDelete(ap);
1823  ::Error("TApplication::Open",
1824  "TApplicationRemote for %s could not be instantiated", url);
1825  }
1826 
1827  // Done
1828  return ap;
1829 }
1830 
1831 ////////////////////////////////////////////////////////////////////////////////
1832 /// Static function used to close a remote application
1833 
1835 {
1836  if (app) {
1837  app->Terminate(0);
1838  fgApplications->Remove(app);
1839  gROOT->GetListOfBrowsables()->RecursiveRemove(app);
1840  TIter next(gROOT->GetListOfBrowsers());
1841  TBrowser *b;
1842  while ((b = (TBrowser*) next()))
1843  b->RecursiveRemove(app);
1844  gROOT->RefreshBrowsers();
1845  }
1846 }
1847 
1848 ////////////////////////////////////////////////////////////////////////////////
1849 /// Show available sessions
1850 
1851 void TApplication::ls(Option_t *opt) const
1852 {
1853  if (fgApplications) {
1854  TIter nxa(fgApplications);
1855  TApplication *a = nullptr;
1856  while ((a = (TApplication *) nxa())) {
1857  a->Print(opt);
1858  }
1859  } else {
1860  Print(opt);
1861  }
1862 }
1863 
1864 ////////////////////////////////////////////////////////////////////////////////
1865 /// Static method returning the list of available applications
1866 
1868 {
1869  return fgApplications;
1870 }
TApplication::Close
static void Close(TApplication *app)
gClassTable
R__EXTERN TClassTable * gClassTable
Definition: TClassTable.h:95
TApplication::MakeBatch
virtual void MakeBatch()
Switch to batch mode.
Definition: TApplication.cxx:1160
n
const Int_t n
Definition: legend1.C:16
TSystem::GetPathInfo
int GetPathInfo(const char *path, Long_t *id, Long_t *size, Long_t *flags, Long_t *modtime)
Get info about a file: id, size, flags, modification time.
Definition: TSystem.cxx:1397
TApplication::fAppImp
TApplicationImp * fAppImp
Definition: TApplication.h:60
TROOT::ShutDown
static void ShutDown()
Shut down ROOT.
Definition: TROOT.cxx:3048
TApplication::ProcessFile
virtual Longptr_t ProcessFile(const char *file, Int_t *error=0, Bool_t keep=kFALSE)
TApplication::ApplicationName
virtual const char * ApplicationName() const
Definition: TApplication.h:124
TDataMember::GetFullTypeName
const char * GetFullTypeName() const
Get full type description of data member, e,g.: "class TDirectory*".
Definition: TDataMember.cxx:416
TBrowser
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:37
TApplication::fAppRemote
TApplication * fAppRemote
Definition: TApplication.h:81
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:100
TEnv::SetValue
virtual void SetValue(const char *name, const char *value, EEnvLevel level=kEnvChange, const char *type=nullptr)
Set the value of a resource or create a new resource.
Definition: TEnv.cxx:736
TObjArray::Delete
virtual void Delete(Option_t *option="")
Remove all objects from the array AND delete all heap based objects.
Definition: TObjArray.cxx:356
TObject::TestBit
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition: TObject.h:187
TApplication::kDefaultApplication
@ kDefaultApplication
Definition: TApplication.h:45
TInterpreter::kRecoverable
@ kRecoverable
Definition: TInterpreter.h:78
TClass::GetMethodAllAny
TMethod * GetMethodAllAny(const char *method)
Return pointer to method without looking at parameters.
Definition: TClass.cxx:4377
TObjArray
An array of TObjects.
Definition: TObjArray.h:37
TApplication::ReturnPressed
virtual void ReturnPressed(char *text)
TStyle::SetScreenFactor
void SetScreenFactor(Float_t factor=1)
Definition: TStyle.h:303
f
#define f(i)
Definition: RSha256.hxx:104
Option_t
const char Option_t
Definition: RtypesCore.h:66
TSystem::ExitLoop
virtual void ExitLoop()
Exit from event loop.
Definition: TSystem.cxx:394
TClass::GetListOfAllPublicDataMembers
TList * GetListOfAllPublicDataMembers(Bool_t load=kTRUE)
Returns a list of all public data members of this class and its base classes.
Definition: TClass.cxx:3855
TSystem::ChangeDirectory
virtual Bool_t ChangeDirectory(const char *path)
Change directory.
Definition: TSystem.cxx:862
TString::Atoi
Int_t Atoi() const
Return integer value of string.
Definition: TString.cxx:1943
TApplication::fgApplications
static TList * fgApplications
Definition: TApplication.h:83
TString::Strip
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
Definition: TString.cxx:1128
TObject::Print
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
Definition: TObject.cxx:552
TString::Prepend
TString & Prepend(const char *cs)
Definition: TString.h:661
TApplication::OpenInBrowser
void OpenInBrowser(const TString &url)
The function generates and executes a command that loads the Doxygen URL in a browser.
Definition: TApplication.cxx:642
TApplication::fWorkDir
TString fWorkDir
Definition: TApplication.h:68
gEnv
R__EXTERN TEnv * gEnv
Definition: TEnv.h:171
gVirtualX
#define gVirtualX
Definition: TVirtualX.h:338
TList::FindObject
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition: TList.cxx:578
TSystem::RemoveTimer
virtual TTimer * RemoveTimer(TTimer *t)
Remove timer from list of system timers.
Definition: TSystem.cxx:483
TString::Data
const char * Data() const
Definition: TString.h:369
kIsVirtual
@ kIsVirtual
Definition: TDictionary.h:72
ROOT::EnableThreadSafety
void EnableThreadSafety()
Enables the global mutex to make ROOT thread safe/aware.
Definition: TROOT.cxx:494
CallEndOfProcessCleanups
static void CallEndOfProcessCleanups()
Definition: TApplication.cxx:79
TROOT::GetMacroPath
static const char * GetMacroPath()
Get macro search path. Static utility function.
Definition: TROOT.cxx:2718
TSystem::Which
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
Definition: TSystem.cxx:1545
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
Form
char * Form(const char *fmt,...)
TClass::Property
Long_t Property() const
Returns the properties of the TClass as a bit field stored as a Long_t value.
Definition: TClass.cxx:6038
TObjString.h
TApplication::GetIdleCommand
const char * GetIdleCommand() const
Definition: TApplication.h:119
TApplication::ParseRemoteLine
static Int_t ParseRemoteLine(const char *ln, TString &hostdir, TString &user, Int_t &dbg, TString &script)
Parse the content of a line starting with ".R" (already stripped-off) The format is.
Definition: TApplication.cxx:1184
TString::Replace
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
Definition: TString.h:682
TApplication::fNoLog
Bool_t fNoLog
Definition: TApplication.h:63
TMethod.h
kIsNamespace
@ kIsNamespace
Definition: TDictionary.h:95
TObject::Info
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:867
Long64_t
long long Long64_t
Definition: RtypesCore.h:80
TObject::Error
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:893
TVirtualX
Semi-Abstract base class defining a generic interface to the underlying, low level,...
Definition: TVirtualX.h:46
TApplication::InitializeGraphics
void InitializeGraphics()
Initialize the graphics environment.
Definition: TApplication.cxx:260
TGuiFactory::CreateApplicationImp
virtual TApplicationImp * CreateApplicationImp(const char *classname, int *argc, char **argv)
Create a batch version of TApplicationImp.
Definition: TGuiFactory.cxx:48
gInterpreter
#define gInterpreter
Definition: TInterpreter.h:560
TApplication::kExpression
@ kExpression
Definition: TApplication.h:49
TDataMember.h
TApplication::ExitOnException
EExitOnException ExitOnException(EExitOnException opt=kExit)
Set the exit on exception option.
Definition: TApplication.cxx:627
TApplication::LoadGraphicsLibs
virtual void LoadGraphicsLibs()
Load shared libs necessary for graphics.
Definition: TApplication.cxx:1099
TApplication::~TApplication
virtual ~TApplication()
TApplication dtor.
Definition: TApplication.cxx:221
TStyle.h
TROOT::GetTutorialDir
static const TString & GetTutorialDir()
Get the tutorials directory in the installation. Static utility function.
Definition: TROOT.cxx:3027
TGeant4Unit::s
static constexpr double s
Definition: TGeant4SystemOfUnits.h:162
TObject::Fatal
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition: TObject.cxx:921
Int_t
int Int_t
Definition: RtypesCore.h:45
TDataMember
All ROOT classes may have RTTI (run time type identification) support added.
Definition: TDataMember.h:31
TSystem::SetProgname
virtual void SetProgname(const char *name)
Set the application name (from command line, argv[0]) and copy it in gProgName.
Definition: TSystem.cxx:224
TBrowser.h
kInvalidObject
@ kInvalidObject
Definition: TObject.h:361
TApplication::ProcessLine
virtual Longptr_t ProcessLine(const char *line, Bool_t sync=kFALSE, Int_t *error=0)
TApplication::GetOptions
virtual void GetOptions(Int_t *argc, char **argv)
Get and handle command line options.
Definition: TApplication.cxx:355
TString::Contains
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:624
SafeDelete
#define SafeDelete(p)
Definition: RConfig.hxx:536
TString::EndsWith
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition: TString.cxx:2199
TString::ReadFile
std::istream & ReadFile(std::istream &str)
Replace string with the contents of strm, stopping at an EOF.
Definition: Stringio.cxx:28
TObjArray::GetEntries
Int_t GetEntries() const
Return the number of objects in array (i.e.
Definition: TObjArray.cxx:523
x
Double_t x[n]
Definition: legend1.C:17
TString::Length
Ssiz_t Length() const
Definition: TString.h:410
TApplication::OpenReferenceGuideFor
void OpenReferenceGuideFor(const TString &strippedClass)
It opens the online reference guide, generated with Doxygen, for the chosen scope (class/namespace/st...
Definition: TApplication.cxx:961
TEnv::GetValue
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition: TEnv.cxx:491
TColor.h
TIdleTimer
Definition: TApplication.cxx:60
TInterpreter::EErrorCode
EErrorCode
Definition: TInterpreter.h:76
TApplication::fIsRunning
std::atomic< bool > fIsRunning
Window system specific application implementation.
Definition: TApplication.h:61
TVirtualX.h
TClass::GetListOfEnums
TList * GetListOfEnums(Bool_t load=kTRUE)
Return a list containing the TEnums of a class.
Definition: TClass.cxx:3679
TDataMember::IsEnum
Bool_t IsEnum() const
Return true if data member is an enum.
Definition: TDataMember.cxx:524
TApplication::fArgv
char ** fArgv
Definition: TApplication.h:59
TTimer.h
TObjArray::At
TObject * At(Int_t idx) const
Definition: TObjArray.h:166
TEnv.h
TSystem::Load
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Definition: TSystem.cxx:1854
TApplication::ClearInputFiles
void ClearInputFiles()
Clear list containing macro files passed as program arguments.
Definition: TApplication.cxx:328
TApplication::HandleIdleTimer
virtual void HandleIdleTimer()
Handle idle timeout.
Definition: TApplication.cxx:590
TString
Basic string class.
Definition: TString.h:136
TSystem::AccessPathName
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Definition: TSystem.cxx:1295
TApplication::fIdleCommand
TString fIdleCommand
Definition: TApplication.h:69
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
text
TText * text
Definition: entrylist_figure1.C:10
b
#define b(i)
Definition: RSha256.hxx:100
TString.h
TSystem::AddTimer
virtual void AddTimer(TTimer *t)
Add timer to list of system timers.
Definition: TSystem.cxx:473
bool
TSystem::WorkingDirectory
virtual const char * WorkingDirectory()
Return working directory.
Definition: TSystem.cxx:871
gGXBatch
R__EXTERN TVirtualX * gGXBatch
Definition: TVirtualX.h:341
TString::ReplaceAll
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:692
TObjArray::Add
void Add(TObject *obj)
Definition: TObjArray.h:74
TApplication::fgGraphNeeded
static Bool_t fgGraphNeeded
Definition: TApplication.h:74
id
XFontStruct * id
Definition: TGX11.cxx:109
TSystem::SplitAclicMode
virtual TString SplitAclicMode(const char *filename, TString &mode, TString &args, TString &io) const
This method split a filename of the form:
Definition: TSystem.cxx:4240
TObjString::String
TString & String()
Definition: TObjString.h:48
TString::kBoth
@ kBoth
Definition: TString.h:267
ROOT::EnableImplicitMT
void EnableImplicitMT(UInt_t numthreads=0)
Enable ROOT's implicit multi-threading for all objects and methods that provide an internal paralleli...
Definition: TROOT.cxx:525
TROOT.h
TObjString
Collectable string class.
Definition: TObjString.h:28
TApplication::LineProcessed
virtual void LineProcessed(const char *line)
TApplication.h
TObject::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:359
TPluginHandler
Definition: TPluginManager.h:101
TApplication::SetReturnFromRun
void SetReturnFromRun(Bool_t ret)
Definition: TApplication.h:150
TString::Form
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition: TString.cxx:2311
TSystem::GetBuildArch
virtual const char * GetBuildArch() const
Return the build architecture.
Definition: TSystem.cxx:3861
TTimer
Handles synchronous and a-synchronous timer events.
Definition: TTimer.h:51
TApplication::fQuit
Bool_t fQuit
Definition: TApplication.h:65
TPRegexp.h
Throw
R__EXTERN void Throw(int code)
If an exception context has been set (using the TRY and RETRY macros) jump back to where it was set.
Definition: TException.cxx:27
gBatchGuiFactory
R__EXTERN TGuiFactory * gBatchGuiFactory
Definition: TGuiFactory.h:67
TClassTable.h
TFunction::Property
Long_t Property() const
Get property description word. For meaning of bits see EProperty.
Definition: TFunction.cxx:184
TApplication::kProcessRemotely
@ kProcessRemotely
Definition: TApplication.h:44
TList::FirstLink
virtual TObjLink * FirstLink() const
Definition: TList.h:108
TGuiFactory
This ABC is a factory for GUI components.
Definition: TGuiFactory.h:42
gStyle
R__EXTERN TStyle * gStyle
Definition: TStyle.h:412
TObject::ResetBit
void ResetBit(UInt_t f)
Definition: TObject.h:186
TSystem.h
gInterpreterMutex
R__EXTERN TVirtualMutex * gInterpreterMutex
Definition: TInterpreter.h:44
gROOTMutex
R__EXTERN TVirtualMutex * gROOTMutex
Definition: TROOT.h:61
h
#define h(i)
Definition: RSha256.hxx:106
size
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
TObject::SetBit
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:696
TApplication::TApplication
TApplication()
Default ctor. Can be used by classes deriving from TApplication.
Definition: TApplication.cxx:97
TROOT::Initialized
static Bool_t Initialized()
Return kTRUE if the TROOT object has been initialized.
Definition: TROOT.cxx:2821
a
auto * a
Definition: textangle.C:12
TString::Remove
TString & Remove(Ssiz_t pos)
Definition: TString.h:673
TNamed
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:101
TString::Append
TString & Append(const char *cs)
Definition: TString.h:564
TROOT::GetDocDir
static const TString & GetDocDir()
Get the documentation directory in the installation. Static utility function.
Definition: TROOT.cxx:2990
TSystem::Exec
virtual Int_t Exec(const char *shellcmd)
Execute a command.
Definition: TSystem.cxx:655
TMethod
Each ROOT class (see TClass) has a linked list of methods.
Definition: TMethod.h:38
Long_t
long Long_t
Definition: RtypesCore.h:54
TString::First
Ssiz_t First(char c) const
Find first occurrence of a character c.
Definition: TString.cxx:520
TApplication::KeyPressed
virtual void KeyPressed(Int_t key)
TApplication::kExit
@ kExit
Definition: TApplication.h:53
TSystem::NotifyApplicationCreated
virtual void NotifyApplicationCreated()
Hook to tell TSystem that the TApplication object has been created.
Definition: TSystem.cxx:313
gDirectory
#define gDirectory
Definition: TDirectory.h:327
gGuiFactory
R__EXTERN TGuiFactory * gGuiFactory
Definition: TGuiFactory.h:66
TApplication::StartIdleing
virtual void StartIdleing()
StrDup
char * StrDup(const char *str)
Duplicate the string str.
Definition: TString.cxx:2512
TIdleTimer::TIdleTimer
TIdleTimer(Long_t ms)
Definition: TApplication.cxx:62
TApplication::fReturnFromRun
Bool_t fReturnFromRun
Definition: TApplication.h:62
gDebug
Int_t gDebug
Definition: TROOT.cxx:590
R__LOCKGUARD
#define R__LOCKGUARD(mutex)
Definition: TVirtualMutex.h:104
TString::Insert
TString & Insert(Ssiz_t pos, const char *s)
Definition: TString.h:649
TVirtualPad.h
UInt_t
unsigned int UInt_t
Definition: RtypesCore.h:46
TString::BeginsWith
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition: TString.h:615
TFunction::GetReturnTypeName
const char * GetReturnTypeName() const
Get full type description of function return type, e,g.: "class TDirectory*".
Definition: TFunction.cxx:141
TClassEdit::GetUnqualifiedName
const char * GetUnqualifiedName(const char *name)
Return the start of the unqualified name include in 'original'.
Definition: TClassEdit.cxx:925
TApplication::ls
virtual void ls(Option_t *option="") const
The ls function lists the contents of a class on stdout.
TClass::GetClass
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition: TClass.cxx:2955
y
Double_t y[n]
Definition: legend1.C:17
TApplication::Terminate
virtual void Terminate(Int_t status=0)
TSystem::ExpandPathName
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition: TSystem.cxx:1273
TApplication::RemoveIdleTimer
virtual void RemoveIdleTimer()
TString::MD5
TString MD5() const
Return the MD5 digest for this string, in a string representation.
Definition: TString.cxx:922
line
TLine * line
Definition: entrylistblock_figure1.C:235
TApplication::Run
virtual void Run(Bool_t retrn=kFALSE)
TApplication::fgGraphInit
static Bool_t fgGraphInit
Definition: TApplication.h:75
TVirtualMutex.h
TObject::Warning
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:879
TUrl::GetUrl
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
Definition: TUrl.cxx:389
TUrl
This class represents a WWW compatible URL.
Definition: TUrl.h:33
gApplication
TApplication * gApplication
Definition: TApplication.cxx:53
TApplication::HandleException
virtual void HandleException(Int_t sig)
Handle exceptions (kSigBus, kSigSegmentationViolation, kSigIllegalInstruction and kSigFloatingExcepti...
Definition: TApplication.cxx:603
TApplication::Open
virtual void Open()
Definition: TApplication.h:128
TFunction::ExtraProperty
Long_t ExtraProperty() const
Get property description word. For meaning of bits see EProperty.
Definition: TFunction.cxx:192
TObject::kInvalidObject
@ kInvalidObject
if object ctor succeeded but object should not be used
Definition: TObject.h:68
TClassTable::GetDict
static DictFuncPtr_t GetDict(const char *cname)
Given the class name returns the Dictionary() function of a class (uses hash of name).
Definition: TClassTable.cxx:574
unsigned int
TApplication::fFiles
TObjArray * fFiles
Definition: TApplication.h:67
TApplication::kAbort
@ kAbort
Definition: TApplication.h:54
TPRegexp
Definition: TPRegexp.h:36
TUrl::GetFile
const char * GetFile() const
Definition: TUrl.h:69
TString::Index
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:639
Printf
void Printf(const char *fmt,...)
TUrl::GetProtocol
const char * GetProtocol() const
Definition: TUrl.h:64
gSystem
R__EXTERN TSystem * gSystem
Definition: TSystem.h:559
Ssiz_t
int Ssiz_t
Definition: RtypesCore.h:67
TApplication::fExitOnException
EExitOnException fExitOnException
Definition: TApplication.h:72
TSystem::Getenv
virtual const char * Getenv(const char *env)
Get environment variable.
Definition: TSystem.cxx:1662
Longptr_t
long Longptr_t
Definition: RtypesCore.h:82
TApplication::fArgc
Int_t fArgc
Definition: TApplication.h:58
kIsStruct
@ kIsStruct
Definition: TDictionary.h:66
TString::IsNull
Bool_t IsNull() const
Definition: TString.h:407
TApplication::NeedGraphicsLibs
static void NeedGraphicsLibs()
Static method.
Definition: TApplication.cxx:252
TPluginManager.h
TSystem::Exit
virtual void Exit(int code, Bool_t mode=kTRUE)
Exit the application.
Definition: TSystem.cxx:718
TObjArray.h
TSystem::Abort
virtual void Abort(int code=0)
Abort the application.
Definition: TSystem.cxx:726
TClassEdit.h
TApplication::fNoLogo
Bool_t fNoLogo
Definition: TApplication.h:64
TApplication::fUseMemstat
Bool_t fUseMemstat
Definition: TApplication.h:66
TList::Remove
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:822
TApplication::ExecuteFile
static Longptr_t ExecuteFile(const char *file, Int_t *error=0, Bool_t keep=kFALSE)
TInterpreter.h
TClass
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:80
file
Definition: file.py:1
TList::Add
virtual void Add(TObject *obj)
Definition: TList.h:87
TApplication::StopIdleing
virtual void StopIdleing()
name
char name[80]
Definition: TGX11.cxx:110
TApplication::Help
virtual void Help(const char *line)
The function lists useful commands (".help") or opens the online reference guide, generated with Doxy...
Definition: TApplication.cxx:1061
TApplication::Init
virtual void Init()
Definition: TApplication.h:113
TDataMember::GetTrueTypeName
const char * GetTrueTypeName() const
Get full type description of data member, e,g.: "class TDirectory*".
Definition: TDataMember.cxx:426
TUrl::GetFileAndOptions
const char * GetFileAndOptions() const
Return the file and its options (the string specified behind the ?).
Definition: TUrl.cxx:503
TApplication::CreateApplication
static void CreateApplication()
TApplication::SetIdleTimer
virtual void SetIdleTimer(UInt_t idleTimeInSec, const char *command)
Compress
char * Compress(const char *str)
Remove all blanks from the string str.
Definition: TString.cxx:2527
gPad
#define gPad
Definition: TVirtualPad.h:287
TException.h
TIter
Definition: TCollection.h:233
kIsInlined
@ kIsInlined
Definition: TDictionary.h:131
TFunction::GetSignature
const char * GetSignature()
Return signature of function.
Definition: TFunction.cxx:116
gException
R__EXTERN ExceptionContext_t * gException
Definition: TException.h:74
TROOT::GetTTFFontDir
static const TString & GetTTFFontDir()
Get the fonts directory in the installation. Static utility function.
Definition: TROOT.cxx:3101
TApplication::SetEchoMode
virtual void SetEchoMode(Bool_t mode)
TGeant4Unit::ms
static constexpr double ms
Definition: TGeant4SystemOfUnits.h:163
TApplication
This class creates the ROOT Application Environment that interfaces to the windowing system eventloop...
Definition: TApplication.h:39
ROOT::TMetaUtils::propNames::comment
static const std::string comment("comment")
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
kIsConstexpr
@ kIsConstexpr
Definition: TDictionary.h:93
TString::ToLower
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1147
kReadPermission
@ kReadPermission
Definition: TSystem.h:47
TSystem::Run
virtual void Run()
System event loop.
Definition: TSystem.cxx:345
TTimer::Reset
void Reset()
Reset the timer.
Definition: TTimer.cxx:157
TColor::InitializeColors
static void InitializeColors()
Initialize colors used by the TCanvas based graphics (via TColor objects).
Definition: TColor.cxx:1095
TApplication::fIdleTimer
TTimer * fIdleTimer
Definition: TApplication.h:70
TIdleTimer::Notify
Bool_t Notify()
Notify handler.
Definition: TApplication.cxx:69
TGuiFactory.h
TUrl.h
TApplication::TabCompletionHook
virtual Int_t TabCompletionHook(char *buf, int *pLoc, std::ostream &out)
TApplication::Argv
char ** Argv() const
Definition: TApplication.h:137
TApplication::EExitOnException
EExitOnException
Definition: TApplication.h:51
Strip
char * Strip(const char *str, char c=' ')
Strip leading and trailing c (blanks by default) from a string.
Definition: TString.cxx:2476
TFunction
Global functions class (global functions are obtained from CINT).
Definition: TFunction.h:30
TList
A doubly linked list.
Definition: TList.h:44
TQObject::Emit
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition: TQObject.h:164
TApplication::GetApplications
static TList * GetApplications()
gROOT
#define gROOT
Definition: TROOT.h:406
int
TApplication::ProcessRemote
virtual Longptr_t ProcessRemote(const char *line, Int_t *error=0)
Process the content of a line starting with ".R" (already stripped-off) The format is.
Definition: TApplication.cxx:1250
Error
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition: TError.cxx:187
TError.h