ROOT logo
// @(#)root/eve:$Id$
// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007

/*************************************************************************
 * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TEveUtil
#define ROOT_TEveUtil

#include "TObject.h"
#include "TString.h"
#include "TError.h"

#include "GuiTypes.h"

#include <list>
#include <map>
#include <set>
#include <exception>

class TVirtualPad;
class TGeoManager;

class TEveElement;

/******************************************************************************/
// TEveUtil
/******************************************************************************/

class TEveUtil
{
private:
   static TObjArray* fgDefaultColors;

public:
   virtual ~TEveUtil() {}

   // Environment, Macro functions

   static void   SetupEnvironment();
   static void   SetupGUI();

   static Bool_t CheckMacro(const char* mac);
   static void   AssertMacro(const char* mac);
   static void   Macro(const char* mac);
   static void   LoadMacro(const char* mac);

   // Color management

   static void     ColorFromIdx(Color_t ci, UChar_t col[4], Bool_t alpha=kTRUE);
   static void     ColorFromIdx(Color_t ci, UChar_t col[4], Char_t transparency);
   static void     ColorFromIdx(Float_t f1, Color_t c1, Float_t f2, Color_t c2,
                                UChar_t col[4], Bool_t alpha=kTRUE);
   static Color_t* FindColorVar(TObject* obj, const char* varname);

   static void     SetColorBrightness(Float_t value, Bool_t full_redraw=kFALSE);


   // Math utilities

   static Bool_t IsU1IntervalContainedByMinMax  (Float_t minM, Float_t maxM,
                                                 Float_t minQ, Float_t maxQ);
   static Bool_t IsU1IntervalOverlappingByMinMax(Float_t minM, Float_t maxM,
                                                 Float_t minQ, Float_t maxQ);

   static Bool_t IsU1IntervalContainedByMeanDelta  (Float_t meanM, Float_t deltaM,
                                                    Float_t meanQ, Float_t deltaQ);
   static Bool_t IsU1IntervalOverlappingByMeanDelta(Float_t meanM, Float_t deltaM,
                                                    Float_t meanQ, Float_t deltaQ);

   static Float_t GetFraction(Float_t minM, Float_t maxM, Float_t minQ, Float_t maxQ);


   ClassDef(TEveUtil, 0); // Standard utility functions for Reve.
};

inline Bool_t TEveUtil::IsU1IntervalContainedByMeanDelta(Float_t meanM, Float_t deltaM,
                                                         Float_t meanQ, Float_t deltaQ)
{
   return IsU1IntervalContainedByMinMax(meanM - deltaM, meanM + deltaM, meanQ - deltaQ, meanQ + deltaQ);
}

inline Bool_t TEveUtil::IsU1IntervalOverlappingByMeanDelta(Float_t meanM, Float_t deltaM,
                                                             Float_t meanQ, Float_t deltaQ)
{
   return IsU1IntervalContainedByMinMax(meanM - deltaM, meanM + deltaM, meanQ - deltaQ, meanQ + deltaQ);
}


/******************************************************************************/
// Exceptions, string functions
/******************************************************************************/

bool operator==(const TString& t, const std::string& s);
bool operator==(const std::string& s, const TString& t);

class TEveException : public std::exception, public TString
{
public:
   TEveException() {}
   TEveException(const TString& s) : TString(s) {}
   TEveException(const char* s)    : TString(s) {}
   TEveException(const std::string& s);

   virtual ~TEveException() throw () {}

   virtual const char* what() const throw () { return Data(); }

   ClassDef(TEveException, 1); // Exception-type thrown by Eve classes.
};

TEveException operator+(const TEveException &s1, const std::string  &s2);
TEveException operator+(const TEveException &s1, const TString &s2);
TEveException operator+(const TEveException &s1, const char    *s2);


/******************************************************************************/
// Exception-safe global variable holders
/******************************************************************************/

class TEvePadHolder
{
private:
   TVirtualPad *fOldPad;
   Bool_t       fModifyUpdateP;

   TEvePadHolder(const TEvePadHolder&);            // Not implemented
   TEvePadHolder& operator=(const TEvePadHolder&); // Not implemented

public:
   TEvePadHolder(Bool_t modify_update_p, TVirtualPad* new_pad=0, Int_t subpad=0);
   virtual ~TEvePadHolder();

   ClassDef(TEvePadHolder, 0); // Exception-safe wrapper for temporary setting of gPad variable.
};

