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