run.sh 3.54 KB
Newer Older
Pavel Sharov's avatar
Pavel Sharov committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
#!/bin/bash

if [ -z ${GO4SYS+x} ]; then
	echo "GO4SYS is unset. Aborting.";
	exit;
else
	echo "GO4SYS is set to '$GO4SYS'";
fi

# =============================================================================

# Please specify the path to a directory which contains _ONLY_ the files you want to analyse
# You should not put the trailing slash sign (but actually if you will, it should not affect the result...)
# You need to have write access to this directory
INPUTLMDDIR=/home/LynxOS/mbsusr/mbsdaq/mbsrun/exp202003/data/clb

if [ ! -d "${INPUTLMDDIR}" ]; then
	echo -e "Directory ${INPUTLMDDIR} does not exist. Aborting."
	exit;
fi

# Please specify the path to the output directory where the resulting root files will be written
OUTPUTROOTDIR=/media/analysis_nas/exp202003/clb/root

# TODO check that ${OUTPUTROOTDIR} exists ???

# Please specify the input XML configuration file
SETUPFILE=/media/analysis_nas/exp202003/raw2/conversion/setupEXP2003.xml

# TODO check that ${SETUPFILE} exists

# Please specify how many threads do you want to occupy
NTHREADS=1

# Please specify the prefix for the generated lml files
# In principle, there are no constraints, but you may want to keep it the same as the directory name

PREFIX=crun_0

FILES=${INPUTLMDDIR}/${PREFIX}*.lmd

# Remove textual output if it already exists from previous analysis runs
if [ -d ${OUTPUTROOTDIR}/textoutput/ ]; then
  rm -fv ${OUTPUTROOTDIR}/textoutput/*.txt
else
  mkdir ${OUTPUTROOTDIR}/textoutput
fi

# Remove asf output if it already exists from previous analysis runs
if ! [ -d ${OUTPUTROOTDIR}/autosave/ ]; then
  mkdir ${OUTPUTROOTDIR}/autosave
fi
# =============================================================================

#NAMES=${FILES}-${INPUTLMDDIR}

# Count input data files
NFILES=`ls -1q ${FILES} | wc -l`

echo "nFiles=${NFILES}"
echo "nThreads=${NTHREADS}"

  #let IBATCH=1
let iFile=0

for INPUTFILENAME in ${FILES}
do
  NAME=$(basename "$INPUTFILENAME")
  OUTPUTFILENAME=${NAME//lmd/root}
  OUTPUTFILENAME=${OUTPUTROOTDIR}/${OUTPUTFILENAME}

  TEXTERRFILE=${OUTPUTROOTDIR}/textoutput/${NAME}_err.txt  # Default: textoutput/err.txt
  TEXTOUTFILE=${OUTPUTROOTDIR}/textoutput/${NAME}_out.txt  # Default: textoutput/out.txt # No reason to suppres
  AUTOSAVEFILE=${OUTPUTROOTDIR}/autosave/${NAME}_asf.root

  # Remove output file if it already exists from previous analysis runs
  if [ -f $OUTPUTFILENAME ]; then
    rm ${OUTPUTFILENAME}
  fi
  # Remove autosave file if it already exists from previous analysis runs
  if [ -f $AUTOSAVEFILE ]; then
    rm ${AUTOSAVEFILE}
  fi

  if [ $iFile -eq $NTHREADS ]; then
    echo -e "\e[1;32;1mWaiting for all threads to finish\e[0m"
    wait
    let iFile=0
  fi
	
  if [ $iFile -lt $NTHREADS ]; then

    ANARUNINFO="========================== ANALYSIS RUN INFO ===================================
    Current date and time                      ${DATETIME}
    Processing input file                      ${INPUTFILENAME}
    into output file                           ${OUTPUTFILENAME}
    Text output file:                          ${TEXTOUTFILE}
    Text error file:                           ${TEXTERRFILE}
    ============================================================================================"

# Starting outoutfile with ANARUNINFO 
cat > ${TEXTOUTFILE} << EOF
${ANARUNINFO}
EOF

    echo -e "\e[1m\e[34m${ANARUNINFO}\e[0m"

    echo -e "\e[1m\e[32m"`date` "Analysis started.\e[0m"

    go4analysis -file ${INPUTFILENAME} -store ${OUTPUTFILENAME} >> ${TEXTOUTFILE} 2> ${TEXTERRFILE} 

    let iFile++
  fi
done

echo -e "\e[1m\e[32m"`date` "Analysis finished.\e[0m"