Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TEveUtil.h
Go to the documentation of this file.
1 // @(#)root/eve:$Id$
2 // Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TEveUtil
13 #define ROOT_TEveUtil
14 
15 #include "TObject.h"
16 #include "TString.h"
17 #include "TError.h"
18 
19 #include "GuiTypes.h"
20 
21 #include <list>
22 #include <map>
23 #include <set>
24 #include <exception>
25 
26 class TVirtualPad;
27 class TGeoManager;
28 
29 class TEveElement;
30 
31 /******************************************************************************/
32 // TEveUtil
33 /******************************************************************************/
34 
35 class TEveUtil
36 {
37 private:
38  static TObjArray* fgDefaultColors;
39 
40 public:
41  virtual ~TEveUtil() {}
42 
43  // Environment, Macro functions
44 
45  static void SetupEnvironment();
46  static void SetupGUI();
47 
48  static Bool_t CheckMacro(const char* mac);
49  static void AssertMacro(const char* mac);
50  static void Macro(const char* mac);
51  static void LoadMacro(const char* mac);
52 
53  // Color management
54 
55  static void ColorFromIdx(Color_t ci, UChar_t col[4], Bool_t alpha=kTRUE);
56  static void ColorFromIdx(Color_t ci, UChar_t col[4], Char_t transparency);
57  static void ColorFromIdx(Float_t f1, Color_t c1, Float_t f2, Color_t c2,
58  UChar_t col[4], Bool_t alpha=kTRUE);
59  static Color_t* FindColorVar(TObject* obj, const char* varname);
60 
61  static void SetColorBrightness(Float_t value, Bool_t full_redraw=kFALSE);
62 
63 
64  // Math utilities
65 
66  static Bool_t IsU1IntervalContainedByMinMax (Float_t minM, Float_t maxM,
67  Float_t minQ, Float_t maxQ);
68  static Bool_t IsU1IntervalOverlappingByMinMax(Float_t minM, Float_t maxM,
69  Float_t minQ, Float_t maxQ);
70 
71  static Bool_t IsU1IntervalContainedByMeanDelta (Float_t meanM, Float_t deltaM,
72  Float_t meanQ, Float_t deltaQ);
73  static Bool_t IsU1IntervalOverlappingByMeanDelta(Float_t meanM, Float_t deltaM,
74  Float_t meanQ, Float_t deltaQ);
75 
76  static Float_t GetFraction(Float_t minM, Float_t maxM, Float_t minQ, Float_t maxQ);
77 
78 
79  ClassDef(TEveUtil, 0); // Standard utility functions for Reve.
80 };
81 
82 inline Bool_t TEveUtil::IsU1IntervalContainedByMeanDelta(Float_t meanM, Float_t deltaM,
83  Float_t meanQ, Float_t deltaQ)
84 {
85  return IsU1IntervalContainedByMinMax(meanM - deltaM, meanM + deltaM, meanQ - deltaQ, meanQ + deltaQ);
86 }
87 
88 inline Bool_t TEveUtil::IsU1IntervalOverlappingByMeanDelta(Float_t meanM, Float_t deltaM,
89  Float_t meanQ, Float_t deltaQ)
90 {
91  return IsU1IntervalContainedByMinMax(meanM - deltaM, meanM + deltaM, meanQ - deltaQ, meanQ + deltaQ);
92 }
93 
94 
95 /******************************************************************************/
96 // Exceptions, string functions
97 /******************************************************************************/
98 
99 bool operator==(const TString& t, const std::string& s);
100 bool operator==(const std::string& s, const TString& t);
101 
102 class TEveException : public std::exception, public TString
103 {
104 public:
105  TEveException() {}
106  TEveException(const TString& s) : TString(s) {}
107  TEveException(const char* s) : TString(s) {}
108  TEveException(const std::string& s);
109 
110  virtual ~TEveException() noexcept {}
111 
112  virtual const char* what() const noexcept { return Data(); }
113 
114  ClassDef(TEveException, 1); // Exception-type thrown by Eve classes.
115 };
116 
117 TEveException operator+(const TEveException &s1, const std::string &s2);
118 TEveException operator+(const TEveException &s1, const TString &s2);
119 TEveException operator+(const TEveException &s1, const char *s2);
120 
121 
122 /******************************************************************************/
123 // Exception-safe global variable holders
124 /******************************************************************************/
125 
126 class TEvePadHolder
127 {
128 private:
129  TVirtualPad *fOldPad;
130  Bool_t fModifyUpdateP;
131 
132  TEvePadHolder(const TEvePadHolder&); // Not implemented
133  TEvePadHolder& operator=(const TEvePadHolder&); // Not implemented
134 
135 public:
136  TEvePadHolder(Bool_t modify_update_p, TVirtualPad* new_pad=0, Int_t subpad=0);
137  virtual ~TEvePadHolder();
138 
139  ClassDef(TEvePadHolder, 0); // Exception-safe wrapper for temporary setting of gPad variable.
140 };
141 
142 class TEveGeoManagerHolder
143 {
144 private:
145  TGeoManager *fManager;
146  Int_t fNSegments;
147 
148  TEveGeoManagerHolder(const TEveGeoManagerHolder&); // Not implemented
149  TEveGeoManagerHolder& operator=(const TEveGeoManagerHolder&); // Not implemented
150 
151 public:
152  TEveGeoManagerHolder(TGeoManager* new_gmgr=0, Int_t n_seg=0);
153  virtual ~TEveGeoManagerHolder();
154 
155  ClassDef(TEveGeoManagerHolder, 0); // Exception-safe wrapper for temporary setting of gGeoManager variable.
156 };
157 
158 
159 /******************************************************************************/
160 // TEveRefCnt base-class (interface)
161 /******************************************************************************/
162 
163 class TEveRefCnt
164 {
165 protected:
166  Int_t fRefCount;
167 
168 public:
169  TEveRefCnt() : fRefCount(0) {}
170  virtual ~TEveRefCnt() {}
171 
172  TEveRefCnt(const TEveRefCnt&) : fRefCount(0) {}
173  TEveRefCnt& operator=(const TEveRefCnt&) { return *this; }
174 
175  void IncRefCount() { ++fRefCount; }
176  void DecRefCount() { if(--fRefCount <= 0) OnZeroRefCount(); }
177 
178  virtual void OnZeroRefCount() { delete this; }
179 
180  ClassDef(TEveRefCnt, 0); // Base-class for reference-counted objects.
181 };
182 
183 /******************************************************************************/
184 // TEveRefBackPtr reference-count with back pointers
185 /******************************************************************************/
186 
187 class TEveRefBackPtr : public TEveRefCnt
188 {
189 protected:
190  typedef std::map<TEveElement*, Int_t> RefMap_t;
191  typedef RefMap_t::iterator RefMap_i;
192 
193  RefMap_t fBackRefs;
194 
195 public:
196  TEveRefBackPtr();
197  virtual ~TEveRefBackPtr();
198 
199  TEveRefBackPtr(const TEveRefBackPtr&);
200  TEveRefBackPtr& operator=(const TEveRefBackPtr&);
201 
202  using TEveRefCnt::IncRefCount;
203  using TEveRefCnt::DecRefCount;
204  virtual void IncRefCount(TEveElement* re);
205  virtual void DecRefCount(TEveElement* re);
206 
207  virtual void StampBackPtrElements(UChar_t stamps);
208 
209  ClassDef(TEveRefBackPtr, 0); // Base-class for reference-counted objects with reverse references to TEveElement objects.
210 };
211 
212 #endif