FRIB_e21062/convertRoot.sh

97 lines
2.2 KiB
Bash
Raw Normal View History

2022-06-08 14:43:03 -04:00
2022-06-08 15:24:21 -04:00
nCore=15;
2022-06-08 14:43:03 -04:00
if [ $# -eq 0 ]; then
echo "Usage: "
echo " ./convertRoot.sh [Start_RunNum] [Stop_RunNum]"
exit;
fi
runNum1=$1
runNum2=$2
2022-06-08 15:24:21 -04:00
overWrite=0
if [[ ${runNum1} -lt 0 ]]; then
overWrite=1
runNum1=$(( ${runNum1} * (-1) ))
fi
if [[ ${runNum2} -lt 0 ]]; then
overWrite=1
runNum2=$(( ${runNum2} * (-1) ))
fi
echo "is overWrite : ${overWrite} | ${runNum1} ${runNum2}"
2022-06-08 14:43:03 -04:00
for (( runNum=${runNum1}; runNum <=${runNum2}; runNum++)); do
nFile=$(ls -1 rawdata/run${runNum}/run*evt | wc -l)
files=$(ls -1 rawdata/run${runNum}/run*evt)
nLoop=$((${nFile}/nCore+1))
echo "===== number of files in run-${runNum} = ${nFile}"
echo " number of loops = ${nLoop}"
echo "================================================="
i=0
while [[ $i -lt ${nLoop} ]]; do
j=0
while [[ $j -lt ${nCore} ]]; do
SegNum=$((${nCore}*i+j))
if [[ ${SegNum} -ge ${nFile} ]]; then break; fi
#patching the prefix ZERO
if [ $runNum -lt 10 ]; then
runPrefix="000"
elif [ $runNum -lt 100 ]; then
runPrefix="00"
elif [ $runNum -lt 1000 ]; then
runPrefix="0"
fi
#patching the prefix ZERO for segment
if [ $SegNum -lt 10 ]; then
segPrefix="0"
else
segPrefix=""
fi
fileName=rawdata/run${runNum}/run-${runPrefix}${runNum}-${segPrefix}${SegNum}.evt
outFileName=root_data/run-${runPrefix}${runNum}-${segPrefix}${SegNum}.root
2022-06-08 15:24:21 -04:00
if [[ ${overWrite} -gt 0 ]]; then
2022-06-08 14:43:03 -04:00
echo ${fileName}
armory/EventBuilder ${outFileName} 1 250 ${fileName} > /dev/null &
2022-06-08 15:24:21 -04:00
else
if [[ -f ${outFileName} ]]; then
echo "${outFileName} exist. Skip."
else
echo ${fileName}
armory/EventBuilder ${outFileName} 1 250 ${fileName} > /dev/null &
fi
2022-06-08 14:43:03 -04:00
fi
((j += 1))
done
sleep 2
SegNum0=$((${nCore}*i))
2022-06-08 15:24:21 -04:00
SegNum1=$((${nCore}*i + j - 1 ))
2022-06-08 14:43:03 -04:00
while true; do
2022-06-08 15:24:21 -04:00
nthings=`ps aux | grep "armory/[E]ventBuilder"| wc -l`
2022-06-08 14:43:03 -04:00
echo $(date)" || "$nthings" EventBuilder are running. $runNum, ${SegNum0}-${SegNum1}"
if [[ $nthings > 0 ]]; then
sleep 10;
else
break
fi
done
((i += 1))
done
done