Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
REveUtil.hxx
Go to the documentation of this file.
1 // @(#)root/eve7:$Id$
2 // Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2019, 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 ROOT7_REveUtil
13 #define ROOT7_REveUtil
14 
15 #include "REveTypes.hxx"
16 
17 #include "TError.h"
18 
19 #include <list>
20 #include <map>
21 #include <set>
22 #include <exception>
23 
24 class TGeoManager;
25 
26 namespace ROOT {
27 namespace Experimental {
28 
29 class REveElement;
30 
31 ////////////////////////////////////////////////////////////////////////////////
32 /// REveUtil
33 /// Standard utility functions for Reve.
34 ////////////////////////////////////////////////////////////////////////////////
35 
36 class REveUtil
37 {
38 private:
39  static TObjArray *fgDefaultColors;
40 
41 public:
42  virtual ~REveUtil() {}
43 
44  // Macro functions
45 
46  static Bool_t CheckMacro(const char *mac);
47  static void AssertMacro(const char *mac);
48  static void Macro(const char *mac);
49  static void LoadMacro(const char *mac);
50 
51  // Color management
52 
53  static void ColorFromIdx(Color_t ci, UChar_t col[4], Bool_t alpha = kTRUE);
54  static void ColorFromIdx(Color_t ci, UChar_t col[4], Char_t transparency);
55  static void ColorFromIdx(Float_t f1, Color_t c1, Float_t f2, Color_t c2, UChar_t col[4], Bool_t alpha = kTRUE);
56  static Color_t *FindColorVar(TObject *obj, const char *varname);
57 
58  static void SetColorBrightness(Float_t value, Bool_t full_redraw = kFALSE);
59 
60  // Math utilities
61 
62  static Bool_t IsU1IntervalContainedByMinMax(Float_t minM, Float_t maxM, Float_t minQ, Float_t maxQ);
63  static Bool_t IsU1IntervalOverlappingByMinMax(Float_t minM, Float_t maxM, Float_t minQ, Float_t maxQ);
64 
65  static Bool_t IsU1IntervalContainedByMeanDelta(Float_t meanM, Float_t deltaM, Float_t meanQ, Float_t deltaQ);
66  static Bool_t IsU1IntervalOverlappingByMeanDelta(Float_t meanM, Float_t deltaM, Float_t meanQ, Float_t deltaQ);
67 
68  static Float_t GetFraction(Float_t minM, Float_t maxM, Float_t minQ, Float_t maxQ);
69 };
70 
71 inline Bool_t REveUtil::IsU1IntervalContainedByMeanDelta(Float_t meanM, Float_t deltaM, Float_t meanQ, Float_t deltaQ)
72 {
73  return IsU1IntervalContainedByMinMax(meanM - deltaM, meanM + deltaM, meanQ - deltaQ, meanQ + deltaQ);
74 }
75 
76 inline Bool_t REveUtil::IsU1IntervalOverlappingByMeanDelta(Float_t meanM, Float_t deltaM, Float_t meanQ, Float_t deltaQ)
77 {
78  return IsU1IntervalContainedByMinMax(meanM - deltaM, meanM + deltaM, meanQ - deltaQ, meanQ + deltaQ);
79 }
80 
81 
82 ////////////////////////////////////////////////////////////////////////////////
83 /// REveGeoManagerHolder
84 /// Exception-safe global variable holders
85 ////////////////////////////////////////////////////////////////////////////////
86 
87 class REveGeoManagerHolder
88 {
89 private:
90  TGeoManager *fManager{nullptr}; ///<! hold manager
91  Int_t fNSegments{0}; ///<! previous settings for num segments
92 
93 public:
94  REveGeoManagerHolder(TGeoManager *new_gmgr = nullptr, Int_t n_seg = 0);
95  ~REveGeoManagerHolder();
96 };
97 
98 ////////////////////////////////////////////////////////////////////////////////
99 /// REveRefCnt
100 /// REveRefCnt base-class (interface)
101 ////////////////////////////////////////////////////////////////////////////////
102 
103 class REveRefCnt
104 {
105 protected:
106  Int_t fRefCount{0};
107 
108 public:
109  REveRefCnt() = default;
110  virtual ~REveRefCnt() {}
111 
112  REveRefCnt(const REveRefCnt &) : fRefCount(0) {}
113  REveRefCnt &operator=(const REveRefCnt &) { return *this; }
114 
115  void IncRefCount() { ++fRefCount; }
116  void DecRefCount()
117  {
118  if (--fRefCount <= 0)
119  OnZeroRefCount();
120  }
121 
122  virtual void OnZeroRefCount() { delete this; }
123 };
124 
125 ////////////////////////////////////////////////////////////////////////////////
126 /// REveRefBackPtr
127 /// reference-count with back pointers
128 ////////////////////////////////////////////////////////////////////////////////
129 
130 class REveRefBackPtr : public REveRefCnt
131 {
132 protected:
133  typedef std::map<REveElement *, Int_t> RefMap_t;
134 
135  RefMap_t fBackRefs;
136 
137 public:
138  REveRefBackPtr();
139  virtual ~REveRefBackPtr();
140 
141  REveRefBackPtr(const REveRefBackPtr &);
142  REveRefBackPtr &operator=(const REveRefBackPtr &);
143 
144  using REveRefCnt::DecRefCount;
145  using REveRefCnt::IncRefCount;
146  virtual void IncRefCount(REveElement *re);
147  virtual void DecRefCount(REveElement *re);
148 
149  virtual void StampBackPtrElements(UChar_t stamps);
150 };
151 
152 } // namespace Experimental
153 } // namespace ROOT
154 
155 #endif