22 #include "RConfigure.h" 51 #if defined(R__MACOSX) && (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR) 63 class TIdleTimer :
public TTimer {
72 Bool_t TIdleTimer::Notify()
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");
282 #if !defined(R__WIN32) 292 if ((
h =
gROOT->GetPluginManager()->FindHandler(
"TVirtualX",
"x11ttf")))
293 if (
h->LoadPlugin() == -1)
294 Info(
"InitializeGraphics",
"no TTF support");
347 if (index >=
fArgc) {
348 Error(
"Argv",
"index (%d) >= number of arguments (%d)", index,
fArgc);
362 static char null[1] = {
"" };
374 for (i = 1; i < *argc; i++) {
375 if (!strcmp(argv[i],
"-?") || !strncmp(argv[i],
"-h", 2) ||
376 !strncmp(argv[i],
"--help", 6)) {
379 }
else if (!strcmp(argv[i],
"-config")) {
380 fprintf(stderr,
"ROOT ./configure options:\n%s\n",
gROOT->GetConfigOptions());
382 }
else if (!strcmp(argv[i],
"-memstat")) {
385 }
else if (!strcmp(argv[i],
"-b")) {
388 }
else if (!strcmp(argv[i],
"-n")) {
391 }
else if (!strcmp(argv[i],
"-t")) {
397 }
else if (!strcmp(argv[i],
"-q")) {
400 }
else if (!strcmp(argv[i],
"-l")) {
404 }
else if (!strcmp(argv[i],
"-x")) {
407 }
else if (!strcmp(argv[i],
"-splash")) {
411 }
else if (!strcmp(argv[i],
"-e")) {
422 Warning(
"GetOptions",
"-e must be followed by an expression.");
424 }
else if (!strcmp(argv[i],
"--")) {
426 bool warnShown =
false;
432 Error(
"GetOptions()",
"Inconsistent file entry (not a TObjString)!");
439 if (
file->String().EndsWith(
".root"))
441 if (
file->String().Contains(
'('))
444 if (macro && !warnShown && (warnShown =
true))
445 Warning(
"GetOptions",
"-- is used with several macros. " 446 "The arguments will be passed to the last one.");
458 for (; i < *argc; i++) {
465 Warning(
"GetOptions",
"no macro to pass arguments to was provided. " 466 "Everything after the -- will be ignored.");
467 for (; i < *argc; i++)
470 }
else if (argv[i][0] !=
'-' && argv[i][0] !=
'+') {
473 char *arg = strchr(argv[i],
'(');
474 if (arg) *arg =
'\0';
496 }
else if (!strcmp(
gROOT->GetName(),
"Rint")) {
497 Warning(
"GetOptions",
"only one directory argument can be specified (%s)", dir);
499 }
else if (size > 0) {
505 Warning(
"GetOptions",
"file %s has size 0, skipping", dir);
512 if (!strcmp(
gROOT->GetName(),
"Rint"))
513 Warning(
"GetOptions",
"file %s not found", dir);
534 if (!strcmp(
gROOT->GetName(),
"Rint"))
535 Warning(
"GetOptions",
"macro %s not found", fname.
Data());
550 for (i = 0; i < *argc; i++) {
551 if (strcmp(argv[i],
"")) {
569 Emit(
"HandleIdleTimer()");
615 Printf(
"\nROOT special commands.");
616 Printf(
"===========================================================================");
617 Printf(
" pwd : show current directory, pad and style");
618 Printf(
" ls : list contents of current directory");
619 Printf(
" which [file] : shows path of macro file");
628 if (
gROOT->IsBatch())
return;
631 if ((
h =
gROOT->GetPluginManager()->FindHandler(
"TVirtualPad")))
632 if (
h->LoadPlugin() == -1)
636 TString title1 =
"ROOT interface to ";
641 nativex =
"win32gdk";
643 title = title1 +
"Win32gdk";
644 #elif defined(R__HAS_COCOA) 647 title = title1 +
"Quartz";
651 title = title1 +
"X11";
656 if (guiBackend ==
"native") {
657 guiBackend = nativex;
660 title = title1 + guiBackend;
664 if (guiFactory ==
"native")
665 guiFactory = nativeg;
667 if ((
h =
gROOT->GetPluginManager()->FindHandler(
"TVirtualX", guiBackend))) {
668 if (
h->LoadPlugin() == -1) {
675 if ((
h =
gROOT->GetPluginManager()->FindHandler(
"TGuiFactory", guiFactory))) {
676 if (
h->LoadPlugin() == -1) {
715 if (!ln || strlen(ln) <= 0)
727 while (
line.Tokenize(tkn, from,
" ")) {
731 }
else if (tkn ==
"-d") {
733 }
else if (tkn ==
"-close") {
736 ::Warning(
"TApplication::ParseRemoteLine",
"unknown option: %s", tkn.
Data());
744 }
else if (isHostDir) {
749 }
else if (isScript) {
781 if (!strncmp(
line,
"-?", 2) || !strncmp(
line,
"-h", 2) ||
782 !strncmp(
line,
"--help", 6)) {
783 Info(
"ProcessRemote",
"remote session help:");
784 Printf(
".R [user@]host[:dir] [-l user] [-d dbg] [[<]script] | [host] -close");
785 Printf(
"Create a ROOT session on the specified remote host.");
786 Printf(
"The variable \"dir\" is the remote directory to be used as working dir.");
787 Printf(
"The username can be specified in two ways, \"-l\" having the priority");
788 Printf(
"(as in ssh). A \"dbg\" value > 0 gives increasing verbosity.");
789 Printf(
"The last argument \"script\" allows to specify an alternative script to");
790 Printf(
"be executed remotely to startup the session, \"roots\" being");
791 Printf(
"the default. If the script is preceded by a \"<\" the script will be");
792 Printf(
"sourced, after which \"roots\" is executed. The sourced script can be ");
793 Printf(
"used to change the PATH and other variables, allowing an alternative");
794 Printf(
"\"roots\" script to be found.");
795 Printf(
"To close down a session do \".R host -close\".");
796 Printf(
"To switch between sessions do \".R host\", to switch to the local");
797 Printf(
"session do \".R\".");
798 Printf(
"To list all open sessions do \"gApplication->GetApplications()->Print()\".");
805 if (hostdir.
Length() <= 0) {
815 }
else if (rc == 1) {
826 const char *sc = (script.
Length() > 0) ? script.
Data() : 0;
837 static int PrintFile(
const char* filename) {
841 Error(
"ProcessLine()",
"Cannot find file %s", filename);
844 std::ifstream instr(sFileName);
862 if (!strncmp(
line,
".R", 2)) {
864 while (*(
line+
n) ==
' ')
875 if (!strncasecmp(
line,
".qqqqqqq", 7)) {
877 }
else if (!strncasecmp(
line,
".qqqqq", 5)) {
878 Info(
"ProcessLine",
"Bye... (try '.qqqqqqq' if still running)");
880 }
else if (!strncasecmp(
line,
".exit", 4) || !strncasecmp(
line,
".quit", 2)) {
885 if (!strncmp(
line,
"?", 1) || !strncmp(
line,
".help", 5)) {
890 if (!strncmp(
line,
".demo", 5)) {
891 if (
gROOT->IsBatch()) {
892 Error(
"ProcessLine",
"Cannot show demos in batch mode!");
899 if (!strncmp(
line,
".license", 8)) {
903 if (!strncmp(
line,
".credits", 8)) {
907 return PrintFile(credits);
910 if (!strncmp(
line,
".pwd", 4)) {
920 if (!strncmp(
line,
".ls", 3)) {
927 if (!strncmp(
line,
".which", 6)) {
929 char *
s = strtok(fn,
"+(");
940 if (!strncmp(
line,
".L", 2) || !strncmp(
line,
".U", 2)) {
948 Warning(
"ProcessLine",
"argument(s) \"%s\" ignored with .%c", arguments.
Data(),
953 Error(
"ProcessLine",
"macro %s not found in path %s", fname.
Data(),
957 Ssiz_t posSpace = cmd.Index(
' ');
958 if (posSpace == -1) cmd.Remove(1);
959 else cmd.Remove(posSpace);
962 tempbuf.
Form(
".%s %s%s%s", cmd.Data(), mac, aclicMode.
Data(),io.
Data());
966 tempbuf.
Form(
".%s %s%s%s", cmd.Data(), mac, aclicMode.
Data(),io.
Data());
979 if (!strncmp(
line,
".X", 2) || !strncmp(
line,
".x", 2)) {
983 if (!strcmp(
line,
".reset")) {
985 Printf(
"*** .reset not allowed, please use gROOT->Reset() ***");
991 gROOT->GetListOfClasses()->Delete();
1016 static const Int_t kBufSize = 1024;
1027 ::Error(
"TApplication::ExecuteFile",
"macro %s not found in path %s", fname.
Data(),
1035 ::std::ifstream macro(exnam, std::ios::in);
1036 if (!macro.good()) {
1037 ::Error(
"TApplication::ExecuteFile",
"%s no such file", exnam);
1044 char currentline[kBufSize];
1045 char dummyline[kBufSize];
1055 bool res = (bool)macro.getline(currentline, kBufSize);
1056 if (macro.eof())
break;
1061 while (!macro.getline(dummyline, kBufSize) && !macro.eof()) {
1066 while (
s && (*
s ==
' ' || *
s ==
'\t'))
s++;
1073 if (strstr(cs,
"#ifndef__CINT__") ||
1074 strstr(cs,
"#if!defined(__CINT__)"))
1076 else if (ifndefc && (strstr(cs,
"#ifdef") || strstr(cs,
"#ifndef") ||
1077 strstr(cs,
"#ifdefined") || strstr(cs,
"#if!defined")))
1079 else if (ifndefc && strstr(cs,
"#endif")) {
1084 }
else if (ifndefc && !ifdef && strstr(cs,
"#else"))
1088 if (!*
s || *
s ==
'#' || ifndefc || !strncmp(
s,
"//", 2))
continue;
1090 if (!comment && (!strncmp(
s,
".X", 2) || !strncmp(
s,
".x", 2))) {
1096 if (!strncmp(
s,
"/*", 2)) comment = 1;
1100 s = strstr(
s,
"*/");
1105 while (
s && (*
s ==
' ' || *
s ==
'\t'))
s++;
1107 if (!strncmp(
s,
"//", 2))
continue;
1108 if (!strncmp(
s,
"/*", 2)) {
1114 if (!comment && *
s ==
'{') tempfile = 1;
1115 if (!comment)
break;
1124 exname += aclicMode;
1126 exname += arguments;
1131 tempbuf.
Form(
".x %s", exname.
Data());
1133 tempbuf.
Form(
".X%s %s", keep ?
"k" :
" ", exname.
Data());
1163 fIdleTimer =
new TIdleTimer(idleTimeInSec*1000);
1214 Emit(
"Terminate(Int_t)", status);
1234 Emit(
"LineProcessed(const char*)",
line);
1242 Emit(
"KeyPressed(Int_t)", key);
1250 Emit(
"ReturnPressed(char*)",
text);
1279 Printf(
"<TApplication::CreateApplication>: " 1280 "created default TApplication");
1281 delete []
a;
delete []
b;
1291 Int_t debug,
const char *script)
1308 if (strlen(au.GetUser()) > 0 && strlen(nu.GetUser()) > 0 &&
1309 !strcmp(au.GetUser(), nu.GetUser())) {
1310 if (!strncmp(au.GetHost(), nu.GetHost(), strlen(nu.GetHost())))
1317 ::Error(
"TApplication::Open",
"list of applications undefined - protocol error");
1324 nu.SetOptions(
Form(
"%d", nnew));
1329 if ((
h =
gROOT->GetPluginManager()->FindHandler(
"TApplication",
"remote"))) {
1330 if (
h->LoadPlugin() == 0) {
1331 ap = (
TApplication *)
h->ExecPlugin(3, nu.GetUrl(), debug, script);
1333 ::Error(
"TApplication::Open",
"failed to load plugin for TApplicationRemote");
1336 ::Error(
"TApplication::Open",
"failed to find plugin for TApplicationRemote");
1347 gROOT->RefreshBrowsers();
1351 "TApplicationRemote for %s could not be instantiated", url);
1366 gROOT->GetListOfBrowsables()->RecursiveRemove(app);
1370 b->RecursiveRemove(app);
1371 gROOT->RefreshBrowsers();
virtual const char * GetName() const
Returns name of object.
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 LoadGraphicsLibs()
Load shared libs necessary for graphics.
std::istream & ReadFile(std::istream &str)
Replace string with the contents of strm, stopping at an EOF.
R__EXTERN TGuiFactory * gBatchGuiFactory
Semi-Abstract base class defining a generic interface to the underlying, low level, native graphics backend (X11, Win32, MacOS, OpenGL...).
virtual void KeyPressed(Int_t key)
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
static const TString & GetTutorialDir()
Get the tutorials directory in the installation. Static utility function.
static Bool_t fgGraphInit
virtual const char * WorkingDirectory()
Return working directory.
char * Compress(const char *str)
Remove all blanks from the string str.
void Reset()
Reset the timer.
virtual void ls(Option_t *option="") const
The ls function lists the contents of a class on stdout.
virtual void NotifyApplicationCreated()
Hook to tell TSystem that the TApplication object has been created.
Collectable string class.
virtual void StartIdleing()
R__EXTERN TClassTable * gClassTable
virtual TString SplitAclicMode(const char *filename, TString &mode, TString &args, TString &io) const
This method split a filename of the form: ~~~ {.cpp} [path/]macro.C[+|++[k|f|g|O|c|s|d|v|-]][(args)]...
virtual void Delete(Option_t *option="")
Remove all objects from the array AND delete all heap based objects.
R__EXTERN TVirtualMutex * gInterpreterMutex
This class represents a WWW compatible URL.
TString & ReplaceAll(const TString &s1, const TString &s2)
R__EXTERN TStyle * gStyle
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.
const char * GetProtocol() const
virtual void RemoveIdleTimer()
virtual void MakeBatch()
Switch to batch mode.
virtual Bool_t ChangeDirectory(const char *path)
Change directory.
const char * GetFileAndOptions() const
Return the file and its options (the string specified behind the ?).
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
static void Close(TApplication *app)
void ToLower()
Change string to lower-case.
virtual TTimer * RemoveTimer(TTimer *t)
Remove timer from list of system timers.
static Bool_t fgGraphNeeded
R__EXTERN TVirtualMutex * gROOTMutex
EExitOnException fExitOnException
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
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 [user@]host[:di...
TString & Insert(Ssiz_t pos, const char *s)
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
static const char * GetMacroPath()
Get macro search path. Static utility function.
const char * GetFile() const
static constexpr const char kCommandLineOptionsHelp[]
Help for command line options.
virtual TApplicationImp * CreateApplicationImp(const char *classname, int *argc, char **argv)
Create a batch version of TApplicationImp.
virtual Long_t ProcessLine(const char *line, Bool_t sync=kFALSE, Int_t *error=0)
static Bool_t Initialized()
Return kTRUE if the TROOT object has been initialized.
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 [user@]host[:dir]...
virtual Int_t TabCompletionHook(char *buf, int *pLoc, std::ostream &out)
virtual ~TApplication()
TApplication dtor.
virtual void SetEchoMode(Bool_t mode)
static const TString & GetDocDir()
Get the documentation directory in the installation. Static utility function.
static void CreateApplication()
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
static TList * GetApplications()
virtual void ExitLoop()
Exit from event loop.
static void CallEndOfProcessCleanups()
virtual void Run(Bool_t retrn=kFALSE)
R__EXTERN TGuiFactory * gGuiFactory
void Error(const char *location, const char *msgfmt,...)
virtual void GetOptions(Int_t *argc, char **argv)
Get and handle command line options.
void EnableImplicitMT(UInt_t numthreads=0)
Enable ROOT's implicit multi-threading for all objects and methods that provide an internal paralleli...
virtual Bool_t Notify()
Notify when timer times out.
Using a TBrowser one can browse all ROOT objects.
R__EXTERN TVirtualX * gGXBatch
Bool_t fIsRunning
Window system specific application implementation.
void ClearInputFiles()
Clear list containing macro files passed as program arguments.
virtual const char * ApplicationName() const
static void NeedGraphicsLibs()
Static method.
R__EXTERN TSystem * gSystem
if object ctor succeeded but object should not be used
static Long_t ExecuteFile(const char *file, Int_t *error=0, Bool_t keep=kFALSE)
virtual void ReturnPressed(char *text)
virtual TObject * Remove(TObject *obj)
Remove object from the list.
void SetScreenFactor(Float_t factor=1)
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
char * Form(const char *fmt,...)
TApplicationImp * fAppImp
Handles synchronous and a-synchronous timer events.
char * Strip(const char *str, char c=' ')
Strip leading and trailing c (blanks by default) from a string.
virtual void Abort(int code=0)
Abort the application.
TApplication * fAppRemote
void Reset(Detail::TBranchProxy *x)
static constexpr double ms
virtual TObjLink * FirstLink() const
virtual void Run()
System event loop.
char * StrDup(const char *str)
Duplicate the string str.
virtual void Help(const char *line)
Print help on interpreter.
void InitializeGraphics()
Initialize the graphics environment.
virtual void SetIdleTimer(UInt_t idleTimeInSec, const char *command)
R__EXTERN ExceptionContext_t * gException
void EnableThreadSafety()
Enables the global mutex to make ROOT thread safe/aware.
static DictFuncPtr_t GetDict(const char *cname)
Given the class name returns the Dictionary() function of a class (uses hash of name).
const char * GetIdleCommand() const
virtual void SetProgname(const char *name)
Set the application name (from command line, argv[0]) and copy it in gProgName.
static constexpr double s
#define R__LOCKGUARD(mutex)
virtual Long_t ProcessFile(const char *file, Int_t *error=0, Bool_t keep=kFALSE)
virtual void Terminate(Int_t status=0)
EExitOnException ExitOnException(EExitOnException opt=kExit)
Set the exit on exception option.
void Throw(int code)
If an exception context has been set (using the TRY and RETRY macros) jump back to where it was set...
This ABC is a factory for GUI components.
virtual void HandleIdleTimer()
Handle idle timeout.
virtual void HandleException(Int_t sig)
Handle exceptions (kSigBus, kSigSegmentationViolation, kSigIllegalInstruction and kSigFloatingExcepti...
virtual void Add(TObject *obj)
virtual void AddTimer(TTimer *t)
Add timer to list of system timers.
virtual void Exit(int code, Bool_t mode=kTRUE)
Exit the application.
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
TApplication * gApplication
Int_t Atoi() const
Return integer value of string.
static void InitializeColors()
Initialize colors used by the TCanvas based graphics (via TColor objects).
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
This class creates the ROOT Application Environment that interfaces to the windowing system eventloop...
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
static TList * fgApplications
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
void SetReturnFromRun(Bool_t ret)
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual void LineProcessed(const char *line)
const char * Data() const
TApplication()
Default ctor. Can be used by classes deriving from TApplication.
virtual void StopIdleing()