Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /**
0002    \file
0003    Test suit for EcalContainer
0004 
0005 
0006    \note This test is not exaustive     
0007 */
0008 
0009 #include <Utilities/Testing/interface/CppUnit_testdriver.icpp>
0010 #include <cppunit/extensions/HelperMacros.h>
0011 #include <DataFormats/EcalDetId/interface/EBDetId.h>
0012 #include <DataFormats/EcalDetId/interface/EcalContainer.h>
0013 #include "FWCore/Utilities/interface/Exception.h"
0014 
0015 #include <vector>
0016 
0017 #include <iostream>
0018 
0019 class testEcalContainer : public CppUnit::TestFixture {
0020   CPPUNIT_TEST_SUITE(testEcalContainer);
0021   CPPUNIT_TEST(testContainer);
0022   CPPUNIT_TEST_SUITE_END();
0023 
0024 public:
0025   void testContainer();
0026 };
0027 
0028 ///registration of the test so that the runner can find it
0029 CPPUNIT_TEST_SUITE_REGISTRATION(testEcalContainer);
0030 
0031 void testEcalContainer::testContainer() {
0032   EcalContainer<EBDetId, float> ec;
0033   std::cout << "EcalContainer istantiated." << std::endl;
0034 
0035   for (int ieta = EBDetId::MIN_IETA; ieta <= EBDetId::MAX_IETA; ieta++)
0036     for (int iphi = EBDetId::MIN_IPHI; iphi <= EBDetId::MAX_IPHI; iphi++) {
0037       //EBDetId Zside 1
0038       try {
0039         {
0040           EBDetId aPositiveId(ieta, iphi);
0041           ec[aPositiveId] = aPositiveId.hashedIndex();
0042           EcalContainer<EBDetId, float>::const_iterator citer = ec.find(aPositiveId.rawId());
0043           if (citer != ec.end()) {
0044             CPPUNIT_ASSERT(*(ec.find(aPositiveId.rawId())) == aPositiveId.hashedIndex());
0045           }
0046         }
0047 
0048         //EBDetId Zside -1
0049         {
0050           EBDetId aNegativeId(-1 * ieta, iphi);
0051           ec[aNegativeId] = aNegativeId.hashedIndex();
0052           EcalContainer<EBDetId, float>::const_iterator citer = ec.find(aNegativeId.rawId());
0053           if (citer != ec.end()) {
0054             CPPUNIT_ASSERT(*(ec.find(aNegativeId.rawId())) == aNegativeId.hashedIndex());
0055           }
0056         }
0057       } catch (cms::Exception &e) {
0058         bool cmsExceptionCought = false;
0059         CPPUNIT_ASSERT(cmsExceptionCought);
0060       } catch (std::exception &e) {
0061         bool stdExceptionCought = false;
0062         CPPUNIT_ASSERT(stdExceptionCought);
0063       }
0064     }
0065   std::cout << "Loop finished." << std::endl;
0066 
0067   for (int i = 0; i != EBDetId::kSizeForDenseIndexing; ++i) {
0068     CPPUNIT_ASSERT(ec.item(i) == i);
0069     //std::cout << ec.item(i) << " " << i << std::endl;
0070   }
0071 
0072   float i = 0.;
0073   for (EcalContainer<EBDetId, float>::const_iterator citer = ec.begin(); citer != ec.end(); citer++) {
0074     CPPUNIT_ASSERT((*citer) == i);
0075     ++i;
0076   }
0077 }