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