Logo ROOT   6.14/05
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], "--web")) {
420  // the web mode is requested.
421  argv[i] = null;
422  ++i;
423  TString opt;
424  opt = argv[i];
425  if (opt.BeginsWith("-")) {
426  if (gROOT->IsBatch()) gROOT->SetWebDisplay("batch");
427  else gROOT->SetWebDisplay("");
428  } else {
429  argv[i] = null;
430  if (gROOT->IsBatch()) opt.Prepend("batch");
431  gROOT->SetWebDisplay(opt.Data());
432  }
433  } else if (!strcmp(argv[i], "-e")) {
434  argv[i] = null;
435  ++i;
436 
437  if ( i < *argc ) {
438  if (!fFiles) fFiles = new TObjArray;
439  TObjString *expr = new TObjString(argv[i]);
440  expr->SetBit(kExpression);
441  fFiles->Add(expr);
442  argv[i] = null;
443  } else {
444  Warning("GetOptions", "-e must be followed by an expression.");
445  }
446  } else if (!strcmp(argv[i], "--")) {
447  TObjString* macro = nullptr;
448  bool warnShown = false;
449 
450  if (fFiles) {
451  for (auto f: *fFiles) {
452  TObjString* file = dynamic_cast<TObjString*>(f);
453  if (!file) {
454  Error("GetOptions()", "Inconsistent file entry (not a TObjString)!");
455  f->Dump();
456  continue;
457  }
458 
459  if (file->TestBit(kExpression))
460  continue;
461  if (file->String().EndsWith(".root"))
462  continue;
463  if (file->String().Contains('('))
464  continue;
465 
466  if (macro && !warnShown && (warnShown = true))
467  Warning("GetOptions", "-- is used with several macros. "
468  "The arguments will be passed to the last one.");
469 
470  macro = file;
471  }
472  }
473 
474  if (macro) {
475  argv[i] = null;
476  ++i;
477  TString& str = macro->String();
478 
479  str += '(';
480  for (; i < *argc; i++) {
481  str += argv[i];
482  str += ',';
483  argv[i] = null;
484  }
485  str.EndsWith(",") ? str[str.Length() - 1] = ')' : str += ')';
486  } else {
487  Warning("GetOptions", "no macro to pass arguments to was provided. "
488  "Everything after the -- will be ignored.");
489  for (; i < *argc; i++)
490  argv[i] = null;
491  }
492  } else if (argv[i][0] != '-' && argv[i][0] != '+') {
493  Long64_t size;
494  Long_t id, flags, modtime;
495  char *arg = strchr(argv[i], '(');
496  if (arg) *arg = '\0';
497  char *dir = gSystem->ExpandPathName(argv[i]);
498  TUrl udir(dir, kTRUE);
499  // remove options and anchor to check the path
500  TString sfx = udir.GetFileAndOptions();
501  TString fln = udir.GetFile();
502  sfx.Replace(sfx.Index(fln), fln.Length(), "");
503  TString path = udir.GetFile();
504  if (strcmp(udir.GetProtocol(), "file")) {
505  path = udir.GetUrl();
506  path.Replace(path.Index(sfx), sfx.Length(), "");
507  }
508  // 'path' is the full URL without suffices (options and/or anchor)
509  if (arg) *arg = '(';
510  if (!arg && !gSystem->GetPathInfo(path.Data(), &id, &size, &flags, &modtime)) {
511  if ((flags & 2)) {
512  // if directory set it in fWorkDir
513  if (pwd == "") {
514  pwd = gSystem->WorkingDirectory();
515  fWorkDir = dir;
516  gSystem->ChangeDirectory(dir);
517  argv[i] = null;
518  } else if (!strcmp(gROOT->GetName(), "Rint")) {
519  Warning("GetOptions", "only one directory argument can be specified (%s)", dir);
520  }
521  } else if (size > 0) {
522  // if file add to list of files to be processed
523  if (!fFiles) fFiles = new TObjArray;
524  fFiles->Add(new TObjString(path.Data()));
525  argv[i] = null;
526  } else {
527  Warning("GetOptions", "file %s has size 0, skipping", dir);
528  }
529  } else {
530  if (TString(udir.GetFile()).EndsWith(".root")) {
531  if (!strcmp(udir.GetProtocol(), "file")) {
532  // file ending on .root but does not exist, likely a typo
533  // warn user if plain root...
534  if (!strcmp(gROOT->GetName(), "Rint"))
535  Warning("GetOptions", "file %s not found", dir);
536  } else {
537  // remote file, give it the benefit of the doubt and add it to list of files
538  if (!fFiles) fFiles = new TObjArray;
539  fFiles->Add(new TObjString(argv[i]));
540  argv[i] = null;
541  }
542  } else {
543  TString mode,fargs,io;
544  TString fname = gSystem->SplitAclicMode(dir,mode,fargs,io);
545  char *mac;
546  if ((mac = gSystem->Which(TROOT::GetMacroPath(), fname,
547  kReadPermission))) {
548  // if file add to list of files to be processed
549  if (!fFiles) fFiles = new TObjArray;
550  fFiles->Add(new TObjString(argv[i]));
551  argv[i] = null;
552  delete [] mac;
553  } else {
554  // only warn if we're plain root,
555  // other progs might have their own params
556  if (!strcmp(gROOT->GetName(), "Rint"))
557  Warning("GetOptions", "macro %s not found", fname.Data());
558  }
559  }
560  }
561  delete [] dir;
562  }
563  // ignore unknown options
564  }
565 
566  // go back to startup directory
567  if (pwd != "")
568  gSystem->ChangeDirectory(pwd);
569 
570  // remove handled arguments from argument array
571  j = 0;
572  for (i = 0; i < *argc; i++) {
573  if (strcmp(argv[i], "")) {
574  argv[j] = argv[i];
575  j++;
576  }
577  }
578 
579  *argc = j;
580 }
581 
582 ////////////////////////////////////////////////////////////////////////////////
583 /// Handle idle timeout. When this timer expires the registered idle command
584 /// will be executed by this routine and a signal will be emitted.
585 
587 {
588  if (!fIdleCommand.IsNull())
590 
591  Emit("HandleIdleTimer()");
592 }
593 
594 ////////////////////////////////////////////////////////////////////////////////
595 /// Handle exceptions (kSigBus, kSigSegmentationViolation,
596 /// kSigIllegalInstruction and kSigFloatingException) trapped in TSystem.
597 /// Specific TApplication implementations may want something different here.
598 
600 {
601  if (TROOT::Initialized()) {
602  if (gException) {
603  gInterpreter->RewindDictionary();
604  gInterpreter->ClearFileBusy();
605  }
606  if (fExitOnException == kExit)
607  gSystem->Exit(sig);
608  else if (fExitOnException == kAbort)
609  gSystem->Abort();
610  else
611  Throw(sig);
612  }
613  gSystem->Exit(sig);
614 }
615 
616 ////////////////////////////////////////////////////////////////////////////////
617 /// Set the exit on exception option. Setting this option determines what
618 /// happens in HandleException() in case an exception (kSigBus,
619 /// kSigSegmentationViolation, kSigIllegalInstruction or kSigFloatingException)
620 /// is trapped. Choices are: kDontExit (default), kExit or kAbort.
621 /// Returns the previous value.
622 
624 {
626  fExitOnException = opt;
627  return old;
628 }
629 
630 ////////////////////////////////////////////////////////////////////////////////
631 /// Print help on interpreter.
632 
633 void TApplication::Help(const char *line)
634 {
635  gInterpreter->ProcessLine(line);
636 
637  Printf("\nROOT special commands.");
638  Printf("===========================================================================");
639  Printf(" pwd : show current directory, pad and style");
640  Printf(" ls : list contents of current directory");
641  Printf(" which [file] : shows path of macro file");
642 }
643 
644 ////////////////////////////////////////////////////////////////////////////////
645 /// Load shared libs necessary for graphics. These libraries are only
646 /// loaded when gROOT->IsBatch() is kFALSE.
647 
649 {
650  if (gROOT->IsBatch()) return;
651 
652  TPluginHandler *h;
653  if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualPad")))
654  if (h->LoadPlugin() == -1)
655  return;
656 
657  TString name;
658  TString title1 = "ROOT interface to ";
659  TString nativex, title;
660  TString nativeg = "root";
661 
662 #ifdef R__WIN32
663  nativex = "win32gdk";
664  name = "Win32gdk";
665  title = title1 + "Win32gdk";
666 #elif defined(R__HAS_COCOA)
667  nativex = "quartz";
668  name = "quartz";
669  title = title1 + "Quartz";
670 #else
671  nativex = "x11";
672  name = "X11";
673  title = title1 + "X11";
674 #endif
675 
676  TString guiBackend(gEnv->GetValue("Gui.Backend", "native"));
677  guiBackend.ToLower();
678  if (guiBackend == "native") {
679  guiBackend = nativex;
680  } else {
681  name = guiBackend;
682  title = title1 + guiBackend;
683  }
684  TString guiFactory(gEnv->GetValue("Gui.Factory", "native"));
685  guiFactory.ToLower();
686  if (guiFactory == "native")
687  guiFactory = nativeg;
688 
689  if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualX", guiBackend))) {
690  if (h->LoadPlugin() == -1) {
691  gROOT->SetBatch(kTRUE);
692  return;
693  }
694  gVirtualX = (TVirtualX *) h->ExecPlugin(2, name.Data(), title.Data());
695  fgGraphInit = kTRUE;
696  }
697  if ((h = gROOT->GetPluginManager()->FindHandler("TGuiFactory", guiFactory))) {
698  if (h->LoadPlugin() == -1) {
699  gROOT->SetBatch(kTRUE);
700  return;
701  }
702  gGuiFactory = (TGuiFactory *) h->ExecPlugin(0);
703  }
704 }
705 
706 ////////////////////////////////////////////////////////////////////////////////
707 /// Switch to batch mode.
708 
710 {
711  gROOT->SetBatch();
714 #ifndef R__WIN32
715  if (gVirtualX != gGXBatch) delete gVirtualX;
716 #endif
718 }
719 
720 ////////////////////////////////////////////////////////////////////////////////
721 /// Parse the content of a line starting with ".R" (already stripped-off)
722 /// The format is
723 /// ~~~ {.cpp}
724 /// [user@]host[:dir] [-l user] [-d dbg] [script]
725 /// ~~~
726 /// The variable 'dir' is the remote directory to be used as working dir.
727 /// The username can be specified in two ways, "-l" having the priority
728 /// (as in ssh).
729 /// A 'dbg' value > 0 gives increasing verbosity.
730 /// The last argument 'script' allows to specify an alternative script to
731 /// be executed remotely to startup the session.
732 
734  TString &hostdir, TString &user,
735  Int_t &dbg, TString &script)
736 {
737  if (!ln || strlen(ln) <= 0)
738  return 0;
739 
740  Int_t rc = 0;
741  Bool_t isHostDir = kTRUE;
742  Bool_t isScript = kFALSE;
743  Bool_t isUser = kFALSE;
744  Bool_t isDbg = kFALSE;
745 
746  TString line(ln);
747  TString tkn;
748  Int_t from = 0;
749  while (line.Tokenize(tkn, from, " ")) {
750  if (tkn == "-l") {
751  // Next is a user name
752  isUser = kTRUE;
753  } else if (tkn == "-d") {
754  isDbg = kTRUE;
755  } else if (tkn == "-close") {
756  rc = 1;
757  } else if (tkn.BeginsWith("-")) {
758  ::Warning("TApplication::ParseRemoteLine","unknown option: %s", tkn.Data());
759  } else {
760  if (isUser) {
761  user = tkn;
762  isUser = kFALSE;
763  } else if (isDbg) {
764  dbg = tkn.Atoi();
765  isDbg = kFALSE;
766  } else if (isHostDir) {
767  hostdir = tkn;
768  hostdir.ReplaceAll(":","/");
769  isHostDir = kFALSE;
770  isScript = kTRUE;
771  } else if (isScript) {
772  // Add everything left
773  script = tkn;
774  script.Insert(0, "\"");
775  script += "\"";
776  isScript = kFALSE;
777  break;
778  }
779  }
780  }
781 
782  // Done
783  return rc;
784 }
785 
786 ////////////////////////////////////////////////////////////////////////////////
787 /// Process the content of a line starting with ".R" (already stripped-off)
788 /// The format is
789 /// ~~~ {.cpp}
790 /// [user@]host[:dir] [-l user] [-d dbg] [script] | [host] -close
791 /// ~~~
792 /// The variable 'dir' is the remote directory to be used as working dir.
793 /// The username can be specified in two ways, "-l" having the priority
794 /// (as in ssh).
795 /// A 'dbg' value > 0 gives increasing verbosity.
796 /// The last argument 'script' allows to specify an alternative script to
797 /// be executed remotely to startup the session.
798 
800 {
801  if (!line) return 0;
802 
803  if (!strncmp(line, "-?", 2) || !strncmp(line, "-h", 2) ||
804  !strncmp(line, "--help", 6)) {
805  Info("ProcessRemote", "remote session help:");
806  Printf(".R [user@]host[:dir] [-l user] [-d dbg] [[<]script] | [host] -close");
807  Printf("Create a ROOT session on the specified remote host.");
808  Printf("The variable \"dir\" is the remote directory to be used as working dir.");
809  Printf("The username can be specified in two ways, \"-l\" having the priority");
810  Printf("(as in ssh). A \"dbg\" value > 0 gives increasing verbosity.");
811  Printf("The last argument \"script\" allows to specify an alternative script to");
812  Printf("be executed remotely to startup the session, \"roots\" being");
813  Printf("the default. If the script is preceded by a \"<\" the script will be");
814  Printf("sourced, after which \"roots\" is executed. The sourced script can be ");
815  Printf("used to change the PATH and other variables, allowing an alternative");
816  Printf("\"roots\" script to be found.");
817  Printf("To close down a session do \".R host -close\".");
818  Printf("To switch between sessions do \".R host\", to switch to the local");
819  Printf("session do \".R\".");
820  Printf("To list all open sessions do \"gApplication->GetApplications()->Print()\".");
821  return 0;
822  }
823 
824  TString hostdir, user, script;
825  Int_t dbg = 0;
826  Int_t rc = ParseRemoteLine(line, hostdir, user, dbg, script);
827  if (hostdir.Length() <= 0) {
828  // Close the remote application if required
829  if (rc == 1) {
831  delete fAppRemote;
832  }
833  // Return to local run
834  fAppRemote = 0;
835  // Done
836  return 1;
837  } else if (rc == 1) {
838  // close an existing remote application
839  TApplication *ap = TApplication::Open(hostdir, 0, 0);
840  if (ap) {
842  delete ap;
843  }
844  }
845  // Attach or start a remote application
846  if (user.Length() > 0)
847  hostdir.Insert(0,Form("%s@", user.Data()));
848  const char *sc = (script.Length() > 0) ? script.Data() : 0;
849  TApplication *ap = TApplication::Open(hostdir, dbg, sc);
850  if (ap) {
851  fAppRemote = ap;
852  }
853 
854  // Done
855  return 1;
856 }
857 
858 namespace {
859  static int PrintFile(const char* filename) {
860  TString sFileName(filename);
861  gSystem->ExpandPathName(sFileName);
862  if (gSystem->AccessPathName(sFileName)) {
863  Error("ProcessLine()", "Cannot find file %s", filename);
864  return 1;
865  }
866  std::ifstream instr(sFileName);
867  TString content;
868  content.ReadFile(instr);
869  Printf("%s", content.Data());
870  return 0;
871  }
872 }
873 
874 ////////////////////////////////////////////////////////////////////////////////
875 /// Process a single command line, either a C++ statement or an interpreter
876 /// command starting with a ".".
877 /// Return the return value of the command cast to a long.
878 
880 {
881  if (!line || !*line) return 0;
882 
883  // If we are asked to go remote do it
884  if (!strncmp(line, ".R", 2)) {
885  Int_t n = 2;
886  while (*(line+n) == ' ')
887  n++;
888  return ProcessRemote(line+n, err);
889  }
890 
891  // Redirect, if requested
894  return fAppRemote->ProcessLine(line, err);
895  }
896 
897  if (!strncasecmp(line, ".qqqqqqq", 7)) {
898  gSystem->Abort();
899  } else if (!strncasecmp(line, ".qqqqq", 5)) {
900  Info("ProcessLine", "Bye... (try '.qqqqqqq' if still running)");
901  gSystem->Exit(1);
902  } else if (!strncasecmp(line, ".exit", 4) || !strncasecmp(line, ".quit", 2)) {
903  Terminate(0);
904  return 0;
905  }
906 
907  if (!strncmp(line, "?", 1) || !strncmp(line, ".help", 5)) {
908  Help(line);
909  return 1;
910  }
911 
912  if (!strncmp(line, ".demo", 5)) {
913  if (gROOT->IsBatch()) {
914  Error("ProcessLine", "Cannot show demos in batch mode!");
915  return 1;
916  }
917  ProcessLine(".x " + TROOT::GetTutorialDir() + "/demos.C");
918  return 0;
919  }
920 
921  if (!strncmp(line, ".license", 8)) {
922  return PrintFile(TROOT::GetDocDir() + "/LICENSE");
923  }
924 
925  if (!strncmp(line, ".credits", 8)) {
926  TString credits = TROOT::GetDocDir() + "/CREDITS";
927  if (gSystem->AccessPathName(credits, kReadPermission))
928  credits = TROOT::GetDocDir() + "/README/CREDITS";
929  return PrintFile(credits);
930  }
931 
932  if (!strncmp(line, ".pwd", 4)) {
933  if (gDirectory)
934  Printf("Current directory: %s", gDirectory->GetPath());
935  if (gPad)
936  Printf("Current pad: %s", gPad->GetName());
937  if (gStyle)
938  Printf("Current style: %s", gStyle->GetName());
939  return 1;
940  }
941 
942  if (!strncmp(line, ".ls", 3)) {
943  const char *opt = 0;
944  if (line[3]) opt = &line[3];
945  if (gDirectory) gDirectory->ls(opt);
946  return 1;
947  }
948 
949  if (!strncmp(line, ".which", 6)) {
950  char *fn = Strip(line+7);
951  char *s = strtok(fn, "+(");
952  char *mac = gSystem->Which(TROOT::GetMacroPath(), s, kReadPermission);
953  if (!mac)
954  Printf("No macro %s in path %s", s, TROOT::GetMacroPath());
955  else
956  Printf("%s", mac);
957  delete [] fn;
958  delete [] mac;
959  return mac ? 1 : 0;
960  }
961 
962  if (!strncmp(line, ".L", 2) || !strncmp(line, ".U", 2)) {
963  TString aclicMode;
964  TString arguments;
965  TString io;
966  TString fname = gSystem->SplitAclicMode(line+3, aclicMode, arguments, io);
967 
968  char *mac = gSystem->Which(TROOT::GetMacroPath(), fname, kReadPermission);
969  if (arguments.Length()) {
970  Warning("ProcessLine", "argument(s) \"%s\" ignored with .%c", arguments.Data(),
971  line[1]);
972  }
973  Long_t retval = 0;
974  if (!mac)
975  Error("ProcessLine", "macro %s not found in path %s", fname.Data(),
977  else {
978  TString cmd(line+1);
979  Ssiz_t posSpace = cmd.Index(' ');
980  if (posSpace == -1) cmd.Remove(1);
981  else cmd.Remove(posSpace);
982  TString tempbuf;
983  if (sync) {
984  tempbuf.Form(".%s %s%s%s", cmd.Data(), mac, aclicMode.Data(),io.Data());
985  retval = gInterpreter->ProcessLineSynch(tempbuf,
987  } else {
988  tempbuf.Form(".%s %s%s%s", cmd.Data(), mac, aclicMode.Data(),io.Data());
989  retval = gInterpreter->ProcessLine(tempbuf,
991  }
992  }
993 
994  delete [] mac;
995 
997 
998  return retval;
999  }
1000 
1001  if (!strncmp(line, ".X", 2) || !strncmp(line, ".x", 2)) {
1002  return ProcessFile(line+3, err, line[2] == 'k');
1003  }
1004 
1005  if (!strcmp(line, ".reset")) {
1006  // Do nothing, .reset disabled in CINT because too many side effects
1007  Printf("*** .reset not allowed, please use gROOT->Reset() ***");
1008  return 0;
1009 
1010 #if 0
1011  // delete the ROOT dictionary since CINT will destroy all objects
1012  // referenced by the dictionary classes (TClass et. al.)
1013  gROOT->GetListOfClasses()->Delete();
1014  // fall through
1015 #endif
1016  }
1017 
1018  if (sync)
1019  return gInterpreter->ProcessLineSynch(line, (TInterpreter::EErrorCode*)err);
1020  else
1021  return gInterpreter->ProcessLine(line, (TInterpreter::EErrorCode*)err);
1022 }
1023 
1024 ////////////////////////////////////////////////////////////////////////////////
1025 /// Process a file containing a C++ macro.
1026 
1028 {
1029  return ExecuteFile(file, error, keep);
1030 }
1031 
1032 ////////////////////////////////////////////////////////////////////////////////
1033 /// Execute a file containing a C++ macro (static method). Can be used
1034 /// while TApplication is not yet created.
1035 
1037 {
1038  static const Int_t kBufSize = 1024;
1039 
1040  if (!file || !*file) return 0;
1041 
1042  TString aclicMode;
1043  TString arguments;
1044  TString io;
1045  TString fname = gSystem->SplitAclicMode(file, aclicMode, arguments, io);
1046 
1047  char *exnam = gSystem->Which(TROOT::GetMacroPath(), fname, kReadPermission);
1048  if (!exnam) {
1049  ::Error("TApplication::ExecuteFile", "macro %s not found in path %s", fname.Data(),
1051  delete [] exnam;
1052  if (error)
1054  return 0;
1055  }
1056 
1057  ::std::ifstream macro(exnam, std::ios::in);
1058  if (!macro.good()) {
1059  ::Error("TApplication::ExecuteFile", "%s no such file", exnam);
1060  if (error)
1062  delete [] exnam;
1063  return 0;
1064  }
1065 
1066  char currentline[kBufSize];
1067  char dummyline[kBufSize];
1068  int tempfile = 0;
1069  int comment = 0;
1070  int ifndefc = 0;
1071  int ifdef = 0;
1072  char *s = 0;
1073  Bool_t execute = kFALSE;
1074  Long_t retval = 0;
1075 
1076  while (1) {
1077  bool res = (bool)macro.getline(currentline, kBufSize);
1078  if (macro.eof()) break;
1079  if (!res) {
1080  // Probably only read kBufSize, let's ignore the remainder of
1081  // the line.
1082  macro.clear();
1083  while (!macro.getline(dummyline, kBufSize) && !macro.eof()) {
1084  macro.clear();
1085  }
1086  }
1087  s = currentline;
1088  while (s && (*s == ' ' || *s == '\t')) s++; // strip-off leading blanks
1089 
1090  // very simple minded pre-processor parsing, only works in case macro file
1091  // starts with "#ifndef __CINT__". In that case everything till next
1092  // "#else" or "#endif" will be skipped.
1093  if (*s == '#') {
1094  char *cs = Compress(currentline);
1095  if (strstr(cs, "#ifndef__CINT__") ||
1096  strstr(cs, "#if!defined(__CINT__)"))
1097  ifndefc = 1;
1098  else if (ifndefc && (strstr(cs, "#ifdef") || strstr(cs, "#ifndef") ||
1099  strstr(cs, "#ifdefined") || strstr(cs, "#if!defined")))
1100  ifdef++;
1101  else if (ifndefc && strstr(cs, "#endif")) {
1102  if (ifdef)
1103  ifdef--;
1104  else
1105  ifndefc = 0;
1106  } else if (ifndefc && !ifdef && strstr(cs, "#else"))
1107  ifndefc = 0;
1108  delete [] cs;
1109  }
1110  if (!*s || *s == '#' || ifndefc || !strncmp(s, "//", 2)) continue;
1111 
1112  if (!comment && (!strncmp(s, ".X", 2) || !strncmp(s, ".x", 2))) {
1113  retval = ExecuteFile(s+3);
1114  execute = kTRUE;
1115  continue;
1116  }
1117 
1118  if (!strncmp(s, "/*", 2)) comment = 1;
1119  if (comment) {
1120  // handle slightly more complex cases like: /* */ /*
1121 again:
1122  s = strstr(s, "*/");
1123  if (s) {
1124  comment = 0;
1125  s += 2;
1126 
1127  while (s && (*s == ' ' || *s == '\t')) s++; // strip-off leading blanks
1128  if (!*s) continue;
1129  if (!strncmp(s, "//", 2)) continue;
1130  if (!strncmp(s, "/*", 2)) {
1131  comment = 1;
1132  goto again;
1133  }
1134  }
1135  }
1136  if (!comment && *s == '{') tempfile = 1;
1137  if (!comment) break;
1138  }
1139  macro.close();
1140 
1141  if (!execute) {
1142  TString exname = exnam;
1143  if (!tempfile) {
1144  // We have a script that does NOT contain an unnamed macro,
1145  // so we can call the script compiler on it.
1146  exname += aclicMode;
1147  }
1148  exname += arguments;
1149  exname += io;
1150 
1151  TString tempbuf;
1152  if (tempfile) {
1153  tempbuf.Form(".x %s", exname.Data());
1154  } else {
1155  tempbuf.Form(".X%s %s", keep ? "k" : " ", exname.Data());
1156  }
1157  retval = gInterpreter->ProcessLineSynch(tempbuf,(TInterpreter::EErrorCode*)error);
1158  }
1159 
1160  delete [] exnam;
1161  return retval;
1162 }
1163 
1164 ////////////////////////////////////////////////////////////////////////////////
1165 /// Main application eventloop. Calls system dependent eventloop via gSystem.
1166 
1168 {
1169  SetReturnFromRun(retrn);
1170 
1171  fIsRunning = kTRUE;
1172 
1173  gSystem->Run();
1174  fIsRunning = kFALSE;
1175 }
1176 
1177 ////////////////////////////////////////////////////////////////////////////////
1178 /// Set the command to be executed after the system has been idle for
1179 /// idleTimeInSec seconds. Normally called via TROOT::Idle(...).
1180 
1181 void TApplication::SetIdleTimer(UInt_t idleTimeInSec, const char *command)
1182 {
1183  if (fIdleTimer) RemoveIdleTimer();
1184  fIdleCommand = command;
1185  fIdleTimer = new TIdleTimer(idleTimeInSec*1000);
1187 }
1188 
1189 ////////////////////////////////////////////////////////////////////////////////
1190 /// Remove idle timer. Normally called via TROOT::Idle(0).
1191 
1193 {
1194  if (fIdleTimer) {
1195  // timers are removed from the gSystem timer list by their dtor
1197  }
1198 }
1199 
1200 ////////////////////////////////////////////////////////////////////////////////
1201 /// Called when system starts idleing.
1202 
1204 {
1205  if (fIdleTimer) {
1206  fIdleTimer->Reset();
1208  }
1209 }
1210 
1211 ////////////////////////////////////////////////////////////////////////////////
1212 /// Called when system stops idleing.
1213 
1215 {
1216  if (fIdleTimer)
1218 }
1219 
1220 ////////////////////////////////////////////////////////////////////////////////
1221 /// What to do when tab is pressed. Re-implemented by TRint.
1222 /// See TTabCom::Hook() for meaning of return values.
1223 
1224 Int_t TApplication::TabCompletionHook(char* /*buf*/, int* /*pLoc*/, std::ostream& /*out*/)
1225 {
1226  return -1;
1227 }
1228 
1229 
1230 ////////////////////////////////////////////////////////////////////////////////
1231 /// Terminate the application by call TSystem::Exit() unless application has
1232 /// been told to return from Run(), by a call to SetReturnFromRun().
1233 
1235 {
1236  Emit("Terminate(Int_t)", status);
1237 
1238  if (fReturnFromRun)
1239  gSystem->ExitLoop();
1240  else {
1241  //close TMemStat
1242  if (fUseMemstat) {
1243  ProcessLine("TMemStat::Close()");
1244  fUseMemstat = kFALSE;
1245  }
1246 
1247  gSystem->Exit(status);
1248  }
1249 }
1250 
1251 ////////////////////////////////////////////////////////////////////////////////
1252 /// Emit signal when a line has been processed.
1253 
1255 {
1256  Emit("LineProcessed(const char*)", line);
1257 }
1258 
1259 ////////////////////////////////////////////////////////////////////////////////
1260 /// Emit signal when console keyboard key was pressed.
1261 
1263 {
1264  Emit("KeyPressed(Int_t)", key);
1265 }
1266 
1267 ////////////////////////////////////////////////////////////////////////////////
1268 /// Emit signal when return key was pressed.
1269 
1271 {
1272  Emit("ReturnPressed(char*)", text);
1273 }
1274 
1275 ////////////////////////////////////////////////////////////////////////////////
1276 /// Set console echo mode:
1277 ///
1278 /// - mode = kTRUE - echo input symbols
1279 /// - mode = kFALSE - noecho input symbols
1280 
1282 {
1283 }
1284 
1285 ////////////////////////////////////////////////////////////////////////////////
1286 /// Static function used to create a default application environment.
1287 
1289 {
1291  // gApplication is set at the end of 'new TApplication.
1292  if (!gApplication) {
1293  char *a = StrDup("RootApp");
1294  char *b = StrDup("-b");
1295  char *argv[2];
1296  Int_t argc = 2;
1297  argv[0] = a;
1298  argv[1] = b;
1299  new TApplication("RootApp", &argc, argv, 0, 0);
1300  if (gDebug > 0)
1301  Printf("<TApplication::CreateApplication>: "
1302  "created default TApplication");
1303  delete [] a; delete [] b;
1304  gApplication->SetBit(kDefaultApplication);
1305  }
1306 }
1307 
1308 ////////////////////////////////////////////////////////////////////////////////
1309 /// Static function used to attach to an existing remote application
1310 /// or to start one.
1311 
1313  Int_t debug, const char *script)
1314 {
1315  TApplication *ap = 0;
1316  TUrl nu(url);
1317  Int_t nnew = 0;
1318 
1319  // Look among the existing ones
1320  if (fgApplications) {
1321  TIter nxa(fgApplications);
1322  while ((ap = (TApplication *) nxa())) {
1323  TString apn(ap->ApplicationName());
1324  if (apn == url) {
1325  // Found matching application
1326  return ap;
1327  } else {
1328  // Check if same machine and user
1329  TUrl au(apn);
1330  if (strlen(au.GetUser()) > 0 && strlen(nu.GetUser()) > 0 &&
1331  !strcmp(au.GetUser(), nu.GetUser())) {
1332  if (!strncmp(au.GetHost(), nu.GetHost(), strlen(nu.GetHost())))
1333  // New session on a known machine
1334  nnew++;
1335  }
1336  }
1337  }
1338  } else {
1339  ::Error("TApplication::Open", "list of applications undefined - protocol error");
1340  return ap;
1341  }
1342 
1343  // If new session on a known machine pass the number as option
1344  if (nnew > 0) {
1345  nnew++;
1346  nu.SetOptions(Form("%d", nnew));
1347  }
1348 
1349  // Instantiate the TApplication object to be run
1350  TPluginHandler *h = 0;
1351  if ((h = gROOT->GetPluginManager()->FindHandler("TApplication","remote"))) {
1352  if (h->LoadPlugin() == 0) {
1353  ap = (TApplication *) h->ExecPlugin(3, nu.GetUrl(), debug, script);
1354  } else {
1355  ::Error("TApplication::Open", "failed to load plugin for TApplicationRemote");
1356  }
1357  } else {
1358  ::Error("TApplication::Open", "failed to find plugin for TApplicationRemote");
1359  }
1360 
1361  // Add to the list
1362  if (ap && !(ap->TestBit(kInvalidObject))) {
1363  fgApplications->Add(ap);
1364  gROOT->GetListOfBrowsables()->Add(ap, ap->ApplicationName());
1365  TIter next(gROOT->GetListOfBrowsers());
1366  TBrowser *b;
1367  while ((b = (TBrowser*) next()))
1368  b->Add(ap, ap->ApplicationName());
1369  gROOT->RefreshBrowsers();
1370  } else {
1371  SafeDelete(ap);
1372  ::Error("TApplication::Open",
1373  "TApplicationRemote for %s could not be instantiated", url);
1374  }
1375 
1376  // Done
1377  return ap;
1378 }
1379 
1380 ////////////////////////////////////////////////////////////////////////////////
1381 /// Static function used to close a remote application
1382 
1384 {
1385  if (app) {
1386  app->Terminate(0);
1387  fgApplications->Remove(app);
1388  gROOT->GetListOfBrowsables()->RecursiveRemove(app);
1389  TIter next(gROOT->GetListOfBrowsers());
1390  TBrowser *b;
1391  while ((b = (TBrowser*) next()))
1392  b->RecursiveRemove(app);
1393  gROOT->RefreshBrowsers();
1394  }
1395 }
1396 
1397 ////////////////////////////////////////////////////////////////////////////////
1398 /// Show available sessions
1399 
1400 void TApplication::ls(Option_t *opt) const
1401 {
1402  if (fgApplications) {
1403  TIter nxa(fgApplications);
1404  TApplication *a = 0;
1405  while ((a = (TApplication *) nxa())) {
1406  a->Print(opt);
1407  }
1408  } else {
1409  Print(opt);
1410  }
1411 }
1412 
1413 ////////////////////////////////////////////////////////////////////////////////
1414 /// Static method returning the list of available applications
1415 
1417 {
1418  return fgApplications;
1419 }
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:3128
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:3065
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:2479
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:4138
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:687
R__EXTERN TStyle * gStyle
Definition: TStyle.h:406
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
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:410
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:634
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:131
TSignalHandler * fSigHandler
Definition: TApplication.h:71
#define f(i)
Definition: RSha256.hxx:104
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1100
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:527
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
TString & Prepend(const char *cs)
Definition: TString.h:656
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:644
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:677
static const char * GetMacroPath()
Get macro search path. Static utility function.
Definition: TROOT.cxx:2743
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
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:2840
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:3028
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition: TString.cxx:2152
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:576
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:297
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition: TString.h:610
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:2264
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:405
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:2429
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 h(i)
Definition: RSha256.hxx:106
#define Printf
Definition: TGeoToOCC.h:18
char * StrDup(const char *str)
Duplicate the string str.
Definition: TString.cxx:2465
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.
#define SafeDelete(p)
Definition: RConfig.h:529
TString & Remove(Ssiz_t pos)
Definition: TString.h:668
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:2172
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:546
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:619
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:402
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:1896
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:1077
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:364
TApplication()
Default ctor. Can be used by classes deriving from TApplication.