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 std::ostream, std::setw;
43
44
46
47namespace RooFit {
48 ostream& operator<<(ostream& os, const RooPrintable& rp) {
49 // Implement ostream operator on RooPrintable in terms of printStream(InLine)
50 rp.printStream(os,rp.defaultPrintContents("I"),RooPrintable::kInline) ; return os ;
51 }
52}
53
54
55////////////////////////////////////////////////////////////////////////////////
56/// Set length of field reserved from printing name of RooAbsArgs in
57/// multi-line collection printing to given amount.
58
63
64
65
66////////////////////////////////////////////////////////////////////////////////
67/// Print description of object on ostream, printing contents set by contents integer,
68/// which is interpreted as an OR of 'enum ContentsOptions' values and in the style
69/// given by 'enum StyleOption'. Each message is prefixed by string 'indent' when printed
70
72{
73 // Handling of 'verbose' and 'treestructure' is delegated to dedicated implementation functions
75 printMultiline(os,contents,style==kVerbose,indent) ;
76 return ;
77 } else if (style==kTreeStructure) {
78 printTree(os,indent) ;
79 return ;
80 }
81
82 // Handle here Inline and SingleLine styles
83 if (style!=kInline) os << indent ;
84
85 // Print class name if requested
86 if (contents&kAddress) {
87 printAddress(os) ;
88 if (contents!=kAddress) {
89 os << " " ;
90 }
91 }
92
93 // Print class name if requested
94 if (contents&kClassName) {
95 printClassName(os) ;
96 if (contents!=kClassName) {
97 os << "::" ;
98 }
99 }
100
101 // Print object name if requested
102 if (contents&kName) {
103 if (_nameLength>0) {
104 os << setw(_nameLength) ;
105 }
106 printName(os) ;
107 }
108
109 // Print input argument structure from proxies if requested
110 if (contents&kArgs) {
111 printArgs(os) ;
112 }
113
114 // Print value if requested
115 if (contents&kValue) {
116 if (contents&kName) {
117 os << " = " ;
118 }
119 printValue(os) ;
120 }
121
122 // Print extras if required
123 if (contents&kExtras) {
124 if (contents!=kExtras) {
125 os << " " ;
126 }
127 printExtras(os) ;
128 }
129
130 // Print title if required
131 if (contents&kTitle) {
132 if (contents==kTitle) {
133 printTitle(os) ;
134 } else {
135 os << " \"" ;
136 printTitle(os) ;
137 os << "\"" ;
138 }
139 }
140
141 if (style!=kInline) os << std::endl ;
142
143}
144
145
146// Virtual hook function for class-specific content implementation
147
148////////////////////////////////////////////////////////////////////////////////
149/// Interface to print value of object
150
151void RooPrintable::printValue(ostream& /*os*/) const
152{
153}
154
155
156////////////////////////////////////////////////////////////////////////////////
157/// Interface to print extras of object
158
159void RooPrintable::printExtras(ostream& /*os*/) const
160{
161}
162
163
164////////////////////////////////////////////////////////////////////////////////
165/// Interface for detailed printing of object
166
167void RooPrintable::printMultiline(ostream& /*os*/, Int_t /*contents*/, bool /*verbose*/, TString /*indent*/) const
168{
169}
170
171
172////////////////////////////////////////////////////////////////////////////////
173/// Interface for tree structure printing of object
174
175void RooPrintable::printTree(ostream& /*os*/, TString /*indent*/) const
176{
177 std::cout << "Tree structure printing not implement for class " << IsA()->GetName() << std::endl ;
178}
179
180
181////////////////////////////////////////////////////////////////////////////////
182/// Interface for printing of object arguments. Arguments
183/// are loosely defined as external server objects
184/// in this context
185
186void RooPrintable::printArgs(ostream& /*os*/) const
187{
188}
189
190
191////////////////////////////////////////////////////////////////////////////////
192/// Print name of object
193
194void RooPrintable::printName(ostream& /*os*/) const
195{
196}
197
198
199////////////////////////////////////////////////////////////////////////////////
200/// Print title of object
201
202void RooPrintable::printTitle(ostream& /*os*/) const
203{
204}
205
206
207////////////////////////////////////////////////////////////////////////////////
208/// Print class name of object
209
210void RooPrintable::printClassName(ostream& /*os*/) const
211{
212}
213
214
215
216////////////////////////////////////////////////////////////////////////////////
217/// Print class name of object
218
219void RooPrintable::printAddress(ostream& os) const
220{
221 os << this ;
222}
223
224
225
226////////////////////////////////////////////////////////////////////////////////
227/// Default choice of contents to be printed (name and value)
228
230{
231 return kName|kValue ;
232}
233
234
235////////////////////////////////////////////////////////////////////////////////
236
238{
239 if (!opt) {
240 return kSingleLine ;
241 }
242
243 TString o(opt) ;
244 o.ToLower() ;
245
246 if (o.Contains("v")) {
247 return kVerbose ;
248 } else if (o.Contains("s")) {
249 return kStandard ;
250 } else if (o.Contains("i")) {
251 return kInline ;
252 } else if (o.Contains("t")) {
253 return kTreeStructure ;
254 }
255
256 return kSingleLine ;
257}
258
259
260
261////////////////////////////////////////////////////////////////////////////////
262/// Return a reference to the current default stream to use in
263/// Print(). Use the optional parameter to specify a new default
264/// stream (a reference to the old one is still returned). This
265/// method allows subclasses to provide an inline implementation of
266/// Print() without pulling in iostream.h.
267
268ostream &RooPrintable::defaultPrintStream(std::ostream *os)
269{
270 static ostream *_defaultPrintStream = &std::cout;
271
273 if(nullptr != os) _defaultPrintStream= os;
274 return _oldDefault;
275}
int Int_t
Definition RtypesCore.h:45
const char Option_t
Definition RtypesCore.h:66
static void indent(ostringstream &buf, int indent_level)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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.
Basic string class.
Definition TString.h:139
void ToLower()
Change string to lower-case.
Definition TString.cxx:1182
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:632
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition CodegenImpl.h:64
std::ostream & operator<<(std::ostream &os, const RooPrintable &rp)