Logo ROOT   6.16/01
Reference Guide
RooSharedPropertiesList.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 RooSharedPropertiesList.cxx
19\class RooSharedPropertiesList
20\ingroup Roofitcore
21
22Class RooSharedPropertiesList maintains the properties of RooRealVars
23and RooCategories that are clones of each other.
24**/
25
26#include "RooFit.h"
28#include "RooSharedProperties.h"
29#include "RooLinkedListIter.h"
30#include "TIterator.h"
31#include "RooMsgService.h"
32#include "Riostream.h"
33using std::cout ;
34using std::endl ;
35
36using namespace std;
37
39;
40
41
42
43////////////////////////////////////////////////////////////////////////////////
44/// Constructor
45
47{
49}
50
51
52
53////////////////////////////////////////////////////////////////////////////////
54/// Destructor
55
57{
58 // Delete all objects in property list
61 while((prop=(RooSharedProperties*)iter.next())) {
62 delete prop ;
63 }
64}
65
66
67
68////////////////////////////////////////////////////////////////////////////////
69/// Register property into list and take ownership.
70///
71/// If an existing entry has a UUID that identical to that of the argument prop,
72/// the argument prop is deleted and a pointer to the already stored is returned to
73/// eliminate the duplication of instances with a unique identity.
74///
75/// The caller should therefore not refer anymore to the input argument pointer as
76/// as the object cannot be assumed to be live.
77
79{
80 if (prop==0) {
81 oocoutE((TObject*)0,InputArguments) << "RooSharedPropertiesList::ERROR null pointer!:" << endl ;
82 return 0 ;
83 }
84
85
86 // If the reference count is non-zero, it is already in the list, so no need
87 // to look it up anymore
88 if (prop->inSharedList()) {
89 prop->increaseRefCount() ;
90 return prop ;
91 }
92
93 //std::cout << "REGISTER properties " << prop->asString() << " - list size = " << _propList.GetSize() << std::endl;
95
96 std::map<std::string, RooSharedProperties *>::iterator it;
97
98 it = _newPropList.find(prop->asString().Data());
99 if (it != _newPropList.end() ) {
100 tmp = it->second;
101 if (tmp != prop) {
102 // found another instance with same UUID
103 if (canDeleteIncoming) delete prop;
104 }
105 tmp->increaseRefCount();
106 return tmp;
107 }
108 prop->setInSharedList() ;
109 prop->increaseRefCount() ;
110 _newPropList[prop->asString().Data()] = prop;
111
112 return prop ;
113}
114
115
116
117////////////////////////////////////////////////////////////////////////////////
118/// Decrease reference count of property. If reference count is at zero,
119/// delete the propery
120
122{
123 prop->decreaseRefCount() ;
124
125 if (prop->refCount()==0) {
126 _propList.Remove(prop) ;
127
128 std::map<std::string, RooSharedProperties *>::iterator it;
129 it = _newPropList.find(prop->asString().Data());
130 if (it != _newPropList.end() ) _newPropList.erase(it);
131
132 // We own object if ref-counted list. If count drops to zero, delete object
133 delete prop ;
134 }
135
136}
137
138
#define oocoutE(o, a)
Definition: RooMsgService.h:47
bool Bool_t
Definition: RtypesCore.h:59
#define ClassImp(name)
Definition: Rtypes.h:363
RooAbsArg * next()
RooFIter fwdIterator() const
void setHashTableSize(Int_t size)
Change the threshold for hash-table use to given size.
virtual Bool_t Remove(TObject *obj)
Remove object from list and if reference count reaches zero delete object itself as well.
Class RooSharedPropertiesList maintains the properties of RooRealVars and RooCategories that are clon...
std::map< std::string, RooSharedProperties * > _newPropList
void unregisterProperties(RooSharedProperties *)
Decrease reference count of property.
virtual ~RooSharedPropertiesList()
Destructor.
RooSharedProperties * registerProperties(RooSharedProperties *, Bool_t canDeleteIncoming=kTRUE)
Register property into list and take ownership.
Class RooSharedProperties is the base class for shared properties that can be stored in RooSharedProp...
Bool_t inSharedList() const
Mother of all ROOT objects.
Definition: TObject.h:37
@ InputArguments
Definition: RooGlobalFunc.h:58
STL namespace.