Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:02:36

0001 // -*- C++ -*-
0002 //
0003 // Package:     Package
0004 // Class  :     edconsumerbase_t
0005 //
0006 // Implementation:
0007 //     [Notes on implementation]
0008 //
0009 // Original Author:  Chris Jones
0010 //         Created:  Sat, 06 Apr 2013 16:39:12 GMT
0011 //
0012 
0013 // system include files
0014 #include <vector>
0015 #include <iostream>
0016 
0017 // user include files
0018 #include "cppunit/extensions/HelperMacros.h"
0019 #include "FWCore/Framework/interface/EDConsumerBase.h"
0020 #include "FWCore/Framework/interface/ConsumesCollector.h"
0021 #include "FWCore/Framework/interface/ProductResolverIndexAndSkipBit.h"
0022 
0023 #include "FWCore/Utilities/interface/EDGetToken.h"
0024 #include "FWCore/Utilities/interface/TypeToGet.h"
0025 
0026 #include "DataFormats/Provenance/interface/ProductResolverIndexHelper.h"
0027 #include "DataFormats/TestObjects/interface/ToyProducts.h"
0028 
0029 #include "DataFormats/Provenance/interface/EventID.h"
0030 #include "DataFormats/Provenance/interface/ProductID.h"
0031 
0032 #include "DataFormats/Common/interface/View.h"
0033 
0034 class TestEDConsumerBase : public CppUnit::TestFixture {
0035 public:
0036   CPPUNIT_TEST_SUITE(TestEDConsumerBase);
0037   CPPUNIT_TEST(testRegularType);
0038   CPPUNIT_TEST(testViewType);
0039   CPPUNIT_TEST(testMany);
0040   CPPUNIT_TEST(testMay);
0041   CPPUNIT_TEST_SUITE_END();
0042 
0043 public:
0044   void setUp();
0045   void tearDown() {}
0046 
0047   void testRegularType();
0048   void testViewType();
0049   void testMany();
0050   void testMay();
0051 };
0052 
0053 ///registration of the test so that the runner can find it
0054 CPPUNIT_TEST_SUITE_REGISTRATION(TestEDConsumerBase);
0055 
0056 void TestEDConsumerBase::setUp() {}
0057 
0058 namespace {
0059   class IntsConsumer : public edm::EDConsumerBase {
0060   public:
0061     IntsConsumer(std::vector<edm::InputTag> const& iTags) {
0062       m_tokens.reserve(iTags.size());
0063       for (auto const& tag : iTags) {
0064         m_tokens.emplace_back(consumes(tag));
0065       }
0066     }
0067 
0068     std::vector<edm::EDGetTokenT<std::vector<int>>> m_tokens;
0069   };
0070 
0071   class IntsMayConsumer : public edm::EDConsumerBase {
0072   public:
0073     IntsMayConsumer(std::vector<edm::InputTag> const& iTags, std::vector<edm::InputTag> const& iMayTags) {
0074       m_tokens.reserve(iTags.size());
0075       m_mayTokens.reserve(iMayTags.size());
0076       for (auto const& tag : iTags) {
0077         m_tokens.emplace_back(consumes(tag));
0078       }
0079       for (auto const& tag : iMayTags) {
0080         m_mayTokens.push_back(mayConsume<std::vector<int>>(tag));
0081       }
0082     }
0083 
0084     std::vector<edm::EDGetTokenT<std::vector<int>>> m_tokens;
0085     std::vector<edm::EDGetTokenT<std::vector<int>>> m_mayTokens;
0086   };
0087 
0088   class TypeToGetConsumer : public edm::EDConsumerBase {
0089   public:
0090     TypeToGetConsumer(std::vector<std::pair<edm::TypeToGet, edm::InputTag>> const& iTags) {
0091       m_tokens.reserve(iTags.size());
0092       for (auto const& typeTag : iTags) {
0093         m_tokens.push_back(consumes(typeTag.first, typeTag.second));
0094       }
0095     }
0096 
0097     std::vector<edm::EDGetToken> m_tokens;
0098   };
0099 
0100   class IntsConsumesCollectorConsumer : public edm::EDConsumerBase {
0101   public:
0102     IntsConsumesCollectorConsumer(std::vector<edm::InputTag> const& iTags) {
0103       m_tokens.reserve(iTags.size());
0104       edm::ConsumesCollector collector{consumesCollector()};
0105       edm::ConsumesCollector collectorCopy(collector);
0106       edm::ConsumesCollector collectorCopy1(collector);
0107       edm::ConsumesCollector collectorCopy2(collector);
0108       collectorCopy1 = collectorCopy;
0109       collectorCopy2 = std::move(collectorCopy1);
0110 
0111       for (auto const& tag : iTags) {
0112         m_tokens.emplace_back(collectorCopy2.consumes(tag));
0113       }
0114     }
0115 
0116     std::vector<edm::EDGetTokenT<std::vector<int>>> m_tokens;
0117   };
0118 
0119 }  // namespace
0120 
0121 void TestEDConsumerBase::testRegularType() {
0122   edm::ProductResolverIndexHelper helper;
0123 
0124   edm::TypeID typeIDProductID(typeid(edm::ProductID));
0125   edm::TypeID typeIDEventID(typeid(edm::EventID));
0126   edm::TypeID typeIDVectorInt(typeid(std::vector<int>));
0127   edm::TypeID typeIDSetInt(typeid(std::set<int>));
0128   edm::TypeID typeIDVSimpleDerived(typeid(std::vector<edmtest::SimpleDerived>));
0129 
0130   helper.insert(typeIDVectorInt, "labelC", "instanceC", "processC");       // 0, 1, 2
0131   helper.insert(typeIDVectorInt, "label", "instance", "process");          // 3, 4, 5
0132   helper.insert(typeIDEventID, "labelB", "instanceB", "processB");         // 6, 7
0133   helper.insert(typeIDEventID, "label", "instanceB", "processB");          // 8, 9
0134   helper.insert(typeIDEventID, "labelX", "instanceB", "processB");         // 10, 11
0135   helper.insert(typeIDEventID, "labelB", "instance", "processB");          // 12, 13
0136   helper.insert(typeIDEventID, "labelB", "instanceX", "processB");         // 14, 15
0137   helper.insert(typeIDEventID, "labelB", "instanceB", "processB1");        // 16, 5
0138   helper.insert(typeIDEventID, "labelB", "instanceB", "processB3");        // 17, 5
0139   helper.insert(typeIDEventID, "labelB", "instanceB", "processB2");        // 18, 5
0140   helper.insert(typeIDProductID, "label", "instance", "process");          // 19, 20
0141   helper.insert(typeIDEventID, "label", "instance", "process");            // 21, 22
0142   helper.insert(typeIDProductID, "labelA", "instanceA", "processA");       // 23, 24
0143   helper.insert(typeIDSetInt, "labelC", "instanceC", "processC");          // 25, 26
0144   helper.insert(typeIDVSimpleDerived, "labelC", "instanceC", "processC");  // 27, 28, 29, 30
0145 
0146   helper.setFrozen();
0147 
0148   edm::TypeID typeID_vint(typeid(std::vector<int>));
0149   const auto vint_c = helper.index(edm::PRODUCT_TYPE, typeID_vint, "labelC", "instanceC", "processC");
0150   const auto vint_c_no_proc = helper.index(edm::PRODUCT_TYPE, typeID_vint, "labelC", "instanceC", 0);
0151   const auto vint_blank = helper.index(edm::PRODUCT_TYPE, typeID_vint, "label", "instance", "process");
0152   const auto vint_blank_no_proc = helper.index(edm::PRODUCT_TYPE, typeID_vint, "label", "instance", 0);
0153   {
0154     std::vector<edm::InputTag> vTags = {{"label", "instance", "process"}, {"labelC", "instanceC", "processC"}};
0155     IntsConsumer intConsumer{vTags};
0156     intConsumer.updateLookup(edm::InEvent, helper, false);
0157 
0158     CPPUNIT_ASSERT(intConsumer.m_tokens[0].index() == 0);
0159     CPPUNIT_ASSERT(intConsumer.m_tokens[1].index() == 1);
0160 
0161     CPPUNIT_ASSERT(vint_c ==
0162                    intConsumer.indexFrom(intConsumer.m_tokens[1], edm::InEvent, typeID_vint).productResolverIndex());
0163     CPPUNIT_ASSERT(vint_blank ==
0164                    intConsumer.indexFrom(intConsumer.m_tokens[0], edm::InEvent, typeID_vint).productResolverIndex());
0165 
0166     std::vector<edm::ProductResolverIndexAndSkipBit> indices;
0167     intConsumer.itemsToGet(edm::InEvent, indices);
0168 
0169     CPPUNIT_ASSERT(2 == indices.size());
0170     CPPUNIT_ASSERT(indices.end() !=
0171                    std::find(indices.begin(), indices.end(), edm::ProductResolverIndexAndSkipBit(vint_c, false)));
0172     CPPUNIT_ASSERT(indices.end() !=
0173                    std::find(indices.begin(), indices.end(), edm::ProductResolverIndexAndSkipBit(vint_blank, false)));
0174 
0175     std::vector<edm::ProductResolverIndexAndSkipBit> indicesMay;
0176     intConsumer.itemsMayGet(edm::InEvent, indicesMay);
0177     CPPUNIT_ASSERT(0 == indicesMay.size());
0178   }
0179   {
0180     std::vector<edm::InputTag> vTags = {{"label", "instance", "process"}, {"labelC", "instanceC", "processC"}};
0181     IntsConsumesCollectorConsumer intConsumer{vTags};
0182     intConsumer.updateLookup(edm::InEvent, helper, false);
0183 
0184     CPPUNIT_ASSERT(intConsumer.m_tokens[0].index() == 0);
0185     CPPUNIT_ASSERT(intConsumer.m_tokens[1].index() == 1);
0186 
0187     CPPUNIT_ASSERT(vint_c ==
0188                    intConsumer.indexFrom(intConsumer.m_tokens[1], edm::InEvent, typeID_vint).productResolverIndex());
0189     CPPUNIT_ASSERT(vint_blank ==
0190                    intConsumer.indexFrom(intConsumer.m_tokens[0], edm::InEvent, typeID_vint).productResolverIndex());
0191 
0192     std::vector<edm::ProductResolverIndexAndSkipBit> indices;
0193     intConsumer.itemsToGet(edm::InEvent, indices);
0194 
0195     CPPUNIT_ASSERT(2 == indices.size());
0196     CPPUNIT_ASSERT(indices.end() !=
0197                    std::find(indices.begin(), indices.end(), edm::ProductResolverIndexAndSkipBit(vint_c, false)));
0198     CPPUNIT_ASSERT(indices.end() !=
0199                    std::find(indices.begin(), indices.end(), edm::ProductResolverIndexAndSkipBit(vint_blank, false)));
0200 
0201     std::vector<edm::ProductResolverIndexAndSkipBit> indicesMay;
0202     intConsumer.itemsMayGet(edm::InEvent, indicesMay);
0203     CPPUNIT_ASSERT(0 == indicesMay.size());
0204   }
0205   {
0206     std::vector<edm::InputTag> vTagsRev = {{"labelC", "instanceC", "processC"}, {"label", "instance", "process"}};
0207     IntsConsumer intConsumerRev{vTagsRev};
0208     intConsumerRev.updateLookup(edm::InEvent, helper, false);
0209 
0210     CPPUNIT_ASSERT(intConsumerRev.m_tokens[0].index() == 0);
0211     CPPUNIT_ASSERT(intConsumerRev.m_tokens[1].index() == 1);
0212 
0213     CPPUNIT_ASSERT(
0214         vint_c ==
0215         intConsumerRev.indexFrom(intConsumerRev.m_tokens[0], edm::InEvent, typeID_vint).productResolverIndex());
0216     CPPUNIT_ASSERT(
0217         vint_blank ==
0218         intConsumerRev.indexFrom(intConsumerRev.m_tokens[1], edm::InEvent, typeID_vint).productResolverIndex());
0219 
0220     std::vector<edm::ProductResolverIndexAndSkipBit> indices;
0221     intConsumerRev.itemsToGet(edm::InEvent, indices);
0222 
0223     CPPUNIT_ASSERT(2 == indices.size());
0224     CPPUNIT_ASSERT(indices.end() !=
0225                    std::find(indices.begin(), indices.end(), edm::ProductResolverIndexAndSkipBit(vint_c, false)));
0226     CPPUNIT_ASSERT(indices.end() !=
0227                    std::find(indices.begin(), indices.end(), edm::ProductResolverIndexAndSkipBit(vint_blank, false)));
0228 
0229     std::vector<edm::ProductResolverIndexAndSkipBit> indicesMay;
0230     intConsumerRev.itemsMayGet(edm::InEvent, indicesMay);
0231     CPPUNIT_ASSERT(0 == indicesMay.size());
0232   }
0233   {
0234     std::vector<edm::InputTag> vTagsRev = {{"labelC", "instanceC", "processC"}, {"label", "instance", "process"}};
0235     IntsConsumesCollectorConsumer intConsumerRev{vTagsRev};
0236     intConsumerRev.updateLookup(edm::InEvent, helper, false);
0237 
0238     CPPUNIT_ASSERT(intConsumerRev.m_tokens[0].index() == 0);
0239     CPPUNIT_ASSERT(intConsumerRev.m_tokens[1].index() == 1);
0240 
0241     CPPUNIT_ASSERT(edm::ProductResolverIndexAndSkipBit(vint_c, false) ==
0242                    intConsumerRev.indexFrom(intConsumerRev.m_tokens[0], edm::InEvent, typeID_vint));
0243     CPPUNIT_ASSERT(edm::ProductResolverIndexAndSkipBit(vint_blank, false) ==
0244                    intConsumerRev.indexFrom(intConsumerRev.m_tokens[1], edm::InEvent, typeID_vint));
0245 
0246     std::vector<edm::ProductResolverIndexAndSkipBit> indices;
0247     intConsumerRev.itemsToGet(edm::InEvent, indices);
0248 
0249     CPPUNIT_ASSERT(2 == indices.size());
0250     CPPUNIT_ASSERT(indices.end() !=
0251                    std::find(indices.begin(), indices.end(), edm::ProductResolverIndexAndSkipBit(vint_c, false)));
0252     CPPUNIT_ASSERT(indices.end() !=
0253                    std::find(indices.begin(), indices.end(), edm::ProductResolverIndexAndSkipBit(vint_blank, false)));
0254 
0255     std::vector<edm::ProductResolverIndexAndSkipBit> indicesMay;
0256     intConsumerRev.itemsMayGet(edm::InEvent, indicesMay);
0257     CPPUNIT_ASSERT(0 == indicesMay.size());
0258   }
0259   {
0260     //test default process
0261     std::vector<edm::InputTag> vTags = {{"label", "instance"}, {"labelC", "instanceC", "@skipCurrentProcess"}};
0262     IntsConsumer intConsumer{vTags};
0263     intConsumer.updateLookup(edm::InEvent, helper, false);
0264 
0265     CPPUNIT_ASSERT(intConsumer.m_tokens[0].index() == 0);
0266     CPPUNIT_ASSERT(intConsumer.m_tokens[1].index() == 1);
0267 
0268     CPPUNIT_ASSERT(edm::ProductResolverIndexAndSkipBit(vint_c_no_proc, true) ==
0269                    intConsumer.indexFrom(intConsumer.m_tokens[1], edm::InEvent, typeID_vint));
0270     CPPUNIT_ASSERT(edm::ProductResolverIndexAndSkipBit(vint_blank_no_proc, false) ==
0271                    intConsumer.indexFrom(intConsumer.m_tokens[0], edm::InEvent, typeID_vint));
0272 
0273     std::vector<edm::ProductResolverIndexAndSkipBit> indices;
0274     intConsumer.itemsToGet(edm::InEvent, indices);
0275 
0276     CPPUNIT_ASSERT(2 == indices.size());
0277     CPPUNIT_ASSERT(indices.end() != std::find(indices.begin(),
0278                                               indices.end(),
0279                                               edm::ProductResolverIndexAndSkipBit(vint_c_no_proc, true)));
0280     CPPUNIT_ASSERT(indices.end() != std::find(indices.begin(),
0281                                               indices.end(),
0282                                               edm::ProductResolverIndexAndSkipBit(vint_blank_no_proc, false)));
0283 
0284     std::vector<edm::ProductResolverIndexAndSkipBit> indicesMay;
0285     intConsumer.itemsMayGet(edm::InEvent, indicesMay);
0286     CPPUNIT_ASSERT(0 == indicesMay.size());
0287   }
0288   {
0289     //Ask for something that doesn't exist
0290     std::vector<edm::InputTag> vTags = {{"notHere"}};
0291     IntsConsumer intConsumer{vTags};
0292     intConsumer.updateLookup(edm::InEvent, helper, false);
0293 
0294     CPPUNIT_ASSERT(intConsumer.m_tokens[0].index() == 0);
0295     CPPUNIT_ASSERT(edm::ProductResolverIndexInvalid ==
0296                    intConsumer.indexFrom(intConsumer.m_tokens[0], edm::InEvent, typeID_vint).productResolverIndex());
0297 
0298     std::vector<edm::ProductResolverIndexAndSkipBit> indices;
0299     intConsumer.itemsToGet(edm::InEvent, indices);
0300     //nothing to get since not here
0301     CPPUNIT_ASSERT(0 == indices.size());
0302   }
0303 
0304   {
0305     //Use an empty tag
0306     std::vector<edm::InputTag> vTags = {{}};
0307     IntsConsumer intConsumer{vTags};
0308     intConsumer.updateLookup(edm::InEvent, helper, false);
0309 
0310     CPPUNIT_ASSERT(intConsumer.m_tokens[0].index() == 0);
0311     CPPUNIT_ASSERT(edm::ProductResolverIndexInvalid ==
0312                    intConsumer.indexFrom(intConsumer.m_tokens[0], edm::InEvent, typeID_vint).productResolverIndex());
0313 
0314     std::vector<edm::ProductResolverIndexAndSkipBit> indices;
0315     intConsumer.itemsToGet(edm::InEvent, indices);
0316     //nothing to get since not here
0317     CPPUNIT_ASSERT(0 == indices.size());
0318   }
0319 }
0320 
0321 void TestEDConsumerBase::testViewType() {
0322   edm::ProductResolverIndexHelper helper;
0323 
0324   edm::TypeID typeIDProductID(typeid(edm::ProductID));
0325   edm::TypeID typeIDEventID(typeid(edm::EventID));
0326   edm::TypeID typeIDVectorInt(typeid(std::vector<int>));
0327   edm::TypeID typeIDSetInt(typeid(std::set<int>));
0328   edm::TypeID typeIDVSimpleDerived(typeid(std::vector<edmtest::SimpleDerived>));
0329 
0330   helper.insert(typeIDVectorInt, "labelC", "instanceC", "processC");       // 0, 1, 2
0331   helper.insert(typeIDVectorInt, "label", "instance", "process");          // 3, 4, 5
0332   helper.insert(typeIDEventID, "labelB", "instanceB", "processB");         // 6, 7
0333   helper.insert(typeIDEventID, "label", "instanceB", "processB");          // 8, 9
0334   helper.insert(typeIDEventID, "labelX", "instanceB", "processB");         // 10, 11
0335   helper.insert(typeIDEventID, "labelB", "instance", "processB");          // 12, 13
0336   helper.insert(typeIDEventID, "labelB", "instanceX", "processB");         // 14, 15
0337   helper.insert(typeIDEventID, "labelB", "instanceB", "processB1");        // 16, 5
0338   helper.insert(typeIDEventID, "labelB", "instanceB", "processB3");        // 17, 5
0339   helper.insert(typeIDEventID, "labelB", "instanceB", "processB2");        // 18, 5
0340   helper.insert(typeIDProductID, "label", "instance", "process");          // 19, 20
0341   helper.insert(typeIDEventID, "label", "instance", "process");            // 21, 22
0342   helper.insert(typeIDProductID, "labelA", "instanceA", "processA");       // 23, 24
0343   helper.insert(typeIDSetInt, "labelC", "instanceC", "processC");          // 25, 26
0344   helper.insert(typeIDVSimpleDerived, "labelC", "instanceC", "processC");  // 27, 28, 29, 30
0345 
0346   helper.setFrozen();
0347 
0348   edm::TypeID typeID_int(typeid(int));
0349   edm::TypeID typeID_Simple(typeid(edmtest::Simple));
0350 
0351   const auto v_int = helper.index(edm::ELEMENT_TYPE, typeID_int, "label", "instance", "process");
0352   const auto v_simple = helper.index(edm::ELEMENT_TYPE, typeID_Simple, "labelC", "instanceC", "processC");
0353 
0354   const auto v_int_no_proc = helper.index(edm::ELEMENT_TYPE, typeID_int, "label", "instance");
0355   const auto v_simple_no_proc = helper.index(edm::ELEMENT_TYPE, typeID_Simple, "labelC", "instanceC");
0356 
0357   {
0358     std::vector<std::pair<edm::TypeToGet, edm::InputTag>> vT = {
0359         {edm::TypeToGet::make<edm::View<int>>(), {"label", "instance", "process"}},
0360         {edm::TypeToGet::make<edm::View<edmtest::Simple>>(), {"labelC", "instanceC", "processC"}}};
0361     TypeToGetConsumer consumer{vT};
0362 
0363     consumer.updateLookup(edm::InEvent, helper, false);
0364     CPPUNIT_ASSERT(edm::ProductResolverIndexAndSkipBit(v_int, false) ==
0365                    consumer.indexFrom(consumer.m_tokens[0], edm::InEvent, typeID_int));
0366     CPPUNIT_ASSERT(edm::ProductResolverIndexAndSkipBit(v_simple, false) ==
0367                    consumer.indexFrom(consumer.m_tokens[1], edm::InEvent, typeID_Simple));
0368 
0369     {
0370       std::vector<edm::ProductResolverIndexAndSkipBit> indices;
0371       consumer.itemsToGet(edm::InEvent, indices);
0372 
0373       CPPUNIT_ASSERT(2 == indices.size());
0374       CPPUNIT_ASSERT(indices.end() !=
0375                      std::find(indices.begin(), indices.end(), edm::ProductResolverIndexAndSkipBit(v_int, false)));
0376       CPPUNIT_ASSERT(indices.end() !=
0377                      std::find(indices.begin(), indices.end(), edm::ProductResolverIndexAndSkipBit(v_simple, false)));
0378 
0379       std::vector<edm::ProductResolverIndexAndSkipBit> indicesMay;
0380       consumer.itemsMayGet(edm::InEvent, indicesMay);
0381       CPPUNIT_ASSERT(0 == indicesMay.size());
0382     }
0383   }
0384 
0385   {
0386     std::vector<std::pair<edm::TypeToGet, edm::InputTag>> vT = {
0387         {edm::TypeToGet::make<edm::View<int>>(), {"label", "instance"}},
0388         {edm::TypeToGet::make<edm::View<edmtest::Simple>>(), {"labelC", "instanceC", "@skipCurrentProcess"}}};
0389     TypeToGetConsumer consumer{vT};
0390 
0391     consumer.updateLookup(edm::InEvent, helper, false);
0392 
0393     CPPUNIT_ASSERT(edm::ProductResolverIndexAndSkipBit(v_int_no_proc, false) ==
0394                    consumer.indexFrom(consumer.m_tokens[0], edm::InEvent, typeID_int));
0395     CPPUNIT_ASSERT(edm::ProductResolverIndexAndSkipBit(v_simple_no_proc, true) ==
0396                    consumer.indexFrom(consumer.m_tokens[1], edm::InEvent, typeID_Simple));
0397     {
0398       std::vector<edm::ProductResolverIndexAndSkipBit> indices;
0399       consumer.itemsToGet(edm::InEvent, indices);
0400 
0401       CPPUNIT_ASSERT(2 == indices.size());
0402       CPPUNIT_ASSERT(indices.end() != std::find(indices.begin(),
0403                                                 indices.end(),
0404                                                 edm::ProductResolverIndexAndSkipBit(v_int_no_proc, false)));
0405       CPPUNIT_ASSERT(indices.end() != std::find(indices.begin(),
0406                                                 indices.end(),
0407                                                 edm::ProductResolverIndexAndSkipBit(v_simple_no_proc, true)));
0408 
0409       std::vector<edm::ProductResolverIndexAndSkipBit> indicesMay;
0410       consumer.itemsMayGet(edm::InEvent, indicesMay);
0411       CPPUNIT_ASSERT(0 == indicesMay.size());
0412     }
0413   }
0414 
0415   {
0416     //Ask for something that doesn't exist
0417     std::vector<std::pair<edm::TypeToGet, edm::InputTag>> vT = {
0418         {edm::TypeToGet::make<edm::View<int>>(), {"notHere", ""}}};
0419     TypeToGetConsumer consumer{vT};
0420     consumer.updateLookup(edm::InEvent, helper, false);
0421 
0422     CPPUNIT_ASSERT(consumer.m_tokens[0].index() == 0);
0423     CPPUNIT_ASSERT(edm::ProductResolverIndexInvalid ==
0424                    consumer.indexFrom(consumer.m_tokens[0], edm::InEvent, typeID_int).productResolverIndex());
0425     {
0426       std::vector<edm::ProductResolverIndexAndSkipBit> indices;
0427       consumer.itemsToGet(edm::InEvent, indices);
0428 
0429       CPPUNIT_ASSERT(0 == indices.size());
0430     }
0431   }
0432 }
0433 
0434 namespace {
0435   class ManyEventIDConsumer : public edm::EDConsumerBase {
0436   public:
0437     ManyEventIDConsumer() { consumesMany<edm::EventID>(); }
0438   };
0439 }  // namespace
0440 
0441 void TestEDConsumerBase::testMany() {
0442   edm::ProductResolverIndexHelper helper;
0443 
0444   edm::TypeID typeIDProductID(typeid(edm::ProductID));
0445   edm::TypeID typeIDEventID(typeid(edm::EventID));
0446   edm::TypeID typeIDVectorInt(typeid(std::vector<int>));
0447   edm::TypeID typeIDSetInt(typeid(std::set<int>));
0448   edm::TypeID typeIDVSimpleDerived(typeid(std::vector<edmtest::SimpleDerived>));
0449 
0450   helper.insert(typeIDVectorInt, "labelC", "instanceC", "processC");       // 0, 1, 2
0451   helper.insert(typeIDVectorInt, "label", "instance", "process");          // 3, 4, 5
0452   helper.insert(typeIDEventID, "labelB", "instanceB", "processB");         // 6, 7
0453   helper.insert(typeIDEventID, "label", "instanceB", "processB");          // 8, 9
0454   helper.insert(typeIDEventID, "labelX", "instanceB", "processB");         // 10, 11
0455   helper.insert(typeIDEventID, "labelB", "instance", "processB");          // 12, 13
0456   helper.insert(typeIDEventID, "labelB", "instanceX", "processB");         // 14, 15
0457   helper.insert(typeIDEventID, "labelB", "instanceB", "processB1");        // 16, 5
0458   helper.insert(typeIDEventID, "labelB", "instanceB", "processB3");        // 17, 5
0459   helper.insert(typeIDEventID, "labelB", "instanceB", "processB2");        // 18, 5
0460   helper.insert(typeIDProductID, "label", "instance", "process");          // 19, 20
0461   helper.insert(typeIDEventID, "label", "instance", "process");            // 21, 22
0462   helper.insert(typeIDProductID, "labelA", "instanceA", "processA");       // 23, 24
0463   helper.insert(typeIDSetInt, "labelC", "instanceC", "processC");          // 25, 26
0464   helper.insert(typeIDVSimpleDerived, "labelC", "instanceC", "processC");  // 27, 28, 29, 30
0465 
0466   helper.setFrozen();
0467 
0468   edm::TypeID typeID_EventID(typeid(edm::EventID));
0469 
0470   const auto productIndex = helper.index(edm::PRODUCT_TYPE, typeID_EventID, "labelB", "instanceB", "processB");
0471 
0472   {
0473     ManyEventIDConsumer consumer{};
0474     consumer.updateLookup(edm::InEvent, helper, false);
0475 
0476     std::vector<edm::ProductResolverIndexAndSkipBit> indices;
0477     consumer.itemsToGet(edm::InEvent, indices);
0478 
0479     CPPUNIT_ASSERT(9 == indices.size());
0480     CPPUNIT_ASSERT(indices.end() !=
0481                    std::find(indices.begin(), indices.end(), edm::ProductResolverIndexAndSkipBit(productIndex, false)));
0482   }
0483 }
0484 
0485 void TestEDConsumerBase::testMay() {
0486   edm::ProductResolverIndexHelper helper;
0487 
0488   edm::TypeID typeIDProductID(typeid(edm::ProductID));
0489   edm::TypeID typeIDEventID(typeid(edm::EventID));
0490   edm::TypeID typeIDVectorInt(typeid(std::vector<int>));
0491   edm::TypeID typeIDSetInt(typeid(std::set<int>));
0492   edm::TypeID typeIDVSimpleDerived(typeid(std::vector<edmtest::SimpleDerived>));
0493 
0494   helper.insert(typeIDVectorInt, "labelC", "instanceC", "processC");       // 0, 1, 2
0495   helper.insert(typeIDVectorInt, "label", "instance", "process");          // 3, 4, 5
0496   helper.insert(typeIDEventID, "labelB", "instanceB", "processB");         // 6, 7
0497   helper.insert(typeIDEventID, "label", "instanceB", "processB");          // 8, 9
0498   helper.insert(typeIDEventID, "labelX", "instanceB", "processB");         // 10, 11
0499   helper.insert(typeIDEventID, "labelB", "instance", "processB");          // 12, 13
0500   helper.insert(typeIDEventID, "labelB", "instanceX", "processB");         // 14, 15
0501   helper.insert(typeIDEventID, "labelB", "instanceB", "processB1");        // 16, 5
0502   helper.insert(typeIDEventID, "labelB", "instanceB", "processB3");        // 17, 5
0503   helper.insert(typeIDEventID, "labelB", "instanceB", "processB2");        // 18, 5
0504   helper.insert(typeIDProductID, "label", "instance", "process");          // 19, 20
0505   helper.insert(typeIDEventID, "label", "instance", "process");            // 21, 22
0506   helper.insert(typeIDProductID, "labelA", "instanceA", "processA");       // 23, 24
0507   helper.insert(typeIDSetInt, "labelC", "instanceC", "processC");          // 25, 26
0508   helper.insert(typeIDVSimpleDerived, "labelC", "instanceC", "processC");  // 27, 28, 29, 30
0509 
0510   helper.setFrozen();
0511   edm::TypeID typeID_vint(typeid(std::vector<int>));
0512   const auto vint_c = helper.index(edm::PRODUCT_TYPE, typeID_vint, "labelC", "instanceC", "processC");
0513   const auto vint_c_no_proc = helper.index(edm::PRODUCT_TYPE, typeID_vint, "labelC", "instanceC", 0);
0514   const auto vint_blank = helper.index(edm::PRODUCT_TYPE, typeID_vint, "label", "instance", "process");
0515   const auto vint_blank_no_proc = helper.index(edm::PRODUCT_TYPE, typeID_vint, "label", "instance", 0);
0516   {
0517     std::vector<edm::InputTag> vTags = {{"label", "instance", "process"}, {"labelC", "instanceC", "processC"}};
0518     std::vector<edm::InputTag> vMayTags;
0519     IntsMayConsumer consumer{vTags, vMayTags};
0520     consumer.updateLookup(edm::InEvent, helper, false);
0521 
0522     CPPUNIT_ASSERT(consumer.m_tokens[0].index() == 0);
0523     CPPUNIT_ASSERT(consumer.m_tokens[1].index() == 1);
0524     CPPUNIT_ASSERT(consumer.m_mayTokens.size() == 0);
0525 
0526     CPPUNIT_ASSERT(edm::ProductResolverIndexAndSkipBit(vint_c, false) ==
0527                    consumer.indexFrom(consumer.m_tokens[1], edm::InEvent, typeID_vint));
0528     CPPUNIT_ASSERT(edm::ProductResolverIndexAndSkipBit(vint_blank, false) ==
0529                    consumer.indexFrom(consumer.m_tokens[0], edm::InEvent, typeID_vint));
0530 
0531     std::vector<edm::ProductResolverIndexAndSkipBit> indices;
0532     consumer.itemsToGet(edm::InEvent, indices);
0533 
0534     CPPUNIT_ASSERT(2 == indices.size());
0535     CPPUNIT_ASSERT(indices.end() !=
0536                    std::find(indices.begin(), indices.end(), edm::ProductResolverIndexAndSkipBit(vint_c, false)));
0537     CPPUNIT_ASSERT(indices.end() !=
0538                    std::find(indices.begin(), indices.end(), edm::ProductResolverIndexAndSkipBit(vint_blank, false)));
0539 
0540     std::vector<edm::ProductResolverIndexAndSkipBit> indicesMay;
0541     consumer.itemsMayGet(edm::InEvent, indicesMay);
0542     CPPUNIT_ASSERT(0 == indicesMay.size());
0543   }
0544 
0545   {
0546     std::vector<edm::InputTag> vTags;
0547     std::vector<edm::InputTag> vMayTags = {{"label", "instance", "process"}, {"labelC", "instanceC", "processC"}};
0548     IntsMayConsumer consumer{vTags, vMayTags};
0549     consumer.updateLookup(edm::InEvent, helper, false);
0550 
0551     CPPUNIT_ASSERT(consumer.m_mayTokens.size() == 2);
0552     CPPUNIT_ASSERT(consumer.m_mayTokens[0].index() == 0);
0553     CPPUNIT_ASSERT(consumer.m_mayTokens[1].index() == 1);
0554     CPPUNIT_ASSERT(consumer.m_tokens.size() == 0);
0555 
0556     CPPUNIT_ASSERT(vint_c ==
0557                    consumer.indexFrom(consumer.m_mayTokens[1], edm::InEvent, typeID_vint).productResolverIndex());
0558     CPPUNIT_ASSERT(vint_blank ==
0559                    consumer.indexFrom(consumer.m_mayTokens[0], edm::InEvent, typeID_vint).productResolverIndex());
0560 
0561     std::vector<edm::ProductResolverIndexAndSkipBit> indices;
0562     consumer.itemsToGet(edm::InEvent, indices);
0563     CPPUNIT_ASSERT(0 == indices.size());
0564 
0565     std::vector<edm::ProductResolverIndexAndSkipBit> indicesMay;
0566     consumer.itemsMayGet(edm::InEvent, indicesMay);
0567     CPPUNIT_ASSERT(2 == indicesMay.size());
0568     CPPUNIT_ASSERT(indicesMay.end() !=
0569                    std::find(indicesMay.begin(), indicesMay.end(), edm::ProductResolverIndexAndSkipBit(vint_c, false)));
0570     CPPUNIT_ASSERT(indicesMay.end() != std::find(indicesMay.begin(),
0571                                                  indicesMay.end(),
0572                                                  edm::ProductResolverIndexAndSkipBit(vint_blank, false)));
0573   }
0574 
0575   {
0576     std::vector<edm::InputTag> vTags = {{"label", "instance", "process"}};
0577     std::vector<edm::InputTag> vMayTags = {{"labelC", "instanceC", "processC"}};
0578     IntsMayConsumer consumer{vTags, vMayTags};
0579     consumer.updateLookup(edm::InEvent, helper, false);
0580 
0581     CPPUNIT_ASSERT(consumer.m_mayTokens.size() == 1);
0582     CPPUNIT_ASSERT(consumer.m_tokens.size() == 1);
0583     CPPUNIT_ASSERT(consumer.m_tokens[0].index() == 0);
0584     CPPUNIT_ASSERT(consumer.m_mayTokens[0].index() == 1);
0585 
0586     CPPUNIT_ASSERT(vint_c ==
0587                    consumer.indexFrom(consumer.m_mayTokens[0], edm::InEvent, typeID_vint).productResolverIndex());
0588     CPPUNIT_ASSERT(vint_blank ==
0589                    consumer.indexFrom(consumer.m_tokens[0], edm::InEvent, typeID_vint).productResolverIndex());
0590 
0591     std::vector<edm::ProductResolverIndexAndSkipBit> indices;
0592     consumer.itemsToGet(edm::InEvent, indices);
0593 
0594     CPPUNIT_ASSERT(1 == indices.size());
0595     CPPUNIT_ASSERT(indices.end() !=
0596                    std::find(indices.begin(), indices.end(), edm::ProductResolverIndexAndSkipBit(vint_blank, false)));
0597 
0598     std::vector<edm::ProductResolverIndexAndSkipBit> indicesMay;
0599     consumer.itemsMayGet(edm::InEvent, indicesMay);
0600     CPPUNIT_ASSERT(1 == indicesMay.size());
0601     CPPUNIT_ASSERT(indicesMay.end() !=
0602                    std::find(indicesMay.begin(), indicesMay.end(), edm::ProductResolverIndexAndSkipBit(vint_c, false)));
0603   }
0604   {
0605     std::vector<edm::InputTag> vTags;
0606     std::vector<edm::InputTag> vMayTags = {{"label", "instance", ""}, {"labelC", "instanceC", "@skipCurrentProcess"}};
0607     IntsMayConsumer consumer{vTags, vMayTags};
0608     consumer.updateLookup(edm::InEvent, helper, false);
0609 
0610     CPPUNIT_ASSERT(consumer.m_mayTokens.size() == 2);
0611     CPPUNIT_ASSERT(consumer.m_mayTokens[0].index() == 0);
0612     CPPUNIT_ASSERT(consumer.m_mayTokens[1].index() == 1);
0613     CPPUNIT_ASSERT(consumer.m_tokens.size() == 0);
0614 
0615     CPPUNIT_ASSERT(edm::ProductResolverIndexAndSkipBit(vint_c_no_proc, true) ==
0616                    consumer.indexFrom(consumer.m_mayTokens[1], edm::InEvent, typeID_vint));
0617     CPPUNIT_ASSERT(edm::ProductResolverIndexAndSkipBit(vint_blank_no_proc, false) ==
0618                    consumer.indexFrom(consumer.m_mayTokens[0], edm::InEvent, typeID_vint));
0619   }
0620 }