Logo ROOT   6.08/07
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
20 Sub-class of TMacro, overriding Exec to unload the previous version
21 and cleanup after the execution.
22 */
23 
25 
26 ////////////////////////////////////////////////////////////////////////////////
27 /// Default constructor.
28 
30 {
31 }
32 
34 {
35  // Copy constructor.
36 }
37 
38 TEveMacro::TEveMacro(const char* name) :
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 
62 Long_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 }
TString fTitle
Definition: TNamed.h:37
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
TEveMacro()
Default constructor.
Definition: TEveMacro.cxx:29
#define gROOT
Definition: TROOT.h:364
Class supporting a collection of lines with C++ code.
Definition: TMacro.h:33
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual Long_t Exec(const char *params="0", Int_t *error=0)
Execute the macro.
Definition: TEveMacro.cxx:62
Sub-class of TMacro, overriding Exec to unload the previous version and cleanup after the execution...
Definition: TEveMacro.h:19
virtual int Unlink(const char *name)
Unlink, i.e. remove, a file.
Definition: TSystem.cxx:1347
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
TMarker * m
Definition: textangle.C:8
char * Form(const char *fmt,...)
void SaveSource(FILE *fp)
Save macro source in file pointer fp.
Definition: TMacro.cxx:380
virtual Int_t ReadFile(const char *filename)
Read lines in filename in this macro.
Definition: TMacro.cxx:335
TString fName
Definition: TNamed.h:36
void ResetRoot()
Call gROOT->Reset() via interpreter.
Definition: TEveMacro.cxx:120
long Long_t
Definition: RtypesCore.h:50
#define ClassImp(name)
Definition: Rtypes.h:279
Int_t Match(const TString &s, UInt_t start=0)
Runs a match on s against the regex &#39;this&#39; was created with.
Definition: TPRegexp.cxx:705
Wrapper for PCRE library (Perl Compatible Regular Expressions).
Definition: TPRegexp.h:103
TString fParams
Definition: TMacro.h:37
const Bool_t kTRUE
Definition: Rtypes.h:91
char name[80]
Definition: TGX11.cxx:109
const char * Data() const
Definition: TString.h:349