Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:08:47

0001 #!/bin/sh
0002 #dkcira - 2006.08.20, add more flexibility, change to options instead of add more flexibility, positional parameters
0003 
0004 
0005 ###############################################################################################################
0006 # users can change this to their default directory that will overwrite command line options
0007 ###############################################################################################################
0008 #DEFAULT_CASTOR_OUTPUT_DIRECTORY="/castor/cern.ch/user/d/dkcira/MTCC/2006_08_16_090"
0009 
0010 
0011 ###############################################################################################################
0012 # read options
0013 ###############################################################################################################
0014 echo $0 $@; # echo $OPTIND;
0015 OPTERROR=11; # error option to use when exiting
0016 #
0017 show_usage(){
0018   echo ""
0019   echo "Usage:"
0020   echo "`basename $0` -r mtcc_runnumber [ -w which_input_files -f first_file_of_run -l last_file_of_run -p mtcc_pedestal_runnr -o output_directory_in_castor  -t input_file_ending (default dat) -h ]";
0021   echo ""
0022   echo " -h"
0023   echo "     print out this message"
0024   echo " -r  mtcc_runnumber"
0025   echo "      run number you want to reconstruct"
0026   echo " -w which_input_files :"
0027   echo "      1 - copy files from castor (default option)"
0028   echo "      2 - run directly on castor files"
0029   echo "      3 - copy files from cmsdisk0"
0030   echo "      4 - run on local files in the subdirectory InputFiles/"
0031   echo " -o output_directory_in_castor :"
0032   echo "      Set this for your output files to be copied to castor."
0033   echo "      If DEFAULT_CASTOR_OUTPUT_DIRECTORY is set in the script, it will ignore this option"
0034   echo ""
0035 }
0036 # Exit and complain if no argument given.
0037 if [ -z $1 ]; then show_usage; exit $OPTERROR; fi
0038 #
0039 # echo "OPTIND=$OPTIND"; echo "#=$#";
0040 while getopts ":r:p:f:l:w:o:t:h" Option
0041 do
0042   case $Option in
0043     r)  RUNNR=$OPTARG; echo "will reconstruct RUNNR=$RUNNR" ;;
0044     p)  PED_RUNNR=$OPTARG; echo "will create pedestals from PED_RUNNR=$PED_RUNNR" ;;
0045     f)  FIRSTFILE=$OPTARG; echo "first file of run to be reconstructed FIRSTFILE=$FIRSTFILE" ;;
0046     l)  LASTFILE=$OPTARG; echo "last file of run to be reconstructed LASTFILE=$LASTFILE" ;;
0047     w)  WHICH_INPUT_FILES=$OPTARG; echo "WHICH_INPUT_FILES=$WHICH_INPUT_FILES" ;;
0048     o)  WHERE_TO_COPY_OUTPUT=$OPTARG; echo "WHERE_TO_COPY_OUTPUT=$WHERE_TO_COPY_OUTPUT" ;;
0049     t)  INPUT_FILE_ENDING=$OPTARG; echo "INPUT_FILE_ENDING=$INPUT_FILE_ENDING" ;;
0050     h)  show_usage; exit 0;;
0051     *)  echo "No such option -${Option}";;
0052   esac
0053 done
0054 shift $(($OPTIND - 1)) # Decrements the argument pointer so it points to next argument.
0055 
0056 
0057 ###############################################################################################################
0058 # define functions
0059 ###############################################################################################################
0060 #--- this function has to be called first, obviously
0061 set_shell_variables(){
0062  # this directory must be visible from remote batch machine
0063  DIR_WHERE_TO_EVAL="/afs/cern.ch/user/d/dkcira/scratch0/MTCC/2006_08_14_code_090/CMSSW_0_9_0"
0064  # if you want some example pedestals
0065  PEDESTAL_DIR="/afs/cern.ch/user/d/dkcira/scratch0/MTCC/2006_08_14_code_090/pedestals";
0066  # this will probably remain always 1 from now on
0067  MAX_PED_FILES_TO_RUN_OVER=1;
0068  # for online db access. some variables for the oracle tool of cmssw are not set anymore
0069  LOCAL_ORACLE_ADMINDIR="/afs/cern.ch/project/oracle/admin/"
0070  #--
0071  # username to connect to cmsdisk0.cern.ch for asking list of files and copying them
0072  BATCH_USER_NAME=`whoami`
0073  # these have changed completely, need to find out
0074  CASTOR_DIR="/castor/cern.ch/cms/MTCC/data/0000${RUNNR}/A"
0075  PED_CASTOR_DIR="/castor/cern.ch/cms/MTCC/data/0000${PED_RUNNR}/A"
0076  #
0077  # directory where the job is run or submitted
0078  if [ "${LS_SUBCWD+set}" = set ]; then
0079    LK_WKDIR="${LS_SUBCWD}" # directory where you submit in case of bsub
0080    WWDIR="${WORKDIR}"
0081  else
0082    LK_WKDIR=`pwd`          # directory where you run locally otherwise
0083    WWDIR=`pwd`
0084  fi
0085  #
0086  # this directory will be created, use '/pool' for production and '/tmp' for testing
0087  MTCC_OUTPUT_DIR="${WWDIR}/mtcc_${RUNNR}"
0088  # directory where to copy locally input files, separate from above as this does not necessarely need to be recreated each time
0089  MTCC_INPUT_DIR="${WWDIR}/InputFiles"
0090  PED_MTCC_INPUT_DIR="${WWDIR}/InputFiles"
0091  # pedestals
0092  PED_CFG="${MTCC_OUTPUT_DIR}/${RUNNR}_mtccped.cfg";
0093  PED_LOG_FILE="${MTCC_OUTPUT_DIR}/${RUNNR}_mtcc_pedestals.log";
0094  # reconstruction
0095  LIST_OF_CFG_FILES=""; # start empty, cfg files are added from script
0096  GENERAL_LOG_FILE="${MTCC_OUTPUT_DIR}/${RUNNR}_reco_${FIRSTFILE}.log"
0097  LOCAL_INPUT_DIRECTORY="${MTCC_OUTPUT_DIR}/InputFiles";
0098  # templates
0099  TEMPLATE_CMSSW_CFG="${LK_WKDIR}/template_mtccoffline.cfg"
0100  TEMPLATE_PED_CFG="${LK_WKDIR}/template_mtccped.cfg"
0101  # echo '###########################################################'
0102  # echo 'SHELL VARIABLES'; set; export;
0103  # echo '###########################################################'
0104 }
0105 
0106 #--- initial checks for inconsistencies
0107 inital_checks_and_settings(){
0108   # need a run
0109   if [ "X$RUNNR" == "X" ]; then
0110    echo "You did not choose a run number. Stopping here!"
0111    exit $OPTERROR;
0112   fi
0113 
0114   # need templates
0115   if [ ! -f "$TEMPLATE_CMSSW_CFG" ]; then echo "file ${TEMPLATE_CMSSW_CFG} does not exist, stopping here"; exit $OPTERROR; fi
0116   if [ ! -f "$TEMPLATE_PED_CFG" ]; then echo "file ${TEMPLATE_PED_CFG} does not exist, stopping here"; exit $OPTERROR; fi
0117 
0118   # need input files option
0119   if [ -z "$WHICH_INPUT_FILES" ] ; then WHICH_INPUT_FILES=1; fi
0120   case $WHICH_INPUT_FILES in
0121         1|2|3|4) echo "WHICH_INPUT_FILES=$WHICH_INPUT_FILES";;
0122         *) echo "no such WHICH_INPUT_FILES=$WHICH_INPUT_FILES . exit here!"; exit $OPTERROR;;
0123   esac
0124 
0125   # choose file ending, maybe will go to "root" later
0126   if [ -z "$INPUT_FILE_ENDING" ] ; then
0127      INPUT_FILE_ENDING="dat";
0128      echo "Using default INPUT_FILE_ENDING=$INPUT_FILE_ENDING";
0129   fi
0130 
0131   # first choose castor directory from command line or default variable
0132   if [ "X${DEFAULT_CASTOR_OUTPUT_DIRECTORY}" != "X" ]; then # if set and not empty
0133          echo "Using castor directory from default variable DEFAULT_CASTOR_OUTPUT_DIRECTORY";
0134          WHERE_TO_COPY_OUTPUT="$DEFAULT_CASTOR_OUTPUT_DIRECTORY";
0135   elif [  -n "$WHERE_TO_COPY_OUTPUT" ]; then
0136          echo "Using castor directory from command line option";
0137   else
0138          echo "Output files will NOT be copied to castor.";
0139          CASTOROUTPUT="no"
0140   fi
0141   # then check if castor directory exists
0142   if [ "$CASTOROUTPUT" != "no" ] ; then
0143    if nsls -d "$WHERE_TO_COPY_OUTPUT" > /dev/null # Suppress default output
0144    then 
0145      echo "Using $WHERE_TO_COPY_OUTPUT to copy files to castor";
0146    else
0147      echo "Directory WHERE_TO_COPY_OUTPUT=$WHERE_TO_COPY_OUTPUT does not exist on castor.";
0148      echo "Stopping here!"; exit $OPTERROR;
0149    fi
0150   fi
0151 
0152   # document which code you were using
0153   echo "Using code from ${DIR_WHERE_TO_EVAL}";
0154 }
0155 
0156 #---
0157 create_output_directory(){
0158   if [ -d "$MTCC_OUTPUT_DIR" ]; then
0159     echo "directory ${MTCC_OUTPUT_DIR} already exists, stopping here"; exit $OPTERROR;
0160   else
0161     echo "creating directory ${MTCC_OUTPUT_DIR}"; mkdir $MTCC_OUTPUT_DIR;
0162   fi
0163 }
0164 
0165 #---
0166 get_list_of_local_files(){
0167  echo "Getting list of files to be reconstructed from local directory."
0168  if [ -z "$FIRSTFILE" ] ; then FIRSTFILE=1  ; fi
0169  if [ -z "$LASTFILE" ]  ; then LASTFILE=`ls $LOCAL_INPUT_DIRECTORY | grep ${RUNNR} | grep "\.${INPUT_FILE_ENDING}" | wc -l | sed 's/[ ]*//g'`; fi
0170  let "HOWMANYFILES = $LASTFILE - $FIRSTFILE + 1";
0171  echo "FIRSTFILE=$FIRSTFILE LASTFILE=$LASTFILE HOWMANYFILES=$HOWMANYFILES"
0172  #
0173  # the funny sort is done so that the files are ordered 1, 2, 3, ..., 10, 11, ..., and not 1,10,11,...,2,20, and so on
0174  LIST_OF_DATA_FILES=`ls $LOCAL_INPUT_DIRECTORY |  grep ${RUNNR} | grep "\.${INPUT_FILE_ENDING}" | sed 's/^.* //' | sort -n -t . +4 | head -${LASTFILE} | tail -${HOWMANYFILES}`
0175  if [ "$LIST_OF_DATA_FILES" == "" ] ; then echo "No input reco files found!!!!!! Stopping here"; exit $OPTERROR; fi
0176 }
0177 
0178 #---
0179 get_list_of_local_pedestal_files(){
0180  echo "Getting list of pedestal files from local directory."
0181  if [ $MAX_PED_FILES_TO_RUN_OVER -eq 0 ]
0182  then
0183    LIST_OF_PED_DATA_FILES=`ls $LOCAL_INPUT_DIRECTORY | grep "\.${INPUT_FILE_ENDING}" | sed 's/^.* //'`
0184  else
0185    echo "   !!! Caution !!!      limiting max. nr. of files per run to ${MAX_PED_FILES_TO_RUN_OVER}"
0186    LIST_OF_PED_DATA_FILES=`ls $LOCAL_INPUT_DIRECTORY | grep "\.${INPUT_FILE_ENDING}" | head -${MAX_PED_FILES_TO_RUN_OVER} | sed 's/^.* //'`
0187  fi
0188  if [ "$LIST_OF_PED_DATA_FILES" == "" ] ; then echo "No input pedestal files found!!!!!! Stopping here"; exit $OPTERROR; fi
0189 }
0190 
0191 #---
0192 get_list_of_castor_files(){
0193  echo "Getting list of files to be reconstructed from castor."
0194  if [ -z "$FIRSTFILE" ] ; then FIRSTFILE=1  ; fi
0195  if [ -z "$LASTFILE" ]  ; then LASTFILE=`nsls $CASTOR_DIR | grep ${RUNNR} | grep "\.${INPUT_FILE_ENDING}" | wc -l | sed 's/[ ]*//g'`; fi
0196  let "HOWMANYFILES = $LASTFILE - $FIRSTFILE + 1";
0197  echo "FIRSTFILE=$FIRSTFILE LASTFILE=$LASTFILE HOWMANYFILES=$HOWMANYFILES"
0198  echo "getting from CASTOR the list of files corresponding to run ${RUNNR}";
0199  LIST_OF_DATA_FILES=`nsls $CASTOR_DIR | grep ${RUNNR} | grep "\.${INPUT_FILE_ENDING}" | sed 's/^.* //' | sort -n -t . +4 | head -${LASTFILE} | tail -${HOWMANYFILES}`
0200  if [ "$LIST_OF_DATA_FILES" == "" ] ; then echo "No input files found!!!!!! Stopping here"; exit $OPTERROR; fi
0201 }
0202 
0203 #---
0204 get_list_of_pedestal_castor_files(){
0205  echo "Getting list of pedestal files to be reconstructed from castor."
0206  if [ $MAX_PED_FILES_TO_RUN_OVER -eq 0 ]
0207  then
0208    LIST_OF_PED_DATA_FILES=`nsls $CASTOR_DIR | grep "\.${INPUT_FILE_ENDING}" | sed 's/^.* //'`
0209  else
0210    echo "   !!! Caution !!!      limiting nr. of files for calculating pedestals to ${MAX_PED_FILES_TO_RUN_OVER}"
0211    LIST_OF_PED_DATA_FILES=`nsls $CASTOR_DIR | grep "\.${INPUT_FILE_ENDING}" | head -${MAX_PED_FILES_TO_RUN_OVER} | sed 's/^.* //'`
0212  fi
0213  if [ "$LIST_OF_PED_DATA_FILES" == "" ] ; then echo "No input pedestal files found!!!!!! Stopping here"; exit $OPTERROR; fi
0214 }
0215 
0216 #---
0217 copy_castor_files_locally(){
0218   echo "LIST_OF_DATA_FILES="; echo "$LIST_OF_DATA_FILES";
0219   echo "Will copy locally the input files from castor.";
0220   if [ -d "$MTCC_INPUT_DIR" ]; then
0221     echo "directory ${MTCC_INPUT_DIR} already exists. copying files there";
0222   else
0223     echo "creating directory ${MTCC_INPUT_DIR}"; mkdir $MTCC_INPUT_DIR;
0224   fi
0225   for rfile in $LIST_OF_DATA_FILES
0226   do
0227     if [ -f ${MTCC_INPUT_DIR}/${rfile} ]; then
0228       echo " ${MTCC_INPUT_DIR}/${rfile} exists already, not copying."
0229     else
0230       echo "copying $CASTOR_DIR/${rfile} to ${MTCC_INPUT_DIR}/${rfile}"
0231       rfcp $CASTOR_DIR/${rfile} ${MTCC_INPUT_DIR}/${rfile}
0232     fi
0233   done
0234 }
0235 
0236 #---
0237 copy_castor_pedestal_files_locally(){
0238   echo "LIST_OF_PED_DATA_FILES="; echo "$LIST_OF_PED_DATA_FILES";
0239   echo "Will copy locally the pedestal files from castor.";
0240   if [ -d "$MTCC_INPUT_DIR" ]; then
0241     echo "directory ${MTCC_INPUT_DIR} already exists. copying files there";
0242   else
0243     echo "creating directory ${MTCC_INPUT_DIR}"
0244     mkdir $MTCC_INPUT_DIR;
0245   fi
0246   for rfile in $LIST_OF_PED_DATA_FILES
0247   do
0248     if [ -f ${MTCC_INPUT_DIR}/${rfile} ]; then
0249       echo " ${MTCC_INPUT_DIR}/${rfile} exists already, not copying."
0250     else
0251       echo "copying $CASTOR_DIR/${rfile} to ${MTCC_INPUT_DIR}/${rfile}"
0252       rfcp $CASTOR_DIR/${rfile} ${MTCC_INPUT_DIR}/${rfile}
0253     fi
0254   done
0255 }
0256 
0257 #---
0258 get_list_of_cmsdisk0_files(){
0259  echo "Getting list of files to be reconstructed from cmsdisk0."
0260  if [ -z "$FIRSTFILE" ] ; then FIRSTFILE=1  ; fi
0261  if [ -z "$LASTFILE" ]  ; then LASTFILE=`ssh -n ${BATCH_USER_NAME}@cmsdisk0 'ls /data0/mtcc_0_9_0/' | grep ${RUNNR} | grep "\.${INPUT_FILE_ENDING}" | wc -l | sed 's/[ ]*//g'`; fi
0262  let "HOWMANYFILES = $LASTFILE - $FIRSTFILE + 1";
0263  echo "FIRSTFILE=$FIRSTFILE LASTFILE=$LASTFILE HOWMANYFILES=$HOWMANYFILES"
0264  LIST_OF_DATA_FILES=`ssh -n ${BATCH_USER_NAME}@cmsdisk0 'ls /data0/mtcc_0_9_0/' | grep ${RUNNR} | grep "\.${INPUT_FILE_ENDING}" | sort -n -t . +4 | head -${LASTFILE} | tail -${HOWMANYFILES}`
0265  if [ "$LIST_OF_DATA_FILES" == ""   ] ; then
0266    echo "No input files found!!!!!! Stopping here"; exit $OPTERROR;
0267  fi
0268 }
0269 
0270 #---
0271 copy_cmsdisk0_files_locally(){
0272   echo "LIST_OF_DATA_FILES=$LIST_OF_DATA_FILES"
0273   echo "Will copy locally the input files from cmsdisk0.";
0274   if [ -d "$MTCC_INPUT_DIR" ]; then
0275     echo "directory ${MTCC_INPUT_DIR} already exists. copying files there";
0276   else
0277     echo "creating directory ${MTCC_INPUT_DIR}"; mkdir $MTCC_INPUT_DIR;
0278   fi
0279   for rfile in $LIST_OF_DATA_FILES
0280   do
0281     if [ -f ${MTCC_INPUT_DIR}/${rfile} ]; then
0282       echo " ${MTCC_INPUT_DIR}/${rfile} exists already, not copying."
0283     else
0284       echo "copying  ${BATCH_USER_NAME}@cmsdisk0.cern.ch:/data0/mtcc_0_9_0/${rfile} to ${MTCC_INPUT_DIR}/${rfile}"
0285       scp -c blowfish ${BATCH_USER_NAME}@cmsdisk0.cern.ch:/data0/mtcc_0_9_0/${rfile} ${MTCC_INPUT_DIR}/${rfile}
0286     fi
0287   done
0288 }
0289 
0290 #---
0291 get_list_of_cmsdisk0_pedestal_files(){
0292  echo "Getting list of pedestal files from cmsdisk0."
0293  if [ $MAX_PED_FILES_TO_RUN_OVER -eq 0 ]
0294  then
0295    LIST_OF_PED_DATA_FILES=`ssh -n ${BATCH_USER_NAME}@cmsdisk0 'ls /data0/mtcc_0_9_0/' | grep ${PED_RUNNR} | grep "\.${INPUT_FILE_ENDING}"`
0296  else
0297    echo "   !!! Caution !!!      limiting max. nr. of pedestal files per run to ${MAX_PED_FILES_TO_RUN_OVER}"
0298    LIST_OF_PED_DATA_FILES=`ssh -n ${BATCH_USER_NAME}@cmsdisk0.cern.ch 'ls /data0/mtcc_0_9_0/' | grep ${PED_RUNNR} | grep "\.${INPUT_FILE_ENDING}" | head  -${MAX_PED_FILES_TO_RUN_OVER}`
0299  fi
0300  if [ "$LIST_OF_PED_DATA_FILES" == ""   ] ;
0301  then
0302    echo "No input files found!!!!!! Stopping here";
0303    exit $OPTERROR;
0304  fi
0305 }
0306 
0307 #---
0308 copy_cmsdisk0_pedestal_files_locally(){
0309   echo "LIST_OF_PED_DATA_FILES=$LIST_OF_PED_DATA_FILES"
0310   echo "Will copy locally the pedestal files from cmsdisk0.";
0311   if [ -d "$MTCC_INPUT_DIR" ]; then
0312     echo "directory ${MTCC_INPUT_DIR} already exists. copying files there";
0313   else
0314     echo "creating directory ${MTCC_INPUT_DIR}"
0315     mkdir $MTCC_INPUT_DIR;
0316   fi
0317   for rfile in $LIST_OF_PED_DATA_FILES
0318   do
0319     if [ -f ${MTCC_INPUT_DIR}/${rfile} ]; then
0320       echo " ${MTCC_INPUT_DIR}/${rfile} exists already, not copying."
0321     else
0322       echo "copying ${BATCH_USER_NAME}@cmsdisk0.cern.ch:/data0/mtcc_0_9_0/${rfile} to ${MTCC_INPUT_DIR}/${rfile}"
0323       scp -c blowfish ${BATCH_USER_NAME}@cmsdisk0.cern.ch:/data0/mtcc_0_9_0/${rfile} ${MTCC_INPUT_DIR}/${rfile}
0324     fi
0325   done
0326 }
0327 
0328 #---
0329 copy_example_pedestal_files(){
0330   echo "Copying example pedestals from ${PEDESTAL_DIR}";
0331   cp ${PEDESTAL_DIR}/insert_SiStripPedNoisesDB ${MTCC_OUTPUT_DIR}/.
0332   cp ${PEDESTAL_DIR}/insert_SiStripPedNoisesCatalog ${MTCC_OUTPUT_DIR}/.
0333 }
0334 
0335 #---
0336 create_cmssw_config_files(){
0337 # create the cfg files according to the number of files the run is split from DAQ
0338   for rfile in $LIST_OF_DATA_FILES
0339   do
0340     if [ "$WHICH_INPUT_FILES" == "1" ]; then # files in castor and copy locally
0341       FILE_FULL_PATH="\"${MTCC_INPUT_DIR}/${rfile}\"" # files are local or will be copied locally
0342     elif [ "$WHICH_INPUT_FILES" == "3" ]; then # can only copy locally in case of cmsdisk0
0343       FILE_FULL_PATH="\"${MTCC_INPUT_DIR}/${rfile}\"" # files are local or will be copied locally
0344     elif [ "$WHICH_INPUT_FILES" == "4" ]; then # they have already been copied to some local directory - access them directly
0345       FILE_FULL_PATH="\"${MTCC_INPUT_DIR}/${rfile}\"" # files are local or will be copied locally
0346     elif [ "$WHICH_INPUT_FILES" == "2" ]; then # files in castor, run remotely
0347        FILE_FULL_PATH="\"rfio:${CASTOR_DIR}/${rfile}\"" # files are in castor and not copied
0348     else
0349        echo "Do not know what to do WHICH_INPUT_FILES=${WHICH_INPUT_FILES}";
0350        echo "Stopping here!."; exit $OPTERROR;
0351     fi
0352     # cfg and log
0353     CMSSW_CFG="${MTCC_OUTPUT_DIR}/${RUNNR}_mtccoffline_${rfile}.cfg"
0354     LOG_FILE="${MTCC_OUTPUT_DIR}/${RUNNR}_mtccoffline_${rfile}.log"
0355     POOL_OUTPUT_FILE="${MTCC_OUTPUT_DIR}/${RUNNR}_rec_${rfile}.root"
0356     DQM_OUTPUT_FILE="${MTCC_OUTPUT_DIR}/${RUNNR}_dqm_${rfile}.root"
0357     #
0358     LIST_OF_CFG_FILES="${LIST_OF_CFG_FILES} ${CMSSW_CFG}"
0359     echo "creating $CMSSW_CFG";
0360     touch $CMSSW_CFG;
0361     cat  "$TEMPLATE_CMSSW_CFG" | sed "s@SCRIPT_POOL_OUTPUT_FILE@${POOL_OUTPUT_FILE}@" | sed "s@SCRIPT_DQM_OUTPUT_FILE@${DQM_OUTPUT_FILE}@" | sed "s@SCRIPT_LIST_OF_FILES@${FILE_FULL_PATH}@" >>  ${CMSSW_CFG}
0362   done
0363 }
0364 
0365 #---
0366 create_pedestal_config_file(){
0367 # create list with full paths
0368   PED_LIST_WITH_PATH="";
0369   for rfile in $LIST_OF_PED_DATA_FILES
0370   do
0371    if [ "$WHICH_INPUT_FILES" == "1" ]; then # files in castor and copy locally
0372        PED_LIST_WITH_PATH="${PED_LIST_WITH_PATH},\"${PED_MTCC_INPUT_DIR}/${rfile}\""        # local
0373    elif [ "$WHICH_INPUT_FILES" == "3" ]; then # can only copy locally in case of cmsdisk0
0374        PED_LIST_WITH_PATH="${PED_LIST_WITH_PATH},\"${PED_MTCC_INPUT_DIR}/${rfile}\""        # local
0375    elif [ "$WHICH_INPUT_FILES" == "4" ]; then # they have already been copied to some local directory - access them directly
0376        PED_LIST_WITH_PATH="${PED_LIST_WITH_PATH},\"${PED_MTCC_INPUT_DIR}/${rfile}\""        # local
0377    elif [ "$WHICH_INPUT_FILES" == "2" ]; then # files in castor, run remotely
0378        PED_LIST_WITH_PATH="${PED_LIST_WITH_PATH},\"rfio:${PED_CASTOR_DIR}/${rfile}\""       # castor
0379    else
0380        echo "Do not know what to do WHICH_INPUT_FILES=${WHICH_INPUT_FILES}";
0381        echo "Stopping here!."; exit $OPTERROR;
0382     fi
0383   done
0384   # remove first comma
0385   PED_LIST_WITH_PATH=`echo $PED_LIST_WITH_PATH | sed 's/\,//'`;
0386   echo "creating $PED_CFG";
0387   touch $PED_CFG;
0388   cat  "$TEMPLATE_PED_CFG" | sed "s@SCRIPT_LIST_OF_FILES@${PED_LIST_WITH_PATH}@" >>  ${PED_CFG}
0389 }
0390 
0391 #---
0392 runped(){
0393   cd ${DIR_WHERE_TO_EVAL}; eval `scramv1 runtime -sh`;
0394   export TNS_ADMIN=${LOCAL_ORACLE_ADMINDIR}
0395   export ORACLE_ADMINDIR=${LOCAL_ORACLE_ADMINDIR}
0396   cd ${MTCC_OUTPUT_DIR};
0397   echo "# ************************************************* CALCULATING THE PEDESTALS USING THE CFG FILE ${PED_CFG}"
0398   cat ${PED_CFG};
0399   cmsRun ${PED_CFG};
0400   echo "pedestal jobstatus: $?";
0401   mv ${MTCC_OUTPUT_DIR}/Source_*${PED_RUNNR}.root  ${PED_CFG}_pedestal_histograms.root
0402 }
0403 
0404 #---
0405 runcms(){
0406   cd ${DIR_WHERE_TO_EVAL}; eval `scramv1 runtime -sh`;
0407   export TNS_ADMIN=${LOCAL_ORACLE_ADMINDIR}
0408   export ORACLE_ADMINDIR=${LOCAL_ORACLE_ADMINDIR}
0409   cd ${MTCC_OUTPUT_DIR};
0410   for I_CFG in ${LIST_OF_CFG_FILES}
0411   do
0412     echo ""
0413     echo "########################################################################"
0414     echo "###### RUNNING THE RECONSTRUCTION USING THE CFG FILE ${I_CFG}"
0415     cmsRun ${I_CFG}
0416     echo "reconstruction jobstatus: $?";
0417     mv ${MTCC_OUTPUT_DIR}/monitor_cluster_summary.txt  ${I_CFG}_cluster_summary.txt
0418     mv ${MTCC_OUTPUT_DIR}/monitor_digi_summary.txt  ${I_CFG}_digi_summary.txt
0419   done
0420   cp  ${MTCC_OUTPUT_DIR}/insert_SiStripPedNoisesDB  ${MTCC_OUTPUT_DIR}/${RUNNR}_insert_SiStripPedNoisesDB
0421   cp  ${MTCC_OUTPUT_DIR}/insert_SiStripPedNoisesCatalog  ${MTCC_OUTPUT_DIR}/${RUNNR}_insert_SiStripPedNoisesCatalog
0422 }
0423 
0424 #---
0425 copy_output_to_castor(){
0426 case $# in
0427 1) OUTPUT_CASTOR_DIR="$1" ;;
0428 *) echo "No output castor directory given, not performing copy_output_to_castor." ;;
0429 esac
0430  # copy (some) output files to castor
0431  if [  "X$OUTPUT_CASTOR_DIR" != "X" ]; then
0432    echo "copying output files to $OUTPUT_CASTOR_DIR";
0433    for ifile in ${MTCC_OUTPUT_DIR}/${RUNNR}*
0434    do
0435     rfcp ${ifile}  ${OUTPUT_CASTOR_DIR}/.
0436    done
0437  fi
0438 }
0439 
0440 ###############################################################################################################
0441 # actual execution
0442 ###############################################################################################################
0443 # GENERAL
0444 set_shell_variables;
0445 inital_checks_and_settings;
0446 create_output_directory;
0447 ls -lh;
0448 
0449 # PEDESTALS
0450 if [ -n "$PED_RUNNR" ]; then
0451  if [ "$WHICH_INPUT_FILES" == "1" ]; then # files in castor and copy locally
0452    get_list_of_pedestal_castor_files;
0453    copy_castor_pedestal_files_locally;
0454  elif [ "$WHICH_INPUT_FILES" == "2" ]; then # files in castor, run remotely
0455    get_list_of_pedestal_castor_files;
0456  elif [ "$WHICH_INPUT_FILES" == "3" ]; then # can only copy locally in case of cmsdisk0
0457    get_list_of_cmsdisk0_pedestal_files;
0458    copy_cmsdisk0_pedestal_files_locally;
0459  elif [ "$WHICH_INPUT_FILES" == "4" ]; then # they have already been copied to some local directory - access them directly
0460    get_list_of_local_pedestal_files;
0461  else
0462    echo "Not clear where to get files WHICH_INPUT_FILES=$WHICH_INPUT_FILES"; echo "Stopping here!"; exit $OPTERROR;
0463  fi
0464  #
0465  create_pedestal_config_file;
0466  echo "Running pedestals. Log file: ${PED_LOG_FILE}";
0467  time runped > ${PED_LOG_FILE} 2>&1;
0468 else
0469   copy_example_pedestal_files;
0470 fi
0471 
0472 # RECONSTRUCTION
0473 #WHICH_INPUT_FILES
0474 #  echo "1 - copy files from castor (default option)"
0475 #  echo "2 - run directly on castor files"
0476 #  echo "3 - copy files from cmsdisk0"
0477 #  echo "4 - run on local files in InputFiles/ subdirectory"
0478 if [ "$WHICH_INPUT_FILES" == "1" ]; then # files in castor and copy locally
0479    get_list_of_castor_files;  
0480    copy_castor_files_locally;
0481 elif [ "$WHICH_INPUT_FILES" == "2" ]; then # files in castor, run remotely
0482    get_list_of_castor_files;
0483 elif [ "$WHICH_INPUT_FILES" == "3" ]; then # can only copy locally in case of cmsdisk0
0484    get_list_of_cmsdisk0_files;  
0485    copy_cmsdisk0_files_locally;
0486 elif [ "$WHICH_INPUT_FILES" == "4" ]; then # they have already been copied to some local directory - access them directly
0487    get_list_of_local_files;
0488 else
0489    echo "Not clear where to get files WHICH_INPUT_FILES=${WHICH_INPUT_FILES}"; echo "Stopping here!"; exit $OPTERROR;
0490 fi
0491 #
0492 create_cmssw_config_files;
0493 echo "Running reconstruction and monitoring. Log file: ${GENERAL_LOG_FILE}";
0494 time runcms > ${GENERAL_LOG_FILE} 2>&1;
0495 ls -lh . ${MTCC_OUTPUT_DIR}/ ;
0496 
0497 # copy output to CASTOR if the output directory variable is set
0498 if [ -n "WHERE_TO_COPY_OUTPUT" ]; then
0499    copy_output_to_castor "$WHERE_TO_COPY_OUTPUT";
0500 fi
0501 
0502 ###############################################################################################################
0503 # end
0504 ###############################################################################################################