Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:53:06

0001 #include "cppunit/extensions/HelperMacros.h"
0002 #include "DataFormats/Provenance/interface/ProductID.h"
0003 #include "DataFormats/Common/interface/DetSetRefVector.h"
0004 #include "DataFormats/Common/interface/TestHandle.h"
0005 
0006 class testDetSetRefVector : public CppUnit::TestFixture {
0007   CPPUNIT_TEST_SUITE(testDetSetRefVector);
0008   CPPUNIT_TEST(checkConstruction);
0009   CPPUNIT_TEST(checkFind);
0010   CPPUNIT_TEST_SUITE_END();
0011 
0012 public:
0013   void setUp() {}
0014   void tearDown() {}
0015   void checkConstruction();
0016   void checkFind();
0017 };
0018 
0019 CPPUNIT_TEST_SUITE_REGISTRATION(testDetSetRefVector);
0020 namespace testdetsetrefvector {
0021   class Value {
0022   public:
0023     // VALUES must be default constructible
0024     Value() : d_(0.0) {}
0025 
0026     // This constructor is used for testing; it is not required by the
0027     // concept VALUE.
0028     explicit Value(double d) : d_(d) {}
0029 
0030     // This access function is used for testing; it is not required by
0031     // the concept VALUE.
0032     double val() const { return d_; }
0033 
0034     // VALUES must be destructible
0035     ~Value() {}
0036 
0037     // VALUES must be LessThanComparable
0038     bool operator<(Value const& other) const { return d_ < other.d_; }
0039 
0040     // The private stuff below is all implementation detail, and not
0041     // required by the concept VALUE.
0042   private:
0043     double d_;
0044   };
0045 
0046 }  // namespace testdetsetrefvector
0047 
0048 using namespace testdetsetrefvector;
0049 typedef edm::DetSetVector<Value> dsv_type;
0050 typedef dsv_type::detset detset;
0051 
0052 void testDetSetRefVector::checkConstruction() {
0053   dsv_type c;
0054   detset d3;
0055   Value v1(1.1);
0056   Value v2(2.2);
0057   d3.id = edm::det_id_type(3);
0058   d3.data.push_back(v1);
0059   d3.data.push_back(v2);
0060   c.insert(d3);
0061   detset d1;
0062   Value v1a(4.1);
0063   Value v2a(3.2);
0064   d1.id = edm::det_id_type(1);
0065   d1.data.push_back(v1a);
0066   d1.data.push_back(v2a);
0067   c.insert(d1);
0068   c.post_insert();
0069 
0070   edm::TestHandle<dsv_type> pc2(&c, edm::ProductID(1, 1));
0071 
0072   {
0073     std::vector<edm::det_id_type> ids;
0074     ids.push_back(1);
0075     ids.push_back(3);
0076 
0077     edm::DetSetRefVector<Value> refVector(pc2, ids);
0078     CPPUNIT_ASSERT(refVector.size() == ids.size());
0079 
0080     dsv_type::const_iterator dsvItr = c.begin();
0081     for (edm::DetSetRefVector<Value>::const_iterator it = refVector.begin(), itEnd = refVector.end(); it != itEnd;
0082          ++it, ++dsvItr) {
0083       CPPUNIT_ASSERT(it->id == dsvItr->id);
0084       CPPUNIT_ASSERT(it->data.size() == dsvItr->data.size());
0085     }
0086   }
0087 
0088   {
0089     std::vector<edm::det_id_type> ids;
0090     ids.push_back(3);
0091 
0092     edm::DetSetRefVector<Value> refVector(pc2, ids);
0093     CPPUNIT_ASSERT(refVector.size() == ids.size());
0094 
0095     edm::DetSetRefVector<Value>::const_iterator itRef = refVector.begin();
0096     for (std::vector<edm::det_id_type>::const_iterator itId = ids.begin(), itIdEnd = ids.end(); itId != itIdEnd;
0097          ++itRef, ++itId) {
0098       CPPUNIT_ASSERT(itRef->id == *itId);
0099       CPPUNIT_ASSERT(itRef->id == c.find(*itId)->id);
0100       CPPUNIT_ASSERT(itRef->data.size() == c.find(*itId)->data.size());
0101     }
0102   }
0103 }
0104 
0105 void testDetSetRefVector::checkFind() {
0106   dsv_type c;
0107   detset d3;
0108   Value v1(1.1);
0109   Value v2(2.2);
0110   d3.id = edm::det_id_type(3);
0111   d3.data.push_back(v1);
0112   d3.data.push_back(v2);
0113   c.insert(d3);
0114   detset d1;
0115   Value v1a(4.1);
0116   Value v2a(3.2);
0117   d1.id = edm::det_id_type(1);
0118   d1.data.push_back(v1a);
0119   d1.data.push_back(v2a);
0120   c.insert(d1);
0121   c.post_insert();
0122 
0123   edm::TestHandle<dsv_type> pc2(&c, edm::ProductID(1, 1));
0124 
0125   {
0126     std::vector<edm::det_id_type> ids;
0127     ids.push_back(1);
0128     ids.push_back(3);
0129 
0130     edm::DetSetRefVector<Value> refVector(pc2, ids);
0131 
0132     CPPUNIT_ASSERT(refVector.find(1)->id == c.find(1)->id);
0133     CPPUNIT_ASSERT(refVector.find(3)->id == c.find(3)->id);
0134     CPPUNIT_ASSERT(refVector.find(4) == refVector.end());
0135   }
0136 }