class TEveGeoManagerHolder
{
private:
   TGeoManager *fManager;
   Int_t        fNSegments;

   TEveGeoManagerHolder(const TEveGeoManagerHolder&);            // Not implemented
   TEveGeoManagerHolder& operator=(const TEveGeoManagerHolder&); // Not implemented

public:
   TEveGeoManagerHolder(TGeoManager* new_gmgr=0, Int_t n_seg=0);
   virtual ~TEveGeoManagerHolder();

   ClassDef(TEveGeoManagerHolder, 0); // Exception-safe wrapper for temporary setting of gGeoManager variable.
};


/******************************************************************************/
// TEveRefCnt base-class (interface)
/******************************************************************************/

class TEveRefCnt
{
protected:
   Int_t fRefCount;

public:
   TEveRefCnt() : fRefCount(0) {}
   virtual ~TEveRefCnt() {}

   TEveRefCnt(const TEveRefCnt&) : fRefCount(0) {}
   TEveRefCnt& operator=(const TEveRefCnt&) { return *this; }

   void IncRefCount() { ++fRefCount; }
   void DecRefCount() { if(--fRefCount <= 0) OnZeroRefCount(); }

   virtual void OnZeroRefCount() { delete this; }

   ClassDef(TEveRefCnt, 0); // Base-class for reference-counted objects.
};

/******************************************************************************/
// TEveRefBackPtr reference-count with back pointers
/******************************************************************************/

class TEveRefBackPtr : public TEveRefCnt
{
protected:
   typedef std::map<TEveElement*, Int_t> RefMap_t;
   typedef RefMap_t::iterator            RefMap_i;

   RefMap_t fBackRefs;

public:
   TEveRefBackPtr();
   virtual ~TEveRefBackPtr();

   TEveRefBackPtr(const TEveRefBackPtr&);
   TEveRefBackPtr& operator=(const TEveRefBackPtr&);

   using TEveRefCnt::IncRefCount;
   using TEveRefCnt::DecRefCount;
   virtual void IncRefCount(TEveElement* re);
   virtual void DecRefCount(TEveElement* re);

   virtual void StampBackPtrElements(UChar_t stamps);

   ClassDef(TEveRefBackPtr, 0); // Base-class for reference-counted objects with reverse references to TEveElement objects.
};

