Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-06-25 02:44:10

0001 #include "FWCore/TestProcessor/interface/TestProcessor.h"
0002 #include "FWCore/Utilities/interface/Exception.h"
0003 #include "FWCore/ServiceRegistry/interface/Service.h"
0004 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0005 
0006 #define CATCH_CONFIG_MAIN
0007 #include "catch.hpp"
0008 
0009 // Function to run the catch2 tests
0010 //___________________________________________________________________________________________
0011 void runTestForAnalyzer(const std::string& baseConfig, const std::string& analyzerName) {
0012   edm::test::TestProcessor::Config config{baseConfig};
0013 
0014   SECTION(analyzerName + " base configuration is OK") { REQUIRE_NOTHROW(edm::test::TestProcessor(config)); }
0015 
0016   SECTION(analyzerName + " No Runs data") {
0017     edm::test::TestProcessor tester(config);
0018     REQUIRE_NOTHROW(tester.testWithNoRuns());
0019   }
0020 
0021   SECTION(analyzerName + " beginJob and endJob only") {
0022     edm::test::TestProcessor tester(config);
0023     REQUIRE_NOTHROW(tester.testBeginAndEndJobOnly());
0024   }
0025 
0026   // the following part is commented because the
0027   // HIPTwoBodyDecayAnalyzer crashes on
0028   // No "TransientTrackRecord" record found in the EventSetup.
0029 
0030   /* 
0031   SECTION("No event data") {
0032    edm::test::TestProcessor tester(config);
0033    REQUIRE_NOTHROW(tester.test());
0034   }
0035   */
0036 
0037   SECTION("Run with no LuminosityBlocks") {
0038     edm::test::TestProcessor tester(config);
0039     REQUIRE_NOTHROW(tester.testRunWithNoLuminosityBlocks());
0040   }
0041 
0042   SECTION("LuminosityBlock with no Events") {
0043     edm::test::TestProcessor tester(config);
0044     REQUIRE_NOTHROW(tester.testLuminosityBlockWithNoEvents());
0045   }
0046 }
0047 
0048 // Function to generate base configuration string
0049 //___________________________________________________________________________________________
0050 std::string generateBaseConfig(const std::string& analyzerName, const std::string& rootFileName) {
0051   // Define a raw string literal
0052   constexpr const char* rawString = R"_(from FWCore.TestProcessor.TestProcess import *
0053 from Alignment.HIPAlignmentAlgorithm.{}_cfi import {}
0054 process = TestProcess()
0055 process.trackAnalyzer = {}
0056 process.moduleToTest(process.trackAnalyzer)
0057 process.load("TrackingTools.TransientTrack.TransientTrackBuilder_cfi")
0058 process.add_(cms.ESProducer("TransientTrackBuilderESProducer"))
0059 process.add_(cms.Service('MessageLogger'))
0060 process.add_(cms.Service('JobReportService'))
0061 process.add_(cms.Service('TFileService',fileName=cms.string('{}')))
0062     )_";
0063 
0064   // Format the raw string literal using fmt::format
0065   return fmt::format(rawString, analyzerName, analyzerName, analyzerName, rootFileName);
0066 }
0067 
0068 //___________________________________________________________________________________________
0069 TEST_CASE("LhcTrackAnalyzer tests", "[LhcTrackAnalyzer]") {
0070   const std::string baseConfig = generateBaseConfig("lhcTrackAnalyzer", "testHIPAnalyzers1.root");
0071   runTestForAnalyzer(baseConfig, "LhcTrackAnalyzer");
0072 }
0073 
0074 //___________________________________________________________________________________________
0075 TEST_CASE("HIPTwoBodyDecayAnalyzer tests", "[HIPTwoBodyDecayAnalyzer]") {
0076   const std::string baseConfig = generateBaseConfig("hipTwoBodyDecayAnalyzer", "testHIPAnalyzers2.root");
0077   runTestForAnalyzer(baseConfig, "HIPTwoBodyDecayAnalyzer");
0078 }