Logo ROOT   6.08/02
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  if (arg) *arg = '(';
472  if (!gSystem->GetPathInfo(dir, &id, &size, &flags, &modtime)) {
473  if ((flags & 2)) {
474  // if directory set it in fWorkDir
475  if (pwd == "") {
476  pwd = gSystem->WorkingDirectory();
477  fWorkDir = dir;
478  gSystem->ChangeDirectory(dir);
479  argv[i] = null;
480  } else if (!strcmp(gROOT->GetName(), "Rint")) {
481  Warning("GetOptions", "only one directory argument can be specified (%s)", dir);
482  }
483  } else if (size > 0) {
484  // if file add to list of files to be processed
485  if (!fFiles) fFiles = new TObjArray;
486  fFiles->Add(new TObjString(argv[i]));
487  argv[i] = null;
488  } else {
489  Warning("GetOptions", "file %s has size 0, skipping", dir);
490  }
491  } else {
492  if (TString(udir.GetFile()).EndsWith(".root")) {
493  if (!strcmp(udir.GetProtocol(), "file")) {
494  // file ending on .root but does not exist, likely a typo
495  // warn user if plain root...
496  if (!strcmp(gROOT->GetName(), "Rint"))
497  Warning("GetOptions", "file %s not found", dir);
498  } else {
499  // remote file, give it the benefit of the doubt and add it to list of files
500  if (!fFiles) fFiles = new TObjArray;
501  fFiles->Add(new TObjString(argv[i]));
502  argv[i] = null;
503  }
504  } else {
505  TString mode,fargs,io;
506  TString fname = gSystem->SplitAclicMode(dir,mode,fargs,io);
507  char *mac;
508  if ((mac = gSystem->Which(TROOT::GetMacroPath(), fname,
509  kReadPermission))) {
510  // if file add to list of files to be processed
511  if (!fFiles) fFiles = new TObjArray;
512  fFiles->Add(new TObjString(argv[i]));
513  argv[i] = null;
514  delete [] mac;
515  } else {
516  // only warn if we're plain root,
517  // other progs might have their own params
518  if (!strcmp(gROOT->GetName(), "Rint"))
519  Warning("GetOptions", "macro %s not found", fname.Data());
520  }
521  }
522  }
523  delete [] dir;
524  }
525  // ignore unknown options
526  }
527 
528  // go back to startup directory
529  if (pwd != "")
530  gSystem->ChangeDirectory(pwd);
531 
532  // remove handled arguments from argument array
533  j = 0;
534  for (i = 0; i < *argc; i++) {
535  if (strcmp(argv[i], "")) {
536  argv[j] = argv[i];
537  j++;
538  }
539  }
540 
541  *argc = j;
542 }
543 
544 ////////////////////////////////////////////////////////////////////////////////
545 /// Handle idle timeout. When this timer expires the registered idle command
546 /// will be executed by this routine and a signal will be emitted.
547 
549 {
550  if (!fIdleCommand.IsNull())
552 
553  Emit("HandleIdleTimer()");
554 }
555 
556 ////////////////////////////////////////////////////////////////////////////////
557 /// Handle exceptions (kSigBus, kSigSegmentationViolation,
558 /// kSigIllegalInstruction and kSigFloatingException) trapped in TSystem.
559 /// Specific TApplication implementations may want something different here.
560 
562 {
563  if (TROOT::Initialized()) {
564  if (gException) {
565  gInterpreter->RewindDictionary();
566  gInterpreter->ClearFileBusy();
567  }
568  if (fExitOnException == kExit)
569  gSystem->Exit(sig);
570  else if (fExitOnException == kAbort)
571  gSystem->Abort();
572  else
573  Throw(sig);
574  }
575  gSystem->Exit(sig);
576 }
577 
578 ////////////////////////////////////////////////////////////////////////////////
579 /// Set the exit on exception option. Setting this option determines what
580 /// happens in HandleException() in case an exception (kSigBus,
581 /// kSigSegmentationViolation, kSigIllegalInstruction or kSigFloatingException)
582 /// is trapped. Choices are: kDontExit (default), kExit or kAbort.
583 /// Returns the previous value.
584 
586 {
588  fExitOnException = opt;
589  return old;
590 }
591 
592 ////////////////////////////////////////////////////////////////////////////////
593 /// Print help on interpreter.
594 
595 void TApplication::Help(const char *line)
596 {
597  gInterpreter->ProcessLine(line);
598 
599  Printf("\nROOT special commands.");
600  Printf("===========================================================================");
601  Printf(" pwd : show current directory, pad and style");
602  Printf(" ls : list contents of current directory");
603  Printf(" which [file] : shows path of macro file");
604 }
605 
606 ////////////////////////////////////////////////////////////////////////////////
607 /// Load shared libs necessary for graphics. These libraries are only
608 /// loaded when gROOT->IsBatch() is kFALSE.
609 
611 {
612  if (gROOT->IsBatch()) return;
613 
614  TPluginHandler *h;
615  if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualPad")))
616  if (h->LoadPlugin() == -1)
617  return;
618 
619  TString name;
620  TString title1 = "ROOT interface to ";
621  TString nativex, title;
622  TString nativeg = "root";
623 
624 #ifdef R__WIN32
625  nativex = "win32gdk";
626  name = "Win32gdk";
627  title = title1 + "Win32gdk";
628 #elif defined(R__HAS_COCOA)
629  nativex = "quartz";
630  name = "quartz";
631  title = title1 + "Quartz";
632 #else
633  nativex = "x11";
634  name = "X11";
635  title = title1 + "X11";
636 #endif
637 
638  TString guiBackend(gEnv->GetValue("Gui.Backend", "native"));
639  guiBackend.ToLower();
640  if (guiBackend == "native") {
641  guiBackend = nativex;
642  } else {
643  name = guiBackend;
644  title = title1 + guiBackend;
645  }
646  TString guiFactory(gEnv->GetValue("Gui.Factory", "native"));
647  guiFactory.ToLower();
648  if (guiFactory == "native")
649  guiFactory = nativeg;
650 
651  if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualX", guiBackend))) {
652  if (h->LoadPlugin() == -1) {
653  gROOT->SetBatch(kTRUE);
654  return;
655  }
656  gVirtualX = (TVirtualX *) h->ExecPlugin(2, name.Data(), title.Data());
657  fgGraphInit = kTRUE;
658  }
659  if ((h = gROOT->GetPluginManager()->FindHandler("TGuiFactory", guiFactory))) {
660  if (h->LoadPlugin() == -1) {
661  gROOT->SetBatch(kTRUE);
662  return;
663  }
664  gGuiFactory = (TGuiFactory *) h->ExecPlugin(0);
665  }
666 }
667 
668 ////////////////////////////////////////////////////////////////////////////////
669 /// Switch to batch mode.
670 
672 {
673  gROOT->SetBatch();
676 #ifndef R__WIN32
677  if (gVirtualX != gGXBatch) delete gVirtualX;
678 #endif
680 }
681 
682 ////////////////////////////////////////////////////////////////////////////////
683 /// Parse the content of a line starting with ".R" (already stripped-off)
684 /// The format is
685 /// ~~~ {.cpp}
686 /// [user@]host[:dir] [-l user] [-d dbg] [script]
687 /// ~~~
688 /// The variable 'dir' is the remote directory to be used as working dir.
689 /// The username can be specified in two ways, "-l" having the priority
690 /// (as in ssh).
691 /// A 'dbg' value > 0 gives increasing verbosity.
692 /// The last argument 'script' allows to specify an alternative script to
693 /// be executed remotely to startup the session.
694 
696  TString &hostdir, TString &user,
697  Int_t &dbg, TString &script)
698 {
699  if (!ln || strlen(ln) <= 0)
700  return 0;
701 
702  Int_t rc = 0;
703  Bool_t isHostDir = kTRUE;
704  Bool_t isScript = kFALSE;
705  Bool_t isUser = kFALSE;
706  Bool_t isDbg = kFALSE;
707 
708  TString line(ln);
709  TString tkn;
710  Int_t from = 0;
711  while (line.Tokenize(tkn, from, " ")) {
712  if (tkn == "-l") {
713  // Next is a user name
714  isUser = kTRUE;
715  } else if (tkn == "-d") {
716  isDbg = kTRUE;
717  } else if (tkn == "-close") {
718  rc = 1;
719  } else if (tkn.BeginsWith("-")) {
720  ::Warning("TApplication::ParseRemoteLine","unknown option: %s", tkn.Data());
721  } else {
722  if (isUser) {
723  user = tkn;
724  isUser = kFALSE;
725  } else if (isDbg) {
726  dbg = tkn.Atoi();
727  isDbg = kFALSE;
728  } else if (isHostDir) {
729  hostdir = tkn;
730  hostdir.ReplaceAll(":","/");
731  isHostDir = kFALSE;
732  isScript = kTRUE;
733  } else if (isScript) {
734  // Add everything left
735  script = tkn;
736  script.Insert(0, "\"");
737  script += "\"";
738  isScript = kFALSE;
739  break;
740  }
741  }
742  }
743 
744  // Done
745  return rc;
746 }
747 
748 ////////////////////////////////////////////////////////////////////////////////
749 /// Process the content of a line starting with ".R" (already stripped-off)
750 /// The format is
751 /// ~~~ {.cpp}
752 /// [user@]host[:dir] [-l user] [-d dbg] [script] | [host] -close
753 /// ~~~
754 /// The variable 'dir' is the remote directory to be used as working dir.
755 /// The username can be specified in two ways, "-l" having the priority
756 /// (as in ssh).
757 /// A 'dbg' value > 0 gives increasing verbosity.
758 /// The last argument 'script' allows to specify an alternative script to
759 /// be executed remotely to startup the session.
760 
762 {
763  if (!line) return 0;
764 
765  if (!strncmp(line, "-?", 2) || !strncmp(line, "-h", 2) ||
766  !strncmp(line, "--help", 6)) {
767  Info("ProcessRemote", "remote session help:");
768  Printf(".R [user@]host[:dir] [-l user] [-d dbg] [[<]script] | [host] -close");
769  Printf("Create a ROOT session on the specified remote host.");
770  Printf("The variable \"dir\" is the remote directory to be used as working dir.");
771  Printf("The username can be specified in two ways, \"-l\" having the priority");
772  Printf("(as in ssh). A \"dbg\" value > 0 gives increasing verbosity.");
773  Printf("The last argument \"script\" allows to specify an alternative script to");
774  Printf("be executed remotely to startup the session, \"roots\" being");
775  Printf("the default. If the script is preceded by a \"<\" the script will be");
776  Printf("sourced, after which \"roots\" is executed. The sourced script can be ");
777  Printf("used to change the PATH and other variables, allowing an alternative");
778  Printf("\"roots\" script to be found.");
779  Printf("To close down a session do \".R host -close\".");
780  Printf("To switch between sessions do \".R host\", to switch to the local");
781  Printf("session do \".R\".");
782  Printf("To list all open sessions do \"gApplication->GetApplications()->Print()\".");
783  return 0;
784  }
785 
786  TString hostdir, user, script;
787  Int_t dbg = 0;
788  Int_t rc = ParseRemoteLine(line, hostdir, user, dbg, script);
789  if (hostdir.Length() <= 0) {
790  // Close the remote application if required
791  if (rc == 1) {
793  delete fAppRemote;
794  }
795  // Return to local run
796  fAppRemote = 0;
797  // Done
798  return 1;
799  } else if (rc == 1) {
800  // close an existing remote application
801  TApplication *ap = TApplication::Open(hostdir, 0, 0);
802  if (ap) {
804  delete ap;
805  }
806  }
807  // Attach or start a remote application
808  if (user.Length() > 0)
809  hostdir.Insert(0,Form("%s@", user.Data()));
810  const char *sc = (script.Length() > 0) ? script.Data() : 0;
811  TApplication *ap = TApplication::Open(hostdir, dbg, sc);
812  if (ap) {
813  fAppRemote = ap;
814  }
815 
816  // Done
817  return 1;
818 }
819 
820 namespace {
821  static int PrintFile(const char* filename) {
822  TString sFileName(filename);
823  gSystem->ExpandPathName(sFileName);
824  if (gSystem->AccessPathName(sFileName)) {
825  Error("ProcessLine()", "Cannot find file %s", filename);
826  return 1;
827  }
828  std::ifstream instr(sFileName);
829  TString content;
830  content.ReadFile(instr);
831  Printf("%s", content.Data());
832  return 0;
833  }
834 }
835 
836 ////////////////////////////////////////////////////////////////////////////////
837 /// Process a single command line, either a C++ statement or an interpreter
838 /// command starting with a ".".
839 /// Return the return value of the command cast to a long.
840 
842 {
843  if (!line || !*line) return 0;
844 
845  // If we are asked to go remote do it
846  if (!strncmp(line, ".R", 2)) {
847  Int_t n = 2;
848  while (*(line+n) == ' ')
849  n++;
850  return ProcessRemote(line+n, err);
851  }
852 
853  // Redirect, if requested
856  return fAppRemote->ProcessLine(line, err);
857  }
858 
859  if (!strncasecmp(line, ".qqqqqqq", 7)) {
860  gSystem->Abort();
861  } else if (!strncasecmp(line, ".qqqqq", 5)) {
862  Info("ProcessLine", "Bye... (try '.qqqqqqq' if still running)");
863  gSystem->Exit(1);
864  } else if (!strncasecmp(line, ".exit", 4) || !strncasecmp(line, ".quit", 2)) {
865  Terminate(0);
866  return 0;
867  }
868 
869  if (!strncmp(line, "?", 1) || !strncmp(line, ".help", 5)) {
870  Help(line);
871  return 1;
872  }
873 
874  if (!strncmp(line, ".demo", 5)) {
875  if (gROOT->IsBatch()) {
876  Error("ProcessLine", "Cannot show demos in batch mode!");
877  return 1;
878  }
879  ProcessLine(".x " + TROOT::GetTutorialDir() + "/demos.C");
880  return 0;
881  }
882 
883  if (!strncmp(line, ".license", 8)) {
884  return PrintFile(TROOT::GetDocDir() + "/LICENSE");
885  }
886 
887  if (!strncmp(line, ".credits", 8)) {
888  TString credits = TROOT::GetDocDir() + "/CREDITS";
889  if (gSystem->AccessPathName(credits, kReadPermission))
890  credits = TROOT::GetDocDir() + "/README/CREDITS";
891  return PrintFile(credits);
892  }
893 
894  if (!strncmp(line, ".pwd", 4)) {
895  if (gDirectory)
896  Printf("Current directory: %s", gDirectory->GetPath());
897  if (gPad)
898  Printf("Current pad: %s", gPad->GetName());
899  if (gStyle)
900  Printf("Current style: %s", gStyle->GetName());
901  return 1;
902  }
903 
904  if (!strncmp(line, ".ls", 3)) {
905  const char *opt = 0;
906  if (line[3]) opt = &line[3];
907  if (gDirectory) gDirectory->ls(opt);
908  return 1;
909  }
910 
911  if (!strncmp(line, ".which", 6)) {
912  char *fn = Strip(line+7);
913  char *s = strtok(fn, "+(");
914  char *mac = gSystem->Which(TROOT::GetMacroPath(), s, kReadPermission);
915  if (!mac)
916  Printf("No macro %s in path %s", s, TROOT::GetMacroPath());
917  else
918  Printf("%s", mac);
919  delete [] fn;
920  delete [] mac;
921  return mac ? 1 : 0;
922  }
923 
924  if (!strncmp(line, ".L", 2) || !strncmp(line, ".U", 2)) {
925  TString aclicMode;
926  TString arguments;
927  TString io;
928  TString fname = gSystem->SplitAclicMode(line+3, aclicMode, arguments, io);
929 
930  char *mac = gSystem->Which(TROOT::GetMacroPath(), fname, kReadPermission);
931  if (arguments.Length()) {
932  Warning("ProcessLine", "argument(s) \"%s\" ignored with .%c", arguments.Data(),
933  line[1]);
934  }
935  Long_t retval = 0;
936  if (!mac)
937  Error("ProcessLine", "macro %s not found in path %s", fname.Data(),
939  else {
940  TString cmd(line+1);
941  Ssiz_t posSpace = cmd.Index(' ');
942  if (posSpace == -1) cmd.Remove(1);
943  else cmd.Remove(posSpace);
944  TString tempbuf;
945  if (sync) {
946  tempbuf.Form(".%s %s%s%s", cmd.Data(), mac, aclicMode.Data(),io.Data());
947  retval = gInterpreter->ProcessLineSynch(tempbuf,
949  } else {
950  tempbuf.Form(".%s %s%s%s", cmd.Data(), mac, aclicMode.Data(),io.Data());
951  retval = gInterpreter->ProcessLine(tempbuf,
953  }
954  }
955 
956  delete [] mac;
957 
959 
960  return retval;
961  }
962 
963  if (!strncmp(line, ".X", 2) || !strncmp(line, ".x", 2)) {
964  return ProcessFile(line+3, err, line[2] == 'k');
965  }
966 
967  if (!strcmp(line, ".reset")) {
968  // Do nothing, .reset disabled in CINT because too many side effects
969  Printf("*** .reset not allowed, please use gROOT->Reset() ***");
970  return 0;
971 
972 #if 0
973  // delete the ROOT dictionary since CINT will destroy all objects
974  // referenced by the dictionary classes (TClass et. al.)
975  gROOT->GetListOfClasses()->Delete();
976  // fall through
977 #endif
978  }
979 
980  if (sync)
981  return gInterpreter->ProcessLineSynch(line, (TInterpreter::EErrorCode*)err);
982  else
983  return gInterpreter->ProcessLine(line, (TInterpreter::EErrorCode*)err);
984 }
985 
986 ////////////////////////////////////////////////////////////////////////////////
987 /// Process a file containing a C++ macro.
988 
989 Long_t TApplication::ProcessFile(const char *file, Int_t *error, Bool_t keep)
990 {
991  return ExecuteFile(file, error, keep);
992 }
993 
994 ////////////////////////////////////////////////////////////////////////////////
995 /// Execute a file containing a C++ macro (static method). Can be used
996 /// while TApplication is not yet created.
997 
998 Long_t TApplication::ExecuteFile(const char *file, Int_t *error, Bool_t keep)
999 {
1000  static const Int_t kBufSize = 1024;
1001 
1002  if (!file || !*file) return 0;
1003 
1004  TString aclicMode;
1005  TString arguments;
1006  TString io;
1007  TString fname = gSystem->SplitAclicMode(file, aclicMode, arguments, io);
1008 
1009  char *exnam = gSystem->Which(TROOT::GetMacroPath(), fname, kReadPermission);
1010  if (!exnam) {
1011  ::Error("TApplication::ExecuteFile", "macro %s not found in path %s", fname.Data(),
1013  delete [] exnam;
1014  return 0;
1015  }
1016 
1017  ::std::ifstream macro(exnam, std::ios::in);
1018  if (!macro.good()) {
1019  ::Error("TApplication::ExecuteFile", "%s no such file", exnam);
1020  delete [] exnam;
1021  return 0;
1022  }
1023 
1024  char currentline[kBufSize];
1025  char dummyline[kBufSize];
1026  int tempfile = 0;
1027  int comment = 0;
1028  int ifndefc = 0;
1029  int ifdef = 0;
1030  char *s = 0;
1031  Bool_t execute = kFALSE;
1032  Long_t retval = 0;
1033 
1034  while (1) {
1035  bool res = (bool)macro.getline(currentline, kBufSize);
1036  if (macro.eof()) break;
1037  if (!res) {
1038  // Probably only read kBufSize, let's ignore the remainder of
1039  // the line.
1040  macro.clear();
1041  while (!macro.getline(dummyline, kBufSize) && !macro.eof()) {
1042  macro.clear();
1043  }
1044  }
1045  s = currentline;
1046  while (s && (*s == ' ' || *s == '\t')) s++; // strip-off leading blanks
1047 
1048  // very simple minded pre-processor parsing, only works in case macro file
1049  // starts with "#ifndef __CINT__". In that case everything till next
1050  // "#else" or "#endif" will be skipped.
1051  if (*s == '#') {
1052  char *cs = Compress(currentline);
1053  if (strstr(cs, "#ifndef__CINT__") ||
1054  strstr(cs, "#if!defined(__CINT__)"))
1055  ifndefc = 1;
1056  else if (ifndefc && (strstr(cs, "#ifdef") || strstr(cs, "#ifndef") ||
1057  strstr(cs, "#ifdefined") || strstr(cs, "#if!defined")))
1058  ifdef++;
1059  else if (ifndefc && strstr(cs, "#endif")) {
1060  if (ifdef)
1061  ifdef--;
1062  else
1063  ifndefc = 0;
1064  } else if (ifndefc && !ifdef && strstr(cs, "#else"))
1065  ifndefc = 0;
1066  delete [] cs;
1067  }
1068  if (!*s || *s == '#' || ifndefc || !strncmp(s, "//", 2)) continue;
1069 
1070  if (!comment && (!strncmp(s, ".X", 2) || !strncmp(s, ".x", 2))) {
1071  retval = ExecuteFile(s+3);
1072  execute = kTRUE;
1073  continue;
1074  }
1075 
1076  if (!strncmp(s, "/*", 2)) comment = 1;
1077  if (comment) {
1078  // handle slightly more complex cases like: /* */ /*
1079 again:
1080  s = strstr(s, "*/");
1081  if (s) {
1082  comment = 0;
1083  s += 2;
1084 
1085  while (s && (*s == ' ' || *s == '\t')) s++; // strip-off leading blanks
1086  if (!*s) continue;
1087  if (!strncmp(s, "//", 2)) continue;
1088  if (!strncmp(s, "/*", 2)) {
1089  comment = 1;
1090  goto again;
1091  }
1092  }
1093  }
1094  if (!comment && *s == '{') tempfile = 1;
1095  if (!comment) break;
1096  }
1097  macro.close();
1098 
1099  if (!execute) {
1100  TString exname = exnam;
1101  if (!tempfile) {
1102  // We have a script that does NOT contain an unnamed macro,
1103  // so we can call the script compiler on it.
1104  exname += aclicMode;
1105  }
1106  exname += arguments;
1107  exname += io;
1108 
1109  TString tempbuf;
1110  if (tempfile) {
1111  tempbuf.Form(".x %s", exname.Data());
1112  } else {
1113  tempbuf.Form(".X%s %s", keep ? "k" : " ", exname.Data());
1114  }
1115  retval = gInterpreter->ProcessLineSynch(tempbuf,(TInterpreter::EErrorCode*)error);
1116  }
1117 
1118  delete [] exnam;
1119  return retval;
1120 }
1121 
1122 ////////////////////////////////////////////////////////////////////////////////
1123 /// Main application eventloop. Calls system dependent eventloop via gSystem.
1124 
1126 {
1127  SetReturnFromRun(retrn);
1128 
1129  fIsRunning = kTRUE;
1130 
1131  gSystem->Run();
1132  fIsRunning = kFALSE;
1133 }
1134 
1135 ////////////////////////////////////////////////////////////////////////////////
1136 /// Set the command to be executed after the system has been idle for
1137 /// idleTimeInSec seconds. Normally called via TROOT::Idle(...).
1138 
1139 void TApplication::SetIdleTimer(UInt_t idleTimeInSec, const char *command)
1140 {
1141  if (fIdleTimer) RemoveIdleTimer();
1142  fIdleCommand = command;
1143  fIdleTimer = new TIdleTimer(idleTimeInSec*1000);
1145 }
1146 
1147 ////////////////////////////////////////////////////////////////////////////////
1148 /// Remove idle timer. Normally called via TROOT::Idle(0).
1149 
1151 {
1152  if (fIdleTimer) {
1153  // timers are removed from the gSystem timer list by their dtor
1155  }
1156 }
1157 
1158 ////////////////////////////////////////////////////////////////////////////////
1159 /// Called when system starts idleing.
1160 
1162 {
1163  if (fIdleTimer) {
1164  fIdleTimer->Reset();
1166  }
1167 }
1168 
1169 ////////////////////////////////////////////////////////////////////////////////
1170 /// Called when system stops idleing.
1171 
1173 {
1174  if (fIdleTimer)
1176 }
1177 
1178 ////////////////////////////////////////////////////////////////////////////////
1179 /// What to do when tab is pressed. Re-implemented by TRint.
1180 /// See TTabCom::Hook() for meaning of return values.
1181 
1182 Int_t TApplication::TabCompletionHook(char* /*buf*/, int* /*pLoc*/, std::ostream& /*out*/)
1183 {
1184  return -1;
1185 }
1186 
1187 
1188 ////////////////////////////////////////////////////////////////////////////////
1189 /// Terminate the application by call TSystem::Exit() unless application has
1190 /// been told to return from Run(), by a call to SetReturnFromRun().
1191 
1193 {
1194  Emit("Terminate(Int_t)", status);
1195 
1196  if (fReturnFromRun)
1197  gSystem->ExitLoop();
1198  else {
1199  //close TMemStat
1200  if (fUseMemstat) {
1201  ProcessLine("TMemStat::Close()");
1202  fUseMemstat = kFALSE;
1203  }
1204 
1205  gSystem->Exit(status);
1206  }
1207 }
1208 
1209 ////////////////////////////////////////////////////////////////////////////////
1210 /// Emit signal when a line has been processed.
1211 
1213 {
1214  Emit("LineProcessed(const char*)", line);
1215 }
1216 
1217 ////////////////////////////////////////////////////////////////////////////////
1218 /// Emit signal when console keyboard key was pressed.
1219 
1221 {
1222  Emit("KeyPressed(Int_t)", key);
1223 }
1224 
1225 ////////////////////////////////////////////////////////////////////////////////
1226 /// Emit signal when return key was pressed.
1227 
1229 {
1230  Emit("ReturnPressed(char*)", text);
1231 }
1232 
1233 ////////////////////////////////////////////////////////////////////////////////
1234 /// Set console echo mode:
1235 ///
1236 /// - mode = kTRUE - echo input symbols
1237 /// - mode = kFALSE - noecho input symbols
1238 
1240 {
1241 }
1242 
1243 ////////////////////////////////////////////////////////////////////////////////
1244 /// Static function used to create a default application environment.
1245 
1247 {
1249  // gApplication is set at the end of 'new TApplication.
1250  if (!gApplication) {
1251  char *a = StrDup("RootApp");
1252  char *b = StrDup("-b");
1253  char *argv[2];
1254  Int_t argc = 2;
1255  argv[0] = a;
1256  argv[1] = b;
1257  new TApplication("RootApp", &argc, argv, 0, 0);
1258  if (gDebug > 0)
1259  Printf("<TApplication::CreateApplication>: "
1260  "created default TApplication");
1261  delete [] a; delete [] b;
1262  gApplication->SetBit(kDefaultApplication);
1263  }
1264 }
1265 
1266 ////////////////////////////////////////////////////////////////////////////////
1267 /// Static function used to attach to an existing remote application
1268 /// or to start one.
1269 
1271  Int_t debug, const char *script)
1272 {
1273  TApplication *ap = 0;
1274  TUrl nu(url);
1275  Int_t nnew = 0;
1276 
1277  // Look among the existing ones
1278  if (fgApplications) {
1279  TIter nxa(fgApplications);
1280  while ((ap = (TApplication *) nxa())) {
1281  TString apn(ap->ApplicationName());
1282  if (apn == url) {
1283  // Found matching application
1284  return ap;
1285  } else {
1286  // Check if same machine and user
1287  TUrl au(apn);
1288  if (strlen(au.GetUser()) > 0 && strlen(nu.GetUser()) > 0 &&
1289  !strcmp(au.GetUser(), nu.GetUser())) {
1290  if (!strncmp(au.GetHost(), nu.GetHost(), strlen(nu.GetHost())))
1291  // New session on a known machine
1292  nnew++;
1293  }
1294  }
1295  }
1296  } else {
1297  ::Error("TApplication::Open", "list of applications undefined - protocol error");
1298  return ap;
1299  }
1300 
1301  // If new session on a known machine pass the number as option
1302  if (nnew > 0) {
1303  nnew++;
1304  nu.SetOptions(Form("%d", nnew));
1305  }
1306 
1307  // Instantiate the TApplication object to be run
1308  TPluginHandler *h = 0;
1309  if ((h = gROOT->GetPluginManager()->FindHandler("TApplication","remote"))) {
1310  if (h->LoadPlugin() == 0) {
1311  ap = (TApplication *) h->ExecPlugin(3, nu.GetUrl(), debug, script);
1312  } else {
1313  ::Error("TApplication::Open", "failed to load plugin for TApplicationRemote");
1314  }
1315  } else {
1316  ::Error("TApplication::Open", "failed to find plugin for TApplicationRemote");
1317  }
1318 
1319  // Add to the list
1320  if (ap && !(ap->TestBit(kInvalidObject))) {
1321  fgApplications->Add(ap);
1322  gROOT->GetListOfBrowsables()->Add(ap, ap->ApplicationName());
1323  TIter next(gROOT->GetListOfBrowsers());
1324  TBrowser *b;
1325  while ((b = (TBrowser*) next()))
1326  b->Add(ap, ap->ApplicationName());
1327  gROOT->RefreshBrowsers();
1328  } else {
1329  SafeDelete(ap);
1330  ::Error("TApplication::Open",
1331  "TApplicationRemote for %s could not be instantiated", url);
1332  }
1333 
1334  // Done
1335  return ap;
1336 }
1337 
1338 ////////////////////////////////////////////////////////////////////////////////
1339 /// Static function used to close a remote application
1340 
1342 {
1343  if (app) {
1344  app->Terminate(0);
1345  fgApplications->Remove(app);
1346  gROOT->GetListOfBrowsables()->RecursiveRemove(app);
1347  TIter next(gROOT->GetListOfBrowsers());
1348  TBrowser *b;
1349  while ((b = (TBrowser*) next()))
1350  b->RecursiveRemove(app);
1351  gROOT->RefreshBrowsers();
1352  }
1353 }
1354 
1355 ////////////////////////////////////////////////////////////////////////////////
1356 /// Show available sessions
1357 
1358 void TApplication::ls(Option_t *opt) const
1359 {
1360  if (fgApplications) {
1361  TIter nxa(fgApplications);
1362  TApplication *a = 0;
1363  while ((a = (TApplication *) nxa())) {
1364  a->Print(opt);
1365  }
1366  } else {
1367  Print(opt);
1368  }
1369 }
1370 
1371 ////////////////////////////////////////////////////////////////////////////////
1372 /// Static method returning the list of available applications
1373 
1375 {
1376  return fgApplications;
1377 }
const char * GetHost() const
Definition: TUrl.h:76
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Definition: TSystem.cxx:1265
virtual void LoadGraphicsLibs()
Load shared libs necessary for graphics.
std::istream & ReadFile(std::istream &str)
Replace string with the contents of strm, stopping at an EOF.
Definition: Stringio.cxx:28
R__EXTERN TGuiFactory * gBatchGuiFactory
Definition: TGuiFactory.h:69
virtual Long_t ProcessLine(const char *line, Bool_t sync=kFALSE, Int_t *error=0)
Process a single command line, either a C++ statement or an interpreter command starting with a &quot;...
Semi-Abstract base class defining a generic interface to the underlying, low level, native graphics backend (X11, Win32, MacOS, OpenGL...).
Definition: TVirtualX.h:70
virtual TString SplitAclicMode(const char *filename, TString &mode, TString &args, TString &io) const
This method split a filename of the form: ~~~ {.cpp} [path/]macro.C[+|++[k|f|g|O|c|s|d|v|-]][(args)]...
Definition: TSystem.cxx:4064
An array of TObjects.
Definition: TObjArray.h:39
const char * GetIdleCommand() const
Definition: TApplication.h:124
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:2829
Bool_t fReturnFromRun
Definition: TApplication.h:68
static Bool_t fgGraphInit
Definition: TApplication.h:81
virtual const char * WorkingDirectory()
Return working directory.
Definition: TSystem.cxx:866
char * Compress(const char *str)
Remove all blanks from the string str.
Definition: TString.cxx:2528
void Reset()
Reset the timer.
Definition: TTimer.cxx:157
virtual void NotifyApplicationCreated()
Hook to tell TSystem that the TApplication object has been created.
Definition: TSystem.cxx:316
Ssiz_t Length() const
Definition: TString.h:390
TLine * line
Collectable string class.
Definition: TObjString.h:32
R__EXTERN TClassTable * gClassTable
Definition: TClassTable.h:97
const char Option_t
Definition: RtypesCore.h:62
static const std::string comment("comment")
virtual void Delete(Option_t *option="")
Remove all objects from the array AND delete all heap based objects.
Definition: TObjArray.cxx:329
R__EXTERN TVirtualMutex * gInterpreterMutex
Definition: TInterpreter.h:46
This class represents a WWW compatible URL.
Definition: TUrl.h:41
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:635
R__EXTERN TStyle * gStyle
Definition: TStyle.h:418
int GetPathInfo(const char *path, Long_t *id, Long_t *size, Long_t *flags, Long_t *modtime)
Get info about a file: id, size, flags, modification time.
Definition: TSystem.cxx:1363
const char * GetProtocol() const
Definition: TUrl.h:73
TH1 * h
Definition: legend2.C:5
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:899
virtual void MakeBatch()
Switch to batch mode.
TString fIdleCommand
Definition: TApplication.h:75
virtual Bool_t ChangeDirectory(const char *path)
Change directory.
Definition: TSystem.cxx:857
#define gROOT
Definition: TROOT.h:379
Int_t LoadPlugin()
Load the plugin library for this handler.
Basic string class.
Definition: TString.h:137
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1089
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual TTimer * RemoveTimer(TTimer *t)
Remove timer from list of system timers.
Definition: TSystem.cxx:486
static Bool_t fgGraphNeeded
Definition: TApplication.h:80
TArc * a
Definition: textangle.C:12
R__EXTERN TVirtualMutex * gROOTMutex
Definition: TROOT.h:63
EExitOnException fExitOnException
Definition: TApplication.h:78
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual void ReturnPressed(char *text)
Emit signal when return key was pressed.
#define gInterpreter
Definition: TInterpreter.h:517
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
Definition: TSystem.cxx:1511
virtual void Terminate(Int_t status=0)
Terminate the application by call TSystem::Exit() unless application has been told to return from Run...
R__EXTERN TApplication * gApplication
Definition: TApplication.h:171
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:558
Bool_t fNoLogo
Definition: TApplication.h:70
TString & Insert(Ssiz_t pos, const char *s)
Definition: TString.h:592
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:739
static const char * GetMacroPath()
Get macro search path. Static utility function.
Definition: TROOT.cxx:2549
const char * Data() const
Definition: TString.h:349
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition: TObject.cxx:953
null_t< F > null()
#define SafeDelete(p)
Definition: RConfig.h:507
TString fWorkDir
Definition: TApplication.h:74
Double_t x[n]
Definition: legend1.C:17
virtual TApplicationImp * CreateApplicationImp(const char *classname, int *argc, char **argv)
Create a batch version of TApplicationImp.
Definition: TGuiFactory.cxx:48
virtual void SetIdleTimer(UInt_t idleTimeInSec, const char *command)
Set the command to be executed after the system has been idle for idleTimeInSec seconds.
virtual void Run(Bool_t retrn=kFALSE)
Main application eventloop. Calls system dependent eventloop via gSystem.
static Bool_t Initialized()
Return kTRUE if the TROOT object has been initialized.
Definition: TROOT.cxx:2604
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:118
static const TString & GetDocDir()
Get the documentation directory in the installation. Static utility function.
Definition: TROOT.cxx:2792
virtual void ExitLoop()
Exit from event loop.
Definition: TSystem.cxx:397
Int_t Atoi() const
Return integer value of string.
Definition: TString.cxx:1965
XFontStruct * id
Definition: TGX11.cxx:108
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:925
static void CallEndOfProcessCleanups()
R__EXTERN TGuiFactory * gGuiFactory
Definition: TGuiFactory.h:68
void Error(const char *location, const char *msgfmt,...)
void Emit(const char *signal)
Acitvate signal without args.
Definition: TQObject.cxx:561
virtual void GetOptions(Int_t *argc, char **argv)
Get and handle command line options.
virtual Bool_t Notify()
Notify when timer times out.
Definition: TTimer.cxx:143
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
Definition: TObject.cxx:595
A doubly linked list.
Definition: TList.h:47
char ** Argv() const
Definition: TApplication.h:142
static TList * GetApplications()
Static method returning the list of available applications.
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:41
virtual void Open()
Definition: TApplication.h:133
R__EXTERN TVirtualX * gGXBatch
Definition: TVirtualX.h:365
Bool_t fIsRunning
Window system specific application implementation.
Definition: TApplication.h:67
TObjArray * fFiles
Definition: TApplication.h:73
void ClearInputFiles()
Clear list containing macro files passed as program arguments.
virtual void RemoveIdleTimer()
Remove idle timer. Normally called via TROOT::Idle(0).
static void NeedGraphicsLibs()
Static method.
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
if object ctor succeeded but object should not be used
Definition: TObject.h:63
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:675
void SetScreenFactor(Float_t factor=1)
Definition: TStyle.h:310
char * Strip(const char *str, char c= ' ')
Strip leading and trailing c (blanks by default) from a string.
Definition: TString.cxx:2478
static Long_t ExecuteFile(const char *file, Int_t *error=0, Bool_t keep=kFALSE)
Execute a file containing a C++ macro (static method).
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition: TString.cxx:2322
unsigned int UInt_t
Definition: RtypesCore.h:42
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:157
char * Form(const char *fmt,...)
Bool_t fUseMemstat
Definition: TApplication.h:72
TApplicationImp * fAppImp
Definition: TApplication.h:66
virtual void SetEchoMode(Bool_t mode)
Set console echo mode:
Handles synchronous and a-synchronous timer events.
Definition: TTimer.h:57
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
virtual void StopIdleing()
Called when system stops idleing.
virtual void Abort(int code=0)
Abort the application.
Definition: TSystem.cxx:729
TApplication * fAppRemote
Definition: TApplication.h:87
Bool_t IsNull() const
Definition: TString.h:387
virtual TObjLink * FirstLink() const
Definition: TList.h:101
void Reset(Detail::TBranchProxy *x)
static void Close(TApplication *app)
Static function used to close a remote application.
#define gVirtualX
Definition: TVirtualX.h:362
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
Definition: TString.cxx:2241
virtual void Run()
System event loop.
Definition: TSystem.cxx:348
#define Printf
Definition: TGeoToOCC.h:18
char * StrDup(const char *str)
Duplicate the string str.
Definition: TString.cxx:2514
virtual void Help(const char *line)
Print help on interpreter.
#define R__LOCKGUARD2(mutex)
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
Definition: TUrl.cxx:387
static void CreateApplication()
Static function used to create a default application environment.
void InitializeGraphics()
Initialize the graphics environment.
TString & Remove(Ssiz_t pos)
Definition: TString.h:616
long Long_t
Definition: RtypesCore.h:50
int Ssiz_t
Definition: RtypesCore.h:63
R__EXTERN ExceptionContext_t * gException
Definition: TException.h:78
virtual void StartIdleing()
Called when system starts idleing.
Bool_t fNoLog
Definition: TApplication.h:69
#define ClassImp(name)
Definition: Rtypes.h:279
TText * text
static DictFuncPtr_t GetDict(const char *cname)
Given the class name returns the Dictionary() function of a class (uses hash of name).
virtual void KeyPressed(Int_t key)
Emit signal when console keyboard key was pressed.
R__EXTERN TEnv * gEnv
Definition: TEnv.h:174
TTimer(const TTimer &)
Double_t y[n]
Definition: legend1.C:17
virtual void SetProgname(const char *name)
Set the application name (from command line, argv[0]) and copy it in gProgName.
Definition: TSystem.cxx:228
TTimer * fIdleTimer
Definition: TApplication.h:76
virtual void LineProcessed(const char *line)
Emit signal when a line has been processed.
bool EndsWith(const std::string &theString, const std::string &theSubstring)
char ** fArgv
Definition: TApplication.h:65
virtual Int_t TabCompletionHook(char *buf, int *pLoc, std::ostream &out)
What to do when tab is pressed.
EExitOnException ExitOnException(EExitOnException opt=kExit)
Set the exit on exception option.
void Throw(int code)
If an exception context has been set (using the TRY and RETRY macros) jump back to where it was set...
Definition: TException.cxx:27
This ABC is a factory for GUI components.
Definition: TGuiFactory.h:44
virtual void HandleIdleTimer()
Handle idle timeout.
virtual void HandleException(Int_t sig)
Handle exceptions (kSigBus, kSigSegmentationViolation, kSigIllegalInstruction and kSigFloatingExcepti...
virtual void Add(TObject *obj)
Definition: TList.h:81
virtual void AddTimer(TTimer *t)
Add timer to list of system timers.
Definition: TSystem.cxx:476
virtual void Exit(int code, Bool_t mode=kTRUE)
Exit the application.
Definition: TSystem.cxx:721
void SetOptions(const char *opt)
Definition: TUrl.h:96
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
#define gPad
Definition: TVirtualPad.h:289
R__EXTERN Int_t gDebug
Definition: Rtypes.h:128
bool debug
void Add(TObject *obj)
Definition: TObjArray.h:75
#define gDirectory
Definition: TDirectory.h:221
static void InitializeColors()
Initialize colors used by the TCanvas based graphics (via TColor objects).
Definition: TColor.cxx:1048
void ResetBit(UInt_t f)
Definition: TObject.h:156
This class creates the ROOT Application Environment that interfaces to the windowing system eventloop...
Definition: TApplication.h:45
Bool_t fQuit
Definition: TApplication.h:71
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition: TSystem.cxx:1243
static TList * fgApplications
Definition: TApplication.h:89
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:582
void SetReturnFromRun(Bool_t ret)
Definition: TApplication.h:155
virtual const char * ApplicationName() const
Definition: TApplication.h:129
const Bool_t kTRUE
Definition: Rtypes.h:91
const Int_t n
Definition: legend1.C:16
const char * GetUser() const
Definition: TUrl.h:74
char name[80]
Definition: TGX11.cxx:109
const char * GetFile() const
Definition: TUrl.h:78
virtual Long_t ProcessFile(const char *file, Int_t *error=0, Bool_t keep=kFALSE)
Process a file containing a C++ macro.
virtual void ls(Option_t *option="") const
Show available sessions.
TApplication()
Default ctor. Can be used by classes deriving from TApplication.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:911