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