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