]>
Commit | Line | Data |
---|---|---|
5a5a1232 | 1 | // $Header$ |
2 | ||
3 | #include "Reve.h" | |
4 | ||
5 | #include <TError.h> | |
6 | #include <TPad.h> | |
7 | #include <TGeoManager.h> | |
915dabe1 | 8 | #include <TColor.h> |
5a5a1232 | 9 | |
10 | #include <TROOT.h> | |
11 | ||
12 | #include <list> | |
13 | ||
14 | #include <iostream> | |
15 | ||
16 | //______________________________________________________________________ | |
17 | // Reve | |
18 | // | |
19 | ||
20 | namespace Reve { | |
21 | ||
22 | Exc_t operator+(const Exc_t &s1, const std::string &s2) | |
23 | { return Exc_t((std::string&)s1 + s2); } | |
24 | ||
25 | Exc_t operator+(const Exc_t &s1, const TString &s2) | |
26 | { return Exc_t((std::string&)s1 + s2.Data()); } | |
27 | ||
28 | Exc_t operator+(const Exc_t &s1, const char *s2) | |
29 | { return Exc_t((std::string&)s1 + s2); } | |
30 | ||
31 | ||
32 | void WarnCaller(const TString& warning) | |
33 | { | |
34 | std::cout << "WRN: " << warning << std::endl; | |
35 | } | |
36 | ||
915dabe1 | 37 | void ColorFromIdx(Color_t ci, UChar_t* col) |
38 | { | |
39 | TColor* c = gROOT->GetColor(ci); | |
40 | if(c) { | |
41 | col[0] = (UChar_t)(255*c->GetRed()); | |
42 | col[1] = (UChar_t)(255*c->GetGreen()); | |
43 | col[2] = (UChar_t)(255*c->GetBlue()); | |
44 | col[3] = 255; | |
45 | } | |
46 | } | |
47 | ||
5a5a1232 | 48 | /**************************************************************************/ |
49 | /**************************************************************************/ | |
50 | ||
51 | void SetupEnvironment() | |
52 | { | |
53 | // Check REVESYS exists, try fallback to $ALICE_ROOT/EVE. | |
54 | ||
55 | static const Exc_t eH("Reve::SetupEnvironment"); | |
56 | ||
57 | if(gSystem->Getenv("REVESYS") == 0) { | |
58 | if(gSystem->Getenv("ALICE_ROOT") != 0) { | |
59 | Info(eH.Data(), "setting REVESYS from ALICE_ROOT."); | |
60 | gSystem->Setenv("REVESYS", Form("%s/EVE", gSystem->Getenv("ALICE_ROOT"))); | |
61 | } else { | |
62 | Error(eH.Data(), "REVESYS not defined, neither is ALICE_ROOT."); | |
63 | gSystem->Exit(1); | |
64 | } | |
65 | } | |
66 | if(gSystem->AccessPathName(gSystem->Getenv("REVESYS")) == kTRUE) { | |
67 | Error(eH.Data(), "REVESYS '%s' does not exist.", gSystem->Getenv("REVESYS")); | |
68 | gSystem->Exit(1); | |
69 | } | |
70 | } | |
71 | ||
72 | /**************************************************************************/ | |
73 | ||
74 | namespace { | |
75 | void ChompTail(TString& s, char c='.') { | |
76 | Ssiz_t p = s.Last(c); | |
77 | if(p != kNPOS) | |
78 | s.Remove(p); | |
79 | } | |
80 | } | |
81 | ||
82 | void AssertMacro(const Text_t* mac) | |
83 | { | |
84 | // Load and execute macro 'mac' if it has not been loaded yet. | |
85 | ||
86 | TString foo(mac); ChompTail(foo); | |
87 | if(gROOT->GetGlobalFunction(foo.Data(), 0, true) == 0) { | |
88 | gROOT->Macro(mac); | |
89 | } | |
90 | } | |
91 | ||
92 | void Macro(const Text_t* mac) | |
93 | { | |
94 | // Execute macro 'mac'. Do not reload the macro. | |
95 | ||
96 | TString foo(mac); ChompTail(foo); | |
97 | if(gROOT->GetGlobalFunction(foo.Data(), 0, true) == 0) | |
98 | gROOT->LoadMacro(mac); | |
99 | ||
100 | foo += "()"; | |
101 | gROOT->ProcessLine(foo.Data()); | |
102 | } | |
103 | ||
104 | void LoadMacro(const Text_t* mac) | |
105 | { | |
106 | // Makes sure that macro 'mac' is loaded, but do not reload it. | |
107 | ||
108 | TString foo(mac); ChompTail(foo); | |
109 | if(gROOT->GetGlobalFunction(foo.Data(), 0, true) == 0) | |
110 | gROOT->LoadMacro(mac); | |
111 | } | |
112 | ||
113 | /**************************************************************************/ | |
114 | /**************************************************************************/ | |
115 | ||
116 | // Pad stack for RINT/GUI thread. | |
117 | std::list<TVirtualPad*> s_Pad_Stack; | |
118 | ||
119 | TVirtualPad* PushPad(TVirtualPad* new_gpad, Int_t subpad) | |
120 | { | |
121 | // printf("Reve::PushPad old=%p, new=%p\n", gPad, new_gpad); | |
122 | s_Pad_Stack.push_back(gPad); | |
123 | if(new_gpad != 0) | |
124 | new_gpad->cd(subpad); | |
125 | else | |
126 | gPad = 0; | |
127 | return gPad; | |
128 | } | |
129 | ||
130 | TVirtualPad* PopPad(Bool_t modify_update_p) | |
131 | { | |
132 | // printf("Reve::PopPad old=%p, new=%p\n", gPad, s_Pad_Stack.empty() ? 0 : s_Pad_Stack.back()); | |
133 | if(s_Pad_Stack.empty()) { | |
134 | Warning("Reve::PopTPad", "stack empty."); | |
135 | } else { | |
136 | if(modify_update_p && gPad != 0) { | |
137 | gPad->Modified(); | |
138 | gPad->Update(); | |
139 | } | |
140 | gPad = s_Pad_Stack.back(); | |
141 | s_Pad_Stack.pop_back(); | |
142 | } | |
143 | return gPad; | |
144 | } | |
145 | ||
146 | /**************************************************************************/ | |
147 | // | |
148 | /**************************************************************************/ | |
149 | ||
150 | GeoManagerHolder::GeoManagerHolder(TGeoManager* new_gmgr) : | |
151 | fManager(gGeoManager) | |
152 | { | |
153 | gGeoManager = new_gmgr; | |
154 | } | |
155 | ||
156 | GeoManagerHolder::~GeoManagerHolder() | |
157 | { | |
158 | gGeoManager = fManager; | |
159 | } | |
160 | ||
161 | ||
162 | } |