Logo ROOT   6.12/06
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 {
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) :
125  fArgc(0), fArgv(0), fAppImp(0), fIsRunning(kFALSE), fReturnFromRun(kFALSE),
126  fNoLog(kFALSE), fNoLogo(kFALSE), fQuit(kFALSE), fUseMemstat(kFALSE),
127  fFiles(0), fIdleTimer(0), fSigHandler(0), fExitOnException(kDontExit),
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 
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. Abort silently
281  // if libttf or libGX11TTF are not found in $ROOTSYS/lib or $ROOTSYS/ttf/lib.
282 #if !defined(R__WIN32)
283  if (!gROOT->IsBatch() && !strcmp(gVirtualX->GetName(), "X11") &&
284  gEnv->GetValue("Root.UseTTFonts", 1)) {
285  if (gClassTable->GetDict("TGX11TTF")) {
286  // in principle we should not have linked anything against libGX11TTF
287  // but with ACLiC this can happen, initialize TGX11TTF by hand
288  // (normally this is done by the static library initializer)
289  ProcessLine("TGX11TTF::Activate();");
290  } else {
291  TPluginHandler *h;
292  if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualX", "x11ttf")))
293  if (h->LoadPlugin() == -1)
294  Info("InitializeGraphics", "no TTF support");
295  }
296  }
297 #endif
298 
299  // Create WM dependent application environment
300  if (fAppImp)
301  delete fAppImp;
303  if (!fAppImp) {
304  MakeBatch();
306  }
307 
308  // Create the canvas colors early so they are allocated before
309  // any color table expensive bitmaps get allocated in GUI routines (like
310  // creation of XPM bitmaps).
312 
313  // Hook for further initializing the WM dependent application environment
314  Init();
315 
316  // Set default screen factor (if not disabled in rc file)
317  if (gEnv->GetValue("Canvas.UseScreenFactor", 1)) {
318  Int_t x, y;
319  UInt_t w, h;
320  if (gVirtualX) {
321  gVirtualX->GetGeometry(-1, x, y, w, h);
322  if (h > 0 && h < 1000) gStyle->SetScreenFactor(0.0011*h);
323  }
324  }
325 #endif // iOS
326 }
327 
328 ////////////////////////////////////////////////////////////////////////////////
329 /// Clear list containing macro files passed as program arguments.
330 /// This method is called from TRint::Run() to ensure that the macro
331 /// files are only executed the first time Run() is called.
332 
334 {
335  if (fFiles) {
336  fFiles->Delete();
338  }
339 }
340 
341 ////////////////////////////////////////////////////////////////////////////////
342 /// Return specified argument.
343 
344 char *TApplication::Argv(Int_t index) const
345 {
346  if (fArgv) {
347  if (index >= fArgc) {
348  Error("Argv", "index (%d) >= number of arguments (%d)", index, fArgc);
349  return 0;
350  }
351  return fArgv[index];
352  }
353  return 0;
354 }
355 
356 ////////////////////////////////////////////////////////////////////////////////
357 /// Get and handle command line options. Arguments handled are removed
358 /// from the argument array. See CommandLineOptionsHelp.h for options.
359 
360 void TApplication::GetOptions(Int_t *argc, char **argv)
361 {
362  static char null[1] = { "" };
363 
364  fNoLog = kFALSE;
365  fQuit = kFALSE;
366  fFiles = 0;
367 
368  if (!argc)
369  return;
370 
371  int i, j;
372  TString pwd;
373 
374  for (i = 1; i < *argc; i++) {
375  if (!strcmp(argv[i], "-?") || !strncmp(argv[i], "-h", 2) ||
376  !strncmp(argv[i], "--help", 6)) {
377  fprintf(stderr, kCommandLineOptionsHelp, argv[0]);
378  Terminate(0);
379  } else if (!strcmp(argv[i], "-config")) {
380  fprintf(stderr, "ROOT ./configure options:\n%s\n", gROOT->GetConfigOptions());
381  Terminate(0);
382  } else if (!strcmp(argv[i], "-memstat")) {
383  fUseMemstat = kTRUE;
384  argv[i] = null;
385  } else if (!strcmp(argv[i], "-b")) {
386  MakeBatch();
387  argv[i] = null;
388  } else if (!strcmp(argv[i], "-n")) {
389  fNoLog = kTRUE;
390  argv[i] = null;
391  } else if (!strcmp(argv[i], "-t")) {
393  // EnableImplicitMT() only enables thread safety if IMT was configured;
394  // enable thread safety even with IMT off:
396  argv[i] = null;
397  } else if (!strcmp(argv[i], "-q")) {
398  fQuit = kTRUE;
399  argv[i] = null;
400  } else if (!strcmp(argv[i], "-l")) {
401  // used by front-end program to not display splash screen
402  fNoLogo = kTRUE;
403  argv[i] = null;
404  } else if (!strcmp(argv[i], "-x")) {
406  argv[i] = null;
407  } else if (!strcmp(argv[i], "-splash")) {
408  // used when started by front-end program to signal that
409  // splash screen can be popped down (TRint::PrintLogo())
410  argv[i] = null;
411  } else if (!strcmp(argv[i], "-e")) {
412  argv[i] = null;
413  ++i;
414 
415  if ( i < *argc ) {
416  if (!fFiles) fFiles = new TObjArray;
417  TObjString *expr = new TObjString(argv[i]);
418  expr->SetBit(kExpression);
419  fFiles->Add(expr);
420  argv[i] = null;
421  } else {
422  Warning("GetOptions", "-e must be followed by an expression.");
423  }
424  } else if (!strcmp(argv[i], "--")) {
425  TObjString* macro = nullptr;
426  bool warnShown = false;
427 
428  if (fFiles) {
429  for (auto f: *fFiles) {
430  TObjString* file = dynamic_cast<TObjString*>(f);
431  if (!file) {
432  Error("GetOptions()", "Inconsistent file entry (not a TObjString)!");
433  f->Dump();
434  continue;
435  }
436 
437  if (file->TestBit(kExpression))
438  continue;
439  if (file->String().EndsWith(".root"))
440  continue;
441  if (file->String().Contains('('))
442  continue;
443 
444  if (macro && !warnShown && (warnShown = true))
445  Warning("GetOptions", "-- is used with several macros. "
446  "The arguments will be passed to the last one.");
447 
448  macro = file;
449  }
450  }
451 
452  if (macro) {
453  argv[i] = null;
454  ++i;
455  TString& str = macro->String();
456 
457  str += '(';
458  for (; i < *argc; i++) {
459  str += argv[i];
460  str += ',';
461  argv[i] = null;
462  }
463  str.EndsWith(",") ? str[str.Length() - 1] = ')' : str += ')';
464  } else {
465  Warning("GetOptions", "no macro to pass arguments to was provided. "
466  "Everything after the -- will be ignored.");
467  for (; i < *argc; i++)
468  argv[i] = null;
469  }
470  } else if (argv[i][0] != '-' && argv[i][0] != '+') {
471  Long64_t size;
472  Long_t id, flags, modtime;
473  char *arg = strchr(argv[i], '(');
474  if (arg) *arg = '\0';
475  char *dir = gSystem->ExpandPathName(argv[i]);
476  TUrl udir(dir, kTRUE);
477  // remove options and anchor to check the path
478  TString sfx = udir.GetFileAndOptions();
479  TString fln = udir.GetFile();
480  sfx.Replace(sfx.Index(fln), fln.Length(), "");
481  TString path = udir.GetFile();
482  if (strcmp(udir.GetProtocol(), "file")) {
483  path = udir.GetUrl();
484  path.Replace(path.Index(sfx), sfx.Length(), "");
485  }
486  // 'path' is the full URL without suffices (options and/or anchor)
487  if (arg) *arg = '(';
488  if (!arg && !gSystem->GetPathInfo(path.Data(), &id, &size, &flags, &modtime)) {
489  if ((flags & 2)) {
490  // if directory set it in fWorkDir
491  if (pwd == "") {
492  pwd = gSystem->WorkingDirectory();
493  fWorkDir = dir;
494  gSystem->ChangeDirectory(dir);
495  argv[i] = null;
496  } else if (!strcmp(gROOT->GetName(), "Rint")) {
497  Warning("GetOptions", "only one directory argument can be specified (%s)", dir);
498  }
499  } else if (size > 0) {
500  // if file add to list of files to be processed
501  if (!fFiles) fFiles = new TObjArray;
502  fFiles->Add(new TObjString(path.Data()));
503  argv[i] = null;
504  } else {
505  Warning("GetOptions", "file %s has size 0, skipping", dir);
506  }
507  } else {
508  if (TString(udir.GetFile()).EndsWith(".root")) {
509  if (!strcmp(udir.GetProtocol(), "file")) {
510  // file ending on .root but does not exist, likely a typo
511  // warn user if plain root...
512  if (!strcmp(gROOT->GetName(), "Rint"))
513  Warning("GetOptions", "file %s not found", dir);
514  } else {
515  // remote file, give it the benefit of the doubt and add it to list of files
516  if (!fFiles) fFiles = new TObjArray;
517  fFiles->Add(new TObjString(argv[i]));
518  argv[i] = null;
519  }
520  } else {
521  TString mode,fargs,io;
522  TString fname = gSystem->SplitAclicMode(dir,mode,fargs,io);
523  char *mac;
524  if ((mac = gSystem->Which(TROOT::GetMacroPath(), fname,
525  kReadPermission))) {
526  // if file add to list of files to be processed
527  if (!fFiles) fFiles = new TObjArray;
528  fFiles->Add(new TObjString(argv[i]));
529  argv[i] = null;
530  delete [] mac;
531  } else {
532  // only warn if we're plain root,
533  // other progs might have their own params
534  if (!strcmp(gROOT->GetName(), "Rint"))
535  Warning("GetOptions", "macro %s not found", fname.Data());
536  }
537  }
538  }
539  delete [] dir;
540  }
541  // ignore unknown options
542  }
543 
544  // go back to startup directory
545  if (pwd != "")
546  gSystem->ChangeDirectory(pwd);
547 
548  // remove handled arguments from argument array
549  j = 0;
550  for (i = 0; i < *argc; i++) {
551  if (strcmp(argv[i], "")) {
552  argv[j] = argv[i];
553  j++;
554  }
555  }
556 
557  *argc = j;
558 }
559 
560 ////////////////////////////////////////////////////////////////////////////////
561 /// Handle idle timeout. When this timer expires the registered idle command
562 /// will be executed by this routine and a signal will be emitted.
563 
565 {
566  if (!fIdleCommand.IsNull())
568 
569  Emit("HandleIdleTimer()");
570 }
571 
572 ////////////////////////////////////////////////////////////////////////////////
573 /// Handle exceptions (kSigBus, kSigSegmentationViolation,
574 /// kSigIllegalInstruction and kSigFloatingException) trapped in TSystem.
575 /// Specific TApplication implementations may want something different here.
576 
578 {
579  if (TROOT::Initialized()) {
580  if (gException) {
581  gInterpreter->RewindDictionary();
582  gInterpreter->ClearFileBusy();
583  }
584  if (fExitOnException == kExit)
585  gSystem->Exit(sig);
586  else if (fExitOnException == kAbort)
587  gSystem->Abort();
588  else
589  Throw(sig);
590  }
591  gSystem->Exit(sig);
592 }
593 
594 ////////////////////////////////////////////////////////////////////////////////
595 /// Set the exit on exception option. Setting this option determines what
596 /// happens in HandleException() in case an exception (kSigBus,
597 /// kSigSegmentationViolation, kSigIllegalInstruction or kSigFloatingException)
598 /// is trapped. Choices are: kDontExit (default), kExit or kAbort.
599 /// Returns the previous value.
600 
602 {
604  fExitOnException = opt;
605  return old;
606 }
607 
608 ////////////////////////////////////////////////////////////////////////////////
609 /// Print help on interpreter.
610 
611 void TApplication::Help(const char *line)
612 {
613  gInterpreter->ProcessLine(line);
614 
615  Printf("\nROOT special commands.");
616  Printf("===========================================================================");
617  Printf(" pwd : show current directory, pad and style");
618  Printf(" ls : list contents of current directory");
619  Printf(" which [file] : shows path of macro file");
620 }
621 
622 ////////////////////////////////////////////////////////////////////////////////
623 /// Load shared libs necessary for graphics. These libraries are only
624 /// loaded when gROOT->IsBatch() is kFALSE.
625 
627 {
628  if (gROOT->IsBatch()) return;
629 
630  TPluginHandler *h;
631  if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualPad")))
632  if (h->LoadPlugin() == -1)
633  return;
634 
635  TString name;
636  TString title1 = "ROOT interface to ";
637  TString nativex, title;
638  TString nativeg = "root";
639 
640 #ifdef R__WIN32
641  nativex = "win32gdk";
642  name = "Win32gdk";
643  title = title1 + "Win32gdk";
644 #elif defined(R__HAS_COCOA)
645  nativex = "quartz";
646  name = "quartz";
647  title = title1 + "Quartz";
648 #else
649  nativex = "x11";
650  name = "X11";
651  title = title1 + "X11";
652 #endif
653 
654  TString guiBackend(gEnv->GetValue("Gui.Backend", "native"));
655  guiBackend.ToLower();
656  if (guiBackend == "native") {
657  guiBackend = nativex;
658  } else {
659  name = guiBackend;
660  title = title1 + guiBackend;
661  }
662  TString guiFactory(gEnv->GetValue("Gui.Factory", "native"));
663  guiFactory.ToLower();
664  if (guiFactory == "native")
665  guiFactory = nativeg;
666 
667  if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualX", guiBackend))) {
668  if (h->LoadPlugin() == -1) {
669  gROOT->SetBatch(kTRUE);
670  return;
671  }
672  gVirtualX = (TVirtualX *) h->ExecPlugin(2, name.Data(), title.Data());
673  fgGraphInit = kTRUE;
674  }
675  if ((h = gROOT->GetPluginManager()->FindHandler("TGuiFactory", guiFactory))) {
676  if (h->LoadPlugin() == -1) {
677  gROOT->SetBatch(kTRUE);
678  return;
679  }
680  gGuiFactory = (TGuiFactory *) h->ExecPlugin(0);
681  }
682 }
683 
684 ////////////////////////////////////////////////////////////////////////////////
685 /// Switch to batch mode.
686 
688 {
689  gROOT->SetBatch();
692 #ifndef R__WIN32
693  if (gVirtualX != gGXBatch) delete gVirtualX;
694 #endif
696 }
697 
698 ////////////////////////////////////////////////////////////////////////////////
699 /// Parse the content of a line starting with ".R" (already stripped-off)
700 /// The format is
701 /// ~~~ {.cpp}
702 /// [user@]host[:dir] [-l user] [-d dbg] [script]
703 /// ~~~
704 /// The variable 'dir' is the remote directory to be used as working dir.
705 /// The username can be specified in two ways, "-l" having the priority
706 /// (as in ssh).
707 /// A 'dbg' value > 0 gives increasing verbosity.
708 /// The last argument 'script' allows to specify an alternative script to
709 /// be executed remotely to startup the session.
710 
712  TString &hostdir, TString &user,
713  Int_t &dbg, TString &script)
714 {
715  if (!ln || strlen(ln) <= 0)
716  return 0;
717 
718  Int_t rc = 0;
719  Bool_t isHostDir = kTRUE;
720  Bool_t isScript = kFALSE;
721  Bool_t isUser = kFALSE;
722  Bool_t isDbg = kFALSE;
723 
724  TString line(ln);
725  TString tkn;
726  Int_t from = 0;
727  while (line.Tokenize(tkn, from, " ")) {
728  if (tkn == "-l") {
729  // Next is a user name
730  isUser = kTRUE;
731  } else if (tkn == "-d") {
732  isDbg = kTRUE;
733  } else if (tkn == "-close") {
734  rc = 1;
735  } else if (tkn.BeginsWith("-")) {
736  ::Warning("TApplication::ParseRemoteLine","unknown option: %s", tkn.Data());
737  } else {
738  if (isUser) {
739  user = tkn;
740  isUser = kFALSE;
741  } else if (isDbg) {
742  dbg = tkn.Atoi();
743  isDbg = kFALSE;
744  } else if (isHostDir) {
745  hostdir = tkn;
746  hostdir.ReplaceAll(":","/");
747  isHostDir = kFALSE;
748  isScript = kTRUE;
749  } else if (isScript) {
750  // Add everything left
751  script = tkn;
752  script.Insert(0, "\"");
753  script += "\"";
754  isScript = kFALSE;
755  break;
756  }
757  }
758  }
759 
760  // Done
761  return rc;
762 }
763 
764 ////////////////////////////////////////////////////////////////////////////////
765 /// Process the content of a line starting with ".R" (already stripped-off)
766 /// The format is
767 /// ~~~ {.cpp}
768 /// [user@]host[:dir] [-l user] [-d dbg] [script] | [host] -close
769 /// ~~~
770 /// The variable 'dir' is the remote directory to be used as working dir.
771 /// The username can be specified in two ways, "-l" having the priority
772 /// (as in ssh).
773 /// A 'dbg' value > 0 gives increasing verbosity.
774 /// The last argument 'script' allows to specify an alternative script to
775 /// be executed remotely to startup the session.
776 
778 {
779  if (!line) return 0;
780 
781  if (!strncmp(line, "-?", 2) || !strncmp(line, "-h", 2) ||
782  !strncmp(line, "--help", 6)) {
783  Info("ProcessRemote", "remote session help:");
784  Printf(".R [user@]host[:dir] [-l user] [-d dbg] [[<]script] | [host] -close");
785  Printf("Create a ROOT session on the specified remote host.");
786  Printf("The variable \"dir\" is the remote directory to be used as working dir.");
787  Printf("The username can be specified in two ways, \"-l\" having the priority");
788  Printf("(as in ssh). A \"dbg\" value > 0 gives increasing verbosity.");
789  Printf("The last argument \"script\" allows to specify an alternative script to");
790  Printf("be executed remotely to startup the session, \"roots\" being");
791  Printf("the default. If the script is preceded by a \"<\" the script will be");
792  Printf("sourced, after which \"roots\" is executed. The sourced script can be ");
793  Printf("used to change the PATH and other variables, allowing an alternative");
794  Printf("\"roots\" script to be found.");
795  Printf("To close down a session do \".R host -close\".");
796  Printf("To switch between sessions do \".R host\", to switch to the local");
797  Printf("session do \".R\".");
798  Printf("To list all open sessions do \"gApplication->GetApplications()->Print()\".");
799  return 0;
800  }
801 
802  TString hostdir, user, script;
803  Int_t dbg = 0;
804  Int_t rc = ParseRemoteLine(line, hostdir, user, dbg, script);
805  if (hostdir.Length() <= 0) {
806  // Close the remote application if required
807  if (rc == 1) {
809  delete fAppRemote;
810  }
811  // Return to local run
812  fAppRemote = 0;
813  // Done
814  return 1;
815  } else if (rc == 1) {
816  // close an existing remote application
817  TApplication *ap = TApplication::Open(hostdir, 0, 0);
818  if (ap) {
820  delete ap;
821  }
822  }
823  // Attach or start a remote application
824  if (user.Length() > 0)
825  hostdir.Insert(0,Form("%s@", user.Data()));
826  const char *sc = (script.Length() > 0) ? script.Data() : 0;
827  TApplication *ap = TApplication::Open(hostdir, dbg, sc);
828  if (ap) {
829  fAppRemote = ap;
830  }
831 
832  // Done
833  return 1;
834 }
835 
836 namespace {
837  static int PrintFile(const char* filename) {
838  TString sFileName(filename);
839  gSystem->ExpandPathName(sFileName);
840  if (gSystem->AccessPathName(sFileName)) {
841  Error("ProcessLine()", "Cannot find file %s", filename);
842  return 1;
843  }
844  std::ifstream instr(sFileName);
845  TString content;
846  content.ReadFile(instr);
847  Printf("%s", content.Data());
848  return 0;
849  }
850 }
851 
852 ////////////////////////////////////////////////////////////////////////////////
853 /// Process a single command line, either a C++ statement or an interpreter
854 /// command starting with a ".".
855 /// Return the return value of the command cast to a long.
856 
857 Long_t TApplication::ProcessLine(const char *line, Bool_t sync, Int_t *err)
858 {
859  if (!line || !*line) return 0;
860 
861  // If we are asked to go remote do it
862  if (!strncmp(line, ".R", 2)) {
863  Int_t n = 2;
864  while (*(line+n) == ' ')
865  n++;
866  return ProcessRemote(line+n, err);
867  }
868 
869  // Redirect, if requested
872  return fAppRemote->ProcessLine(line, err);
873  }
874 
875  if (!strncasecmp(line, ".qqqqqqq", 7)) {
876  gSystem->Abort();
877  } else if (!strncasecmp(line, ".qqqqq", 5)) {
878  Info("ProcessLine", "Bye... (try '.qqqqqqq' if still running)");
879  gSystem->Exit(1);
880  } else if (!strncasecmp(line, ".exit", 4) || !strncasecmp(line, ".quit", 2)) {
881  Terminate(0);
882  return 0;
883  }
884 
885  if (!strncmp(line, "?", 1) || !strncmp(line, ".help", 5)) {
886  Help(line);
887  return 1;
888  }
889 
890  if (!strncmp(line, ".demo", 5)) {
891  if (gROOT->IsBatch()) {
892  Error("ProcessLine", "Cannot show demos in batch mode!");
893  return 1;
894  }
895  ProcessLine(".x " + TROOT::GetTutorialDir() + "/demos.C");
896  return 0;
897  }
898 
899  if (!strncmp(line, ".license", 8)) {
900  return PrintFile(TROOT::GetDocDir() + "/LICENSE");
901  }
902 
903  if (!strncmp(line, ".credits", 8)) {
904  TString credits = TROOT::GetDocDir() + "/CREDITS";
905  if (gSystem->AccessPathName(credits, kReadPermission))
906  credits = TROOT::GetDocDir() + "/README/CREDITS";
907  return PrintFile(credits);
908  }
909 
910  if (!strncmp(line, ".pwd", 4)) {
911  if (gDirectory)
912  Printf("Current directory: %s", gDirectory->GetPath());
913  if (gPad)
914  Printf("Current pad: %s", gPad->GetName());
915  if (gStyle)
916  Printf("Current style: %s", gStyle->GetName());
917  return 1;
918  }
919 
920  if (!strncmp(line, ".ls", 3)) {
921  const char *opt = 0;
922  if (line[3]) opt = &line[3];
923  if (gDirectory) gDirectory->ls(opt);
924  return 1;
925  }
926 
927  if (!strncmp(line, ".which", 6)) {
928  char *fn = Strip(line+7);
929  char *s = strtok(fn, "+(");
931  if (!mac)
932  Printf("No macro %s in path %s", s, TROOT::GetMacroPath());
933  else
934  Printf("%s", mac);
935  delete [] fn;
936  delete [] mac;
937  return mac ? 1 : 0;
938  }
939 
940  if (!strncmp(line, ".L", 2) || !strncmp(line, ".U", 2)) {
941  TString aclicMode;
942  TString arguments;
943  TString io;
944  TString fname = gSystem->SplitAclicMode(line+3, aclicMode, arguments, io);
945 
946  char *mac = gSystem->Which(TROOT::GetMacroPath(), fname, kReadPermission);
947  if (arguments.Length()) {
948  Warning("ProcessLine", "argument(s) \"%s\" ignored with .%c", arguments.Data(),
949  line[1]);
950  }
951  Long_t retval = 0;
952  if (!mac)
953  Error("ProcessLine", "macro %s not found in path %s", fname.Data(),
955  else {
956  TString cmd(line+1);
957  Ssiz_t posSpace = cmd.Index(' ');
958  if (posSpace == -1) cmd.Remove(1);
959  else cmd.Remove(posSpace);
960  TString tempbuf;
961  if (sync) {
962  tempbuf.Form(".%s %s%s%s", cmd.Data(), mac, aclicMode.Data(),io.Data());
963  retval = gInterpreter->ProcessLineSynch(tempbuf,
965  } else {
966  tempbuf.Form(".%s %s%s%s", cmd.Data(), mac, aclicMode.Data(),io.Data());
967  retval = gInterpreter->ProcessLine(tempbuf,
969  }
970  }
971 
972  delete [] mac;
973 
975 
976  return retval;
977  }
978 
979  if (!strncmp(line, ".X", 2) || !strncmp(line, ".x", 2)) {
980  return ProcessFile(line+3, err, line[2] == 'k');
981  }
982 
983  if (!strcmp(line, ".reset")) {
984  // Do nothing, .reset disabled in CINT because too many side effects
985  Printf("*** .reset not allowed, please use gROOT->Reset() ***");
986  return 0;
987 
988 #if 0
989  // delete the ROOT dictionary since CINT will destroy all objects
990  // referenced by the dictionary classes (TClass et. al.)
991  gROOT->GetListOfClasses()->Delete();
992  // fall through
993 #endif
994  }
995 
996  if (sync)
997  return gInterpreter->ProcessLineSynch(line, (TInterpreter::EErrorCode*)err);
998  else
999  return gInterpreter->ProcessLine(line, (TInterpreter::EErrorCode*)err);
1000 }
1001 
1002 ////////////////////////////////////////////////////////////////////////////////
1003 /// Process a file containing a C++ macro.
1004 
1005 Long_t TApplication::ProcessFile(const char *file, Int_t *error, Bool_t keep)
1006 {
1007  return ExecuteFile(file, error, keep);
1008 }
1009 
1010 ////////////////////////////////////////////////////////////////////////////////
1011 /// Execute a file containing a C++ macro (static method). Can be used
1012 /// while TApplication is not yet created.
1013 
1014 Long_t TApplication::ExecuteFile(const char *file, Int_t *error, Bool_t keep)
1015 {
1016  static const Int_t kBufSize = 1024;
1017 
1018  if (!file || !*file) return 0;
1019 
1020  TString aclicMode;
1021  TString arguments;
1022  TString io;
1023  TString fname = gSystem->SplitAclicMode(file, aclicMode, arguments, io);
1024 
1025  char *exnam = gSystem->Which(TROOT::GetMacroPath(), fname, kReadPermission);
1026  if (!exnam) {
1027  ::Error("TApplication::ExecuteFile", "macro %s not found in path %s", fname.Data(),
1029  delete [] exnam;
1030  if (error)
1032  return 0;
1033  }
1034 
1035  ::std::ifstream macro(exnam, std::ios::in);
1036  if (!macro.good()) {
1037  ::Error("TApplication::ExecuteFile", "%s no such file", exnam);
1038  if (error)
1040  delete [] exnam;
1041  return 0;
1042  }
1043 
1044  char currentline[kBufSize];
1045  char dummyline[kBufSize];
1046  int tempfile = 0;
1047  int comment = 0;
1048  int ifndefc = 0;
1049  int ifdef = 0;
1050  char *s = 0;
1051  Bool_t execute = kFALSE;
1052  Long_t retval = 0;
1053 
1054  while (1) {
1055  bool res = (bool)macro.getline(currentline, kBufSize);
1056  if (macro.eof()) break;
1057  if (!res) {
1058  // Probably only read kBufSize, let's ignore the remainder of
1059  // the line.
1060  macro.clear();
1061  while (!macro.getline(dummyline, kBufSize) && !macro.eof()) {
1062  macro.clear();
1063  }
1064  }
1065  s = currentline;
1066  while (s && (*s == ' ' || *s == '\t')) s++; // strip-off leading blanks
1067 
1068  // very simple minded pre-processor parsing, only works in case macro file
1069  // starts with "#ifndef __CINT__". In that case everything till next
1070  // "#else" or "#endif" will be skipped.
1071  if (*s == '#') {
1072  char *cs = Compress(currentline);
1073  if (strstr(cs, "#ifndef__CINT__") ||
1074  strstr(cs, "#if!defined(__CINT__)"))
1075  ifndefc = 1;
1076  else if (ifndefc && (strstr(cs, "#ifdef") || strstr(cs, "#ifndef") ||
1077  strstr(cs, "#ifdefined") || strstr(cs, "#if!defined")))
1078  ifdef++;
1079  else if (ifndefc && strstr(cs, "#endif")) {
1080  if (ifdef)
1081  ifdef--;
1082  else
1083  ifndefc = 0;
1084  } else if (ifndefc && !ifdef && strstr(cs, "#else"))
1085  ifndefc = 0;
1086  delete [] cs;
1087  }
1088  if (!*s || *s == '#' || ifndefc || !strncmp(s, "//", 2)) continue;
1089 
1090  if (!comment && (!strncmp(s, ".X", 2) || !strncmp(s, ".x", 2))) {
1091  retval = ExecuteFile(s+3);
1092  execute = kTRUE;
1093  continue;
1094  }
1095 
1096  if (!strncmp(s, "/*", 2)) comment = 1;
1097  if (comment) {
1098  // handle slightly more complex cases like: /* */ /*
1099 again:
1100  s = strstr(s, "*/");
1101  if (s) {
1102  comment = 0;
1103  s += 2;
1104 
1105  while (s && (*s == ' ' || *s == '\t')) s++; // strip-off leading blanks
1106  if (!*s) continue;
1107  if (!strncmp(s, "//", 2)) continue;
1108  if (!strncmp(s, "/*", 2)) {
1109  comment = 1;
1110  goto again;
1111  }
1112  }
1113  }
1114  if (!comment && *s == '{') tempfile = 1;
1115  if (!comment) break;
1116  }
1117  macro.close();
1118 
1119  if (!execute) {
1120  TString exname = exnam;
1121  if (!tempfile) {
1122  // We have a script that does NOT contain an unnamed macro,
1123  // so we can call the script compiler on it.
1124  exname += aclicMode;
1125  }
1126  exname += arguments;
1127  exname += io;
1128 
1129  TString tempbuf;
1130  if (tempfile) {
1131  tempbuf.Form(".x %s", exname.Data());
1132  } else {
1133  tempbuf.Form(".X%s %s", keep ? "k" : " ", exname.Data());
1134  }
1135  retval = gInterpreter->ProcessLineSynch(tempbuf,(TInterpreter::EErrorCode*)error);
1136  }
1137 
1138  delete [] exnam;
1139  return retval;
1140 }
1141 
1142 ////////////////////////////////////////////////////////////////////////////////
1143 /// Main application eventloop. Calls system dependent eventloop via gSystem.
1144 
1145 void TApplication::Run(Bool_t retrn)
1146 {
1147  SetReturnFromRun(retrn);
1148 
1149  fIsRunning = kTRUE;
1150 
1151  gSystem->Run();
1152  fIsRunning = kFALSE;
1153 }
1154 
1155 ////////////////////////////////////////////////////////////////////////////////
1156 /// Set the command to be executed after the system has been idle for
1157 /// idleTimeInSec seconds. Normally called via TROOT::Idle(...).
1158 
1159 void TApplication::SetIdleTimer(UInt_t idleTimeInSec, const char *command)
1160 {
1161  if (fIdleTimer) RemoveIdleTimer();
1162  fIdleCommand = command;
1163  fIdleTimer = new TIdleTimer(idleTimeInSec*1000);
1165 }
1166 
1167 ////////////////////////////////////////////////////////////////////////////////
1168 /// Remove idle timer. Normally called via TROOT::Idle(0).
1169 
1171 {
1172  if (fIdleTimer) {
1173  // timers are removed from the gSystem timer list by their dtor
1175  }
1176 }
1177 
1178 ////////////////////////////////////////////////////////////////////////////////
1179 /// Called when system starts idleing.
1180 
1182 {
1183  if (fIdleTimer) {
1184  fIdleTimer->Reset();
1186  }
1187 }
1188 
1189 ////////////////////////////////////////////////////////////////////////////////
1190 /// Called when system stops idleing.
1191 
1193 {
1194  if (fIdleTimer)
1196 }
1197 
1198 ////////////////////////////////////////////////////////////////////////////////
1199 /// What to do when tab is pressed. Re-implemented by TRint.
1200 /// See TTabCom::Hook() for meaning of return values.
1201 
1202 Int_t TApplication::TabCompletionHook(char* /*buf*/, int* /*pLoc*/, std::ostream& /*out*/)
1203 {
1204  return -1;
1205 }
1206 
1207 
1208 ////////////////////////////////////////////////////////////////////////////////
1209 /// Terminate the application by call TSystem::Exit() unless application has
1210 /// been told to return from Run(), by a call to SetReturnFromRun().
1211 
1212 void TApplication::Terminate(Int_t status)
1213 {
1214  Emit("Terminate(Int_t)", status);
1215 
1216  if (fReturnFromRun)
1217  gSystem->ExitLoop();
1218  else {
1219  //close TMemStat
1220  if (fUseMemstat) {
1221  ProcessLine("TMemStat::Close()");
1222  fUseMemstat = kFALSE;
1223  }
1224 
1225  gSystem->Exit(status);
1226  }
1227 }
1228 
1229 ////////////////////////////////////////////////////////////////////////////////
1230 /// Emit signal when a line has been processed.
1231 
1232 void TApplication::LineProcessed(const char *line)
1233 {
1234  Emit("LineProcessed(const char*)", line);
1235 }
1236 
1237 ////////////////////////////////////////////////////////////////////////////////
1238 /// Emit signal when console keyboard key was pressed.
1239 
1241 {
1242  Emit("KeyPressed(Int_t)", key);
1243 }
1244 
1245 ////////////////////////////////////////////////////////////////////////////////
1246 /// Emit signal when return key was pressed.
1247 
1248 void TApplication::ReturnPressed(char *text )
1249 {
1250  Emit("ReturnPressed(char*)", text);
1251 }
1252 
1253 ////////////////////////////////////////////////////////////////////////////////
1254 /// Set console echo mode:
1255 ///
1256 /// - mode = kTRUE - echo input symbols
1257 /// - mode = kFALSE - noecho input symbols
1258 
1260 {
1261 }
1262 
1263 ////////////////////////////////////////////////////////////////////////////////
1264 /// Static function used to create a default application environment.
1265 
1267 {
1269  // gApplication is set at the end of 'new TApplication.
1270  if (!gApplication) {
1271  char *a = StrDup("RootApp");
1272  char *b = StrDup("-b");
1273  char *argv[2];
1274  Int_t argc = 2;
1275  argv[0] = a;
1276  argv[1] = b;
1277  new TApplication("RootApp", &argc, argv, 0, 0);
1278  if (gDebug > 0)
1279  Printf("<TApplication::CreateApplication>: "
1280  "created default TApplication");
1281  delete [] a; delete [] b;
1283  }
1284 }
1285 
1286 ////////////////////////////////////////////////////////////////////////////////
1287 /// Static function used to attach to an existing remote application
1288 /// or to start one.
1289 
1290 TApplication *TApplication::Open(const char *url,
1291  Int_t debug, const char *script)
1292 {
1293  TApplication *ap = 0;
1294  TUrl nu(url);
1295  Int_t nnew = 0;
1296 
1297  // Look among the existing ones
1298  if (fgApplications) {
1299  TIter nxa(fgApplications);
1300  while ((ap = (TApplication *) nxa())) {
1301  TString apn(ap->ApplicationName());
1302  if (apn == url) {
1303  // Found matching application
1304  return ap;
1305  } else {
1306  // Check if same machine and user
1307  TUrl au(apn);
1308  if (strlen(au.GetUser()) > 0 && strlen(nu.GetUser()) > 0 &&
1309  !strcmp(au.GetUser(), nu.GetUser())) {
1310  if (!strncmp(au.GetHost(), nu.GetHost(), strlen(nu.GetHost())))
1311  // New session on a known machine
1312  nnew++;
1313  }
1314  }
1315  }
1316  } else {
1317  ::Error("TApplication::Open", "list of applications undefined - protocol error");
1318  return ap;
1319  }
1320 
1321  // If new session on a known machine pass the number as option
1322  if (nnew > 0) {
1323  nnew++;
1324  nu.SetOptions(Form("%d", nnew));
1325  }
1326 
1327  // Instantiate the TApplication object to be run
1328  TPluginHandler *h = 0;
1329  if ((h = gROOT->GetPluginManager()->FindHandler("TApplication","remote"))) {
1330  if (h->LoadPlugin() == 0) {
1331  ap = (TApplication *) h->ExecPlugin(3, nu.GetUrl(), debug, script);
1332  } else {
1333  ::Error("TApplication::Open", "failed to load plugin for TApplicationRemote");
1334  }
1335  } else {
1336  ::Error("TApplication::Open", "failed to find plugin for TApplicationRemote");
1337  }
1338 
1339  // Add to the list
1340  if (ap && !(ap->TestBit(kInvalidObject))) {
1341  fgApplications->Add(ap);
1342  gROOT->GetListOfBrowsables()->Add(ap, ap->ApplicationName());
1343  TIter next(gROOT->GetListOfBrowsers());
1344  TBrowser *b;
1345  while ((b = (TBrowser*) next()))
1346  b->Add(ap, ap->ApplicationName());
1347  gROOT->RefreshBrowsers();
1348  } else {
1349  SafeDelete(ap);
1350  ::Error("TApplication::Open",
1351  "TApplicationRemote for %s could not be instantiated", url);
1352  }
1353 
1354  // Done
1355  return ap;
1356 }
1357 
1358 ////////////////////////////////////////////////////////////////////////////////
1359 /// Static function used to close a remote application
1360 
1362 {
1363  if (app) {
1364  app->Terminate(0);
1365  fgApplications->Remove(app);
1366  gROOT->GetListOfBrowsables()->RecursiveRemove(app);
1367  TIter next(gROOT->GetListOfBrowsers());
1368  TBrowser *b;
1369  while ((b = (TBrowser*) next()))
1370  b->RecursiveRemove(app);
1371  gROOT->RefreshBrowsers();
1372  }
1373 }
1374 
1375 ////////////////////////////////////////////////////////////////////////////////
1376 /// Show available sessions
1377 
1378 void TApplication::ls(Option_t *opt) const
1379 {
1380  if (fgApplications) {
1381  TIter nxa(fgApplications);
1382  TApplication *a = 0;
1383  while ((a = (TApplication *) nxa())) {
1384  a->Print(opt);
1385  }
1386  } else {
1387  Print(opt);
1388  }
1389 }
1390 
1391 ////////////////////////////////////////////////////////////////////////////////
1392 /// Static method returning the list of available applications
1393 
1395 {
1396  return fgApplications;
1397 }
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.
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
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 KeyPressed(Int_t key)
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:854
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 ls(Option_t *option="") const
The ls function lists the contents of a class on stdout.
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
virtual void StartIdleing()
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 RemoveIdleTimer()
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:393
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
Basic string class.
Definition: TString.h:125
static void Close(TApplication *app)
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
#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 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.
#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 Long_t ProcessLine(const char *line, Bool_t sync=kFALSE, Int_t *error=0)
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 Int_t TabCompletionHook(char *buf, int *pLoc, std::ostream &out)
virtual ~TApplication()
TApplication dtor.
virtual void SetEchoMode(Bool_t mode)
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
static void CreateApplication()
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition: TString.cxx:2231
static TList * GetApplications()
virtual void ExitLoop()
Exit from event loop.
Definition: TSystem.cxx:400
XFontStruct * id
Definition: TGX11.cxx:108
static void CallEndOfProcessCleanups()
virtual void Run(Bool_t retrn=kFALSE)
R__EXTERN TGuiFactory * gGuiFactory
Definition: TGuiFactory.h:66
void Error(const char *location, const char *msgfmt,...)
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
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
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
static Long_t ExecuteFile(const char *file, Int_t *error=0, Bool_t keep=kFALSE)
virtual void ReturnPressed(char *text)
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
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
Handles synchronous and a-synchronous timer events.
Definition: TTimer.h:51
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
void Reset(Detail::TBranchProxy *x)
TString & String()
Definition: TObjString.h:49
static constexpr double ms
#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
void InitializeGraphics()
Initialize the graphics environment.
long Long_t
Definition: RtypesCore.h:50
virtual void SetIdleTimer(UInt_t idleTimeInSec, const char *command)
int Ssiz_t
Definition: RtypesCore.h:63
R__EXTERN ExceptionContext_t * gException
Definition: TException.h:74
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).
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
static constexpr double s
#define R__LOCKGUARD(mutex)
virtual Long_t ProcessFile(const char *file, Int_t *error=0, Bool_t keep=kFALSE)
TTimer * fIdleTimer
Definition: TApplication.h:70
virtual void Terminate(Int_t status=0)
char ** fArgv
Definition: TApplication.h:59
Bool_t IsNull() const
Definition: TString.h:383
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
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 void LineProcessed(const char *line)
const char * Data() const
Definition: TString.h:345
TApplication()
Default ctor. Can be used by classes deriving from TApplication.
virtual void StopIdleing()