7 #include <TGeoManager.h>
13 #include <TInterpreter.h>
19 //______________________________________________________________________
23 /**************************************************************************/
24 /**************************************************************************/
26 /**************************************************************************/
29 // TString .vs. string
31 bool operator==(const TString& t, const std::string& s)
32 { return (s == t.Data()); }
34 bool operator==(const std::string& s, const TString& t)
35 { return (s == t.Data()); }
39 Exc_t::Exc_t(const std::string& s) : TString(s.c_str()) {}
43 Exc_t operator+(const Exc_t &s1, const std::string &s2)
44 { return Exc_t((TString&)s1 + s2.c_str()); }
46 Exc_t operator+(const Exc_t &s1, const TString &s2)
47 { return Exc_t((TString&)s1 + s2); }
49 Exc_t operator+(const Exc_t &s1, const char *s2)
50 { return Exc_t((TString&)s1 + s2); }
52 // ----------------------------------------------------------------
54 void WarnCaller(const TString& warning)
56 std::cout << "WRN: " << warning << std::endl;
59 /**************************************************************************/
60 /**************************************************************************/
62 void SetupEnvironment()
64 // Check if REVESYS exists, try fallback to $ALICE_ROOT/EVE.
65 // Setup Include and Macro paths.
67 static const Exc_t eH("Reve::SetupEnvironment");
68 static Bool_t setupDone = kFALSE;
71 Info(eH.Data(), "has already been run.");
75 if(gSystem->Getenv("REVESYS") == 0) {
76 if(gSystem->Getenv("ALICE_ROOT") != 0) {
77 Info(eH.Data(), "setting REVESYS from ALICE_ROOT.");
78 gSystem->Setenv("REVESYS", Form("%s/EVE", gSystem->Getenv("ALICE_ROOT")));
80 Error(eH.Data(), "REVESYS not defined, neither is ALICE_ROOT.");
84 if(gSystem->AccessPathName(gSystem->Getenv("REVESYS")) == kTRUE) {
85 Error(eH.Data(), "REVESYS '%s' does not exist.", gSystem->Getenv("REVESYS"));
89 TString macPath(gROOT->GetMacroPath());
90 macPath += Form(":%s/macros", gSystem->Getenv("REVESYS"));
91 gInterpreter->AddIncludePath(gSystem->Getenv("REVESYS"));
92 if(gSystem->Getenv("ALICE_ROOT") != 0) {
93 macPath += Form(":%s/alice-macros", gSystem->Getenv("REVESYS"));
94 gInterpreter->AddIncludePath(Form("%s/include", gSystem->Getenv("ALICE_ROOT")));
95 gInterpreter->AddIncludePath(gSystem->Getenv("ALICE_ROOT"));
97 gROOT->SetMacroPath(macPath);
102 /**************************************************************************/
105 void ChompTail(TString& s, char c='.') {
106 Ssiz_t p = s.Last(c);
112 Bool_t CheckMacro(const Text_t* mac)
114 // Checks if macro 'mac' is loaded.
116 return gROOT->GetInterpreter()->IsLoaded(mac);
118 // Previous version expected function with same name and used ROOT's
119 // list of global functions.
121 TString foo(mac); ChompTail(foo);
123 TCollection* logf = gROOT->GetListOfGlobalFunctions(kFALSE);
127 return (gROOT->GetGlobalFunction(foo.Data(), 0, kTRUE) != 0);
131 void AssertMacro(const Text_t* mac)
133 // Load and execute macro 'mac' if it has not been loaded yet.
135 if(CheckMacro(mac) == kFALSE) {
140 void Macro(const Text_t* mac)
142 // Execute macro 'mac'. Do not reload the macro.
144 if(CheckMacro(mac) == kFALSE) {
145 gROOT->LoadMacro(mac);
147 TString foo(mac); ChompTail(foo); foo += "()";
148 gROOT->ProcessLine(foo.Data());
151 void LoadMacro(const Text_t* mac)
153 // Makes sure that macro 'mac' is loaded, but do not reload it.
155 if(CheckMacro(mac) == kFALSE) {
156 gROOT->LoadMacro(mac);
160 /**************************************************************************/
161 /**************************************************************************/
163 // Pad stack for RINT/GUI thread.
164 std::list<TVirtualPad*> s_Pad_Stack;
166 TVirtualPad* PushPad(TVirtualPad* new_gpad, Int_t subpad)
168 // printf("Reve::PushPad old=%p, new=%p\n", gPad, new_gpad);
169 s_Pad_Stack.push_back(gPad);
171 new_gpad->cd(subpad);
177 TVirtualPad* PopPad(Bool_t modify_update_p)
179 // printf("Reve::PopPad old=%p, new=%p\n", gPad, s_Pad_Stack.empty() ? 0 : s_Pad_Stack.back());
180 if(s_Pad_Stack.empty()) {
181 Warning("Reve::PopTPad", "stack empty.");
183 if(modify_update_p && gPad != 0) {
187 gPad = s_Pad_Stack.back();
188 s_Pad_Stack.pop_back();
193 /**************************************************************************/
195 /**************************************************************************/
197 GeoManagerHolder::GeoManagerHolder(TGeoManager* new_gmgr) :
198 fManager(gGeoManager)
200 gGeoManager = new_gmgr;
203 GeoManagerHolder::~GeoManagerHolder()
205 gGeoManager = fManager;
208 /**************************************************************************/
209 // Color, palette management
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);
250 /**************************************************************************/
252 /**************************************************************************/
254 RGBAPalette::RGBAPalette() :
256 Reve::ReferenceCount(),
257 fInterpolate (kFALSE),
264 RGBAPalette::RGBAPalette(Int_t min, Int_t max) :
266 Reve::ReferenceCount(),
267 fInterpolate (kFALSE),
274 RGBAPalette::RGBAPalette(Int_t min, Int_t max, Bool_t interp, Bool_t wrap) :
276 Reve::ReferenceCount(),
277 fInterpolate (interp),
284 RGBAPalette::~RGBAPalette()
286 delete [] fColorArray;
289 /**************************************************************************/
291 void RGBAPalette::SetupColor(Int_t val, UChar_t* pixel) const
293 using namespace TMath;
294 Float_t div = Max(1, fMaxVal - fMinVal);
295 Int_t nCol = gStyle->GetNumberOfColors();
298 if (val <= fMinVal) f = 0;
299 else if (val >= fMaxVal) f = nCol - 1;
300 else f = (val - fMinVal)/div*(nCol - 1);
303 Int_t bin = (Int_t) f;
304 Float_t f1 = f - bin, f2 = 1.0f - f1;
305 ColorFromIdx(f1, gStyle->GetColorPalette(bin),
306 f2, gStyle->GetColorPalette(Min(bin + 1, nCol - 1)),
309 ColorFromIdx(gStyle->GetColorPalette((Int_t) Nint(f)), pixel);
313 void RGBAPalette::SetupColorArray() const
318 fColorArray = new UChar_t [4 * fNBins];
319 UChar_t* p = fColorArray;
320 for(Int_t v=fMinVal; v<=fMaxVal; ++v, p+=4)
324 void RGBAPalette::ClearColorArray()
327 delete [] fColorArray;
332 /**************************************************************************/
334 void RGBAPalette::SetMinMax(Int_t min, Int_t max)
338 fNBins = max - min + 1;
342 void RGBAPalette::SetInterpolate(Bool_t b)
348 void RGBAPalette::SetWrap(Bool_t b)
353 /**************************************************************************/
354 } // end namespace Reve
355 /**************************************************************************/
356 /**************************************************************************/