#!/bin/bash

if [ "$#" -ne 3 ]; then
    echo "Usage: $0 runID timeWindow_ns option"
    echo "option: 0 - process raw data, 1 - process mapped data"
    echo "Exiting..."
    exit 1
fi

runID=$(printf "%03d" $1)
timeWindow=$2

option=$3

# rawFolder=/home/tandem/data1/2024_09_17Fap/data
# rawFolder=/mnt/d/17F
# rootFolder=/mnt/d/Remapped_files/17F_data/root_data
# rawFolder=/mnt/data1/vs19g/2024_06_27Al
# rootFolder=/home/vs19g/Desktop/27Al_Data/root_data
rawFolder=/mnt/data1/vs19g/2024_09_17Fap/data
rootFolder=/home/vs19g/Desktop/17F_Data/root_data

if [ $option -eq 0 ]; then

    # rsync -auh --info=progress2 splitpole@128.186.111.223:/media/nvmeData/2024_09_17Fap/*.fsu /home/tandem/data1/2024_09_17Fap/data

    fileList=`\ls -1 ${rawFolder}/*Run*_${runID}_*.fsu`

    time ./EventBuilder ${timeWindow} 0 0 100000000 ${fileList}

    outFile=${rawFolder}/*${runID}*${timeWindow}.root

    mv -vf ${outFile} ${rootFolder}/.

    time ./Mapper ${rootFolder}/*${runID}*${timeWindow}.root
fi

# root "processRun.C(\"${rootFolder}/Run_${runID}_mapped.root\")"
