Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:41

0001 // @(#)root/eve7:$Id$
0002 // Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT7_REveUtil
0013 #define ROOT7_REveUtil
0014 
0015 #include "REveTypes.hxx"
0016 
0017 #include "TError.h"
0018 
0019 #include <map>
0020 #include <set>
0021 #include <exception>
0022 
0023 class TGeoManager;
0024 
0025 namespace ROOT {
0026 namespace Experimental {
0027 
0028 class REveElement;
0029 
0030 ////////////////////////////////////////////////////////////////////////////////
0031 /// REveUtil
0032 /// Standard utility functions for Reve.
0033 ////////////////////////////////////////////////////////////////////////////////
0034 
0035 class REveUtil
0036 {
0037 private:
0038    static TObjArray *fgDefaultColors;
0039 
0040 public:
0041    virtual ~REveUtil() {}
0042 
0043    // Macro functions
0044 
0045    static Bool_t CheckMacro(const char *mac);
0046    static void AssertMacro(const char *mac);
0047    static void Macro(const char *mac);
0048    static void LoadMacro(const char *mac);
0049 
0050    // Color management
0051 
0052    static void ColorFromIdx(Color_t ci, UChar_t col[4], Bool_t alpha = kTRUE);
0053    static void ColorFromIdx(Color_t ci, UChar_t col[4], Char_t transparency);
0054    static void ColorFromIdx(Float_t f1, Color_t c1, Float_t f2, Color_t c2, UChar_t col[4], Bool_t alpha = kTRUE);
0055    static Color_t *FindColorVar(TObject *obj, const char *varname);
0056 
0057    static void SetColorBrightness(Float_t value, Bool_t full_redraw = kFALSE);
0058 
0059    // Math utilities
0060 
0061    static Bool_t IsU1IntervalContainedByMinMax(Float_t minM, Float_t maxM, Float_t minQ, Float_t maxQ);
0062    static Bool_t IsU1IntervalOverlappingByMinMax(Float_t minM, Float_t maxM, Float_t minQ, Float_t maxQ);
0063 
0064    static Bool_t IsU1IntervalContainedByMeanDelta(Float_t meanM, Float_t deltaM, Float_t meanQ, Float_t deltaQ);
0065    static Bool_t IsU1IntervalOverlappingByMeanDelta(Float_t meanM, Float_t deltaM, Float_t meanQ, Float_t deltaQ);
0066 
0067    static Float_t GetFraction(Float_t minM, Float_t maxM, Float_t minQ, Float_t maxQ);
0068 };
0069 
0070 inline Bool_t REveUtil::IsU1IntervalContainedByMeanDelta(Float_t meanM, Float_t deltaM, Float_t meanQ, Float_t deltaQ)
0071 {
0072    return IsU1IntervalContainedByMinMax(meanM - deltaM, meanM + deltaM, meanQ - deltaQ, meanQ + deltaQ);
0073 }
0074 
0075 inline Bool_t REveUtil::IsU1IntervalOverlappingByMeanDelta(Float_t meanM, Float_t deltaM, Float_t meanQ, Float_t deltaQ)
0076 {
0077    return IsU1IntervalContainedByMinMax(meanM - deltaM, meanM + deltaM, meanQ - deltaQ, meanQ + deltaQ);
0078 }
0079 
0080 
0081 ////////////////////////////////////////////////////////////////////////////////
0082 /// REveGeoManagerHolder
0083 /// Exception-safe global variable holders
0084 ////////////////////////////////////////////////////////////////////////////////
0085 
0086 class REveGeoManagerHolder
0087 {
0088 private:
0089    TGeoManager *fManager{nullptr};  ///<!  hold manager
0090    Int_t fNSegments{0};             ///<!  previous settings for num segments
0091 
0092 public:
0093    REveGeoManagerHolder(TGeoManager *new_gmgr = nullptr, Int_t n_seg = 0);
0094    ~REveGeoManagerHolder();
0095 };
0096 
0097 ////////////////////////////////////////////////////////////////////////////////
0098 /// REveRefCnt
0099 /// REveRefCnt base-class (interface)
0100 ////////////////////////////////////////////////////////////////////////////////
0101 
0102 class REveRefCnt
0103 {
0104    REveRefCnt(const REveRefCnt &) = delete;
0105    REveRefCnt &operator=(const REveRefCnt &) = delete;
0106 
0107 protected:
0108    Int_t fRefCount{0};
0109 
0110 public:
0111    REveRefCnt() = default;
0112    virtual ~REveRefCnt() {}
0113 
0114    void IncRefCount() { ++fRefCount; }
0115    void DecRefCount()
0116    {
0117       if (--fRefCount <= 0)
0118          OnZeroRefCount();
0119    }
0120 
0121    virtual void OnZeroRefCount() = 0;
0122 };
0123 
0124 ////////////////////////////////////////////////////////////////////////////////
0125 /// REveRefBackPtr
0126 /// reference-count with back pointers
0127 ////////////////////////////////////////////////////////////////////////////////
0128 
0129 class REveRefBackPtr : public REveRefCnt
0130 {
0131    REveRefBackPtr(const REveRefBackPtr &) = delete;
0132    REveRefBackPtr &operator=(const REveRefBackPtr &) = delete;
0133 
0134 protected:
0135    typedef std::map<REveElement *, Int_t> RefMap_t;
0136 
0137    RefMap_t fBackRefs;
0138 
0139 public:
0140    REveRefBackPtr() = default;
0141    ~REveRefBackPtr() override;
0142 
0143    using REveRefCnt::DecRefCount;
0144    using REveRefCnt::IncRefCount;
0145    virtual void IncRefCount(REveElement *re);
0146    virtual void DecRefCount(REveElement *re);
0147 
0148    virtual void StampBackPtrElements(UChar_t stamps);
0149 };
0150 
0151 } // namespace Experimental
0152 } // namespace ROOT
0153 
0154 #endif