Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:18:26

0001 #define CATCH_CONFIG_MAIN
0002 #include "catch.hpp"
0003 
0004 #include <string>
0005 
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include "HLTrigger/HLTcore/interface/TriggerExpressionParser.h"
0008 
0009 namespace {
0010   using namespace std::literals;
0011 
0012   bool testExpression(std::string const& expression, std::string const& expected = {}) {
0013     auto const* expr = triggerExpression::parse(expression);
0014 
0015     if (not expr) {
0016       edm::LogWarning("InvalidInput") << "Couldn't parse trigger-results expression \"" << expression << "\"";
0017       return false;
0018     }
0019 
0020     std::ostringstream out;
0021     expr->dump(out);
0022     std::string const& str = out.str();
0023 
0024     if (not expected.empty() and str != expected) {
0025       edm::LogWarning("InvalidInput")                         //
0026           << "Parsed expression: \"" << expression << "\"\n"  //
0027           << "as:                \"" << str << "\"\n"         //
0028           << "instead of:        \"" << expected << '"';
0029       return false;
0030     }
0031 
0032     edm::LogPrint("testExpression")                         //
0033         << "Parsed expression: \"" << expression << "\"\n"  //
0034         << "as:                \"" << str << '"';
0035     return true;
0036   }
0037 
0038 }  // namespace
0039 
0040 TEST_CASE("Test TriggerExpressionParser", "[TriggerExpressionParser]") {
0041   // examples of expressions supported by the triggerExpression parser
0042   SECTION("CorrectExpressions") {
0043     REQUIRE(testExpression("TRUE",  //
0044                            "TRUE"));
0045     REQUIRE(testExpression("FALSE",  //
0046                            "FALSE"));
0047     REQUIRE(testExpression("NOT (FALSE)",  //
0048                            "(NOT FALSE)"));
0049     REQUIRE(testExpression("(NOT FALSE) OR TRUE",  //
0050                            "((NOT FALSE) OR TRUE)"));
0051     REQUIRE(testExpression("NOTThisHLTPath AND TRUE AND NOT L1_A?_*",
0052                            "((Uninitialised_Path_Expression AND TRUE) AND (NOT Uninitialised_L1_Expression))"));
0053     REQUIRE(testExpression("NOT NOTThisHLTPath",  //
0054                            "(NOT Uninitialised_Path_Expression)"));
0055     REQUIRE(testExpression("XYZ XOR TRUE",  //
0056                            "(Uninitialised_Path_Expression XOR TRUE)"));
0057     REQUIRE(testExpression("XYZ XOR ABC AND L1_* OR DEF/10",  //
0058                            "(((Uninitialised_Path_Expression XOR Uninitialised_Path_Expression) AND "
0059                            "Uninitialised_L1_Expression) OR (Uninitialised_Path_Expression / 10))"));
0060     REQUIRE(testExpression("ThisHLTANDNOTThatORTheOther",  //
0061                            "Uninitialised_Path_Expression"));
0062     REQUIRE(testExpression("TRUEPath AND NOTPath",  //
0063                            "(Uninitialised_Path_Expression AND Uninitialised_Path_Expression)"));
0064     REQUIRE(testExpression("NOT L1_SEED1 AND L1_SEED2*",  //
0065                            "((NOT Uninitialised_L1_Expression) AND Uninitialised_L1_Expression)"));
0066     REQUIRE(testExpression("NOT L1_SEED2 AND (HLT_PATH_? AND NOT HLT_PATH2_??_*)",  //
0067                            "((NOT Uninitialised_L1_Expression) AND (Uninitialised_Path_Expression AND (NOT "
0068                            "Uninitialised_Path_Expression)))"));
0069     REQUIRE(testExpression("NOT (HLT_Path1 AND HLT_Path2)",  //
0070                            "(NOT (Uninitialised_Path_Expression AND Uninitialised_Path_Expression))"));
0071     REQUIRE(testExpression("NOT (NOTHLT_Path OR HLT_Path2)",  //
0072                            "(NOT (Uninitialised_Path_Expression OR Uninitialised_Path_Expression))"));
0073     REQUIRE(testExpression(
0074         "((L1_A AND HLT_B) OR Dataset_C) AND NOT (Status_D OR Name_E OR HLT_F*) AND L1_??_?_?",  //
0075         "((((Uninitialised_L1_Expression AND Uninitialised_Path_Expression) OR Uninitialised_Path_Expression)"
0076         " AND (NOT ((Uninitialised_Path_Expression OR Uninitialised_Path_Expression)"
0077         " OR Uninitialised_Path_Expression))) AND Uninitialised_L1_Expression)"));
0078     REQUIRE(testExpression("NOT (NOT (HLT_Path1 AND HLT_Path_*))",  //
0079                            "(NOT (NOT (Uninitialised_Path_Expression AND Uninitialised_Path_Expression)))"));
0080     REQUIRE(testExpression("NOT NOT (HLT_Path1 AND L1_Seed_?? OR HLT_Path_*)",  //
0081                            "(NOT (NOT ((Uninitialised_Path_Expression AND Uninitialised_L1_Expression) OR "
0082                            "Uninitialised_Path_Expression)))"));
0083     REQUIRE(testExpression("NOT NOT HLT_Path1 AND L1_Seed_??",  //
0084                            "((NOT (NOT Uninitialised_Path_Expression)) AND Uninitialised_L1_Expression)"));
0085     REQUIRE(testExpression("NOT(THIS OR THAT)AND(L1_THEOTHER)OR(NOTFALSE)",  //
0086                            "(((NOT (Uninitialised_Path_Expression OR Uninitialised_Path_Expression))"
0087                            " AND Uninitialised_L1_Expression) OR Uninitialised_Path_Expression)"));
0088     REQUIRE(testExpression("EXPR_A MASKING L1_?",  //
0089                            "(Uninitialised_Path_Expression MASKING Uninitialised_L1_Expression)"));
0090     REQUIRE(testExpression(
0091         "L1_*copy* MASKING L1_*copy MASKING ((L1_*copy2))",  //
0092         "((Uninitialised_L1_Expression MASKING Uninitialised_L1_Expression) MASKING Uninitialised_L1_Expression)"));
0093     REQUIRE(testExpression(
0094         "(A AND B XOR C) MASKING D OR E",  //
0095         "((((Uninitialised_Path_Expression AND Uninitialised_Path_Expression) XOR Uninitialised_Path_Expression)"
0096         " MASKING Uninitialised_Path_Expression) OR Uninitialised_Path_Expression)"));
0097     REQUIRE(testExpression("EXPR_A MASKING FALSE", "(Uninitialised_Path_Expression MASKING FALSE)"));
0098   }
0099 
0100   // examples of expressions not supported by the triggerExpression parser
0101   SECTION("IncorrectExpressions") {
0102     REQUIRE(not testExpression("A | B"));
0103     REQUIRE(not testExpression("A && B"));
0104     REQUIRE(not testExpression("NOT"));
0105     REQUIRE(not testExpression("AND"));
0106     REQUIRE(not testExpression("OR"));
0107     REQUIRE(not testExpression("XOR"));
0108     REQUIRE(not testExpression("MASKING"));
0109     REQUIRE(not testExpression("NOT L1_SEED1 ANDD L1_SEED2*"));
0110     REQUIRE(not testExpression("NOT (NOTHLT_Path OR HLT_Path2))"));
0111     REQUIRE(not testExpression("HLT_Path* NOT TRUE"));
0112     REQUIRE(not testExpression("ThisPath ANDThatPath"));
0113     REQUIRE(not testExpression("ThisPath AND ThatPath AND OR"));
0114     REQUIRE(not testExpression("ThisPath AND ThatPath OR NOT"));
0115     REQUIRE(not testExpression("ThisPath AND ThatPath MASKING MASKING"));
0116     REQUIRE(not testExpression("Path_? AND MASKING Path_2"));
0117     REQUIRE(not testExpression("MASKING Path_1 AND Path_?"));
0118     REQUIRE(not testExpression("EXPR_1 MASKING (Path_1 OR Path_2)"));
0119     REQUIRE(not testExpression("EXPR_1 MASKING TRUE"));
0120     REQUIRE(not testExpression("EXPR_1 MASKING (NOT Path_1)"));
0121     REQUIRE(not testExpression("EXPR_1 MASKING (Path_1 / 15)"));
0122     REQUIRE(not testExpression("EXPR_1 MASKING (Path*_* MASKING Path1_*)"));
0123     REQUIRE(not testExpression("EXPR_1 MASKINGPath2"));
0124   }
0125 }