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