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