#!/bin/sh

# HistFactory workplace setup script

if [ -z $ROOTSYS ]
then
  echo "ROOTSYS is not set. try to use root-config" 
  ROOTPREFDIR=`root-config --prefix`
  ROOTETCDIR=`root-config --etcdir`
  echo "Using etcdir "$ROOTETCDIR
  ROOTTUTDIR=$ROOTPREFDIR/tutorials
  if test -e $ROOTTUTDIR; then
      echo "Using tutorials dir" $ROOTTUTDIR 
  else     
      ROOTTUTDIR=${ROOTPREFDIR}/share/doc/root/tutorials
      echo "Using tutorials dir" $ROOTTUTDIR 
  fi
else
  ROOTETCDIR=$ROOTSYS/etc
  ROOTTUTDIR=$ROOTSYS/tutorials
fi

if [ $# -eq 1 ]
then
  DIR=$1
  echo "HistFactory workplace will be created in: " $DIR
else
  DIR=.
  echo "HistFactory workplace will be created in the current directory"
fi

echo "Creating directory structure..."
mkdir -p $DIR/config
mkdir -p $DIR/config/examples
mkdir -p $DIR/data
mkdir -p $DIR/results

echo "Copying skeleton configuration files..."
cp $ROOTETCDIR/HistFactorySchema.dtd $DIR/config/
cp $ROOTTUTDIR/histfactory/example.xml $DIR/config/
cp $ROOTTUTDIR/histfactory/example_channel.xml $DIR/config/

cp $ROOTETCDIR/HistFactorySchema.dtd $DIR/config/examples
cp $ROOTTUTDIR/histfactory/example_Expression.xml $DIR/config/examples/
cp $ROOTTUTDIR/histfactory/example_Expression_channel.xml $DIR/config/examples/
cp $ROOTTUTDIR/histfactory/example_ShapeSys.xml $DIR/config/examples/
cp $ROOTTUTDIR/histfactory/example_ShapeSys_channel.xml $DIR/config/examples/
cp $ROOTTUTDIR/histfactory/example_ShapeSys2D.xml $DIR/config/examples/
cp $ROOTTUTDIR/histfactory/example_ShapeSys2D_channel.xml $DIR/config/examples/
cp $ROOTTUTDIR/histfactory/example_DataDriven.xml $DIR/config/examples/
cp $ROOTTUTDIR/histfactory/example_DataDriven_signalRegion.xml $DIR/config/examples/
cp $ROOTTUTDIR/histfactory/example_DataDriven_controlRegion.xml $DIR/config/examples/


#echo "Making skeleton data files..."
root -b -q $ROOTTUTDIR/histfactory/makeExample.C
mv ShapeSys.root ShapeSys2D.root StatError.root  dataDriven.root example.root $DIR/data

echo "Done!"
#echo "You can run the example with: hist2workspace $DIR/config/example.xml"

exit
