Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-07-02 00:53:33

0001 #define CATCH_CONFIG_MAIN
0002 #include "catch.hpp"
0003 
0004 #include <algorithm>
0005 #include <string>
0006 
0007 #include "DataFormats/L1TGlobal/interface/GlobalObject.h"
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 
0010 namespace {
0011 
0012   bool hasNoDuplicateEnums() {
0013     std::vector<l1t::GlobalObject> vec;
0014     vec.reserve(l1t::kGlobalObjectEnumStringPairs.size());
0015     for (auto const& [value, name] : l1t::kGlobalObjectEnumStringPairs) {
0016       vec.emplace_back(value);
0017     }
0018     std::sort(vec.begin(), vec.end());
0019     auto const it = std::unique(vec.begin(), vec.end());
0020     return (it == vec.end());
0021   }
0022 
0023   bool hasNoDuplicateStrings() {
0024     std::vector<std::string> vec;
0025     vec.reserve(l1t::kGlobalObjectEnumStringPairs.size());
0026     for (auto const& [value, name] : l1t::kGlobalObjectEnumStringPairs) {
0027       vec.emplace_back(name);
0028     }
0029     std::sort(vec.begin(), vec.end());
0030     auto const it = std::unique(vec.begin(), vec.end());
0031     return (it == vec.end());
0032   }
0033 
0034   bool isValidGlobalObject(unsigned int const idx, l1t::GlobalObject const& obj, std::string const& label) {
0035     if (idx != obj) {
0036       edm::LogError("testL1TGlobalObjectCatch2")
0037           << "Index (" << idx << ") and Enum (" << obj << ") do not match (Label = \"" << label << "\")";
0038       return false;
0039     }
0040 
0041     auto const enumToString = l1t::GlobalObjectEnumToString(obj);
0042     if (enumToString != label) {
0043       edm::LogError("testL1TGlobalObjectCatch2")
0044           << "EnumToString (\"" << enumToString << "\") and Label (\"" << label << "\") do not match"
0045           << " (Index = " << idx << ", Enum = " << obj << ") !!";
0046       return false;
0047     }
0048 
0049     auto const stringToEnum = l1t::GlobalObjectStringToEnum(label);
0050     if (stringToEnum != obj) {
0051       edm::LogError("testL1TGlobalObjectCatch2")
0052           << "StringToEnum (\"" << stringToEnum << "\") and Enum (" << obj << ") do not match"
0053           << " (Index = " << idx << ", Label = \"" << label << "\") !!";
0054       return false;
0055     }
0056 
0057     return true;
0058   }
0059 
0060 }  // namespace
0061 
0062 TEST_CASE("Test l1t::GlobalObject", "[l1tGlobalObject]") {
0063   // verify that the enums in l1t::kGlobalObjectEnumStringPairs are all unique
0064   SECTION("NoDuplicateEnums") { REQUIRE(hasNoDuplicateEnums()); }
0065 
0066   // verify that the strings in l1t::kGlobalObjectEnumStringPairs are all unique
0067   SECTION("NoDuplicateStrings") { REQUIRE(hasNoDuplicateStrings()); }
0068 
0069   // verify correctness of index, enum and string of every GlobalObject
0070   SECTION("TestGlobalObjects") {
0071     REQUIRE(isValidGlobalObject(0, l1t::gtMu, "Mu"));                     //  0
0072     REQUIRE(isValidGlobalObject(1, l1t::gtMuShower, "MuShower"));         //  1
0073     REQUIRE(isValidGlobalObject(2, l1t::gtEG, "EG"));                     //  2
0074     REQUIRE(isValidGlobalObject(3, l1t::gtJet, "Jet"));                   //  3
0075     REQUIRE(isValidGlobalObject(4, l1t::gtTau, "Tau"));                   //  4
0076     REQUIRE(isValidGlobalObject(5, l1t::gtETM, "ETM"));                   //  5
0077     REQUIRE(isValidGlobalObject(6, l1t::gtETT, "ETT"));                   //  6
0078     REQUIRE(isValidGlobalObject(7, l1t::gtHTT, "HTT"));                   //  7
0079     REQUIRE(isValidGlobalObject(8, l1t::gtHTM, "HTM"));                   //  8
0080     REQUIRE(isValidGlobalObject(9, l1t::gtETMHF, "ETMHF"));               //  9
0081     REQUIRE(isValidGlobalObject(10, l1t::gtTowerCount, "TowerCount"));    // 10
0082     REQUIRE(isValidGlobalObject(11, l1t::gtMinBiasHFP0, "MinBiasHFP0"));  // 11
0083     REQUIRE(isValidGlobalObject(12, l1t::gtMinBiasHFM0, "MinBiasHFM0"));  // 12
0084     REQUIRE(isValidGlobalObject(13, l1t::gtMinBiasHFP1, "MinBiasHFP1"));  // 13
0085     REQUIRE(isValidGlobalObject(14, l1t::gtMinBiasHFM1, "MinBiasHFM1"));  // 14
0086     REQUIRE(isValidGlobalObject(15, l1t::gtETTem, "ETTem"));              // 15
0087     REQUIRE(isValidGlobalObject(16, l1t::gtAsymmetryEt, "AsymEt"));       // 16
0088     REQUIRE(isValidGlobalObject(17, l1t::gtAsymmetryHt, "AsymHt"));       // 17
0089     REQUIRE(isValidGlobalObject(18, l1t::gtAsymmetryEtHF, "AsymEtHF"));   // 18
0090     REQUIRE(isValidGlobalObject(19, l1t::gtAsymmetryHtHF, "AsymHtHF"));   // 19
0091     REQUIRE(isValidGlobalObject(20, l1t::gtCentrality0, "CENT0"));        // 20
0092     REQUIRE(isValidGlobalObject(21, l1t::gtCentrality1, "CENT1"));        // 21
0093     REQUIRE(isValidGlobalObject(22, l1t::gtCentrality2, "CENT2"));        // 22
0094     REQUIRE(isValidGlobalObject(23, l1t::gtCentrality3, "CENT3"));        // 23
0095     REQUIRE(isValidGlobalObject(24, l1t::gtCentrality4, "CENT4"));        // 24
0096     REQUIRE(isValidGlobalObject(25, l1t::gtCentrality5, "CENT5"));        // 25
0097     REQUIRE(isValidGlobalObject(26, l1t::gtCentrality6, "CENT6"));        // 26
0098     REQUIRE(isValidGlobalObject(27, l1t::gtCentrality7, "CENT7"));        // 27
0099     REQUIRE(isValidGlobalObject(28, l1t::gtExternal, "External"));        // 28
0100     REQUIRE(isValidGlobalObject(29, l1t::gtZDCP, "ZDCP"));                // 29
0101     REQUIRE(isValidGlobalObject(30, l1t::gtZDCM, "ZDCM"));                // 30
0102     REQUIRE(isValidGlobalObject(31, l1t::ObjNull, "ObjNull"));            // 31
0103     REQUIRE(isValidGlobalObject(32, l1t::gtHTMHF, "HTMHF"));              // 32
0104   }
0105 }