Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:23

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