Logo ROOT   6.12/07
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 "Riostream.h"
24 #include "TApplication.h"
25 #include "TException.h"
26 #include "TGuiFactory.h"
27 #include "TVirtualX.h"
28 #include "TROOT.h"
29 #include "TSystem.h"
30 #include "TString.h"
31 #include "TError.h"
32 #include "TObjArray.h"
33 #include "TObjString.h"
34 #include "TTimer.h"
35 #include "TInterpreter.h"
36 #include "TStyle.h"
37 #include "TVirtualPad.h"
38 #include "TEnv.h"
39 #include "TColor.h"
40 #include "TClassTable.h"
41 #include "TPluginManager.h"
42 #include "TClassTable.h"
43 #include "TBrowser.h"
44 #include "TUrl.h"
45 #include "TVirtualMutex.h"
46 
47 #include "CommandLineOptionsHelp.h"
48 
49 #include <stdlib.h>
50 
51 #if defined(R__MACOSX) && (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
52 #include "TGIOS.h"
53 #endif
54 
55 
59 TList *TApplication::fgApplications = 0; // List of available applications
60 
61 ////////////////////////////////////////////////////////////////////////////////
62 
63 class TIdleTimer : public TTimer {
64 public:
65  TIdleTimer(Long_t ms) : TTimer(ms, kTRUE) { }
66  Bool_t Notify();
67 };
68 
69 ////////////////////////////////////////////////////////////////////////////////
70 /// Notify handler.
71 
72 Bool_t TIdleTimer::Notify()
73 {
74  gApplication->HandleIdleTimer();
75  Reset();
76  return kFALSE;
77 }
78 
79 
81 
83 {
84  // Insure that the files, canvases and sockets are closed.
85 
86  // If we get here, the tear down has started. We have no way to know what
87  // has or has not yet been done. In particular on Ubuntu, this was called
88  // after the function static in TSystem.cxx has been destructed. So we
89  // set gROOT in its end-of-life mode which prevents executing code, like
90  // autoloading libraries (!) that is pointless ...
91  if (gROOT) {
92  gROOT->SetBit(kInvalidObject);
93  gROOT->EndOfProcessCleanups();
94  }
95 }
96 
97 ////////////////////////////////////////////////////////////////////////////////
98 /// Default ctor. Can be used by classes deriving from TApplication.
99 
101  fArgc(0), fArgv(0), fAppImp(0), fIsRunning(kFALSE), fReturnFromRun(kFALSE),
102  fNoLog(kFALSE), fNoLogo(kFALSE), fQuit(kFALSE), fUseMemstat(kFALSE),
103  fFiles(0), fIdleTimer(0), fSigHandler(0), fExitOnException(kDontExit),
104  fAppRemote(0)
105 {
107 }
108 
109 ////////////////////////////////////////////////////////////////////////////////
110 /// Create an application environment. The application environment
111 /// provides an interface to the graphics system and eventloop
112 /// (be it X, Windows, MacOS or BeOS). After creating the application
113 /// object start the eventloop by calling its Run() method. The command
114 /// line options recognized by TApplication are described in the GetOptions()
115 /// method. The recognized options are removed from the argument array.
116 /// The original list of argument options can be retrieved via the Argc()
117 /// and Argv() methods. The appClassName "proofserv" is reserved for the
118 /// PROOF system. The "options" and "numOptions" arguments are not used,
119 /// except if you want to by-pass the argv processing by GetOptions()
120 /// in which case you should specify numOptions<0. All options will
121 /// still be available via the Argv() method for later use.
122 
123 TApplication::TApplication(const char *appClassName, Int_t *argc, char **argv,
124  void * /*options*/, Int_t numOptions) :
128  fAppRemote(0)
129 {
131 
132  // Create the list of applications the first time
133  if (!fgApplications)
134  fgApplications = new TList;
135 
136  // Add the new TApplication early, so that the destructor of the
137  // default TApplication (if it is called in the block of code below)
138  // will not destroy the files, socket or TColor that have already been
139  // created.
140  fgApplications->Add(this);
141 
142  if (gApplication && gApplication->TestBit(kDefaultApplication)) {
143  // allow default TApplication to be replaced by a "real" TApplication
144  delete gApplication;
145  gApplication = 0;
146  gROOT->SetBatch(kFALSE);
148  }
149 
150  if (gApplication) {
151  Error("TApplication", "only one instance of TApplication allowed");
152  fgApplications->Remove(this);
153  return;
154  }
155 
156  if (!gROOT)
157  ::Fatal("TApplication::TApplication", "ROOT system not initialized");
158 
159  if (!gSystem)
160  ::Fatal("TApplication::TApplication", "gSystem not initialized");
161 
162  static Bool_t hasRegisterAtExit(kFALSE);
163  if (!hasRegisterAtExit) {
164  // If we are the first TApplication register the atexit)
165  atexit(CallEndOfProcessCleanups);
166  hasRegisterAtExit = kTRUE;
167  }
168  gROOT->SetName(appClassName);
169 
170  // copy command line arguments, can be later accessed via Argc() and Argv()
171  if (argc && *argc > 0) {
172  fArgc = *argc;
173  fArgv = (char **)new char*[fArgc];
174  }
175 
176  for (int i = 0; i < fArgc; i++)
177  fArgv[i] = StrDup(argv[i]);
178 
179  if (numOptions >= 0)
180  GetOptions(argc, argv);
181 
182  if (fArgv)
184 
185  // Tell TSystem the TApplication has been created
187 
188  fAppImp = gGuiFactory->CreateApplicationImp(appClassName, argc, argv);
190 
191  // Initialize the graphics environment
192  if (gClassTable->GetDict("TPad")) {
195  }
196 
197  // Save current interpreter context
198  gInterpreter->SaveContext();
199  gInterpreter->SaveGlobalsContext();
200 
201  // to allow user to interact with TCanvas's under WIN32
202  gROOT->SetLineHasBeenProcessed();
203 
204  // activate TMemStat
205  if (fUseMemstat || gEnv->GetValue("Root.TMemStat", 0)) {
206  fUseMemstat = kTRUE;
207  Int_t buffersize = gEnv->GetValue("Root.TMemStat.buffersize", 100000);
208  Int_t maxcalls = gEnv->GetValue("Root.TMemStat.maxcalls", 5000000);
209  const char *ssystem = gEnv->GetValue("Root.TMemStat.system","gnubuiltin");
210  if (maxcalls > 0) {
211  gROOT->ProcessLine(Form("new TMemStat(\"%s\",%d,%d);",ssystem,buffersize,maxcalls));
212  }
213  }
214 
215  //Needs to be done last
216  gApplication = this;
217  gROOT->SetApplication(this);
218 
219 }
220 
221 ////////////////////////////////////////////////////////////////////////////////
222 /// TApplication dtor.
223 
225 {
226  for (int i = 0; i < fArgc; i++)
227  if (fArgv[i]) delete [] fArgv[i];
228  delete [] fArgv;
229 
230  if (fgApplications)
231  fgApplications->Remove(this);
232 
233  //close TMemStat
234  if (fUseMemstat) {
235  ProcessLine("TMemStat::Close()");
237  }
238 
239  // Reduce the risk of the files or sockets being closed after the
240  // end of 'main' (or more exactly before the library start being
241  // unloaded).
242  if (fgApplications == 0 || fgApplications->FirstLink() == 0 ) {
243  if (gROOT) {
244  gROOT->EndOfProcessCleanups();
245  } else if (gInterpreter) {
246  gInterpreter->ResetGlobals();
247  }
248  }
249 
250  // Now that all the canvases and files have been closed we can
251  // delete the implementation.
253 }
254 
255 ////////////////////////////////////////////////////////////////////////////////
256 /// Static method. This method should be called from static library
257 /// initializers if the library needs the low level graphics system.
258 
260 {
262 }
263 
264 ////////////////////////////////////////////////////////////////////////////////
265 /// Initialize the graphics environment.
266 
268 {
269  if (fgGraphInit || !fgGraphNeeded) return;
270 
271  // Load the graphics related libraries
272 
273 #if defined(R__MACOSX) && (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
274  gVirtualX = new ROOT::iOS::TGIOS("TGIOS", "VirtualX for iOS");
275 #else
276 
278 
279  // Try to load TrueType font renderer. Only try to load if not in batch
280  // mode and Root.UseTTFonts is true and Root.TTFontPath exists. Abort silently
281  // if libttf or libGX11TTF are not found in $ROOTSYS/lib or $ROOTSYS/ttf/lib.
282  const char *ttpath = gEnv->GetValue("Root.TTFontPath",
284  char *ttfont = gSystem->Which(ttpath, "arialbd.ttf", kReadPermission);
285  // Check for use of DFSG - fonts
286  if (!ttfont)
287  ttfont = gSystem->Which(ttpath, "FreeSansBold.ttf", kReadPermission);
288 
289 #if !defined(R__WIN32)
290  if (!gROOT->IsBatch() && !strcmp(gVirtualX->GetName(), "X11") &&
291  ttfont && gEnv->GetValue("Root.UseTTFonts", 1)) {
292  if (gClassTable->GetDict("TGX11TTF")) {
293  // in principle we should not have linked anything against libGX11TTF
294  // but with ACLiC this can happen, initialize TGX11TTF by hand
295  // (normally this is done by the static library initializer)
296  ProcessLine("TGX11TTF::Activate();");
297  } else {
298  TPluginHandler *h;
299  if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualX", "x11ttf")))
300  if (h->LoadPlugin() == -1)
301  Info("InitializeGraphics", "no TTF support");
302  }
303  }
304 #endif
305  delete [] ttfont;
306 
307  // Create WM dependent application environment
308  if (fAppImp)
309  delete fAppImp;
311  if (!fAppImp) {
312  MakeBatch();
314  }
315 
316  // Create the canvas colors early so they are allocated before
317  // any color table expensive bitmaps get allocated in GUI routines (like
318  // creation of XPM bitmaps).
320 
321  // Hook for further initializing the WM dependent application environment
322  Init();
323 
324  // Set default screen factor (if not disabled in rc file)
325  if (gEnv->GetValue("Canvas.UseScreenFactor", 1)) {
326  Int_t x, y;
327  UInt_t w, h;
328  if (gVirtualX) {
329  gVirtualX->GetGeometry(-1, x, y, w, h);
330  if (h > 0 && h < 1000) gStyle->SetScreenFactor(0.0011*h);
331  }
332  }
333 #endif // iOS
334 }
335 
336 ////////////////////////////////////////////////////////////////////////////////
337 /// Clear list containing macro files passed as program arguments.
338 /// This method is called from TRint::Run() to ensure that the macro
339 /// files are only executed the first time Run() is called.
340 
342 {
343  if (fFiles) {
344  fFiles->Delete();
346  }
347 }
348 
349 ////////////////////////////////////////////////////////////////////////////////
350 /// Return specified argument.
351 
352 char *TApplication::Argv(Int_t index) const
353 {
354  if (fArgv) {
355  if (index >= fArgc) {
356  Error("Argv", "index (%d) >= number of arguments (%d)", index, fArgc);
357  return 0;
358  }
359  return fArgv[index];
360  }
361  return 0;
362 }
363 
364 ////////////////////////////////////////////////////////////////////////////////
365 /// Get and handle command line options. Arguments handled are removed
366 /// from the argument array. See CommandLineOptionsHelp.h for options.
367 
368 void TApplication::GetOptions(Int_t *argc, char **argv)
369 {
370  static char null[1] = { "" };
371 
372  fNoLog = kFALSE;
373  fQuit = kFALSE;
374  fFiles = 0;
375 
376  if (!argc)
377  return;
378 
379  int i, j;
380  TString pwd;
381 
382  for (i = 1; i < *argc; i++) {
383  if (!strcmp(argv[i], "-?") || !strncmp(argv[i], "-h", 2) ||
384  !strncmp(argv[i], "--help", 6)) {
385  fprintf(stderr, kCommandLineOptionsHelp, argv[0]);
386  Terminate(0);
387  } else if (!strcmp(argv[i], "-config")) {
388  fprintf(stderr, "ROOT ./configure options:\n%s\n", gROOT->GetConfigOptions());
389  Terminate(0);
390  } else if (!strcmp(argv[i], "-memstat")) {
391  fUseMemstat = kTRUE;
392  argv[i] = null;
393  } else if (!strcmp(argv[i], "-b")) {
394  MakeBatch();
395  argv[i] = null;
396  } else if (!strcmp(argv[i], "-n")) {
397  fNoLog = kTRUE;
398  argv[i] = null;
399  } else if (!strcmp(argv[i], "-t")) {
401  // EnableImplicitMT() only enables thread safety if IMT was configured;
402  // enable thread safety even with IMT off:
404  argv[i] = null;
405  } else if (!strcmp(argv[i], "-q")) {
406  fQuit = kTRUE;
407  argv[i] = null;
408  } else if (!strcmp(argv[i], "-l")) {
409  // used by front-end program to not display splash screen
410  fNoLogo = kTRUE;
411  argv[i] = null;
412  } else if (!strcmp(argv[i], "-x")) {
414  argv[i] = null;
415  } else if (!strcmp(argv[i], "-splash")) {
416  // used when started by front-end program to signal that
417  // splash screen can be popped down (TRint::PrintLogo())
418  argv[i] = null;
419  } else if (!strcmp(argv[i], "-e")) {
420  argv[i] = null;
421  ++i;
422 
423  if ( i < *argc ) {
424  if (!fFiles) fFiles = new TObjArray;
425  TObjString *expr = new TObjString(argv[i]);
426  expr->SetBit(kExpression);
427  fFiles->Add(expr);
428  argv[i] = null;
429  } else {
430  Warning("GetOptions", "-e must be followed by an expression.");
431  }
432  } else if (!strcmp(argv[i], "--")) {
433  TObjString* macro = nullptr;
434  bool warnShown = false;
435 
436  if (fFiles) {
437  for (auto f: *fFiles) {
438  TObjString* file = dynamic_cast<TObjString*>(f);
439  if (!file) {
440  Error("GetOptions()", "Inconsistent file entry (not a TObjString)!");
441  f->Dump();
442  continue;
443  }
444 
445  if (file->TestBit(kExpression))
446  continue;
447  if (file->String().EndsWith(".root"))
448  continue;
449  if (file->String().Contains('('))
450  continue;
451 
452  if (macro && !warnShown && (warnShown = true))
453  Warning("GetOptions", "-- is used with several macros. "
454  "The arguments will be passed to the last one.");
455 
456  macro = file;
457  }
458  }
459 
460  if (macro) {
461  argv[i] = null;
462  ++i;
463  TString& str = macro->String();
464 
465  str += '(';
466  for (; i < *argc; i++) {
467  str += argv[i];
468  str += ',';
469  argv[i] = null;
470  }
471  str.EndsWith(",") ? str[str.Length() - 1] = ')' : str += ')';
472  } else {
473  Warning("GetOptions", "no macro to pass arguments to was provided. "
474  "Everything after the -- will be ignored.");
475  for (; i < *argc; i++)
476  argv[i] = null;
477  }
478  } else if (argv[i][0] != '-' && argv[i][0] != '+') {
479  Long64_t size;
480  Long_t id, flags, modtime;
481  char *arg = strchr(argv[i], '(');
482  if (arg) *arg = '\0';
483  char *dir = gSystem->ExpandPathName(argv[i]);
484  TUrl udir(dir, kTRUE);
485  // remove options and anchor to check the path
486  TString sfx = udir.GetFileAndOptions();
487  TString fln = udir.GetFile();
488  sfx.Replace(sfx.Index(fln), fln.Length(), "");
489  TString path = udir.GetFile();
490  if (strcmp(udir.GetProtocol(), "file")) {
491  path = udir.GetUrl();
492  path.Replace(path.Index(sfx), sfx.Length(), "");
493  }
494  // 'path' is the full URL without suffices (options and/or anchor)
495  if (arg) *arg = '(';
496  if (!arg && !gSystem->GetPathInfo(path.Data(), &id, &size, &flags, &modtime)) {
497  if ((flags & 2)) {
498  // if directory set it in fWorkDir
499  if (pwd == "") {
500  pwd = gSystem->WorkingDirectory();
501  fWorkDir = dir;
502  gSystem->ChangeDirectory(dir);
503  argv[i] = null;
504  } else if (!strcmp(gROOT->GetName(), "Rint")) {
505  Warning("GetOptions", "only one directory argument can be specified (%s)", dir);
506  }
507  } else if (size > 0) {
508  // if file add to list of files to be processed
509  if (!fFiles) fFiles = new TObjArray;
510  fFiles->Add(new TObjString(path.Data()));
511  argv[i] = null;
512  } else {
513  Warning("GetOptions", "file %s has size 0, skipping", dir);
514  }
515  } else {
516  if (TString(udir.GetFile()).EndsWith(".root")) {
517  if (!strcmp(udir.GetProtocol(), "file")) {
518  // file ending on .root but does not exist, likely a typo
519  // warn user if plain root...
520  if (!strcmp(gROOT->GetName(), "Rint"))
521  Warning("GetOptions", "file %s not found", dir);
522  } else {
523  // remote file, give it the benefit of the doubt and add it to list of files
524  if (!fFiles) fFiles = new TObjArray;
525  fFiles->Add(new TObjString(argv[i]));
526  argv[i] = null;
527  }
528  } else {
529  TString mode,fargs,io;
530  TString fname = gSystem->SplitAclicMode(dir,mode,fargs,io);
531  char *mac;
532  if ((mac = gSystem->Which(TROOT::GetMacroPath(), fname,
533  kReadPermission))) {
534  // if file add to list of files to be processed
535  if (!fFiles) fFiles = new TObjArray;
536  fFiles->Add(new TObjString(argv[i]));
537  argv[i] = null;
538  delete [] mac;
539  } else {
540  // only warn if we're plain root,
541  // other progs might have their own params
542  if (!strcmp(gROOT->GetName(), "Rint"))
543  Warning("GetOptions", "macro %s not found", fname.Data());
544  }
545  }
546  }
547  delete [] dir;
548  }
549  // ignore unknown options
550  }
551 
552  // go back to startup directory
553  if (pwd != "")
554  gSystem->ChangeDirectory(pwd);
555 
556  // remove handled arguments from argument array
557  j = 0;
558  for (i = 0; i < *argc; i++) {
559  if (strcmp(argv[i], "")) {
560  argv[j] = argv[i];
561  j++;
562  }
563  }
564 
565  *argc = j;
566 }
567 
568 ////////////////////////////////////////////////////////////////////////////////
569 /// Handle idle timeout. When this timer expires the registered idle command
570 /// will be executed by this routine and a signal will be emitted.
571 
573 {
574  if (!fIdleCommand.IsNull())
576 
577  Emit("HandleIdleTimer()");
578 }
579 
580 ////////////////////////////////////////////////////////////////////////////////
581 /// Handle exceptions (kSigBus, kSigSegmentationViolation,
582 /// kSigIllegalInstruction and kSigFloatingException) trapped in TSystem.
583 /// Specific TApplication implementations may want something different here.
584 
586 {
587  if (TROOT::Initialized()) {
588  if (gException) {
589  gInterpreter->RewindDictionary();
590  gInterpreter->ClearFileBusy();
591  }
592  if (fExitOnException == kExit)
593  gSystem->Exit(sig);
594  else if (fExitOnException == kAbort)
595  gSystem->Abort();
596  else
597  Throw(sig);
598  }
599  gSystem->Exit(sig);
600 }
601 
602 ////////////////////////////////////////////////////////////////////////////////
603 /// Set the exit on exception option. Setting this option determines what
604 /// happens in HandleException() in case an exception (kSigBus,
605 /// kSigSegmentationViolation, kSigIllegalInstruction or kSigFloatingException)
606 /// is trapped. Choices are: kDontExit (default), kExit or kAbort.
607 /// Returns the previous value.
608 
610 {
612  fExitOnException = opt;
613  return old;
614 }
615 
616 ////////////////////////////////////////////////////////////////////////////////
617 /// Print help on interpreter.
618 
619 void TApplication::Help(const char *line)
620 {
621  gInterpreter->ProcessLine(line);
622 
623  Printf("\nROOT special commands.");
624  Printf("===========================================================================");
625  Printf(" pwd : show current directory, pad and style");
626  Printf(" ls : list contents of current directory");
627  Printf(" which [file] : shows path of macro file");
628 }
629 
630 ////////////////////////////////////////////////////////////////////////////////
631 /// Load shared libs necessary for graphics. These libraries are only
632 /// loaded when gROOT->IsBatch() is kFALSE.
633 
635 {
636  if (gROOT->IsBatch()) return;
637 
638  TPluginHandler *h;
639  if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualPad")))
640  if (h->LoadPlugin() == -1)
641  return;
642 
643  TString name;
644  TString title1 = "ROOT interface to ";
645  TString nativex, title;
646  TString nativeg = "root";
647 
648 #ifdef R__WIN32
649  nativex = "win32gdk";
650  name = "Win32gdk";
651  title = title1 + "Win32gdk";
652 #elif defined(R__HAS_COCOA)
653  nativex = "quartz";
654  name = "quartz";
655  title = title1 + "Quartz";
656 #else
657  nativex = "x11";
658  name = "X11";
659  title = title1 + "X11";
660 #endif
661 
662  TString guiBackend(gEnv->GetValue("Gui.Backend", "native"));
663  guiBackend.ToLower();
664  if (guiBackend == "native") {
665  guiBackend = nativex;
666  } else {
667  name = guiBackend;
668  title = title1 + guiBackend;
669  }
670  TString guiFactory(gEnv->GetValue("Gui.Factory", "native"));
671  guiFactory.ToLower();
672  if (guiFactory == "native")
673  guiFactory = nativeg;
674 
675  if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualX", guiBackend))) {
676  if (h->LoadPlugin() == -1) {
677  gROOT->SetBatch(kTRUE);
678  return;
679  }
680  gVirtualX = (TVirtualX *) h->ExecPlugin(2, name.Data(), title.Data());
681  fgGraphInit = kTRUE;
682  }
683  if ((h = gROOT->GetPluginManager()->FindHandler("TGuiFactory", guiFactory))) {
684  if (h->LoadPlugin() == -1) {
685  gROOT->SetBatch(kTRUE);
686  return;
687  }
688  gGuiFactory = (TGuiFactory *) h->ExecPlugin(0);
689  }
690 }
691 
692 ////////////////////////////////////////////////////////////////////////////////
693 /// Switch to batch mode.
694 
696 {
697  gROOT->SetBatch();
700 #ifndef R__WIN32
701  if (gVirtualX != gGXBatch) delete gVirtualX;
702 #endif
704 }
705 
706 ////////////////////////////////////////////////////////////////////////////////
707 /// Parse the content of a line starting with ".R" (already stripped-off)
708 /// The format is
709 /// ~~~ {.cpp}
710 /// [user@]host[:dir] [-l user] [-d dbg] [script]
711 /// ~~~
712 /// The variable 'dir' is the remote directory to be used as working dir.
713 /// The username can be specified in two ways, "-l" having the priority
714 /// (as in ssh).
715 /// A 'dbg' value > 0 gives increasing verbosity.
716 /// The last argument 'script' allows to specify an alternative script to
717 /// be executed remotely to startup the session.
718 
720  TString &hostdir, TString &user,
721  Int_t &dbg, TString &script)
722 {
723  if (!ln || strlen(ln) <= 0)
724  return 0;
725 
726  Int_t rc = 0;
727  Bool_t isHostDir = kTRUE;
728  Bool_t isScript = kFALSE;
729  Bool_t isUser = kFALSE;
730  Bool_t isDbg = kFALSE;
731 
732  TString line(ln);
733  TString tkn;
734  Int_t from = 0;
735  while (line.Tokenize(tkn, from, " ")) {
736  if (tkn == "-l") {
737  // Next is a user name
738  isUser = kTRUE;
739  } else if (tkn == "-d") {
740  isDbg = kTRUE;
741  } else if (tkn == "-close") {
742  rc = 1;
743  } else if (tkn.BeginsWith("-")) {
744  ::Warning("TApplication::ParseRemoteLine","unknown option: %s", tkn.Data());
745  } else {
746  if (isUser) {
747  user = tkn;
748  isUser = kFALSE;
749  } else if (isDbg) {
750  dbg = tkn.Atoi();
751  isDbg = kFALSE;
752  } else if (isHostDir) {
753  hostdir = tkn;
754  hostdir.ReplaceAll(":","/");
755  isHostDir = kFALSE;
756  isScript = kTRUE;
757  } else if (isScript) {
758  // Add everything left
759  script = tkn;
760  script.Insert(0, "\"");
761  script += "\"";
762  isScript = kFALSE;
763  break;
764  }
765  }
766  }
767 
768  // Done
769  return rc;
770 }
771 
772 ////////////////////////////////////////////////////////////////////////////////
773 /// Process the content of a line starting with ".R" (already stripped-off)
774 /// The format is
775 /// ~~~ {.cpp}
776 /// [user@]host[:dir] [-l user] [-d dbg] [script] | [host] -close
777 /// ~~~
778 /// The variable 'dir' is the remote directory to be used as working dir.
779 /// The username can be specified in two ways, "-l" having the priority
780 /// (as in ssh).
781 /// A 'dbg' value > 0 gives increasing verbosity.
782 /// The last argument 'script' allows to specify an alternative script to
783 /// be executed remotely to startup the session.
784 
786 {
787  if (!line) return 0;
788 
789  if (!strncmp(line, "-?", 2) || !strncmp(line, "-h", 2) ||
790  !strncmp(line, "--help", 6)) {
791  Info("ProcessRemote", "remote session help:");
792  Printf(".R [user@]host[:dir] [-l user] [-d dbg] [[<]script] | [host] -close");
793  Printf("Create a ROOT session on the specified remote host.");
794  Printf("The variable \"dir\" is the remote directory to be used as working dir.");
795  Printf("The username can be specified in two ways, \"-l\" having the priority");
796  Printf("(as in ssh). A \"dbg\" value > 0 gives increasing verbosity.");
797  Printf("The last argument \"script\" allows to specify an alternative script to");
798  Printf("be executed remotely to startup the session, \"roots\" being");
799  Printf("the default. If the script is preceded by a \"<\" the script will be");
800  Printf("sourced, after which \"roots\" is executed. The sourced script can be ");
801  Printf("used to change the PATH and other variables, allowing an alternative");
802  Printf("\"roots\" script to be found.");
803  Printf("To close down a session do \".R host -close\".");
804  Printf("To switch between sessions do \".R host\", to switch to the local");
805  Printf("session do \".R\".");
806  Printf("To list all open sessions do \"gApplication->GetApplications()->Print()\".");
807  return 0;
808  }
809 
810  TString hostdir, user, script;
811  Int_t dbg = 0;
812  Int_t rc = ParseRemoteLine(line, hostdir, user, dbg, script);
813  if (hostdir.Length() <= 0) {
814  // Close the remote application if required
815  if (rc == 1) {
817  delete fAppRemote;
818  }
819  // Return to local run
820  fAppRemote = 0;
821  // Done
822  return 1;
823  } else if (rc == 1) {
824  // close an existing remote application
825  TApplication *ap = TApplication::Open(hostdir, 0, 0);
826  if (ap) {
828  delete ap;
829  }
830  }
831  // Attach or start a remote application
832  if (user.Length() > 0)
833  hostdir.Insert(0,Form("%s@", user.Data()));
834  const char *sc = (script.Length() > 0) ? script.Data() : 0;
835  TApplication *ap = TApplication::Open(hostdir, dbg, sc);
836  if (ap) {
837  fAppRemote = ap;
838  }
839 
840  // Done
841  return 1;
842 }
843 
844 namespace {
845  static int PrintFile(const char* filename) {
846  TString sFileName(filename);
847  gSystem->ExpandPathName(sFileName);
848  if (gSystem->AccessPathName(sFileName)) {
849  Error("ProcessLine()", "Cannot find file %s", filename);
850  return 1;
851  }
852  std::ifstream instr(sFileName);
853  TString content;
854  content.ReadFile(instr);
855  Printf("%s", content.Data());
856  return 0;
857  }
858 }
859 
860 ////////////////////////////////////////////////////////////////////////////////
861 /// Process a single command line, either a C++ statement or an interpreter
862 /// command starting with a ".".
863 /// Return the return value of the command cast to a long.
864 
866 {
867  if (!line || !*line) return 0;
868 
869  // If we are asked to go remote do it
870  if (!strncmp(line, ".R", 2)) {
871  Int_t n = 2;
872  while (*(line+n) == ' ')
873  n++;
874  return ProcessRemote(line+n, err);
875  }
876 
877  // Redirect, if requested
880  return fAppRemote->ProcessLine(line, err);
881  }
882 
883  if (!strncasecmp(line, ".qqqqqqq", 7)) {
884  gSystem->Abort();
885  } else if (!strncasecmp(line, ".qqqqq", 5)) {
886  Info("ProcessLine", "Bye... (try '.qqqqqqq' if still running)");
887  gSystem->Exit(1);
888  } else if (!strncasecmp(line, ".exit", 4) || !strncasecmp(line, ".quit", 2)) {
889  Terminate(0);
890  return 0;
891  }
892 
893  if (!strncmp(line, "?", 1) || !strncmp(line, ".help", 5)) {
894  Help(line);
895  return 1;
896  }
897 
898  if (!strncmp(line, ".demo", 5)) {
899  if (gROOT->IsBatch()) {
900  Error("ProcessLine", "Cannot show demos in batch mode!");
901  return 1;
902  }
903  ProcessLine(".x " + TROOT::GetTutorialDir() + "/demos.C");
904  return 0;
905  }
906 
907  if (!strncmp(line, ".license", 8)) {
908  return PrintFile(TROOT::GetDocDir() + "/LICENSE");
909  }
910 
911  if (!strncmp(line, ".credits", 8)) {
912  TString credits = TROOT::GetDocDir() + "/CREDITS";
913  if (gSystem->AccessPathName(credits, kReadPermission))
914  credits = TROOT::GetDocDir() + "/README/CREDITS";
915  return PrintFile(credits);
916  }
917 
918  if (!strncmp(line, ".pwd", 4)) {
919  if (gDirectory)
920  Printf("Current directory: %s", gDirectory->GetPath());
921  if (gPad)
922  Printf("Current pad: %s", gPad->GetName());
923  if (gStyle)
924  Printf("Current style: %s", gStyle->GetName());
925  return 1;
926  }
927 
928  if (!strncmp(line, ".ls", 3)) {
929  const char *opt = 0;
930  if (line[3]) opt = &line[3];
931  if (gDirectory) gDirectory->ls(opt);
932  return 1;
933  }
934 
935  if (!strncmp(line, ".which", 6)) {
936  char *fn = Strip(line+7);
937  char *s = strtok(fn, "+(");
938  char *mac = gSystem->Which(TROOT::GetMacroPath(), s, kReadPermission);
939  if (!mac)
940  Printf("No macro %s in path %s", s, TROOT::GetMacroPath());
941  else
942  Printf("%s", mac);
943  delete [] fn;
944  delete [] mac;
945  return mac ? 1 : 0;
946  }
947 
948  if (!strncmp(line, ".L", 2) || !strncmp(line, ".U", 2)) {
949  TString aclicMode;
950  TString arguments;
951  TString io;
952  TString fname = gSystem->SplitAclicMode(line+3, aclicMode, arguments, io);
953 
954  char *mac = gSystem->Which(TROOT::GetMacroPath(), fname, kReadPermission);
955  if (arguments.Length()) {
956  Warning("ProcessLine", "argument(s) \"%s\" ignored with .%c", arguments.Data(),
957  line[1]);
958  }
959  Long_t retval = 0;
960  if (!mac)
961  Error("ProcessLine", "macro %s not found in path %s", fname.Data(),
963  else {
964  TString cmd(line+1);
965  Ssiz_t posSpace = cmd.Index(' ');
966  if (posSpace == -1) cmd.Remove(1);
967  else cmd.Remove(posSpace);
968  TString tempbuf;
969  if (sync) {
970  tempbuf.Form(".%s %s%s%s", cmd.Data(), mac, aclicMode.Data(),io.Data());
971  retval = gInterpreter->ProcessLineSynch(tempbuf,
973  } else {
974  tempbuf.Form(".%s %s%s%s", cmd.Data(), mac, aclicMode.Data(),io.Data());
975  retval = gInterpreter->ProcessLine(tempbuf,
977  }
978  }
979 
980  delete [] mac;
981 
983 
984  return retval;
985  }
986 
987  if (!strncmp(line, ".X", 2) || !strncmp(line, ".x", 2)) {
988  return ProcessFile(line+3, err, line[2] == 'k');
989  }
990 
991  if (!strcmp(line, ".reset")) {
992  // Do nothing, .reset disabled in CINT because too many side effects
993  Printf("*** .reset not allowed, please use gROOT->Reset() ***");
994  return 0;
995 
996 #if 0
997  // delete the ROOT dictionary since CINT will destroy all objects
998  // referenced by the dictionary classes (TClass et. al.)
999  gROOT->GetListOfClasses()->Delete();
1000  // fall through
1001 #endif
1002  }
1003 
1004  if (sync)
1005  return gInterpreter->ProcessLineSynch(line, (TInterpreter::EErrorCode*)err);
1006  else
1007  return gInterpreter->ProcessLine(line, (TInterpreter::EErrorCode*)err);
1008 }
1009 
1010 ////////////////////////////////////////////////////////////////////////////////
1011 /// Process a file containing a C++ macro.
1012 
1014 {
1015  return ExecuteFile(file, error, keep);
1016 }
1017 
1018 ////////////////////////////////////////////////////////////////////////////////
1019 /// Execute a file containing a C++ macro (static method). Can be used
1020 /// while TApplication is not yet created.
1021 
1023 {
1024  static const Int_t kBufSize = 1024;
1025 
1026  if (!file || !*file) return 0;
1027 
1028  TString aclicMode;
1029  TString arguments;
1030  TString io;
1031  TString fname = gSystem->SplitAclicMode(file, aclicMode, arguments, io);
1032 
1033  char *exnam = gSystem->Which(TROOT::GetMacroPath(), fname, kReadPermission);
1034  if (!exnam) {
1035  ::Error("TApplication::ExecuteFile", "macro %s not found in path %s", fname.Data(),
1037  delete [] exnam;
1038  if (error)
1040  return 0;
1041  }
1042 
1043  ::std::ifstream macro(exnam, std::ios::in);
1044  if (!macro.good()) {
1045  ::Error("TApplication::ExecuteFile", "%s no such file", exnam);
1046  if (error)
1048  delete [] exnam;
1049  return 0;
1050  }
1051 
1052  char currentline[kBufSize];
1053  char dummyline[kBufSize];
1054  int tempfile = 0;
1055  int comment = 0;
1056  int ifndefc = 0;
1057  int ifdef = 0;
1058  char *s = 0;
1059  Bool_t execute = kFALSE;
1060  Long_t retval = 0;
1061 
1062  while (1) {
1063  bool res = (bool)macro.getline(currentline, kBufSize);
1064  if (macro.eof()) break;
1065  if (!res) {
1066  // Probably only read kBufSize, let's ignore the remainder of
1067  // the line.
1068  macro.clear();
1069  while (!macro.getline(dummyline, kBufSize) && !macro.eof()) {
1070  macro.clear();
1071  }
1072  }
1073  s = currentline;
1074  while (s && (*s == ' ' || *s == '\t')) s++; // strip-off leading blanks
1075 
1076  // very simple minded pre-processor parsing, only works in case macro file
1077  // starts with "#ifndef __CINT__". In that case everything till next
1078  // "#else" or "#endif" will be skipped.
1079  if (*s == '#') {
1080  char *cs = Compress(currentline);
1081  if (strstr(cs, "#ifndef__CINT__") ||
1082  strstr(cs, "#if!defined(__CINT__)"))
1083  ifndefc = 1;
1084  else if (ifndefc && (strstr(cs, "#ifdef") || strstr(cs, "#ifndef") ||
1085  strstr(cs, "#ifdefined") || strstr(cs, "#if!defined")))
1086  ifdef++;
1087  else if (ifndefc && strstr(cs, "#endif")) {
1088  if (ifdef)
1089  ifdef--;
1090  else
1091  ifndefc = 0;
1092  } else if (ifndefc && !ifdef && strstr(cs, "#else"))
1093  ifndefc = 0;
1094  delete [] cs;
1095  }
1096  if (!*s || *s == '#' || ifndefc || !strncmp(s, "//", 2)) continue;
1097 
1098  if (!comment && (!strncmp(s, ".X", 2) || !strncmp(s, ".x", 2))) {
1099  retval = ExecuteFile(s+3);
1100  execute = kTRUE;
1101  continue;
1102  }
1103 
1104  if (!strncmp(s, "/*", 2)) comment = 1;
1105  if (comment) {
1106  // handle slightly more complex cases like: /* */ /*
1107 again:
1108  s = strstr(s, "*/");
1109  if (s) {
1110  comment = 0;
1111  s += 2;
1112 
1113  while (s && (*s == ' ' || *s == '\t')) s++; // strip-off leading blanks
1114  if (!*s) continue;
1115  if (!strncmp(s, "//", 2)) continue;
1116  if (!strncmp(s, "/*", 2)) {
1117  comment = 1;
1118  goto again;
1119  }
1120  }
1121  }
1122  if (!comment && *s == '{') tempfile = 1;
1123  if (!comment) break;
1124  }
1125  macro.close();
1126 
1127  if (!execute) {
1128  TString exname = exnam;
1129  if (!tempfile) {
1130  // We have a script that does NOT contain an unnamed macro,
1131  // so we can call the script compiler on it.
1132  exname += aclicMode;
1133  }
1134  exname += arguments;
1135  exname += io;
1136 
1137  TString tempbuf;
1138  if (tempfile) {
1139  tempbuf.Form(".x %s", exname.Data());
1140  } else {
1141  tempbuf.Form(".X%s %s", keep ? "k" : " ", exname.Data());
1142  }
1143  retval = gInterpreter->ProcessLineSynch(tempbuf,(TInterpreter::EErrorCode*)error);
1144  }
1145 
1146  delete [] exnam;
1147  return retval;
1148 }
1149 
1150 ////////////////////////////////////////////////////////////////////////////////
1151 /// Main application eventloop. Calls system dependent eventloop via gSystem.
1152 
1154 {
1155  SetReturnFromRun(retrn);
1156 
1157  fIsRunning = kTRUE;
1158 
1159  gSystem->Run();
1160  fIsRunning = kFALSE;
1161 }
1162 
1163 ////////////////////////////////////////////////////////////////////////////////
1164 /// Set the command to be executed after the system has been idle for
1165 /// idleTimeInSec seconds. Normally called via TROOT::Idle(...).
1166 
1167 void TApplication::SetIdleTimer(UInt_t idleTimeInSec, const char *command)
1168 {
1169  if (fIdleTimer) RemoveIdleTimer();
1170  fIdleCommand = command;
1171  fIdleTimer = new TIdleTimer(idleTimeInSec*1000);
1173 }
1174 
1175 ////////////////////////////////////////////////////////////////////////////////
1176 /// Remove idle timer. Normally called via TROOT::Idle(0).
1177 
1179 {
1180  if (fIdleTimer) {
1181  // timers are removed from the gSystem timer list by their dtor
1183  }
1184 }
1185 
1186 ////////////////////////////////////////////////////////////////////////////////
1187 /// Called when system starts idleing.
1188 
1190 {
1191  if (fIdleTimer) {
1192  fIdleTimer->Reset();
1194  }
1195 }
1196 
1197 ////////////////////////////////////////////////////////////////////////////////
1198 /// Called when system stops idleing.
1199 
1201 {
1202  if (fIdleTimer)
1204 }
1205 
1206 ////////////////////////////////////////////////////////////////////////////////
1207 /// What to do when tab is pressed. Re-implemented by TRint.
1208 /// See TTabCom::Hook() for meaning of return values.
1209 
1210 Int_t TApplication::TabCompletionHook(char* /*buf*/, int* /*pLoc*/, std::ostream& /*out*/)
1211 {
1212  return -1;
1213 }
1214 
1215 
1216 ////////////////////////////////////////////////////////////////////////////////
1217 /// Terminate the application by call TSystem::Exit() unless application has
1218 /// been told to return from Run(), by a call to SetReturnFromRun().
1219 
1221 {
1222  Emit("Terminate(Int_t)", status);
1223 
1224  if (fReturnFromRun)
1225  gSystem->ExitLoop();
1226  else {
1227  //close TMemStat
1228  if (fUseMemstat) {
1229  ProcessLine("TMemStat::Close()");
1230  fUseMemstat = kFALSE;
1231  }
1232 
1233  gSystem->Exit(status);
1234  }
1235 }
1236 
1237 ////////////////////////////////////////////////////////////////////////////////
1238 /// Emit signal when a line has been processed.
1239 
1241 {
1242  Emit("LineProcessed(const char*)", line);
1243 }
1244 
1245 ////////////////////////////////////////////////////////////////////////////////
1246 /// Emit signal when console keyboard key was pressed.
1247 
1249 {
1250  Emit("KeyPressed(Int_t)", key);
1251 }
1252 
1253 ////////////////////////////////////////////////////////////////////////////////
1254 /// Emit signal when return key was pressed.
1255 
1257 {
1258  Emit("ReturnPressed(char*)", text);
1259 }
1260 
1261 ////////////////////////////////////////////////////////////////////////////////
1262 /// Set console echo mode:
1263 ///
1264 /// - mode = kTRUE - echo input symbols
1265 /// - mode = kFALSE - noecho input symbols
1266 
1268 {
1269 }
1270 
1271 ////////////////////////////////////////////////////////////////////////////////
1272 /// Static function used to create a default application environment.
1273 
1275 {
1277  // gApplication is set at the end of 'new TApplication.
1278  if (!gApplication) {
1279  char *a = StrDup("RootApp");
1280  char *b = StrDup("-b");
1281  char *argv[2];
1282  Int_t argc = 2;
1283  argv[0] = a;
1284  argv[1] = b;
1285  new TApplication("RootApp", &argc, argv, 0, 0);
1286  if (gDebug > 0)
1287  Printf("<TApplication::CreateApplication>: "
1288  "created default TApplication");
1289  delete [] a; delete [] b;
1290  gApplication->SetBit(kDefaultApplication);
1291  }
1292 }
1293 
1294 ////////////////////////////////////////////////////////////////////////////////
1295 /// Static function used to attach to an existing remote application
1296 /// or to start one.
1297 
1299  Int_t debug, const char *script)
1300 {
1301  TApplication *ap = 0;
1302  TUrl nu(url);
1303  Int_t nnew = 0;
1304 
1305  // Look among the existing ones
1306  if (fgApplications) {
1307  TIter nxa(fgApplications);
1308  while ((ap = (TApplication *) nxa())) {
1309  TString apn(ap->ApplicationName());
1310  if (apn == url) {
1311  // Found matching application
1312  return ap;
1313  } else {
1314  // Check if same machine and user
1315  TUrl au(apn);
1316  if (strlen(au.GetUser()) > 0 && strlen(nu.GetUser()) > 0 &&
1317  !strcmp(au.GetUser(), nu.GetUser())) {
1318  if (!strncmp(au.GetHost(), nu.GetHost(), strlen(nu.GetHost())))
1319  // New session on a known machine
1320  nnew++;
1321  }
1322  }
1323  }
1324  } else {
1325  ::Error("TApplication::Open", "list of applications undefined - protocol error");
1326  return ap;
1327  }
1328 
1329  // If new session on a known machine pass the number as option
1330  if (nnew > 0) {
1331  nnew++;
1332  nu.SetOptions(Form("%d", nnew));
1333  }
1334 
1335  // Instantiate the TApplication object to be run
1336  TPluginHandler *h = 0;
1337  if ((h = gROOT->GetPluginManager()->FindHandler("TApplication","remote"))) {
1338  if (h->LoadPlugin() == 0) {
1339  ap = (TApplication *) h->ExecPlugin(3, nu.GetUrl(), debug, script);
1340  } else {
1341  ::Error("TApplication::Open", "failed to load plugin for TApplicationRemote");
1342  }
1343  } else {
1344  ::Error("TApplication::Open", "failed to find plugin for TApplicationRemote");
1345  }
1346 
1347  // Add to the list
1348  if (ap && !(ap->TestBit(kInvalidObject))) {
1349  fgApplications->Add(ap);
1350  gROOT->GetListOfBrowsables()->Add(ap, ap->ApplicationName());
1351  TIter next(gROOT->GetListOfBrowsers());
1352  TBrowser *b;
1353  while ((b = (TBrowser*) next()))
1354  b->Add(ap, ap->ApplicationName());
1355  gROOT->RefreshBrowsers();
1356  } else {
1357  SafeDelete(ap);
1358  ::Error("TApplication::Open",
1359  "TApplicationRemote for %s could not be instantiated", url);
1360  }
1361 
1362  // Done
1363  return ap;
1364 }
1365 
1366 ////////////////////////////////////////////////////////////////////////////////
1367 /// Static function used to close a remote application
1368 
1370 {
1371  if (app) {
1372  app->Terminate(0);
1373  fgApplications->Remove(app);
1374  gROOT->GetListOfBrowsables()->RecursiveRemove(app);
1375  TIter next(gROOT->GetListOfBrowsers());
1376  TBrowser *b;
1377  while ((b = (TBrowser*) next()))
1378  b->RecursiveRemove(app);
1379  gROOT->RefreshBrowsers();
1380  }
1381 }
1382 
1383 ////////////////////////////////////////////////////////////////////////////////
1384 /// Show available sessions
1385 
1386 void TApplication::ls(Option_t *opt) const
1387 {
1388  if (fgApplications) {
1389  TIter nxa(fgApplications);
1390  TApplication *a = 0;
1391  while ((a = (TApplication *) nxa())) {
1392  a->Print(opt);
1393  }
1394  } else {
1395  Print(opt);
1396  }
1397 }
1398 
1399 ////////////////////////////////////////////////////////////////////////////////
1400 /// Static method returning the list of available applications
1401 
1403 {
1404  return fgApplications;
1405 }
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
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:1276
virtual void LoadGraphicsLibs()
Load shared libs necessary for graphics.
static const TString & GetTTFFontDir()
Get the fonts directory in the installation. Static utility function.
Definition: TROOT.cxx:3042
std::istream & ReadFile(std::istream &str)
Replace string with the contents of strm, stopping at an EOF.
Definition: Stringio.cxx:28
R__EXTERN TGuiFactory * gBatchGuiFactory
Definition: TGuiFactory.h:67
virtual Long_t ProcessLine(const char *line, Bool_t sync=kFALSE, Int_t *error=0)
Process a single command line, either a C++ statement or an interpreter command starting with a "...
Semi-Abstract base class defining a generic interface to the underlying, low level, native graphics backend (X11, Win32, MacOS, OpenGL...).
Definition: TVirtualX.h:58
An array of TObjects.
Definition: TObjArray.h:37
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:854
virtual void ls(Option_t *option="") const
Show available sessions.
long long Long64_t
Definition: RtypesCore.h:69
static const TString & GetTutorialDir()
Get the tutorials directory in the installation. Static utility function.
Definition: TROOT.cxx:2979
Bool_t fReturnFromRun
Definition: TApplication.h:62
static Bool_t fgGraphInit
Definition: TApplication.h:75
virtual const char * WorkingDirectory()
Return working directory.
Definition: TSystem.cxx:869
char * Compress(const char *str)
Remove all blanks from the string str.
Definition: TString.cxx:2558
void Reset()
Reset the timer.
Definition: TTimer.cxx:157
virtual void NotifyApplicationCreated()
Hook to tell TSystem that the TApplication object has been created.
Definition: TSystem.cxx:319
TLine * line
Collectable string class.
Definition: TObjString.h:28
R__EXTERN TClassTable * gClassTable
Definition: TClassTable.h:95
const char Option_t
Definition: RtypesCore.h:62
virtual TString SplitAclicMode(const char *filename, TString &mode, TString &args, TString &io) const
This method split a filename of the form: ~~~ {.cpp} [path/]macro.C[+|++[k|f|g|O|c|s|d|v|-]][(args)]...
Definition: TSystem.cxx:4124
virtual void Delete(Option_t *option="")
Remove all objects from the array AND delete all heap based objects.
Definition: TObjArray.cxx:355
R__EXTERN TVirtualMutex * gInterpreterMutex
Definition: TInterpreter.h:40
This class represents a WWW compatible URL.
Definition: TUrl.h:35
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:638
R__EXTERN TStyle * gStyle
Definition: TStyle.h:402
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:1374
const char * GetProtocol() const
Definition: TUrl.h:67
TH1 * h
Definition: legend2.C:5
virtual void MakeBatch()
Switch to batch mode.
TString fIdleCommand
Definition: TApplication.h:69
virtual Bool_t ChangeDirectory(const char *path)
Change directory.
Definition: TSystem.cxx:860
const char * GetFileAndOptions() const
Return the file and its options (the string specified behind the ?).
Definition: TUrl.cxx:501
#define gROOT
Definition: TROOT.h:402
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:585
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition: TObject.h:172
Int_t LoadPlugin()
Load the plugin library for this handler.
Basic string class.
Definition: TString.h:125
TSignalHandler * fSigHandler
Definition: TApplication.h:71
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1099
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual TTimer * RemoveTimer(TTimer *t)
Remove timer from list of system timers.
Definition: TSystem.cxx:489
static Bool_t fgGraphNeeded
Definition: TApplication.h:74
R__EXTERN TVirtualMutex * gROOTMutex
Definition: TROOT.h:57
EExitOnException fExitOnException
Definition: TApplication.h:72
virtual void ReturnPressed(char *text)
Emit signal when return key was pressed.
#define gInterpreter
Definition: TInterpreter.h:526
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
Definition: TSystem.cxx:1522
virtual void Terminate(Int_t status=0)
Terminate the application by call TSystem::Exit() unless application has been told to return from Run...
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
Definition: TObject.cxx:550
virtual Long_t ProcessRemote(const char *line, Int_t *error=0)
Process the content of a line starting with ".R" (already stripped-off) The format is [user@]host[:di...
Bool_t fNoLogo
Definition: TApplication.h:64
TString & Insert(Ssiz_t pos, const char *s)
Definition: TString.h:595
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:694
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
Definition: TUrl.cxx:387
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
Definition: TString.h:628
static const char * GetMacroPath()
Get macro search path. Static utility function.
Definition: TROOT.cxx:2699
const char * GetFile() const
Definition: TUrl.h:72
null_t< F > null()
static constexpr const char kCommandLineOptionsHelp[]
Help for command line options.
const char * GetHost() const
Definition: TUrl.h:70
#define SafeDelete(p)
Definition: RConfig.h:509
TString fWorkDir
Definition: TApplication.h:68
Double_t x[n]
Definition: legend1.C:17
virtual TApplicationImp * CreateApplicationImp(const char *classname, int *argc, char **argv)
Create a batch version of TApplicationImp.
Definition: TGuiFactory.cxx:48
virtual void SetIdleTimer(UInt_t idleTimeInSec, const char *command)
Set the command to be executed after the system has been idle for idleTimeInSec seconds.
virtual void Run(Bool_t retrn=kFALSE)
Main application eventloop. Calls system dependent eventloop via gSystem.
static Bool_t Initialized()
Return kTRUE if the TROOT object has been initialized.
Definition: TROOT.cxx:2754
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 [user@]host[:dir]...
virtual ~TApplication()
TApplication dtor.
virtual void Init()
Definition: TApplication.h:112
static const TString & GetDocDir()
Get the documentation directory in the installation. Static utility function.
Definition: TROOT.cxx:2942
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition: TString.cxx:2231
virtual void ExitLoop()
Exit from event loop.
Definition: TSystem.cxx:400
XFontStruct * id
Definition: TGX11.cxx:108
static void CallEndOfProcessCleanups()
R__EXTERN TGuiFactory * gGuiFactory
Definition: TGuiFactory.h:66
virtual void GetOptions(Int_t *argc, char **argv)
Get and handle command line options.
void EnableImplicitMT(UInt_t numthreads=0)
Enable ROOT&#39;s implicit multi-threading for all objects and methods that provide an internal paralleli...
Definition: TROOT.cxx:555
virtual Bool_t Notify()
Notify when timer times out.
Definition: TTimer.cxx:143
A doubly linked list.
Definition: TList.h:44
const char * GetUser() const
Definition: TUrl.h:68
static TList * GetApplications()
Static method returning the list of available applications.
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:37
virtual void Open()
Definition: TApplication.h:127
R__EXTERN TVirtualX * gGXBatch
Definition: TVirtualX.h:353
Bool_t fIsRunning
Window system specific application implementation.
Definition: TApplication.h:61
TObjArray * fFiles
Definition: TApplication.h:67
void ClearInputFiles()
Clear list containing macro files passed as program arguments.
virtual const char * ApplicationName() const
Definition: TApplication.h:123
virtual void RemoveIdleTimer()
Remove idle timer. Normally called via TROOT::Idle(0).
static void NeedGraphicsLibs()
Static method.
R__EXTERN TSystem * gSystem
Definition: TSystem.h:540
if object ctor succeeded but object should not be used
Definition: TObject.h:68
auto * a
Definition: textangle.C:12
Long_t ExecPlugin(int nargs, const T &... params)
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:818
void SetScreenFactor(Float_t factor=1)
Definition: TStyle.h:294
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition: TString.h:561
static Long_t ExecuteFile(const char *file, Int_t *error=0, Bool_t keep=kFALSE)
Execute a file containing a C++ macro (static method).
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition: TString.cxx:2343
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:880
char * Form(const char *fmt,...)
Ssiz_t Length() const
Definition: TString.h:386
Bool_t fUseMemstat
Definition: TApplication.h:66
TApplicationImp * fAppImp
Definition: TApplication.h:60
virtual void SetEchoMode(Bool_t mode)
Set console echo mode:
Handles synchronous and a-synchronous timer events.
Definition: TTimer.h:51
virtual void StopIdleing()
Called when system stops idleing.
char * Strip(const char *str, char c=' ')
Strip leading and trailing c (blanks by default) from a string.
Definition: TString.cxx:2508
virtual void Abort(int code=0)
Abort the application.
Definition: TSystem.cxx:732
TApplication * fAppRemote
Definition: TApplication.h:81
TString & String()
Definition: TObjString.h:49
static constexpr double ms
static void Close(TApplication *app)
Static function used to close a remote application.
#define gVirtualX
Definition: TVirtualX.h:350
virtual TObjLink * FirstLink() const
Definition: TList.h:108
virtual void Run()
System event loop.
Definition: TSystem.cxx:351
#define Printf
Definition: TGeoToOCC.h:18
char * StrDup(const char *str)
Duplicate the string str.
Definition: TString.cxx:2544
virtual void Help(const char *line)
Print help on interpreter.
const Bool_t kFALSE
Definition: RtypesCore.h:88
static void CreateApplication()
Static function used to create a default application environment.
void InitializeGraphics()
Initialize the graphics environment.
TString & Remove(Ssiz_t pos)
Definition: TString.h:619
long Long_t
Definition: RtypesCore.h:50
int Ssiz_t
Definition: RtypesCore.h:63
R__EXTERN ExceptionContext_t * gException
Definition: TException.h:74
virtual void StartIdleing()
Called when system starts idleing.
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
Definition: TString.cxx:2251
Bool_t fNoLog
Definition: TApplication.h:63
#define ClassImp(name)
Definition: Rtypes.h:359
void EnableThreadSafety()
Enables the global mutex to make ROOT thread safe/aware.
Definition: TROOT.cxx:528
TText * text
static DictFuncPtr_t GetDict(const char *cname)
Given the class name returns the Dictionary() function of a class (uses hash of name).
virtual void KeyPressed(Int_t key)
Emit signal when console keyboard key was pressed.
const char * GetIdleCommand() const
Definition: TApplication.h:118
R__EXTERN TEnv * gEnv
Definition: TEnv.h:171
TTimer(const TTimer &)
Double_t y[n]
Definition: legend1.C:17
char ** Argv() const
Definition: TApplication.h:136
virtual void SetProgname(const char *name)
Set the application name (from command line, argv[0]) and copy it in gProgName.
Definition: TSystem.cxx:231
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:570
static constexpr double s
#define R__LOCKGUARD(mutex)
TTimer * fIdleTimer
Definition: TApplication.h:70
virtual void LineProcessed(const char *line)
Emit signal when a line has been processed.
char ** fArgv
Definition: TApplication.h:59
Bool_t IsNull() const
Definition: TString.h:383
virtual Int_t TabCompletionHook(char *buf, int *pLoc, std::ostream &out)
What to do when tab is pressed.
EExitOnException ExitOnException(EExitOnException opt=kExit)
Set the exit on exception option.
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
This ABC is a factory for GUI components.
Definition: TGuiFactory.h:42
virtual void HandleIdleTimer()
Handle idle timeout.
virtual void HandleException(Int_t sig)
Handle exceptions (kSigBus, kSigSegmentationViolation, kSigIllegalInstruction and kSigFloatingExcepti...
virtual void Add(TObject *obj)
Definition: TList.h:87
virtual void AddTimer(TTimer *t)
Add timer to list of system timers.
Definition: TSystem.cxx:479
Definition: file.py:1
virtual void Exit(int code, Bool_t mode=kTRUE)
Exit the application.
Definition: TSystem.cxx:724
void SetOptions(const char *opt)
Definition: TUrl.h:90
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
TApplication * gApplication
#define gPad
Definition: TVirtualPad.h:285
R__EXTERN Int_t gDebug
Definition: Rtypes.h:86
Int_t Atoi() const
Return integer value of string.
Definition: TString.cxx:1975
void Add(TObject *obj)
Definition: TObjArray.h:73
#define gDirectory
Definition: TDirectory.h:213
static void InitializeColors()
Initialize colors used by the TCanvas based graphics (via TColor objects).
Definition: TColor.cxx:1070
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition: TQObject.h:165
void ResetBit(UInt_t f)
Definition: TObject.h:171
This class creates the ROOT Application Environment that interfaces to the windowing system eventloop...
Definition: TApplication.h:39
Bool_t fQuit
Definition: TApplication.h:65
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition: TSystem.cxx:1254
static TList * fgApplications
Definition: TApplication.h:83
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition: TObject.cxx:908
void SetReturnFromRun(Bool_t ret)
Definition: TApplication.h:149
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition: TEnv.cxx:491
const Bool_t kTRUE
Definition: RtypesCore.h:87
const Int_t n
Definition: legend1.C:16
char name[80]
Definition: TGX11.cxx:109
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:866
virtual Long_t ProcessFile(const char *file, Int_t *error=0, Bool_t keep=kFALSE)
Process a file containing a C++ macro.
const char * Data() const
Definition: TString.h:345
TApplication()
Default ctor. Can be used by classes deriving from TApplication.