ROOT logo
/*****************************************************************************
 * Project: RooFit                                                           *
 * Package: RooFitCore                                                       *
 * @(#)root/roofitcore:$Id: RooPrintable.cxx 25184 2008-08-20 13:59:55Z wouter $
 * Authors:                                                                  *
 *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
 *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
 *                                                                           *
 * Copyright (c) 2000-2005, Regents of the University of California          *
 *                          and Stanford University. All rights reserved.    *
 *                                                                           *
 * Redistribution and use in source and binary forms,                        *
 * with or without modification, are permitted according to the terms        *
 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
 *****************************************************************************/

//////////////////////////////////////////////////////////////////////////////
//
// BEGIN_HTML
// RooPlotable is a 'mix-in' base class that define the standard RooFit plotting and
// printing methods. Each RooPlotable implementation must define methods that
// print the objects name, class name, title, value, arguments and extras
// to a provided stream. The definition of value is class dependent. The definition
// of arguments is also class dependent, but should always be interpreted as
// the names (and properties) of any (RooAbsArg) external inputs of a given object.
// The extras method can be used to print any properties that does not fit in any
// of the other classes. Each object an also override the definitions made
// in defaultPrintStyle and defaultPrintContents to determine what is printed
// (in terms of contents) and how it is printed (inline,single-line or multiline)
// given a Print() option string. 
// END_HTML
//

#include "RooFit.h"

#include "RooPrintable.h"

#include "Riostream.h"
#include <iomanip>
#include "TNamed.h"
#include "TClass.h"

ClassImp(RooPrintable)
;

Int_t  RooPrintable::_nameLength(0) ;

namespace RooFit {
  ostream& operator<<(ostream& os, const RooPrintable& rp) { 
    // Implement ostream operator on RooPrintable in terms of printStream(InLine)  
    rp.printStream(os,rp.defaultPrintContents("I"),RooPrintable::kInline) ; return os ; 
  }
}


//_____________________________________________________________________________
void RooPrintable::nameFieldLength(Int_t newLen)
{
  // Set length of field reserved from printing name of RooAbsArgs in 
  // multi-line collection printing to given amount. 
  _nameLength = newLen>0 ? newLen : 0 ;
}



//_____________________________________________________________________________
void RooPrintable::printStream(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 'enum ContentsOptions' values and in the style
  // given by 'enum StyleOption'. Each message is prefixed by string 'indent' when printed

  // Handling of 'verbose' and 'treestructure' is delegated to dedicated implementation functions
  if (style==kVerbose||style==kStandard) {
    printMultiline(os,contents,style==kVerbose,indent) ;
    return ;
  } else if (style==kTreeStructure) {
    printTree(os,indent) ;
    return ;
  }

  // Handle here Inline and SingleLine styles
  if (style!=kInline) os << indent ;

  // Print class name if requested
  if (contents&kAddress) {
    printAddress(os) ;
    if (contents!=kAddress) {
      os << " " ;
    }
  }

  // Print class name if requested
  if (contents&kClassName) {
    printClassName(os) ;
    if (contents!=kClassName) {
      os << "::" ;
    }
  }

  // Print object name if requested
  if (contents&kName) {
    if (_nameLength>0) {
      os << setw(_nameLength) ;
    }
    printName(os) ;
  }

  // Print input argument structure from proxies if requested
  if (contents&kArgs) {
    printArgs(os) ;
  }
  
  // Print value if requested
  if (contents&kValue) {
    if (contents&kName) {
      os << " = " ;
    }
    printValue(os) ;
  }

  // Print extras if required
  if (contents&kExtras) {
    if (contents!=kExtras) {
      os << " " ;
    }
    printExtras(os) ;
  }

  // Print title if required
  if (contents&kTitle) {
    if (contents==kTitle) {
      printTitle(os) ;
    } else {
      os << " \"" ;
      printTitle(os) ;
      os << "\"" ;
    }
  }

  if (style!=kInline) os << endl ;
  
}


// Virtual hook function for class-specific content implementation

