Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:15:46

0001 #! /bin/bash
0002 
0003 # orted_with_cmsenv - Open RTE Daemon wrapper for CMSSW
0004 
0005 PROGRAM=$(basename $0)
0006 WORKDIR=$PWD
0007 MCA_PREFIX=cmsenv
0008 
0009 function usage() {
0010   cat << @EOF
0011 $PROGRAM - Open RTE Daemon wrapper for CMSSW
0012 
0013 Usage:
0014   $PROGRAM [-mca ${MCA_PREFIX}_release CMSSW_BASE] [-mca ${MCA_PREFIX}_verbose {true|false}] ...
0015 
0016 Load the CMS environment from the given release area, then launch orted with the same arguments.
0017 @EOF
0018 }
0019 
0020 function error() {
0021   echo "$PROGRAM: error: $@"
0022   echo
0023   usage
0024   exit 1
0025 }
0026 
0027 function warning() {
0028   echo "$PROGRAM: warning: $@"
0029 }
0030 
0031 function validate_and_set_option() {
0032   local VARIABLE="$1"
0033   local VALUE="$2"
0034 
0035   case $VARIABLE in
0036     VERBOSE )
0037       # boolean argument
0038       case "$VALUE" in
0039         true | yes | 1)
0040           eval $VARIABLE=true
0041           return 0
0042           ;;
0043         false | no | 0)
0044           eval $VARIABLE=false
0045           return 0
0046           ;;
0047         *)
0048           return 1
0049           ;;
0050       esac
0051       ;;
0052 
0053     RELEASE )
0054       # directory argument
0055       if [ -d "$VALUE" ]; then
0056         eval $VARIABLE=$(realpath "$VALUE")
0057         return 0
0058       else
0059         return 1
0060       fi
0061       ;;
0062 
0063     * )
0064       # unknown variable, do not perform any validation
0065       ;;
0066   
0067   esac
0068 }
0069 
0070 
0071 function parse_mca_options() {
0072   local MCA_OPTION=""
0073   local MCA_VARIABLE=""
0074 
0075   for ARG in "$@"; do
0076     # look for an "--mca ${MCA_PREFIX}_variable value" triplet
0077     case "$ARG" in
0078       -mca | --mca)
0079         MCA_OPTION="$ARG"
0080         MCA_VARIABLE=""
0081         ;;
0082       ${MCA_PREFIX}_release)
0083         [ "$MCA_OPTION" ] && MCA_VARIABLE="RELEASE"
0084         ;;
0085       ${MCA_PREFIX}_verbose)
0086         [ "$MCA_OPTION" ] && MCA_VARIABLE="VERBOSE"
0087         ;;
0088       ${MCA_PREFIX}_*)
0089         warning "unrecognized option $MCA_OPTION $ARG"
0090         # reset the parsing state
0091         MCA_OPTION=""
0092         MCA_VARIABLE=""
0093         ;;
0094       *)
0095         [ "$MCA_OPTION" ] && [ "$MCA_VARIABLE" ] || continue
0096         # validate and set the argument
0097         if validate_and_set_option "$MCA_VARIABLE" "$ARG"; then
0098           true
0099         else
0100           warning "invalid argument $MCA_OPTION $MCA_VARIABLE $ARG"
0101         fi
0102         # reset the parsing state
0103         MCA_OPTION=""
0104         MCA_VARIABLE=""
0105         ;;
0106     esac
0107   done
0108 }
0109 
0110 # arguments and options
0111 RELEASE=
0112 VERBOSE=false
0113 
0114 # parse the command line options, look for "--mca ${MCA_PREFIX}_variable value" triplets
0115 parse_mca_options "$@"
0116 
0117 if $VERBOSE; then
0118   echo "$PROGRAM initial environment:"
0119   echo "--------------------------------------------------------------------------------"
0120   env | sort
0121   echo "--------------------------------------------------------------------------------"
0122   echo
0123 fi
0124 
0125 if $VERBOSE; then
0126   echo "$PROGRAM command line arguments:"
0127   echo "--------------------------------------------------------------------------------"
0128   echo "$0" "$@" | sed -e's/ \+-/ \\\n  -/g'
0129   echo "--------------------------------------------------------------------------------"
0130   echo
0131 fi
0132 
0133 # if CMSSW is not set from the MCA options, try to determine it from the location of this file
0134 if [ "$RELEASE" ]; then
0135   [ -f "$RELEASE/config/scram_basedir" ] || error "invalid release area at $RELEASE"
0136 else
0137   RELEASE="$(realpath $(dirname $(realpath "$0"))/../..)"
0138   [ -f "$RELEASE/config/scram_basedir" ] || error "cannot automatically determine CMSSW_BASE, please set it with the \"-mca ${MCA_PREFIX}_release CMSSW_BASE\" option"
0139 fi
0140 
0141 export VO_CMS_SW_DIR=$(< $RELEASE/config/scram_basedir)
0142 [ -f "$VO_CMS_SW_DIR/cmsset_default.sh" ] || error "invalid CMS installation at $VO_CMS_SW_DIR"
0143 
0144 # load the CMS environment
0145 source "$VO_CMS_SW_DIR"/cmsset_default.sh
0146 
0147 # load the CMSSW release environment
0148 cd "$RELEASE"
0149 eval $(scram runtime -sh)
0150 
0151 # run the ORTED/MPI processes in the work directory
0152 cd "$WORKDIR"
0153 exec orted "$@"