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