Logo ROOT   6.18/05
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
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 "RooFit.h"
29
30#include "RooRefCountList.h"
31#include "RooRefCountList.h"
32
33#include "Riostream.h"
34#include <stdlib.h>
35
36using namespace std;
37
39 ;
40
41
42
43////////////////////////////////////////////////////////////////////////////////
44/// Default constructor construct lists with initial hash table size of 17
45
47 : RooLinkedList(0)
48{
49}
50
51
52
53////////////////////////////////////////////////////////////////////////////////
54/// Add object to list with given reference count increment
55/// List takes ownership of object.
56
58{
59 // Check if we already have it
60 TObject* listObj = FindObject(obj) ;
61 if (!listObj) {
62 // Add to list with reference count
63 RooLinkedList::Add(obj, count) ;
64 //cout << "RooRefCountList::AddLast(" << obj << ") adding object" << endl ;
65 } else {
66 RooLinkedListElem* link = findLink(obj) ;
67 if(link) {
68 while(count--) link->incRefCount() ;
69 }
70 //cout << "RooRefCountList::AddLast(" << obj << ") incremented reference count to " << link->refCount() << endl ;
71 }
72
73}
74
75
76
77////////////////////////////////////////////////////////////////////////////////
78/// Remove object from list and if reference count
79/// reaches zero delete object itself as well.
80
82{
83 RooLinkedListElem* link = findLink(obj) ;
84 if (!link) {
85 return 0 ;
86 } else {
87 if (link->decRefCount()==0) {
88 //cout << "RooRefCountList::AddLast(" << obj << ") removed object" << endl ;
89 return RooLinkedList::Remove(obj) ;
90 }
91 //cout << "RooRefCountList::AddLast(" << obj << ") decremented reference count to " << link->refCount() << endl ;
92 }
93 return 0 ;
94}
95
96
97
98////////////////////////////////////////////////////////////////////////////////
99/// Remove object from list and delete object itself
100/// regardless of reference count
101
103{
104 return RooLinkedList::Remove(obj) ;
105}
106
107
108
109////////////////////////////////////////////////////////////////////////////////
110/// Return reference count associated with 'obj'
111
113{
114 RooLinkedListElem* link = findLink(obj) ;
115 if (!link) {
116 return 0 ;
117 } else {
118 return link->refCount() ;
119 }
120}
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
#define ClassImp(name)
Definition: Rtypes.h:365
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 ...
Definition: RooLinkedList.h:36
TObject * FindObject(const char *name) const
Return pointer to obejct with given name.
RooLinkedListElem * findLink(const TObject *arg) const
Find the element link containing the given object.
virtual void Add(TObject *arg)
Definition: RooLinkedList.h:63
virtual Bool_t 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.
virtual void Add(TObject *arg)
virtual Bool_t RemoveAll(TObject *obj)
Remove object from list and delete object itself regardless of reference count.
virtual Bool_t Remove(TObject *obj)
Remove object from list and if reference count reaches zero delete object itself as well.
Mother of all ROOT objects.
Definition: TObject.h:37