Logo ROOT   6.18/05
Reference Guide
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#include <memory>
15
16class TH1;
17
18namespace RooStats{
19namespace HistFactory {
20
21
22// Internal class wrapping an histogram and managing its content.
23// conveninet for dealing with histogram pointers in the
24// HistFactory class
25class HistRef {
26
27public:
28
29
30 /// constructor - use gives away ownerhip of the given pointer
31 HistRef(TH1 * h = nullptr) : fHist(h) {}
32
33 HistRef( const HistRef& other ) :
34 fHist() {
35 if (other.fHist) fHist.reset(CopyObject(other.fHist.get()));
36 }
37
38 HistRef(HistRef&& other) :
39 fHist(std::move(other.fHist)) {}
40
42
43 /// assignment operator (delete previous contained histogram)
44 HistRef & operator= (const HistRef & other) {
45 if (this == &other) return *this;
46
47 fHist.reset(CopyObject(other.fHist.get()));
48 return *this;
49 }
50
52 fHist = std::move(other.fHist);
53 return *this;
54 }
55
56 TH1 * GetObject() const { return fHist.get(); }
57
58 /// set the object - user gives away the ownerhisp
59 void SetObject(TH1 *h) {
60 fHist.reset(h);
61 }
62
63 /// operator= passing an object pointer : user gives away its ownerhisp
64 void operator= (TH1 * h) { SetObject(h); }
65
66 /// Release ownership of object.
68 return fHist.release();
69 }
70
71
72
73private:
74 static TH1 * CopyObject(const TH1 * h);
75 std::unique_ptr<TH1> fHist; // pointer to contained histogram
76};
77
78}
79}
80
81#endif
#define h(i)
Definition: RSha256.hxx:106
Internal class wrapping an histogram and managing its content.
Definition: HistRef.h:25
HistRef(TH1 *h=nullptr)
constructor - use gives away ownerhip of the given pointer
Definition: HistRef.h:31
HistRef & operator=(const HistRef &other)
assignment operator (delete previous contained histogram)
Definition: HistRef.h:44
HistRef(HistRef &&other)
Definition: HistRef.h:38
HistRef(const HistRef &other)
Definition: HistRef.h:33
void SetObject(TH1 *h)
set the object - user gives away the ownerhisp
Definition: HistRef.h:59
HistRef & operator=(HistRef &&other)
Definition: HistRef.h:51
std::unique_ptr< TH1 > fHist
Definition: HistRef.h:75
static TH1 * CopyObject(const TH1 *h)
Definition: HistRef.cxx:24
TH1 * ReleaseObject()
Release ownership of object.
Definition: HistRef.h:67
The TH1 histogram class.
Definition: TH1.h:56
Namespace for the RooStats classes.
Definition: Asimov.h:20