CMS 3D CMS Logo

Classes | Public Member Functions | Private Types | Private Attributes

cacheutils::ValuesCache Class Reference

#include <CachingNLL.h>

List of all members.

Classes

struct  Item

Public Member Functions

void clear ()
std::pair< std::vector
< Double_t > *, bool > 
get ()
 ValuesCache (const RooAbsCollection &params, int size=MaxItems_)
 ValuesCache (const RooAbsReal &pdf, const RooArgSet &obs, 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.

{ MaxItems_ = 3 };

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_.

                                                                                        :
    size_(1),
    maxSize_(size)
{
    assert(size <= MaxItems_);
    std::auto_ptr<RooArgSet> params(pdf.getParameters(obs));
    items[0] = new Item(*params);
}
cacheutils::ValuesCache::ValuesCache ( const RooAbsCollection &  params,
int  size = MaxItems_ 
)

Definition at line 94 of file CachingNLL.cc.

References items, and MaxItems_.

                                                                           :
    size_(1),
    maxSize_(size)
{
    assert(size <= MaxItems_);
    items[0] = new Item(params);
}
cacheutils::ValuesCache::~ValuesCache ( )

Definition at line 111 of file CachingNLL.cc.

References i, and edm::size_().

{
    for (int i = 0; i < size_; ++i) delete items[i];
}

Member Function Documentation

void cacheutils::ValuesCache::clear ( void  )

Definition at line 116 of file CachingNLL.cc.

References i, and edm::size_().

{
    for (int i = 0; i < size_; ++i) items[i]->good = false;
}
std::pair< std::vector< Double_t > *, bool > cacheutils::ValuesCache::get ( void  )

Definition at line 121 of file CachingNLL.cc.

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

{
    int found = -1; bool good = false;
    for (int i = 0; i < size_; ++i) {
        if (items[i]->good) {
            // valid entry, check if fresh
            if (!items[i]->checker.changed()) {
#ifdef DEBUG_CACHE
                PerfCounter::add(i == 0 ? "ValuesCache::get hit first" : "ValuesCache::get hit other");
#endif
                // fresh: done! 
                found = i; 
                good = true; 
                break;
            } 
        } else if (found == -1) {
            // invalid entry, can be replaced
            found = i;
#ifdef DEBUG_CACHE
            PerfCounter::add("ValuesCache::get hit invalid");
#endif
        }
    } 
    if (found == -1) {
        // all entries are valid but old 
#ifdef DEBUG_CACHE
        PerfCounter::add("ValuesCache::get miss");
#endif
        if (size_ < maxSize_) {
            // if I can, make a new entry
            items[size_] = new Item(items[0]->checker); // create a new item, copying the ArgSetChecker from the first one
            found = size_; 
            size_++;
        } else {
            // otherwise, pick the last one
            found = size_-1;
        }
    }
    // make sure new entry is the first one
    if (found != 0) {
        // remember what found is pointing to
        Item *f = items[found];
        // shift the other items down one place
        while (found > 0) { items[found] = items[found-1]; --found; } 
        // and put found on top
        items[found] = f;
    }
    if (!good) items[found]->checker.changed(true); // store new values in cache sentry
    items[found]->good = true;                      // mark this as valid entry
    return std::pair<std::vector<Double_t> *, bool>(&items[found]->values, good);
}

Member Data Documentation

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

Definition at line 51 of file CachingNLL.h.

Referenced by ValuesCache().

Definition at line 49 of file CachingNLL.h.

Definition at line 49 of file CachingNLL.h.