00001 /***************************************************************************** 00002 * Project: RooFit * 00003 * Package: RooFitCore * 00004 * @(#)root/roofitcore:$Id: RooPrintable.cxx 25184 2008-08-20 13:59:55Z wouter $ 00005 * Authors: * 00006 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu * 00007 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu * 00008 * * 00009 * Copyright (c) 2000-2005, Regents of the University of California * 00010 * and Stanford University. All rights reserved. * 00011 * * 00012 * Redistribution and use in source and binary forms, * 00013 * with or without modification, are permitted according to the terms * 00014 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) * 00015 *****************************************************************************/ 00016 00017 ////////////////////////////////////////////////////////////////////////////// 00018 // 00019 // BEGIN_HTML 00020 // RooPlotable is a 'mix-in' base class that define the standard RooFit plotting and 00021 // printing methods. Each RooPlotable implementation must define methods that 00022 // print the objects name, class name, title, value, arguments and extras 00023 // to a provided stream. The definition of value is class dependent. The definition 00024 // of arguments is also class dependent, but should always be interpreted as 00025 // the names (and properties) of any (RooAbsArg) external inputs of a given object. 00026 // The extras method can be used to print any properties that does not fit in any 00027 // of the other classes. Each object an also override the definitions made 00028 // in defaultPrintStyle and defaultPrintContents to determine what is printed 00029 // (in terms of contents) and how it is printed (inline,single-line or multiline) 00030 // given a Print() option string. 00031 // END_HTML 00032 // 00033 00034 #include "RooFit.h" 00035 00036 #include "RooPrintable.h" 00037 00038 #include "Riostream.h" 00039 #include <iomanip> 00040 #include "TNamed.h" 00041 #include "TClass.h" 00042 00043 ClassImp(RooPrintable) 00044 ; 00045 00046 Int_t RooPrintable::_nameLength(0) ; 00047 00048 namespace RooFit { 00049 ostream& operator<<(ostream& os, const RooPrintable& rp) { 00050 // Implement ostream operator on RooPrintable in terms of printStream(InLine) 00051 rp.printStream(os,rp.defaultPrintContents("I"),RooPrintable::kInline) ; return os ; 00052 } 00053 } 00054 00055 00056 //_____________________________________________________________________________ 00057 void RooPrintable::nameFieldLength(Int_t newLen) 00058 { 00059 // Set length of field reserved from printing name of RooAbsArgs in 00060 // multi-line collection printing to given amount. 00061 _nameLength = newLen>0 ? newLen : 0 ; 00062 } 00063 00064 00065 00066 //_____________________________________________________________________________ 00067 void RooPrintable::printStream(ostream& os, Int_t contents, StyleOption style, TString indent) const 00068 { 00069 // Print description of object on ostream, printing contents set by contents integer, 00070 // which is interpreted as an OR of 'enum ContentsOptions' values and in the style 00071 // given by 'enum StyleOption'. Each message is prefixed by string 'indent' when printed 00072 00073 // Handling of 'verbose' and 'treestructure' is delegated to dedicated implementation functions 00074 if (style==kVerbose||style==kStandard) { 00075 printMultiline(os,contents,style==kVerbose,indent) ; 00076 return ; 00077 } else if (style==kTreeStructure) { 00078 printTree(os,indent) ; 00079 return ; 00080 } 00081 00082 // Handle here Inline and SingleLine styles 00083 if (style!=kInline) os << indent ; 00084 00085 // Print class name if requested 00086 if (contents&kAddress) { 00087 printAddress(os) ; 00088 if (contents!=kAddress) { 00089 os << " " ; 00090 } 00091 } 00092 00093 // Print class name if requested 00094 if (contents&kClassName) { 00095 printClassName(os) ; 00096 if (contents!=kClassName) { 00097 os << "::" ; 00098 } 00099 } 00100 00101 // Print object name if requested 00102 if (contents&kName) { 00103 if (_nameLength>0) { 00104 os << setw(_nameLength) ; 00105 } 00106 printName(os) ; 00107 } 00108 00109 // Print input argument structure from proxies if requested 00110 if (contents&kArgs) { 00111 printArgs(os) ; 00112 } 00113 00114 // Print value if requested 00115 if (contents&kValue) { 00116 if (contents&kName) { 00117 os << " = " ; 00118 } 00119 printValue(os) ; 00120 } 00121 00122 // Print extras if required 00123 if (contents&kExtras) { 00124 if (contents!=kExtras) { 00125 os << " " ; 00126 } 00127 printExtras(os) ; 00128 } 00129 00130 // Print title if required 00131 if (contents&kTitle) { 00132 if (contents==kTitle) { 00133 printTitle(os) ; 00134 } else { 00135 os << " \"" ; 00136 printTitle(os) ; 00137 os << "\"" ; 00138 } 00139 } 00140 00141 if (style!=kInline) os << endl ; 00142 00143 } 00144 00145 00146 // Virtual hook function for class-specific content implementation 00147 00148 //_____________________________________________________________________________ 00149 void RooPrintable::printValue(ostream& /*os*/) const 00150 { 00151 // Interface to print value of object 00152 } 00153 00154 00155 //_____________________________________________________________________________ 00156 void RooPrintable::printExtras(ostream& /*os*/) const 00157 { 00158 // Interface to print extras of object 00159 } 00160 00161 00162 //_____________________________________________________________________________ 00163 void RooPrintable::printMultiline(ostream& /*os*/, Int_t /*contents*/, Bool_t /*verbose*/, TString /*indent*/) const 00164 { 00165 // Interface for detailed printing of object 00166 } 00167 00168 00169 //_____________________________________________________________________________ 00170 void RooPrintable::printTree(ostream& /*os*/, TString /*indent*/) const 00171 { 00172 // Interface for tree structure printing of object 00173 cout << "Tree structure printing not implement for class " << IsA()->GetName() << endl ; 00174 } 00175 00176 00177 //_____________________________________________________________________________ 00178 void RooPrintable::printArgs(ostream& /*os*/) const 00179 { 00180 // Interface for printing of object arguments. Arguments 00181 // are loosely defined as external server objects 00182 // in this context 00183 } 00184 00185 00186 //_____________________________________________________________________________ 00187 void RooPrintable::printName(ostream& /*os*/) const 00188 { 00189 // Print name of object 00190 } 00191 00192 00193 //_____________________________________________________________________________ 00194 void RooPrintable::printTitle(ostream& /*os*/) const 00195 { 00196 // Print title of object 00197 } 00198 00199 00200 //_____________________________________________________________________________ 00201 void RooPrintable::printClassName(ostream& /*os*/) const 00202 { 00203 // Print class name of object 00204 } 00205 00206 00207 00208 //_____________________________________________________________________________ 00209 void RooPrintable::printAddress(ostream& os) const 00210 { 00211 // Print class name of object 00212 os << this ; 00213 } 00214 00215 00216 00217 //_____________________________________________________________________________ 00218 Int_t RooPrintable::defaultPrintContents(Option_t* /*opt*/) const 00219 { 00220 // Default choice of contents to be printed (name and value) 00221 return kName|kValue ; 00222 } 00223 00224 00225 //_____________________________________________________________________________ 00226 RooPrintable::StyleOption RooPrintable::defaultPrintStyle(Option_t* opt) const 00227 { 00228 if (!opt) { 00229 return kSingleLine ; 00230 } 00231 00232 TString o(opt) ; 00233 o.ToLower() ; 00234 00235 if (o.Contains("v")) { 00236 return kVerbose ; 00237 } else if (o.Contains("s")) { 00238 return kStandard ; 00239 } else if (o.Contains("i")) { 00240 return kInline ; 00241 } else if (o.Contains("t")) { 00242 return kTreeStructure ; 00243 } 00244 00245 return kSingleLine ; 00246 } 00247 00248 00249 00250 //_____________________________________________________________________________ 00251 ostream &RooPrintable::defaultPrintStream(ostream *os) 00252 { 00253 // Return a reference to the current default stream to use in 00254 // Print(). Use the optional parameter to specify a new default 00255 // stream (a reference to the old one is still returned). This 00256 // method allows subclasses to provide an inline implementation of 00257 // Print() without pulling in iostream.h. 00258 00259 static ostream *_defaultPrintStream = &cout; 00260 00261 ostream& _oldDefault= *_defaultPrintStream; 00262 if(0 != os) _defaultPrintStream= os; 00263 return _oldDefault; 00264 }