forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TEveMacro.cxx
122 lines (101 loc) · 3.4 KB
/
TEveMacro.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// @(#)root/eve:$Id$
// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
/*************************************************************************
* Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
#include "TEveMacro.h"
#include "TPRegexp.h"
#include "TSystem.h"
#include "TROOT.h"
#include "TApplication.h"
/** \class TEveMacro
\ingroup TEve
Sub-class of TMacro, overriding Exec to unload the previous version
and cleanup after the execution.
*/
ClassImp(TEveMacro);
////////////////////////////////////////////////////////////////////////////////
/// Default constructor.
TEveMacro::TEveMacro() : TMacro()
{
}
TEveMacro::TEveMacro(const TEveMacro& m) : TMacro(m)
{
// Copy constructor.
}
TEveMacro::TEveMacro(const char* name) :
TMacro()
{
// Constructor with file name.
if (!name) return;
fTitle = name;
TPMERegexp re("([^/]+?)(?:\\.\\w*)?$");
Int_t nm = re.Match(fTitle);
if (nm >= 2) {
fName = re[1];
} else {
fName = "<unknown>";
}
ReadFile(fTitle);
}
////////////////////////////////////////////////////////////////////////////////
/// Execute the macro.
Longptr_t TEveMacro::Exec(const char* params, Int_t* error)
{
Longptr_t retval = -1;
if (gROOT->GetGlobalFunction(fName, nullptr, kTRUE) != nullptr)
{
gROOT->SetExecutingMacro(kTRUE);
gROOT->SetExecutingMacro(kFALSE);
retval = gROOT->ProcessLine(Form("%s()", fName.Data()), error);
}
else
{
// Copy from TMacro::Exec. Difference is that the file is really placed
// into the /tmp.
TString fname = "/tmp/";
{
//the current implementation uses a file in the current directory.
//should be replaced by a direct execution from memory by CINT
fname += GetName();
fname += ".C";
SaveSource(fname);
//disable a possible call to gROOT->Reset from the executed script
gROOT->SetExecutingMacro(kTRUE);
//execute script in /tmp
TString exec = ".x " + fname;
TString p = params;
if (p == "") p = fParams;
if (p != "")
exec += "(" + p + ")";
retval = gROOT->ProcessLine(exec, error);
//enable gROOT->Reset
gROOT->SetExecutingMacro(kFALSE);
//delete the temporary file
gSystem->Unlink(fname);
}
}
//G__unloadfile(fname);
// In case an exception was thrown (which i do not know how to detect
// the execution of next macros does not succeed.
// However strange this might seem, this solves the problem.
// TTimer::SingleShot(100, "TEveMacro", this, "ResetRoot()");
//
// 27.8.07 - ok, this does not work any more. Seems I'll have to fix
// this real soon now.
//
// !!!! FIX MACRO HANDLING !!!!
//
return retval;
}
////////////////////////////////////////////////////////////////////////////////
/// Call gROOT->Reset() via interpreter.
void TEveMacro::ResetRoot()
{
// printf ("TEveMacro::ResetRoot doing 'gROOT->Reset()'.\n");
gROOT->GetApplication()->ProcessLine("gROOT->Reset()");
}