Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
24 ClassImp(TEveMacro);
25 
26 ////////////////////////////////////////////////////////////////////////////////
27 /// Default constructor.
28 
29 TEveMacro::TEveMacro() : TMacro()
30 {
31 }
32 
33 TEveMacro::TEveMacro(const TEveMacro& m) : TMacro(m)
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  }
54  ReadFile(fTitle);
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 
120 void TEveMacro::ResetRoot()
121 {
122  // printf ("TEveMacro::ResetRoot doing 'gROOT->Reset()'.\n");
123  gROOT->GetApplication()->ProcessLine("gROOT->Reset()");
124 }