CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Member Functions | Private Types | Private Attributes
cacheutils::ValuesCache Class Reference

#include <CachingNLL.h>

Classes

struct  Item
 

Public Member Functions

void clear ()
 
std::pair< std::vector
< Double_t > *, bool > 
get ()
 
 ValuesCache (const RooAbsReal &pdf, const RooArgSet &obs, int size=MaxItems_)
 
 ValuesCache (const RooAbsCollection &params, int size=MaxItems_)
 
 ~ValuesCache ()
 

Private Types

enum  { MaxItems_ = 3 }
 

Private Attributes

Itemitems [MaxItems_]
 
int maxSize_
 
int size_
 

Detailed Description

Definition at line 30 of file CachingNLL.h.

Member Enumeration Documentation

anonymous enum
private
Enumerator
MaxItems_ 

Definition at line 50 of file CachingNLL.h.

Constructor & Destructor Documentation

cacheutils::ValuesCache::ValuesCache ( const RooAbsReal &  pdf,
const RooArgSet &  obs,
int  size = MaxItems_ 
)

Definition at line 101 of file CachingNLL.cc.

References items, and MaxItems_.

101  :
102  size_(1),
103  maxSize_(size)
104 {
105  assert(size <= MaxItems_);
106  std::auto_ptr<RooArgSet> params(pdf.getParameters(obs));
107  items[0] = new Item(*params);
108 }
Item * items[MaxItems_]
Definition: CachingNLL.h:51
tuple size
Write out results.
cacheutils::ValuesCache::ValuesCache ( const RooAbsCollection &  params,
int  size = MaxItems_ 
)

Definition at line 94 of file CachingNLL.cc.

References items, and MaxItems_.

94  :
95  size_(1),
96  maxSize_(size)
97 {
98  assert(size <= MaxItems_);
99  items[0] = new Item(params);
100 }
Item * items[MaxItems_]
Definition: CachingNLL.h:51
tuple size
Write out results.
cacheutils::ValuesCache::~ValuesCache ( )

Definition at line 111 of file CachingNLL.cc.

References i, and edm::size_().

112 {
113  for (int i = 0; i < size_; ++i) delete items[i];
114 }
int i
Definition: DBlmapReader.cc:9
Item * items[MaxItems_]
Definition: CachingNLL.h:51

Member Function Documentation

void cacheutils::ValuesCache::clear ( void  )

Definition at line 116 of file CachingNLL.cc.

References i, and edm::size_().

117 {
118  for (int i = 0; i < size_; ++i) items[i]->good = false;
119 }
int i
Definition: DBlmapReader.cc:9
Item * items[MaxItems_]
Definition: CachingNLL.h:51
std::pair< std::vector< Double_t > *, bool > cacheutils::ValuesCache::get ( void  )

Definition at line 121 of file CachingNLL.cc.

References PerfCounter::add(), f, newFWLiteAna::found, i, and edm::size_().

Referenced by Options.Options::__getitem__(), betterConfigParser.BetterConfigParser::__updateDict(), betterConfigParser.BetterConfigParser::getCompares(), betterConfigParser.BetterConfigParser::getGeneral(), and betterConfigParser.BetterConfigParser::getResultingSection().

122 {
123  int found = -1; bool good = false;
124  for (int i = 0; i < size_; ++i) {
125  if (items[i]->good) {
126  // valid entry, check if fresh
127  if (!items[i]->checker.changed()) {
128 #ifdef DEBUG_CACHE
129  PerfCounter::add(i == 0 ? "ValuesCache::get hit first" : "ValuesCache::get hit other");
130 #endif
131  // fresh: done!
132  found = i;
133  good = true;
134  break;
135  }
136  } else if (found == -1) {
137  // invalid entry, can be replaced
138  found = i;
139 #ifdef DEBUG_CACHE
140  PerfCounter::add("ValuesCache::get hit invalid");
141 #endif
142  }
143  }
144  if (found == -1) {
145  // all entries are valid but old
146 #ifdef DEBUG_CACHE
147  PerfCounter::add("ValuesCache::get miss");
148 #endif
149  if (size_ < maxSize_) {
150  // if I can, make a new entry
151  items[size_] = new Item(items[0]->checker); // create a new item, copying the ArgSetChecker from the first one
152  found = size_;
153  size_++;
154  } else {
155  // otherwise, pick the last one
156  found = size_-1;
157  }
158  }
159  // make sure new entry is the first one
160  if (found != 0) {
161  // remember what found is pointing to
162  Item *f = items[found];
163  // shift the other items down one place
164  while (found > 0) { items[found] = items[found-1]; --found; }
165  // and put found on top
166  items[found] = f;
167  }
168  if (!good) items[found]->checker.changed(true); // store new values in cache sentry
169  items[found]->good = true; // mark this as valid entry
170  return std::pair<std::vector<Double_t> *, bool>(&items[found]->values, good);
171 }
int i
Definition: DBlmapReader.cc:9
void add(double increment=1.0)
std::vector< Double_t > values
Definition: CachingNLL.h:45
Item * items[MaxItems_]
Definition: CachingNLL.h:51
bool changed(bool updateIfChanged=false)
Definition: CachingNLL.cc:77
double f[11][100]

Member Data Documentation

Item* cacheutils::ValuesCache::items[MaxItems_]
private
int cacheutils::ValuesCache::maxSize_
private

Definition at line 49 of file CachingNLL.h.

int cacheutils::ValuesCache::size_
private

Definition at line 49 of file CachingNLL.h.