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