File indexing completed on 2024-04-06 12:08:47
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 echo $0 $@;
0015 OPTERROR=11;
0016
0017 show_usage(){
0018 echo ""
0019 echo "Usage:"
0020 echo "`basename $0` -r mtcc_runnumber [ -i which_input_directory -o output_directory_in_castor -h ]";
0021 echo ""
0022 echo " -h"
0023 echo " print out this message"
0024 echo " -r mtcc_runnumber"
0025 echo " run number you want to filter"
0026 echo " -i which_input_directory"
0027 echo " Set this to castor directory or local directory"
0028 echo " If DEFAULT_CASTOR_INPUT_DIRECTORY is set in the script, it will ignore this option"
0029 echo " -o output_directory_in_castor :"
0030 echo " Set this for your output files to be copied to castor."
0031 echo " If DEFAULT_CASTOR_OUTPUT_DIRECTORY is set in the script, it will ignore this option"
0032 echo ""
0033 }
0034
0035
0036 if [ -z $1 ]; then show_usage; exit $OPTERROR; fi
0037
0038
0039 while getopts ":r:i:o:h" Option
0040 do
0041 case $Option in
0042 r) RUNNR=$OPTARG; echo "will reconstruct RUNNR=$RUNNR" ;;
0043 i) WHICH_INPUT_DIRECTORY=$OPTARG; echo "WHICH_INPUT_DIRECTORY=$WHICH_INPUT_DIRECTORY" ;;
0044 o) WHERE_TO_COPY_OUTPUT=$OPTARG; echo "WHERE_TO_COPY_OUTPUT=$WHERE_TO_COPY_OUTPUT" ;;
0045 h) show_usage; exit 0;;
0046 *) echo "No such option -${Option}";;
0047 esac
0048 done
0049 shift $(($OPTIND - 1))
0050
0051
0052
0053
0054
0055
0056 set_shell_variables(){
0057
0058 DIR_WHERE_TO_EVAL="/afs/cern.ch/user/d/dkcira/scratch0/MTCC/2006_08_14_code_090/CMSSW_0_9_0"
0059
0060 LOCAL_ORACLE_ADMINDIR="/afs/cern.ch/project/oracle/admin/"
0061
0062 BATCH_USER_NAME=`whoami`
0063
0064 if [ "${LS_SUBCWD+set}" = set ]; then
0065 LK_WKDIR="${LS_SUBCWD}"
0066 WWDIR="${WORKDIR}"
0067 else
0068 LK_WKDIR=`pwd`
0069 WWDIR=`pwd`
0070 fi
0071
0072 MTCC_OUTPUT_DIR="${WWDIR}/mtcc_filter_${RUNNR}"
0073
0074 TEMPLATE_FILTER_CFG="${LK_WKDIR}/template_filter.cfg"
0075
0076 FILTER_CFG="${MTCC_OUTPUT_DIR}/${RUNNR}_filter.cfg";
0077
0078 FILTER_LOG="${MTCC_OUTPUT_DIR}/${RUNNR}_filter.log";
0079
0080 FILTER_POOL_OUTPUT_FILE="${MTCC_OUTPUT_DIR}/${RUNNR}_filter_rec.root";
0081 DQM_OUTPUT_FILE="${MTCC_OUTPUT_DIR}/${RUNNR}_filter_dqm.root"
0082
0083 MAX_FILES_TO_RUN_OVER=100000;
0084
0085
0086
0087 }
0088
0089
0090
0091 inital_checks_and_settings(){
0092
0093 if [ "X$RUNNR" == "X" ]; then
0094 echo "You did not choose a run number. Stopping here!"
0095 exit $OPTERROR;
0096 fi
0097
0098
0099 if [ ! -f "$TEMPLATE_FILTER_CFG" ]; then echo "file ${TEMPLATE_FILTER_CFG} does not exist, stopping here"; exit $OPTERROR; fi
0100 if [ -f "$FILTER_CFG" ]; then echo "file ${FILTER_CFG} already exists, stopping here"; exit $OPTERROR; fi
0101
0102
0103 if [ "X$DEFAULT_INPUT_DIRECTORY" != "X" ]; then
0104 echo "Using input directory from default variable DEFAULT_INPUT_DIRECTORY";
0105 WHICH_INPUT_DIRECTORY="$DEFAULT_INPUT_DIRECTORY";
0106 elif [ -n "$WHICH_INPUT_DIRECTORY" ]; then
0107 echo "Using input directory from command line option.";
0108 else
0109 echo "No input directory. Stopping here!"; exit $OPTERROR;
0110 fi
0111
0112 if nsls -d "$WHICH_INPUT_DIRECTORY" >& /dev/null
0113 then
0114 echo "Input directory is castor $WHICH_INPUT_DIRECTORY";
0115 TYPE_INPUT_DIRECTORY=1;
0116 elif [ -d $WHICH_INPUT_DIRECTORY ] ; then
0117
0118 if [ "${InputFiles:0:1}" != "/" ] ; then
0119 WHICH_INPUT_DIRECTORY="${PWD}/${WHICH_INPUT_DIRECTORY}";
0120 fi
0121 echo "Input directory is local $WHICH_INPUT_DIRECTORY";
0122 TYPE_INPUT_DIRECTORY=2;
0123 else
0124 echo "Input directory does not exist $WHICH_INPUT_DIRECTORY"
0125 echo "Stopping here!"; exit $OPTERROR;
0126 fi
0127
0128
0129 if [ "X${DEFAULT_CASTOR_OUTPUT_DIRECTORY}" != "X" ]; then
0130 echo "Using castor directory from default variable DEFAULT_CASTOR_OUTPUT_DIRECTORY";
0131 WHERE_TO_COPY_OUTPUT="$DEFAULT_CASTOR_OUTPUT_DIRECTORY";
0132 elif [ -n "$WHERE_TO_COPY_OUTPUT" ]; then
0133 echo "Using castor directory from command line option";
0134 else
0135 echo "Output files will NOT be copied to castor.";
0136 CASTOROUTPUT="no"
0137 fi
0138
0139 if [ "$CASTOROUTPUT" != "no" ] ; then
0140 if nsls -d "$WHERE_TO_COPY_OUTPUT" > /dev/null
0141 then
0142 echo "Using $WHERE_TO_COPY_OUTPUT to copy files to castor";
0143 else
0144 echo "Directory WHERE_TO_COPY_OUTPUT=$WHERE_TO_COPY_OUTPUT does not exist on castor.";
0145 echo "Stopping here!"; exit $OPTERROR;
0146 fi
0147 fi
0148
0149
0150 echo "Using code from ${DIR_WHERE_TO_EVAL}";
0151 }
0152
0153
0154 create_output_directory(){
0155 if [ -d "$MTCC_OUTPUT_DIR" ]; then
0156 echo "directory ${MTCC_OUTPUT_DIR} already exists, stopping here"; exit $OPTERROR;
0157 else
0158 echo "creating directory ${MTCC_OUTPUT_DIR}"; mkdir $MTCC_OUTPUT_DIR;
0159 fi
0160 }
0161
0162
0163 get_list_of_input_files(){
0164 echo "getting the list of files corresponding to run ${RUNNR}";
0165 if [ "$TYPE_INPUT_DIRECTORY" == "1" ] ; then
0166 LIST_OF_DATA_FILES=`nsls $WHICH_INPUT_DIRECTORY | grep "${RUNNR}_rec" | grep '\.root' | head -${MAX_FILES_TO_RUN_OVER}`
0167 elif [ "$TYPE_INPUT_DIRECTORY" == "2" ] ; then
0168 LIST_OF_DATA_FILES=`ls $WHICH_INPUT_DIRECTORY | grep "${RUNNR}_rec" | grep '\.root' | head -${MAX_FILES_TO_RUN_OVER}`
0169 else
0170 echo "No such TYPE_INPUT_DIRECTORY=$TYPE_INPUT_DIRECTORY. Stopping here!"; exit $OPTERROR;
0171 fi
0172 if [ "X$LIST_OF_DATA_FILES" == "X" ] ; then echo "No input files found. Stopping here!"; exit $OPTERROR; fi
0173 }
0174
0175
0176 create_filter_config_file(){
0177
0178 LIST_WITH_PATH="";
0179 for rfile in $LIST_OF_DATA_FILES
0180 do
0181 if [ "$TYPE_INPUT_DIRECTORY" == "1" ]; then
0182 LIST_WITH_PATH="${LIST_WITH_PATH},\"rfio:${WHICH_INPUT_DIRECTORY}/${rfile}\""
0183 elif [ "$TYPE_INPUT_DIRECTORY" == "2" ] ; then
0184 LIST_WITH_PATH="${LIST_WITH_PATH},\"file:${WHICH_INPUT_DIRECTORY}/${rfile}\""
0185 else
0186 echo "No such TYPE_INPUT_DIRECTORY=$TYPE_INPUT_DIRECTORY. Stopping here!"; exit $OPTERROR;
0187 fi
0188 done
0189
0190 LIST_WITH_PATH=`echo $LIST_WITH_PATH | sed 's/\,//'`;
0191 echo "creating $FILTER_CFG";
0192 touch $FILTER_CFG;
0193 cat "$TEMPLATE_FILTER_CFG" | sed "s@SCRIPT_POOL_OUTPUT_FILE@${FILTER_POOL_OUTPUT_FILE}@" | sed "s@SCRIPT_DQM_OUTPUT_FILE@${DQM_OUTPUT_FILE}@" | sed "s@SCRIPT_LIST_OF_FILES@${LIST_WITH_PATH}@" >> ${FILTER_CFG}
0194 }
0195
0196
0197 runfilter(){
0198 cd ${DIR_WHERE_TO_EVAL}; eval `scramv1 runtime -sh`;
0199 cd ${MTCC_OUTPUT_DIR};
0200 echo "##### RUNNING THE RECONSTRUCTION USING THE CFG FILE ${FILTER_CFG}"
0201 cat ${FILTER_CFG}
0202 cmsRun ${FILTER_CFG}
0203 echo "filter jobstatus: $?";
0204 }
0205
0206
0207 copy_output_to_castor(){
0208 case $
0209 1) OUTPUT_CASTOR_DIR="$1" ;;
0210 *) echo "No output castor directory given, not performing copy_output_to_castor." ;;
0211 esac
0212
0213
0214 if [ "X$OUTPUT_CASTOR_DIR" != "X" ]; then
0215 echo "copying output files to $OUTPUT_CASTOR_DIR";
0216 for ifile in ${MTCC_OUTPUT_DIR}/${RUNNR}_filter*
0217 do
0218 rfcp ${ifile} ${OUTPUT_CASTOR_DIR}/.
0219 done
0220 fi
0221 }
0222
0223
0224
0225
0226
0227 ls -lh;
0228 set_shell_variables;
0229 inital_checks_and_settings;
0230 create_output_directory;
0231 get_list_of_input_files;
0232 create_filter_config_file;
0233 echo "Running filter. Log file: ${FILTER_LOG}";
0234 time runfilter > ${FILTER_LOG} 2>&1 ;
0235 ls -lh . ${MTCC_OUTPUT_DIR}/ ;
0236
0237
0238 if [ -n "WHERE_TO_COPY_OUTPUT" ]; then
0239 copy_output_to_castor "$WHERE_TO_COPY_OUTPUT";
0240 fi
0241
0242