Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:11:43

0001 // @(#)root/eve:$Id$
0002 // Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2007, 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 ROOT_TEveUtil
0013 #define ROOT_TEveUtil
0014 
0015 #include "TObject.h"
0016 #include "TString.h"
0017 #include "TError.h"
0018 
0019 #include "GuiTypes.h"
0020 
0021 #include <map>
0022 #include <string>
0023 #include <exception>
0024 
0025 class TVirtualPad;
0026 class TGeoManager;
0027 
0028 class TEveElement;
0029 
0030 /******************************************************************************/
0031 // TEveUtil
0032 /******************************************************************************/
0033 
0034 class TEveUtil
0035 {
0036 private:
0037    static TObjArray* fgDefaultColors;
0038 
0039 public:
0040    virtual ~TEveUtil() {}
0041 
0042    // Environment, Macro functions
0043 
0044    static void   SetupEnvironment();
0045    static void   SetupGUI();
0046 
0047    static Bool_t CheckMacro(const char* mac);
0048    static void   AssertMacro(const char* mac);
0049    static void   Macro(const char* mac);
0050    static void   LoadMacro(const char* mac);
0051 
0052    // Color management
0053 
0054    static void     ColorFromIdx(Color_t ci, UChar_t col[4], Bool_t alpha=kTRUE);
0055    static void     ColorFromIdx(Color_t ci, UChar_t col[4], Char_t transparency);
0056    static void     ColorFromIdx(Float_t f1, Color_t c1, Float_t f2, Color_t c2,
0057                                 UChar_t col[4], Bool_t alpha=kTRUE);
0058    static Color_t* FindColorVar(TObject* obj, const char* varname);
0059 
0060    static void     SetColorBrightness(Float_t value, Bool_t full_redraw=kFALSE);
0061 
0062 
0063    // Math utilities
0064 
0065    static Bool_t IsU1IntervalContainedByMinMax  (Float_t minM, Float_t maxM,
0066                                                  Float_t minQ, Float_t maxQ);
0067    static Bool_t IsU1IntervalOverlappingByMinMax(Float_t minM, Float_t maxM,
0068                                                  Float_t minQ, Float_t maxQ);
0069 
0070    static Bool_t IsU1IntervalContainedByMeanDelta  (Float_t meanM, Float_t deltaM,
0071                                                     Float_t meanQ, Float_t deltaQ);
0072    static Bool_t IsU1IntervalOverlappingByMeanDelta(Float_t meanM, Float_t deltaM,
0073                                                     Float_t meanQ, Float_t deltaQ);
0074 
0075    static Float_t GetFraction(Float_t minM, Float_t maxM, Float_t minQ, Float_t maxQ);
0076 
0077 
0078    ClassDef(TEveUtil, 0); // Standard utility functions for Reve.
0079 };
0080 
0081 inline Bool_t TEveUtil::IsU1IntervalContainedByMeanDelta(Float_t meanM, Float_t deltaM,
0082                                                          Float_t meanQ, Float_t deltaQ)
0083 {
0084    return IsU1IntervalContainedByMinMax(meanM - deltaM, meanM + deltaM, meanQ - deltaQ, meanQ + deltaQ);
0085 }
0086 
0087 inline Bool_t TEveUtil::IsU1IntervalOverlappingByMeanDelta(Float_t meanM, Float_t deltaM,
0088                                                              Float_t meanQ, Float_t deltaQ)
0089 {
0090    return IsU1IntervalContainedByMinMax(meanM - deltaM, meanM + deltaM, meanQ - deltaQ, meanQ + deltaQ);
0091 }
0092 
0093 
0094 /******************************************************************************/
0095 // Exceptions, string functions
0096 /******************************************************************************/
0097 
0098 bool operator==(const TString& t, const std::string& s);
0099 bool operator==(const std::string& s, const TString& t);
0100 
0101 class TEveException : public std::exception, public TString
0102 {
0103 public:
0104    TEveException() {}
0105    TEveException(const TString& s) : TString(s) {}
0106    TEveException(const char* s)    : TString(s) {}
0107    TEveException(const std::string& s);
0108 
0109    ~TEveException() noexcept override {}
0110 
0111    const char* what() const noexcept override { return Data(); }
0112 
0113    ClassDefOverride(TEveException, 1); // Exception-type thrown by Eve classes.
0114 };
0115 
0116 TEveException operator+(const TEveException &s1, const std::string  &s2);
0117 TEveException operator+(const TEveException &s1, const TString &s2);
0118 TEveException operator+(const TEveException &s1, const char    *s2);
0119 
0120 
0121 /******************************************************************************/
0122 // Exception-safe global variable holders
0123 /******************************************************************************/
0124 
0125 class TEvePadHolder
0126 {
0127 private:
0128    TVirtualPad *fOldPad;
0129    Bool_t       fModifyUpdateP;
0130 
0131    TEvePadHolder(const TEvePadHolder&);            // Not implemented
0132    TEvePadHolder& operator=(const TEvePadHolder&); // Not implemented
0133 
0134 public:
0135    TEvePadHolder(Bool_t modify_update_p, TVirtualPad* new_pad=nullptr, Int_t subpad=0);
0136    virtual ~TEvePadHolder();
0137 
0138    ClassDef(TEvePadHolder, 0); // Exception-safe wrapper for temporary setting of gPad variable.
0139 };
0140 
0141 class TEveGeoManagerHolder
0142 {
0143 private:
0144    TGeoManager *fManager;
0145    Int_t        fNSegments;
0146 
0147    TEveGeoManagerHolder(const TEveGeoManagerHolder&);            // Not implemented
0148    TEveGeoManagerHolder& operator=(const TEveGeoManagerHolder&); // Not implemented
0149 
0150 public:
0151    TEveGeoManagerHolder(TGeoManager* new_gmgr=nullptr, Int_t n_seg=0);
0152    virtual ~TEveGeoManagerHolder();
0153 
0154    ClassDef(TEveGeoManagerHolder, 0); // Exception-safe wrapper for temporary setting of gGeoManager variable.
0155 };
0156 
0157 
0158 /******************************************************************************/
0159 // TEveRefCnt base-class (interface)
0160 /******************************************************************************/
0161 
0162 class TEveRefCnt
0163 {
0164 protected:
0165    Int_t fRefCount;
0166 
0167 public:
0168    TEveRefCnt() : fRefCount(0) {}
0169    virtual ~TEveRefCnt() {}
0170 
0171    TEveRefCnt(const TEveRefCnt&) : fRefCount(0) {}
0172    TEveRefCnt& operator=(const TEveRefCnt&) { return *this; }
0173 
0174    void IncRefCount() { ++fRefCount; }
0175    void DecRefCount() { if(--fRefCount <= 0) OnZeroRefCount(); }
0176 
0177    virtual void OnZeroRefCount() { delete this; }
0178 
0179    ClassDef(TEveRefCnt, 0); // Base-class for reference-counted objects.
0180 };
0181 
0182 /******************************************************************************/
0183 // TEveRefBackPtr reference-count with back pointers
0184 /******************************************************************************/
0185 
0186 class TEveRefBackPtr : public TEveRefCnt
0187 {
0188 protected:
0189    typedef std::map<TEveElement*, Int_t> RefMap_t;
0190    typedef RefMap_t::iterator            RefMap_i;
0191 
0192    RefMap_t fBackRefs;
0193 
0194 public:
0195    TEveRefBackPtr();
0196    ~TEveRefBackPtr() override;
0197 
0198    TEveRefBackPtr(const TEveRefBackPtr&);
0199    TEveRefBackPtr& operator=(const TEveRefBackPtr&);
0200 
0201    using TEveRefCnt::IncRefCount;
0202    using TEveRefCnt::DecRefCount;
0203    virtual void IncRefCount(TEveElement* re);
0204    virtual void DecRefCount(TEveElement* re);
0205 
0206    virtual void StampBackPtrElements(UChar_t stamps);
0207 
0208    ClassDefOverride(TEveRefBackPtr, 0); // Base-class for reference-counted objects with reverse references to TEveElement objects.
0209 };
0210 
0211 #endif