Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TEveMacro.cxx
Go to the documentation of this file.
1// @(#)root/eve:$Id$
2// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
3
4/*************************************************************************
5 * Copyright (C) 1995-2007, 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#include "TEveMacro.h"
13
14#include "TPRegexp.h"
15#include "TSystem.h"
16#include "TROOT.h"
17#include "TApplication.h"
18
19/** \class TEveMacro
20\ingroup TEve
21Sub-class of TMacro, overriding Exec to unload the previous version
22and cleanup after the execution.
23*/
24
25
26////////////////////////////////////////////////////////////////////////////////
27/// Default constructor.
28
32
34{
35 // Copy constructor.
36}
37
39 TMacro()
40{
41 // Constructor with file name.
42
43 if (!name) return;
44
45 fTitle = name;
46
47 TPMERegexp re("([^/]+?)(?:\\.\\w*)?$");
48 Int_t nm = re.Match(fTitle);
49 if (nm >= 2) {
50 fName = re[1];
51 } else {
52 fName = "<unknown>";
53 }
55}
56
57
58////////////////////////////////////////////////////////////////////////////////
59/// Execute the macro.
60
61Longptr_t TEveMacro::Exec(const char* params, Int_t* error)
62{
63 Longptr_t retval = -1;
64
65 if (gROOT->GetGlobalFunction(fName, nullptr, kTRUE) != nullptr)
66 {
67 gROOT->SetExecutingMacro(kTRUE);
68 gROOT->SetExecutingMacro(kFALSE);
69 retval = gROOT->ProcessLine(Form("%s()", fName.Data()), error);
70 }
71 else
72 {
73 // Copy from TMacro::Exec. Difference is that the file is really placed
74 // into the /tmp.
75 TString fname = "/tmp/";
76 {
77 //the current implementation uses a file in the current directory.
78 //should be replaced by a direct execution from memory by CINT
79 fname += GetName();
80 fname += ".C";
82 //disable a possible call to gROOT->Reset from the executed script
83 gROOT->SetExecutingMacro(kTRUE);
84 //execute script in /tmp
85 TString exec = ".x " + fname;
86 TString p = params;
87 if (p == "") p = fParams;
88 if (p != "")
89 exec += "(" + p + ")";
90 retval = gROOT->ProcessLine(exec, error);
91 //enable gROOT->Reset
92 gROOT->SetExecutingMacro(kFALSE);
93 //delete the temporary file
95 }
96 }
97
98 //G__unloadfile(fname);
99
100 // In case an exception was thrown (which i do not know how to detect
101 // the execution of next macros does not succeed.
102 // However strange this might seem, this solves the problem.
103 // TTimer::SingleShot(100, "TEveMacro", this, "ResetRoot()");
104 //
105 // 27.8.07 - ok, this does not work any more. Seems I'll have to fix
106 // this real soon now.
107 //
108 // !!!! FIX MACRO HANDLING !!!!
109 //
110
111 return retval;
112}
113
114////////////////////////////////////////////////////////////////////////////////
115/// Call gROOT->Reset() via interpreter.
116
118{
119 // printf ("TEveMacro::ResetRoot doing 'gROOT->Reset()'.\n");
120 gROOT->GetApplication()->ProcessLine("gROOT->Reset()");
121}
long Longptr_t
Integer large enough to hold a pointer (platform-dependent)
Definition RtypesCore.h:89
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
winID h TVirtualViewer3D TVirtualGLPainter p
char name[80]
Definition TGX11.cxx:110
#define gROOT
Definition TROOT.h:411
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2495
R__EXTERN TSystem * gSystem
Definition TSystem.h:572
Sub-class of TMacro, overriding Exec to unload the previous version and cleanup after the execution.
Definition TEveMacro.h:20
void ResetRoot()
Call gROOT->Reset() via interpreter.
Longptr_t Exec(const char *params="0", Int_t *error=nullptr) override
Execute the macro.
Definition TEveMacro.cxx:61
TEveMacro()
Default constructor.
Definition TEveMacro.cxx:29
Class supporting a collection of lines with C++ code.
Definition TMacro.h:31
TString fParams
Definition TMacro.h:35
virtual Int_t ReadFile(const char *filename)
Read lines in filename in this macro.
Definition TMacro.cxx:328
void SaveSource(FILE *fp)
Save macro source in file pointer fp.
Definition TMacro.cxx:370
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
TString fTitle
Definition TNamed.h:33
TString fName
Definition TNamed.h:32
Wrapper for PCRE library (Perl Compatible Regular Expressions).
Definition TPRegexp.h:97
Basic string class.
Definition TString.h:138
const char * Data() const
Definition TString.h:384
virtual int Unlink(const char *name)
Unlink, i.e.
Definition TSystem.cxx:1392
TMarker m
Definition textangle.C:8