Logo ROOT   6.14/05
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 <utility>
20 #include <vector>
21 #include <map>
22 
23 #include "Rtypes.h"
24 #include "RooNameSet.h"
25 
26 class RooAbsArg;
27 class RooArgSet;
28 
29 typedef RooArgSet* pRooArgSet ;
30 
32 protected:
33  typedef std::pair<const RooArgSet*, const RooArgSet*> Pair;
34  struct PairCmp {
35  inline bool operator()(const Pair& a, const Pair& b) const
36  {
37  if (a.first < b.first) return true;
38  if (b.first < a.first) return false;
39  return a.second < b.second;
40  }
41  };
42  typedef std::vector<Pair> PairVectType;
43  typedef std::map<Pair, ULong_t> PairIdxMapType;
44 
45 public:
46  RooNormSetCache(ULong_t max = 32);
47  virtual ~RooNormSetCache();
48 
49  void add(const RooArgSet* set1, const RooArgSet* set2 = 0);
50 
51  inline Int_t index(const RooArgSet* set1, const RooArgSet* set2 = 0,
52  const TNamed* set2RangeName = 0)
53  {
54  // Match range name first
55  if (set2RangeName != _set2RangeName) return -1;
56  const Pair pair(set1, set2);
57  PairIdxMapType::const_iterator it = _pairToIdx.lower_bound(pair);
58  if (_pairToIdx.end() != it &&
59  !PairCmp()(it->first, pair) && !PairCmp()(pair, it->first))
60  return it->second;
61  return -1;
62  }
63 
64  inline Bool_t contains(const RooArgSet* set1, const RooArgSet* set2 = 0,
65  const TNamed* set2RangeName = 0)
66  { return (index(set1,set2,set2RangeName) >= 0); }
67 
68  inline Bool_t containsSet1(const RooArgSet* set1)
69  {
70  const Pair pair(set1, (const RooArgSet*)0);
71  PairIdxMapType::const_iterator it = _pairToIdx.lower_bound(pair);
72  if (_pairToIdx.end() != it && it->first.first == set1)
73  return kTRUE;
74  return kFALSE;
75  }
76 
77  const RooArgSet* lastSet1() const { return _pairs.empty()?0:_pairs.back().first; }
78  const RooArgSet* lastSet2() const { return _pairs.empty()?0:_pairs.back().second; }
79  const RooNameSet& nameSet1() const { return _name1; }
80  const RooNameSet& nameSet2() const { return _name2; }
81 
82  Bool_t autoCache(const RooAbsArg* self, const RooArgSet* set1,
83  const RooArgSet* set2 = 0, const TNamed* set2RangeName = 0,
84  Bool_t autoRefill = kTRUE);
85 
86  void clear();
87  Int_t entries() const { return _pairs.size(); }
88 
89  void initialize(const RooNormSetCache& other) { clear(); *this = other; }
90 
91 protected:
92 
93  PairVectType _pairs; //!
94  PairIdxMapType _pairToIdx; //!
97 
101 
102  ClassDef(RooNormSetCache, 0) // Management tool for tracking sets of similar integration/normalization sets
103 };
104 
105 #endif
const RooArgSet * lastSet2() const
Int_t entries() const
RooNameSet _name2
Int_t index(const RooArgSet *set1, const RooArgSet *set2=0, const TNamed *set2RangeName=0)
void initialize(const RooNormSetCache &other)
Bool_t contains(const RooArgSet *set1, const RooArgSet *set2=0, const TNamed *set2RangeName=0)
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const RooNameSet & nameSet2() const
Class RooNormSet cache manage the bookkeeping of multiple instances of sets of integration and normal...
PairIdxMapType _pairToIdx
#define ClassDef(name, id)
Definition: Rtypes.h:320
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
void add(const RooArgSet *set1, const RooArgSet *set2=0)
Add given pair of RooArgSet pointers to our store.
RooNameSet is a utility class that stores the names the objects in a RooArget.
Definition: RooNameSet.h:24
TNamed * _set2RangeName
Bool_t containsSet1(const RooArgSet *set1)
auto * a
Definition: textangle.C:12
RooNameSet _name1
RooNormSetCache(ULong_t max=32)
std::pair< const RooArgSet *, const RooArgSet * > Pair
const RooArgSet * lastSet1() const
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool operator()(const Pair &a, const Pair &b) const
unsigned long ULong_t
Definition: RtypesCore.h:51
const RooNameSet & nameSet1() const
PairVectType _pairs
RooArgSet * pRooArgSet
void clear()
Clear contents.
std::vector< Pair > PairVectType
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
std::map< Pair, ULong_t > PairIdxMapType
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:66
const Bool_t kTRUE
Definition: RtypesCore.h:87
Bool_t autoCache(const RooAbsArg *self, const RooArgSet *set1, const RooArgSet *set2=0, const TNamed *set2RangeName=0, Bool_t autoRefill=kTRUE)
If RooArgSets set1 and set2 or sets with similar contents have been seen by this cache manager before...
virtual ~RooNormSetCache()
Destructor.