00001 // @(#)root/eve:$Id: TEveMacro.cxx 25394 2008-09-12 16:13:47Z matevz $ 00002 // Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007 00003 00004 /************************************************************************* 00005 * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. * 00006 * All rights reserved. * 00007 * * 00008 * For the licensing terms see $ROOTSYS/LICENSE. * 00009 * For the list of contributors see $ROOTSYS/README/CREDITS. * 00010 *************************************************************************/ 00011 00012 #include "TEveMacro.h" 00013 00014 #include "TPRegexp.h" 00015 #include "TSystem.h" 00016 #include "TROOT.h" 00017 00018 //______________________________________________________________________________ 00019 // 00020 // Sub-class of TMacro, overriding Exec to unload the previous verison 00021 // and cleanup after the execution. 00022 00023 ClassImp(TEveMacro); 00024 00025 //______________________________________________________________________________ 00026 TEveMacro::TEveMacro() : TMacro() 00027 { 00028 // Default constructor. 00029 } 00030 00031 TEveMacro::TEveMacro(const TEveMacro& m) : TMacro(m) 00032 { 00033 // Copy constructor. 00034 } 00035 00036 TEveMacro::TEveMacro(const char* name) : 00037 TMacro() 00038 { 00039 // Constructor with file name. 00040 00041 if (!name) return; 00042 00043 fTitle = name; 00044 00045 TPMERegexp re("([^/]+?)(?:\\.\\w*)?$"); 00046 Int_t nm = re.Match(fTitle); 00047 if (nm >= 2) { 00048 fName = re[1]; 00049 } else { 00050 fName = "<unknown>"; 00051 } 00052 ReadFile(fTitle); 00053 } 00054 00055 /******************************************************************************/ 00056 00057 #include "TTimer.h" 00058 00059 //______________________________________________________________________________ 00060 Long_t TEveMacro::Exec(const char* params, Int_t* error) 00061 { 00062 // Execute the macro. 00063 00064 Long_t retval = -1; 00065 00066 if (gROOT->GetGlobalFunction(fName, 0, kTRUE) != 0) 00067 { 00068 gROOT->SetExecutingMacro(kTRUE); 00069 gROOT->SetExecutingMacro(kFALSE); 00070 retval = gROOT->ProcessLine(Form("%s()", fName.Data()), error); 00071 } 00072 else 00073 { 00074 // Copy from TMacro::Exec. Difference is that the file is really placed 00075 // into the /tmp. 00076 TString fname = "/tmp/"; 00077 { 00078 //the current implementation uses a file in the current directory. 00079 //should be replaced by a direct execution from memory by CINT 00080 fname += GetName(); 00081 fname += ".C"; 00082 SaveSource(fname); 00083 //disable a possible call to gROOT->Reset from the executed script 00084 gROOT->SetExecutingMacro(kTRUE); 00085 //execute script in /tmp 00086 TString exec = ".x " + fname; 00087 TString p = params; 00088 if (p == "") p = fParams; 00089 if (p != "") 00090 exec += "(" + p + ")"; 00091 retval = gROOT->ProcessLine(exec, error); 00092 //enable gROOT->Reset 00093 gROOT->SetExecutingMacro(kFALSE); 00094 //delete the temporary file 00095 gSystem->Unlink(fname); 00096 } 00097 } 00098 00099 //G__unloadfile(fname); 00100 00101 // In case an exception was thrown (which i do not know how to detect 00102 // the execution of next macros does not succeed. 00103 // However strange this might seem, this solves the problem. 00104 // TTimer::SingleShot(100, "TEveMacro", this, "ResetRoot()"); 00105 // 00106 // 27.8.07 - ok, this does not work any more. Seems I'll have to fix 00107 // this real soon now. 00108 // 00109 // !!!! FIX MACRO HANDLING !!!! 00110 // 00111 00112 return retval; 00113 } 00114 00115 #include "TApplication.h" 00116 00117 //______________________________________________________________________________ 00118 void TEveMacro::ResetRoot() 00119 { 00120 // Call gROOT->Reset() via interpreter. 00121 00122 // printf ("TEveMacro::ResetRoot doing 'gROOT->Reset()'.\n"); 00123 gROOT->GetApplication()->ProcessLine("gROOT->Reset()"); 00124 }