#include <MultiAssociation.h>
Classes | |
class | FastFiller |
struct | IDComparator |
Public Types | |
typedef std::pair< unsigned int, unsigned int > | range |
Public Member Functions | |
bool | contains (ProductID id) const |
True if this IndexRangeAssociation has info for this product id. | |
bool | empty () const |
True if it's empty (no keys) | |
range | get (const edm::ProductID &id, unsigned int t) const |
IndexRangeAssociation () | |
template<typename RefKey > | |
range | operator[] (const RefKey &r) const |
unsigned int | size () const |
Size of this collection (number of keys) | |
void | swap (IndexRangeAssociation &other) |
Static Public Member Functions | |
static void | throwUnexpectedProductID (ProductID found, ProductID expected, const char *where) |
Private Types | |
typedef std::pair < edm::ProductID, unsigned int > | id_off_pair |
typedef std::vector< id_off_pair > | id_offset_vector |
typedef std::vector< int > | offset_vector |
Private Attributes | |
id_offset_vector | id_offsets_ |
bool | isFilling_ |
offset_vector | ref_offsets_ |
Friends | |
class | FastFiller |
Base class to map to items one a range within a target collection. All items in a target collection must be mapped to one and only one key. The target collection will normally be a RefVector (also PtrVector and std::vector could work) To be used by MultiAssociation. Any other usage beyond MultiAssociation is not supported. This class holds:
Definition at line 74 of file MultiAssociation.h.
typedef std::pair<edm::ProductID,unsigned int> edm::helper::IndexRangeAssociation::id_off_pair [private] |
Definition at line 133 of file MultiAssociation.h.
typedef std::vector<id_off_pair> edm::helper::IndexRangeAssociation::id_offset_vector [private] |
Definition at line 134 of file MultiAssociation.h.
typedef std::vector<int> edm::helper::IndexRangeAssociation::offset_vector [private] |
Definition at line 135 of file MultiAssociation.h.
typedef std::pair<unsigned int, unsigned int> edm::helper::IndexRangeAssociation::range |
Definition at line 76 of file MultiAssociation.h.
edm::helper::IndexRangeAssociation::IndexRangeAssociation | ( | ) | [inline] |
Definition at line 78 of file MultiAssociation.h.
: isFilling_(false) {}
bool IndexRangeAssociation::contains | ( | ProductID | id | ) | const |
True if this IndexRangeAssociation has info for this product id.
Definition at line 32 of file MultiAssociation.cc.
References id_offsets_, and pos.
Referenced by edm::MultiAssociation< C >::contains().
{ typedef IndexRangeAssociation::id_offset_vector::const_iterator iter; iter pos = std::lower_bound(id_offsets_.begin(), id_offsets_.end(), id, IDComparator()); return (pos != id_offsets_.end()) && (pos->first == id); }
bool edm::helper::IndexRangeAssociation::empty | ( | ) | const [inline] |
True if it's empty (no keys)
Definition at line 98 of file MultiAssociation.h.
References ref_offsets_.
Referenced by edm::MultiAssociation< C >::empty().
{ return ref_offsets_.empty(); }
IndexRangeAssociation::range IndexRangeAssociation::get | ( | const edm::ProductID & | id, |
unsigned int | t | ||
) | const |
Get a range of indices for this product id and key (non-template version) And end value of -1 means 'until the end of the other collection, AFAICT'
Definition at line 11 of file MultiAssociation.cc.
References Exception, id_offsets_, combine::key, pos, ref_offsets_, and edm::second().
Referenced by edm::MultiAssociation< C >::get().
{ typedef IndexRangeAssociation::id_offset_vector::const_iterator iter; iter pos = std::lower_bound(id_offsets_.begin(), id_offsets_.end(), id, IDComparator()); if ((pos == id_offsets_.end()) || (pos->first != id)) { throw cms::Exception("Bad Key") << "Product ID " << id << " not found in this IndexRangeAssociation\n"; } // === Do we want this check ? I would say yes, even if it costs some extra CPU cycles if ((pos + 1 != id_offsets_.end()) && (pos->second + key >= (pos+1)->second)) { throw cms::Exception("Bad Offset") << "Key " << key << " goes beyond bounds " << ((pos+1)->second - pos->second) << " of this key collection within IndexRangeAssociation\n"; } // === End check offset_vector::const_iterator offs = ref_offsets_.begin() + pos->second + key; if (offs >= ref_offsets_.end()-1) { throw cms::Exception("Bad Offset") << "Key " << key << " goes beyond bounds " << ref_offsets_.size()-1 << " of this IndexRangeAssociation\n"; } return range(*offs,*(offs+1)); }
range edm::helper::IndexRangeAssociation::operator[] | ( | const RefKey & | r | ) | const [inline] |
Get a range of indices for this key. RefKey can be edm::Ref, edm::Ptr, edm::RefToBase And end value of -1 means 'until the end of the other collection, AFAICT'
Definition at line 83 of file MultiAssociation.h.
unsigned int edm::helper::IndexRangeAssociation::size | ( | void | ) | const [inline] |
Size of this collection (number of keys)
Definition at line 95 of file MultiAssociation.h.
References ref_offsets_.
Referenced by edm::helper::IndexRangeAssociation::FastFiller::insert(), and edm::MultiAssociation< C >::size().
{ return ref_offsets_.empty() ? 0 : ref_offsets_.size() - 1; }
void IndexRangeAssociation::swap | ( | IndexRangeAssociation & | other | ) |
Definition at line 39 of file MultiAssociation.cc.
References Exception, id_offsets_, isFilling_, and ref_offsets_.
Referenced by edm::helper::swap(), and edm::MultiAssociation< C >::swap().
{ if (isFilling_ || other.isFilling_) throw cms::Exception("Busy") << "Can't swap an IndexRangeAssociation while it's being filled!\n"; id_offsets_.swap(other.id_offsets_); ref_offsets_.swap(other.ref_offsets_); }
void IndexRangeAssociation::throwUnexpectedProductID | ( | ProductID | found, |
ProductID | expected, | ||
const char * | where | ||
) | [static] |
Definition at line 116 of file MultiAssociation.cc.
References Exception.
Referenced by edm::helper::IndexRangeAssociation::FastFiller::insert(), edm::MultiAssociation< C >::LazyFiller::setValues(), and edm::MultiAssociation< C >::LazyFiller::swapValues().
{ throw cms::Exception("Unexpected ProductID") << where << ": found product id " << found << ", while expecting " << expected << ".\n" << "Make sure you're not mismatching references from different collections.\n"; }
friend class FastFiller [friend] |
Definition at line 127 of file MultiAssociation.h.
Definition at line 136 of file MultiAssociation.h.
Referenced by contains(), get(), and swap().
bool edm::helper::IndexRangeAssociation::isFilling_ [private] |
Definition at line 139 of file MultiAssociation.h.
Referenced by swap().