//_____________________________________________________________________________
void RooPrintable::printValue(ostream& /*os*/) const
{
  // Interface to print value of object
}


//_____________________________________________________________________________
void RooPrintable::printExtras(ostream& /*os*/) const
{
  // Interface to print extras of object
}


//_____________________________________________________________________________
void RooPrintable::printMultiline(ostream& /*os*/, Int_t /*contents*/, Bool_t /*verbose*/, TString /*indent*/) const
{
  // Interface for detailed printing of object
}


//_____________________________________________________________________________
void RooPrintable::printTree(ostream& /*os*/, TString /*indent*/) const
{
  // Interface for tree structure printing of object
  cout << "Tree structure printing not implement for class " << IsA()->GetName() << endl ;
}


//_____________________________________________________________________________
void RooPrintable::printArgs(ostream& /*os*/) const 
{
  // Interface for printing of object arguments. Arguments
  // are loosely defined as external server objects
  // in this context
}


//_____________________________________________________________________________
void RooPrintable::printName(ostream& /*os*/) const 
{
  // Print name of object
}


//_____________________________________________________________________________
void RooPrintable::printTitle(ostream& /*os*/) const 
{
  // Print title of object
}


//_____________________________________________________________________________
void RooPrintable::printClassName(ostream& /*os*/) const 
{
  // Print class name of object
}



//_____________________________________________________________________________
void RooPrintable::printAddress(ostream& os) const 
{
  // Print class name of object
  os << this ;
}



//_____________________________________________________________________________
Int_t RooPrintable::defaultPrintContents(Option_t* /*opt*/) const
{ 
  // Default choice of contents to be printed (name and value)
  return kName|kValue ; 
}


//_____________________________________________________________________________
RooPrintable::StyleOption RooPrintable::defaultPrintStyle(Option_t* opt) const
{ 
  if (!opt) {
    return kSingleLine ;
  }

  TString o(opt) ;
  o.ToLower() ;

  if (o.Contains("v")) {
    return kVerbose ;
  } else if (o.Contains("s")) {
    return kStandard ;
  } else if (o.Contains("i")) {
    return kInline ;
  } else if (o.Contains("t")) {
    return kTreeStructure ;
  }

  return kSingleLine ;
}



