RooAICRegistry.cxx

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitCore                                                       *
00004  * @(#)root/roofitcore:$Id: RooAICRegistry.cxx 36209 2010-10-08 21:37:36Z wouter $
00005  * Authors:                                                                  *
00006  *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
00007  *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
00008  *                                                                           *
00009  * Copyright (c) 2000-2005, Regents of the University of California          *
00010  *                          and Stanford University. All rights reserved.    *
00011  *                                                                           *
00012  * Redistribution and use in source and binary forms,                        *
00013  * with or without modification, are permitted according to the terms        *
00014  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
00015  *****************************************************************************/
00016 
00017 //////////////////////////////////////////////////////////////////////////////
00018 // 
00019 // BEGIN_HTML 
00020 // RooAICRegistry is a utility class for operator p.d.f
00021 // classes that keeps track of analytical integration codes and
00022 // associated normalization and integration sets.  
00023 // END_HTML
00024 //
00025 
00026 #include "RooFit.h"
00027 
00028 #include "RooAICRegistry.h"
00029 #include "RooMsgService.h"
00030 #include "RooArgSet.h"
00031 #include "RooMsgService.h"
00032 
00033 #include "Riostream.h"
00034 
00035 
00036 ClassImp(RooAICRegistry)
00037 ;
00038 
00039 
00040 //_____________________________________________________________________________
00041 RooAICRegistry::RooAICRegistry(Int_t regSize) :
00042   _regSize(regSize), _clSize(0), _clArr(0), _asArr1(0), _asArr2(0), _asArr3(0), _asArr4(0)
00043 {
00044   // Constructor
00045 }
00046 
00047 
00048 
00049 //_____________________________________________________________________________
00050 RooAICRegistry::RooAICRegistry(const RooAICRegistry& other) :
00051   _regSize(other._regSize), _clSize(0), _clArr(0), _asArr1(0), _asArr2(0), _asArr3(0), _asArr4(0)
00052 {
00053   // Copy constructor
00054 
00055   // Copy code-list array if other PDF has one
00056   if (other._clArr) {
00057     _clArr = new pInt_t[other._regSize] ;    
00058     _asArr1 = new pRooArgSet[other._regSize] ;
00059     _asArr2 = new pRooArgSet[other._regSize] ;
00060     _asArr3 = new pRooArgSet[other._regSize] ;
00061     _asArr4 = new pRooArgSet[other._regSize] ;
00062     _clSize = new Int_t[other._regSize] ;
00063     Int_t i,j ;
00064     for (i=0 ; i<_regSize ; i++) {
00065       _clArr[i]=0 ;
00066       _clSize[i]=0 ;
00067       _asArr1[i]=0 ;
00068       _asArr2[i]=0 ;
00069       _asArr3[i]=0 ;
00070       _asArr4[i]=0 ;
00071     }
00072     i=0 ;
00073     while(other._clArr[i] && i<_regSize) {
00074       _clSize[i] = other._clSize[i] ;
00075       _asArr1[i] = other._asArr1[i] ? ((RooArgSet*)other._asArr1[i]->snapshot(kFALSE)) : 0 ; 
00076       _asArr2[i] = other._asArr2[i] ? ((RooArgSet*)other._asArr2[i]->snapshot(kFALSE)) : 0 ;
00077       _asArr3[i] = other._asArr3[i] ? ((RooArgSet*)other._asArr3[i]->snapshot(kFALSE)) : 0 ;
00078       _asArr4[i] = other._asArr4[i] ? ((RooArgSet*)other._asArr4[i]->snapshot(kFALSE)) : 0 ;
00079       _clArr[i] = new Int_t[_clSize[i]] ;
00080       for (j=0 ; j<_clSize[i] ; j++) {
00081         _clArr[i][j] = other._clArr[i][j] ;
00082       }
00083       i++ ;
00084     }
00085   }
00086 }
00087 
00088 
00089 
00090 //_____________________________________________________________________________
00091 RooAICRegistry::~RooAICRegistry() 
00092 {
00093   // Destructor
00094 
00095   // Delete code list array, if allocated
00096   if (_clArr) {
00097     Int_t i(0) ;
00098     while(_clArr[i] && i<_regSize) {
00099       delete[] _clArr[i] ;
00100       if (_asArr1[i]) delete _asArr1[i] ;
00101       if (_asArr2[i]) delete _asArr2[i] ;
00102       if (_asArr3[i]) delete _asArr3[i] ;
00103       if (_asArr4[i]) delete _asArr4[i] ;
00104       i++ ;
00105     }
00106     delete[] _clArr ;
00107     delete[] _clSize ;
00108     delete[] _asArr1 ;
00109     delete[] _asArr2 ;
00110     delete[] _asArr3 ;
00111     delete[] _asArr4 ;
00112   }
00113 }
00114 
00115 
00116 
00117 //_____________________________________________________________________________
00118 Int_t RooAICRegistry::store(Int_t* codeList, Int_t size, RooArgSet* set1, RooArgSet* set2, RooArgSet* set3, RooArgSet* set4)
00119 {
00120   // Store given arrays of integer codes, and up to four RooArgSets in
00121   // the registry (each setX pointer may be null). The size of the
00122   // arrays should be passed by the 'size' argument. The registry
00123   // clones all RooArgSets internally so the RooArgSets passed as
00124   // arguments do not need to live beyond the store() call. The return
00125   // value is a unique master code for the given configuration of
00126   // integers and RooArgSets. If an identical combination is
00127   // previously stored in the registry no objects are stored and the
00128   // unique code of the existing entry is returned.
00129 
00130   Int_t i,j ;
00131 
00132   // If code list array has never been used, allocate and initialize here
00133   if (!_clArr) {
00134     _clArr = new pInt_t[_regSize] ;
00135     _clSize = new Int_t[_regSize] ;
00136     _asArr1 = new pRooArgSet[_regSize] ;
00137     _asArr2 = new pRooArgSet[_regSize] ;
00138     _asArr3 = new pRooArgSet[_regSize] ;
00139     _asArr4 = new pRooArgSet[_regSize] ;
00140     for (i=0 ; i<_regSize ; i++) {
00141       _clArr[i] = 0 ;    
00142       _clSize[i] = 0 ;
00143       _asArr1[i] = 0 ;
00144       _asArr2[i] = 0 ;
00145       _asArr3[i] = 0 ;
00146       _asArr4[i] = 0 ;
00147     }
00148   }
00149 
00150   // Loop over code-list array
00151   for (i=0 ; i<_regSize ; i++) {
00152     if (_clArr[i]==0) {
00153       // Empty slot, store code list and return index
00154       _clArr[i] = new Int_t[size] ;
00155       _clSize[i] = size ;
00156       _asArr1[i] = set1 ? (RooArgSet*)set1->snapshot(kFALSE) : 0;
00157       _asArr2[i] = set2 ? (RooArgSet*)set2->snapshot(kFALSE) : 0;
00158       _asArr3[i] = set3 ? (RooArgSet*)set3->snapshot(kFALSE) : 0;
00159       _asArr4[i] = set4 ? (RooArgSet*)set4->snapshot(kFALSE) : 0;
00160       for (j=0 ; j<size ; j++) _clArr[i][j] = codeList[j] ;
00161 
00162       if (set1) delete set1 ;
00163       if (set2) delete set2 ;
00164       if (set3) delete set3 ;
00165       if (set4) delete set4 ;
00166 
00167       return i ;
00168     } else {
00169 
00170       // Existing slot, compare with current list, if matched return index
00171       Bool_t match(kTRUE) ;
00172 
00173       // Check that array contents is identical
00174       for (j=0 ; j<size ; j++) {
00175         if (_clArr[i][j] != codeList[j]) match=kFALSE ;
00176       }
00177       // Check that supplied configuration of lists is identical
00178       if (_asArr1[i] && !set1) match=kFALSE ;
00179       if (!_asArr1[i] && set1) match=kFALSE ;
00180       if (_asArr2[i] && !set2) match=kFALSE ;
00181       if (!_asArr2[i] && set2) match=kFALSE ;
00182       if (_asArr3[i] && !set3) match=kFALSE ;
00183       if (!_asArr3[i] && set3) match=kFALSE ;
00184       if (_asArr4[i] && !set4) match=kFALSE ;
00185       if (!_asArr4[i] && set4) match=kFALSE ;
00186 
00187       // Check that contents of arrays is identical
00188       if (_asArr1[i] && set1 && !set1->equals(*_asArr1[i])) match=kFALSE ;
00189       if (_asArr2[i] && set2 && !set2->equals(*_asArr2[i])) match=kFALSE ;      
00190       if (_asArr3[i] && set3 && !set3->equals(*_asArr3[i])) match=kFALSE ;      
00191       if (_asArr4[i] && set4 && !set4->equals(*_asArr4[i])) match=kFALSE ;      
00192 
00193       if (match) {
00194         if (set1) delete set1 ;
00195         if (set2) delete set2 ;
00196         if (set3) delete set3 ;
00197         if (set4) delete set4 ;
00198         return i ;
00199       }
00200     }
00201   }
00202 
00203   oocoutF((TObject*)0,Caching) << "RooAICRegistry::store: ERROR: capacity exceeded" << endl ;
00204   assert(0) ;
00205   return 0 ;
00206 }
00207 
00208 
00209 
00210 //_____________________________________________________________________________
00211 const Int_t* RooAICRegistry::retrieve(Int_t masterCode) const 
00212 {
00213   // Retrieve the array of integer codes associated with the given master code
00214   return _clArr[masterCode] ;
00215 }
00216 
00217 
00218 
00219 //_____________________________________________________________________________
00220 const Int_t* RooAICRegistry::retrieve(Int_t masterCode, pRooArgSet& set1) const 
00221 {
00222   // Retrieve the array of integer codes associated with the given master code
00223   // and set the passed set1 pointer to the first RooArgSet associated with this master code
00224 
00225   set1 = _asArr1[masterCode] ;
00226   return _clArr[masterCode] ;
00227 }
00228 
00229 
00230 
00231 //_____________________________________________________________________________
00232 const Int_t* RooAICRegistry::retrieve(Int_t masterCode, pRooArgSet& set1, pRooArgSet& set2) const 
00233 {
00234   // Retrieve the array of integer codes associated with the given master code
00235   // and set the passed set1,set2 pointers to the first and second  RooArgSets associated with this 
00236   // master code respectively
00237 
00238   set1 = _asArr1[masterCode] ;
00239   set2 = _asArr2[masterCode] ;
00240   return _clArr[masterCode] ;
00241 }
00242 
00243 
00244 
00245 //_____________________________________________________________________________
00246 const Int_t* RooAICRegistry::retrieve(Int_t masterCode, pRooArgSet& set1, pRooArgSet& set2, pRooArgSet& set3, pRooArgSet& set4) const 
00247 {
00248   // Retrieve the array of integer codes associated with the given master code
00249   // and set the passed set1-4 pointers to the four  RooArgSets associated with this 
00250   // master code respectively
00251 
00252   set1 = _asArr1[masterCode] ;
00253   set2 = _asArr2[masterCode] ;
00254   set3 = _asArr3[masterCode] ;
00255   set4 = _asArr4[masterCode] ;
00256   return _clArr[masterCode] ;
00257 }

Generated on Tue Jul 5 15:06:00 2011 for ROOT_528-00b_version by  doxygen 1.5.1