1 #ifndef SimDataFormats_Associations_TICLAssociationMap_h 2 #define SimDataFormats_Associations_TICLAssociationMap_h 24 template <
typename MapType,
typename Collection1 =
void,
typename Collection2 =
void>
29 typename std::conditional_t<std::is_void_v<Collection1> || std::is_void_v<Collection2>,
36 template <
typename C1 = Collection1,
37 typename C2 = Collection2,
38 typename std::enable_if_t<std::is_void_v<C1> && std::is_void_v<C2>,
int> = 0>
44 template <
typename C1 = Collection1,
45 typename C2 = Collection2,
46 typename std::enable_if_t<!std::is_void_v<C1> && !std::is_void_v<C2>,
int> = 0>
53 template <
typename C1 = Collection1,
54 typename C2 = Collection2,
55 typename std::enable_if_t<!std::is_void_v<C1> && !std::is_void_v<C2>,
int> = 0>
66 template <
typename C1 = Collection1,
67 typename C2 = Collection2,
68 typename std::enable_if_t<!std::is_void_v<C1> && !std::is_void_v<C2>,
int> = 0>
73 template <
typename C1 = Collection1,
74 typename C2 = Collection2,
75 typename std::enable_if_t<!std::is_void_v<C1> && !std::is_void_v<C2>,
int> = 0>
81 template <
typename C1 = Collection1,
82 typename C2 = Collection2,
83 typename std::enable_if_t<!std::is_void_v<C1> && !std::is_void_v<C2>,
int> = 0>
90 if (index1 >=
map_.size()) {
91 map_.resize(index1 + 1);
93 auto& vec =
map_[index1];
94 auto it = std::find_if(vec.begin(), vec.end(), [&](
const auto& pair) {
return pair.first == index2; });
95 if (
it != vec.end()) {
101 if (index1 >=
map_.size()) {
102 map_.resize(index1 + 1);
104 auto& vec =
map_[index1];
105 auto it = std::find_if(vec.begin(), vec.end(), [&](
const auto& pair) {
return pair.first == index2; });
106 if (
it != vec.end()) {
113 auto it = std::find_if(
map_.begin(),
map_.end(), [&](
const auto& pair) {
return pair.first == index1; });
120 auto it = std::find_if(
map_.begin(),
map_.end(), [&](
const auto& pair) {
return pair.first == index1; });
131 template <
typename C1 = Collection1,
132 typename C2 = Collection2,
133 typename std::enable_if_t<!std::is_void_v<C1> && !std::is_void_v<C2>,
int> = 0>
138 void sort(
bool byScore =
false) {
139 static_assert(!std::is_same_v<MapType, oneToOneMapWithFraction> &&
140 !std::is_same_v<MapType, oneToOneMapWithFractionAndScore>,
141 "Sort is not applicable for one-to-one maps");
143 if constexpr (std::is_same_v<MapType, mapWithFraction>) {
144 for (
auto& vec :
map_) {
145 std::sort(vec.begin(), vec.end(), [](
const auto&
a,
const auto&
b) {
return a.second >
b.second; });
147 }
else if constexpr (std::is_same_v<MapType, mapWithFractionAndScore>) {
148 for (
auto& vec :
map_) {
151 vec.begin(), vec.end(), [](
const auto&
a,
const auto&
b) {
return a.second.second >
b.second.second; });
154 vec.begin(), vec.end(), [](
const auto&
a,
const auto&
b) {
return a.second.first >
b.second.first; });
164 const auto&
at(
unsigned int index1)
const {
165 if (index1 >=
map_.size()) {
166 throw std::out_of_range(
"Index out of range");
171 auto&
at(
unsigned int index1) {
172 if (index1 >=
map_.size()) {
173 throw std::out_of_range(
"Index out of range");
178 template <
typename C1 = Collection1,
179 typename C2 = Collection2,
180 typename std::enable_if_t<!std::is_void_v<C1> && !std::is_void_v<C2>,
int> = 0>
185 template <
typename C1 = Collection1,
186 typename C2 = Collection2,
187 typename std::enable_if_t<std::is_void_v<C1> && std::is_void_v<C2>,
int> = 0>
194 for (
size_t i = 0;
i <
map_.size(); ++
i) {
195 os <<
"Index " <<
i <<
":\n";
196 for (
const auto& pair :
map_[
i]) {
197 os <<
" (" << pair.first <<
", ";
200 os << pair.second.first <<
", " << pair.second.second;
const auto & operator[](unsigned int index1) const
AssociationMap(const edm::Handle< C1 > &handle1, const edm::Handle< C2 > &handle2, const edm::Event &event)
const MapType & getMap() const
CollectionRefProdType collectionRefProds
void resize(const edm::Event &event)
AssociationMap(const unsigned int size1=0)
void insert(unsigned int index1, unsigned int index2, float fraction, float score=0.0f)
edm::Ref< C1 > getRefFirst(unsigned int index) const
key_type key() const
Accessor for product key.
const auto & at(unsigned int index1) const
std::vector< std::vector< std::pair< unsigned int, float > >> mapWithFraction
typename std::conditional_t< std::is_void_v< Collection1 >||std::is_void_v< Collection2 >, std::monostate, std::pair< edm::RefProd< Collection1 >, edm::RefProd< Collection2 > >> CollectionRefProdType
auto & operator[](unsigned int index1)
std::vector< std::pair< unsigned int, float > > oneToOneMapWithFraction
std::vector< std::vector< std::pair< unsigned int, std::pair< float, float > >> > mapWithFractionAndScore
void print(std::ostream &os) const
std::vector< std::pair< unsigned int, std::pair< float, float > >> oneToOneMapWithFractionAndScore
void sort(bool byScore=false)
edm::RefProd< Container > RefProd
void insert(const edm::Ref< C1 > &ref1, const edm::Ref< C2 > &ref2, float fraction, float score=0.0f)
AssociationMap(const edm::RefProd< C1 > &id1, const edm::RefProd< C2 > &id2, const edm::Event &event)
edm::Ref< C2 > getRefSecond(unsigned int index) const
void resize(const unsigned int size1)
auto & at(unsigned int index1)
std::pair< const edm::RefProd< C1 >, const edm::RefProd< C2 > > getCollectionIDs() const