Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "catch.hpp"
0002 
0003 #include "FWCore/Framework/interface/InputProcessBlockCacheImpl.h"
0004 #include "FWCore/Framework/interface/global/EDProducerBase.h"
0005 #include "FWCore/Framework/interface/global/implementors.h"
0006 #include "FWCore/Utilities/interface/StreamID.h"
0007 
0008 #include <iostream>
0009 
0010 namespace edm {
0011   class Event;
0012   class EventSetup;
0013 }  // namespace edm
0014 
0015 namespace edmtest {
0016 
0017   class TestProcessBlockCacheA {
0018     int x_;
0019   };
0020 
0021   class TestProcessBlockCacheB {
0022     int x_;
0023   };
0024 
0025   class TestProcessBlockCacheC {
0026     int x_;
0027   };
0028 
0029   class TestProcessBlockCacheD {
0030     int x_;
0031   };
0032 
0033   class TestInputBlockCacheHolder0
0034       : public edm::global::impl::InputProcessBlockCacheHolder<edm::global::EDProducerBase> {
0035   public:
0036     bool wantsProcessBlocks() const override { return true; }
0037     bool wantsInputProcessBlocks() const override { return true; }
0038     bool wantsGlobalRuns() const override { return true; }
0039     bool wantsGlobalLuminosityBlocks() const override { return true; }
0040     bool wantsStreamRuns() const override { return true; }
0041     bool wantsStreamLuminosityBlocks() const override { return true; }
0042     void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override {}
0043   };
0044 
0045   class TestInputBlockCacheHolder1
0046       : public edm::global::impl::InputProcessBlockCacheHolder<edm::global::EDProducerBase, TestProcessBlockCacheA> {
0047   public:
0048     bool wantsProcessBlocks() const override { return true; }
0049     bool wantsInputProcessBlocks() const override { return true; }
0050     bool wantsGlobalRuns() const override { return true; }
0051     bool wantsGlobalLuminosityBlocks() const override { return true; }
0052     bool wantsStreamRuns() const override { return true; }
0053     bool wantsStreamLuminosityBlocks() const override { return true; }
0054     void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override {}
0055   };
0056 
0057   class TestInputBlockCacheHolder2 : public edm::global::impl::InputProcessBlockCacheHolder<edm::global::EDProducerBase,
0058                                                                                             TestProcessBlockCacheA,
0059                                                                                             TestProcessBlockCacheB> {
0060   public:
0061     bool wantsProcessBlocks() const override { return true; }
0062     bool wantsInputProcessBlocks() const override { return true; }
0063     bool wantsGlobalRuns() const override { return true; }
0064     bool wantsGlobalLuminosityBlocks() const override { return true; }
0065     bool wantsStreamRuns() const override { return true; }
0066     bool wantsStreamLuminosityBlocks() const override { return true; }
0067     void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override {}
0068   };
0069 
0070   class TestInputBlockCacheHolder3 : public edm::global::impl::InputProcessBlockCacheHolder<edm::global::EDProducerBase,
0071                                                                                             TestProcessBlockCacheA,
0072                                                                                             TestProcessBlockCacheB,
0073                                                                                             TestProcessBlockCacheC> {
0074   public:
0075     bool wantsProcessBlocks() const override { return true; }
0076     bool wantsInputProcessBlocks() const override { return true; }
0077     bool wantsGlobalRuns() const override { return true; }
0078     bool wantsGlobalLuminosityBlocks() const override { return true; }
0079     bool wantsStreamRuns() const override { return true; }
0080     bool wantsStreamLuminosityBlocks() const override { return true; }
0081     void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override {}
0082   };
0083 }  // namespace edmtest
0084 
0085 TEST_CASE("test InputProcessBlockCacheHolder", "[InputProcessBlockCacheHolder]") {
0086   SECTION("test countTypeInParameterPack") {
0087     STATIC_REQUIRE(edm::impl::countTypeInParameterPack<edmtest::TestProcessBlockCacheA>() == 0);
0088     STATIC_REQUIRE(
0089         edm::impl::countTypeInParameterPack<edmtest::TestProcessBlockCacheA, edmtest::TestProcessBlockCacheA>() == 1);
0090     STATIC_REQUIRE(
0091         edm::impl::countTypeInParameterPack<edmtest::TestProcessBlockCacheA, edmtest::TestProcessBlockCacheB>() == 0);
0092     STATIC_REQUIRE(edm::impl::countTypeInParameterPack<edmtest::TestProcessBlockCacheA,
0093                                                        edmtest::TestProcessBlockCacheA,
0094                                                        edmtest::TestProcessBlockCacheB>() == 1);
0095     STATIC_REQUIRE(edm::impl::countTypeInParameterPack<edmtest::TestProcessBlockCacheA,
0096                                                        edmtest::TestProcessBlockCacheB,
0097                                                        edmtest::TestProcessBlockCacheA>() == 1);
0098     STATIC_REQUIRE(edm::impl::countTypeInParameterPack<edmtest::TestProcessBlockCacheA,
0099                                                        edmtest::TestProcessBlockCacheA,
0100                                                        edmtest::TestProcessBlockCacheA>() == 2);
0101     STATIC_REQUIRE(edm::impl::countTypeInParameterPack<edmtest::TestProcessBlockCacheA,
0102                                                        edmtest::TestProcessBlockCacheB,
0103                                                        edmtest::TestProcessBlockCacheB>() == 0);
0104 
0105     STATIC_REQUIRE(edm::impl::countTypeInParameterPack<edmtest::TestProcessBlockCacheA,
0106                                                        edmtest::TestProcessBlockCacheA,
0107                                                        edmtest::TestProcessBlockCacheB,
0108                                                        edmtest::TestProcessBlockCacheA>() == 2);
0109     STATIC_REQUIRE(edm::impl::countTypeInParameterPack<edmtest::TestProcessBlockCacheA,
0110                                                        edmtest::TestProcessBlockCacheA,
0111                                                        edmtest::TestProcessBlockCacheB,
0112                                                        edmtest::TestProcessBlockCacheC>() == 1);
0113     STATIC_REQUIRE(edm::impl::countTypeInParameterPack<edmtest::TestProcessBlockCacheA,
0114                                                        edmtest::TestProcessBlockCacheA,
0115                                                        edmtest::TestProcessBlockCacheA,
0116                                                        edmtest::TestProcessBlockCacheA>() == 3);
0117     STATIC_REQUIRE(edm::impl::countTypeInParameterPack<edmtest::TestProcessBlockCacheA,
0118                                                        edmtest::TestProcessBlockCacheA,
0119                                                        edmtest::TestProcessBlockCacheA,
0120                                                        edmtest::TestProcessBlockCacheC>() == 2);
0121     STATIC_REQUIRE(edm::impl::countTypeInParameterPack<edmtest::TestProcessBlockCacheA,
0122                                                        edmtest::TestProcessBlockCacheB,
0123                                                        edmtest::TestProcessBlockCacheB,
0124                                                        edmtest::TestProcessBlockCacheA>() == 1);
0125     STATIC_REQUIRE(edm::impl::countTypeInParameterPack<edmtest::TestProcessBlockCacheA,
0126                                                        edmtest::TestProcessBlockCacheB,
0127                                                        edmtest::TestProcessBlockCacheB,
0128                                                        edmtest::TestProcessBlockCacheC>() == 0);
0129     STATIC_REQUIRE(edm::impl::countTypeInParameterPack<edmtest::TestProcessBlockCacheA,
0130                                                        edmtest::TestProcessBlockCacheB,
0131                                                        edmtest::TestProcessBlockCacheA,
0132                                                        edmtest::TestProcessBlockCacheA>() == 2);
0133     STATIC_REQUIRE(edm::impl::countTypeInParameterPack<edmtest::TestProcessBlockCacheA,
0134                                                        edmtest::TestProcessBlockCacheB,
0135                                                        edmtest::TestProcessBlockCacheA,
0136                                                        edmtest::TestProcessBlockCacheC>() == 1);
0137 
0138     // The following should not compile and I manually verified it doesn't
0139     // REQUIRE(edm::impl::countTypeInParameterPack<>() == 0);
0140   }
0141 
0142   SECTION("test indexInputProcessBlockCache") {
0143     STATIC_REQUIRE(
0144         edm::impl::indexInputProcessBlockCache<edmtest::TestProcessBlockCacheA, edmtest::TestProcessBlockCacheA>() ==
0145         0);
0146     STATIC_REQUIRE(edm::impl::indexInputProcessBlockCache<edmtest::TestProcessBlockCacheA,
0147                                                           edmtest::TestProcessBlockCacheA,
0148                                                           edmtest::TestProcessBlockCacheB>() == 0);
0149     STATIC_REQUIRE(edm::impl::indexInputProcessBlockCache<edmtest::TestProcessBlockCacheA,
0150                                                           edmtest::TestProcessBlockCacheB,
0151                                                           edmtest::TestProcessBlockCacheA>() == 1);
0152     STATIC_REQUIRE(edm::impl::indexInputProcessBlockCache<edmtest::TestProcessBlockCacheD,
0153                                                           edmtest::TestProcessBlockCacheA,
0154                                                           edmtest::TestProcessBlockCacheB,
0155                                                           edmtest::TestProcessBlockCacheC,
0156                                                           edmtest::TestProcessBlockCacheD>() == 3);
0157     // The following fails compilation if uncommented, tested manually
0158     // REQUIRE(edm::impl::indexInputProcessBlockCache<edmtest::TestProcessBlockCacheD, edmtest::TestProcessBlockCacheA, edmtest::TestProcessBlockCacheB, edmtest::TestProcessBlockCacheC>() == 3);
0159     // REQUIRE(edm::impl::indexInputProcessBlockCache<edmtest::TestProcessBlockCacheD>() == 3);
0160   }
0161 
0162   SECTION("test constructor") {
0163     edmtest::TestInputBlockCacheHolder0 holder0;
0164     edmtest::TestInputBlockCacheHolder1 holder1;
0165     edmtest::TestInputBlockCacheHolder2 holder2;
0166     edmtest::TestInputBlockCacheHolder3 holder3;
0167   }
0168 }