]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/Reve/Reve.cxx
In CheckMacro() use TInterpreter::IsLoaded(mac) instead of searching the list of...
[u/mrichter/AliRoot.git] / EVE / Reve / Reve.cxx
CommitLineData
5a5a1232 1// $Header$
2
3#include "Reve.h"
4
5#include <TError.h>
6#include <TPad.h>
7#include <TGeoManager.h>
915dabe1 8#include <TColor.h>
5a5a1232 9
10#include <TROOT.h>
5987168b 11#include <TInterpreter.h>
5a5a1232 12
13#include <list>
14
15#include <iostream>
16
17//______________________________________________________________________
18// Reve
19//
20
21namespace Reve {
22
23Exc_t operator+(const Exc_t &s1, const std::string &s2)
24{ return Exc_t((std::string&)s1 + s2); }
25
26Exc_t operator+(const Exc_t &s1, const TString &s2)
27{ return Exc_t((std::string&)s1 + s2.Data()); }
28
29Exc_t operator+(const Exc_t &s1, const char *s2)
30{ return Exc_t((std::string&)s1 + s2); }
31
32
33void WarnCaller(const TString& warning)
34{
35 std::cout << "WRN: " << warning << std::endl;
36}
37
915dabe1 38void ColorFromIdx(Color_t ci, UChar_t* col)
39{
40 TColor* c = gROOT->GetColor(ci);
41 if(c) {
42 col[0] = (UChar_t)(255*c->GetRed());
43 col[1] = (UChar_t)(255*c->GetGreen());
44 col[2] = (UChar_t)(255*c->GetBlue());
45 col[3] = 255;
46 }
47}
48
092578a7 49Color_t* FindColorVar(TObject* obj, const Text_t* varname)
50{
51 static const Exc_t eH("Reve::FindColorVar");
52
53 Int_t off = obj->IsA()->GetDataMemberOffset(varname);
54 if(off == 0)
55 throw(eH + "could not find member '" + varname + "' in class " + obj->IsA()->GetName() + ".");
56 return (Color_t*) (((char*)obj) + off);
57}
58
5a5a1232 59/**************************************************************************/
60/**************************************************************************/
61
62void SetupEnvironment()
63{
5987168b 64 // Check if REVESYS exists, try fallback to $ALICE_ROOT/EVE.
65 // Setup Include and Macro paths.
5a5a1232 66
67 static const Exc_t eH("Reve::SetupEnvironment");
68
69 if(gSystem->Getenv("REVESYS") == 0) {
70 if(gSystem->Getenv("ALICE_ROOT") != 0) {
71 Info(eH.Data(), "setting REVESYS from ALICE_ROOT.");
72 gSystem->Setenv("REVESYS", Form("%s/EVE", gSystem->Getenv("ALICE_ROOT")));
73 } else {
74 Error(eH.Data(), "REVESYS not defined, neither is ALICE_ROOT.");
75 gSystem->Exit(1);
76 }
77 }
78 if(gSystem->AccessPathName(gSystem->Getenv("REVESYS")) == kTRUE) {
79 Error(eH.Data(), "REVESYS '%s' does not exist.", gSystem->Getenv("REVESYS"));
80 gSystem->Exit(1);
81 }
5987168b 82
83 TString macPath(gROOT->GetMacroPath());
84 macPath += Form(":%s/macros", gSystem->Getenv("REVESYS"));
85 gInterpreter->AddIncludePath(gSystem->Getenv("REVESYS"));
86 if(gSystem->Getenv("ALICE_ROOT") != 0) {
87 macPath += Form(":%s/alice-macros", gSystem->Getenv("REVESYS"));
88 gInterpreter->AddIncludePath(Form("%s/include", gSystem->Getenv("ALICE_ROOT")));
89 gInterpreter->AddIncludePath(gSystem->Getenv("ALICE_ROOT"));
90 }
91 gROOT->SetMacroPath(macPath);
5a5a1232 92}
93
94/**************************************************************************/
95
96namespace {
97 void ChompTail(TString& s, char c='.') {
98 Ssiz_t p = s.Last(c);
99 if(p != kNPOS)
100 s.Remove(p);
101 }
102}
103
f8fae956 104Bool_t CheckMacro(const Text_t* mac)
105{
4fc7595c 106 // Checks if macro 'mac' is loaded.
f8fae956 107
4fc7595c 108 return gROOT->GetInterpreter()->IsLoaded(mac);
109
110 // Previous version expected function with same name and used ROOT's
111 // list of global functions.
112 /*
f8fae956 113 TString foo(mac); ChompTail(foo);
4fc7595c 114 if(recreate) {
115 TCollection* logf = gROOT->GetListOfGlobalFunctions(kFALSE);
116 logf->SetOwner();
117 logf->Clear();
118 }
f8fae956 119 return (gROOT->GetGlobalFunction(foo.Data(), 0, kTRUE) != 0);
4fc7595c 120 */
f8fae956 121}
122
5a5a1232 123void AssertMacro(const Text_t* mac)
124{
125 // Load and execute macro 'mac' if it has not been loaded yet.
126
f8fae956 127 if(CheckMacro(mac) == kFALSE) {
5a5a1232 128 gROOT->Macro(mac);
129 }
130}
131
132void Macro(const Text_t* mac)
133{
134 // Execute macro 'mac'. Do not reload the macro.
135
4fc7595c 136 if(CheckMacro(mac) == kFALSE) {
5a5a1232 137 gROOT->LoadMacro(mac);
f8fae956 138 }
4fc7595c 139 TString foo(mac); ChompTail(foo); foo += "()";
5a5a1232 140 gROOT->ProcessLine(foo.Data());
141}
142
143void LoadMacro(const Text_t* mac)
144{
145 // Makes sure that macro 'mac' is loaded, but do not reload it.
146
f8fae956 147 if(CheckMacro(mac) == kFALSE) {
5a5a1232 148 gROOT->LoadMacro(mac);
f8fae956 149 }
5a5a1232 150}
151
152/**************************************************************************/
153/**************************************************************************/
154
155// Pad stack for RINT/GUI thread.
156std::list<TVirtualPad*> s_Pad_Stack;
157
158TVirtualPad* PushPad(TVirtualPad* new_gpad, Int_t subpad)
159{
160 // printf("Reve::PushPad old=%p, new=%p\n", gPad, new_gpad);
161 s_Pad_Stack.push_back(gPad);
162 if(new_gpad != 0)
163 new_gpad->cd(subpad);
164 else
165 gPad = 0;
166 return gPad;
167}
168
169TVirtualPad* PopPad(Bool_t modify_update_p)
170{
171 // printf("Reve::PopPad old=%p, new=%p\n", gPad, s_Pad_Stack.empty() ? 0 : s_Pad_Stack.back());
172 if(s_Pad_Stack.empty()) {
173 Warning("Reve::PopTPad", "stack empty.");
174 } else {
175 if(modify_update_p && gPad != 0) {
176 gPad->Modified();
177 gPad->Update();
178 }
179 gPad = s_Pad_Stack.back();
180 s_Pad_Stack.pop_back();
181 }
182 return gPad;
183}
184
185/**************************************************************************/
186//
187/**************************************************************************/
188
189GeoManagerHolder::GeoManagerHolder(TGeoManager* new_gmgr) :
190 fManager(gGeoManager)
191{
192 gGeoManager = new_gmgr;
193}
194
195GeoManagerHolder::~GeoManagerHolder()
196{
197 gGeoManager = fManager;
198}
199
200
201}