From aee7c467e978c835a4bfccc072068b11d3aab0f2 Mon Sep 17 00:00:00 2001
From: Boris Perovic <boris.perovic@cern.ch>
Date: Thu, 20 Aug 2015 18:36:59 +0200
Subject: [PATCH] TObject and TH1 printValue demo implementation.

---
 core/base/inc/TObject.h   |  4 ++++
 core/base/src/TObject.cxx | 10 ++++++++++
 hist/hist/inc/TH1.h       |  4 ++++
 hist/hist/src/TH1.cxx     | 10 ++++++++++
 4 files changed, 28 insertions(+)

diff --git a/core/base/inc/TObject.h b/core/base/inc/TObject.h
index 090a4967d6a..399889afd91 100644
--- a/core/base/inc/TObject.h
+++ b/core/base/inc/TObject.h
@@ -228,6 +228,10 @@ enum EObjBits {
    kInvalidObject    = TObject::kInvalidObject
 };
 
+namespace cling {
+   std::string printValue(TObject *val);
+}
+
 #ifndef ROOT_TBuffer
 #include "TBuffer.h"
 #endif
diff --git a/core/base/src/TObject.cxx b/core/base/src/TObject.cxx
index 124b0d66ccd..8af0e147d81 100644
--- a/core/base/src/TObject.cxx
+++ b/core/base/src/TObject.cxx
@@ -32,6 +32,7 @@
 #endif
 #include <stdlib.h>
 #include <stdio.h>
+#include <sstream>
 
 #include "Varargs.h"
 #include "Riostream.h"
@@ -1055,6 +1056,15 @@ void TObject::operator delete[](void *ptr)
       fgDtorOnly = 0;
 }
 
+////////////////////////////////////////////////////////////////////////////////
+/// Print value overload
+
+std::string cling::printValue(TObject *val) {
+   std::ostringstream strm;
+   strm << "Name: " << val->GetName() << " Title: " << val->GetTitle();
+   return strm.str();
+}
+
 #ifdef R__PLACEMENTDELETE
 ////////////////////////////////////////////////////////////////////////////////
 /// Only called by placement new when throwing an exception.
diff --git a/hist/hist/inc/TH1.h b/hist/hist/inc/TH1.h
index 83fff6ce99b..73f4c67085a 100644
--- a/hist/hist/inc/TH1.h
+++ b/hist/hist/inc/TH1.h
@@ -438,6 +438,10 @@ protected:
    virtual Double_t GetBinErrorSqUnchecked(Int_t bin) const { return fSumw2.fN ? fSumw2.fArray[bin] : RetrieveBinContent(bin); }
 };
 
+namespace cling {
+  std::string printValue(TH1 *val);
+}
+
 //________________________________________________________________________
 
 class TH1C : public TH1, public TArrayC {
diff --git a/hist/hist/src/TH1.cxx b/hist/hist/src/TH1.cxx
index b70f63c37fa..76b5fd2e669 100644
--- a/hist/hist/src/TH1.cxx
+++ b/hist/hist/src/TH1.cxx
@@ -13,6 +13,7 @@
 #include <string.h>
 #include <stdio.h>
 #include <ctype.h>
+#include <sstream>
 
 #include "Riostream.h"
 #include "TROOT.h"
@@ -8794,6 +8795,15 @@ void TH1::UpdateBinContent(Int_t, Double_t)
    AbstractMethod("UpdateBinContent");
 }
 
+////////////////////////////////////////////////////////////////////////////////
+/// Print value overload
+
+std::string cling::printValue(TH1 *val) {
+  std::ostringstream strm;
+  strm << cling::printValue((TObject*)val) << " NbinsX: " << val->GetNbinsX();
+  return strm.str();
+}
+
 
 //______________________________________________________________________________
 //                     TH1C methods
-- 
GitLab