Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:58

0001 #define CATCH_CONFIG_MAIN
0002 #include "catch.hpp"
0003 
0004 #include "DataFormats/Common/interface/DetSetVectorNew.h"
0005 #include "DataFormats/Common/interface/ThinnedRefSet.h"
0006 
0007 #include "SimpleEDProductGetter.h"
0008 
0009 #include <memory>
0010 #include <vector>
0011 
0012 TEST_CASE("ThinnedRefSet", "[ThinnedRefSet]") {
0013   SECTION("Default constructor") { edm::ThinnedRefSet<int> set; }
0014 
0015   SECTION("std::vector<int>") {
0016     SimpleEDProductGetter getter;
0017 
0018     edm::ProductID id(1, 42U);
0019     REQUIRE(id.isValid());
0020 
0021     auto prod = std::make_unique<std::vector<int>>();
0022     for (int i = 0; i < 10; ++i) {
0023       prod->push_back(i);
0024     }
0025     getter.addProduct(id, std::move(prod));
0026 
0027     edm::ThinnedRefSet<std::vector<int>> refSet;
0028     edm::RefProd<std::vector<int>> refProd(id, &getter);
0029     auto filler = refSet.fill(refProd, getter);
0030 
0031     filler.insert(edm::Ref<std::vector<int>>(id, 0, &getter));
0032     filler.insert(edm::Ref<std::vector<int>>(id, 4, &getter));
0033     filler.insert(edm::Ref<std::vector<int>>(id, 9, &getter));
0034 
0035     REQUIRE(refSet.contains(0));
0036     REQUIRE(not refSet.contains(1));
0037     REQUIRE(not refSet.contains(2));
0038     REQUIRE(not refSet.contains(3));
0039     REQUIRE(refSet.contains(4));
0040     REQUIRE(not refSet.contains(5));
0041     REQUIRE(not refSet.contains(6));
0042     REQUIRE(not refSet.contains(7));
0043     REQUIRE(not refSet.contains(8));
0044     REQUIRE(refSet.contains(9));
0045     REQUIRE(not refSet.contains(10));
0046   }
0047 
0048   SECTION("edmNew::DetSetVector<int>") {
0049     SimpleEDProductGetter getter;
0050 
0051     edm::ProductID id(1, 75U);
0052     REQUIRE(id.isValid());
0053 
0054     {
0055       auto detsets = std::make_unique<edmNew::DetSetVector<int>>(2);
0056       {
0057         edmNew::DetSetVector<int>::FastFiller filler(*detsets, 1);
0058         filler.push_back(1);
0059         filler.push_back(2);
0060         filler.push_back(3);
0061       }
0062       {
0063         edmNew::DetSetVector<int>::FastFiller filler(*detsets, 2);
0064         filler.push_back(10);
0065         filler.push_back(20);
0066       }
0067       REQUIRE(detsets->size() == 2);
0068       REQUIRE(detsets->dataSize() == 5);
0069       REQUIRE(detsets->detsetSize(0) == 3);
0070       REQUIRE(detsets->detsetSize(1) == 2);
0071 
0072       auto ds = detsets->find(1);
0073       REQUIRE(ds != detsets->end());
0074       REQUIRE(ds->id() == 1);
0075       REQUIRE(detsets->find(3) == detsets->end());
0076 
0077       getter.addProduct(id, std::move(detsets));
0078     }
0079 
0080     edm::ThinnedRefSet<edmNew::DetSetVector<int>> refSet;
0081     edm::RefProd<edmNew::DetSetVector<int>> refProd(id, &getter);
0082     auto filler = refSet.fill(refProd, getter);
0083 
0084     REQUIRE(*(edm::Ref<edmNew::DetSetVector<int>, int>(id, 0, &getter)) == 1);
0085     REQUIRE(*(edm::Ref<edmNew::DetSetVector<int>, int>(id, 2, &getter)) == 3);
0086     REQUIRE(*(edm::Ref<edmNew::DetSetVector<int>, int>(id, 4, &getter)) == 20);
0087 
0088     filler.insert(edm::Ref<edmNew::DetSetVector<int>, int>(id, 0, &getter));
0089     filler.insert(edm::Ref<edmNew::DetSetVector<int>, int>(id, 2, &getter));
0090     filler.insert(edm::Ref<edmNew::DetSetVector<int>, int>(id, 4, &getter));
0091 
0092     REQUIRE(refSet.contains(0));
0093     REQUIRE(not refSet.contains(1));
0094     REQUIRE(refSet.contains(2));
0095     REQUIRE(not refSet.contains(3));
0096     REQUIRE(refSet.contains(4));
0097     REQUIRE(not refSet.contains(5));
0098   }
0099 }