#!/bin/csh
#usage: g4bl_wrap.csh <RunID>

# Logging data
echo "Running on `hostname -f`"
echo "Processor - `cat /proc/cpuinfo |grep 'model name'`"
echo "Physical memory - `cat /proc/meminfo | grep 'MemTotal'`"
setenv PHYS_MEM `cat /proc/meminfo | grep "MemTotal:" | cut -c 14-23`
echo "Physical memory (${PHYS_MEM}): `expr ${PHYS_MEM} / 1048576` MB"
echo
echo "Grid job: ${EDG_WL_JOBID} "
echo "running at: ${SITE_NAME} on CE: ${GLOBUS_CE}"
echo "Job spooled as: ${PBS_JOBID} in queue: ${PBS_QUEUE}"
echo "Running as user: ${USER}"
echo ; echo ;
echo "mu.datacards:"
echo "-----------------------------------------"
cat mu.datacards
echo "-----------------------------------------"
echo 
echo "AnaParams.dat:"
echo "-----------------------------------------"
cat AnaParams.dat
echo "-----------------------------------------"
echo ; echo ;

setenv GRIDDIR "gsiftp://dgc-grid-38.brunel.ac.uk/storage/for/LCG/mice/BeamOptics"

echo "Fetching data: ${GRIDDIR}/for009.dat.$1.gz"
globus-url-copy "${GRIDDIR}/for009.dat.$1.gz" "file://`pwd`/for009.dat.gz"
gunzip -v for009.dat.gz
echo 
date
echo ; echo ;

# Setup:
source ${VO_MICE_SW_DIR}/g4mice-20071214/setupmice.csh

# Run
${VO_MICE_SW_DIR}/g4mice-20071214/MICE/Applications/Analysis/Analysis mu.datacards

echo ; echo ;
date
echo ; echo ;
rm -f *.dat
ls -l
