CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
edm::helper::IndexRangeAssociation::FastFiller Class Reference

#include <MultiAssociation.h>

Inheritance diagram for edm::helper::IndexRangeAssociation::FastFiller:

Public Member Functions

 FastFiller (IndexRangeAssociation &assoc, ProductID id, unsigned int size)
 Make a filler for a collection with a given product id and size. More...
 
template<typename RefKey >
void insert (const RefKey &r, unsigned int startingOffset, unsigned int size)
 Sets the starting offset for this key. More...
 
void insert (edm::ProductID id, unsigned int key, unsigned int startingOffset, unsigned int size)
 Sets the starting offset for this key (non-templated variant) More...
 
 ~FastFiller ()
 When the FastFiller goes out of scope, it unlocks the map so you can make a new one. More...
 

Private Attributes

IndexRangeAssociationassoc_
 
unsigned int end_
 
const ProductID id_
 
int lastKey_
 last key used to fill (to check that the new key must be strictly greater than lastKey_) More...
 
unsigned int start_
 

Detailed Description

FastFiller for the IndexRangeAssociation: It requires to fill items in strict key order. You can have a single FastFiller for a given map at time You can't access the map for this collection while filling it

Definition at line 103 of file MultiAssociation.h.

Constructor & Destructor Documentation

IndexRangeAssociation::FastFiller::FastFiller ( IndexRangeAssociation assoc,
ProductID  id,
unsigned int  size 
)

Make a filler for a collection with a given product id and size.

Definition at line 44 of file MultiAssociation.cc.

References assoc_, end_, Exception, triggerObjects_cff::id, edm::helper::IndexRangeAssociation::id_offsets_, edm::helper::IndexRangeAssociation::isFilling_, pfDeepBoostedJetPreprocessParams_cfi::lower_bound, edm::helper::IndexRangeAssociation::ref_offsets_, and start_.

Referenced by edm::MultiAssociation< C >::fastFiller().

44  :
45  assoc_(assoc), id_(id),
46  start_(assoc.ref_offsets_.empty() ? 0 : assoc.ref_offsets_.size() - 1), // must skip the end marker element
47  end_(start_ + size),
48  lastKey_(-1)
49 {
50  if (assoc_.isFilling_) throw cms::Exception("Unsupported Operation") <<
51  "IndexRangeAssociation::FastFiller: you already have one active filler for this map.\n";
52 
53  // Look if the key is there, or find the right place to insert it
54  typedef IndexRangeAssociation::id_offset_vector::iterator iter;
55  iter pos = std::lower_bound(assoc_.id_offsets_.begin(), assoc_.id_offsets_.end(), id, IndexRangeAssociation::IDComparator());
56 
57  // Check for duplicate ProductID
58  if ((pos != assoc_.id_offsets_.end()) && (pos->first == id)) throw cms::Exception("Duplicated Key") <<
59  "IndexRangeAssociation::FastFiller: there is already an entry for ProductID " << id << " in this map.\n";
60 
61  // Lock the map
62  assoc_.isFilling_ = true;
63 
64  // Insert the key, keeping id_offsets_ sorted
66 
67  int lastEnd = (assoc_.ref_offsets_.empty() ? 0 : assoc_.ref_offsets_.back());
68  assoc_.ref_offsets_.resize(end_ + 1, -1);
69  assoc_.ref_offsets_.back() = lastEnd;
70 }
unsigned int size() const
Size of this collection (number of keys)
int lastKey_
last key used to fill (to check that the new key must be strictly greater than lastKey_) ...
std::pair< edm::ProductID, unsigned int > id_off_pair
IndexRangeAssociation::FastFiller::~FastFiller ( )

When the FastFiller goes out of scope, it unlocks the map so you can make a new one.

Definition at line 72 of file MultiAssociation.cc.

References assoc_, end_, edm::helper::IndexRangeAssociation::isFilling_, PFRecoTauDiscriminationByIsolation_cfi::offset, edm::helper::IndexRangeAssociation::ref_offsets_, and start_.

