]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/Reve/Reve.cxx
Added function to create 4 check box pictures which mark fRnrSelf and fRnrChildren...
[u/mrichter/AliRoot.git] / EVE / Reve / Reve.cxx
CommitLineData
5a5a1232 1// $Header$
2
3#include "Reve.h"
465af230 4#include "RenderElement.h"
5a5a1232 5
6#include <TError.h>
7#include <TPad.h>
8#include <TGeoManager.h>
0b28fd57 9#include <TClass.h>
51a6ecc6 10
11#include <TStyle.h>
915dabe1 12#include <TColor.h>
5a5a1232 13
14#include <TROOT.h>
5987168b 15#include <TInterpreter.h>
5a5a1232 16
83f960dc 17#include <TGClient.h>
18
5a5a1232 19#include <iostream>
20
21//______________________________________________________________________
22// Reve
23//
24
51a6ecc6 25/**************************************************************************/
26/**************************************************************************/
5a5a1232 27namespace Reve {
51a6ecc6 28/**************************************************************************/
29
5a5a1232 30
a8600b56 31// TString .vs. string
32
33bool operator==(const TString& t, const std::string& s)
34{ return (s == t.Data()); }
35
36bool operator==(const std::string& s, const TString& t)
37{ return (s == t.Data()); }
38
39// Exc
40
41Exc_t::Exc_t(const std::string& s) : TString(s.c_str()) {}
42
43// Exc + ops
44
5a5a1232 45Exc_t operator+(const Exc_t &s1, const std::string &s2)
770a6032 46{ return Exc_t((TString&)s1 + s2.c_str()); }
5a5a1232 47
48Exc_t operator+(const Exc_t &s1, const TString &s2)
770a6032 49{ return Exc_t((TString&)s1 + s2); }
5a5a1232 50
51Exc_t operator+(const Exc_t &s1, const char *s2)
770a6032 52{ return Exc_t((TString&)s1 + s2); }
5a5a1232 53
a8600b56 54// ----------------------------------------------------------------
5a5a1232 55
56void WarnCaller(const TString& warning)
57{
58 std::cout << "WRN: " << warning << std::endl;
59}
60
61/**************************************************************************/
62/**************************************************************************/
63
64void SetupEnvironment()
65{
5987168b 66 // Check if REVESYS exists, try fallback to $ALICE_ROOT/EVE.
67 // Setup Include and Macro paths.
5a5a1232 68
69 static const Exc_t eH("Reve::SetupEnvironment");
a8600b56 70 static Bool_t setupDone = kFALSE;
71
72 if (setupDone) {
73 Info(eH.Data(), "has already been run.");
74 return;
75 }
5a5a1232 76
77 if(gSystem->Getenv("REVESYS") == 0) {
78 if(gSystem->Getenv("ALICE_ROOT") != 0) {
79 Info(eH.Data(), "setting REVESYS from ALICE_ROOT.");
80 gSystem->Setenv("REVESYS", Form("%s/EVE", gSystem->Getenv("ALICE_ROOT")));
81 } else {
82 Error(eH.Data(), "REVESYS not defined, neither is ALICE_ROOT.");
83 gSystem->Exit(1);
84 }
85 }
86 if(gSystem->AccessPathName(gSystem->Getenv("REVESYS")) == kTRUE) {
87 Error(eH.Data(), "REVESYS '%s' does not exist.", gSystem->Getenv("REVESYS"));
88 gSystem->Exit(1);
89 }
5987168b 90
91 TString macPath(gROOT->GetMacroPath());
92 macPath += Form(":%s/macros", gSystem->Getenv("REVESYS"));
93 gInterpreter->AddIncludePath(gSystem->Getenv("REVESYS"));
94 if(gSystem->Getenv("ALICE_ROOT") != 0) {
95 macPath += Form(":%s/alice-macros", gSystem->Getenv("REVESYS"));
96 gInterpreter->AddIncludePath(Form("%s/include", gSystem->Getenv("ALICE_ROOT")));
97 gInterpreter->AddIncludePath(gSystem->Getenv("ALICE_ROOT"));
98 }
99 gROOT->SetMacroPath(macPath);
83f960dc 100}
a8600b56 101
83f960dc 102void SetupGUI()
103{
104 TString fld( Form("%s/icons/", gSystem->Getenv("REVESYS")) );
105 // printf("foofoo %p %p %p %p\n",
106 // RenderElement::fgRnrIcons[0],RenderElement::fgRnrIcons[1],
107 // RenderElement::fgRnrIcons[2],RenderElement::fgRnrIcons[3]);
108 RenderElement::fgRnrIcons[0] = gClient->GetPicture(fld + "rnr00_t.xpm");
109 RenderElement::fgRnrIcons[1] = gClient->GetPicture(fld + "rnr01_t.xpm");
110 RenderElement::fgRnrIcons[2] = gClient->GetPicture(fld + "rnr10_t.xpm");
111 RenderElement::fgRnrIcons[3] = gClient->GetPicture(fld + "rnr11_t.xpm");
5a5a1232 112}
113
114/**************************************************************************/
115
116namespace {
117 void ChompTail(TString& s, char c='.') {
118 Ssiz_t p = s.Last(c);
119 if(p != kNPOS)
120 s.Remove(p);
121 }
122}
123
f8fae956 124Bool_t CheckMacro(const Text_t* mac)
125{
4fc7595c 126 // Checks if macro 'mac' is loaded.
f8fae956 127
4fc7595c 128 return gROOT->GetInterpreter()->IsLoaded(mac);
129
130 // Previous version expected function with same name and used ROOT's
131 // list of global functions.
132 /*
f8fae956 133 TString foo(mac); ChompTail(foo);
4fc7595c 134 if(recreate) {
135 TCollection* logf = gROOT->GetListOfGlobalFunctions(kFALSE);
136 logf->SetOwner();
137 logf->Clear();
138 }
f8fae956 139 return (gROOT->GetGlobalFunction(foo.Data(), 0, kTRUE) != 0);
4fc7595c 140 */
f8fae956 141}
142
5a5a1232 143void AssertMacro(const Text_t* mac)
144{
145 // Load and execute macro 'mac' if it has not been loaded yet.
146
f8fae956 147 if(CheckMacro(mac) == kFALSE) {
5a5a1232 148 gROOT->Macro(mac);
149 }
150}
151
152void Macro(const Text_t* mac)
153{
154 // Execute macro 'mac'. Do not reload the macro.
155
4fc7595c 156 if(CheckMacro(mac) == kFALSE) {
5a5a1232 157 gROOT->LoadMacro(mac);
f8fae956 158 }
4fc7595c 159 TString foo(mac); ChompTail(foo); foo += "()";
5a5a1232 160 gROOT->ProcessLine(foo.Data());
161}
162
163void LoadMacro(const Text_t* mac)
164{
165 // Makes sure that macro 'mac' is loaded, but do not reload it.
166
f8fae956 167 if(CheckMacro(mac) == kFALSE) {
5a5a1232 168 gROOT->LoadMacro(mac);
f8fae956 169 }
5a5a1232 170}
171
172/**************************************************************************/
173/**************************************************************************/
174
175// Pad stack for RINT/GUI thread.
176std::list<TVirtualPad*> s_Pad_Stack;
177
178TVirtualPad* PushPad(TVirtualPad* new_gpad, Int_t subpad)
179{
180 // printf("Reve::PushPad old=%p, new=%p\n", gPad, new_gpad);
181 s_Pad_Stack.push_back(gPad);
182 if(new_gpad != 0)
183 new_gpad->cd(subpad);
184 else
185 gPad = 0;
186 return gPad;
187}
188
189TVirtualPad* PopPad(Bool_t modify_update_p)
190{
191 // printf("Reve::PopPad old=%p, new=%p\n", gPad, s_Pad_Stack.empty() ? 0 : s_Pad_Stack.back());
192 if(s_Pad_Stack.empty()) {
193 Warning("Reve::PopTPad", "stack empty.");
194 } else {
195 if(modify_update_p && gPad != 0) {
196 gPad->Modified();
197 gPad->Update();
198 }
199 gPad = s_Pad_Stack.back();
200 s_Pad_Stack.pop_back();
201 }
202 return gPad;
203}
204
205/**************************************************************************/
465af230 206// GeoManagerHolder
5a5a1232 207/**************************************************************************/
208
209GeoManagerHolder::GeoManagerHolder(TGeoManager* new_gmgr) :
210 fManager(gGeoManager)
211{
212 gGeoManager = new_gmgr;
213}
214
215GeoManagerHolder::~GeoManagerHolder()
216{
217 gGeoManager = fManager;
218}
219
465af230 220
51a6ecc6 221/**************************************************************************/
843e6acd 222// Color management
51a6ecc6 223/**************************************************************************/
224
225void ColorFromIdx(Color_t ci, UChar_t* col, Bool_t alpha)
226{
227 if (ci < 0) {
228 col[0] = col[1] = col[2] = col[3] = 0;
229 return;
230 }
231 TColor* c = gROOT->GetColor(ci);
232 if(c) {
233 col[0] = (UChar_t)(255*c->GetRed());
234 col[1] = (UChar_t)(255*c->GetGreen());
235 col[2] = (UChar_t)(255*c->GetBlue());
236 if (alpha) col[3] = 255;
237 }
238}
5a5a1232 239
51a6ecc6 240void ColorFromIdx(Float_t f1, Color_t c1, Float_t f2, Color_t c2,
241 UChar_t* col, Bool_t alpha)
242{
243 TColor* t1 = gROOT->GetColor(c1);
244 TColor* t2 = gROOT->GetColor(c2);
245 if(t1 && t2) {
246 col[0] = (UChar_t)(255*(f1*t1->GetRed() + f2*t2->GetRed()));
247 col[1] = (UChar_t)(255*(f1*t1->GetGreen() + f2*t2->GetGreen()));
248 col[2] = (UChar_t)(255*(f1*t1->GetBlue() + f2*t2->GetBlue()));
249 if (alpha) col[3] = 255;
250 }
5a5a1232 251}
51a6ecc6 252
253Color_t* FindColorVar(TObject* obj, const Text_t* varname)
254{
255 static const Exc_t eH("Reve::FindColorVar");
256
257 Int_t off = obj->IsA()->GetDataMemberOffset(varname);
258 if(off == 0)
259 throw(eH + "could not find member '" + varname + "' in class " + obj->IsA()->GetName() + ".");
260 return (Color_t*) (((char*)obj) + off);
261}
262
51a6ecc6 263
264/**************************************************************************/
265} // end namespace Reve
266/**************************************************************************/
267/**************************************************************************/
465af230 268
269using namespace Reve;
270
271/**************************************************************************/
272// ReferenceBackPtr
273/**************************************************************************/
274
275ClassImp(ReferenceBackPtr)
276
277ReferenceBackPtr::ReferenceBackPtr() :
278 ReferenceCount(),
279 fBackRefs()
280{}
281
282ReferenceBackPtr::~ReferenceBackPtr()
283{
284 // !!!! Complain if list not empty.
285}
286
287ReferenceBackPtr::ReferenceBackPtr(const ReferenceBackPtr&) :
288 ReferenceCount(),
289 fBackRefs()
290{}
291
292ReferenceBackPtr& ReferenceBackPtr::operator=(const ReferenceBackPtr&)
293{
294 return *this;
295}
296
297/**************************************************************************/
298
299void ReferenceBackPtr::IncRefCount(RenderElement* re)
300{
301 ReferenceCount::IncRefCount();
302 fBackRefs.push_back(re);
303}
304
305void ReferenceBackPtr::DecRefCount(RenderElement* re)
306{
307 static const Exc_t eH("ReferenceBackPtr::DecRefCount ");
308
309 std::list<RenderElement*>::iterator i =
310 std::find(fBackRefs.begin(), fBackRefs.end(), re);
311 if (i != fBackRefs.end()) {
312 fBackRefs.erase(i);
313 ReferenceCount::DecRefCount();
314 } else {
315 Warning(eH, Form("render element '%s' not found in back-refs.",
316 re->GetObject()->GetName()));
317 }
318}
319
320/**************************************************************************/
321
322void ReferenceBackPtr::UpdateBackPtrItems()
323{
324 std::list<RenderElement*>::iterator i = fBackRefs.begin();
325 while (i != fBackRefs.end())
326 {
327 (*i)->UpdateItems();
328 ++i;
329 }
330}