ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HistRef.h
Go to the documentation of this file.
1 // @(#)root/roostats:$Id$
2 // Author: L. Moneta
3 /*************************************************************************
4  * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. *
5  * All rights reserved. *
6  * *
7  * For the licensing terms see $ROOTSYS/LICENSE. *
8  * For the list of contributors see $ROOTSYS/README/CREDITS. *
9  *************************************************************************/
10 
11 #ifndef HISTFACTORY_HISTREF_H
12 #define HISTFACTORY_HISTREF_H
13 
14 
15 class TH1;
16 
17 namespace RooStats{
18 namespace HistFactory {
19 
20 
21 // Internal class wrapping an histogram and managing its content.
22 // conveninet for dealing with histogram pointers in the
23 // HistFactory class
24 class HistRef {
25 
26 public:
27 
28 
29  // constructor - use gives away ownerhip of the given pointer
30  HistRef(TH1 * h = 0) : fHist(h) {}
31 
32  HistRef( const HistRef& other ) :
33  fHist(0) {
34  if (other.fHist) fHist = CopyObject(other.fHist);
35  }
36 
37  ~HistRef() {
39  }
40 
41  // assignment operator (delete previous contained histogram)
42  HistRef & operator= (const HistRef & other) {
43  if (this == &other) return *this;
45  fHist = CopyObject(other.fHist);
46  return *this;
47  }
48 
49  TH1 * GetObject() const { return fHist; }
50 
51  // set the object - user gives away the ownerhisp
52  void SetObject(TH1 *h) {
54  fHist = h;
55  }
56 
57  // operator= passing an object pointer : user gives away its ownerhisp
58  void operator= (TH1 * h) { SetObject(h); }
59 
60  static TH1 * CopyObject(TH1 * h);
61  static void DeleteObject(TH1 * h);
62 
63 protected:
64 
65  TH1 * fHist; // pointer to contained histogram
66 };
67 
68 }
69 }
70 
71 #endif
TH1 * GetObject() const
Definition: HistRef.h:49
TH1 * h
Definition: legend2.C:5
HistRef(const HistRef &other)
Definition: HistRef.h:32
HistRef & operator=(const HistRef &other)
Definition: HistRef.h:42
static TH1 * CopyObject(TH1 *h)
Definition: HistRef.cxx:18
The TH1 histogram class.
Definition: TH1.h:80
static void DeleteObject(TH1 *h)
Definition: HistRef.cxx:25