72  {
73  // I have to consolidate, replacing "-1" with the correct end offset.
74  // I can start from the end, as I know that the last item is never -1
75  typedef IndexRangeAssociation::offset_vector::iterator IT;
76  //std::cout << "Fixupping [" << start_ << ", " << end_ << "]" << std::endl;
77  //for(IT i = assoc_.ref_offsets_.begin() + start_; i <= assoc_.ref_offsets_.begin() + end_; ++i) { std::cout << " - " << *i << std::endl; }
78  IT top = assoc_.ref_offsets_.begin() + start_;
79  IT it = assoc_.ref_offsets_.begin() + end_;
80  int offset = *it;
81  for (--it; it >= top; --it) {
82  if (*it == -1) {
83  //std::cout << " > replace *it " << *it << " with offset " << offset << " at " << (it - top) << std::endl;
84  *it = offset; // replace -1 with real end offset
85  } else {
86  //std::cout << " > replace offset " << offset << " with *it " << *it << " at " << (it - top) << std::endl;
87  offset = *it; // take as new end offset for the preceding "-1"s
88  }
89  }
90  assoc_.isFilling_ = false; // unlock
91  //std::cout << "Fixupped [" << start_ << ", " << end_ << "]" << std::endl;
92  //for(IT i = assoc_.ref_offsets_.begin() + start_; i <= assoc_.ref_offsets_.begin() + end_; ++i) { std::cout << " - " << *i << std::endl; }
93 }
std::vector< LinkConnSpec >::const_iterator IT

Member Function Documentation

template<typename RefKey >
void edm::helper::IndexRangeAssociation::FastFiller::insert ( const RefKey &  r,
unsigned int  startingOffset,
unsigned int  size 
)
inline

Sets the starting offset for this key.

Definition at line 113 of file MultiAssociation.h.

References crabWrapper::key, and edm::helper::IndexRangeAssociation::size().

Referenced by BeautifulSoup.PageElement::append().

113  {
114  insert(r.id(), r.key(), startingOffset, size);
115  }
unsigned int size() const
Size of this collection (number of keys)
void insert(const RefKey &r, unsigned int startingOffset, unsigned int size)
Sets the starting offset for this key.
void IndexRangeAssociation::FastFiller::insert ( edm::ProductID  id,
unsigned int  key,
unsigned int  startingOffset,
unsigned int  size 
)

Sets the starting offset for this key (non-templated variant)

Definition at line 96 of file MultiAssociation.cc.

References assoc_, end_, Exception, id_, crabWrapper::key, lastKey_, edm::helper::IndexRangeAssociation::ref_offsets_, edm::helper::IndexRangeAssociation::size(), start_, and edm::helper::IndexRangeAssociation::throwUnexpectedProductID().

Referenced by BeautifulSoup.PageElement::append().

96  {
97  if (id != id_) IndexRangeAssociation::throwUnexpectedProductID(id,id_,"FastFiller::insert");
98  if (int(key) <= lastKey_) throw cms::Exception("Bad Key") <<
99  "IndexRangeAssociation::FastFiller: you must fill this in strict key order\n" <<
100  "\tLast key = " << lastKey_ << ", this key = " << key << "\n";
101  if (key >= end_) throw cms::Exception("Bad Key") <<
102  "IndexRangeAssociation::FastFiller: key index out of bounds for this collection\n" <<
103  "\tKey = " << key << ", bound = " << end_ << "\n";
104  if ((assoc_.ref_offsets_.back() != 0) && (int(startingOffset) != assoc_.ref_offsets_.back()))
105  throw cms::Exception("Bad Offset") <<
106  "IndexRangeAssociation::FastFiller: The start for this key is not the end of the preceding key.\n" <<
107  "\tThis offset = " << startingOffset << ", last key = " << lastKey_ <<
108  ", last end offset = " << assoc_.ref_offsets_.back() << "\n";
109  assoc_.ref_offsets_[start_ + key] = startingOffset;
110  lastKey_ = key;
111  assoc_.ref_offsets_.back() += size;
112 }
static void throwUnexpectedProductID(ProductID found, ProductID expected, const char *where)
unsigned int size() const
Size of this collection (number of keys)
int lastKey_
last key used to fill (to check that the new key must be strictly greater than lastKey_) ...

Member Data Documentation

IndexRangeAssociation& edm::helper::IndexRangeAssociation::FastFiller::assoc_
private
unsigned int edm::helper::IndexRangeAssociation::FastFiller::end_
private

Definition at line 122 of file MultiAssociation.h.

Referenced by FastFiller(), insert(), and ~FastFiller().

const ProductID edm::helper::IndexRangeAssociation::FastFiller::id_
private
int edm::helper::IndexRangeAssociation::FastFiller::lastKey_
private

last key used to fill (to check that the new key must be strictly greater than lastKey_)

Definition at line 124 of file MultiAssociation.h.

Referenced by insert().

unsigned int edm::helper::IndexRangeAssociation::FastFiller::start_
private

Definition at line 122 of file MultiAssociation.h.

Referenced by FastFiller(), insert(), and ~FastFiller().