4 #include "RenderElement.h"
8 #include <TGeoManager.h>
15 #include <TInterpreter.h>
21 //______________________________________________________________________
25 /**************************************************************************/
26 /**************************************************************************/
28 /**************************************************************************/
31 // TString .vs. string
33 bool operator==(const TString& t, const std::string& s)
34 { return (s == t.Data()); }
36 bool operator==(const std::string& s, const TString& t)
37 { return (s == t.Data()); }
41 Exc_t::Exc_t(const std::string& s) : TString(s.c_str()) {}
45 Exc_t operator+(const Exc_t &s1, const std::string &s2)
46 { return Exc_t((TString&)s1 + s2.c_str()); }
48 Exc_t operator+(const Exc_t &s1, const TString &s2)
49 { return Exc_t((TString&)s1 + s2); }
51 Exc_t operator+(const Exc_t &s1, const char *s2)
52 { return Exc_t((TString&)s1 + s2); }
54 // ----------------------------------------------------------------
56 void WarnCaller(const TString& warning)
58 std::cout << "WRN: " << warning << std::endl;
61 /**************************************************************************/
62 /**************************************************************************/
64 void SetupEnvironment()
66 // Check if REVESYS exists, try fallback to $ALICE_ROOT/EVE.
67 // Setup Include and Macro paths.
69 static const Exc_t eH("Reve::SetupEnvironment");
70 static Bool_t setupDone = kFALSE;
73 Info(eH.Data(), "has already been run.");
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")));
82 Error(eH.Data(), "REVESYS not defined, neither is ALICE_ROOT.");
86 if(gSystem->AccessPathName(gSystem->Getenv("REVESYS")) == kTRUE) {
87 Error(eH.Data(), "REVESYS '%s' does not exist.", gSystem->Getenv("REVESYS"));
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"));
99 gROOT->SetMacroPath(macPath);
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");
114 /**************************************************************************/
117 void ChompTail(TString& s, char c='.') {
118 Ssiz_t p = s.Last(c);
124 Bool_t CheckMacro(const Text_t* mac)
126 // Checks if macro 'mac' is loaded.
128 return gROOT->GetInterpreter()->IsLoaded(mac);
130 // Previous version expected function with same name and used ROOT's
131 // list of global functions.
133 TString foo(mac); ChompTail(foo);
135 TCollection* logf = gROOT->GetListOfGlobalFunctions(kFALSE);
139 return (gROOT->GetGlobalFunction(foo.Data(), 0, kTRUE) != 0);
143 void AssertMacro(const Text_t* mac)
145 // Load and execute macro 'mac' if it has not been loaded yet.
147 if(CheckMacro(mac) == kFALSE) {
152 void Macro(const Text_t* mac)
154 // Execute macro 'mac'. Do not reload the macro.
156 if(CheckMacro(mac) == kFALSE) {
157 gROOT->LoadMacro(mac);
159 TString foo(mac); ChompTail(foo); foo += "()";
160 gROOT->ProcessLine(foo.Data());
163 void LoadMacro(const Text_t* mac)
165 // Makes sure that macro 'mac' is loaded, but do not reload it.
167 if(CheckMacro(mac) == kFALSE) {
168 gROOT->LoadMacro(mac);
172 /**************************************************************************/
173 /**************************************************************************/
175 // Pad stack for RINT/GUI thread.
176 std::list<TVirtualPad*> s_Pad_Stack;
178 TVirtualPad* PushPad(TVirtualPad* new_gpad, Int_t subpad)
180 // printf("Reve::PushPad old=%p, new=%p\n", gPad, new_gpad);
181 s_Pad_Stack.push_back(gPad);
183 new_gpad->cd(subpad);
189 TVirtualPad* PopPad(Bool_t modify_update_p)
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.");
195 if(modify_update_p && gPad != 0) {
199 gPad = s_Pad_Stack.back();
200 s_Pad_Stack.pop_back();
205 /**************************************************************************/
207 /**************************************************************************/
209 GeoManagerHolder::GeoManagerHolder(TGeoManager* new_gmgr) :
210 fManager(gGeoManager)
212 gGeoManager = new_gmgr;
215 GeoManagerHolder::~GeoManagerHolder()
217 gGeoManager = fManager;
221 /**************************************************************************/
223 /**************************************************************************/
225 void ColorFromIdx(Color_t ci, UChar_t* col, Bool_t alpha)
228 col[0] = col[1] = col[2] = col[3] = 0;
231 TColor* c = gROOT->GetColor(ci);
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;
240 void ColorFromIdx(Float_t f1, Color_t c1, Float_t f2, Color_t c2,
241 UChar_t* col, Bool_t alpha)
243 TColor* t1 = gROOT->GetColor(c1);
244 TColor* t2 = gROOT->GetColor(c2);
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;
253 Color_t* FindColorVar(TObject* obj, const Text_t* varname)
255 static const Exc_t eH("Reve::FindColorVar");
257 Int_t off = obj->IsA()->GetDataMemberOffset(varname);
259 throw(eH + "could not find member '" + varname + "' in class " + obj->IsA()->GetName() + ".");
260 return (Color_t*) (((char*)obj) + off);
264 /**************************************************************************/
265 } // end namespace Reve
266 /**************************************************************************/
267 /**************************************************************************/
269 using namespace Reve;
271 /**************************************************************************/
273 /**************************************************************************/
275 ClassImp(ReferenceBackPtr)
277 ReferenceBackPtr::ReferenceBackPtr() :
282 ReferenceBackPtr::~ReferenceBackPtr()
284 // !!!! Complain if list not empty.
287 ReferenceBackPtr::ReferenceBackPtr(const ReferenceBackPtr&) :
292 ReferenceBackPtr& ReferenceBackPtr::operator=(const ReferenceBackPtr&)
297 /**************************************************************************/
299 void ReferenceBackPtr::IncRefCount(RenderElement* re)
301 ReferenceCount::IncRefCount();
302 fBackRefs.push_back(re);
305 void ReferenceBackPtr::DecRefCount(RenderElement* re)
307 static const Exc_t eH("ReferenceBackPtr::DecRefCount ");
309 std::list<RenderElement*>::iterator i =
310 std::find(fBackRefs.begin(), fBackRefs.end(), re);
311 if (i != fBackRefs.end()) {
313 ReferenceCount::DecRefCount();
315 Warning(eH, Form("render element '%s' not found in back-refs.",
316 re->GetObject()->GetName()));
320 /**************************************************************************/
322 void ReferenceBackPtr::UpdateBackPtrItems()
324 std::list<RenderElement*>::iterator i = fBackRefs.begin();
325 while (i != fBackRefs.end())