Logo ROOT  
Reference Guide
RooNormSetCache.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * File: $Id: RooNormSetCache.h,v 1.12 2007/08/09 19:55:47 wouter Exp $
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#ifndef ROO_NORMSET_CACHE
17#define ROO_NORMSET_CACHE
18
19#include <RooArgSet.h>
20
21#include <vector>
22#include <map>
23#include <string>
24
26private:
27 class Pair {
28 public:
30 Pair(const RooArgSet* set1, const RooArgSet* set2)
31 : _pair{RooFit::getUniqueId(set1), RooFit::getUniqueId(set2)} {}
32 bool operator==(Pair const &other) const { return _pair == other._pair; }
33 bool operator<(Pair const &other) const { return _pair < other._pair; }
34
35 Value_t const& first() const { return _pair.first; }
36 Value_t const& second() const { return _pair.second; }
37 private:
38 std::pair<Value_t,Value_t> _pair;
39 };
40
41 typedef std::vector<Pair> PairVectType;
42 typedef std::map<Pair, std::size_t> PairIdxMapType;
43
44public:
45 RooNormSetCache(std::size_t max = 32) : _max(max) {}
46
47 void add(const RooArgSet* set1, const RooArgSet* set2 = 0);
48
49 inline int index(const RooArgSet* set1, const RooArgSet* set2 = 0,
50 const TNamed* set2RangeName = 0)
51 {
52 // Match range name first
53 if (set2RangeName != _set2RangeName) return -1;
54 const Pair pair(set1, set2);
55 PairIdxMapType::const_iterator it = _pairToIdx.lower_bound(pair);
56 if (_pairToIdx.end() != it && it->first == pair) {
57 return it->second;
58 }
59 return -1;
60 }
61
62 inline bool contains(const RooArgSet* set1, const RooArgSet* set2 = 0,
63 const TNamed* set2RangeName = 0)
64 { return (index(set1,set2,set2RangeName) >= 0); }
65
66 inline bool containsSet1(const RooArgSet* set1)
67 {
68 const Pair pair(set1, (const RooArgSet*)0);
69 PairIdxMapType::const_iterator it = _pairToIdx.lower_bound(pair);
70 if (_pairToIdx.end() != it && it->first.first() == RooFit::getUniqueId(set1))
71 return true;
72 return false;
73 }
74
75 const std::string& nameSet1() const { return _name1; }
76 const std::string& nameSet2() const { return _name2; }
77
78 bool autoCache(const RooAbsArg* self, const RooArgSet* set1,
79 const RooArgSet* set2 = 0, const TNamed* set2RangeName = 0,
80 bool autoRefill = true);
81
82 void clear();
83 std::size_t entries() const { return _pairs.size(); }
84
85 void initialize(const RooNormSetCache& other) { clear(); *this = other; }
86
87private:
88
91 std::size_t _max; ///<!
92 std::size_t _next = 0; ///<!
93
94 std::string _name1; ///<!
95 std::string _name2; ///<!
96 TNamed* _set2RangeName = nullptr; ///<!
97};
98
99#endif
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition: RooAbsArg.h:72
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:57
bool operator==(Pair const &other) const
bool operator<(Pair const &other) const
Value_t const & first() const
Value_t const & second() const
Pair(const RooArgSet *set1, const RooArgSet *set2)
RooFit::UniqueId< RooArgSet >::Value_t Value_t
std::pair< Value_t, Value_t > _pair
Class RooNormSet cache manage the bookkeeping of multiple instances of sets of integration and normal...
bool autoCache(const RooAbsArg *self, const RooArgSet *set1, const RooArgSet *set2=0, const TNamed *set2RangeName=0, bool autoRefill=true)
If RooArgSets set1 and set2 or sets with similar contents have been seen by this cache manager before...
const std::string & nameSet2() const
void clear()
Clear contents.
std::size_t entries() const
TNamed * _set2RangeName
!
std::string _name1
!
PairIdxMapType _pairToIdx
!
bool containsSet1(const RooArgSet *set1)
int index(const RooArgSet *set1, const RooArgSet *set2=0, const TNamed *set2RangeName=0)
void initialize(const RooNormSetCache &other)
bool contains(const RooArgSet *set1, const RooArgSet *set2=0, const TNamed *set2RangeName=0)
std::size_t _max
!
std::size_t _next
!
void add(const RooArgSet *set1, const RooArgSet *set2=0)
Add given pair of RooArgSet pointers to our store.
std::string _name2
!
PairVectType _pairs
!
std::map< Pair, std::size_t > PairIdxMapType
std::vector< Pair > PairVectType
const std::string & nameSet1() const
RooNormSetCache(std::size_t max=32)
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition: Common.h:18
UniqueId< Class > const & getUniqueId(Class const *ptr)
A helper function to replace pointer comparisons with UniqueId comparisons.
Definition: UniqueId.h:87
unsigned long Value_t
Definition: UniqueId.h:41