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