Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-10 02:50:29

0001 #! /bin/bash
0002 #
0003 # utility functions used to generate HLT tables from master table in ConfDB
0004 #
0005 
0006 # load common HLT functions
0007 if [ -f "$CMSSW_BASE/src/HLTrigger/Configuration/common/utils.sh" ]; then
0008   source "$CMSSW_BASE/src/HLTrigger/Configuration/common/utils.sh"
0009 elif [ -f "$CMSSW_RELEASE_BASE/src/HLTrigger/Configuration/common/utils.sh" ]; then
0010   source "$CMSSW_RELEASE_BASE/src/HLTrigger/Configuration/common/utils.sh"
0011 else
0012   exit 1
0013 fi
0014 
0015 CONFDB_TAG="HEAD"
0016 
0017 # if set, remove the ConfDB working directory
0018 private=false
0019 
0020 function cleanup() {
0021   local TABLES="$@"
0022 
0023   # clean up
0024   for TABLE in $TABLES; do
0025     rm -f "${TABLE}_expanded.txt"
0026   done
0027 
0028   if $private; then
0029     rm -rf $workDir
0030   fi
0031 }
0032 
0033 function getPathList() {
0034   local DATA=$(hltConfigFromDB --$Vx --$DB --cff --configName $MASTER --noedsources --noes --noservices --nosequences --nomodules)
0035   if echo "$DATA" | grep -q 'Exhausted Resultset\|CONFIG_NOT_FOUND'; then
0036     echo "Error: $MASTER is not a valid HLT menu"
0037     exit 1
0038   fi
0039   echo "$DATA" | sed -ne's/ *= *cms.\(Final\|End\)\?Path.*//p'
0040 }
0041 
0042 function checkJars() {
0043   local BASE="$1"; shift
0044   local JARS="$@"
0045   for F in "$BASE/$JARS"; do
0046     [ -f "$F" ] || return 1
0047   done
0048   return 0
0049 }
0050 
0051 function makeCreateConfig() {
0052   local baseDir="/afs/cern.ch/user/c/confdb/www/${Vx}/lib"
0053   local baseUrl="http://confdb.web.cern.ch/confdb/${Vx}/lib"
0054   local JARS="ojdbc8.jar cmssw-evf-confdb-gui.jar"
0055   workDir="$baseDir"
0056 
0057   # try to read the .jar files from AFS, or download them
0058   if checkJars "$baseDir" $JARS; then
0059     # read the .jar fles from AFS
0060     workDir="$baseDir"
0061   else
0062     # try to use $CMSSW_BASE/tmp
0063     mkdir -p "$CMSSW_BASE/tmp/confdb"
0064     if [ -d "$CMSSW_BASE/tmp/confdb" ]; then
0065       workDir="$CMSSW_BASE/tmp/confdb"
0066     else
0067       workDir=$(mktemp -d confdb.XXXXXXXXXX)
0068       private=true
0069     fi
0070     # download the .jar files
0071     for JAR in $JARS; do
0072       # check if the file is already present
0073       if [ -f $workDir/$JAR ]; then
0074         continue
0075       fi
0076       # download to a temporay file and use an atomic move (in case an other istance is downloading the same file
0077       local TMPJAR=$(mktemp -p "$workDir" .${JAR}.XXXXXXXXXX)
0078       curl -s -L "$baseUrl/$JAR" -o "$TMPJAR"
0079       mv -n "$TMPJAR" "$workDir/$JAR"
0080       rm -f "$TMPJAR"
0081     done
0082   fi
0083 
0084   CLASSPATH=
0085   for JAR in $JARS; do
0086     CLASSPATH="$CLASSPATH${CLASSPATH:+:}$workDir/$JAR"
0087   done
0088 }
0089 
0090 function loadConfiguration() {
0091   case "$1" in
0092     "v1/offline" | "v1/hltdev")
0093       # v1 offline aka "hltdev"
0094       DBHOST="cmsr1-v.cern.ch"
0095       DBNAME="cms_cond.cern.ch"
0096       DBUSER="cms_hltdev_writer"
0097       PWHASH="0196d34dd35b04c0f3597dc89fbbe6e2"
0098       ;;
0099     "v2/offline")
0100       # v2 offline
0101       DBHOST="cmsr1-v.cern.ch"
0102       DBNAME="cms_cond.cern.ch"
0103       DBUSER="cms_hlt_gdr_w"
0104       PWHASH="0196d34dd35b04c0f3597dc89fbbe6e2"
0105       ;;
0106      "v3/run3")
0107       # v3 run3
0108       DBHOST="cmsr1-s.cern.ch"
0109       DBNAME="cms_hlt.cern.ch"
0110       DBUSER="cms_hlt_v3_w"
0111       PWHASH="0196d34dd35b04c0f3597dc89fbbe6e2"
0112       ;;
0113       "v3-test/dev")
0114       # v3-test dev
0115       DBHOST="cmsr1-s.cern.ch"
0116       DBNAME="cms_hlt.cern.ch"
0117       DBUSER="cms_hlt_gdrdev_w"
0118       PWHASH="0196d34dd35b04c0f3597dc89fbbe6e2"
0119       ;;
0120       "v3/dev")
0121       # v3 dev
0122       DBHOST="cmsr1-s.cern.ch"
0123       DBNAME="cms_hlt.cern.ch"
0124       DBUSER="cms_hlt_gdrdev_w"
0125       PWHASH="0196d34dd35b04c0f3597dc89fbbe6e2"
0126       ;;
0127     *)
0128       # see https://github.com/fwyzard/hlt-confdb/blob/confdbv2/test/runCreateConfig
0129       echo "Error, unnown database \"$1\", exiting."
0130       exit 1
0131       ;;
0132   esac
0133 }
0134 
0135 function runCreateConfig() {
0136   loadConfiguration "$1"
0137   java \
0138     -Djava.security.egd=file:///dev/urandom \
0139     -Doracle.jdbc.timezoneAsRegion=false \
0140     -Xss32M \
0141     -Xmx1024m \
0142     -classpath "$CLASSPATH" \
0143     confdb.db.ConfDBCreateConfig \
0144     --dbHost $DBHOST \
0145     --dbName $DBNAME \
0146     --dbUser $DBUSER \
0147     --dbPwrd $2 \
0148     --master $3 \
0149     --paths $4 \
0150     --name $5
0151 }
0152 
0153 # expands the patterns in "TABLE.txt" into "TABLE_expanded.txt"
0154 function expandSubtable() {
0155   local TABLE="$1"
0156   local LIST="$2"
0157   local FAIL=0
0158 
0159   echo "Parsing table: $TABLE ..."
0160   rm -f ${TABLE}_expanded.txt
0161   cat "$TABLE.txt" | while read LINE; do
0162     PATTERN=$(echo $LINE | sed -e's/ *#.*//' -e's/^/\\</' -e's/$/\\>/' -e's/?/./g' -e's/\*/.*/g')
0163     [ "$PATTERN" == "\<\>" ] && continue
0164     echo "$LIST" | grep "$PATTERN" >> "${TABLE}_expanded.txt"
0165     if (( $? != 0 )); then
0166       echo "Error: pattern \"$LINE\" does not match any paths" 1>&2
0167       FAIL=1
0168     fi
0169   done
0170 
0171   return $FAIL
0172 }
0173 
0174 
0175 function readPassword() {
0176   # ask for the ConfDB password, and validate its hash
0177   loadConfiguration "$DATABASE"
0178   PASSWORD=""
0179   read -p "Enter password for DB: " -s PASSWORD
0180   echo
0181 
0182   if [ "$(echo "$PASSWORD" | tr 'a-z' 'A-Z' | md5sum | cut -c1-32)" != "$PWHASH" ]; then
0183     echo "Incorrect password, exiting." 1>&2
0184     exit 1
0185   fi
0186 }
0187 
0188 
0189 function createSubtables() {
0190   local DATABASE="$1"; shift
0191   local MASTER="$1";   shift
0192   local TARGET="$1";   shift
0193   local TABLES="$@"
0194 
0195   # extract the schema version from the database name
0196   local Vx DB
0197   read Vx DB <<< $(parse_HLT_schema "$DATABASE")
0198   local DATABASE="${Vx}/${DB}"
0199 
0200   # dump the requested configuration
0201   echo "ConfDB master: $DATABASE:$MASTER"
0202   echo "Subtables:     $TABLES"
0203   echo "Created under: $DATABASE:$TARGET"
0204 
0205   # install a clean up hook
0206   trap "cleanup $TABLES; exit 1" INT TERM EXIT
0207 
0208   # expand the wildcards in the path names in each subtables
0209   local LIST=$(getPathList $MASTER)
0210   local FAIL=0
0211   for TABLE in $TABLES; do
0212     expandSubtable "$TABLE" "$LIST" || FAIL=1
0213   done
0214   if (( $FAIL )); then
0215     echo "Error: one or more patterns do not match any paths, exiting." 1>&2
0216     exit 1
0217   fi
0218 
0219   # ask the user for the database password
0220   readPassword
0221 
0222   # make sure the needed sripts are available
0223   makeCreateConfig
0224 
0225   # extract each subtable
0226   for TABLE in $TABLES; do
0227     runCreateConfig "$DATABASE" "$PASSWORD" "$MASTER" "${TABLE}_expanded.txt" $(echo "$TARGET" | sed -e"s|TABLE|$TABLE|")
0228   done
0229 
0230   # remove clean up hook, and call explicit cleanup
0231   trap - INT TERM EXIT
0232   cleanup $TABLES
0233 }