00001 /***************************************************************************** 00002 * Project: RooFit * 00003 * Package: RooFitCore * 00004 * @(#)root/roofitcore:$Id: RooTrace.cxx 36222 2010-10-09 18:27:06Z 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 // Class RooTrace controls the memory tracing hooks in all RooFit 00021 // objects. When tracing is active, a table of live RooFit objects 00022 // is kept that can be queried at any time. In verbose mode, messages 00023 // are printed in addition at the construction and destruction of 00024 // each object. 00025 // END_HTML 00026 // 00027 00028 #include "RooFit.h" 00029 00030 #include "RooTrace.h" 00031 #include "RooAbsArg.h" 00032 #include "Riostream.h" 00033 00034 #include <iomanip> 00035 00036 00037 00038 ClassImp(RooTrace) 00039 ; 00040 00041 00042 Bool_t RooTrace::_active(kFALSE) ; 00043 Bool_t RooTrace::_verbose(kFALSE) ; 00044 RooLinkedList RooTrace::_list ; 00045 RooLinkedList RooTrace::_markList ; 00046 00047 00048 00049 //_____________________________________________________________________________ 00050 void RooTrace::create(const TObject* obj) 00051 { 00052 // Register creation of object 'obj' 00053 00054 if (_active) create2(obj) ; 00055 } 00056 00057 00058 //_____________________________________________________________________________ 00059 void RooTrace::destroy(const TObject* obj) 00060 { 00061 // Register deletion of object 'obj' 00062 00063 if (_active) destroy2(obj) ; 00064 } 00065 00066 00067 //_____________________________________________________________________________ 00068 void RooTrace::active(Bool_t flag) 00069 { 00070 // If flag is true, memory tracing is activated 00071 00072 _active = flag ; 00073 } 00074 00075 00076 //_____________________________________________________________________________ 00077 void RooTrace::verbose(Bool_t flag) 00078 { 00079 // If flag is true, a message will be printed at each 00080 // object creation or deletion 00081 00082 _verbose = flag ; 00083 } 00084 00085 00086 00087 //_____________________________________________________________________________ 00088 void RooTrace::create2(const TObject* obj) 00089 { 00090 // Back end function of create(), register creation of object 'obj' 00091 00092 _list.Add((RooAbsArg*)obj) ; 00093 if (_verbose) { 00094 cout << "RooTrace::create: object " << obj << " of type " << obj->ClassName() 00095 << " created " << endl ; 00096 } 00097 } 00098 00099 00100 00101 00102 //_____________________________________________________________________________ 00103 void RooTrace::destroy2(const TObject* obj) 00104 { 00105 // Back end function of destroy(), register deletion of object 'obj' 00106 00107 if (!_list.Remove((RooAbsArg*)obj)) { 00108 } else if (_verbose) { 00109 cout << "RooTrace::destroy: object " << obj << " of type " << obj->ClassName() 00110 << " destroyed [" << obj->GetTitle() << "]" << endl ; 00111 } 00112 } 00113 00114 00115 00116 //_____________________________________________________________________________ 00117 void RooTrace::mark() 00118 { 00119 // Put marker in object list, that allows to dump contents of list 00120 // relative to this marker 00121 00122 _markList = _list ; 00123 } 00124 00125 00126 00127 //_____________________________________________________________________________ 00128 void RooTrace::dump() 00129 { 00130 // Dump contents of object registry to stdout 00131 dump(cout,kFALSE) ; 00132 } 00133 00134 00135 //_____________________________________________________________________________ 00136 void RooTrace::dump(ostream& os, Bool_t sinceMarked) 00137 { 00138 // Dump contents of object register to stream 'os'. If sinceMarked is 00139 // true, only object created after the last call to mark() are shown. 00140 00141 os << "List of RooFit objects allocated while trace active:" << endl ; 00142 00143 00144 Int_t i, nMarked(0) ; 00145 for(i=0 ; i<_list.GetSize() ; i++) { 00146 if (!sinceMarked || _markList.IndexOf(_list.At(i)) == -1) { 00147 os << hex << setw(10) << _list.At(i) << dec << " : " << setw(20) << _list.At(i)->ClassName() << setw(0) << " - " << _list.At(i)->GetName() << endl ; 00148 } else { 00149 nMarked++ ; 00150 } 00151 } 00152 if (sinceMarked) os << nMarked << " marked objects suppressed" << endl ; 00153 }