]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/Reve/Reve.cxx
Merge from EVE-dev to HEAD.
[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>
11
12#include <list>
13
14#include <iostream>
15
16//______________________________________________________________________
17// Reve
18//
19
20namespace Reve {
21
22Exc_t operator+(const Exc_t &s1, const std::string &s2)
23{ return Exc_t((std::string&)s1 + s2); }
24
25Exc_t operator+(const Exc_t &s1, const TString &s2)
26{ return Exc_t((std::string&)s1 + s2.Data()); }
27
28Exc_t operator+(const Exc_t &s1, const char *s2)
29{ return Exc_t((std::string&)s1 + s2); }
30
31
32void WarnCaller(const TString& warning)
33{
34 std::cout << "WRN: " << warning << std::endl;
35}
36
915dabe1 37void ColorFromIdx(Color_t ci, UChar_t* col)
38{
39 TColor* c = gROOT->GetColor(ci);
40 if(c) {
41 col[0] = (UChar_t)(255*c->GetRed());
42 col[1] = (UChar_t)(255*c->GetGreen());
43 col[2] = (UChar_t)(255*c->GetBlue());
44 col[3] = 255;
45 }
46}
47
092578a7 48Color_t* FindColorVar(TObject* obj, const Text_t* varname)
49{
50 static const Exc_t eH("Reve::FindColorVar");
51
52 Int_t off = obj->IsA()->GetDataMemberOffset(varname);
53 if(off == 0)
54 throw(eH + "could not find member '" + varname + "' in class " + obj->IsA()->GetName() + ".");
55 return (Color_t*) (((char*)obj) + off);
56}
57
5a5a1232 58/**************************************************************************/
59/**************************************************************************/
60
61void SetupEnvironment()
62{
63 // Check REVESYS exists, try fallback to $ALICE_ROOT/EVE.
64
65 static const Exc_t eH("Reve::SetupEnvironment");
66
67 if(gSystem->Getenv("REVESYS") == 0) {
68 if(gSystem->Getenv("ALICE_ROOT") != 0) {
69 Info(eH.Data(), "setting REVESYS from ALICE_ROOT.");
70 gSystem->Setenv("REVESYS", Form("%s/EVE", gSystem->Getenv("ALICE_ROOT")));
71 } else {
72 Error(eH.Data(), "REVESYS not defined, neither is ALICE_ROOT.");
73 gSystem->Exit(1);
74 }
75 }
76 if(gSystem->AccessPathName(gSystem->Getenv("REVESYS")) == kTRUE) {
77 Error(eH.Data(), "REVESYS '%s' does not exist.", gSystem->Getenv("REVESYS"));
78 gSystem->Exit(1);
79 }
80}
81
82/**************************************************************************/
83
84namespace {
85 void ChompTail(TString& s, char c='.') {
86 Ssiz_t p = s.Last(c);
87 if(p != kNPOS)
88 s.Remove(p);
89 }
90}
91
92void AssertMacro(const Text_t* mac)
93{
94 // Load and execute macro 'mac' if it has not been loaded yet.
95
96 TString foo(mac); ChompTail(foo);
97 if(gROOT->GetGlobalFunction(foo.Data(), 0, true) == 0) {
98 gROOT->Macro(mac);
99 }
100}
101
102void Macro(const Text_t* mac)
103{
104 // Execute macro 'mac'. Do not reload the macro.
105
106 TString foo(mac); ChompTail(foo);
107 if(gROOT->GetGlobalFunction(foo.Data(), 0, true) == 0)
108 gROOT->LoadMacro(mac);
109
110 foo += "()";
111 gROOT->ProcessLine(foo.Data());
112}
113
114void LoadMacro(const Text_t* mac)
115{
116 // Makes sure that macro 'mac' is loaded, but do not reload it.
117
118 TString foo(mac); ChompTail(foo);
119 if(gROOT->GetGlobalFunction(foo.Data(), 0, true) == 0)
120 gROOT->LoadMacro(mac);
121}
122
123/**************************************************************************/
124/**************************************************************************/
125
126// Pad stack for RINT/GUI thread.
127std::list<TVirtualPad*> s_Pad_Stack;
128
129TVirtualPad* PushPad(TVirtualPad* new_gpad, Int_t subpad)
130{
131 // printf("Reve::PushPad old=%p, new=%p\n", gPad, new_gpad);
132 s_Pad_Stack.push_back(gPad);
133 if(new_gpad != 0)
134 new_gpad->cd(subpad);
135 else
136 gPad = 0;
137 return gPad;
138}
139
140TVirtualPad* PopPad(Bool_t modify_update_p)
141{
142 // printf("Reve::PopPad old=%p, new=%p\n", gPad, s_Pad_Stack.empty() ? 0 : s_Pad_Stack.back());
143 if(s_Pad_Stack.empty()) {
144 Warning("Reve::PopTPad", "stack empty.");
145 } else {
146 if(modify_update_p && gPad != 0) {
147 gPad->Modified();
148 gPad->Update();
149 }
150 gPad = s_Pad_Stack.back();
151 s_Pad_Stack.pop_back();
152 }
153 return gPad;
154}
155
156/**************************************************************************/
157//
158/**************************************************************************/
159
160GeoManagerHolder::GeoManagerHolder(TGeoManager* new_gmgr) :
161 fManager(gGeoManager)
162{
163 gGeoManager = new_gmgr;
164}
165
166GeoManagerHolder::~GeoManagerHolder()
167{
168 gGeoManager = fManager;
169}
170
171
172}