7 #include <TGeoManager.h>
11 #include <TInterpreter.h>
17 //______________________________________________________________________
23 Exc_t operator+(const Exc_t &s1, const std::string &s2)
24 { return Exc_t((std::string&)s1 + s2); }
26 Exc_t operator+(const Exc_t &s1, const TString &s2)
27 { return Exc_t((std::string&)s1 + s2.Data()); }
29 Exc_t operator+(const Exc_t &s1, const char *s2)
30 { return Exc_t((std::string&)s1 + s2); }
33 void WarnCaller(const TString& warning)
35 std::cout << "WRN: " << warning << std::endl;
38 void ColorFromIdx(Color_t ci, UChar_t* col)
40 TColor* c = gROOT->GetColor(ci);
42 col[0] = (UChar_t)(255*c->GetRed());
43 col[1] = (UChar_t)(255*c->GetGreen());
44 col[2] = (UChar_t)(255*c->GetBlue());
49 Color_t* FindColorVar(TObject* obj, const Text_t* varname)
51 static const Exc_t eH("Reve::FindColorVar");
53 Int_t off = obj->IsA()->GetDataMemberOffset(varname);
55 throw(eH + "could not find member '" + varname + "' in class " + obj->IsA()->GetName() + ".");
56 return (Color_t*) (((char*)obj) + off);
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");
69 if(gSystem->Getenv("REVESYS") == 0) {
70 if(gSystem->Getenv("ALICE_ROOT") != 0) {
71 Info(eH.Data(), "setting REVESYS from ALICE_ROOT.");
72 gSystem->Setenv("REVESYS", Form("%s/EVE", gSystem->Getenv("ALICE_ROOT")));
74 Error(eH.Data(), "REVESYS not defined, neither is ALICE_ROOT.");
78 if(gSystem->AccessPathName(gSystem->Getenv("REVESYS")) == kTRUE) {
79 Error(eH.Data(), "REVESYS '%s' does not exist.", gSystem->Getenv("REVESYS"));
83 TString macPath(gROOT->GetMacroPath());
84 macPath += Form(":%s/macros", gSystem->Getenv("REVESYS"));
85 gInterpreter->AddIncludePath(gSystem->Getenv("REVESYS"));
86 if(gSystem->Getenv("ALICE_ROOT") != 0) {
87 macPath += Form(":%s/alice-macros", gSystem->Getenv("REVESYS"));
88 gInterpreter->AddIncludePath(Form("%s/include", gSystem->Getenv("ALICE_ROOT")));
89 gInterpreter->AddIncludePath(gSystem->Getenv("ALICE_ROOT"));
91 gROOT->SetMacroPath(macPath);
94 /**************************************************************************/
97 void ChompTail(TString& s, char c='.') {
104 Bool_t CheckMacro(const Text_t* mac)
106 // Checks if macro 'mac' is loaded.
108 return gROOT->GetInterpreter()->IsLoaded(mac);
110 // Previous version expected function with same name and used ROOT's
111 // list of global functions.
113 TString foo(mac); ChompTail(foo);
115 TCollection* logf = gROOT->GetListOfGlobalFunctions(kFALSE);
119 return (gROOT->GetGlobalFunction(foo.Data(), 0, kTRUE) != 0);
123 void AssertMacro(const Text_t* mac)
125 // Load and execute macro 'mac' if it has not been loaded yet.
127 if(CheckMacro(mac) == kFALSE) {
132 void Macro(const Text_t* mac)
134 // Execute macro 'mac'. Do not reload the macro.
136 if(CheckMacro(mac) == kFALSE) {
137 gROOT->LoadMacro(mac);
139 TString foo(mac); ChompTail(foo); foo += "()";
140 gROOT->ProcessLine(foo.Data());
143 void LoadMacro(const Text_t* mac)
145 // Makes sure that macro 'mac' is loaded, but do not reload it.
147 if(CheckMacro(mac) == kFALSE) {
148 gROOT->LoadMacro(mac);
152 /**************************************************************************/
153 /**************************************************************************/
155 // Pad stack for RINT/GUI thread.
156 std::list<TVirtualPad*> s_Pad_Stack;
158 TVirtualPad* PushPad(TVirtualPad* new_gpad, Int_t subpad)
160 // printf("Reve::PushPad old=%p, new=%p\n", gPad, new_gpad);
161 s_Pad_Stack.push_back(gPad);
163 new_gpad->cd(subpad);
169 TVirtualPad* PopPad(Bool_t modify_update_p)
171 // printf("Reve::PopPad old=%p, new=%p\n", gPad, s_Pad_Stack.empty() ? 0 : s_Pad_Stack.back());
172 if(s_Pad_Stack.empty()) {
173 Warning("Reve::PopTPad", "stack empty.");
175 if(modify_update_p && gPad != 0) {
179 gPad = s_Pad_Stack.back();
180 s_Pad_Stack.pop_back();
185 /**************************************************************************/
187 /**************************************************************************/
189 GeoManagerHolder::GeoManagerHolder(TGeoManager* new_gmgr) :
190 fManager(gGeoManager)
192 gGeoManager = new_gmgr;
195 GeoManagerHolder::~GeoManagerHolder()
197 gGeoManager = fManager;