//_____________________________________________________________________________
ostream &RooPrintable::defaultPrintStream(ostream *os) 
{
  // Return a reference to the current default stream to use in
  // Print(). Use the optional parameter to specify a new default
  // stream (a reference to the old one is still returned). This
  // method allows subclasses to provide an inline implementation of
  // Print() without pulling in iostream.h.

  static ostream *_defaultPrintStream = &cout;

  ostream& _oldDefault= *_defaultPrintStream;
  if(0 != os) _defaultPrintStream= os;
  return _oldDefault;
}
 RooPrintable.cxx:1
 RooPrintable.cxx:2
 RooPrintable.cxx:3
 RooPrintable.cxx:4
 RooPrintable.cxx:5
 RooPrintable.cxx:6
 RooPrintable.cxx:7
 RooPrintable.cxx:8
 RooPrintable.cxx:9
 RooPrintable.cxx:10
 RooPrintable.cxx:11
 RooPrintable.cxx:12
 RooPrintable.cxx:13
 RooPrintable.cxx:14
 RooPrintable.cxx:15
 RooPrintable.cxx:16
 RooPrintable.cxx:17
 RooPrintable.cxx:18
 RooPrintable.cxx:19
 RooPrintable.cxx:20
 RooPrintable.cxx:21
 RooPrintable.cxx:22
 RooPrintable.cxx:23
 RooPrintable.cxx:24
 RooPrintable.cxx:25
 RooPrintable.cxx:26
 RooPrintable.cxx:27
 RooPrintable.cxx:28
 RooPrintable.cxx:29
 RooPrintable.cxx:30
 RooPrintable.cxx:31
 RooPrintable.cxx:32
 RooPrintable.cxx:33
 RooPrintable.cxx:34
 RooPrintable.cxx:35
 RooPrintable.cxx:36
 RooPrintable.cxx:37
 RooPrintable.cxx:38
 RooPrintable.cxx:39
 RooPrintable.cxx:40
 RooPrintable.cxx:41
 RooPrintable.cxx:42
 RooPrintable.cxx:43
 RooPrintable.cxx:44
 RooPrintable.cxx:45
 RooPrintable.cxx:46
 RooPrintable.cxx:47
 RooPrintable.cxx:48
 RooPrintable.cxx:49
 RooPrintable.cxx:50
 RooPrintable.cxx:51
 RooPrintable.cxx:52
 RooPrintable.cxx:53
 RooPrintable.cxx:54
 RooPrintable.cxx:55
 RooPrintable.cxx:56
 RooPrintable.cxx:57
 RooPrintable.cxx:58
 RooPrintable.cxx:59
 RooPrintable.cxx:60
 RooPrintable.cxx:61
 RooPrintable.cxx:62
 RooPrintable.cxx:63
 RooPrintable.cxx:64
 RooPrintable.cxx:65
 RooPrintable.cxx:66
 RooPrintable.cxx:67
 RooPrintable.cxx:68
 RooPrintable.cxx:69
 RooPrintable.cxx:70
 RooPrintable.cxx:71
 RooPrintable.cxx:72
 RooPrintable.cxx:73
 RooPrintable.cxx:74
 RooPrintable.cxx:75
 RooPrintable.cxx:76
 RooPrintable.cxx:77
 RooPrintable.cxx:78
 RooPrintable.cxx:79
 RooPrintable.cxx:80
 RooPrintable.cxx:81
 RooPrintable.cxx:82
 RooPrintable.cxx:83
 RooPrintable.cxx:84
 RooPrintable.cxx:85
 RooPrintable.cxx:86
 RooPrintable.cxx:87
 RooPrintable.cxx:88
 RooPrintable.cxx:89
 RooPrintable.cxx:90
 RooPrintable.cxx:91
 RooPrintable.cxx:92
 RooPrintable.cxx:93
 RooPrintable.cxx:94
 RooPrintable.cxx:95
 RooPrintable.cxx:96
 RooPrintable.cxx:97
 RooPrintable.cxx:98
 RooPrintable.cxx:99
 RooPrintable.cxx:100
 RooPrintable.cxx:101
 RooPrintable.cxx:102
 RooPrintable.cxx:103
 RooPrintable.cxx:104
 RooPrintable.cxx:105
 RooPrintable.cxx:106
 RooPrintable.cxx:107
 RooPrintable.cxx:108
 RooPrintable.cxx:109
 RooPrintable.cxx:110
 RooPrintable.cxx:111
 RooPrintable.cxx:112
 RooPrintable.cxx:113
 RooPrintable.cxx:114
 RooPrintable.cxx:115
 RooPrintable.cxx:116
 RooPrintable.cxx:117
 RooPrintable.cxx:118
 RooPrintable.cxx:119
 RooPrintable.cxx:120
 RooPrintable.cxx:121
 RooPrintable.cxx:122
 RooPrintable.cxx:123
 RooPrintable.cxx:124
 RooPrintable.cxx:125
 RooPrintable.cxx:126
 RooPrintable.cxx:127
 RooPrintable.cxx:128
 RooPrintable.cxx:129
 RooPrintable.cxx:130
 RooPrintable.cxx:131
 RooPrintable.cxx:132
 RooPrintable.cxx:133
 RooPrintable.cxx:134
 RooPrintable.cxx:135
 RooPrintable.cxx:136
 RooPrintable.cxx:137
 RooPrintable.cxx:138
 RooPrintable.cxx:139
 RooPrintable.cxx:140
 RooPrintable.cxx:141
 RooPrintable.cxx:142
 RooPrintable.cxx:143
 RooPrintable.cxx:144
 RooPrintable.cxx:145
 RooPrintable.cxx:146
 RooPrintable.cxx:147
 RooPrintable.cxx:148
 RooPrintable.cxx:149
 RooPrintable.cxx:150
 RooPrintable.cxx:151
 RooPrintable.cxx:152
 RooPrintable.cxx:153
 RooPrintable.cxx:154
 RooPrintable.cxx:155
 RooPrintable.cxx:156
 RooPrintable.cxx:157
 RooPrintable.cxx:158
 RooPrintable.cxx:159
 RooPrintable.cxx:160
 RooPrintable.cxx:161
 RooPrintable.cxx:162
 RooPrintable.cxx:163
 RooPrintable.cxx:164
 RooPrintable.cxx:165
 RooPrintable.cxx:166
 RooPrintable.cxx:167
 RooPrintable.cxx:168
 RooPrintable.cxx:169
 RooPrintable.cxx:170
 RooPrintable.cxx:171
 RooPrintable.cxx:172
 RooPrintable.cxx:173
 RooPrintable.cxx:174
 RooPrintable.cxx:175
 RooPrintable.cxx:176
 RooPrintable.cxx:177
 RooPrintable.cxx:178
 RooPrintable.cxx:179
 RooPrintable.cxx:180
 RooPrintable.cxx:181
 RooPrintable.cxx:182
 RooPrintable.cxx:183
 RooPrintable.cxx:184
 RooPrintable.cxx:185
 RooPrintable.cxx:186
 RooPrintable.cxx:187
 RooPrintable.cxx:188
 RooPrintable.cxx:189
 RooPrintable.cxx:190
 RooPrintable.cxx:191
 RooPrintable.cxx:192
 RooPrintable.cxx:193
 RooPrintable.cxx:194
 RooPrintable.cxx:195
 RooPrintable.cxx:196
 RooPrintable.cxx:197
 RooPrintable.cxx:198
 RooPrintable.cxx:199
 RooPrintable.cxx:200
 RooPrintable.cxx:201
 RooPrintable.cxx:202
 RooPrintable.cxx:203
 RooPrintable.cxx:204
 RooPrintable.cxx:205
 RooPrintable.cxx:206
 RooPrintable.cxx:207
 RooPrintable.cxx:208
 RooPrintable.cxx:209
 RooPrintable.cxx:210
 RooPrintable.cxx:211
 RooPrintable.cxx:212
 RooPrintable.cxx:213
 RooPrintable.cxx:214
 RooPrintable.cxx:215
 RooPrintable.cxx:216
 RooPrintable.cxx:217
 RooPrintable.cxx:218
 RooPrintable.cxx:219
 RooPrintable.cxx:220
 RooPrintable.cxx:221
 RooPrintable.cxx:222
 RooPrintable.cxx:223
 RooPrintable.cxx:224
 RooPrintable.cxx:225
 RooPrintable.cxx:226
 RooPrintable.cxx:227
 RooPrintable.cxx:228
 RooPrintable.cxx:229
 RooPrintable.cxx:230
 RooPrintable.cxx:231
 RooPrintable.cxx:232
 RooPrintable.cxx:233
 RooPrintable.cxx:234
 RooPrintable.cxx:235
 RooPrintable.cxx:236
 RooPrintable.cxx:237
 RooPrintable.cxx:238
 RooPrintable.cxx:239
 RooPrintable.cxx:240
 RooPrintable.cxx:241
 RooPrintable.cxx:242
 RooPrintable.cxx:243
 RooPrintable.cxx:244
 RooPrintable.cxx:245
 RooPrintable.cxx:246
 RooPrintable.cxx:247
 RooPrintable.cxx:248
 RooPrintable.cxx:249
 RooPrintable.cxx:250
 RooPrintable.cxx:251
 RooPrintable.cxx:252
 RooPrintable.cxx:253
 RooPrintable.cxx:254
 RooPrintable.cxx:255
 RooPrintable.cxx:256
 RooPrintable.cxx:257
 RooPrintable.cxx:258
 RooPrintable.cxx:259
 RooPrintable.cxx:260
 RooPrintable.cxx:261
 RooPrintable.cxx:262
 RooPrintable.cxx:263
 RooPrintable.cxx:264