ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TFitResultPtr.cxx
Go to the documentation of this file.
1 // @(#)root/hist:$Id$
2 // Author: David Gonzalez Maline 12/11/09
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include "TFitResultPtr.h"
13 #include "TFitResult.h"
14 #include "TError.h"
15 
16 /** \class TFitResultPtr
17 Provides an indirection to the TFitResult class and with a semantics
18 identical to a TFitResult pointer, i.e. it is like a smart pointer to a TFitResult.
19 In addition it provides an automatic comversion to an integer. In this way it can be
20 returned from the TH1::Fit method and the change in TH1::Fit be backward compatible.
21  */
22 
24 
25 ////////////////////////////////////////////////////////////////////////////////
26 /// Constructor from a TFitResult pointer
27 
28 TFitResultPtr::TFitResultPtr(const std::shared_ptr<TFitResult> & p) :
29  fStatus(-1),
30  fPointer(p)
31 {
32  if (fPointer) fStatus = fPointer->Status();
33 }
34 
35 ////////////////////////////////////////////////////////////////////////////////
36 /// Constructor from a TFitResult pointer
37 
39  fStatus(-1),
40  fPointer(std::shared_ptr<TFitResult>(p))
41 {
42  if (fPointer) fStatus = fPointer->Status();
43 }
44 
46  fStatus(rhs.fStatus), fPointer(rhs.fPointer)
47 {
48 }
49 
50 ////////////////////////////////////////////////////////////////////////////////
51 /// Destructor. Delete the contained TFitResult pointer if needed
52 /// if ( fPointer != 0)
53 /// delete fPointer;
54 
56 {
57 }
58 
59 ////////////////////////////////////////////////////////////////////////////////
60 /// Implement the de-reference operator to make the class acts as a pointer to a TFitResult
61 /// assert in case the class does not contain a pointer to TFitResult
62 
64 {
65  if (!fPointer) {
66  Error("TFitResultPtr","TFitResult is empty - use the fit option S");
67  }
68  return *fPointer;
69 }
70 
71 ////////////////////////////////////////////////////////////////////////////////
72 /// Implement the -> operator to make the class acts as a pointer to a TFitResult.
73 /// assert in case the class does not contain a pointer to TFitResult
74 
76 {
77  if (!fPointer) {
78  Error("TFitResultPtr","TFitResult is empty - use the fit option S");
79  }
80  return fPointer.get();
81 }
82 
83 ////////////////////////////////////////////////////////////////////////////////
84 /// Return contained pointer
85 
87  return fPointer.get();
88 }
89 
90 ////////////////////////////////////////////////////////////////////////////////
91 /// Assignment operator.
92 /// if needed copy the TFitResult object and delete previous one if existing
93 
95 {
96  if ( &rhs == this) return *this; // self assignment
97  fStatus = rhs.fStatus;
98  fPointer = rhs.fPointer;
99  // if ( fPointer ) delete fPointer;
100  // fPointer = 0;
101  // if (rhs.fPointer != 0) fPointer = new TFitResult(*rhs);
102  return *this;
103 }
104 
TFitResultPtr & operator=(const TFitResultPtr &rhs)
Assignment operator.
Extends the ROOT::Fit::Result class with a TNamed inheritance providing easy possibility for I/O...
Definition: TFitResult.h:36
virtual ~TFitResultPtr()
Destructor.
void Error(const char *location, const char *msgfmt,...)
TFitResult & operator*() const
Implement the de-reference operator to make the class acts as a pointer to a TFitResult assert in cas...
TFitResultPtr(int status=-1)
Definition: TFitResultPtr.h:36
ClassImp(TFitResultPtr) TFitResultPtr
Constructor from a TFitResult pointer.
int Status() const
minimizer status code
Definition: FitResult.h:142
Provides an indirection to the TFitResult class and with a semantics identical to a TFitResult pointe...
Definition: TFitResultPtr.h:33
TFitResult * operator->() const
Implement the -> operator to make the class acts as a pointer to a TFitResult.
TFitResult * Get() const
Return contained pointer.
std::shared_ptr< TFitResult > fPointer
Definition: TFitResultPtr.h:59