// @(#)root/roostats:$Id$
// Author: L. Moneta
/*************************************************************************
 * Copyright (C) 1995-2008, 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 HISTFACTORY_HISTREF_H
#define HISTFACTORY_HISTREF_H


class TH1; 

namespace RooStats{
namespace HistFactory {


// Internal class wrapping an histogram and managing its content. 
// conveninet for dealing with histogram pointers in the 
// HistFactory class 
class HistRef {
  
public:


   // constructor - use gives away ownerhip of the given pointer
   HistRef(TH1 * h = 0) : fHist(h) {}

   HistRef( const HistRef& other ) : 
   fHist(0) { 
      if (other.fHist) fHist = CopyObject(other.fHist); 
   }

   ~HistRef() { 
      DeleteObject(fHist); 
   }
 
   // assignment operator (delete previous contained histogram)
   HistRef & operator= (const HistRef & other) { 
      if (this == &other) return *this; 
      DeleteObject(fHist); 
      fHist = CopyObject(other.fHist);
      return *this;
   }

   TH1 * GetObject() const { return fHist; }

   // set the object - user gives away the ownerhisp 
   void SetObject(TH1 *h)  { 
      DeleteObject(fHist);
      fHist = h;
   }

   // operator= passing an object pointer :  user gives away its ownerhisp 
   void operator= (TH1 * h) { SetObject(h); } 

   static TH1 * CopyObject(TH1 * h); 
   static void  DeleteObject(TH1 * h); 
   
protected: 
   
   TH1 * fHist;   // pointer to contained histogram 
};

}
}

#endif
 HistRef.h:1
 HistRef.h:2
 HistRef.h:3
 HistRef.h:4
 HistRef.h:5
 HistRef.h:6
 HistRef.h:7
 HistRef.h:8
 HistRef.h:9
 HistRef.h:10
 HistRef.h:11
 HistRef.h:12
 HistRef.h:13
 HistRef.h:14
 HistRef.h:15
 HistRef.h:16
 HistRef.h:17
 HistRef.h:18
 HistRef.h:19
 HistRef.h:20
 HistRef.h:21
 HistRef.h:22
 HistRef.h:23
 HistRef.h:24
 HistRef.h:25
 HistRef.h:26
 HistRef.h:27
 HistRef.h:28
 HistRef.h:29
 HistRef.h:30
 HistRef.h:31
 HistRef.h:32
 HistRef.h:33
 HistRef.h:34
 HistRef.h:35
 HistRef.h:36
 HistRef.h:37
 HistRef.h:38
 HistRef.h:39
 HistRef.h:40
 HistRef.h:41
 HistRef.h:42
 HistRef.h:43
 HistRef.h:44
 HistRef.h:45
 HistRef.h:46
 HistRef.h:47
 HistRef.h:48
 HistRef.h:49
 HistRef.h:50
 HistRef.h:51
 HistRef.h:52
 HistRef.h:53
 HistRef.h:54
 HistRef.h:55
 HistRef.h:56
 HistRef.h:57
 HistRef.h:58
 HistRef.h:59
 HistRef.h:60
 HistRef.h:61
 HistRef.h:62
 HistRef.h:63
 HistRef.h:64
 HistRef.h:65
 HistRef.h:66
 HistRef.h:67
 HistRef.h:68
 HistRef.h:69
 HistRef.h:70
 HistRef.h:71