File indexing completed on 2023-03-17 11:02:51
0001
0002
0003
0004
0005 #include "DataFormats/Common/interface/AssociationMap.h"
0006 #include "DataFormats/Common/interface/OneToOne.h"
0007 #include "DataFormats/Common/interface/Handle.h"
0008 #include "FWCore/Framework/interface/global/EDAnalyzer.h"
0009 #include "FWCore/Framework/interface/Event.h"
0010 #include "FWCore/Framework/interface/MakerMacros.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 #include "FWCore/Utilities/interface/EDGetToken.h"
0013 #include "FWCore/Utilities/interface/InputTag.h"
0014
0015 #include <vector>
0016
0017 namespace edm {
0018 class EventSetup;
0019 class StreamID;
0020 }
0021
0022 namespace edmtest {
0023
0024 class AssociationMapAnalyzer : public edm::global::EDAnalyzer<> {
0025 public:
0026 typedef edm::AssociationMap<edm::OneToValue<std::vector<int>, double>> AssocOneToValue;
0027 typedef edm::AssociationMap<edm::OneToOne<std::vector<int>, std::vector<int>>> AssocOneToOne;
0028 typedef edm::AssociationMap<edm::OneToMany<std::vector<int>, std::vector<int>>> AssocOneToMany;
0029 typedef edm::AssociationMap<edm::OneToManyWithQuality<std::vector<int>, std::vector<int>, double>>
0030 AssocOneToManyWithQuality;
0031 typedef edm::AssociationMap<edm::OneToOne<edm::View<int>, edm::View<int>>> AssocOneToOneView;
0032
0033 explicit AssociationMapAnalyzer(edm::ParameterSet const&);
0034 void analyze(edm::StreamID, edm::Event const& event, edm::EventSetup const&) const override;
0035
0036 edm::EDGetTokenT<std::vector<int>> inputToken1_;
0037 edm::EDGetTokenT<std::vector<int>> inputToken2_;
0038 edm::EDGetTokenT<edm::View<int>> inputToken1V_;
0039 edm::EDGetTokenT<edm::View<int>> inputToken2V_;
0040
0041 edm::EDGetTokenT<AssocOneToOne> associationMapToken1_;
0042 edm::EDGetTokenT<AssocOneToOne> associationMapToken2_;
0043 edm::EDGetTokenT<AssocOneToValue> associationMapToken3_;
0044 edm::EDGetTokenT<AssocOneToValue> associationMapToken4_;
0045 edm::EDGetTokenT<AssocOneToMany> associationMapToken5_;
0046 edm::EDGetTokenT<AssocOneToManyWithQuality> associationMapToken6_;
0047 edm::EDGetTokenT<AssocOneToOneView> associationMapToken7_;
0048 edm::EDGetTokenT<AssocOneToOneView> associationMapToken8_;
0049 };
0050
0051 AssociationMapAnalyzer::AssociationMapAnalyzer(edm::ParameterSet const& pset) {
0052 inputToken1_ = consumes<std::vector<int>>(pset.getParameter<edm::InputTag>("inputTag1"));
0053 inputToken2_ = consumes<std::vector<int>>(pset.getParameter<edm::InputTag>("inputTag2"));
0054 inputToken1V_ = consumes<edm::View<int>>(pset.getParameter<edm::InputTag>("inputTag1"));
0055 inputToken2V_ = consumes<edm::View<int>>(pset.getParameter<edm::InputTag>("inputTag2"));
0056 associationMapToken1_ = consumes<AssocOneToOne>(pset.getParameter<edm::InputTag>("associationMapTag1"));
0057 associationMapToken2_ = consumes<AssocOneToOne>(pset.getParameter<edm::InputTag>("associationMapTag2"));
0058 associationMapToken3_ = consumes<AssocOneToValue>(pset.getParameter<edm::InputTag>("associationMapTag3"));
0059 associationMapToken4_ = consumes<AssocOneToValue>(pset.getParameter<edm::InputTag>("associationMapTag4"));
0060 associationMapToken5_ = consumes<AssocOneToMany>(pset.getParameter<edm::InputTag>("associationMapTag5"));
0061 associationMapToken6_ = consumes<AssocOneToManyWithQuality>(pset.getParameter<edm::InputTag>("associationMapTag6"));
0062 associationMapToken7_ = consumes<AssocOneToOneView>(pset.getParameter<edm::InputTag>("associationMapTag7"));
0063 associationMapToken8_ = consumes<AssocOneToOneView>(pset.getParameter<edm::InputTag>("associationMapTag8"));
0064 }
0065
0066 void AssociationMapAnalyzer::analyze(edm::StreamID, edm::Event const& event, edm::EventSetup const&) const {
0067 edm::Handle<std::vector<int>> inputCollection1 = event.getHandle(inputToken1_);
0068
0069 edm::Handle<std::vector<int>> inputCollection2 = event.getHandle(inputToken2_);
0070
0071
0072
0073
0074
0075
0076 AssocOneToOne const& associationMap1 = event.get(associationMapToken1_);
0077
0078 if (*associationMap1[edm::Ref<std::vector<int>>(inputCollection1, 0)] != 22 ||
0079 *associationMap1[edm::Ref<std::vector<int>>(inputCollection1, 2)] != 24 ||
0080 *associationMap1[edm::Ptr<int>(inputCollection1, 0)] != 22 ||
0081 *associationMap1[edm::Ptr<int>(inputCollection1, 2)] != 24) {
0082 throw cms::Exception("TestFailure") << "unexpected result after using AssociationMap 1";
0083 }
0084 AssocOneToOne::const_iterator iter = associationMap1.begin();
0085 if (*iter->val != 22 || iter->key != edm::Ref<std::vector<int>>(inputCollection1, 0)) {
0086 throw cms::Exception("TestFailure") << "unexpected result after using AssociationMap 2";
0087 }
0088 ++iter;
0089 if (*iter->val != 24 || iter->key != edm::Ref<std::vector<int>>(inputCollection1, 2)) {
0090 throw cms::Exception("TestFailure") << "unexpected result after using AssociationMap 3";
0091 }
0092 ++iter;
0093 if (iter != associationMap1.end()) {
0094 throw cms::Exception("TestFailure") << "unexpected result after using AssociationMap 4";
0095 }
0096
0097
0098 AssocOneToOne const& associationMap2 = event.get(associationMapToken2_);
0099
0100 if (*associationMap2[edm::Ref<std::vector<int>>(inputCollection1, 0)] != 22 ||
0101 *associationMap2[edm::Ref<std::vector<int>>(inputCollection1, 2)] != 25 ||
0102 *associationMap2[edm::Ptr<int>(inputCollection1, 0)] != 22 ||
0103 *associationMap2[edm::Ptr<int>(inputCollection1, 2)] != 25) {
0104 throw cms::Exception("TestFailure") << "unexpected result after using AssociationMap 5";
0105 }
0106
0107 AssocOneToOne::const_iterator iter2 = associationMap2.begin();
0108 ++iter2;
0109 if (*iter2->val != 25 || iter2->key != edm::Ref<std::vector<int>>(inputCollection1, 2)) {
0110 throw cms::Exception("TestFailure") << "unexpected result after using AssociationMap 6";
0111 }
0112
0113
0114
0115 AssocOneToValue const& associationMap3 = event.get(associationMapToken3_);
0116
0117 if (associationMap3[edm::Ref<std::vector<int>>(inputCollection1, 0)] != 11.0 ||
0118 associationMap3[edm::Ref<std::vector<int>>(inputCollection1, 2)] != 12.0 ||
0119 associationMap3[edm::Ptr<int>(inputCollection1, 0)] != 11.0 ||
0120 associationMap3[edm::Ptr<int>(inputCollection1, 2)] != 12.0) {
0121 throw cms::Exception("TestFailure") << "unexpected result after using AssociationMap 7";
0122 }
0123 AssocOneToValue::const_iterator iter3 = associationMap3.begin();
0124 ++iter3;
0125 if (iter3->val != 12.0 || iter3->key != edm::Ref<std::vector<int>>(inputCollection1, 2)) {
0126 throw cms::Exception("TestFailure") << "unexpected result after using AssociationMap 8";
0127 }
0128
0129
0130
0131 AssocOneToValue const& associationMap4 = event.get(associationMapToken4_);
0132
0133 if (associationMap4[edm::Ref<std::vector<int>>(inputCollection1, 0)] != 21.0 ||
0134 associationMap4[edm::Ref<std::vector<int>>(inputCollection1, 2)] != 22.0 ||
0135 associationMap4[edm::Ptr<int>(inputCollection1, 0)] != 21.0 ||
0136 associationMap4[edm::Ptr<int>(inputCollection1, 2)] != 22.0) {
0137 throw cms::Exception("TestFailure") << "unexpected result after using AssociationMap 9";
0138 }
0139 AssocOneToValue::const_iterator iter4 = associationMap4.begin();
0140 ++iter4;
0141 if (iter4->val != 22.0 || iter4->key != edm::Ref<std::vector<int>>(inputCollection1, 2)) {
0142 throw cms::Exception("TestFailure") << "unexpected result after using AssociationMap 10";
0143 }
0144
0145
0146
0147 AssocOneToMany const& associationMap5 = event.get(associationMapToken5_);
0148
0149 if (*associationMap5[edm::Ref<std::vector<int>>(inputCollection1, 0)].at(0) != 22 ||
0150 *associationMap5[edm::Ref<std::vector<int>>(inputCollection1, 2)].at(1) != 27 ||
0151 *associationMap5[edm::Ptr<int>(inputCollection1, 0)].at(0) != 22 ||
0152 *associationMap5[edm::Ptr<int>(inputCollection1, 2)].at(1) != 27) {
0153 throw cms::Exception("TestFailure") << "unexpected result after using AssociationMap 11";
0154 }
0155 AssocOneToMany::const_iterator iter5 = associationMap5.begin();
0156 ++iter5;
0157 if (*iter5->val.at(1) != 27 || iter5->key != edm::Ref<std::vector<int>>(inputCollection1, 2)) {
0158 throw cms::Exception("TestFailure") << "unexpected result after using AssociationMap 12";
0159 }
0160
0161
0162
0163 AssocOneToManyWithQuality const& associationMap6 = event.get(associationMapToken6_);
0164 if (*associationMap6[edm::Ref<std::vector<int>>(inputCollection1, 0)].at(0).first != 22 ||
0165 *associationMap6[edm::Ref<std::vector<int>>(inputCollection1, 2)].at(1).first != 25 ||
0166 *associationMap6[edm::Ptr<int>(inputCollection1, 0)].at(0).first != 22 ||
0167 *associationMap6[edm::Ptr<int>(inputCollection1, 2)].at(1).first != 25 ||
0168 associationMap6[edm::Ref<std::vector<int>>(inputCollection1, 0)].at(0).second != 31.0 ||
0169 associationMap6[edm::Ref<std::vector<int>>(inputCollection1, 2)].at(1).second != 32.0 ||
0170 associationMap6[edm::Ptr<int>(inputCollection1, 0)].at(0).second != 31.0 ||
0171 associationMap6[edm::Ptr<int>(inputCollection1, 2)].at(1).second != 32.0) {
0172 throw cms::Exception("TestFailure") << "unexpected result after using AssociationMap 13";
0173 }
0174 AssocOneToManyWithQuality::const_iterator iter6 = associationMap6.begin();
0175 ++iter6;
0176 if (*iter6->val.at(1).first != 25 || iter6->val.at(1).second != 32.0 ||
0177 iter6->key != edm::Ref<std::vector<int>>(inputCollection1, 2)) {
0178 throw cms::Exception("TestFailure") << "unexpected result after using AssociationMap 14";
0179 }
0180
0181
0182
0183 edm::View<int> const& inputView1 = event.get(inputToken1V_);
0184
0185 edm::Handle<edm::View<int>> inputView2 = event.getHandle(inputToken2V_);
0186
0187 AssocOneToOneView const& associationMap7 = event.get(associationMapToken7_);
0188 if (*associationMap7[inputView1.refAt(0)] != 24 || *associationMap7[inputView1.refAt(2)] != 25) {
0189 throw cms::Exception("TestFailure") << "unexpected result after using AssociationMap 15";
0190 }
0191 AssocOneToOneView::const_iterator iter7 = associationMap7.begin();
0192 ++iter7;
0193 if (*iter7->val != 25 || iter7->key != inputView1.refAt(2)) {
0194 throw cms::Exception("TestFailure") << "unexpected result after using AssociationMap 16";
0195 }
0196
0197
0198
0199 AssocOneToOneView const& associationMap8 = event.get(associationMapToken8_);
0200 if (*associationMap8[inputView1.refAt(0)] != 26 || *associationMap8[inputView1.refAt(2)] != 27) {
0201 throw cms::Exception("TestFailure") << "unexpected result after using AssociationMap 17";
0202 }
0203 AssocOneToOneView::const_iterator iter8 = associationMap8.begin();
0204 ++iter8;
0205 if (*iter8->val != 27 || iter8->key != inputView1.refAt(2)) {
0206 throw cms::Exception("TestFailure") << "unexpected result after using AssociationMap 18";
0207 }
0208 }
0209 }
0210 using edmtest::AssociationMapAnalyzer;
0211 DEFINE_FWK_MODULE(AssociationMapAnalyzer);