Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
31 class RooNormSetCache {
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; //!
95  ULong_t _max; //!
96  ULong_t _next; //!
97 
98  RooNameSet _name1; //!
99  RooNameSet _name2; //!
100  TNamed* _set2RangeName; //!
101 
102  ClassDef(RooNormSetCache, 0) // Management tool for tracking sets of similar integration/normalization sets
103 };
104 
105 #endif