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