Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooAICRegistry.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 RooAICRegistry.cxx
19\class RooAICRegistry
20\ingroup Roofitcore
21
22RooAICRegistry is a utility class for operator p.d.f
23classes that keeps track of analytical integration codes and
24associated normalization and integration sets.
25**/
26
27#include "RooAICRegistry.h"
28#include "RooMsgService.h"
29#include "RooArgSet.h"
30
31#include "Riostream.h"
32
33
34using namespace std;
35
37
38namespace {
39
40RooArgSet * makeSnapshot(RooArgSet const* set) {
41 if(!set) {
42 return nullptr;
43 }
44 auto out = new RooArgSet;
45 set->snapshot(*out, false);
46 return out;
47}
48
49}
50
51////////////////////////////////////////////////////////////////////////////////
52
54 : _clArr(0), _asArr1(0), _asArr2(0), _asArr3(0), _asArr4(0)
55{
56 _clArr.reserve(size);
57 _asArr1.reserve(size);
58 _asArr2.reserve(size);
59 _asArr3.reserve(size);
60 _asArr4.reserve(size);
61}
62
63////////////////////////////////////////////////////////////////////////////////
64/// Copy constructor
65
67 : _clArr(other._clArr), _asArr1(other._clArr.size(), nullptr), _asArr2(other._clArr.size(), nullptr),
68 _asArr3(other._clArr.size(), nullptr), _asArr4(other._clArr.size(), nullptr)
69{
70 // Copy code-list array if other PDF has one
71 UInt_t size = other._clArr.size();
72 if (size) {
73 _asArr1.resize(size, nullptr);
74 _asArr2.resize(size, nullptr);
75 _asArr3.resize(size, nullptr);
76 _asArr4.resize(size, nullptr);
77 for(UInt_t i = 0; i < size; ++i) {
78 _asArr1[i] = makeSnapshot(other._asArr1[i]);
79 _asArr2[i] = makeSnapshot(other._asArr2[i]);
80 _asArr3[i] = makeSnapshot(other._asArr3[i]);
81 _asArr4[i] = makeSnapshot(other._asArr4[i]);
82 }
83 }
84}
85
86////////////////////////////////////////////////////////////////////////////////
87/// Destructor
88
90{
91 // Delete code list array, if allocated
92 for (unsigned int i = 0; i < _clArr.size(); ++i) {
93 if (_asArr1[i]) delete _asArr1[i];
94 if (_asArr2[i]) delete _asArr2[i];
95 if (_asArr3[i]) delete _asArr3[i];
96 if (_asArr4[i]) delete _asArr4[i];
97 }
98}
99
100////////////////////////////////////////////////////////////////////////////////
101/// Store given arrays of integer codes, and up to four RooArgSets in
102/// the registry (each setX pointer may be null). The registry
103/// clones all RooArgSets internally so the RooArgSets passed as
104/// arguments do not need to live beyond the store() call. The return
105/// value is a unique master code for the given configuration of
106/// integers and RooArgSets. If an identical combination is
107/// previously stored in the registry no objects are stored and the
108/// unique code of the existing entry is returned.
109
110Int_t RooAICRegistry::store(const std::vector<Int_t>& codeList, RooArgSet* set1,
111 RooArgSet* set2, RooArgSet* set3, RooArgSet* set4)
112{
113 // Loop over code-list array
114 for (UInt_t i = 0; i < _clArr.size(); ++i) {
115 // Existing slot, compare with current list, if matched return index
116 bool match(true) ;
117
118 // Check that array contents is identical
119 match &= _clArr[i] == codeList;
120
121 // Check that supplied configuration of lists is identical
122 if (_asArr1[i] && !set1) match=false ;
123 if (!_asArr1[i] && set1) match=false ;
124 if (_asArr2[i] && !set2) match=false ;
125 if (!_asArr2[i] && set2) match=false ;
126 if (_asArr3[i] && !set3) match=false ;
127 if (!_asArr3[i] && set3) match=false ;
128 if (_asArr4[i] && !set4) match=false ;
129 if (!_asArr4[i] && set4) match=false ;
130
131 // Check that contents of arrays is identical
132 if (_asArr1[i] && set1 && !set1->equals(*_asArr1[i])) match=false ;
133 if (_asArr2[i] && set2 && !set2->equals(*_asArr2[i])) match=false ;
134 if (_asArr3[i] && set3 && !set3->equals(*_asArr3[i])) match=false ;
135 if (_asArr4[i] && set4 && !set4->equals(*_asArr4[i])) match=false ;
136
137 if (match) {
138 if (set1) delete set1 ;
139 if (set2) delete set2 ;
140 if (set3) delete set3 ;
141 if (set4) delete set4 ;
142 return i ;
143 }
144 }
145
146 // Store code list and return index
147 _clArr.push_back(codeList);
148 _asArr1.emplace_back(makeSnapshot(set1));
149 _asArr2.emplace_back(makeSnapshot(set2));
150 _asArr3.emplace_back(makeSnapshot(set3));
151 _asArr4.emplace_back(makeSnapshot(set4));
152
153 if (set1) delete set1 ;
154 if (set2) delete set2 ;
155 if (set3) delete set3 ;
156 if (set4) delete set4 ;
157 return _clArr.size() - 1;
158}
159
160////////////////////////////////////////////////////////////////////////////////
161/// Retrieve the array of integer codes associated with the given master code
162
163const std::vector<Int_t>& RooAICRegistry::retrieve(Int_t masterCode) const
164{
165 return _clArr[masterCode] ;
166}
167
168////////////////////////////////////////////////////////////////////////////////
169/// Retrieve the array of integer codes associated with the given master code
170/// and set the passed set1 pointer to the first RooArgSet associated with this master code
171
172const std::vector<Int_t>& RooAICRegistry::retrieve(Int_t masterCode, pRooArgSet& set1) const
173{
174 set1 = _asArr1[masterCode] ;
175 return _clArr[masterCode] ;
176}
177
178////////////////////////////////////////////////////////////////////////////////
179/// Retrieve the array of integer codes associated with the given master code
180/// and set the passed set1,set2 pointers to the first and second RooArgSets associated with this
181/// master code respectively
182
183const std::vector<Int_t>& RooAICRegistry::retrieve
184(Int_t masterCode, pRooArgSet& set1, pRooArgSet& set2) const
185{
186 set1 = _asArr1[masterCode] ;
187 set2 = _asArr2[masterCode] ;
188 return _clArr[masterCode] ;
189}
190
191////////////////////////////////////////////////////////////////////////////////
192/// Retrieve the array of integer codes associated with the given master code
193/// and set the passed set1-4 pointers to the four RooArgSets associated with this
194/// master code respectively
195
196const std::vector<Int_t>& RooAICRegistry::retrieve
197(Int_t masterCode, pRooArgSet& set1, pRooArgSet& set2, pRooArgSet& set3, pRooArgSet& set4) const
198{
199 set1 = _asArr1[masterCode] ;
200 set2 = _asArr2[masterCode] ;
201 set3 = _asArr3[masterCode] ;
202 set4 = _asArr4[masterCode] ;
203 return _clArr[masterCode] ;
204}
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
#define ClassImp(name)
Definition Rtypes.h:377
RooAICRegistry is a utility class for operator p.d.f classes that keeps track of analytical integrati...
virtual ~RooAICRegistry()
Destructor.
const std::vector< Int_t > & retrieve(Int_t masterCode) const
Retrieve the array of integer codes associated with the given master code.
RooAICRegistry(UInt_t size=10)
std::vector< pRooArgSet > _asArr2
! Array of 2nd RooArgSet pointers
Int_t store(const std::vector< Int_t > &codeList, RooArgSet *set1=nullptr, RooArgSet *set2=nullptr, RooArgSet *set3=nullptr, RooArgSet *set4=nullptr)
Store given arrays of integer codes, and up to four RooArgSets in the registry (each setX pointer may...
std::vector< pRooArgSet > _asArr1
! Array of 1st RooArgSet pointers
std::vector< pRooArgSet > _asArr4
! Array of 4th RooArgSet pointers
std::vector< std::vector< Int_t > > _clArr
! Array of array of code lists
std::vector< pRooArgSet > _asArr3
! Array of 3rd RooArgSet pointers
bool equals(const RooAbsCollection &otherColl) const
Check if this and other collection have identically-named contents.
Storage_t::size_type size() const
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition RooArgSet.h:178