4 #include "RenderElement.h"
8 #include <TGeoManager.h>
14 #include <TInterpreter.h>
18 //______________________________________________________________________
22 /**************************************************************************/
23 /**************************************************************************/
25 /**************************************************************************/
28 // TString .vs. string
30 bool operator==(const TString& t, const std::string& s)
31 { return (s == t.Data()); }
33 bool operator==(const std::string& s, const TString& t)
34 { return (s == t.Data()); }
38 Exc_t::Exc_t(const std::string& s) : TString(s.c_str()) {}
42 Exc_t operator+(const Exc_t &s1, const std::string &s2)
43 { return Exc_t((TString&)s1 + s2.c_str()); }
45 Exc_t operator+(const Exc_t &s1, const TString &s2)
46 { return Exc_t((TString&)s1 + s2); }
48 Exc_t operator+(const Exc_t &s1, const char *s2)
49 { return Exc_t((TString&)s1 + s2); }
51 // ----------------------------------------------------------------
53 void WarnCaller(const TString& warning)
55 std::cout << "WRN: " << warning << std::endl;
58 /**************************************************************************/
59 /**************************************************************************/
61 void SetupEnvironment()
63 // Check if REVESYS exists, try fallback to $ALICE_ROOT/EVE.
64 // Setup Include and Macro paths.
66 static const Exc_t eH("Reve::SetupEnvironment");
67 static Bool_t setupDone = kFALSE;
70 Info(eH.Data(), "has already been run.");
74 if(gSystem->Getenv("REVESYS") == 0) {
75 if(gSystem->Getenv("ALICE_ROOT") != 0) {
76 Info(eH.Data(), "setting REVESYS from ALICE_ROOT.");
77 gSystem->Setenv("REVESYS", Form("%s/EVE", gSystem->Getenv("ALICE_ROOT")));
79 Error(eH.Data(), "REVESYS not defined, neither is ALICE_ROOT.");
83 if(gSystem->AccessPathName(gSystem->Getenv("REVESYS")) == kTRUE) {
84 Error(eH.Data(), "REVESYS '%s' does not exist.", gSystem->Getenv("REVESYS"));
88 TString macPath(gROOT->GetMacroPath());
89 macPath += Form(":%s/macros", gSystem->Getenv("REVESYS"));
90 gInterpreter->AddIncludePath(gSystem->Getenv("REVESYS"));
91 if(gSystem->Getenv("ALICE_ROOT") != 0) {
92 macPath += Form(":%s/alice-macros", gSystem->Getenv("REVESYS"));
93 gInterpreter->AddIncludePath(Form("%s/include", gSystem->Getenv("ALICE_ROOT")));
94 gInterpreter->AddIncludePath(gSystem->Getenv("ALICE_ROOT"));
96 gROOT->SetMacroPath(macPath);
101 /**************************************************************************/
104 void ChompTail(TString& s, char c='.') {
105 Ssiz_t p = s.Last(c);
111 Bool_t CheckMacro(const Text_t* mac)
113 // Checks if macro 'mac' is loaded.
115 return gROOT->GetInterpreter()->IsLoaded(mac);
117 // Previous version expected function with same name and used ROOT's
118 // list of global functions.
120 TString foo(mac); ChompTail(foo);
122 TCollection* logf = gROOT->GetListOfGlobalFunctions(kFALSE);
126 return (gROOT->GetGlobalFunction(foo.Data(), 0, kTRUE) != 0);
130 void AssertMacro(const Text_t* mac)
132 // Load and execute macro 'mac' if it has not been loaded yet.
134 if(CheckMacro(mac) == kFALSE) {
139 void Macro(const Text_t* mac)
141 // Execute macro 'mac'. Do not reload the macro.
143 if(CheckMacro(mac) == kFALSE) {
144 gROOT->LoadMacro(mac);
146 TString foo(mac); ChompTail(foo); foo += "()";
147 gROOT->ProcessLine(foo.Data());
150 void LoadMacro(const Text_t* mac)
152 // Makes sure that macro 'mac' is loaded, but do not reload it.
154 if(CheckMacro(mac) == kFALSE) {
155 gROOT->LoadMacro(mac);
159 /**************************************************************************/
160 /**************************************************************************/
162 // Pad stack for RINT/GUI thread.
163 std::list<TVirtualPad*> s_Pad_Stack;
165 TVirtualPad* PushPad(TVirtualPad* new_gpad, Int_t subpad)
167 // printf("Reve::PushPad old=%p, new=%p\n", gPad, new_gpad);
168 s_Pad_Stack.push_back(gPad);
170 new_gpad->cd(subpad);
176 TVirtualPad* PopPad(Bool_t modify_update_p)
178 // printf("Reve::PopPad old=%p, new=%p\n", gPad, s_Pad_Stack.empty() ? 0 : s_Pad_Stack.back());
179 if(s_Pad_Stack.empty()) {
180 Warning("Reve::PopTPad", "stack empty.");
182 if(modify_update_p && gPad != 0) {
186 gPad = s_Pad_Stack.back();
187 s_Pad_Stack.pop_back();
192 /**************************************************************************/
194 /**************************************************************************/
196 GeoManagerHolder::GeoManagerHolder(TGeoManager* new_gmgr) :
197 fManager(gGeoManager)
199 gGeoManager = new_gmgr;
202 GeoManagerHolder::~GeoManagerHolder()
204 gGeoManager = fManager;
208 /**************************************************************************/
210 /**************************************************************************/
212 void ColorFromIdx(Color_t ci, UChar_t* col, Bool_t alpha)
215 col[0] = col[1] = col[2] = col[3] = 0;
218 TColor* c = gROOT->GetColor(ci);
220 col[0] = (UChar_t)(255*c->GetRed());
221 col[1] = (UChar_t)(255*c->GetGreen());
222 col[2] = (UChar_t)(255*c->GetBlue());
223 if (alpha) col[3] = 255;
227 void ColorFromIdx(Float_t f1, Color_t c1, Float_t f2, Color_t c2,
228 UChar_t* col, Bool_t alpha)
230 TColor* t1 = gROOT->GetColor(c1);
231 TColor* t2 = gROOT->GetColor(c2);
233 col[0] = (UChar_t)(255*(f1*t1->GetRed() + f2*t2->GetRed()));
234 col[1] = (UChar_t)(255*(f1*t1->GetGreen() + f2*t2->GetGreen()));
235 col[2] = (UChar_t)(255*(f1*t1->GetBlue() + f2*t2->GetBlue()));
236 if (alpha) col[3] = 255;
240 Color_t* FindColorVar(TObject* obj, const Text_t* varname)
242 static const Exc_t eH("Reve::FindColorVar");
244 Int_t off = obj->IsA()->GetDataMemberOffset(varname);
246 throw(eH + "could not find member '" + varname + "' in class " + obj->IsA()->GetName() + ".");
247 return (Color_t*) (((char*)obj) + off);
251 /**************************************************************************/
252 } // end namespace Reve
253 /**************************************************************************/
254 /**************************************************************************/
256 using namespace Reve;
258 /**************************************************************************/
260 /**************************************************************************/
262 ClassImp(ReferenceBackPtr)
264 ReferenceBackPtr::ReferenceBackPtr() :
269 ReferenceBackPtr::~ReferenceBackPtr()
271 // !!!! Complain if list not empty.
274 ReferenceBackPtr::ReferenceBackPtr(const ReferenceBackPtr&) :
279 ReferenceBackPtr& ReferenceBackPtr::operator=(const ReferenceBackPtr&)
284 /**************************************************************************/
286 void ReferenceBackPtr::IncRefCount(RenderElement* re)
288 ReferenceCount::IncRefCount();
289 fBackRefs.push_back(re);
292 void ReferenceBackPtr::DecRefCount(RenderElement* re)
294 static const Exc_t eH("ReferenceBackPtr::DecRefCount ");
296 std::list<RenderElement*>::iterator i =
297 std::find(fBackRefs.begin(), fBackRefs.end(), re);
298 if (i != fBackRefs.end()) {
300 ReferenceCount::DecRefCount();
302 Warning(eH, Form("render element '%s' not found in back-refs.",
303 re->GetObject()->GetName()));
307 /**************************************************************************/
309 void ReferenceBackPtr::UpdateBackPtrItems()
311 std::list<RenderElement*>::iterator i = fBackRefs.begin();
312 while (i != fBackRefs.end())