CMS 3D CMS Logo

Classes | Namespaces | Functions
associationMapFilterValues.h File Reference
#include "DataFormats/Common/interface/Ref.h"
#include "DataFormats/Common/interface/RefVector.h"
#include "DataFormats/Common/interface/View.h"
#include "DataFormats/Common/interface/AssociationMapHelpers.h"
#include "FWCore/Utilities/interface/IndexSet.h"

Go to the source code of this file.

Classes

struct  associationMapFilterValuesHelpers::FillIndices< T_RefVector >
 
struct  associationMapFilterValuesHelpers::FillIndices< edm::View< T > >
 
struct  associationMapFilterValuesHelpers::IfFound< ValueTag >
 
struct  associationMapFilterValuesHelpers::IfFound< edm::Ref< C, T, F > >
 
struct  associationMapFilterValuesHelpers::IfFound< edm::RefToBase< T > >
 
struct  associationMapFilterValuesHelpers::IfFound< edm::RefVector< C, T, F > >
 
struct  associationMapFilterValuesHelpers::IfFound< std::vector< std::pair< edm::Ref< C, T, F >, Q > > >
 
struct  associationMapFilterValuesHelpers::IfFound< std::vector< std::pair< edm::RefToBase< T >, Q > > >
 

Namespaces

 associationMapFilterValuesHelpers
 

Functions

template<typename T_AssociationMap , typename T_RefVector >
T_AssociationMap associationMapFilterValues (const T_AssociationMap &map, const T_RefVector &valueRefs)
 
template<typename T_AssociationMap , typename T_Key , typename T_ValueIndex , typename T_Value , typename T_ValueIndices >
void associationMapFilterValuesHelpers::findInsert (T_AssociationMap &ret, const T_Key &key, const T_ValueIndex &valueIndex, const T_Value &value, const T_ValueIndices &value_indices)
 

Function Documentation

template<typename T_AssociationMap , typename T_RefVector >
T_AssociationMap associationMapFilterValues ( const T_AssociationMap &  map,
const T_RefVector &  valueRefs 
)

Filters entries of AssociationMap by keeping only those associations that have a value in a given collection

Parameters
mapAssociationMap to filter
valueRefsCollection of Refs to values.
Template Parameters
T_AssociationMapType of the AssociationMap
T_RefVectorType of the Ref collection.

For AssociationMap<Tag<CKey, CVal>>, the collection of Refs can be RefVector<CVal>, vector<Ref<CVal>>, vector<RefToBase<CVal>>, or View<T>. More can be supported if needed.

Returns
A filtered copy of the AssociationMap

Throws if the values of AssociationMap and valueRefs point to different collections (similar check as in AssociationMap::operator[] for the keys).

Definition at line 127 of file associationMapFilterValues.h.

References associationMapFilterValuesHelpers::FillIndices< T_RefVector >::fill(), edm::eventsetup::heterocontainer::insert(), and edm::IndexSet::reserve().

Referenced by MultiTrackValidator::dqmAnalyze().

127  {
128  // If the input map is empty, just return it in order to avoid an
129  // exception from failing edm::helpers::checkRef() (in this case the
130  // refProd points to (0,0) that will fail the check).
131  if(map.empty())
132  return map;
133 
134  T_AssociationMap ret(map.refProd());
135 
136  // First copy the keys of values to a set for faster lookup of their existence in the map
137  edm::IndexSet value_indices;
138  value_indices.reserve(valueRefs.size()); // hopefully a good guess of the last ref index without having to do the gymnastics for genericity
139  associationMapFilterValuesHelpers::FillIndices<T_RefVector>::fill(value_indices, valueRefs, map.refProd());
140 
141  for(const auto& keyValue: map) {
143  }
144 
145 
146  return ret;
147 }
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
Definition: HCMethods.h:50
void reserve(unsigned int size)
Reserve memory for the set.
Definition: IndexSet.h:34
static void fill(T_Set &set, const T_RefVector &valueRefs, const T_RefProd &refProd)