]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/Reve/Reve.cxx
Dummy methods DefineParticle required by the interface added.
[u/mrichter/AliRoot.git] / EVE / Reve / Reve.cxx
CommitLineData
5a5a1232 1// $Header$
2
3#include "Reve.h"
465af230 4#include "RenderElement.h"
5a5a1232 5
6#include <TError.h>
7#include <TPad.h>
8#include <TGeoManager.h>
0b28fd57 9#include <TClass.h>
51a6ecc6 10
11#include <TStyle.h>
915dabe1 12#include <TColor.h>
5a5a1232 13
14#include <TROOT.h>
5987168b 15#include <TInterpreter.h>
ae2ab848 16#include <TSystem.h>
5a5a1232 17
83f960dc 18#include <TGClient.h>
32e219c2 19#include <TGMimeTypes.h>
83f960dc 20
5ba491d8 21#include <list>
22#include <algorithm>
5a5a1232 23#include <iostream>
24
25//______________________________________________________________________
26// Reve
27//
28
51a6ecc6 29/**************************************************************************/
30/**************************************************************************/
5a5a1232 31namespace Reve {
51a6ecc6 32/**************************************************************************/
33
5a5a1232 34
a8600b56 35// TString .vs. string
36
37bool operator==(const TString& t, const std::string& s)
38{ return (s == t.Data()); }
39
40bool operator==(const std::string& s, const TString& t)
41{ return (s == t.Data()); }
42
43// Exc
44
45Exc_t::Exc_t(const std::string& s) : TString(s.c_str()) {}
46
47// Exc + ops
48
5a5a1232 49Exc_t operator+(const Exc_t &s1, const std::string &s2)
de3de721 50{ Exc_t r(s1); r += s2; return r; }
5a5a1232 51
52Exc_t operator+(const Exc_t &s1, const TString &s2)
de3de721 53{ Exc_t r(s1); r += s2; return r; }
5a5a1232 54
55Exc_t operator+(const Exc_t &s1, const char *s2)
de3de721 56{ Exc_t r(s1); r += s2; return r; }
5a5a1232 57
a8600b56 58// ----------------------------------------------------------------
5a5a1232 59
60void WarnCaller(const TString& warning)
61{
62 std::cout << "WRN: " << warning << std::endl;
63}
64
65/**************************************************************************/
66/**************************************************************************/
67
68void SetupEnvironment()
69{
5987168b 70 // Check if REVESYS exists, try fallback to $ALICE_ROOT/EVE.
71 // Setup Include and Macro paths.
5a5a1232 72
73 static const Exc_t eH("Reve::SetupEnvironment");
a8600b56 74 static Bool_t setupDone = kFALSE;
75
76 if (setupDone) {
77 Info(eH.Data(), "has already been run.");
78 return;
79 }
5a5a1232 80
81 if(gSystem->Getenv("REVESYS") == 0) {
82 if(gSystem->Getenv("ALICE_ROOT") != 0) {
83 Info(eH.Data(), "setting REVESYS from ALICE_ROOT.");
84 gSystem->Setenv("REVESYS", Form("%s/EVE", gSystem->Getenv("ALICE_ROOT")));
85 } else {
86 Error(eH.Data(), "REVESYS not defined, neither is ALICE_ROOT.");
87 gSystem->Exit(1);
88 }
89 }
90 if(gSystem->AccessPathName(gSystem->Getenv("REVESYS")) == kTRUE) {
91 Error(eH.Data(), "REVESYS '%s' does not exist.", gSystem->Getenv("REVESYS"));
92 gSystem->Exit(1);
93 }
5987168b 94
95 TString macPath(gROOT->GetMacroPath());
96 macPath += Form(":%s/macros", gSystem->Getenv("REVESYS"));
97 gInterpreter->AddIncludePath(gSystem->Getenv("REVESYS"));
98 if(gSystem->Getenv("ALICE_ROOT") != 0) {
99 macPath += Form(":%s/alice-macros", gSystem->Getenv("REVESYS"));
100 gInterpreter->AddIncludePath(Form("%s/include", gSystem->Getenv("ALICE_ROOT")));
101 gInterpreter->AddIncludePath(gSystem->Getenv("ALICE_ROOT"));
102 }
103 gROOT->SetMacroPath(macPath);
83f960dc 104}
a8600b56 105
83f960dc 106void SetupGUI()
107{
108 TString fld( Form("%s/icons/", gSystem->Getenv("REVESYS")) );
109 // printf("foofoo %p %p %p %p\n",
110 // RenderElement::fgRnrIcons[0],RenderElement::fgRnrIcons[1],
111 // RenderElement::fgRnrIcons[2],RenderElement::fgRnrIcons[3]);
112 RenderElement::fgRnrIcons[0] = gClient->GetPicture(fld + "rnr00_t.xpm");
113 RenderElement::fgRnrIcons[1] = gClient->GetPicture(fld + "rnr01_t.xpm");
114 RenderElement::fgRnrIcons[2] = gClient->GetPicture(fld + "rnr10_t.xpm");
115 RenderElement::fgRnrIcons[3] = gClient->GetPicture(fld + "rnr11_t.xpm");
32e219c2 116
117 RenderElement::fgListTreeIcons[0] = gClient->GetPicture("folder_t.xpm");
118 RenderElement::fgListTreeIcons[1] = gClient->GetPicture(fld + "viewer.xpm");
119 RenderElement::fgListTreeIcons[2] = gClient->GetPicture(fld + "scene.xpm");
120 RenderElement::fgListTreeIcons[3] = gClient->GetPicture(fld + "pointset.xpm");
121 RenderElement::fgListTreeIcons[4] = gClient->GetPicture(fld + "track.xpm");
122
123 gClient->GetMimeTypeList()->AddType("root/tmacro", "Reve::RMacro",
124 "tmacro_s.xpm", "tmacro_t.xpm", "");
5a5a1232 125}
126
127/**************************************************************************/
128
129namespace {
130 void ChompTail(TString& s, char c='.') {
131 Ssiz_t p = s.Last(c);
132 if(p != kNPOS)
133 s.Remove(p);
134 }
135}
136
f8fae956 137Bool_t CheckMacro(const Text_t* mac)
138{
4fc7595c 139 // Checks if macro 'mac' is loaded.
f8fae956 140
32e219c2 141 // Axel's advice; now sth seems slow, using old method below for test.
142 // return gROOT->GetInterpreter()->IsLoaded(mac);
4fc7595c 143
144 // Previous version expected function with same name and used ROOT's
145 // list of global functions.
32e219c2 146
f8fae956 147 TString foo(mac); ChompTail(foo);
32e219c2 148 /*
4fc7595c 149 if(recreate) {
150 TCollection* logf = gROOT->GetListOfGlobalFunctions(kFALSE);
151 logf->SetOwner();
152 logf->Clear();
153 }
4fc7595c 154 */
32e219c2 155 if (gROOT->GetGlobalFunction(foo.Data(), 0, kFALSE) != 0)
156 return kTRUE;
157 else
158 return (gROOT->GetGlobalFunction(foo.Data(), 0, kTRUE) != 0);
f8fae956 159}
160
5a5a1232 161void AssertMacro(const Text_t* mac)
162{
163 // Load and execute macro 'mac' if it has not been loaded yet.
164
f8fae956 165 if(CheckMacro(mac) == kFALSE) {
5a5a1232 166 gROOT->Macro(mac);
167 }
168}
169
170void Macro(const Text_t* mac)
171{
172 // Execute macro 'mac'. Do not reload the macro.
173
4fc7595c 174 if(CheckMacro(mac) == kFALSE) {
5a5a1232 175 gROOT->LoadMacro(mac);
f8fae956 176 }
4fc7595c 177 TString foo(mac); ChompTail(foo); foo += "()";
5a5a1232 178 gROOT->ProcessLine(foo.Data());
179}
180
181void LoadMacro(const Text_t* mac)
182{
183 // Makes sure that macro 'mac' is loaded, but do not reload it.
184
f8fae956 185 if(CheckMacro(mac) == kFALSE) {
5a5a1232 186 gROOT->LoadMacro(mac);
f8fae956 187 }
5a5a1232 188}
189
190/**************************************************************************/
191/**************************************************************************/
192
193// Pad stack for RINT/GUI thread.
194std::list<TVirtualPad*> s_Pad_Stack;
195
196TVirtualPad* PushPad(TVirtualPad* new_gpad, Int_t subpad)
197{
198 // printf("Reve::PushPad old=%p, new=%p\n", gPad, new_gpad);
199 s_Pad_Stack.push_back(gPad);
200 if(new_gpad != 0)
201 new_gpad->cd(subpad);
202 else
203 gPad = 0;
204 return gPad;
205}
206
207TVirtualPad* PopPad(Bool_t modify_update_p)
208{
209 // printf("Reve::PopPad old=%p, new=%p\n", gPad, s_Pad_Stack.empty() ? 0 : s_Pad_Stack.back());
210 if(s_Pad_Stack.empty()) {
211 Warning("Reve::PopTPad", "stack empty.");
212 } else {
213 if(modify_update_p && gPad != 0) {
214 gPad->Modified();
215 gPad->Update();
216 }
217 gPad = s_Pad_Stack.back();
218 s_Pad_Stack.pop_back();
219 }
220 return gPad;
221}
222
223/**************************************************************************/
465af230 224// GeoManagerHolder
5a5a1232 225/**************************************************************************/
226
227GeoManagerHolder::GeoManagerHolder(TGeoManager* new_gmgr) :
228 fManager(gGeoManager)
229{
230 gGeoManager = new_gmgr;
231}
232
233GeoManagerHolder::~GeoManagerHolder()
234{
235 gGeoManager = fManager;
236}
237
465af230 238
51a6ecc6 239/**************************************************************************/
843e6acd 240// Color management
51a6ecc6 241/**************************************************************************/
242
243void ColorFromIdx(Color_t ci, UChar_t* col, Bool_t alpha)
244{
245 if (ci < 0) {
246 col[0] = col[1] = col[2] = col[3] = 0;
247 return;
248 }
249 TColor* c = gROOT->GetColor(ci);
250 if(c) {
251 col[0] = (UChar_t)(255*c->GetRed());
252 col[1] = (UChar_t)(255*c->GetGreen());
253 col[2] = (UChar_t)(255*c->GetBlue());
254 if (alpha) col[3] = 255;
255 }
256}
5a5a1232 257
51a6ecc6 258void ColorFromIdx(Float_t f1, Color_t c1, Float_t f2, Color_t c2,
259 UChar_t* col, Bool_t alpha)
260{
261 TColor* t1 = gROOT->GetColor(c1);
262 TColor* t2 = gROOT->GetColor(c2);
263 if(t1 && t2) {
264 col[0] = (UChar_t)(255*(f1*t1->GetRed() + f2*t2->GetRed()));
265 col[1] = (UChar_t)(255*(f1*t1->GetGreen() + f2*t2->GetGreen()));
266 col[2] = (UChar_t)(255*(f1*t1->GetBlue() + f2*t2->GetBlue()));
267 if (alpha) col[3] = 255;
268 }
5a5a1232 269}
51a6ecc6 270
271Color_t* FindColorVar(TObject* obj, const Text_t* varname)
272{
273 static const Exc_t eH("Reve::FindColorVar");
274
275 Int_t off = obj->IsA()->GetDataMemberOffset(varname);
276 if(off == 0)
277 throw(eH + "could not find member '" + varname + "' in class " + obj->IsA()->GetName() + ".");
278 return (Color_t*) (((char*)obj) + off);
279}
280
51a6ecc6 281
282/**************************************************************************/
283} // end namespace Reve
284/**************************************************************************/
285/**************************************************************************/
465af230 286
287using namespace Reve;
288
289/**************************************************************************/
290// ReferenceBackPtr
291/**************************************************************************/
292
293ClassImp(ReferenceBackPtr)
294
295ReferenceBackPtr::ReferenceBackPtr() :
296 ReferenceCount(),
297 fBackRefs()
298{}
299
300ReferenceBackPtr::~ReferenceBackPtr()
301{
302 // !!!! Complain if list not empty.
303}
304
305ReferenceBackPtr::ReferenceBackPtr(const ReferenceBackPtr&) :
306 ReferenceCount(),
307 fBackRefs()
308{}
309
310ReferenceBackPtr& ReferenceBackPtr::operator=(const ReferenceBackPtr&)
311{
312 return *this;
313}
314
315/**************************************************************************/
316
317void ReferenceBackPtr::IncRefCount(RenderElement* re)
318{
319 ReferenceCount::IncRefCount();
320 fBackRefs.push_back(re);
321}
322
323void ReferenceBackPtr::DecRefCount(RenderElement* re)
324{
325 static const Exc_t eH("ReferenceBackPtr::DecRefCount ");
326
327 std::list<RenderElement*>::iterator i =
328 std::find(fBackRefs.begin(), fBackRefs.end(), re);
329 if (i != fBackRefs.end()) {
330 fBackRefs.erase(i);
331 ReferenceCount::DecRefCount();
332 } else {
333 Warning(eH, Form("render element '%s' not found in back-refs.",
334 re->GetObject()->GetName()));
335 }
336}
337
338/**************************************************************************/
339
340void ReferenceBackPtr::UpdateBackPtrItems()
341{
342 std::list<RenderElement*>::iterator i = fBackRefs.begin();
343 while (i != fBackRefs.end())
344 {
345 (*i)->UpdateItems();
346 ++i;
347 }
348}