Logo ROOT  
Reference Guide
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
18/** \class TEveMacro
19\ingroup TEve
20Sub-class of TMacro, overriding Exec to unload the previous version
21and cleanup after the execution.
22*/
23
25
26////////////////////////////////////////////////////////////////////////////////
27/// Default constructor.
28
30{
31}
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#include "TTimer.h"
58
59////////////////////////////////////////////////////////////////////////////////
60/// Execute the macro.
61
62Long_t TEveMacro::Exec(const char* params, Int_t* error)
63{
64 Long_t retval = -1;
65
66 if (gROOT->GetGlobalFunction(fName, 0, kTRUE) != 0)
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#include "TApplication.h"
116
117////////////////////////////////////////////////////////////////////////////////
118/// Call gROOT->Reset() via interpreter.
119
121{
122 // printf ("TEveMacro::ResetRoot doing 'gROOT->Reset()'.\n");
123 gROOT->GetApplication()->ProcessLine("gROOT->Reset()");
124}
const Bool_t kFALSE
Definition: RtypesCore.h:90
long Long_t
Definition: RtypesCore.h:52
const Bool_t kTRUE
Definition: RtypesCore.h:89
#define ClassImp(name)
Definition: Rtypes.h:361
char name[80]
Definition: TGX11.cxx:109
#define gROOT
Definition: TROOT.h:406
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
Definition: TSystem.h:556
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.
Definition: TEveMacro.cxx:120
virtual Long_t Exec(const char *params="0", Int_t *error=0)
Execute the macro.
Definition: TEveMacro.cxx:62
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:336
void SaveSource(FILE *fp)
Save macro source in file pointer fp.
Definition: TMacro.cxx:381
TString fTitle
Definition: TNamed.h:33
TString fName
Definition: TNamed.h:32
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
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:708
Basic string class.
Definition: TString.h:131
const char * Data() const
Definition: TString.h:364
virtual int Unlink(const char *name)
Unlink, i.e.
Definition: TSystem.cxx:1376
static constexpr double nm
auto * m
Definition: textangle.C:8