Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:11:35

0001 #!/bin/bash
0002 
0003 #  ./run_analysis.sh 
0004 #    1: <run_number>
0005 #    2: <HWUPLOAD>
0006 #    3: <AnalysisUpload>
0007 #    4: <DB_PARTITION>
0008 #    5: <UseClientFile>
0009 #    6: <DisableDevices>
0010 #    7: <saveClientFile>
0011 
0012 # tests on env
0013 if [ -n "`uname -n | grep vmepc`" -a `whoami` == "trackerpro" ] ; then
0014     :
0015 elif [ -n "`uname -n | grep cmstracker029`" -a `whoami` == "xdaqtk" ] ; then
0016     :
0017 else
0018     echo "You are not running as trackerpro (on vmepcs) or xdaqtk (on cmstracker029).";
0019     echo "This can cause problems during file moving, like loss of raw data.";
0020     echo "You don't want that to happen, probably, so please login as the appropriate user and try again.";
0021     exit 0;
0022 fi
0023 
0024 
0025 # tests for proper usage
0026 function usage() {
0027     echo "Usage:  ./run_analysis.sh <run_number> <HWUPLOAD> <AnalysisUpload> <DB_partition_name> <UseClientFile> <DisableDevices> <saveClientFile>"
0028     echo "  run_number        = run number"
0029     echo "  HWUpload          = set to true if you want to upload the HW config to the DB"
0030     echo "  AnalysisUpload    = set to true if you want to upload the analysis results to the DB"
0031     echo "  DB_partition_name = Name of the corresponding DB partition"
0032     echo "  UseClientFile     = set to true if you want to analyze an existing client file rather than the source file(s)"
0033     echo "  DisableDevices    = set to true if you want to disable devices in the DB (normally set False)"
0034     echo "  saveClientFile    = set to true if you want to write the client file to disk (normally set True)"
0035 }
0036 if [ $# -eq 0 ]; then
0037     usage
0038     exit 0
0039 fi
0040 if [ $1 = "usage" ]; then
0041     usage
0042     exit 0
0043 fi
0044 if [ $# -lt 7 ]; then
0045     echo "Not enough arguments specified!"
0046     usage
0047     exit 0
0048 fi
0049 
0050 echo "Running analysis script ..."
0051 
0052 # Parse command line parameters
0053 RUNNUMBER=$1
0054 HWUPLOAD=$2         ; HWUPLOAD=`echo $HWUPLOAD | tr 'ft' 'FT'`
0055 ANALYSISUPLOAD=$3   ; ANALYSISUPLOAD=`echo $ANALYSISUPLOAD | tr 'ft' 'FT'`
0056 DBPARTITIONNAME=$4
0057 USECLIENTFILE=$5    ; USECLIENTFILE=`echo $USECLIENTFILE | tr 'ft' 'FT'`
0058 DISABLEDEVICES=$6   ; DISABLEDEVICES=`echo $DISABLEDEVICES | tr 'ft' 'FT'`
0059 DISABLEBADSTRIPS="False"
0060 SAVECLIENTFILE=$7   ; SAVECLIENTFILE=`echo $SAVECLIENTFILE | tr 'ft' 'FT'`
0061 
0062 # Settings for basic directories
0063 BASEDIR=/opt/cmssw
0064 echo "  CMSSW base directory     : "$BASEDIR
0065 DATALOC=/opt/cmssw/Data
0066 echo "  Temporary storage area   : "$DATALOC
0067 SCRATCH=$BASEDIR/Data/$RUNNUMBER
0068 echo "  Output storage directory : "$SCRATCH
0069 TEMPLATEPY=/opt/cmssw/scripts/analysis_template_cfg.py
0070 echo "  Analysis template        : "$TEMPLATEPY
0071 echo "  ConfDB account           : "$CONFDB
0072 
0073 # set up CMSSW environment
0074 source $BASEDIR/scripts/setup.sh
0075 cd $BASEDIR/Stable/current/src
0076 eval `scram runtime -sh`
0077 
0078 # make the output storage directory if it does not already exist
0079 if [ ! -d $SCRATCH ]; then
0080   mkdir -p $SCRATCH
0081 fi
0082 
0083 # copy over the source file
0084 for SOURCEFILE in `ls $DATALOC | grep \`printf %08u $RUNNUMBER\` | grep Source`; do
0085   mv $DATALOC/$SOURCEFILE $SCRATCH
0086 done
0087 
0088 # make the analysis config file to run
0089 sed 's,RUNNUMBER,'$RUNNUMBER',g' $TEMPLATEPY \
0090   | sed 's,DBUPDATE,'$HWUPLOAD',g' \
0091   | sed 's,ANALUPDATE,'$ANALYSISUPLOAD',g' \
0092   | sed 's,DBPART,'$DBPARTITIONNAME',g' \
0093   | sed 's,CLIENTFLAG,'$USECLIENTFILE',g' \
0094   | sed 's,DATALOCATION,'$SCRATCH',g' \
0095   | sed 's,DISABLEDEVICES,'$DISABLEDEVICES',g' \
0096   | sed 's,DISABLEBADSTRIPS,'$DISABLEBADSTRIPS',g' \
0097   | sed 's,SAVECLIENTFILE,'$SAVECLIENTFILE',g' \
0098   > $SCRATCH/analysis_${RUNNUMBER}_cfg.py
0099 
0100 # run the analysis!
0101 source /opt/trackerDAQ/config/oracle.env.bash
0102 cd $SCRATCH
0103 DATESUFF=`date +%s`  # to get consistent dates across logfiles
0104 echo -n "  Running analysis ... "
0105 cmsRun analysis_${RUNNUMBER}_cfg.py > analysis_${RUNNUMBER}_${DATESUFF}.cout
0106 echo "done."
0107 mv debug.log   analysis_${RUNNUMBER}_${DATESUFF}.debug.log
0108 mv info.log    analysis_${RUNNUMBER}_${DATESUFF}.info.log
0109 mv warning.log analysis_${RUNNUMBER}_${DATESUFF}.warning.log
0110 mv error.log   analysis_${RUNNUMBER}_${DATESUFF}.error.log
0111 echo "  Please check the output  : ${SCRATCH}"/analysis_${RUNNUMBER}_${DATESUFF}.*
0112 
0113 # mv client file to the output directory
0114 if [ $USECLIENTFILE = False ] && [ $SAVECLIENTFILE = True ] ; then
0115   CLIENTFILE=$(ls /tmp | grep $RUNNUMBER | grep Client)
0116   if [ -n "$CLIENTFILE" ] ; then
0117     mv /tmp/$CLIENTFILE $SCRATCH
0118   else
0119     echo "No client file found to copy!"
0120   fi
0121 fi
0122 
0123 # copy raw data to the output directory
0124 RAWFILES=$(ls $DATALOC/closed | grep `printf %08u $RUNNUMBER`)
0125 for file in $RAWFILES; do
0126   mv $DATALOC/closed/$file $SCRATCH
0127 done
0128 
0129 # create a cfg so users can run from raw again (needs the converted root files as input)
0130 cat $BASEDIR/scripts/sourcefromraw_template_cfg.py \
0131   | sed 's,RUNNUMBER,'$RUNNUMBER',g' \
0132   | sed 's,DBPART,'$DBPARTITIONNAME',g' \
0133   > $SCRATCH/sourcefromraw_${RUNNUMBER}_cfg.py
0134 for file in `ls USC*storageManager*dat` ; do
0135   echo "process.source.fileNames.extend(cms.untracked.vstring('file:`basename $file .dat`.root'))" >> sourcefromraw_${RUNNUMBER}_cfg.py
0136 done
0137 
0138 # run conversion, only automatic in TAC
0139 if [ -n "`uname -n | grep cmstracker029`" ] ; then
0140   /opt/cmssw/scripts/run_conversion.sh $RUNNUMBER
0141 fi