Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:29:44

0001 // @(#)root/roostats:$Id$
0002 // Author: L. Moneta
0003 /*************************************************************************
0004  * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers.               *
0005  * All rights reserved.                                                  *
0006  *                                                                       *
0007  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0008  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0009  *************************************************************************/
0010 
0011 #ifndef HISTFACTORY_HISTREF_H
0012 #define HISTFACTORY_HISTREF_H
0013 
0014 #include <memory>
0015 #include <TH1.h>
0016 
0017 namespace RooStats{
0018 namespace HistFactory {
0019 
0020 
0021 // Internal class wrapping an histogram and managing its content.
0022 // conveninet for dealing with histogram pointers in the
0023 // HistFactory class
0024 class HistRef {
0025 
0026 public:
0027 
0028 
0029    /// constructor - use gives away ownerhip of the given pointer
0030    HistRef(TH1 * h = nullptr) : fHist(h) {}
0031 
0032    HistRef( const HistRef& other )
0033    {
0034       if (other.fHist) fHist.reset(CopyObject(other.fHist.get()));
0035    }
0036 
0037    HistRef(HistRef&& other) :
0038    fHist(std::move(other.fHist)) {}
0039 
0040    ~HistRef() {}
0041 
0042    /// assignment operator (delete previous contained histogram)
0043    HistRef & operator= (const HistRef & other) {
0044       if (this == &other) return *this;
0045 
0046       fHist.reset(CopyObject(other.fHist.get()));
0047       return *this;
0048    }
0049 
0050    HistRef& operator=(HistRef&& other) {
0051      fHist = std::move(other.fHist);
0052      return *this;
0053    }
0054 
0055    TH1 * GetObject() const { return fHist.get(); }
0056 
0057    /// set the object - user gives away the ownerhisp
0058    void SetObject(TH1 *h)  {
0059       fHist.reset(h);
0060    }
0061 
0062    /// operator= passing an object pointer :  user gives away its ownerhisp
0063    void operator= (TH1 * h) { SetObject(h); }
0064 
0065    /// Release ownership of object.
0066    TH1* ReleaseObject() {
0067      return fHist.release();
0068    }
0069 
0070 
0071 
0072 private:
0073    static TH1 * CopyObject(const TH1 * h);
0074    std::unique_ptr<TH1> fHist;   ///< pointer to contained histogram
0075 };
0076 
0077 }
0078 }
0079 
0080 #endif