#!/bin/bash
#./smalltpc-zsup-lvcard2-ssh.sh "0 1" 0 0 1008 0 5 300 1
fecs=$1
gain=$2
shaper=$3
samples=$4
channels=$5
threshold=$6
events=$7
runnb=$8
mydata=/home/jum/wdir/ilcdaq/data
#
echo "Init SRU for pedestal taking ..."
./srupup --sruif $SRUIF --cfgfile srupup-0-sw.cfg
echo "Next: Software trigger run for pedestals ..."
read -p "Exit[eE], else continue:" myinput
re='^[eE]'
if [[ "$myinput" =~ $re ]] ; then
    echo "EXITING"
    exit 1
fi
#
echo "Software trigger run OK?... $fecs"
read -p "Exit[eE], else continue:" myinput
if [[ "$myinput" =~ $re ]] ; then
    echo "EXITING"
    exit 2
fi
./smalltpc-test-sw-lvcard2-ssh.sh "${fecs}" ${gain} ${shaper} ${samples} ${channels} 100 ${runnb}
echo "Next: calculate pedestals ...."
read -p "Exit[eE], else continue:" myinput
if [[ "$myinput" =~ $re ]] ; then
    echo "EXITING"
    exit 2
fi
#
echo "Calculate pedestals ...."
./plotsmalltpcped.exe ${mydata}/smalltpc chamber-fec01-debug-clk0-ped0-thr0-g${gain}-s${shaper}-p1-${samples}-${runnb} pedrun
cat  ${mydata}/smalltpc/chamber-fec01-debug-clk0-ped0-thr0-g${gain}-s${shaper}-p1-${samples}-${runnb}-pedrun.csv
echo "Next: Init SRU for zerosuppression data taking ..."
read -p "Exit[eE], else continue:" myinput
if [[ "$myinput" =~ $re ]] ; then
    echo "EXITING"
    exit 3
fi
#
echo "Init SRU for zerosuppression data taking ..."
./srupup --sruif $SRUIF --cfgfile srupup-0-hw.cfg
echo "Next: Init SALTRos for zerosuppression data taking ..."
read -p "Exit[eE], else continue:" myinput
re='^[eE]'
if [[ "$myinput" =~ $re ]] ; then
    echo "EXITING"
    exit 1
fi
#
echo "Init SALTRos for zerosuppression data taking"

./ldsmalltpcped --filecsv ${mydata}/smalltpc/chamber-fec01-debug-clk0-ped0-thr0-g${gain}-s${shaper}-p1-${samples}-${runnb}-pedrun.csv --threshold $threshold
#./ldsmalltpcped --filecsv ${mydata}/smalltpc/chamber-fec01-debug-clk0-ped0-thr0-g${gain}-s${shaper}-p1-${samples}-${runnb}-pedrun.csv --rmsfactor 3.5
echo "Next: Data taking with ${events} events, shaper=${shaper}..."
re='^[eE]'
read -p "Exit[eE], else continue:" myinput
if [[ "$myinput" =~ $re ]] ; then
    echo "EXITING"
    exit 1
fi
#
echo "Data taking with ${events} events, shaper=${shaper}..."
#./smalltpc-run-lvcard2-ssh.sh "${fecs}" ${gain} ${shaper} ${samples} ${channels} ${threshold} ${events} ${runnb} 

