#!/bin/bash
#
# example.slurm
# Invoke with:
# sbatch -p express example.slurm

# Uncomment the following to see the values of SLURM Environment variables
# echo "slurm host is"
# echo $SLURMD_NODENAME
# echo "slurm queue is"
# echo $SLURM_JOB_PARTITION
# echo "slurm working directory absolute is"
# echo $SLURM_SUBMIT_DIR
# echo "slurm batch id"
# echo $SLURM_JOB_ID
# echo "slurm job name from me is"
# echo $SLURM_JOB_NAME

source /app/cern/root_v6.08.06/bin/thisroot.sh

# Make sure we are in the right directory in case writing files
mkdir -p /disk/data12/lhcb/saslie/scratch/$SLURM_JOB_ID
mkdir /disk/data12/lhcb/saslie/scratch/$SLURM_JOB_ID/data
mkdir /disk/data12/lhcb/saslie/scratch/$SLURM_JOB_ID/plots
mkdir /disk/data12/lhcb/saslie/scratch/$SLURM_JOB_ID/plots/points

cp test2.py /disk/data12/lhcb/saslie/scratch/$SLURM_JOB_ID
cp raremodel.py /disk/data12/lhcb/saslie/scratch/$SLURM_JOB_ID
cp pdg_const.py /disk/data12/lhcb/saslie/scratch/$SLURM_JOB_ID
cp helperfunctions.py /disk/data12/lhcb/saslie/scratch/$SLURM_JOB_ID

cd /disk/data12/lhcb/saslie/scratch/$SLURM_JOB_ID

# Run actual commands here
echo "Starting simulation"
python test2.py
echo "Simulation finished"

cp -a /disk/data12/lhcb/saslie/scratch/$SLURM_JOB_ID/  /disk/data12/lhcb/saslie/jobs
cp /disk/data12/lhcb/saslie/scratch/$SLURM_JOB_ID/data/*.pkl /disk/data12/lhcb/saslie/data
# Remove scratch directory at the end of your job
# Do not forget to copy any output first to a safe place
rm -rf /disk/data12/lhcb/saslie/scratch/$SLURM_JOB_ID

echo "Data moved to final folder
