Skip to content

Commit

Permalink
added unit test for HLTFiltersDQMonitor plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
missirol committed Jan 4, 2023
1 parent 321bee8 commit 0f5ff99
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 0 deletions.
3 changes: 3 additions & 0 deletions DQMOffline/Trigger/test/BuildFile.xml
Expand Up @@ -2,3 +2,6 @@
<use name="DQMOffline/Trigger"/>
<use name="catch2"/>
</bin>

<!-- test the HLTFiltersDQMonitor plugin -->
<test name="testHLTFiltersDQMonitor" command="testHLTFiltersDQMonitor.sh"/>
54 changes: 54 additions & 0 deletions DQMOffline/Trigger/test/harvesting_cfg.py
@@ -0,0 +1,54 @@
import FWCore.ParameterSet.Config as cms

## CLI parser
import argparse
import sys

parser = argparse.ArgumentParser(
prog = 'cmsRun '+sys.argv[0]+' --',
description = 'Configuration file to run the DQMFileSaver on DQMIO input files.',
formatter_class = argparse.ArgumentDefaultsHelpFormatter
)

parser.add_argument('-t', '--nThreads', type = int, help = 'Number of threads',
default = 4)

parser.add_argument('-s', '--nStreams', type = int, help = 'Number of EDM streams',
default = 0)

parser.add_argument('-i', '--inputFiles', nargs = '+', help = 'List of DQMIO input files',
default = ['file:DQMIO.root'])

argv = sys.argv[:]
if '--' in argv:
argv.remove('--')
args, unknown = parser.parse_known_args(argv)

# Process
process = cms.Process('HARVESTING')

process.options.numberOfThreads = args.nThreads
process.options.numberOfStreams = args.nStreams
process.options.numberOfConcurrentLuminosityBlocks = 1

# Source (DQM input)
process.source = cms.Source('DQMRootSource',
fileNames = cms.untracked.vstring(args.inputFiles)
)

# DQMStore (Service)
process.load('DQMServices.Core.DQMStore_cfi')

# MessageLogger (Service)
process.load('FWCore.MessageLogger.MessageLogger_cfi')

# Output module (file in ROOT format)
from DQMServices.Components.DQMFileSaver_cfi import dqmSaver as _dqmSaver
process.dqmSaver = _dqmSaver.clone(
workflow = '/DQMOffline/Trigger/'+process.name_()
)

# EndPath
process.endp = cms.EndPath(
process.dqmSaver
)
30 changes: 30 additions & 0 deletions DQMOffline/Trigger/test/readme.md
@@ -0,0 +1,30 @@
Unit test: `testHLTFiltersDQMonitor`
------------------------------------

Test of the DQM plugin `HLTFiltersDQMonitor`.

- To run the test via `scram`
```sh
scram build runtests_testHLTFiltersDQMonitor
```

- To run the test without `scram`
```sh
LOCALTOP="${CMSSW_BASE}" "${CMSSW_BASE}"/src/DQMOffline/Trigger/test/testHLTFiltersDQMonitor.sh
```

- To show info on command-line arguments of `testHLTFiltersDQMonitor_cfg.py`
```sh
python3 "${CMSSW_BASE}"/src/DQMOffline/Trigger/test/testHLTFiltersDQMonitor_cfg.py -h
```

- To execute cmsRun with `testHLTFiltersDQMonitor_cfg.py` (example)
```sh
cmsRun "${CMSSW_BASE}"/src/DQMOffline/Trigger/test/testHLTFiltersDQMonitor_cfg.py -- -t 4 -s 0 -o tmp.root -n 100
```

- To create a bare ROOT file from the DQMIO output of `testHLTFiltersDQMonitor_cfg.py`,
run the harvesting step as follows
```sh
cmsRun "${CMSSW_BASE}"/src/DQMOffline/Trigger/test/harvesting_cfg.py -- -i file:tmp.root
```
13 changes: 13 additions & 0 deletions DQMOffline/Trigger/test/testHLTFiltersDQMonitor.sh
@@ -0,0 +1,13 @@
#!/bin/bash

# Pass in name and status
function die {
printf "\n%s: status %s\n" "$1" "$2"
exit $2
}

# run test job
TESTDIR="${LOCALTOP}"/src/DQMOffline/Trigger/test

