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