Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-05 01:46:41

0001 #! /bin/bash
0002 
0003 # load common HLT functions
0004 if [ -f "$CMSSW_BASE/src/HLTrigger/Configuration/common/utils.sh" ]; then
0005   source "$CMSSW_BASE/src/HLTrigger/Configuration/common/utils.sh"
0006 elif [ -f "$CMSSW_RELEASE_BASE/src/HLTrigger/Configuration/common/utils.sh" ]; then
0007   source "$CMSSW_RELEASE_BASE/src/HLTrigger/Configuration/common/utils.sh"
0008 else
0009   exit 1
0010 fi
0011 
0012 function log() {
0013   echo -e "$@"
0014 }
0015 
0016 function err() {
0017   echo -e "$@" 1>&2
0018 }
0019 
0020 
0021 NAME=$(basename $0)
0022 
0023 HELP="Run the integration tests over all paths in a given HLT menu.
0024 
0025 Usage:
0026   $NAME -h|--help
0027   $NAME [-d|--dir WORKDIR] [-s|--setup SETUP] [-i|--input RAW] [-j|--jobs JOBS]
0028         [--streams STREAMS] [--threads THREADS] [-x|--extra OPTIONS] [--mc]
0029         [ [-n|--size EVENTS] [-k|--skip EVENTS] | [-e|--events EVENTS] ] MENU
0030 
0031   MENU is the HLT menu to test.
0032 
0033   -s | --setup SETUP          Use the Services and EventSetup modules from a different menu
0034                               (usefull when testing a ConfDB area with only some new paths).
0035                               Note it is an error to specify the converter/db here, 
0036                               it uses the same as set by the HLT menu
0037   -d | --dir      WORKDIR     Create all files and run all tests inside WORKDIR (defauls: ./hltintegration)
0038   -i | --input    INPUT       Use the specified RAW data file as input
0039   -n | --size     EVENTS      Run on EVENTS events (-1 for all, default is 100)
0040   -k | --skip     EVENTS      Skip the first EVENTS (default is 0)
0041   -e | --events   EVENTS      Run on a comma-separated list of EVENTS, a VEventRange
0042   -j | --jobs     JOBS        Run JOBS single trigger jobs in parallel (default 4)
0043        --streams  STREAMS     Run with STREAMS parallel streams (i.e. events) (default 0 means as many streams as threads)
0044        --threads  THREADS     Run with THREADS threads when running the whole HLT (default 4)
0045   -x | --extra    OPTIONS     Pass OPTIONS directly to hltGetConfiguration
0046        --mc                   Run over MC instead of data (the default)
0047   --dbproxy                   Use a socks proxy to connect to the HLT database
0048   --dbproxyhost    PROXYHOST  Host of the socks proxy (default: "localhost")
0049   --dbproxyport    PROXYPORT  Port of the socks proxy (default: 8080)
0050   -h | --help                 Print this help message and exit.
0051 
0052 
0053   The supported formats for both menu specifications are:
0054     - /path/to/configuration[/Vn]
0055     - [[{v1|v2|v3}/]{run3|run2|online|adg}:]/path/to/configuration[/Vn]
0056     - run:runnumber
0057   The possible converters are \"v1\", \"v2\", and \"v3\" (default).
0058   The possible databases are \"run3\" (default, used for offline run3 development), \"run2\" (previously used for run2 development), \"online\" (used to
0059   extract online menus within Point 5) and \"adg\" (used to extract the online menus outside Point 5).
0060   If no menu version is specified, the latest one is automatically used.
0061   If \"run:\" is used instead, the HLT menu used for the given run number is looked up and used.
0062   Note other converters and databases exist but they are for expert/special use only.
0063 
0064   It's possible to pass arbitrary command line options to hltGetConfiguration, using \"-x --option\".
0065   To pass multiple options, enclose them in quotes, or use \"-x\" more than once.
0066 
0067   Note: '--events' is not supported together with '--size' or '--skip'.
0068 
0069 
0070 Exmples:
0071 
0072   $NAME /dev/CMSSW_4_2_0/GRun
0073 
0074       will test the latest version of the GRun menu.
0075 
0076 
0077   $NAME /dev/CMSSW_4_2_0/GRun -x --l1-emulator
0078 
0079       will test the latest version of the GRun, running the L1 emulator.
0080 
0081 
0082   $NAME /users/fwyzard/physics/HLT/V6 -s adg:/cdaq/physics/Run2011/1e33/v1.3/HLT/V6
0083 
0084       will test the paths from /users/fwyzard/physics/HLT/V6, using the environment from the
0085       online menu \"1e33\" v1.3 V6
0086 
0087 "
0088 
0089 # parse command line argument and options
0090 OPTS=$(getopt -n "$NAME" -o "s:d:i:j:n:k:e:x:h" -l "setup:,dir:,input:,jobs:,size:,skip:,streams:,threads:,events:,mc,extra:,help,dbproxy,dbproxyhost:,dbproxyport:" -- "$@")
0091 
0092 # invalid options
0093 if [ $? != 0 ]; then
0094   exit 1
0095 fi
0096 
0097 # reload the parsed options into the environment
0098 eval set -- "$OPTS"
0099 
0100 # check how many CPUs are available
0101 CPUS=`getconf _NPROCESSORS_ONLN`
0102 
0103 MENU=""
0104 SETUP=""
0105 INPUT=""
0106 SIZE=100
0107 SKIP=0
0108 EVENTS=""
0109 JOBS=4
0110 THREADS=4
0111 STREAMS=0
0112 WORKDIR="hltintegration"
0113 EXTRA=""
0114 DATA="--data"
0115 HLTLISTPATHPROXY=""
0116 
0117 SELECTION=""
0118 
0119 # parse options
0120 while true; do
0121   case "$1" in
0122     "-h" | "--help" )
0123       echo "$HELP"
0124       exit 0
0125       ;;
0126     "-s" | "--setup" )
0127       SETUP="$2"
0128       shift 2
0129       ;;
0130     "-d" | "--dir" )
0131       WORKDIR="$2"
0132       shift 2
0133       ;;
0134     "-i" | "--input" )
0135       INPUT="--input $2"
0136       shift 2
0137       ;;
0138     "-n" | "--size" )
0139       if [ "$SELECTION" == "complex" ]; then
0140         err "'--events' is not supported together with '--size' or '--skip'"
0141         exit 1
0142       fi
0143       SELECTION="simple"
0144       SIZE=$2
0145       if ((SIZE == 0)) && [ "$SIZE" != "0" ]; then
0146         err "$NAME error: invalid option \"$1 $2\""
0147         err "Try '$NAME --help' for more information."
0148         exit 1
0149       fi
0150       shift 2
0151       ;;
0152     "-k" | "--skip" )
0153       if [ "$SELECTION" == "complex" ]; then
0154         err "'--events' is not supported together with '--size' or '--skip'"
0155         exit 1
0156       fi
0157       SELECTION="simple"
0158       SKIP=$2
0159       if ((SKIP == 0)) && [ "$SKIP" != "0" ]; then
0160         err "$NAME error: invalid option \"$1 $2\""
0161         err "Try '$NAME --help' for more information."
0162         exit 1
0163       fi
0164       shift 2
0165       ;;
0166     "-e" | "--events" )
0167       if [ "$SELECTION" == "simple" ]; then
0168         err "'--events' is not supported together with '--size' or '--skip'"
0169         exit 1
0170       fi
0171       SELECTION="complex"
0172       SIZE=-1
0173       EVENTS="$2"
0174       shift 2
0175       ;;
0176     "-j" | "--jobs" )
0177       JOBS=$2
0178       if ((JOBS == 0)); then
0179         err "$NAME error: invalid option \"$1 $2\""
0180         err "Try '$NAME --help' for more information."
0181         exit 1
0182       fi
0183       shift 2
0184       ;;
0185     "--streams" )
0186       STREAMS=$2
0187       shift 2
0188       ;;
0189     "--threads" )
0190       THREADS=$2
0191       shift 2
0192       ;;
0193     "-x" | "--extra" )
0194       EXTRA="$EXTRA $2"
0195       shift 2
0196       ;;
0197     "--mc" )
0198       DATA="--mc"
0199       shift 1
0200       ;;
0201     "--dbproxy" )
0202       HLTLISTPATHPROXY="$HLTLISTPATHPROXY --dbproxy"
0203       EXTRA="$EXTRA --dbproxy"
0204       shift 1
0205       ;;
0206     "--dbproxyhost" )
0207       HLTLISTPATHPROXY="$HLTLISTPATHPROXY --dbproxyhost $2"
0208       EXTRA="$EXTRA --dbproxyhost $2"
0209       shift 2
0210       ;;
0211     "--dbproxyport" )
0212       HLTLISTPATHPROXY="$HLTLISTPATHPROXY --dbproxyport $2"
0213       EXTRA="$EXTRA --dbproxyport $2"
0214       shift 2
0215       ;;
0216     "--" )
0217       # inserted by getopt to singal the end of options
0218       shift
0219       break
0220       ;;
0221   esac
0222 done
0223 
0224 # parse required argument
0225 if (( $# == 0 )); then
0226   err "$NAME error: missing argument."
0227   err "Try '$NAME --help' for more information."
0228   exit 1
0229 elif (( $# > 1 )); then
0230   err "$NAME error: too many arguments."
0231   err "Try '$NAME --help' for more information."
0232   exit 1
0233 else
0234   MENU="$1"
0235 fi
0236 
0237 
0238 # run the tests
0239 rm -rf "$WORKDIR"
0240 mkdir  "$WORKDIR"
0241 cd     "$WORKDIR"
0242 
0243 # find the list of all trigger paths
0244 TRIGGERS=$(hltListPaths "$MENU" $HLTLISTPATHPROXY -p --no-dep --exclude "^HLTriggerFinalPath$" "^Dataset_.+")
0245 echo "${TRIGGERS[@]}" > paths.txt
0246 
0247 # print some info
0248 if [ "$SELECTION" == "complex" ]; then
0249   log "Will run $(echo $TRIGGERS | wc -w) HLT paths over $(echo $EVENTS | tr ',' '\n' | wc -l) events, with $JOBS jobs in parallel"
0250 elif [ "$SIZE" == "-1" ]; then
0251   log "Will run $(echo $TRIGGERS | wc -w) HLT paths over all events, with $JOBS jobs in parallel"
0252 else
0253   log "Will run $(echo $TRIGGERS | wc -w) HLT paths over $SIZE events, with $JOBS jobs in parallel"
0254 fi
0255 
0256 # create all dumps
0257 log "Extracting full menu dump"
0258 hltGetConfiguration "$MENU" --full --offline $DATA $INPUT --unprescale --process "TEST$(date -u +'%Y%m%d%H%M%S')" --max-events $SIZE $EXTRA > hlt.py
0259 
0260 # if missing, add a simplified HLTriggerFinalPath
0261 if ! grep -q HLTriggerFinalPath hlt.py; then
0262   cat >> hlt.py << @EOF
0263 # add (simplified) HLTriggerFinalPath if missing
0264 process.hltTriggerSummaryAOD = cms.EDProducer( "TriggerSummaryProducerAOD",
0265     processName = cms.string( "@" )
0266 )
0267 process.hltTriggerSummaryRAW = cms.EDProducer( "TriggerSummaryProducerRAW",
0268     processName = cms.string( "@" )
0269 )
0270 process.HLTriggerFinalPath = cms.Path( process.hltTriggerSummaryAOD + process.hltTriggerSummaryRAW )
0271 
0272 @EOF
0273 fi
0274 
0275 # select which events to run on
0276 if [ "$SELECTION" == "complex" ]; then
0277   cat >> hlt.py << @EOF
0278 # event selection customised by hltIntegrationTests
0279 process.source.eventsToProcess = cms.untracked.VEventRange( '$(echo $EVENTS | sed -e"s/,/','/g")' )
0280 @EOF
0281 elif (( $SKIP > 0 )); then
0282   cat >> hlt.py << @EOF
0283 # event selection customised by hltIntegrationTests
0284 process.source.skipEvents = cms.untracked.uint32( $SKIP )
0285 @EOF
0286 fi
0287 
0288 # set the number of threads and streams for the whole hlt job
0289 cat >> hlt.py << @EOF
0290 # configure multithreading, and allocate 10 MB of stack space per thread
0291 process.options.numberOfThreads = cms.untracked.uint32( $THREADS )
0292 process.options.numberOfStreams = cms.untracked.uint32( $STREAMS )
0293 process.options.sizeOfStackForThreadsInKB = cms.untracked.uint32( 10*1024 )
0294 process.options.accelerators = cms.untracked.vstring( 'cpu' )
0295 
0296 process.hltTriggerSummaryAOD.throw = cms.bool( True )
0297 @EOF
0298 
0299 # dump the menu name, and its release template
0300 log "HLT menu: $(head -n1 hlt.py | cut -c 3-)"
0301 
0302 # check the prescale modules
0303 hltCheckPrescaleModules -w hlt.py
0304 
0305 # check for multi-threading
0306 edmCheckMultithreading hlt.py | grep legacy
0307 
0308 log "Preparing single-path configurations"
0309 for TRIGGER in $TRIGGERS; do
0310   cat > "$TRIGGER".py << @EOF
0311 from hlt import *
0312 
0313 process.hltOutput = cms.OutputModule( "PoolOutputModule",
0314     fileName = cms.untracked.string( "$TRIGGER.root" ),
0315     fastCloning = cms.untracked.bool( False ),
0316     outputCommands = cms.untracked.vstring(
0317       'drop *',
0318       'keep edmTriggerResults_*_*_*',
0319     )
0320 )
0321 
0322 process.Output = cms.EndPath( process.hltOutput )
0323 
0324 process.schedule = cms.Schedule( process.$TRIGGER, process.HLTriggerFinalPath, process.Output )
0325 
0326 process.hltTriggerSummaryAOD.throw = cms.bool( True )
0327 @EOF
0328 done
0329 
0330 # if a separate setup is requested, create the setup_cff.py file and patch all dumps to use it
0331 if [ "$SETUP" ]; then
0332   log "Extracting setup_cff dump"
0333   #we use $MENU not $SETUP here as we force the same DB / converter as the main menu
0334   #this is the hltGetConfiguration behaviour and would be confusing if you had to 
0335   #specify converter/db on the setup menu on hltIntegration tests but not on hltGetConfiguration
0336   read SETUP_Vx SETUP_DB _ <<< $(parse_HLT_menu "$MENU")
0337 
0338   hltConfigFromDB --$SETUP_Vx --$SETUP_DB $HLTLISTPATHPROXY --cff --configName "$SETUP" --nopaths --services -FUShmDQMOutputService,-PrescaleService,-EvFDaqDirector,-FastMonitoringService > setup_cff.py
0339   sed -i -e's/process = cms.Process(.*)/&\nprocess.load("setup_cff")/' hlt.py $(for TRIGGER in $TRIGGERS; do echo "$TRIGGER".py; done)
0340 fi
0341 
0342 # run all HLT dumps
0343 cat > .makefile << @EOF
0344 TRIGGERS=$(echo $TRIGGERS)
0345 CFGS=\$(TRIGGERS:%=%.py)
0346 LOGS=\$(TRIGGERS:%=%.log)
0347 DONE=\$(TRIGGERS:%=%.done)
0348 
0349 .PHONY: all clean hlt \$(TRIGGERS)
0350 
0351 all: hlt \$(TRIGGERS)
0352 
0353 clean:
0354         @rm -f hlt.log hlt.done \$(LOGS) \$(DONE)
0355 
0356 hlt: hlt.done
0357 
0358 hlt.done: hlt.py
0359         @echo -e "\tfull menu dump"
0360         @cmsRun hlt.py >& hlt.log < /dev/zero && touch hlt.done
0361 
0362 \$(TRIGGERS): %: %.done
0363 
0364 \$(DONE): %.done: %.py
0365         @echo -e "\t\$*"
0366         @cmsRun \$*.py >& \$*.log < /dev/zero && touch \$*.done
0367 
0368 @EOF
0369 
0370 log "Running..."
0371 # if the whole hlt job runs with multithreading, run it by itself
0372 # otherwise, run it in parallel with the single-trigger jobs
0373 if ((THREADS > 0)); then
0374   make -f .makefile hlt
0375   make -f .makefile -j$JOBS -k $TRIGGERS
0376 else
0377   make -f .makefile -j$JOBS -k
0378 fi
0379 
0380 
0381 # compare HLT results
0382 log "Comparing the results of running each path by itself with those from the full menu"
0383 hltCompareResults
0384 STATUS=$?
0385 log "exit status: $STATUS"
0386 log "done"
0387 
0388 # done
0389 cd ..
0390 exit $STATUS