Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooPrintable.cxx
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * @(#)root/roofitcore:$Id$
5 * Authors: *
6 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8 * *
9 * Copyright (c) 2000-2005, Regents of the University of California *
10 * and Stanford University. All rights reserved. *
11 * *
12 * Redistribution and use in source and binary forms, *
13 * with or without modification, are permitted according to the terms *
14 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15 *****************************************************************************/
16
17/**
18\file RooPrintable.cxx
19\class RooPrintable
20\ingroup Roofitcore
21
22A 'mix-in' base class that define the standard RooFit plotting and
23printing methods. Each RooPlotable implementation must define methods that
24print the objects name, class name, title, value, arguments and extras
25to a provided stream. The definition of value is class dependent. The definition
26of arguments is also class dependent, but should always be interpreted as
27the names (and properties) of any (RooAbsArg) external inputs of a given object.
28The extras method can be used to print any properties that does not fit in any
29of the other classes. Each object an also override the definitions made
30in defaultPrintStyle and defaultPrintContents to determine what is printed
31(in terms of contents) and how it is printed (inline,single-line or multiline)
32given a Print() option string.
33**/
34
35#include "RooPrintable.h"
36
37#include "Riostream.h"
38#include <iomanip>
39#include "TNamed.h"
40#include "TClass.h"
41
42using namespace std;
43
45
47
48namespace RooFit {
49 ostream& operator<<(ostream& os, const RooPrintable& rp) {
50 // Implement ostream operator on RooPrintable in terms of printStream(InLine)
51 rp.printStream(os,rp.defaultPrintContents("I"),RooPrintable::kInline) ; return os ;
52 }
53}
54
55
56////////////////////////////////////////////////////////////////////////////////
57/// Set length of field reserved from printing name of RooAbsArgs in
58/// multi-line collection printing to given amount.
59
61{
62 _nameLength = newLen>0 ? newLen : 0 ;
63}
64
65
66
67////////////////////////////////////////////////////////////////////////////////
68/// Print description of object on ostream, printing contents set by contents integer,
69/// which is interpreted as an OR of 'enum ContentsOptions' values and in the style
70/// given by 'enum StyleOption'. Each message is prefixed by string 'indent' when printed
71
73{
74 // Handling of 'verbose' and 'treestructure' is delegated to dedicated implementation functions
76 printMultiline(os,contents,style==kVerbose,indent) ;
77 return ;
78 } else if (style==kTreeStructure) {
79 printTree(os,indent) ;
80 return ;
81 }
82
83 // Handle here Inline and SingleLine styles
84 if (style!=kInline) os << indent ;
85
86 // Print class name if requested
87 if (contents&kAddress) {
88 printAddress(os) ;
89 if (contents!=kAddress) {
90 os << " " ;
91 }
92 }
93
94 // Print class name if requested
95 if (contents&kClassName) {
96 printClassName(os) ;
97 if (contents!=kClassName) {
98 os << "::" ;
99 }
100 }
101
102 // Print object name if requested
103 if (contents&kName) {
104 if (_nameLength>0) {
105 os << setw(_nameLength) ;
106 }
107 printName(os) ;
108 }
109
110 // Print input argument structure from proxies if requested
111 if (contents&kArgs) {
112 printArgs(os) ;
113 }
114
115 // Print value if requested
116 if (contents&kValue) {
117 if (contents&kName) {
118 os << " = " ;
119 }
120 printValue(os) ;
121 }
122
123 // Print extras if required
124 if (contents&kExtras) {
125 if (contents!=kExtras) {
126 os << " " ;
127 }
128 printExtras(os) ;
129 }
130
131 // Print title if required
132 if (contents&kTitle) {
133 if (contents==kTitle) {
134 printTitle(os) ;
135 } else {
136 os << " \"" ;
137 printTitle(os) ;
138 os << "\"" ;
139 }
140 }
141
142 if (style!=kInline) os << endl ;
143
144}
145
146
147// Virtual hook function for class-specific content implementation
148
149////////////////////////////////////////////////////////////////////////////////
150/// Interface to print value of object
151
152void RooPrintable::printValue(ostream& /*os*/) const
153{
154}
155
156
157////////////////////////////////////////////////////////////////////////////////
158/// Interface to print extras of object
159
160void RooPrintable::printExtras(ostream& /*os*/) const
161{
162}
163
164
165////////////////////////////////////////////////////////////////////////////////
166/// Interface for detailed printing of object
167
168void RooPrintable::printMultiline(ostream& /*os*/, Int_t /*contents*/, bool /*verbose*/, TString /*indent*/) const
169{
170}
171
172
173////////////////////////////////////////////////////////////////////////////////
174/// Interface for tree structure printing of object
175
176void RooPrintable::printTree(ostream& /*os*/, TString /*indent*/) const
177{
178 cout << "Tree structure printing not implement for class " << IsA()->GetName() << endl ;
179}
180
181
182////////////////////////////////////////////////////////////////////////////////
183/// Interface for printing of object arguments. Arguments
184/// are loosely defined as external server objects
185/// in this context
186
187void RooPrintable::printArgs(ostream& /*os*/) const
188{
189}
190
191
192////////////////////////////////////////////////////////////////////////////////
193/// Print name of object
194
195void RooPrintable::printName(ostream& /*os*/) const
196{
197}
198
199
200////////////////////////////////////////////////////////////////////////////////
201/// Print title of object
202
203void RooPrintable::printTitle(ostream& /*os*/) const
204{
205}
206
207
208////////////////////////////////////////////////////////////////////////////////
209/// Print class name of object
210
211void RooPrintable::printClassName(ostream& /*os*/) const
212{
213}
214
215
216
217////////////////////////////////////////////////////////////////////////////////
218/// Print class name of object
219
220void RooPrintable::printAddress(ostream& os) const
221{
222 os << this ;
223}
224
225
226
227////////////////////////////////////////////////////////////////////////////////
228/// Default choice of contents to be printed (name and value)
229
231{
232 return kName|kValue ;
233}
234
235
236////////////////////////////////////////////////////////////////////////////////
237
239{
240 if (!opt) {
241 return kSingleLine ;
242 }
243
244 TString o(opt) ;
245 o.ToLower() ;
246
247 if (o.Contains("v")) {
248 return kVerbose ;
249 } else if (o.Contains("s")) {
250 return kStandard ;
251 } else if (o.Contains("i")) {
252 return kInline ;
253 } else if (o.Contains("t")) {
254 return kTreeStructure ;
255 }
256
257 return kSingleLine ;
258}
259
260
261
262////////////////////////////////////////////////////////////////////////////////
263/// Return a reference to the current default stream to use in
264/// Print(). Use the optional parameter to specify a new default
265/// stream (a reference to the old one is still returned). This
266/// method allows subclasses to provide an inline implementation of
267/// Print() without pulling in iostream.h.
268
270{
271 static ostream *_defaultPrintStream = &cout;
272
273 ostream& _oldDefault= *_defaultPrintStream;
274 if(nullptr != os) _defaultPrintStream= os;
275 return _oldDefault;
276}
int Int_t
Definition RtypesCore.h:45
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
TBuffer & operator<<(TBuffer &buf, const Tmpl *obj)
Definition TBuffer.h:399
static void indent(ostringstream &buf, int indent_level)
Option_t Option_t style
A 'mix-in' base class that define the standard RooFit plotting and printing methods.
virtual void printTree(std::ostream &os, TString indent="") const
Interface for tree structure printing of object.
virtual void printName(std::ostream &os) const
Print name of object.
static Int_t _nameLength
virtual void printArgs(std::ostream &os) const
Interface for printing of object arguments.
virtual void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const
Interface for detailed printing of object.
static void nameFieldLength(Int_t newLen)
Set length of field reserved from printing name of RooAbsArgs in multi-line collection printing to gi...
virtual void printExtras(std::ostream &os) const
Interface to print extras of object.
virtual StyleOption defaultPrintStyle(Option_t *opt) const
virtual Int_t defaultPrintContents(Option_t *opt) const
Default choice of contents to be printed (name and value)
virtual void printClassName(std::ostream &os) const
Print class name of object.
virtual void printTitle(std::ostream &os) const
Print title of object.
virtual TClass * IsA() const
virtual void printAddress(std::ostream &os) const
Print class name of object.
static std::ostream & defaultPrintStream(std::ostream *os=nullptr)
Return a reference to the current default stream to use in Print().
virtual void printStream(std::ostream &os, Int_t contents, StyleOption style, TString indent="") const
Print description of object on ostream, printing contents set by contents integer,...
virtual void printValue(std::ostream &os) const
Interface to print value of object.
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
Basic string class.
Definition TString.h:139
void ToLower()
Change string to lower-case.
Definition TString.cxx:1170
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:634
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition JSONIO.h:26