22#include "RConfigure.h"
51#if defined(R__MACOSX) && (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
63class TIdleTimer :
public TTimer {
93 gROOT->EndOfProcessCleanups();
101 fArgc(0), fArgv(0), fAppImp(0), fIsRunning(
kFALSE), fReturnFromRun(
kFALSE),
103 fFiles(0), fIdleTimer(0), fSigHandler(0), fExitOnException(kDontExit),
124 void * ,
Int_t numOptions) :
125 fArgc(0), fArgv(0), fAppImp(0), fIsRunning(
kFALSE), fReturnFromRun(
kFALSE),
127 fFiles(0), fIdleTimer(0), fSigHandler(0), fExitOnException(kDontExit),
151 Error(
"TApplication",
"only one instance of TApplication allowed");
157 ::Fatal(
"TApplication::TApplication",
"ROOT system not initialized");
160 ::Fatal(
"TApplication::TApplication",
"gSystem not initialized");
163 if (!hasRegisterAtExit) {
166 hasRegisterAtExit =
kTRUE;
168 gROOT->SetName(appClassName);
171 if (argc && *argc > 0) {
176 for (
int i = 0; i <
fArgc; i++)
202 gROOT->SetLineHasBeenProcessed();
209 const char *ssystem =
gEnv->
GetValue(
"Root.TMemStat.system",
"gnubuiltin");
211 gROOT->ProcessLine(
Form(
"new TMemStat(\"%s\",%d,%d);",ssystem,buffersize,maxcalls));
217 gROOT->SetApplication(
this);
226 for (
int i = 0; i <
fArgc; i++)
244 gROOT->EndOfProcessCleanups();
273#if defined(R__MACOSX) && (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
274 gVirtualX =
new ROOT::iOS::TGIOS(
"TGIOS",
"VirtualX for iOS");
289#if !defined(R__WIN32)
299 if ((
h =
gROOT->GetPluginManager()->FindHandler(
"TVirtualX",
"x11ttf")))
300 if (
h->LoadPlugin() == -1)
301 Info(
"InitializeGraphics",
"no TTF support");
355 if (index >=
fArgc) {
356 Error(
"Argv",
"index (%d) >= number of arguments (%d)", index,
fArgc);
370 static char null[1] = {
"" };
382 for (i = 1; i < *argc; i++) {
383 if (!strcmp(argv[i],
"-?") || !strncmp(argv[i],
"-h", 2) ||
384 !strncmp(argv[i],
"--help", 6)) {
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());
393 fprintf(stderr,
"From %s@%s\n",
394 gROOT->GetGitBranch(),
395 gROOT->GetGitCommit());
398 }
else if (!strcmp(argv[i],
"-config")) {
399 fprintf(stderr,
"ROOT ./configure options:\n%s\n",
gROOT->GetConfigOptions());
401 }
else if (!strcmp(argv[i],
"-memstat")) {
404 }
else if (!strcmp(argv[i],
"-b")) {
407 }
else if (!strcmp(argv[i],
"-n")) {
410 }
else if (!strcmp(argv[i],
"-t")) {
416 }
else if (!strcmp(argv[i],
"-q")) {
419 }
else if (!strcmp(argv[i],
"-l")) {
423 }
else if (!strcmp(argv[i],
"-x")) {
426 }
else if (!strcmp(argv[i],
"-splash")) {
430 }
else if (strncmp(argv[i],
"--web", 5) == 0) {
432 const char *opt = argv[i] + 5;
435 if (
gROOT->IsBatch()) argw =
"batch";
436 if (*opt ==
'=') argw.
Append(opt+1);
439 }
else if (!strcmp(argv[i],
"-e")) {
450 Warning(
"GetOptions",
"-e must be followed by an expression.");
452 }
else if (!strcmp(argv[i],
"--")) {
454 bool warnShown =
false;
460 if (!
dynamic_cast<TNamed*
>(
f)) {
461 Error(
"GetOptions()",
"Inconsistent file entry (not a TObjString)!");
469 if (
file->String().EndsWith(
".root"))
471 if (
file->String().Contains(
'('))
474 if (macro && !warnShown && (warnShown =
true))
475 Warning(
"GetOptions",
"-- is used with several macros. "
476 "The arguments will be passed to the last one.");
488 for (; i < *argc; i++) {
495 Warning(
"GetOptions",
"no macro to pass arguments to was provided. "
496 "Everything after the -- will be ignored.");
497 for (; i < *argc; i++)
500 }
else if (argv[i][0] !=
'-' && argv[i][0] !=
'+') {
502 Long_t id, flags, modtime;
503 char *arg = strchr(argv[i],
'(');
504 if (arg) *arg =
'\0';
526 }
else if (!strcmp(
gROOT->GetName(),
"Rint")) {
527 Warning(
"GetOptions",
"only one directory argument can be specified (%s)", dir);
529 }
else if (size > 0) {
535 Warning(
"GetOptions",
"file %s has size 0, skipping", dir);
542 if (!strcmp(
gROOT->GetName(),
"Rint"))
543 Warning(
"GetOptions",
"file %s not found", dir);
566 if (!strcmp(
gROOT->GetName(),
"Rint"))
567 Warning(
"GetOptions",
"macro %s not found", fname.
Data());
582 for (i = 0; i < *argc; i++) {
583 if (strcmp(argv[i],
"")) {
601 Emit(
"HandleIdleTimer()");
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");
660 if (
gROOT->IsBatch())
return;
663 if ((
h =
gROOT->GetPluginManager()->FindHandler(
"TVirtualPad")))
664 if (
h->LoadPlugin() == -1)
668 TString title1 =
"ROOT interface to ";
673 nativex =
"win32gdk";
675 title = title1 +
"Win32gdk";
676#elif defined(R__HAS_COCOA)
679 title = title1 +
"Quartz";
683 title = title1 +
"X11";
688 if (guiBackend ==
"native") {
689 guiBackend = nativex;
692 title = title1 + guiBackend;
696 if (guiFactory ==
"native")
697 guiFactory = nativeg;
699 if ((
h =
gROOT->GetPluginManager()->FindHandler(
"TVirtualX", guiBackend))) {
700 if (
h->LoadPlugin() == -1) {
707 if ((
h =
gROOT->GetPluginManager()->FindHandler(
"TGuiFactory", guiFactory))) {
708 if (
h->LoadPlugin() == -1) {
747 if (!ln || strlen(ln) <= 0)
759 while (
line.Tokenize(tkn, from,
" ")) {
763 }
else if (tkn ==
"-d") {
765 }
else if (tkn ==
"-close") {
768 ::Warning(
"TApplication::ParseRemoteLine",
"unknown option: %s", tkn.
Data());
776 }
else if (isHostDir) {
781 }
else if (isScript) {
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()\".");
837 if (hostdir.
Length() <= 0) {
847 }
else if (rc == 1) {
858 const char *sc = (script.
Length() > 0) ? script.
Data() : 0;
869 static int PrintFile(
const char* filename) {
873 Error(
"ProcessLine()",
"Cannot find file %s", filename);
876 std::ifstream instr(sFileName);
894 if (!strncmp(
line,
".R", 2)) {
896 while (*(
line+
n) ==
' ')
907 if (!strncasecmp(
line,
".qqqqqqq", 7)) {
909 }
else if (!strncasecmp(
line,
".qqqqq", 5)) {
910 Info(
"ProcessLine",
"Bye... (try '.qqqqqqq' if still running)");
912 }
else if (!strncasecmp(
line,
".exit", 4) || !strncasecmp(
line,
".quit", 2)) {
917 if (!strncmp(
line,
"?", 1) || !strncmp(
line,
".help", 5)) {
922 if (!strncmp(
line,
".demo", 5)) {
923 if (
gROOT->IsBatch()) {
924 Error(
"ProcessLine",
"Cannot show demos in batch mode!");
931 if (!strncmp(
line,
".license", 8)) {
935 if (!strncmp(
line,
".credits", 8)) {
939 return PrintFile(credits);
942 if (!strncmp(
line,
".pwd", 4)) {
952 if (!strncmp(
line,
".ls", 3)) {
959 if (!strncmp(
line,
".which", 6)) {
961 char *
s = strtok(fn,
"+(");
972 if (!strncmp(
line,
".L", 2) || !strncmp(
line,
".U", 2)) {
980 Warning(
"ProcessLine",
"argument(s) \"%s\" ignored with .%c", arguments.
Data(),
985 Error(
"ProcessLine",
"macro %s not found in path %s", fname.
Data(),
989 Ssiz_t posSpace = cmd.Index(
' ');
990 if (posSpace == -1) cmd.Remove(1);
991 else cmd.Remove(posSpace);
994 tempbuf.
Form(
".%s %s%s%s", cmd.Data(), mac, aclicMode.
Data(),io.
Data());
998 tempbuf.
Form(
".%s %s%s%s", cmd.Data(), mac, aclicMode.
Data(),io.
Data());
1011 if (!strncmp(
line,
".X", 2) || !strncmp(
line,
".x", 2)) {
1015 if (!strcmp(
line,
".reset")) {
1017 Printf(
"*** .reset not allowed, please use gROOT->Reset() ***");
1023 gROOT->GetListOfClasses()->Delete();
1048 static const Int_t kBufSize = 1024;
1059 ::Error(
"TApplication::ExecuteFile",
"macro %s not found in path %s", fname.
Data(),
1067 ::std::ifstream macro(exnam, std::ios::in);
1068 if (!macro.good()) {
1069 ::Error(
"TApplication::ExecuteFile",
"%s no such file", exnam);
1076 char currentline[kBufSize];
1077 char dummyline[kBufSize];
1087 bool res = (bool)macro.getline(currentline, kBufSize);
1088 if (macro.eof())
break;
1093 while (!macro.getline(dummyline, kBufSize) && !macro.eof()) {
1098 while (
s && (*
s ==
' ' || *
s ==
'\t'))
s++;
1105 if (strstr(cs,
"#ifndef__CINT__") ||
1106 strstr(cs,
"#if!defined(__CINT__)"))
1108 else if (ifndefc && (strstr(cs,
"#ifdef") || strstr(cs,
"#ifndef") ||
1109 strstr(cs,
"#ifdefined") || strstr(cs,
"#if!defined")))
1111 else if (ifndefc && strstr(cs,
"#endif")) {
1116 }
else if (ifndefc && !ifdef && strstr(cs,
"#else"))
1120 if (!*
s || *
s ==
'#' || ifndefc || !strncmp(
s,
"//", 2))
continue;
1122 if (!comment && (!strncmp(
s,
".X", 2) || !strncmp(
s,
".x", 2))) {
1128 if (!strncmp(
s,
"/*", 2)) comment = 1;
1132 s = strstr(
s,
"*/");
1137 while (
s && (*
s ==
' ' || *
s ==
'\t'))
s++;
1139 if (!strncmp(
s,
"//", 2))
continue;
1140 if (!strncmp(
s,
"/*", 2)) {
1146 if (!comment && *
s ==
'{') tempfile = 1;
1147 if (!comment)
break;
1156 exname += aclicMode;
1158 exname += arguments;
1163 tempbuf.
Form(
".x %s", exname.
Data());
1165 tempbuf.
Form(
".X%s %s", keep ?
"k" :
" ", exname.
Data());
1195 fIdleTimer =
new TIdleTimer(idleTimeInSec*1000);
1246 Emit(
"Terminate(Int_t)", status);
1266 Emit(
"LineProcessed(const char*)",
line);
1274 Emit(
"KeyPressed(Int_t)", key);
1282 Emit(
"ReturnPressed(char*)",
text);
1311 Printf(
"<TApplication::CreateApplication>: "
1312 "created default TApplication");
1313 delete []
a;
delete []
b;
1323 Int_t debug,
const char *script)
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())))
1349 ::Error(
"TApplication::Open",
"list of applications undefined - protocol error");
1356 nu.SetOptions(
Form(
"%d", nnew));
1361 if ((
h =
gROOT->GetPluginManager()->FindHandler(
"TApplication",
"remote"))) {
1362 if (
h->LoadPlugin() == 0) {
1363 ap = (
TApplication *)
h->ExecPlugin(3, nu.GetUrl(), debug, script);
1365 ::Error(
"TApplication::Open",
"failed to load plugin for TApplicationRemote");
1368 ::Error(
"TApplication::Open",
"failed to find plugin for TApplicationRemote");
1379 gROOT->RefreshBrowsers();
1383 "TApplicationRemote for %s could not be instantiated", url);
1398 gROOT->GetListOfBrowsables()->RecursiveRemove(app);
1402 b->RecursiveRemove(app);
1403 gROOT->RefreshBrowsers();
constexpr static const char kCommandLineOptionsHelp[]
Help for command line options.
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.
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)
static TList * fgApplications
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
virtual void StopIdleing()
virtual Long_t ProcessFile(const char *file, Int_t *error=0, Bool_t keep=kFALSE)
virtual void LoadGraphicsLibs()
Load shared libs necessary for graphics.
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.
void InitializeGraphics()
Initialize the graphics environment.
virtual void Terminate(Int_t status=0)
static Bool_t fgGraphNeeded
virtual const char * ApplicationName() const
virtual void ls(Option_t *option="") const
The ls function lists the contents of a class on stdout.
void SetReturnFromRun(Bool_t ret)
EExitOnException fExitOnException
const char * GetIdleCommand() const
TApplication()
Default ctor. Can be used by classes deriving from TApplication.
virtual void SetEchoMode(Bool_t mode)
static Bool_t fgGraphInit
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.
virtual void RemoveIdleTimer()
virtual void StartIdleing()
virtual void HandleIdleTimer()
Handle idle timeout.
virtual void Run(Bool_t retrn=kFALSE)
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 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 & 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:
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 * 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 ms
static constexpr double s