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