#!/bin/bash

# setup paths and environment to run AGILE and Rivet
set_environment () {
  echo "Setting environment..."
  
  # assume "x86_64-slc5-gcc43-opt" platform:
  LCG_PLATFORM=x86_64-slc5-gcc43-opt
  source /afs/cern.ch/sw/lcg/contrib/gcc/4.3/$LCG_PLATFORM/setup.sh
  
  MCGENERATORS=/afs/cern.ch/sw/lcg/external/MCGenerators
  MCGENERATORS_HEPMC206=/afs/cern.ch/sw/lcg/external/MCGenerators_hepmc20603
  local AGILE=$MCGENERATORS_HEPMC206/agile/1.2.0/$LCG_PLATFORM
  local RIVET=$MCGENERATORS_HEPMC206/rivet/1.4.0/$LCG_PLATFORM
  HEPMC=/afs/cern.ch/sw/lcg/external/HepMC/2.06.03/$LCG_PLATFORM
  local PYTHON=/afs/cern.ch/sw/lcg/external/Python/2.6.5/$LCG_PLATFORM
  
  export PYTHONPATH=$AGILE/lib/python2.5/site-packages:$RIVET/lib/python2.6/site-packages:$PYTHONPATH
  export LD_LIBRARY_PATH=$HEPMC/lib:$AGILE/lib:$RIVET/lib:$PYTHON/lib:$LD_LIBRARY_PATH
  export PATH=$PYTHON/bin:$RIVET/bin:$AGILE/bin:$PATH
  export AGILE_GEN_PATH=$MCGENERATORS
  export AGILE_PARAM_PATH=$(pwd)/configuration
  export RIVET_REF_PATH=$(rivet-config --datadir)
  
  echo "LCG_PLATFORM=$LCG_PLATFORM"
  echo "gcc version = $(gcc -dumpversion)"
  echo "AGILE=$AGILE"
  echo "RIVET=$RIVET"
  echo "HEPMC=$HEPMC"
  echo "AGILE_GEN_PATH=$AGILE_GEN_PATH"
  echo "AGILE_PARAM_PATH=$AGILE_PARAM_PATH"
  echo "RIVET_REF_PATH=$RIVET_REF_PATH"
  echo ""
}

set_environment

echo "===>  STAR_2009_UE_HELEN analysis is not available:"
rivet -a STAR_2009_UE_HELEN

echo
echo "Summary of ==== $RIVET_REF_PATH ==="
echo "number of .aida files = $(ls -1 $RIVET_REF_PATH/*.aida | wc -l)"
echo "number of .info files = $(ls -1 $RIVET_REF_PATH/*.info | wc -l)"
echo "number of .plot files = $(ls -1 $RIVET_REF_PATH/*.plot | wc -l)"

echo
echo "Following analyses do not have full set of files (aida + info + plot):"
( cd $RIVET_REF_PATH && ls -1 *.aida *.info *.plot | cut -d . -f 1 | sort | uniq -c | sort | grep -v "^ *3" )

echo
echo "Following analyses are missing from 'rivet --list-analyses':"
rivet --list-analyses | sort > list-analyses.txt
( cd $RIVET_REF_PATH && ls -1 *.aida *.info *.plot | cut -d . -f 1 | sort | uniq ) > ref-analyses.txt
diff -u list-analyses.txt ref-analyses.txt | grep ^+


rivet --list-analyses | wc -l