Logo ROOT  
Reference Guide
RooRefCountList.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 \file RooRefCountList.cxx
19 \class RooRefCountList
20 \ingroup Roofitcore
21 
22 A RooRefCountList is a RooLinkedList that keeps a reference counter
23 with each added node. Multiple Add()s of the same object will increase
24 the counter instead of adding multiple copies. Remove() decrements the
25 reference count until zero, when the object is actually removed.
26 **/
27 
28 #include "RooFit.h"
29 
30 #include "RooRefCountList.h"
31 
32 #include "Riostream.h"
33 #include <stdlib.h>
34 
35 using namespace std;
36 
38  ;
39 
40 
41 
42 ////////////////////////////////////////////////////////////////////////////////
43 /// Default constructor construct lists with initial hash table size of 17
44 
46  : RooLinkedList(0)
47 {
48 }
49 
50 
51 
52 ////////////////////////////////////////////////////////////////////////////////
53 /// Add object to list with given reference count increment
54 /// List takes ownership of object.
55 
57 {
58  // Check if we already have it
59  TObject* listObj = FindObject(obj) ;
60  if (!listObj) {
61  // Add to list with reference count
62  RooLinkedList::Add(obj, count) ;
63  //cout << "RooRefCountList::AddLast(" << obj << ") adding object" << endl ;
64  } else {
65  RooLinkedListElem* link = findLink(obj) ;
66  if(link) {
67  while(count--) link->incRefCount() ;
68  }
69  //cout << "RooRefCountList::AddLast(" << obj << ") incremented reference count to " << link->refCount() << endl ;
70  }
71 
72 }
73 
74 
75 
76 ////////////////////////////////////////////////////////////////////////////////
77 /// Remove object from list and if reference count
78 /// reaches zero delete object itself as well.
79 
81 {
82  RooLinkedListElem* link = findLink(obj) ;
83  if (!link) {
84  return 0 ;
85  } else {
86  if (link->decRefCount()==0) {
87  //cout << "RooRefCountList::AddLast(" << obj << ") removed object" << endl ;
88  return RooLinkedList::Remove(obj) ;
89  }
90  //cout << "RooRefCountList::AddLast(" << obj << ") decremented reference count to " << link->refCount() << endl ;
91  }
92  return 0 ;
93 }
94 
95 
96 
97 ////////////////////////////////////////////////////////////////////////////////
98 /// Remove object from list and delete object itself
99 /// regardless of reference count
100 
102 {
103  return RooLinkedList::Remove(obj) ;
104 }
105 
106 
107 
108 ////////////////////////////////////////////////////////////////////////////////
109 /// Return reference count associated with 'obj'
110 
112 {
113  RooLinkedListElem* link = findLink(obj) ;
114  if (!link) {
115  return 0 ;
116  } else {
117  return link->refCount() ;
118  }
119 }
RooRefCountList::Add
virtual void Add(TObject *arg)
Definition: RooRefCountList.h:40
RooFit.h
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
RooRefCountList::Remove
virtual Bool_t Remove(TObject *obj)
Remove object from list and if reference count reaches zero delete object itself as well.
Definition: RooRefCountList.cxx:80
RooLinkedList::FindObject
TObject * FindObject(const char *name) const
Return pointer to obejct with given name.
Definition: RooLinkedList.cxx:539
bool
RooLinkedListElem
Definition: RooLinkedListElem.h:30
RooLinkedListElem::decRefCount
Int_t decRefCount()
Definition: RooLinkedListElem.h:81
RooLinkedList
Definition: RooLinkedList.h:35
RooLinkedListElem::incRefCount
Int_t incRefCount()
Definition: RooLinkedListElem.h:80
RooLinkedList::Add
virtual void Add(TObject *arg)
Definition: RooLinkedList.h:62
RooRefCountList.h
RooRefCountList::RooRefCountList
RooRefCountList()
Default constructor construct lists with initial hash table size of 17.
Definition: RooRefCountList.cxx:45
TObject
Definition: TObject.h:37
RooRefCountList::RemoveAll
virtual Bool_t RemoveAll(TObject *obj)
Remove object from list and delete object itself regardless of reference count.
Definition: RooRefCountList.cxx:101
RooLinkedListElem::refCount
Int_t refCount() const
Definition: RooLinkedListElem.h:79
RooRefCountList::refCount
Int_t refCount(TObject *obj) const
Return reference count associated with 'obj'.
Definition: RooRefCountList.cxx:111
Riostream.h
RooLinkedList::findLink
RooLinkedListElem * findLink(const TObject *arg) const
Find the element link containing the given object.
Definition: RooLinkedList.cxx:391
RooLinkedList::Remove
virtual Bool_t Remove(TObject *arg)
Remove object from collection.
Definition: RooLinkedList.cxx:455
int
RooRefCountList
Definition: RooRefCountList.h:21