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
26
27////////////////////////////////////////////////////////////////////////////////
28/// Default constructor.
29
31{
32}
33
35{
36 // Copy constructor.
37}
38
40 TMacro()
41{
42 // Constructor with file name.
43
44 if (!name) return;
45
46 fTitle = name;
47
48 TPMERegexp re("([^/]+?)(?:\\.\\w*)?$");
49 Int_t nm = re.Match(fTitle);
50 if (nm >= 2) {
51 fName = re[1];
52 } else {
53 fName = "<unknown>";
54 }
56}
57
58
59////////////////////////////////////////////////////////////////////////////////
60/// Execute the macro.
61
62Longptr_t TEveMacro::Exec(const char* params, Int_t* error)
63{
64 Longptr_t retval = -1;
65
66 if (gROOT->GetGlobalFunction(fName, nullptr, kTRUE) != nullptr)
67 {
68 gROOT->SetExecutingMacro(kTRUE);
69 gROOT->SetExecutingMacro(kFALSE);
70 retval = gROOT->ProcessLine(Form("%s()", fName.Data()), error);
71 }
72 else
73 {
74 // Copy from TMacro::Exec. Difference is that the file is really placed
75 // into the /tmp.
76 TString fname = "/tmp/";
77 {
78 //the current implementation uses a file in the current directory.
79 //should be replaced by a direct execution from memory by CINT
80 fname += GetName();
81 fname += ".C";
82 SaveSource(fname);
83 //disable a possible call to gROOT->Reset from the executed script
84 gROOT->SetExecutingMacro(kTRUE);
85 //execute script in /tmp
86 TString exec = ".x " + fname;
87 TString p = params;
88 if (p == "") p = fParams;
89 if (p != "")
90 exec += "(" + p + ")";
91 retval = gROOT->ProcessLine(exec, error);
92 //enable gROOT->Reset
93 gROOT->SetExecutingMacro(kFALSE);
94 //delete the temporary file
95 gSystem->Unlink(fname);
96 }
97 }
98
99 //G__unloadfile(fname);
100
101 // In case an exception was thrown (which i do not know how to detect
102 // the execution of next macros does not succeed.
103 // However strange this might seem, this solves the problem.
104 // TTimer::SingleShot(100, "TEveMacro", this, "ResetRoot()");
105 //
106 // 27.8.07 - ok, this does not work any more. Seems I'll have to fix
107 // this real soon now.
108 //
109 // !!!! FIX MACRO HANDLING !!!!
110 //
111
112 return retval;
113}
114
115////////////////////////////////////////////////////////////////////////////////
116/// Call gROOT->Reset() via interpreter.
117
119{
120 // printf ("TEveMacro::ResetRoot doing 'gROOT->Reset()'.\n");
121 gROOT->GetApplication()->ProcessLine("gROOT->Reset()");
122}
long Longptr_t
Definition RtypesCore.h:82
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:377
winID h TVirtualViewer3D TVirtualGLPainter p
char name[80]
Definition TGX11.cxx:110
#define gROOT
Definition TROOT.h:406
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2489
R__EXTERN TSystem * gSystem
Definition TSystem.h:555
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:62
TEveMacro()
Default constructor.
Definition TEveMacro.cxx:30
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:329
void SaveSource(FILE *fp)
Save macro source in file pointer fp.
Definition TMacro.cxx:371
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
TString fTitle
Definition TNamed.h:33
TString fName
Definition TNamed.h:32
Wrapper for PCRE library (Perl Compatible Regular Expressions).
Definition TPRegexp.h:97
Int_t Match(const TString &s, UInt_t start=0)
Runs a match on s against the regex 'this' was created with.
Definition TPRegexp.cxx:797
Basic string class.
Definition TString.h:139
const char * Data() const
Definition TString.h:376
virtual int Unlink(const char *name)
Unlink, i.e.
Definition TSystem.cxx:1381
TMarker m
Definition textangle.C:8