22#include "RConfigure.h"
47#include "TApplicationCommandLineOptionsHelp.h"
58class TIdleTimer :
public TTimer {
88 gROOT->EndOfProcessCleanups();
96 fArgc(0), fArgv(0), fAppImp(0), fIsRunning(
kFALSE), fReturnFromRun(
kFALSE),
98 fFiles(0), fIdleTimer(0), fSigHandler(0), fExitOnException(kDontExit),
119 void * ,
Int_t numOptions) :
120 fArgc(0), fArgv(0), fAppImp(0), fIsRunning(
kFALSE), fReturnFromRun(
kFALSE),
122 fFiles(0), fIdleTimer(0), fSigHandler(0), fExitOnException(kDontExit),
146 Error(
"TApplication",
"only one instance of TApplication allowed");
152 ::Fatal(
"TApplication::TApplication",
"ROOT system not initialized");
155 ::Fatal(
"TApplication::TApplication",
"gSystem not initialized");
158 if (!hasRegisterAtExit) {
161 hasRegisterAtExit =
kTRUE;
163 gROOT->SetName(appClassName);
166 if (argc && *argc > 0) {
171 for (
int i = 0; i <
fArgc; i++)
197 gROOT->SetLineHasBeenProcessed();
204 const char *ssystem =
gEnv->
GetValue(
"Root.TMemStat.system",
"gnubuiltin");
206 gROOT->ProcessLine(
Form(
"new TMemStat(\"%s\",%d,%d);",ssystem,buffersize,maxcalls));
212 gROOT->SetApplication(
this);
221 for (
int i = 0; i <
fArgc; i++)
275#if !defined(R__WIN32)
285 if ((
h =
gROOT->GetPluginManager()->FindHandler(
"TVirtualX",
"x11ttf")))
286 if (
h->LoadPlugin() == -1)
287 Info(
"InitializeGraphics",
"no TTF support");
340 if (index >=
fArgc) {
341 Error(
"Argv",
"index (%d) >= number of arguments (%d)", index,
fArgc);
355 static char null[1] = {
"" };
367 for (i = 1; i < *argc; i++) {
368 if (!strcmp(argv[i],
"-?") || !strncmp(argv[i],
"-h", 2) ||
369 !strncmp(argv[i],
"--help", 6)) {
370 fprintf(stderr, kCommandLineOptionsHelp);
372 }
else if (!strncmp(argv[i],
"--version", 9)) {
373 fprintf(stderr,
"ROOT Version: %s\n",
gROOT->GetVersion());
374 fprintf(stderr,
"Built for %s on %s\n",
376 gROOT->GetGitDate());
378 fprintf(stderr,
"From %s@%s\n",
379 gROOT->GetGitBranch(),
380 gROOT->GetGitCommit());
383 }
else if (!strcmp(argv[i],
"-config")) {
384 fprintf(stderr,
"ROOT ./configure options:\n%s\n",
gROOT->GetConfigOptions());
386 }
else if (!strcmp(argv[i],
"-memstat")) {
389 }
else if (!strcmp(argv[i],
"-b")) {
392 }
else if (!strcmp(argv[i],
"-n")) {
395 }
else if (!strcmp(argv[i],
"-t")) {
401 }
else if (!strcmp(argv[i],
"-q")) {
404 }
else if (!strcmp(argv[i],
"-l")) {
408 }
else if (!strcmp(argv[i],
"-x")) {
411 }
else if (!strcmp(argv[i],
"-splash")) {
415 }
else if (strncmp(argv[i],
"--web", 5) == 0) {
417 const char *opt = argv[i] + 5;
420 if (
gROOT->IsBatch()) argw =
"batch";
421 if (*opt ==
'=') argw.
Append(opt+1);
426 Error(
"GetOptions",
"--web option not supported, ROOT should be built with at least c++14 enabled");
428 }
else if (!strcmp(argv[i],
"-e")) {
439 Warning(
"GetOptions",
"-e must be followed by an expression.");
441 }
else if (!strcmp(argv[i],
"--")) {
443 bool warnShown =
false;
449 if (!
dynamic_cast<TNamed*
>(
f)) {
450 Error(
"GetOptions()",
"Inconsistent file entry (not a TObjString)!");
458 if (
file->String().EndsWith(
".root"))
460 if (
file->String().Contains(
'('))
463 if (macro && !warnShown && (warnShown =
true))
464 Warning(
"GetOptions",
"-- is used with several macros. "
465 "The arguments will be passed to the last one.");
477 for (; i < *argc; i++) {
484 Warning(
"GetOptions",
"no macro to pass arguments to was provided. "
485 "Everything after the -- will be ignored.");
486 for (; i < *argc; i++)
489 }
else if (argv[i][0] !=
'-' && argv[i][0] !=
'+') {
492 char *arg = strchr(argv[i],
'(');
493 if (arg) *arg =
'\0';
517 }
else if (!strcmp(
gROOT->GetName(),
"Rint")) {
518 Warning(
"GetOptions",
"only one directory argument can be specified (%s)", dir);
520 }
else if (size > 0) {
526 Warning(
"GetOptions",
"file %s has size 0, skipping", dir);
533 if (!strcmp(
gROOT->GetName(),
"Rint"))
534 Warning(
"GetOptions",
"file %s not found", dir);
557 if (!strcmp(
gROOT->GetName(),
"Rint"))
558 Warning(
"GetOptions",
"macro %s not found", fname.
Data());
573 for (i = 0; i < *argc; i++) {
574 if (strcmp(argv[i],
"")) {
592 Emit(
"HandleIdleTimer()");
638 Printf(
"\nROOT special commands.");
639 Printf(
"===========================================================================");
640 Printf(
" pwd : show current directory, pad and style");
641 Printf(
" ls : list contents of current directory");
642 Printf(
" which [file] : shows path of macro file");
651 if (
gROOT->IsBatch())
return;
654 if ((
h =
gROOT->GetPluginManager()->FindHandler(
"TVirtualPad")))
655 if (
h->LoadPlugin() == -1)
659 TString title1 =
"ROOT interface to ";
664 nativex =
"win32gdk";
666 title = title1 +
"Win32gdk";
667#elif defined(R__HAS_COCOA)
670 title = title1 +
"Quartz";
674 title = title1 +
"X11";
679 if (guiBackend ==
"native") {
680 guiBackend = nativex;
683 title = title1 + guiBackend;
687 if (guiFactory ==
"native")
688 guiFactory = nativeg;
690 if ((
h =
gROOT->GetPluginManager()->FindHandler(
"TVirtualX", guiBackend))) {
691 if (
h->LoadPlugin() == -1) {
698 if ((
h =
gROOT->GetPluginManager()->FindHandler(
"TGuiFactory", guiFactory))) {
699 if (
h->LoadPlugin() == -1) {
738 if (!ln || strlen(ln) <= 0)
750 while (
line.Tokenize(tkn, from,
" ")) {
754 }
else if (tkn ==
"-d") {
756 }
else if (tkn ==
"-close") {
759 ::Warning(
"TApplication::ParseRemoteLine",
"unknown option: %s", tkn.
Data());
767 }
else if (isHostDir) {
772 }
else if (isScript) {
804 if (!strncmp(
line,
"-?", 2) || !strncmp(
line,
"-h", 2) ||
805 !strncmp(
line,
"--help", 6)) {
806 Info(
"ProcessRemote",
"remote session help:");
807 Printf(
".R [user@]host[:dir] [-l user] [-d dbg] [[<]script] | [host] -close");
808 Printf(
"Create a ROOT session on the specified remote host.");
809 Printf(
"The variable \"dir\" is the remote directory to be used as working dir.");
810 Printf(
"The username can be specified in two ways, \"-l\" having the priority");
811 Printf(
"(as in ssh). A \"dbg\" value > 0 gives increasing verbosity.");
812 Printf(
"The last argument \"script\" allows to specify an alternative script to");
813 Printf(
"be executed remotely to startup the session, \"roots\" being");
814 Printf(
"the default. If the script is preceded by a \"<\" the script will be");
815 Printf(
"sourced, after which \"roots\" is executed. The sourced script can be ");
816 Printf(
"used to change the PATH and other variables, allowing an alternative");
817 Printf(
"\"roots\" script to be found.");
818 Printf(
"To close down a session do \".R host -close\".");
819 Printf(
"To switch between sessions do \".R host\", to switch to the local");
820 Printf(
"session do \".R\".");
821 Printf(
"To list all open sessions do \"gApplication->GetApplications()->Print()\".");
828 if (hostdir.
Length() <= 0) {
838 }
else if (rc == 1) {
849 const char *sc = (script.
Length() > 0) ? script.
Data() : 0;
860 static int PrintFile(
const char* filename) {
864 Error(
"ProcessLine()",
"Cannot find file %s", filename);
867 std::ifstream instr(sFileName);
885 if (!strncmp(
line,
".R", 2)) {
887 while (*(
line+
n) ==
' ')
898 if (!strncasecmp(
line,
".qqqqqqq", 7)) {
900 }
else if (!strncasecmp(
line,
".qqqqq", 5)) {
901 Info(
"ProcessLine",
"Bye... (try '.qqqqqqq' if still running)");
903 }
else if (!strncasecmp(
line,
".exit", 4) || !strncasecmp(
line,
".quit", 2)) {
908 if (!strncmp(
line,
".?", 2) || !strncmp(
line,
".help", 5)) {
913 if (!strncmp(
line,
".demo", 5)) {
914 if (
gROOT->IsBatch()) {
915 Error(
"ProcessLine",
"Cannot show demos in batch mode!");
922 if (!strncmp(
line,
".license", 8)) {
926 if (!strncmp(
line,
".credits", 8)) {
930 return PrintFile(credits);
933 if (!strncmp(
line,
".pwd", 4)) {
943 if (!strncmp(
line,
".ls", 3)) {
950 if (!strncmp(
line,
".which", 6)) {
952 char *
s = strtok(fn,
"+(");
963 if (!strncmp(
line,
".L", 2) || !strncmp(
line,
".U", 2)) {
971 Warning(
"ProcessLine",
"argument(s) \"%s\" ignored with .%c", arguments.
Data(),
976 Error(
"ProcessLine",
"macro %s not found in path %s", fname.
Data(),
981 if (posSpace == -1) cmd.
Remove(1);
982 else cmd.
Remove(posSpace);
1002 if (!strncmp(
line,
".X", 2) || !strncmp(
line,
".x", 2)) {
1006 if (!strcmp(
line,
".reset")) {
1008 Printf(
"*** .reset not allowed, please use gROOT->Reset() ***");
1014 gROOT->GetListOfClasses()->Delete();
1039 static const Int_t kBufSize = 1024;
1050 ::Error(
"TApplication::ExecuteFile",
"macro %s not found in path %s", fname.
Data(),
1058 ::std::ifstream macro(exnam, std::ios::in);
1059 if (!macro.good()) {
1060 ::Error(
"TApplication::ExecuteFile",
"%s no such file", exnam);
1067 char currentline[kBufSize];
1068 char dummyline[kBufSize];
1078 bool res = (bool)macro.getline(currentline, kBufSize);
1079 if (macro.eof())
break;
1084 while (!macro.getline(dummyline, kBufSize) && !macro.eof()) {
1089 while (
s && (*
s ==
' ' || *
s ==
'\t'))
s++;
1096 if (strstr(cs,
"#ifndef__CINT__") ||
1097 strstr(cs,
"#if!defined(__CINT__)"))
1099 else if (ifndefc && (strstr(cs,
"#ifdef") || strstr(cs,
"#ifndef") ||
1100 strstr(cs,
"#ifdefined") || strstr(cs,
"#if!defined")))
1102 else if (ifndefc && strstr(cs,
"#endif")) {
1107 }
else if (ifndefc && !ifdef && strstr(cs,
"#else"))
1111 if (!*
s || *
s ==
'#' || ifndefc || !strncmp(
s,
"//", 2))
continue;
1113 if (!comment && (!strncmp(
s,
".X", 2) || !strncmp(
s,
".x", 2))) {
1119 if (!strncmp(
s,
"/*", 2)) comment = 1;
1123 s = strstr(
s,
"*/");
1128 while (
s && (*
s ==
' ' || *
s ==
'\t'))
s++;
1130 if (!strncmp(
s,
"//", 2))
continue;
1131 if (!strncmp(
s,
"/*", 2)) {
1137 if (!comment && *
s ==
'{') tempfile = 1;
1138 if (!comment)
break;
1147 exname += aclicMode;
1149 exname += arguments;
1154 tempbuf.
Form(
".x %s", exname.
Data());
1156 tempbuf.
Form(
".X%s %s", keep ?
"k" :
" ", exname.
Data());
1186 fIdleTimer =
new TIdleTimer(idleTimeInSec*1000);
1237 Emit(
"Terminate(Int_t)", status);
1257 Emit(
"LineProcessed(const char*)",
line);
1265 Emit(
"KeyPressed(Int_t)", key);
1273 Emit(
"ReturnPressed(char*)",
text);
1302 Printf(
"<TApplication::CreateApplication>: "
1303 "created default TApplication");
1304 delete []
a;
delete []
b;
1314 Int_t debug,
const char *script)
1340 ::Error(
"TApplication::Open",
"list of applications undefined - protocol error");
1352 if ((
h =
gROOT->GetPluginManager()->FindHandler(
"TApplication",
"remote"))) {
1353 if (
h->LoadPlugin() == 0) {
1356 ::Error(
"TApplication::Open",
"failed to load plugin for TApplicationRemote");
1359 ::Error(
"TApplication::Open",
"failed to find plugin for TApplicationRemote");
1370 gROOT->RefreshBrowsers();
1374 "TApplicationRemote for %s could not be instantiated", url);
1389 gROOT->GetListOfBrowsables()->RecursiveRemove(app);
1393 b->RecursiveRemove(app);
1394 gROOT->RefreshBrowsers();
static void CallEndOfProcessCleanups()
TApplication * gApplication
R__EXTERN TClassTable * gClassTable
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.
R__EXTERN ExceptionContext_t * gException
R__EXTERN TGuiFactory * gBatchGuiFactory
R__EXTERN TGuiFactory * gGuiFactory
R__EXTERN TVirtualMutex * gInterpreterMutex
R__EXTERN TVirtualMutex * gROOTMutex
char * Compress(const char *str)
Remove all blanks from the string str.
char * Form(const char *fmt,...)
char * Strip(const char *str, char c=' ')
Strip leading and trailing c (blanks by default) from a string.
void Printf(const char *fmt,...)
char * StrDup(const char *str)
Duplicate the string str.
R__EXTERN TStyle * gStyle
R__EXTERN TSystem * gSystem
#define R__LOCKGUARD(mutex)
R__EXTERN TVirtualX * gGXBatch
This class creates the ROOT Application Environment that interfaces to the windowing system eventloop...
EExitOnException ExitOnException(EExitOnException opt=kExit)
Set the exit on exception option.
virtual void KeyPressed(Int_t key)
Emit signal when console keyboard key was pressed.
static TList * fgApplications
static void Close(TApplication *app)
Static function used to close a remote application.
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 SetEchoMode(Bool_t mode)
Set console echo mode:
virtual void Help(const char *line)
Print help on interpreter.
virtual void LineProcessed(const char *line)
Emit signal when a line has been processed.
void ClearInputFiles()
Clear list containing macro files passed as program arguments.
TApplicationImp * fAppImp
virtual void LoadGraphicsLibs()
Load shared libs necessary for graphics.
virtual void StopIdleing()
Called when system stops idleing.
virtual void StartIdleing()
Called when system starts idleing.
virtual void Run(Bool_t retrn=kFALSE)
Main application eventloop. Calls system dependent eventloop via gSystem.
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.
void InitializeGraphics()
Initialize the graphics environment.
static Bool_t fgGraphNeeded
virtual void Terminate(Int_t status=0)
Terminate the application by call TSystem::Exit() unless application has been told to return from Run...
virtual const char * ApplicationName() const
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 SetReturnFromRun(Bool_t ret)
virtual Int_t TabCompletionHook(char *buf, int *pLoc, std::ostream &out)
What to do when tab is pressed.
EExitOnException fExitOnException
const char * GetIdleCommand() const
virtual void ls(Option_t *option="") const
Show available sessions.
TApplication()
Default ctor. Can be used by classes deriving from TApplication.
virtual void ReturnPressed(char *text)
Emit signal when return key was pressed.
static Bool_t fgGraphInit
virtual void RemoveIdleTimer()
Remove idle timer. Normally called via TROOT::Idle(0).
virtual void SetIdleTimer(UInt_t idleTimeInSec, const char *command)
Set the command to be executed after the system has been idle for idleTimeInSec seconds.
static void CreateApplication()
Static function used to create a default application environment.
virtual void GetOptions(Int_t *argc, char **argv)
Get and handle command line options.
static TList * GetApplications()
Static method returning the list of available applications.
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 "....
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.
virtual void HandleIdleTimer()
Handle idle timeout.
virtual Long_t ProcessFile(const char *file, Int_t *error=0, Bool_t keep=kFALSE)
Process a file containing a C++ macro.
TApplication * fAppRemote
Using a TBrowser one can browse all ROOT objects.
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).
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
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.
This ABC is a factory for GUI components.
virtual TApplicationImp * CreateApplicationImp(const char *classname, int *argc, char **argv)
Create a batch version of TApplicationImp.
virtual void Add(TObject *obj)
virtual TObject * Remove(TObject *obj)
Remove object from the list.
virtual TObjLink * FirstLink() const
The TNamed class is the base class for all named ROOT classes.
virtual const char * GetName() const
Returns name of object.
virtual void Delete(Option_t *option="")
Remove all objects from the array AND delete all heap based objects.
Collectable string class.
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
@ kInvalidObject
if object ctor succeeded but object should not be used
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
static const char * GetMacroPath()
Get macro search path. Static utility function.
static void ShutDown()
Shut down ROOT.
static const TString & GetTTFFontDir()
Get the fonts directory in the installation. Static utility function.
static Bool_t Initialized()
Return kTRUE if the TROOT object has been initialized.
static const TString & GetTutorialDir()
Get the tutorials directory in the installation. Static utility function.
static const TString & GetDocDir()
Get the documentation directory in the installation. Static utility function.
void ToLower()
Change string to lower-case.
TString & Insert(Ssiz_t pos, const char *s)
Int_t Atoi() const
Return integer value of string.
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
const char * Data() const
TString & ReplaceAll(const TString &s1, const TString &s2)
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
std::istream & ReadFile(std::istream &str)
Replace string with the contents of strm, stopping at an EOF.
TString & Remove(Ssiz_t pos)
TString & Append(const char *cs)
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
void SetScreenFactor(Float_t factor=1)
virtual void NotifyApplicationCreated()
Hook to tell TSystem that the TApplication object has been created.
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
virtual TString SplitAclicMode(const char *filename, TString &mode, TString &args, TString &io) const
This method split a filename of the form:
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
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.
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
virtual void Run()
System event loop.
virtual void ExitLoop()
Exit from event loop.
virtual Bool_t ChangeDirectory(const char *path)
Change directory.
virtual void AddTimer(TTimer *t)
Add timer to list of system timers.
virtual void Exit(int code, Bool_t mode=kTRUE)
Exit the application.
virtual const char * WorkingDirectory()
Return working directory.
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
virtual void SetProgname(const char *name)
Set the application name (from command line, argv[0]) and copy it in gProgName.
virtual const char * GetBuildArch() const
Return the build architecture.
virtual void Abort(int code=0)
Abort the application.
virtual TTimer * RemoveTimer(TTimer *t)
Remove timer from list of system timers.
Handles synchronous and a-synchronous timer events.
void Reset()
Reset the timer.
virtual Bool_t Notify()
Notify when timer times out.
This class represents a WWW compatible URL.
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
const char * GetFileAndOptions() const
Return the file and its options (the string specified behind the ?).
const char * GetFile() const
const char * GetUser() const
const char * GetHost() const
void SetOptions(const char *opt)
const char * GetProtocol() const
Semi-Abstract base class defining a generic interface to the underlying, low level,...
void EnableImplicitMT(UInt_t numthreads=0)
Enable ROOT's implicit multi-threading for all objects and methods that provide an internal paralleli...
void EnableThreadSafety()
Enables the global mutex to make ROOT thread safe/aware.
static constexpr double s
static constexpr double ms