Logo ROOT  
Reference Guide
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 <map>
22 #include <string>
23 #include <exception>
24 
25 class TVirtualPad;
26 class TGeoManager;
27 
28 class TEveElement;
29 
30 /******************************************************************************/
31 // TEveUtil
32 /******************************************************************************/
33 
34 class TEveUtil
35 {
36 private:
38 
39 public:
40  virtual ~TEveUtil() {}
41 
42  // Environment, Macro functions
43 
44  static void SetupEnvironment();
45  static void SetupGUI();
46 
47  static Bool_t CheckMacro(const char* mac);
48  static void AssertMacro(const char* mac);
49  static void Macro(const char* mac);
50  static void LoadMacro(const char* mac);
51 
52  // Color management
53 
54  static void ColorFromIdx(Color_t ci, UChar_t col[4], Bool_t alpha=kTRUE);
55  static void ColorFromIdx(Color_t ci, UChar_t col[4], Char_t transparency);
56  static void ColorFromIdx(Float_t f1, Color_t c1, Float_t f2, Color_t c2,
57  UChar_t col[4], Bool_t alpha=kTRUE);
58  static Color_t* FindColorVar(TObject* obj, const char* varname);
59 
60  static void SetColorBrightness(Float_t value, Bool_t full_redraw=kFALSE);
61 
62 
63  // Math utilities
64 
66  Float_t minQ, Float_t maxQ);
68  Float_t minQ, Float_t maxQ);
69 
71  Float_t meanQ, Float_t deltaQ);
73  Float_t meanQ, Float_t deltaQ);
74 
75  static Float_t GetFraction(Float_t minM, Float_t maxM, Float_t minQ, Float_t maxQ);
76 
77 
78  ClassDef(TEveUtil, 0); // Standard utility functions for Reve.
79 };
80 
82  Float_t meanQ, Float_t deltaQ)
83 {
84  return IsU1IntervalContainedByMinMax(meanM - deltaM, meanM + deltaM, meanQ - deltaQ, meanQ + deltaQ);
85 }
86 
88  Float_t meanQ, Float_t deltaQ)
89 {
90  return IsU1IntervalContainedByMinMax(meanM - deltaM, meanM + deltaM, meanQ - deltaQ, meanQ + deltaQ);
91 }
92 
93 
94 /******************************************************************************/
95 // Exceptions, string functions
96 /******************************************************************************/
97 
98 bool operator==(const TString& t, const std::string& s);
99 bool operator==(const std::string& s, const TString& t);
100 
101 class TEveException : public std::exception, public TString
102 {
103 public:
106  TEveException(const char* s) : TString(s) {}
107  TEveException(const std::string& s);
108 
109  virtual ~TEveException() noexcept {}
110 
111  virtual const char* what() const noexcept { return Data(); }
112 
113  ClassDef(TEveException, 1); // Exception-type thrown by Eve classes.
114 };
115 
116 TEveException operator+(const TEveException &s1, const std::string &s2);
117 TEveException operator+(const TEveException &s1, const TString &s2);
118 TEveException operator+(const TEveException &s1, const char *s2);
119 
120 
121 /******************************************************************************/
122 // Exception-safe global variable holders
123 /******************************************************************************/
124 
126 {
127 private:
130 
131  TEvePadHolder(const TEvePadHolder&); // Not implemented
132  TEvePadHolder& operator=(const TEvePadHolder&); // Not implemented
133 
134 public:
135  TEvePadHolder(Bool_t modify_update_p, TVirtualPad* new_pad=0, Int_t subpad=0);
136  virtual ~TEvePadHolder();
137 
138  ClassDef(TEvePadHolder, 0); // Exception-safe wrapper for temporary setting of gPad variable.
139 };
140 
142 {
143 private:
146 
147  TEveGeoManagerHolder(const TEveGeoManagerHolder&); // Not implemented
148  TEveGeoManagerHolder& operator=(const TEveGeoManagerHolder&); // Not implemented
149 
150 public:
151  TEveGeoManagerHolder(TGeoManager* new_gmgr=0, Int_t n_seg=0);
152  virtual ~TEveGeoManagerHolder();
153 
154  ClassDef(TEveGeoManagerHolder, 0); // Exception-safe wrapper for temporary setting of gGeoManager variable.
155 };
156 
157 
158 /******************************************************************************/
159 // TEveRefCnt base-class (interface)
160 /******************************************************************************/
161 
163 {
164 protected:
166 
167 public:
169  virtual ~TEveRefCnt() {}
170 
172  TEveRefCnt& operator=(const TEveRefCnt&) { return *this; }
173 
174  void IncRefCount() { ++fRefCount; }
175  void DecRefCount() { if(--fRefCount <= 0) OnZeroRefCount(); }
176 
177  virtual void OnZeroRefCount() { delete this; }
178 
179  ClassDef(TEveRefCnt, 0); // Base-class for reference-counted objects.
180 };
181 
182 /******************************************************************************/
183 // TEveRefBackPtr reference-count with back pointers
184 /******************************************************************************/
185 
187 {
188 protected:
189  typedef std::map<TEveElement*, Int_t> RefMap_t;
190  typedef RefMap_t::iterator RefMap_i;
191 
193 
194 public:
195  TEveRefBackPtr();
196  virtual ~TEveRefBackPtr();
197 
200 
203  virtual void IncRefCount(TEveElement* re);
204  virtual void DecRefCount(TEveElement* re);
205 
206  virtual void StampBackPtrElements(UChar_t stamps);
207 
208  ClassDef(TEveRefBackPtr, 0); // Base-class for reference-counted objects with reverse references to TEveElement objects.
209 };
210 
211 #endif
TEveRefCnt::operator=
TEveRefCnt & operator=(const TEveRefCnt &)
Definition: TEveUtil.h:172
TEveGeoManagerHolder
Definition: TEveUtil.h:141
TEveUtil::SetupEnvironment
static void SetupEnvironment()
Setup Include and Macro paths.
Definition: TEveUtil.cxx:50
TEveElement
Definition: TEveElement.h:35
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TEveUtil::SetColorBrightness
static void SetColorBrightness(Float_t value, Bool_t full_redraw=kFALSE)
Tweak all ROOT colors to become brighter (if value > 0) or darker (value < 0).
Definition: TEveUtil.cxx:276
TObjArray
Definition: TObjArray.h:37
operator+
TEveException operator+(const TEveException &s1, const std::string &s2)
Definition: TEveUtil.cxx:424
TEveRefBackPtr::TEveRefBackPtr
TEveRefBackPtr()
Default constructor.
Definition: TEveUtil.cxx:540
TString::Data
const char * Data() const
Definition: TString.h:369
TEveUtil::GetFraction
static Float_t GetFraction(Float_t minM, Float_t maxM, Float_t minQ, Float_t maxQ)
Get fraction of interval [minQ, maxQ] in [minM, maxM].
Definition: TEveUtil.cxx:382
TEveUtil::IsU1IntervalOverlappingByMinMax
static Bool_t IsU1IntervalOverlappingByMinMax(Float_t minM, Float_t maxM, Float_t minQ, Float_t maxQ)
Return true if interval Q is overlapping within interval M for U1 variables.
Definition: TEveUtil.cxx:363
TEveRefCnt::DecRefCount
void DecRefCount()
Definition: TEveUtil.h:175
TEveException::what
virtual const char * what() const noexcept
Definition: TEveUtil.h:111
TEveUtil::ColorFromIdx
static void ColorFromIdx(Color_t ci, UChar_t col[4], Bool_t alpha=kTRUE)
Fill col with RGBA values corresponding to index ci.
Definition: TEveUtil.cxx:188
TEvePadHolder::~TEvePadHolder
virtual ~TEvePadHolder()
Destructor.
Definition: TEveUtil.cxx:458
TEveRefCnt::fRefCount
Int_t fRefCount
Definition: TEveUtil.h:165
Float_t
float Float_t
Definition: RtypesCore.h:57
TGeant4Unit::s
static constexpr double s
Definition: TGeant4SystemOfUnits.h:168
TEveRefBackPtr::StampBackPtrElements
virtual void StampBackPtrElements(UChar_t stamps)
Add given stamps to elements in the list of reverse references.
Definition: TEveUtil.cxx:604
TEveException::TEveException
TEveException()
Definition: TEveUtil.h:104
TEveGeoManagerHolder::operator=
TEveGeoManagerHolder & operator=(const TEveGeoManagerHolder &)
TEveUtil::IsU1IntervalContainedByMinMax
static Bool_t IsU1IntervalContainedByMinMax(Float_t minM, Float_t maxM, Float_t minQ, Float_t maxQ)
Return true if interval Q is contained within interval M for U1 variables.
Definition: TEveUtil.cxx:342
TEveUtil::Macro
static void Macro(const char *mac)
Execute macro 'mac'. Do not reload the macro.
Definition: TEveUtil.cxx:164
TEveGeoManagerHolder::fManager
TGeoManager * fManager
Definition: TEveUtil.h:144
TString
Definition: TString.h:136
TEvePadHolder::fModifyUpdateP
Bool_t fModifyUpdateP
Definition: TEveUtil.h:129
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
Color_t
short Color_t
Definition: RtypesCore.h:83
TString.h
TEveRefCnt::~TEveRefCnt
virtual ~TEveRefCnt()
Definition: TEveUtil.h:169
TEveRefBackPtr::~TEveRefBackPtr
virtual ~TEveRefBackPtr()
Destructor. Noop, should complain if back-ref list is not empty.
Definition: TEveUtil.cxx:549
operator==
bool operator==(const TString &t, const std::string &s)
Definition: TEveUtil.cxx:409
bool
TEveRefCnt::OnZeroRefCount
virtual void OnZeroRefCount()
Definition: TEveUtil.h:177
TEveException::TEveException
TEveException(const TString &s)
Definition: TEveUtil.h:105
TEveGeoManagerHolder::~TEveGeoManagerHolder
virtual ~TEveGeoManagerHolder()
Destructor.
Definition: TEveUtil.cxx:504
TEveUtil::CheckMacro
static Bool_t CheckMacro(const char *mac)
Checks if macro 'mac' is loaded.
Definition: TEveUtil.cxx:136
TEveUtil::SetupGUI
static void SetupGUI()
Setup icon pictures and mime-types.
Definition: TEveUtil.cxx:93
TEveGeoManagerHolder::TEveGeoManagerHolder
TEveGeoManagerHolder(const TEveGeoManagerHolder &)
TEveUtil::FindColorVar
static Color_t * FindColorVar(TObject *obj, const char *varname)
Find address of Color_t data-member with name varname in object obj.
Definition: TEveUtil.cxx:257
TEveUtil::fgDefaultColors
static TObjArray * fgDefaultColors
Definition: TEveUtil.h:37
TEveUtil
Definition: TEveUtil.h:34
GuiTypes.h
TEveUtil::LoadMacro
static void LoadMacro(const char *mac)
Makes sure that macro 'mac' is loaded, but do not reload it.
Definition: TEveUtil.cxx:176
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
s1
#define s1(x)
Definition: RSha256.hxx:109
TEveRefBackPtr
Definition: TEveUtil.h:186
TEveRefBackPtr::RefMap_i
RefMap_t::iterator RefMap_i
Definition: TEveUtil.h:190
TEveRefCnt::TEveRefCnt
TEveRefCnt(const TEveRefCnt &)
Definition: TEveUtil.h:171
TEvePadHolder::fOldPad
TVirtualPad * fOldPad
Definition: TEveUtil.h:128
TEveRefCnt::TEveRefCnt
TEveRefCnt()
Definition: TEveUtil.h:168
TEveGeoManagerHolder::fNSegments
Int_t fNSegments
Definition: TEveUtil.h:145
TEveException::TEveException
TEveException(const char *s)
Definition: TEveUtil.h:106
TEvePadHolder
Definition: TEveUtil.h:125
TEveException::~TEveException
virtual ~TEveException() noexcept
Definition: TEveUtil.h:109
TEveUtil::~TEveUtil
virtual ~TEveUtil()
Definition: TEveUtil.h:40
TEvePadHolder::TEvePadHolder
TEvePadHolder(const TEvePadHolder &)
TEveUtil::AssertMacro
static void AssertMacro(const char *mac)
Load and execute macro 'mac' if it has not been loaded yet.
Definition: TEveUtil.cxx:154
TEveRefCnt
Definition: TEveUtil.h:162
TEveRefBackPtr::operator=
TEveRefBackPtr & operator=(const TEveRefBackPtr &)
Assignment operator.
Definition: TEveUtil.cxx:569
f1
TF1 * f1
Definition: legend1.C:11
TVirtualPad
Definition: TVirtualPad.h:50
TObject.h
TEveException
Definition: TEveUtil.h:101
TEveUtil::IsU1IntervalContainedByMeanDelta
static Bool_t IsU1IntervalContainedByMeanDelta(Float_t meanM, Float_t deltaM, Float_t meanQ, Float_t deltaQ)
Definition: TEveUtil.h:81
UChar_t
unsigned char UChar_t
Definition: RtypesCore.h:38
TObject
Definition: TObject.h:37
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TEveUtil::IsU1IntervalOverlappingByMeanDelta
static Bool_t IsU1IntervalOverlappingByMeanDelta(Float_t meanM, Float_t deltaM, Float_t meanQ, Float_t deltaQ)
Definition: TEveUtil.h:87
c2
return c2
Definition: legend2.C:14
TEveRefBackPtr::RefMap_t
std::map< TEveElement *, Int_t > RefMap_t
Definition: TEveUtil.h:189
TEveRefBackPtr::fBackRefs
RefMap_t fBackRefs
Definition: TEveUtil.h:192
TEvePadHolder::operator=
TEvePadHolder & operator=(const TEvePadHolder &)
Char_t
char Char_t
Definition: RtypesCore.h:33
TGeoManager
Definition: TGeoManager.h:44
TEveRefCnt::IncRefCount
void IncRefCount()
Definition: TEveUtil.h:174
int
TError.h
c1
return c1
Definition: legend1.C:41