#endif
 TEveUtil.h:1
 TEveUtil.h:2
 TEveUtil.h:3
 TEveUtil.h:4
 TEveUtil.h:5
 TEveUtil.h:6
 TEveUtil.h:7
 TEveUtil.h:8
 TEveUtil.h:9
 TEveUtil.h:10
 TEveUtil.h:11
 TEveUtil.h:12
 TEveUtil.h:13
 TEveUtil.h:14
 TEveUtil.h:15
 TEveUtil.h:16
 TEveUtil.h:17
 TEveUtil.h:18
 TEveUtil.h:19
 TEveUtil.h:20
 TEveUtil.h:21
 TEveUtil.h:22
 TEveUtil.h:23
 TEveUtil.h:24
 TEveUtil.h:25
 TEveUtil.h:26
 TEveUtil.h:27
 TEveUtil.h:28
 TEveUtil.h:29
 TEveUtil.h:30
 TEveUtil.h:31
 TEveUtil.h:32
 TEveUtil.h:33
 TEveUtil.h:34
 TEveUtil.h:35
 TEveUtil.h:36
 TEveUtil.h:37
 TEveUtil.h:38
 TEveUtil.h:39
 TEveUtil.h:40
 TEveUtil.h:41
 TEveUtil.h:42
 TEveUtil.h:43
 TEveUtil.h:44
 TEveUtil.h:45
 TEveUtil.h:46
 TEveUtil.h:47
 TEveUtil.h:48
 TEveUtil.h:49
 TEveUtil.h:50
 TEveUtil.h:51
 TEveUtil.h:52
 TEveUtil.h:53
 TEveUtil.h:54
 TEveUtil.h:55
 TEveUtil.h:56
 TEveUtil.h:57
 TEveUtil.h:58
 TEveUtil.h:59
 TEveUtil.h:60
 TEveUtil.h:61
 TEveUtil.h:62
 TEveUtil.h:63
 TEveUtil.h:64
 TEveUtil.h:65
 TEveUtil.h:66
 TEveUtil.h:67
 TEveUtil.h:68
 TEveUtil.h:69
 TEveUtil.h:70
 TEveUtil.h:71
 TEveUtil.h:72
 TEveUtil.h:73
 TEveUtil.h:74
 TEveUtil.h:75
 TEveUtil.h:76
 TEveUtil.h:77
 TEveUtil.h:78
 TEveUtil.h:79
 TEveUtil.h:80
 TEveUtil.h:81
 TEveUtil.h:82
 TEveUtil.h:83
 TEveUtil.h:84
 TEveUtil.h:85
 TEveUtil.h:86
 TEveUtil.h:87
 TEveUtil.h:88
 TEveUtil.h:89
 TEveUtil.h:90
 TEveUtil.h:91
 TEveUtil.h:92
 TEveUtil.h:93
 TEveUtil.h:94
 TEveUtil.h:95
 TEveUtil.h:96
 TEveUtil.h:97
 TEveUtil.h:98
 TEveUtil.h:99
 TEveUtil.h:100
 TEveUtil.h:101
 TEveUtil.h:102
 TEveUtil.h:103
 TEveUtil.h:104
 TEveUtil.h:105
 TEveUtil.h:106
 TEveUtil.h:107
 TEveUtil.h:108
 TEveUtil.h:109
 TEveUtil.h:110
 TEveUtil.h:111
 TEveUtil.h:112
 TEveUtil.h:113
 TEveUtil.h:114
 TEveUtil.h:115
 TEveUtil.h:116
 TEveUtil.h:117
 TEveUtil.h:118
 TEveUtil.h:119
 TEveUtil.h:120
 TEveUtil.h:121
 TEveUtil.h:122
 TEveUtil.h:123
 TEveUtil.h:124
 TEveUtil.h:125
 TEveUtil.h:126
 TEveUtil.h:127
 TEveUtil.h:128
 TEveUtil.h:129
 TEveUtil.h:130
 TEveUtil.h:131
 TEveUtil.h:132
 TEveUtil.h:133
 TEveUtil.h:134
 TEveUtil.h:135
 TEveUtil.h:136
 TEveUtil.h:137
 TEveUtil.h:138
 TEveUtil.h:139
 TEveUtil.h:140
 TEveUtil.h:141
 TEveUtil.h:142
 TEveUtil.h:143
 TEveUtil.h:144
 TEveUtil.h:145
 TEveUtil.h:146
 TEveUtil.h:147
 TEveUtil.h:148
 TEveUtil.h:149
 TEveUtil.h:150
 TEveUtil.h:151
 TEveUtil.h:152
 TEveUtil.h:153
 TEveUtil.h:154
 TEveUtil.h:155
 TEveUtil.h:156
 TEveUtil.h:157
 TEveUtil.h:158
 TEveUtil.h:159
 TEveUtil.h:160
 TEveUtil.h:161
 TEveUtil.h:162
 TEveUtil.h:163
 TEveUtil.h:164
 TEveUtil.h:165
 TEveUtil.h:166
 TEveUtil.h:167
 TEveUtil.h:168
 TEveUtil.h:169
 TEveUtil.h:170
 TEveUtil.h:171
 TEveUtil.h:172
 TEveUtil.h:173
 TEveUtil.h:174
 TEveUtil.h:175
 TEveUtil.h:176
 TEveUtil.h:177
 TEveUtil.h:178
 TEveUtil.h:179
 TEveUtil.h:180
 TEveUtil.h:181
 TEveUtil.h:182
 TEveUtil.h:183
 TEveUtil.h:184
 TEveUtil.h:185
 TEveUtil.h:186
 TEveUtil.h:187
 TEveUtil.h:188
 TEveUtil.h:189
 TEveUtil.h:190
 TEveUtil.h:191
 TEveUtil.h:192
 TEveUtil.h:193
 TEveUtil.h:194
 TEveUtil.h:195
 TEveUtil.h:196
 TEveUtil.h:197
 TEveUtil.h:198
 TEveUtil.h:199
 TEveUtil.h:200
 TEveUtil.h:201
 TEveUtil.h:202
 TEveUtil.h:203
 TEveUtil.h:204
 TEveUtil.h:205
 TEveUtil.h:206
 TEveUtil.h:207
 TEveUtil.h:208
 TEveUtil.h:209
 TEveUtil.h:210
 TEveUtil.h:211
 TEveUtil.h:212