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