#!/bin/bash

# This program runs on the server with KNOWN_SERVER code.  It is invoked
# remotely by a KNOWN_LOCAL process on the MOPS master processing host.

set -e

# Quickie to run KNOWN_SERVER from pre-exported data.  Data must be
# exported via
#
#   exportSim --known --name MOPS
#
# to name 'MOPS'.

NAME=MOPS

DIR=$1

if [ "$DIR" = "" ]; then
	echo 'Run directory not specified.'
	echo 'Usage: KNOWN_REMOTE RUNDIR'
	exit 1
fi

if [ ! -d $DIR ]; then
	echo 'Not a directory: ' $DIR
	exit 2
fi


cd $1

if [ ! -f $NAME.manifest ]; then
	echo "Can't locate $NAME.manifest"
	exit 3
fi

if [ `grep -v \!\! $NAME.in.tracklet_pointer | wc -l` = "0" ]; then
    echo "Empty tracklet file."
    exit 0
fi

echo "ingest_simulation_known $NAME run && cd run && run_known $NAME"
#ingest_simulation_known $NAME run 
ingest_simulation_known $NAME run && cd run && run_known $NAME
