TEveUtil.h

Go to the documentation of this file.
00001 // @(#)root/eve:$Id: TEveUtil.h 36373 2010-10-19 17:43:35Z matevz $
00002 // Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_TEveUtil
00013 #define ROOT_TEveUtil
00014 
00015 #include "TObject.h"
00016 #include "TString.h"
00017 #include "TError.h"
00018 
00019 #include "GuiTypes.h"
00020 
00021 #include <list>
00022 #include <map>
00023 #include <set>
00024 #include <exception>
00025 
00026 class TVirtualPad;
00027 class TGeoManager;
00028 
00029 class TEveElement;
00030 
00031 /******************************************************************************/
00032 // TEveUtil
00033 /******************************************************************************/
00034 
00035 class TEveUtil
00036 {
00037 private:
00038    static TObjArray* fgDefaultColors;
00039 
00040 public:
00041    virtual ~TEveUtil() {}
00042 
00043    // Environment, Macro functions
00044 
00045    static void   SetupEnvironment();
00046    static void   SetupGUI();
00047 
00048    static Bool_t CheckMacro(const char* mac);
00049    static void   AssertMacro(const char* mac);
00050    static void   Macro(const char* mac);
00051    static void   LoadMacro(const char* mac);
00052 
00053    // Color management
00054 
00055    static void     ColorFromIdx(Color_t ci, UChar_t col[4], Bool_t alpha=kTRUE);
00056    static void     ColorFromIdx(Color_t ci, UChar_t col[4], Char_t transparency);
00057    static void     ColorFromIdx(Float_t f1, Color_t c1, Float_t f2, Color_t c2,
00058                                 UChar_t col[4], Bool_t alpha=kTRUE);
00059    static Color_t* FindColorVar(TObject* obj, const char* varname);
00060 
00061    static void     SetColorBrightness(Float_t value, Bool_t full_redraw=kFALSE);
00062 
00063 
00064    // Math utilities
00065 
00066    static Bool_t IsU1IntervalContainedByMinMax  (Float_t minM, Float_t maxM,
00067                                                  Float_t minQ, Float_t maxQ);
00068    static Bool_t IsU1IntervalOverlappingByMinMax(Float_t minM, Float_t maxM,
00069                                                  Float_t minQ, Float_t maxQ);
00070 
00071    static Bool_t IsU1IntervalContainedByMeanDelta  (Float_t meanM, Float_t deltaM,
00072                                                     Float_t meanQ, Float_t deltaQ);
00073    static Bool_t IsU1IntervalOverlappingByMeanDelta(Float_t meanM, Float_t deltaM,
00074                                                     Float_t meanQ, Float_t deltaQ);
00075 
00076    static Float_t GetFraction(Float_t minM, Float_t maxM, Float_t minQ, Float_t maxQ);
00077 
00078 
00079    ClassDef(TEveUtil, 0); // Standard utility functions for Reve.
00080 };
00081 
00082 inline Bool_t TEveUtil::IsU1IntervalContainedByMeanDelta(Float_t meanM, Float_t deltaM,
00083                                                          Float_t meanQ, Float_t deltaQ)
00084 {
00085    return IsU1IntervalContainedByMinMax(meanM - deltaM, meanM + deltaM, meanQ - deltaQ, meanQ + deltaQ);
00086 }
00087 
00088 inline Bool_t TEveUtil::IsU1IntervalOverlappingByMeanDelta(Float_t meanM, Float_t deltaM,
00089                                                              Float_t meanQ, Float_t deltaQ)
00090 {
00091    return IsU1IntervalContainedByMinMax(meanM - deltaM, meanM + deltaM, meanQ - deltaQ, meanQ + deltaQ);
00092 }
00093 
00094 
00095 /******************************************************************************/
00096 // Exceptions, string functions
00097 /******************************************************************************/
00098 
00099 bool operator==(const TString& t, const std::string& s);
00100 bool operator==(const std::string& s, const TString& t);
00101 
00102 class TEveException : public std::exception, public TString
00103 {
00104 public:
00105    TEveException() {}
00106    TEveException(const TString& s) : TString(s) {}
00107    TEveException(const char* s)    : TString(s) {}
00108    TEveException(const std::string& s);
00109 
00110    virtual ~TEveException() throw () {}
00111 
00112    virtual const char* what() const throw () { return Data(); }
00113 
00114    ClassDef(TEveException, 1); // Exception-type thrown by Eve classes.
00115 };
00116 
00117 TEveException operator+(const TEveException &s1, const std::string  &s2);
00118 TEveException operator+(const TEveException &s1, const TString &s2);
00119 TEveException operator+(const TEveException &s1, const char    *s2);
00120 
00121 
00122 /******************************************************************************/
00123 // Exception-safe global variable holders
00124 /******************************************************************************/
00125 
00126 class TEvePadHolder
00127 {
00128 private:
00129    TVirtualPad *fOldPad;
00130    Bool_t       fModifyUpdateP;
00131 
00132    TEvePadHolder(const TEvePadHolder&);            // Not implemented
00133    TEvePadHolder& operator=(const TEvePadHolder&); // Not implemented
00134 
00135 public:
00136    TEvePadHolder(Bool_t modify_update_p, TVirtualPad* new_pad=0, Int_t subpad=0);
00137    virtual ~TEvePadHolder();
00138 
00139    ClassDef(TEvePadHolder, 0); // Exception-safe wrapper for temporary setting of gPad variable.
00140 };
00141 
00142 class TEveGeoManagerHolder
00143 {
00144 private:
00145    TGeoManager *fManager;
00146    Int_t        fNSegments;
00147 
00148    TEveGeoManagerHolder(const TEveGeoManagerHolder&);            // Not implemented
00149    TEveGeoManagerHolder& operator=(const TEveGeoManagerHolder&); // Not implemented
00150 
00151 public:
00152    TEveGeoManagerHolder(TGeoManager* new_gmgr=0, Int_t n_seg=0);
00153    virtual ~TEveGeoManagerHolder();
00154 
00155    ClassDef(TEveGeoManagerHolder, 0); // Exception-safe wrapper for temporary setting of gGeoManager variable.
00156 };
00157 
00158 
00159 /******************************************************************************/
00160 // TEveRefCnt base-class (interface)
00161 /******************************************************************************/
00162 
00163 class TEveRefCnt
00164 {
00165 protected:
00166    Int_t fRefCount;
00167 
00168 public:
00169    TEveRefCnt() : fRefCount(0) {}
00170    virtual ~TEveRefCnt() {}
00171 
00172    TEveRefCnt(const TEveRefCnt&) : fRefCount(0) {}
00173    TEveRefCnt& operator=(const TEveRefCnt&) { return *this; }
00174 
00175    void IncRefCount() { ++fRefCount; }
00176    void DecRefCount() { if(--fRefCount <= 0) OnZeroRefCount(); }
00177 
00178    virtual void OnZeroRefCount() { delete this; }
00179 
00180    ClassDef(TEveRefCnt, 0); // Base-class for reference-counted objects.
00181 };
00182 
00183 /******************************************************************************/
00184 // TEveRefBackPtr reference-count with back pointers
00185 /******************************************************************************/
00186 
00187 class TEveRefBackPtr : public TEveRefCnt
00188 {
00189 protected:
00190    typedef std::map<TEveElement*, Int_t> RefMap_t;
00191    typedef RefMap_t::iterator            RefMap_i;
00192 
00193    RefMap_t fBackRefs;
00194 
00195 public:
00196    TEveRefBackPtr();
00197    virtual ~TEveRefBackPtr();
00198 
00199    TEveRefBackPtr(const TEveRefBackPtr&);
00200    TEveRefBackPtr& operator=(const TEveRefBackPtr&);
00201 
00202    using TEveRefCnt::IncRefCount;
00203    using TEveRefCnt::DecRefCount;
00204    virtual void IncRefCount(TEveElement* re);
00205    virtual void DecRefCount(TEveElement* re);
00206 
00207    virtual void StampBackPtrElements(UChar_t stamps);
00208 
00209    ClassDef(TEveRefBackPtr, 0); // Base-class for reference-counted objects with reverse references to TEveElement objects.
00210 };
00211 
00212 #endif

Generated on Tue Jul 5 14:15:04 2011 for ROOT_528-00b_version by  doxygen 1.5.1