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