ROOT logo
/*****************************************************************************
 * Project: RooFit                                                           *
 * Package: RooFitCore                                                       *
 * @(#)root/roofitcore:$Id: RooTrace.cxx 41676 2011-11-01 15:44:30Z 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
// Class RooTrace controls the memory tracing hooks in all RooFit
// objects. When tracing is active, a table of live RooFit objects
// is kept that can be queried at any time. In verbose mode, messages
// are printed in addition at the construction and destruction of
// each object.
// END_HTML
//

#include "RooFit.h"

#include "RooTrace.h"
#include "RooAbsArg.h"
#include "Riostream.h"
#include "RooMsgService.h"

#include <iomanip>



ClassImp(RooTrace)
;


Bool_t RooTrace::_active(kFALSE) ;
Bool_t RooTrace::_verbose(kFALSE) ;
RooLinkedList RooTrace::_list ;
RooLinkedList RooTrace::_markList ;



//_____________________________________________________________________________
void RooTrace::create(const TObject* obj) 
{ 
  // Register creation of object 'obj' 

  if (_active) create2(obj) ; 
}


//_____________________________________________________________________________
void RooTrace::destroy(const TObject* obj) 
{ 
  // Register deletion of object 'obj'

  if (_active) destroy2(obj) ; 
}


//_____________________________________________________________________________
void RooTrace::active(Bool_t flag) 
{ 
  // If flag is true, memory tracing is activated

  _active = flag ; 
}


//_____________________________________________________________________________
void RooTrace::verbose(Bool_t flag) 
{ 
  // If flag is true, a message will be printed at each
  // object creation or deletion

  _verbose = flag ; 
}



//_____________________________________________________________________________
void RooTrace::create2(const TObject* obj) 
{
  // Back end function of create(), register creation of object 'obj' 
  
  _list.Add((RooAbsArg*)obj) ;
  if (_verbose) {
    cout << "RooTrace::create: object " << obj << " of type " << obj->ClassName() 
	 << " created " << endl ;
  }
}


  

//_____________________________________________________________________________
void RooTrace::destroy2(const TObject* obj) 
{
  // Back end function of destroy(), register deletion of object 'obj' 

  if (!_list.Remove((RooAbsArg*)obj)) {
  } else if (_verbose) {
    cout << "RooTrace::destroy: object " << obj << " of type " << obj->ClassName() 
	 << " destroyed [" << obj->GetTitle() << "]" << endl ;
  }
}



//_____________________________________________________________________________
void RooTrace::mark()
{
  // Put marker in object list, that allows to dump contents of list
  // relative to this marker

  _markList = _list ;
}



//_____________________________________________________________________________
void RooTrace::dump() 
{
  // Dump contents of object registry to stdout
  dump(cout,kFALSE) ;
}


//_____________________________________________________________________________
void RooTrace::dump(ostream& os, Bool_t sinceMarked) 
{
  // Dump contents of object register to stream 'os'. If sinceMarked is
  // true, only object created after the last call to mark() are shown.

  os << "List of RooFit objects allocated while trace active:" << endl ;


  Int_t i, nMarked(0) ;
  for(i=0 ; i<_list.GetSize() ; i++) {
    if (!sinceMarked || _markList.IndexOf(_list.At(i)) == -1) {
      os << hex << setw(10) << _list.At(i) << dec << " : " << setw(20) << _list.At(i)->ClassName() << setw(0) << " - " << _list.At(i)->GetName() << endl ;
    } else {
      nMarked++ ;
    }
  }
  if (sinceMarked) os << nMarked << " marked objects suppressed" << endl ;
}



//_____________________________________________________________________________
void RooTrace::callgrind_zero() 
{
  // Utility function to trigger zeroing of callgrind counters.
  //
  // Note that this function does _not_ do anything, other than optionally printing this message
  // To trigger callgrind zero counter action, run callgrind with 
  // argument '--zero-before=RooTrace::callgrind_zero()' (include single quotes in cmdline)
  
  oocoutP((TObject*)0,Tracing) << "RooTrace::callgrind_zero()" << endl ;
}

//_____________________________________________________________________________
void RooTrace::callgrind_dump() 
{
  // Utility function to trigger dumping of callgrind counters.
  //
  // Note that this function does _not_ do anything, other than optionally printing this message
  // To trigger callgrind dumping action, run callgrind with 
  // argument '--dump-before=RooTrace::callgrind_dump()' (include single quotes in cmdline)

  oocoutP((TObject*)0,Tracing) << "RooTrace::callgrind_dump()" << endl ;
}
 RooTrace.cxx:1
 RooTrace.cxx:2
 RooTrace.cxx:3
 RooTrace.cxx:4
 RooTrace.cxx:5
 RooTrace.cxx:6
 RooTrace.cxx:7
 RooTrace.cxx:8
 RooTrace.cxx:9
 RooTrace.cxx:10
 RooTrace.cxx:11
 RooTrace.cxx:12
 RooTrace.cxx:13
 RooTrace.cxx:14
 RooTrace.cxx:15
 RooTrace.cxx:16
 RooTrace.cxx:17
 RooTrace.cxx:18
 RooTrace.cxx:19
 RooTrace.cxx:20
 RooTrace.cxx:21
 RooTrace.cxx:22
 RooTrace.cxx:23
 RooTrace.cxx:24
 RooTrace.cxx:25
 RooTrace.cxx:26
 RooTrace.cxx:27
 RooTrace.cxx:28
 RooTrace.cxx:29
 RooTrace.cxx:30
 RooTrace.cxx:31
 RooTrace.cxx:32
 RooTrace.cxx:33
 RooTrace.cxx:34
 RooTrace.cxx:35
 RooTrace.cxx:36
 RooTrace.cxx:37
 RooTrace.cxx:38
 RooTrace.cxx:39
 RooTrace.cxx:40
 RooTrace.cxx:41
 RooTrace.cxx:42
 RooTrace.cxx:43
 RooTrace.cxx:44
 RooTrace.cxx:45
 RooTrace.cxx:46
 RooTrace.cxx:47
 RooTrace.cxx:48
 RooTrace.cxx:49
 RooTrace.cxx:50
 RooTrace.cxx:51
 RooTrace.cxx:52
 RooTrace.cxx:53
 RooTrace.cxx:54
 RooTrace.cxx:55
 RooTrace.cxx:56
 RooTrace.cxx:57
 RooTrace.cxx:58
 RooTrace.cxx:59
 RooTrace.cxx:60
 RooTrace.cxx:61
 RooTrace.cxx:62
 RooTrace.cxx:63
 RooTrace.cxx:64
 RooTrace.cxx:65
 RooTrace.cxx:66
 RooTrace.cxx:67
 RooTrace.cxx:68
 RooTrace.cxx:69
 RooTrace.cxx:70
 RooTrace.cxx:71
 RooTrace.cxx:72
 RooTrace.cxx:73
 RooTrace.cxx:74
 RooTrace.cxx:75
 RooTrace.cxx:76
 RooTrace.cxx:77
 RooTrace.cxx:78
 RooTrace.cxx:79
 RooTrace.cxx:80
 RooTrace.cxx:81
 RooTrace.cxx:82
 RooTrace.cxx:83
 RooTrace.cxx:84
 RooTrace.cxx:85
 RooTrace.cxx:86
 RooTrace.cxx:87
 RooTrace.cxx:88
 RooTrace.cxx:89
 RooTrace.cxx:90
 RooTrace.cxx:91
 RooTrace.cxx:92
 RooTrace.cxx:93
 RooTrace.cxx:94
 RooTrace.cxx:95
 RooTrace.cxx:96
 RooTrace.cxx:97
 RooTrace.cxx:98
 RooTrace.cxx:99
 RooTrace.cxx:100
 RooTrace.cxx:101
 RooTrace.cxx:102
 RooTrace.cxx:103
 RooTrace.cxx:104
 RooTrace.cxx:105
 RooTrace.cxx:106
 RooTrace.cxx:107
 RooTrace.cxx:108
 RooTrace.cxx:109
 RooTrace.cxx:110
 RooTrace.cxx:111
 RooTrace.cxx:112
 RooTrace.cxx:113
 RooTrace.cxx:114
 RooTrace.cxx:115
 RooTrace.cxx:116
 RooTrace.cxx:117
 RooTrace.cxx:118
 RooTrace.cxx:119
 RooTrace.cxx:120
 RooTrace.cxx:121
 RooTrace.cxx:122
 RooTrace.cxx:123
 RooTrace.cxx:124
 RooTrace.cxx:125
 RooTrace.cxx:126
 RooTrace.cxx:127
 RooTrace.cxx:128
 RooTrace.cxx:129
 RooTrace.cxx:130
 RooTrace.cxx:131
 RooTrace.cxx:132
 RooTrace.cxx:133
 RooTrace.cxx:134
 RooTrace.cxx:135
 RooTrace.cxx:136
 RooTrace.cxx:137
 RooTrace.cxx:138
 RooTrace.cxx:139
 RooTrace.cxx:140
 RooTrace.cxx:141
 RooTrace.cxx:142
 RooTrace.cxx:143
 RooTrace.cxx:144
 RooTrace.cxx:145
 RooTrace.cxx:146
 RooTrace.cxx:147
 RooTrace.cxx:148
 RooTrace.cxx:149
 RooTrace.cxx:150
 RooTrace.cxx:151
 RooTrace.cxx:152
 RooTrace.cxx:153
 RooTrace.cxx:154
 RooTrace.cxx:155
 RooTrace.cxx:156
 RooTrace.cxx:157
 RooTrace.cxx:158
 RooTrace.cxx:159
 RooTrace.cxx:160
 RooTrace.cxx:161
 RooTrace.cxx:162
 RooTrace.cxx:163
 RooTrace.cxx:164
 RooTrace.cxx:165
 RooTrace.cxx:166
 RooTrace.cxx:167
 RooTrace.cxx:168
 RooTrace.cxx:169
 RooTrace.cxx:170
 RooTrace.cxx:171
 RooTrace.cxx:172
 RooTrace.cxx:173
 RooTrace.cxx:174
 RooTrace.cxx:175
 RooTrace.cxx:176
 RooTrace.cxx:177
 RooTrace.cxx:178
 RooTrace.cxx:179
 RooTrace.cxx:180