File indexing completed on 2024-04-06 12:01:16
0001 #ifndef UtilAlgos_SelectionAdderTrait_h
0002 #define UtilAlgos_SelectionAdderTrait_h
0003
0004
0005
0006
0007 #include "DataFormats/Common/interface/Handle.h"
0008 #include "DataFormats/Common/interface/RefVector.h"
0009 #include "DataFormats/Common/interface/PtrVector.h"
0010 #include "DataFormats/Common/interface/RefToBaseVector.h"
0011 #include "DataFormats/Common/interface/RefToBaseProd.h"
0012 #include "DataFormats/Common/interface/RefProd.h"
0013 #include "DataFormats/Common/interface/AssociationVector.h"
0014
0015 namespace helper {
0016
0017 template <typename StoreContainer>
0018 struct SelectionCopyAdder {
0019 template <typename C>
0020 void operator()(StoreContainer &selected, const edm::Handle<C> &c, size_t idx) {
0021 selected.push_back((*c)[idx]);
0022 }
0023 };
0024
0025 template <typename StoreContainer>
0026 struct SelectionPointerAdder {
0027 template <typename C>
0028 void operator()(StoreContainer &selected, const edm::Handle<C> &c, size_t idx) {
0029 selected.push_back(&(*c)[idx]);
0030 }
0031 };
0032
0033 template <typename StoreContainer>
0034 struct SelectionPointerDerefAdder {
0035 template <typename C>
0036 void operator()(StoreContainer &selected, const edm::Handle<C> &c, size_t idx) {
0037 selected.push_back(&*(*c)[idx]);
0038 }
0039 };
0040
0041 template <typename StoreContainer>
0042 struct SelectionFirstPointerAdder {
0043 template <typename C>
0044 void operator()(StoreContainer &selected, const edm::Handle<C> &c, size_t idx) {
0045 selected.push_back(&*((*c)[idx].first));
0046 }
0047 };
0048
0049 template <typename StoreContainer>
0050 struct SelectionFirstRefAdder {
0051 template <typename C>
0052 void operator()(StoreContainer &selected, const edm::Handle<C> &c, size_t idx) {
0053 selected.push_back((*c)[idx].first);
0054 }
0055 };
0056
0057 template <typename StoreContainer>
0058 struct SelectionRefAdder {
0059 template <typename C>
0060 void operator()(StoreContainer &selected, const edm::Handle<C> &c, size_t idx) {
0061 selected.push_back(edm::Ref<C>(c, idx));
0062 }
0063 };
0064
0065 template <typename T>
0066 struct SelectionRefViewAdder {
0067 void operator()(edm::RefToBaseVector<T> &selected, const edm::Handle<edm::View<T> > &c, size_t idx) {
0068 selected.push_back(c->refAt(idx));
0069 }
0070 };
0071
0072 template <typename T>
0073 struct SelectionPtrViewAdder {
0074 void operator()(edm::PtrVector<T> &selected, const edm::Handle<edm::View<T> > &c, size_t idx) {
0075 selected.push_back(c->ptrAt(idx));
0076 }
0077 };
0078
0079 template <typename InputCollection, typename StoreContainer>
0080 struct SelectionAdderTrait {
0081 static_assert(sizeof(InputCollection) == 0);
0082 };
0083
0084 template <typename InputCollection, typename T>
0085 struct SelectionAdderTrait<InputCollection, std::vector<const T *> > {
0086 typedef SelectionPointerAdder<std::vector<const T *> > type;
0087 };
0088
0089 template <typename InputCollection, typename C>
0090 struct SelectionAdderTrait<InputCollection, edm::RefVector<C> > {
0091 typedef SelectionRefAdder<edm::RefVector<C> > type;
0092 };
0093
0094 template <typename C>
0095 struct SelectionAdderTrait<edm::RefVector<C>, edm::RefVector<C> > {
0096 typedef SelectionCopyAdder<edm::RefVector<C> > type;
0097 };
0098
0099 template <typename C, typename T>
0100 struct SelectionAdderTrait<edm::RefVector<C>, std::vector<const T *> > {
0101 typedef SelectionPointerDerefAdder<std::vector<const T *> > type;
0102 };
0103
0104 template <typename T>
0105 struct SelectionAdderTrait<edm::RefToBaseVector<T>, edm::RefToBaseVector<T> > {
0106 typedef SelectionCopyAdder<edm::RefToBaseVector<T> > type;
0107 };
0108
0109 template <typename T>
0110 struct SelectionAdderTrait<edm::RefToBaseVector<T>, std::vector<const T *> > {
0111 typedef SelectionPointerDerefAdder<std::vector<const T *> > type;
0112 };
0113
0114 template <typename K, typename C, typename T>
0115 struct SelectionAdderTrait<edm::AssociationVector<edm::RefProd<K>, C>, std::vector<const T *> > {
0116 typedef SelectionFirstPointerAdder<std::vector<const T *> > type;
0117 };
0118
0119 template <typename C, typename T>
0120 struct SelectionAdderTrait<edm::AssociationVector<edm::RefToBaseProd<T>, C>, std::vector<const T *> > {
0121 typedef SelectionFirstPointerAdder<std::vector<const T *> > type;
0122 };
0123
0124 template <typename K, typename C>
0125 struct SelectionAdderTrait<edm::AssociationVector<edm::RefProd<K>, C>, edm::RefVector<K> > {
0126 typedef SelectionFirstRefAdder<edm::RefVector<K> > type;
0127 };
0128
0129 template <typename T, typename C>
0130 struct SelectionAdderTrait<edm::AssociationVector<edm::RefToBaseProd<T>, C>, edm::RefToBaseVector<T> > {
0131 typedef SelectionFirstRefAdder<edm::RefToBaseVector<T> > type;
0132 };
0133
0134 template <typename T>
0135 struct SelectionAdderTrait<edm::View<T>, edm::RefToBaseVector<T> > {
0136 typedef SelectionRefViewAdder<T> type;
0137 };
0138
0139 template <typename T>
0140 struct SelectionAdderTrait<edm::View<T>, edm::PtrVector<T> > {
0141 typedef SelectionPtrViewAdder<T> type;
0142 };
0143
0144 }
0145
0146 #endif