Logo ROOT  
Reference Guide
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 
22 RooPlotable is a 'mix-in' base class that define the standard RooFit plotting and
23 printing methods. Each RooPlotable implementation must define methods that
24 print the objects name, class name, title, value, arguments and extras
25 to a provided stream. The definition of value is class dependent. The definition
26 of arguments is also class dependent, but should always be interpreted as
27 the names (and properties) of any (RooAbsArg) external inputs of a given object.
28 The extras method can be used to print any properties that does not fit in any
29 of the other classes. Each object an also override the definitions made
30 in defaultPrintStyle and defaultPrintContents to determine what is printed
31 (in terms of contents) and how it is printed (inline,single-line or multiline)
32 given 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 
44 using namespace std;
45 
47 ;
48 
50 
51 namespace 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 
75 void 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
78  if (style==kVerbose||style==kStandard) {
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 
155 void RooPrintable::printValue(ostream& /*os*/) const
156 {
157 }
158 
159 
160 ////////////////////////////////////////////////////////////////////////////////
161 /// Interface to print extras of object
162 
163 void RooPrintable::printExtras(ostream& /*os*/) const
164 {
165 }
166 
167 
168 ////////////////////////////////////////////////////////////////////////////////
169 /// Interface for detailed printing of object
170 
171 void 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 
179 void 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 
190 void RooPrintable::printArgs(ostream& /*os*/) const
191 {
192 }
193 
194 
195 ////////////////////////////////////////////////////////////////////////////////
196 /// Print name of object
197 
198 void RooPrintable::printName(ostream& /*os*/) const
199 {
200 }
201 
202 
203 ////////////////////////////////////////////////////////////////////////////////
204 /// Print title of object
205 
206 void RooPrintable::printTitle(ostream& /*os*/) const
207 {
208 }
209 
210 
211 ////////////////////////////////////////////////////////////////////////////////
212 /// Print class name of object
213 
214 void RooPrintable::printClassName(ostream& /*os*/) const
215 {
216 }
217 
218 
219 
220 ////////////////////////////////////////////////////////////////////////////////
221 /// Print class name of object
222 
223 void 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 
272 ostream &RooPrintable::defaultPrintStream(ostream *os)
273 {
274  static ostream *_defaultPrintStream = &cout;
275 
276  ostream& _oldDefault= *_defaultPrintStream;
277  if(0 != os) _defaultPrintStream= os;
278  return _oldDefault;
279 }
RooPrintable::_nameLength
static Int_t _nameLength
Definition: RooPrintable.h:57
RooPrintable::nameFieldLength
static void nameFieldLength(Int_t newLen)
Set length of field reserved from printing name of RooAbsArgs in multi-line collection printing to gi...
Definition: RooPrintable.cxx:63
RooFit.h
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
RooPrintable::printTree
virtual void printTree(std::ostream &os, TString indent="") const
Interface for tree structure printing of object.
Definition: RooPrintable.cxx:179
TNamed.h
RooPrintable::StyleOption
StyleOption
Definition: RooPrintable.h:34
Int_t
int Int_t
Definition: RtypesCore.h:45
RooPrintable.h
TString::Contains
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:624
TClass.h
indent
static void indent(ostringstream &buf, int indent_level)
Definition: TClingCallFunc.cxx:87
RooPrintable::printClassName
virtual void printClassName(std::ostream &os) const
Print class name of object.
Definition: RooPrintable.cxx:214
TString
Definition: TString.h:136
RooPrintable
Definition: RooPrintable.h:25
bool
style
TCanvas * style()
Definition: style.C:1
RooPrintable::defaultPrintContents
virtual Int_t defaultPrintContents(Option_t *opt) const
Default choice of contents to be printed (name and value)
Definition: RooPrintable.cxx:233
Option_t
const typedef char Option_t
Definition: RtypesCore.h:66
RooPrintable::printAddress
virtual void printAddress(std::ostream &os) const
Print class name of object.
Definition: RooPrintable.cxx:223
RooFit
Definition: RooCFunction1Binding.h:29
RooPrintable::defaultPrintStream
static std::ostream & defaultPrintStream(std::ostream *os=0)
Return a reference to the current default stream to use in Print().
Definition: RooPrintable.cxx:272
kName
@ kName
Definition: TStyleDialog.cxx:45
RooPrintable::printArgs
virtual void printArgs(std::ostream &os) const
Interface for printing of object arguments.
Definition: RooPrintable.cxx:190
RooPrintable::printMultiline
virtual void printMultiline(std::ostream &os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const
Interface for detailed printing of object.
Definition: RooPrintable.cxx:171
RooPrintable::printName
virtual void printName(std::ostream &os) const
Print name of object.
Definition: RooPrintable.cxx:198
RooPrintable::kInline
@ kInline
Definition: RooPrintable.h:34
RooPrintable::printStream
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,...
Definition: RooPrintable.cxx:75
CPyCppyy::Utility::kValue
@ kValue
Definition: Utility.h:36
RooPrintable::defaultPrintStyle
virtual StyleOption defaultPrintStyle(Option_t *opt) const
Definition: RooPrintable.cxx:241
TString::ToLower
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1125
Riostream.h
operator<<
TBuffer & operator<<(TBuffer &buf, const Tmpl *obj)
Definition: TBuffer.h:399
RooPrintable::printTitle
virtual void printTitle(std::ostream &os) const
Print title of object.
Definition: RooPrintable.cxx:206
int
kTitle
@ kTitle
Definition: TStyleDialog.cxx:46
RooPrintable::printExtras
virtual void printExtras(std::ostream &os) const
Interface to print extras of object.
Definition: RooPrintable.cxx:163
RooPrintable::printValue
virtual void printValue(std::ostream &os) const
Interface to print value of object.
Definition: RooPrintable.cxx:155