]>
Commit | Line | Data |
---|---|---|
6a187c6c | 1 | // $Header$ |
2 | ||
3 | #include "RMacro.h" | |
4 | ||
5 | #include <TSystem.h> | |
6 | #include <TROOT.h> | |
7 | #include <G__ci.h> | |
8 | ||
9 | using namespace Reve; | |
10 | ||
11 | //______________________________________________________________________ | |
12 | // RMacro | |
13 | // | |
14 | // Sub-class of TMacro, overriding Exec to unload the previous verison | |
15 | // and cleanup after the execution. | |
16 | ||
17 | ClassImp(RMacro) | |
18 | ||
19 | RMacro::RMacro() : TMacro() {} | |
20 | ||
21 | RMacro::RMacro(const RMacro& m) : TMacro(m) {} | |
22 | ||
8ca3710e | 23 | RMacro::RMacro(const char* name) : |
24 | TMacro() | |
25 | { | |
26 | if (!name) return; | |
27 | ||
28 | fTitle = name; | |
29 | ||
30 | char *dot = (char*)strrchr(name, '.'); | |
31 | char *slash = (char*)strrchr(name, '/'); | |
32 | if (dot) *dot = 0; | |
33 | if (slash) fName = slash + 1; | |
34 | else fName = name; | |
35 | ||
36 | ReadFile(fTitle); | |
37 | } | |
6a187c6c | 38 | |
39 | /**************************************************************************/ | |
40 | ||
b7daeae6 | 41 | #include <TTimer.h> |
42 | ||
6a187c6c | 43 | void RMacro::Exec(const char* params) |
44 | { | |
23443913 | 45 | if(Reve::CheckMacro(fTitle.Data())) |
6a187c6c | 46 | G__unloadfile(fTitle.Data()); |
47 | ||
48 | // Copy from TMacro::Exec. Difference is that the file is really placed | |
49 | // into the /tmp. | |
50 | TString fname = "/tmp/"; | |
51 | { | |
52 | //the current implementation uses a file in the current directory. | |
53 | //should be replaced by a direct execution from memory by CINT | |
54 | fname += GetName(); | |
23443913 | 55 | fname += ".C"; |
6a187c6c | 56 | SaveSource(fname); |
57 | //disable a possible call to gROOT->Reset from the executed script | |
58 | gROOT->SetExecutingMacro(kTRUE); | |
59 | //execute script in /tmp | |
60 | TString exec = ".x " + fname; | |
61 | TString p = params; | |
62 | if (p == "") p = fParams; | |
63 | if (p != "") | |
64 | exec += "(" + p + ")"; | |
b7daeae6 | 65 | Int_t exit; |
66 | gROOT->ProcessLine(exec, &exit); | |
6a187c6c | 67 | //enable gROOT->Reset |
68 | gROOT->SetExecutingMacro(kFALSE); | |
69 | //delete the temporary file | |
70 | gSystem->Unlink(fname); | |
71 | } | |
72 | ||
73 | G__unloadfile(fname); | |
b7daeae6 | 74 | |
75 | // In case an exception was thrown (which i do not know how to detect | |
76 | // the execution of next macros does not succeed. | |
77 | // However strange this might seem, this solves the problem. | |
78 | TTimer::SingleShot(100, "Reve::RMacro", this, "ResetRoot()"); | |
79 | } | |
80 | ||
81 | #include <TApplication.h> | |
82 | ||
83 | void RMacro::ResetRoot() | |
84 | { | |
85 | // printf ("RMacro::ResetRoot doing 'gROOT->Reset()'.\n"); | |
86 | gROOT->GetApplication()->ProcessLine("gROOT->Reset()"); | |
6a187c6c | 87 | } |