Logo ROOT   6.10/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",
280  char *ttfont = gSystem->Which(ttpath, "arialbd.ttf", kReadPermission);
281  // Check for use of DFSG - fonts
282  if (!ttfont)
283  ttfont = gSystem->Which(ttpath, "FreeSansBold.ttf", kReadPermission);
284 
285 #if !defined(R__WIN32)
286  if (!gROOT->IsBatch() && !strcmp(gVirtualX->GetName(), "X11") &&
287  ttfont && gEnv->GetValue("Root.UseTTFonts", 1)) {
288  if (gClassTable->GetDict("TGX11TTF")) {
289  // in principle we should not have linked anything against libGX11TTF
290  // but with ACLiC this can happen, initialize TGX11TTF by hand
291  // (normally this is done by the static library initializer)
292  ProcessLine("TGX11TTF::Activate();");
293  } else {
294  TPluginHandler *h;
295  if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualX", "x11ttf")))
296  if (h->LoadPlugin() == -1)
297  Info("InitializeGraphics", "no TTF support");
298  }
299  }
300 #endif
301  delete [] ttfont;
302 
303  // Create WM dependent application environment
304  if (fAppImp)
305  delete fAppImp;
307  if (!fAppImp) {
308  MakeBatch();
310  }
311 
312  // Create the canvas colors early so they are allocated before
313  // any color table expensive bitmaps get allocated in GUI routines (like
314  // creation of XPM bitmaps).
316 
317  // Hook for further initializing the WM dependent application environment
318  Init();
319 
320  // Set default screen factor (if not disabled in rc file)
321  if (gEnv->GetValue("Canvas.UseScreenFactor", 1)) {
322  Int_t x, y;
323  UInt_t w, h;
324  if (gVirtualX) {
325  gVirtualX->GetGeometry(-1, x, y, w, h);
326  if (h > 0 && h < 1000) gStyle->SetScreenFactor(0.0011*h);
327  }
328  }
329 #endif // iOS
330 }
331 
332 ////////////////////////////////////////////////////////////////////////////////
333 /// Clear list containing macro files passed as program arguments.
334 /// This method is called from TRint::Run() to ensure that the macro
335 /// files are only executed the first time Run() is called.
336 
338 {
339  if (fFiles) {
340  fFiles->Delete();
342  }
343 }
344 
345 ////////////////////////////////////////////////////////////////////////////////
346 /// Return specified argument.
347 
348 char *TApplication::Argv(Int_t index) const
349 {
350  if (fArgv) {
351  if (index >= fArgc) {
352  Error("Argv", "index (%d) >= number of arguments (%d)", index, fArgc);
353  return 0;
354  }
355  return fArgv[index];
356  }
357  return 0;
358 }
359 
360 ////////////////////////////////////////////////////////////////////////////////
361 /// Get and handle command line options. Arguments handled are removed
362 /// from the argument array. The following arguments are handled:
363 ///
364 /// - b : run in batch mode without graphics
365 /// - x : exit on exception
366 /// - e expression: request execution of the given C++ expression.
367 /// - n : do not execute logon and logoff macros as specified in .rootrc
368 /// - q : exit after processing command line macro files
369 /// - l : do not show splash screen
370 ///
371 /// The last three options are only relevant in conjunction with TRint.
372 /// The following help and info arguments are supported:
373 ///
374 /// - ? : print usage
375 /// - h : print usage
376 /// - -help : print usage
377 /// - config : print ./configure options
378 /// - memstat : run with memory usage monitoring
379 ///
380 /// In addition to the above options the arguments that are not options,
381 /// i.e. they don't start with - or + are treated as follows (and also removed
382 /// from the argument array):
383 ///
384 /// - `<dir>` is considered the desired working directory and available
385 /// via WorkingDirectory(), if more than one dir is specified the
386 /// first one will prevail
387 /// - `<file>` if the file exists its added to the InputFiles() list
388 /// - `<file>.root` are considered ROOT files and added to the InputFiles() list,
389 /// the file may be a remote file url
390 /// - `<macro>.C` are considered ROOT macros and also added to the InputFiles() list
391 ///
392 /// In TRint we set the working directory to the `<dir>`, the ROOT files are
393 /// connected, and the macros are executed. If your main TApplication is not
394 /// TRint you have to decide yourself what to do with these options.
395 /// All specified arguments (also the ones removed) can always be retrieved
396 /// via the TApplication::Argv() method.
397 
398 void TApplication::GetOptions(Int_t *argc, char **argv)
399 {
400  static char null[1] = { "" };
401 
402  fNoLog = kFALSE;
403  fQuit = kFALSE;
404  fFiles = 0;
405 
406  if (!argc)
407  return;
408 
409  int i, j;
410  TString pwd;
411 
412  for (i = 1; i < *argc; i++) {
413  if (!strcmp(argv[i], "-?") || !strncmp(argv[i], "-h", 2) ||
414  !strncmp(argv[i], "--help", 6)) {
415  fprintf(stderr, "Usage: %s [-l] [-b] [-n] [-q] [dir] [[file:]data.root] [file1.C ... fileN.C]\n", argv[0]);
416  fprintf(stderr, "Options:\n");
417  fprintf(stderr, " -b : run in batch mode without graphics\n");
418  fprintf(stderr, " -x : exit on exception\n");
419  fprintf(stderr, " -e expression: request execution of the given C++ expression\n");
420  fprintf(stderr, " -n : do not execute logon and logoff macros as specified in .rootrc\n");
421  fprintf(stderr, " -q : exit after processing command line macro files\n");
422  fprintf(stderr, " -l : do not show splash screen\n");
423  fprintf(stderr, " dir : if dir is a valid directory cd to it before executing\n");
424  fprintf(stderr, "\n");
425  fprintf(stderr, " -? : print usage\n");
426  fprintf(stderr, " -h : print usage\n");
427  fprintf(stderr, " --help : print usage\n");
428  fprintf(stderr, " -config : print ./configure options\n");
429  fprintf(stderr, " -memstat : run with memory usage monitoring\n");
430  fprintf(stderr, "\n");
431  Terminate(0);
432  } else if (!strcmp(argv[i], "-config")) {
433  fprintf(stderr, "ROOT ./configure options:\n%s\n", gROOT->GetConfigOptions());
434  Terminate(0);
435  } else if (!strcmp(argv[i], "-memstat")) {
436  fUseMemstat = kTRUE;
437  argv[i] = null;
438  } else if (!strcmp(argv[i], "-b")) {
439  MakeBatch();
440  argv[i] = null;
441  } else if (!strcmp(argv[i], "-n")) {
442  fNoLog = kTRUE;
443  argv[i] = null;
444  } else if (!strcmp(argv[i], "-q")) {
445  fQuit = kTRUE;
446  argv[i] = null;
447  } else if (!strcmp(argv[i], "-l")) {
448  // used by front-end program to not display splash screen
449  fNoLogo = kTRUE;
450  argv[i] = null;
451  } else if (!strcmp(argv[i], "-x")) {
453  argv[i] = null;
454  } else if (!strcmp(argv[i], "-splash")) {
455  // used when started by front-end program to signal that
456  // splash screen can be popped down (TRint::PrintLogo())
457  argv[i] = null;
458  } else if (!strcmp(argv[i], "-e")) {
459  argv[i] = null;
460  ++i;
461 
462  if ( i < *argc ) {
463  if (!fFiles) fFiles = new TObjArray;
464  TObjString *expr = new TObjString(argv[i]);
465  expr->SetBit(kExpression);
466  fFiles->Add(expr);
467  argv[i] = null;
468  } else {
469  Warning("GetOptions", "-e must be followed by an expression.");
470  }
471 
472  } else if (argv[i][0] != '-' && argv[i][0] != '+') {
473  Long64_t size;
474  Long_t id, flags, modtime;
475  char *arg = strchr(argv[i], '(');
476  if (arg) *arg = '\0';
477  char *dir = gSystem->ExpandPathName(argv[i]);
478  TUrl udir(dir, kTRUE);
479  // remove options and anchor to check the path
480  TString sfx = udir.GetFileAndOptions();
481  TString fln = udir.GetFile();
482  sfx.Replace(sfx.Index(fln), fln.Length(), "");
483  TString path = udir.GetFile();
484  if (strcmp(udir.GetProtocol(), "file")) {
485  path = udir.GetUrl();
486  path.Replace(path.Index(sfx), sfx.Length(), "");
487  }
488  // 'path' is the full URL without suffices (options and/or anchor)
489  if (arg) *arg = '(';
490  if (!arg && !gSystem->GetPathInfo(path.Data(), &id, &size, &flags, &modtime)) {
491  if ((flags & 2)) {
492  // if directory set it in fWorkDir
493  if (pwd == "") {
494  pwd = gSystem->WorkingDirectory();
495  fWorkDir = dir;
496  gSystem->ChangeDirectory(dir);
497  argv[i] = null;
498  } else if (!strcmp(gROOT->GetName(), "Rint")) {
499  Warning("GetOptions", "only one directory argument can be specified (%s)", dir);
500  }
501  } else if (size > 0) {
502  // if file add to list of files to be processed
503  if (!fFiles) fFiles = new TObjArray;
504  fFiles->Add(new TObjString(path.Data()));
505  argv[i] = null;
506  } else {
507  Warning("GetOptions", "file %s has size 0, skipping", dir);
508  }
509  } else {
510  if (TString(udir.GetFile()).EndsWith(".root")) {
511  if (!strcmp(udir.GetProtocol(), "file")) {
512  // file ending on .root but does not exist, likely a typo
513  // warn user if plain root...
514  if (!strcmp(gROOT->GetName(), "Rint"))
515  Warning("GetOptions", "file %s not found", dir);
516  } else {
517  // remote file, give it the benefit of the doubt and add it to list of files
518  if (!fFiles) fFiles = new TObjArray;
519  fFiles->Add(new TObjString(argv[i]));
520  argv[i] = null;
521  }
522  } else {
523  TString mode,fargs,io;
524  TString fname = gSystem->SplitAclicMode(dir,mode,fargs,io);
525  char *mac;
526  if ((mac = gSystem->Which(TROOT::GetMacroPath(), fname,
527  kReadPermission))) {
528  // if file add to list of files to be processed
529  if (!fFiles) fFiles = new TObjArray;
530  fFiles->Add(new TObjString(argv[i]));
531  argv[i] = null;
532  delete [] mac;
533  } else {
534  // only warn if we're plain root,
535  // other progs might have their own params
536  if (!strcmp(gROOT->GetName(), "Rint"))
537  Warning("GetOptions", "macro %s not found", fname.Data());
538  }
539  }
540  }
541  delete [] dir;
542  }
543  // ignore unknown options
544  }
545 
546  // go back to startup directory
547  if (pwd != "")
548  gSystem->ChangeDirectory(pwd);
549 
550  // remove handled arguments from argument array
551  j = 0;
552  for (i = 0; i < *argc; i++) {
553  if (strcmp(argv[i], "")) {
554  argv[j] = argv[i];
555  j++;
556  }
557  }
558 
559  *argc = j;
560 }
561 
562 ////////////////////////////////////////////////////////////////////////////////
563 /// Handle idle timeout. When this timer expires the registered idle command
564 /// will be executed by this routine and a signal will be emitted.
565 
567 {
568  if (!fIdleCommand.IsNull())
570 
571  Emit("HandleIdleTimer()");
572 }
573 
574 ////////////////////////////////////////////////////////////////////////////////
575 /// Handle exceptions (kSigBus, kSigSegmentationViolation,
576 /// kSigIllegalInstruction and kSigFloatingException) trapped in TSystem.
577 /// Specific TApplication implementations may want something different here.
578 
580 {
581  if (TROOT::Initialized()) {
582  if (gException) {
583  gInterpreter->RewindDictionary();
584  gInterpreter->ClearFileBusy();
585  }
586  if (fExitOnException == kExit)
587  gSystem->Exit(sig);
588  else if (fExitOnException == kAbort)
589  gSystem->Abort();
590  else
591  Throw(sig);
592  }
593  gSystem->Exit(sig);
594 }
595 
596 ////////////////////////////////////////////////////////////////////////////////
597 /// Set the exit on exception option. Setting this option determines what
598 /// happens in HandleException() in case an exception (kSigBus,
599 /// kSigSegmentationViolation, kSigIllegalInstruction or kSigFloatingException)
600 /// is trapped. Choices are: kDontExit (default), kExit or kAbort.
601 /// Returns the previous value.
602 
604 {
606  fExitOnException = opt;
607  return old;
608 }
609 
610 ////////////////////////////////////////////////////////////////////////////////
611 /// Print help on interpreter.
612 
613 void TApplication::Help(const char *line)
614 {
615  gInterpreter->ProcessLine(line);
616 
617  Printf("\nROOT special commands.");
618  Printf("===========================================================================");
619  Printf(" pwd : show current directory, pad and style");
620  Printf(" ls : list contents of current directory");
621  Printf(" which [file] : shows path of macro file");
622 }
623 
624 ////////////////////////////////////////////////////////////////////////////////
625 /// Load shared libs necessary for graphics. These libraries are only
626 /// loaded when gROOT->IsBatch() is kFALSE.
627 
629 {
630  if (gROOT->IsBatch()) return;
631 
632  TPluginHandler *h;
633  if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualPad")))
634  if (h->LoadPlugin() == -1)
635  return;
636 
637  TString name;
638  TString title1 = "ROOT interface to ";
639  TString nativex, title;
640  TString nativeg = "root";
641 
642 #ifdef R__WIN32
643  nativex = "win32gdk";
644  name = "Win32gdk";
645  title = title1 + "Win32gdk";
646 #elif defined(R__HAS_COCOA)
647  nativex = "quartz";
648  name = "quartz";
649  title = title1 + "Quartz";
650 #else
651  nativex = "x11";
652  name = "X11";
653  title = title1 + "X11";
654 #endif
655 
656  TString guiBackend(gEnv->GetValue("Gui.Backend", "native"));
657  guiBackend.ToLower();
658  if (guiBackend == "native") {
659  guiBackend = nativex;
660  } else {
661  name = guiBackend;
662  title = title1 + guiBackend;
663  }
664  TString guiFactory(gEnv->GetValue("Gui.Factory", "native"));
665  guiFactory.ToLower();
666  if (guiFactory == "native")
667  guiFactory = nativeg;
668 
669  if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualX", guiBackend))) {
670  if (h->LoadPlugin() == -1) {
671  gROOT->SetBatch(kTRUE);
672  return;
673  }
674  gVirtualX = (TVirtualX *) h->ExecPlugin(2, name.Data(), title.Data());
675  fgGraphInit = kTRUE;
676  }
677  if ((h = gROOT->GetPluginManager()->FindHandler("TGuiFactory", guiFactory))) {
678  if (h->LoadPlugin() == -1) {
679  gROOT->SetBatch(kTRUE);
680  return;
681  }
682  gGuiFactory = (TGuiFactory *) h->ExecPlugin(0);
683  }
684 }
685 
686 ////////////////////////////////////////////////////////////////////////////////
687 /// Switch to batch mode.
688 
690 {
691  gROOT->SetBatch();
694 #ifndef R__WIN32
695  if (gVirtualX != gGXBatch) delete gVirtualX;
696 #endif
698 }
699 
700 ////////////////////////////////////////////////////////////////////////////////
701 /// Parse the content of a line starting with ".R" (already stripped-off)
702 /// The format is
703 /// ~~~ {.cpp}
704 /// [user@]host[:dir] [-l user] [-d dbg] [script]
705 /// ~~~
706 /// The variable 'dir' is the remote directory to be used as working dir.
707 /// The username can be specified in two ways, "-l" having the priority
708 /// (as in ssh).
709 /// A 'dbg' value > 0 gives increasing verbosity.
710 /// The last argument 'script' allows to specify an alternative script to
711 /// be executed remotely to startup the session.
712 
714  TString &hostdir, TString &user,
715  Int_t &dbg, TString &script)
716 {
717  if (!ln || strlen(ln) <= 0)
718  return 0;
719 
720  Int_t rc = 0;
721  Bool_t isHostDir = kTRUE;
722  Bool_t isScript = kFALSE;
723  Bool_t isUser = kFALSE;
724  Bool_t isDbg = kFALSE;
725 
726  TString line(ln);
727  TString tkn;
728  Int_t from = 0;
729  while (line.Tokenize(tkn, from, " ")) {
730  if (tkn == "-l") {
731  // Next is a user name
732  isUser = kTRUE;
733  } else if (tkn == "-d") {
734  isDbg = kTRUE;
735  } else if (tkn == "-close") {
736  rc = 1;
737  } else if (tkn.BeginsWith("-")) {
738  ::Warning("TApplication::ParseRemoteLine","unknown option: %s", tkn.Data());
739  } else {
740  if (isUser) {
741  user = tkn;
742  isUser = kFALSE;
743  } else if (isDbg) {
744  dbg = tkn.Atoi();
745  isDbg = kFALSE;
746  } else if (isHostDir) {
747  hostdir = tkn;
748  hostdir.ReplaceAll(":","/");
749  isHostDir = kFALSE;
750  isScript = kTRUE;
751  } else if (isScript) {
752  // Add everything left
753  script = tkn;
754  script.Insert(0, "\"");
755  script += "\"";
756  isScript = kFALSE;
757  break;
758  }
759  }
760  }
761 
762  // Done
763  return rc;
764 }
765 
766 ////////////////////////////////////////////////////////////////////////////////
767 /// Process the content of a line starting with ".R" (already stripped-off)
768 /// The format is
769 /// ~~~ {.cpp}
770 /// [user@]host[:dir] [-l user] [-d dbg] [script] | [host] -close
771 /// ~~~
772 /// The variable 'dir' is the remote directory to be used as working dir.
773 /// The username can be specified in two ways, "-l" having the priority
774 /// (as in ssh).
775 /// A 'dbg' value > 0 gives increasing verbosity.
776 /// The last argument 'script' allows to specify an alternative script to
777 /// be executed remotely to startup the session.
778 
780 {
781  if (!line) return 0;
782 
783  if (!strncmp(line, "-?", 2) || !strncmp(line, "-h", 2) ||
784  !strncmp(line, "--help", 6)) {
785  Info("ProcessRemote", "remote session help:");
786  Printf(".R [user@]host[:dir] [-l user] [-d dbg] [[<]script] | [host] -close");
787  Printf("Create a ROOT session on the specified remote host.");
788  Printf("The variable \"dir\" is the remote directory to be used as working dir.");
789  Printf("The username can be specified in two ways, \"-l\" having the priority");
790  Printf("(as in ssh). A \"dbg\" value > 0 gives increasing verbosity.");
791  Printf("The last argument \"script\" allows to specify an alternative script to");
792  Printf("be executed remotely to startup the session, \"roots\" being");
793  Printf("the default. If the script is preceded by a \"<\" the script will be");
794  Printf("sourced, after which \"roots\" is executed. The sourced script can be ");
795  Printf("used to change the PATH and other variables, allowing an alternative");
796  Printf("\"roots\" script to be found.");
797  Printf("To close down a session do \".R host -close\".");
798  Printf("To switch between sessions do \".R host\", to switch to the local");
799  Printf("session do \".R\".");
800  Printf("To list all open sessions do \"gApplication->GetApplications()->Print()\".");
801  return 0;
802  }
803 
804  TString hostdir, user, script;
805  Int_t dbg = 0;
806  Int_t rc = ParseRemoteLine(line, hostdir, user, dbg, script);
807  if (hostdir.Length() <= 0) {
808  // Close the remote application if required
809  if (rc == 1) {
811  delete fAppRemote;
812  }
813  // Return to local run
814  fAppRemote = 0;
815  // Done
816  return 1;
817  } else if (rc == 1) {
818  // close an existing remote application
819  TApplication *ap = TApplication::Open(hostdir, 0, 0);
820  if (ap) {
822  delete ap;
823  }
824  }
825  // Attach or start a remote application
826  if (user.Length() > 0)
827  hostdir.Insert(0,Form("%s@", user.Data()));
828  const char *sc = (script.Length() > 0) ? script.Data() : 0;
829  TApplication *ap = TApplication::Open(hostdir, dbg, sc);
830  if (ap) {
831  fAppRemote = ap;
832  }
833 
834  // Done
835  return 1;
836 }
837 
838 namespace {
839  static int PrintFile(const char* filename) {
840  TString sFileName(filename);
841  gSystem->ExpandPathName(sFileName);
842  if (gSystem->AccessPathName(sFileName)) {
843  Error("ProcessLine()", "Cannot find file %s", filename);
844  return 1;
845  }
846  std::ifstream instr(sFileName);
847  TString content;
848  content.ReadFile(instr);
849  Printf("%s", content.Data());
850  return 0;
851  }
852 }
853 
854 ////////////////////////////////////////////////////////////////////////////////
855 /// Process a single command line, either a C++ statement or an interpreter
856 /// command starting with a ".".
857 /// Return the return value of the command cast to a long.
858 
860 {
861  if (!line || !*line) return 0;
862 
863  // If we are asked to go remote do it
864  if (!strncmp(line, ".R", 2)) {
865  Int_t n = 2;
866  while (*(line+n) == ' ')
867  n++;
868  return ProcessRemote(line+n, err);
869  }
870 
871  // Redirect, if requested
874  return fAppRemote->ProcessLine(line, err);
875  }
876 
877  if (!strncasecmp(line, ".qqqqqqq", 7)) {
878  gSystem->Abort();
879  } else if (!strncasecmp(line, ".qqqqq", 5)) {
880  Info("ProcessLine", "Bye... (try '.qqqqqqq' if still running)");
881  gSystem->Exit(1);
882  } else if (!strncasecmp(line, ".exit", 4) || !strncasecmp(line, ".quit", 2)) {
883  Terminate(0);
884  return 0;
885  }
886 
887  if (!strncmp(line, "?", 1) || !strncmp(line, ".help", 5)) {
888  Help(line);
889  return 1;
890  }
891 
892  if (!strncmp(line, ".demo", 5)) {
893  if (gROOT->IsBatch()) {
894  Error("ProcessLine", "Cannot show demos in batch mode!");
895  return 1;
896  }
897  ProcessLine(".x " + TROOT::GetTutorialDir() + "/demos.C");
898  return 0;
899  }
900 
901  if (!strncmp(line, ".license", 8)) {
902  return PrintFile(TROOT::GetDocDir() + "/LICENSE");
903  }
904 
905  if (!strncmp(line, ".credits", 8)) {
906  TString credits = TROOT::GetDocDir() + "/CREDITS";
907  if (gSystem->AccessPathName(credits, kReadPermission))
908  credits = TROOT::GetDocDir() + "/README/CREDITS";
909  return PrintFile(credits);
910  }
911 
912  if (!strncmp(line, ".pwd", 4)) {
913  if (gDirectory)
914  Printf("Current directory: %s", gDirectory->GetPath());
915  if (gPad)
916  Printf("Current pad: %s", gPad->GetName());
917  if (gStyle)
918  Printf("Current style: %s", gStyle->GetName());
919  return 1;
920  }
921 
922  if (!strncmp(line, ".ls", 3)) {
923  const char *opt = 0;
924  if (line[3]) opt = &line[3];
925  if (gDirectory) gDirectory->ls(opt);
926  return 1;
927  }
928 
929  if (!strncmp(line, ".which", 6)) {
930  char *fn = Strip(line+7);
931  char *s = strtok(fn, "+(");
932  char *mac = gSystem->Which(TROOT::GetMacroPath(), s, kReadPermission);
933  if (!mac)
934  Printf("No macro %s in path %s", s, TROOT::GetMacroPath());
935  else
936  Printf("%s", mac);
937  delete [] fn;
938  delete [] mac;
939  return mac ? 1 : 0;
940  }
941 
942  if (!strncmp(line, ".L", 2) || !strncmp(line, ".U", 2)) {
943  TString aclicMode;
944  TString arguments;
945  TString io;
946  TString fname = gSystem->SplitAclicMode(line+3, aclicMode, arguments, io);
947 
948  char *mac = gSystem->Which(TROOT::GetMacroPath(), fname, kReadPermission);
949  if (arguments.Length()) {
950  Warning("ProcessLine", "argument(s) \"%s\" ignored with .%c", arguments.Data(),
951  line[1]);
952  }
953  Long_t retval = 0;
954  if (!mac)
955  Error("ProcessLine", "macro %s not found in path %s", fname.Data(),
957  else {
958  TString cmd(line+1);
959  Ssiz_t posSpace = cmd.Index(' ');
960  if (posSpace == -1) cmd.Remove(1);
961  else cmd.Remove(posSpace);
962  TString tempbuf;
963  if (sync) {
964  tempbuf.Form(".%s %s%s%s", cmd.Data(), mac, aclicMode.Data(),io.Data());
965  retval = gInterpreter->ProcessLineSynch(tempbuf,
967  } else {
968  tempbuf.Form(".%s %s%s%s", cmd.Data(), mac, aclicMode.Data(),io.Data());
969  retval = gInterpreter->ProcessLine(tempbuf,
971  }
972  }
973 
974  delete [] mac;
975 
977 
978  return retval;
979  }
980 
981  if (!strncmp(line, ".X", 2) || !strncmp(line, ".x", 2)) {
982  return ProcessFile(line+3, err, line[2] == 'k');
983  }
984 
985  if (!strcmp(line, ".reset")) {
986  // Do nothing, .reset disabled in CINT because too many side effects
987  Printf("*** .reset not allowed, please use gROOT->Reset() ***");
988  return 0;
989 
990 #if 0
991  // delete the ROOT dictionary since CINT will destroy all objects
992  // referenced by the dictionary classes (TClass et. al.)
993  gROOT->GetListOfClasses()->Delete();
994  // fall through
995 #endif
996  }
997 
998  if (sync)
999  return gInterpreter->ProcessLineSynch(line, (TInterpreter::EErrorCode*)err);
1000  else
1001  return gInterpreter->ProcessLine(line, (TInterpreter::EErrorCode*)err);
1002 }
1003 
1004 ////////////////////////////////////////////////////////////////////////////////
1005 /// Process a file containing a C++ macro.
1006 
1008 {
1009  return ExecuteFile(file, error, keep);
1010 }
1011 
1012 ////////////////////////////////////////////////////////////////////////////////
1013 /// Execute a file containing a C++ macro (static method). Can be used
1014 /// while TApplication is not yet created.
1015 
1017 {
1018  static const Int_t kBufSize = 1024;
1019 
1020  if (!file || !*file) return 0;
1021 
1022  TString aclicMode;
1023  TString arguments;
1024  TString io;
1025  TString fname = gSystem->SplitAclicMode(file, aclicMode, arguments, io);
1026 
1027  char *exnam = gSystem->Which(TROOT::GetMacroPath(), fname, kReadPermission);
1028  if (!exnam) {
1029  ::Error("TApplication::ExecuteFile", "macro %s not found in path %s", fname.Data(),
1031  delete [] exnam;
1032  if (error)
1034  return 0;
1035  }
1036 
1037  ::std::ifstream macro(exnam, std::ios::in);
1038  if (!macro.good()) {
1039  ::Error("TApplication::ExecuteFile", "%s no such file", exnam);
1040  if (error)
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 }
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Definition: TSystem.cxx:1272
virtual void LoadGraphicsLibs()
Load shared libs necessary for graphics.
static const TString & GetTTFFontDir()
Get the fonts directory in the installation. Static utility function.
Definition: TROOT.cxx:2928
std::istream & ReadFile(std::istream &str)
Replace string with the contents of strm, stopping at an EOF.
Definition: Stringio.cxx:28
R__EXTERN TGuiFactory * gBatchGuiFactory
Definition: TGuiFactory.h:67
virtual Long_t ProcessLine(const char *line, Bool_t sync=kFALSE, Int_t *error=0)
Process a single command line, either a C++ statement or an interpreter command starting with a "...
Semi-Abstract base class defining a generic interface to the underlying, low level, native graphics backend (X11, Win32, MacOS, OpenGL...).
Definition: TVirtualX.h:58
An array of TObjects.
Definition: TObjArray.h:37
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:847
virtual void ls(Option_t *option="") const
Show available sessions.
long long Long64_t
Definition: RtypesCore.h:69
static const TString & GetTutorialDir()
Get the tutorials directory in the installation. Static utility function.
Definition: TROOT.cxx:2865
Bool_t fReturnFromRun
Definition: TApplication.h:62
static Bool_t fgGraphInit
Definition: TApplication.h:75
virtual const char * WorkingDirectory()
Return working directory.
Definition: TSystem.cxx:868
char * Compress(const char *str)
Remove all blanks from the string str.
Definition: TString.cxx:2538
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:318
TLine * line
Collectable string class.
Definition: TObjString.h:28
R__EXTERN TClassTable * gClassTable
Definition: TClassTable.h:93
const char Option_t
Definition: RtypesCore.h:62
virtual TString SplitAclicMode(const char *filename, TString &mode, TString &args, TString &io) const
This method split a filename of the form: ~~~ {.cpp} [path/]macro.C[+|++[k|f|g|O|c|s|d|v|-]][(args)]...
Definition: TSystem.cxx:4071
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:40
This class represents a WWW compatible URL.
Definition: TUrl.h:35
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:640
R__EXTERN TStyle * gStyle
Definition: TStyle.h:402
int GetPathInfo(const char *path, Long_t *id, Long_t *size, Long_t *flags, Long_t *modtime)
Get info about a file: id, size, flags, modification time.
Definition: TSystem.cxx:1370
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:159
const char * GetProtocol() const
Definition: TUrl.h:67
TH1 * h
Definition: legend2.C:5
virtual void MakeBatch()
Switch to batch mode.
TString fIdleCommand
Definition: TApplication.h:69
virtual Bool_t ChangeDirectory(const char *path)
Change directory.
Definition: TSystem.cxx:859
const char * GetFileAndOptions() const
Return the file and its options (the string specified behind the ?).
Definition: TUrl.cxx:501
#define gROOT
Definition: TROOT.h:375
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:587
Int_t LoadPlugin()
Load the plugin library for this handler.
Basic string class.
Definition: TString.h:129
TSignalHandler * fSigHandler
Definition: TApplication.h:71
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1099
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual TTimer * RemoveTimer(TTimer *t)
Remove timer from list of system timers.
Definition: TSystem.cxx:488
static Bool_t fgGraphNeeded
Definition: TApplication.h:74
TArc * a
Definition: textangle.C:12
R__EXTERN TVirtualMutex * gROOTMutex
Definition: TROOT.h:57
EExitOnException fExitOnException
Definition: TApplication.h:72
virtual void ReturnPressed(char *text)
Emit signal when return key was pressed.
#define gInterpreter
Definition: TInterpreter.h:499
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
Definition: TSystem.cxx:1518
virtual void Terminate(Int_t status=0)
Terminate the application by call TSystem::Exit() unless application has been told to return from Run...
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
Definition: TObject.cxx:543
virtual Long_t ProcessRemote(const char *line, Int_t *error=0)
Process the content of a line starting with ".R" (already stripped-off) The format is [user@]host[:di...
Bool_t fNoLogo
Definition: TApplication.h:64
TString & Insert(Ssiz_t pos, const char *s)
Definition: TString.h:597
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:687
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
Definition: TUrl.cxx:387
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
Definition: TString.h:630
static const char * GetMacroPath()
Get macro search path. Static utility function.
Definition: TROOT.cxx:2585
const char * GetFile() const
Definition: TUrl.h:72
null_t< F > null()
const char * GetHost() const
Definition: TUrl.h:70
#define SafeDelete(p)
Definition: RConfig.h:499
TString fWorkDir
Definition: TApplication.h:68
Double_t x[n]
Definition: legend1.C:17
virtual TApplicationImp * CreateApplicationImp(const char *classname, int *argc, char **argv)
Create a batch version of TApplicationImp.
Definition: TGuiFactory.cxx:48
virtual void SetIdleTimer(UInt_t idleTimeInSec, const char *command)
Set the command to be executed after the system has been idle for idleTimeInSec seconds.
virtual void Run(Bool_t retrn=kFALSE)
Main application eventloop. Calls system dependent eventloop via gSystem.
static Bool_t Initialized()
Return kTRUE if the TROOT object has been initialized.
Definition: TROOT.cxx:2640
static Int_t ParseRemoteLine(const char *ln, TString &hostdir, TString &user, Int_t &dbg, TString &script)
Parse the content of a line starting with ".R" (already stripped-off) The format is [user@]host[:dir]...
virtual ~TApplication()
TApplication dtor.
virtual void Init()
Definition: TApplication.h:112
static const TString & GetDocDir()
Get the documentation directory in the installation. Static utility function.
Definition: TROOT.cxx:2828
virtual void ExitLoop()
Exit from event loop.
Definition: TSystem.cxx:399
static void CallEndOfProcessCleanups()
R__EXTERN TGuiFactory * gGuiFactory
Definition: TGuiFactory.h:66
virtual void GetOptions(Int_t *argc, char **argv)
Get and handle command line options.
virtual Bool_t Notify()
Notify when timer times out.
Definition: TTimer.cxx:143
A doubly linked list.
Definition: TList.h:43
const char * GetUser() const
Definition: TUrl.h:68
static TList * GetApplications()
Static method returning the list of available applications.
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:37
virtual void Open()
Definition: TApplication.h:127
R__EXTERN TVirtualX * gGXBatch
Definition: TVirtualX.h:353
Bool_t fIsRunning
Window system specific application implementation.
Definition: TApplication.h:61
TObjArray * fFiles
Definition: TApplication.h:67
void ClearInputFiles()
Clear list containing macro files passed as program arguments.
virtual const char * ApplicationName() const
Definition: TApplication.h:123
virtual void RemoveIdleTimer()
Remove idle timer. Normally called via TROOT::Idle(0).
static void NeedGraphicsLibs()
Static method.
R__EXTERN TSystem * gSystem
Definition: TSystem.h:539
if object ctor succeeded but object should not be used
Definition: TObject.h:65
Long_t ExecPlugin(int nargs, const T &... params)
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
Definition: TEnv.cxx:482
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:679
void SetScreenFactor(Float_t factor=1)
Definition: TStyle.h:294
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition: TString.h:563
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:2332
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:873
char * Form(const char *fmt,...)
Ssiz_t Length() const
Definition: TString.h:388
Bool_t fUseMemstat
Definition: TApplication.h:66
TApplicationImp * fAppImp
Definition: TApplication.h:60
virtual void SetEchoMode(Bool_t mode)
Set console echo mode:
Handles synchronous and a-synchronous timer events.
Definition: TTimer.h:51
virtual void StopIdleing()
Called when system stops idleing.
char * Strip(const char *str, char c=' ')
Strip leading and trailing c (blanks by default) from a string.
Definition: TString.cxx:2488
virtual void Abort(int code=0)
Abort the application.
Definition: TSystem.cxx:731
TApplication * fAppRemote
Definition: TApplication.h:81
static void Close(TApplication *app)
Static function used to close a remote application.
#define gVirtualX
Definition: TVirtualX.h:350
virtual TObjLink * FirstLink() const
Definition: TList.h:97
virtual void Run()
System event loop.
Definition: TSystem.cxx:350
#define Printf
Definition: TGeoToOCC.h:18
char * StrDup(const char *str)
Duplicate the string str.
Definition: TString.cxx:2524
virtual void Help(const char *line)
Print help on interpreter.
#define R__LOCKGUARD2(mutex)
const Bool_t kFALSE
Definition: RtypesCore.h:92
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:621
long Long_t
Definition: RtypesCore.h:50
int Ssiz_t
Definition: RtypesCore.h:63
R__EXTERN ExceptionContext_t * gException
Definition: TException.h:74
virtual void StartIdleing()
Called when system starts idleing.
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
Definition: TString.cxx:2251
Bool_t fNoLog
Definition: TApplication.h:63
#define ClassImp(name)
Definition: Rtypes.h:336
TText * text
static DictFuncPtr_t GetDict(const char *cname)
Given the class name returns the Dictionary() function of a class (uses hash of name).
virtual void KeyPressed(Int_t key)
Emit signal when console keyboard key was pressed.
const char * GetIdleCommand() const
Definition: TApplication.h:118
R__EXTERN TEnv * gEnv
Definition: TEnv.h:170
TTimer(const TTimer &)
Double_t y[n]
Definition: legend1.C:17
char ** Argv() const
Definition: TApplication.h:136
virtual void SetProgname(const char *name)
Set the application name (from command line, argv[0]) and copy it in gProgName.
Definition: TSystem.cxx:230
TTimer * fIdleTimer
Definition: TApplication.h:70
virtual void LineProcessed(const char *line)
Emit signal when a line has been processed.
char ** fArgv
Definition: TApplication.h:59
Bool_t IsNull() const
Definition: TString.h:385
virtual Int_t TabCompletionHook(char *buf, int *pLoc, std::ostream &out)
What to do when tab is pressed.
EExitOnException ExitOnException(EExitOnException opt=kExit)
Set the exit on exception option.
void Throw(int code)
If an exception context has been set (using the TRY and RETRY macros) jump back to where it was set...
Definition: TException.cxx:27
This ABC is a factory for GUI components.
Definition: TGuiFactory.h:42
virtual void HandleIdleTimer()
Handle idle timeout.
virtual void HandleException(Int_t sig)
Handle exceptions (kSigBus, kSigSegmentationViolation, kSigIllegalInstruction and kSigFloatingExcepti...
virtual void Add(TObject *obj)
Definition: TList.h:77
virtual void AddTimer(TTimer *t)
Add timer to list of system timers.
Definition: TSystem.cxx:478
Definition: file.py:1
virtual void Exit(int code, Bool_t mode=kTRUE)
Exit the application.
Definition: TSystem.cxx:723
void SetOptions(const char *opt)
Definition: TUrl.h:90
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
TApplication * gApplication
#define gPad
Definition: TVirtualPad.h:284
R__EXTERN Int_t gDebug
Definition: Rtypes.h:83
bool debug
Int_t Atoi() const
Return integer value of string.
Definition: TString.cxx:1975
void Add(TObject *obj)
Definition: TObjArray.h:73
#define gDirectory
Definition: TDirectory.h:211
static void InitializeColors()
Initialize colors used by the TCanvas based graphics (via TColor objects).
Definition: TColor.cxx:1049
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition: TQObject.h:164
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:39
Bool_t fQuit
Definition: TApplication.h:65
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition: TSystem.cxx:1250
static TList * fgApplications
Definition: TApplication.h:83
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition: TObject.cxx:901
void SetReturnFromRun(Bool_t ret)
Definition: TApplication.h:149
const Bool_t kTRUE
Definition: RtypesCore.h:91
const Int_t n
Definition: legend1.C:16
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:859
virtual Long_t ProcessFile(const char *file, Int_t *error=0, Bool_t keep=kFALSE)
Process a file containing a C++ macro.
const char * Data() const
Definition: TString.h:347
TApplication()
Default ctor. Can be used by classes deriving from TApplication.