cmsRun "${TESTDIR}"/testHLTFiltersDQMonitor_cfg.py -- -t 1 -n 128 \
|| die "Failure running testHLTFiltersDQMonitor_cfg.py" $?
105 changes: 105 additions & 0 deletions DQMOffline/Trigger/test/testHLTFiltersDQMonitor_cfg.py
@@ -0,0 +1,105 @@
import FWCore.ParameterSet.Config as cms

## CLI parser
import argparse
import sys

parser = argparse.ArgumentParser(
prog = 'cmsRun '+sys.argv[0]+' --',
description = 'Configuration file to test of the HLTFiltersDQMonitor plugin.',
formatter_class = argparse.ArgumentDefaultsHelpFormatter
)

parser.add_argument('-t', '--nThreads', type = int, help = 'Number of threads',
default = 4)

parser.add_argument('-s', '--nStreams', type = int, help = 'Number of EDM streams',
default = 0)

parser.add_argument('-i', '--inputFiles', nargs = '+', help = 'List of EDM input files',
default = ['/store/relval/CMSSW_12_6_0_pre2/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/125X_mcRun3_2022_realistic_v3-v1/2580000/2d96539c-b321-401f-b7b2-51884a5d421f.root'])

parser.add_argument('-n', '--maxEvents', type = int, help = 'Number of input events',
default = 100)

parser.add_argument('-o', '--outputFile', type = str, help = 'Path to output file in DQMIO format',
default = 'DQMIO.root')

parser.add_argument('--wantSummary', action = 'store_true', help = 'Value of process.options.wantSummary',
default = False)

parser.add_argument('-d', '--debugMode', action = 'store_true', help = 'Enable debug info (requires recompiling first with \'USER_CXXFLAGS="-DEDM_ML_DEBUG" scram b\')',
default = False)

argv = sys.argv[:]
if '--' in argv:
argv.remove('--')
args, unknown = parser.parse_known_args(argv)

## Process
process = cms.Process('TEST')

process.options.numberOfThreads = args.nThreads
process.options.numberOfStreams = args.nStreams
process.options.wantSummary = args.wantSummary
process.maxEvents.input = args.maxEvents

## Source
process.source = cms.Source('PoolSource',
fileNames = cms.untracked.vstring(args.inputFiles),
inputCommands = cms.untracked.vstring(
'drop *',
'keep edmTriggerResults_*_*_*',
'keep triggerTriggerEvent_*_*_*',
'keep triggerTriggerEventWithRefs_*_*_*'
)
)

## MessageLogger (Service)
process.load('FWCore.MessageLogger.MessageLogger_cfi')
process.MessageLogger.cerr.FwkReport.reportEvery = 1 # only report every Nth event start
process.MessageLogger.cerr.FwkReport.limit = -1 # max number of reported messages (all if -1)
process.MessageLogger.cerr.enableStatistics = False # enable "MessageLogger Summary" message

## DQMStore (Service)
process.load('DQMServices.Core.DQMStore_cfi')

## FastTimerService (Service)
from HLTrigger.Timer.FastTimerService_cfi import FastTimerService as _FastTimerService
process.FastTimerService = _FastTimerService.clone(
enableDQM = False,
printEventSummary = False,
printJobSummary = True,
printRunSummary = False,
writeJSONSummary = False
)
process.MessageLogger.FastReport = dict()

## EventData Modules
from DQMOffline.Trigger.hltFiltersDQMonitor_cfi import hltFiltersDQMonitor as _hltFiltersDQMonitor
process.dqmHLTFiltersDQMonitor = _hltFiltersDQMonitor.clone(
folderName = 'HLT/Filters',
efficPlotNamePrefix = 'effic_',
triggerResults = 'TriggerResults::HLT',
triggerSummaryAOD = 'hltTriggerSummaryAOD::HLT',
triggerSummaryRAW = 'hltTriggerSummaryRAW::HLT'
)
process.MessageLogger.HLTFiltersDQMonitor = dict()
if args.debugMode:
process.MessageLogger.cerr.threshold = 'DEBUG'
process.MessageLogger.debugModules = ['dqmHLTFiltersDQMonitor']

## Output Modules
process.dqmOutput = cms.OutputModule('DQMRootOutputModule',
fileName = cms.untracked.string(args.outputFile)
)

## Path
process.testPath = cms.Path(
process.dqmHLTFiltersDQMonitor
)

## EndPath
process.testEndPath = cms.EndPath(
process.dqmOutput
)

0 comments on commit 0f5ff99

Please sign in to comment.