From 183d1afdd4ce944b5424a6f995c0aedde5f6431d Mon Sep 17 00:00:00 2001
From: FaserMC <fasermc@cern.ch>
Date: Wed, 13 Jul 2022 12:03:04 +0200
Subject: [PATCH] Finalize update to MDC submission scripts

---
 .../scripts/submit_faserMDC_digi.sh           | 11 +--
 .../scripts/submit_faserMDC_digi_merge.sh     | 11 +--
 .../scripts/submit_faserMDC_foresee.sh        | 11 +--
 .../scripts/submit_faserMDC_particlegun.sh    | 11 +--
 .../scripts/submit_faserMDC_reco.sh           | 11 +--
 .../scripts/submit_faser_reco.sh              | 74 +++++++++++++++++--
 .../scripts/submit_faserMDC_simulate.sh       | 11 +--
 7 files changed, 104 insertions(+), 36 deletions(-)

diff --git a/Control/CalypsoExample/Digitization/scripts/submit_faserMDC_digi.sh b/Control/CalypsoExample/Digitization/scripts/submit_faserMDC_digi.sh
index f53a5632..21ac59fb 100755
--- a/Control/CalypsoExample/Digitization/scripts/submit_faserMDC_digi.sh
+++ b/Control/CalypsoExample/Digitization/scripts/submit_faserMDC_digi.sh
@@ -102,7 +102,8 @@ output_directory="$working_directory/$run_number"
 mkdir -p "$output_directory"
 #
 # This magic redirects everything in this script to our log file
-exec >& "$output_directory/$file_stem.log"
+logfile="${file_stem}.rdo.log"
+exec >& "${output_directory}/${logfile}"
 echo `date` - $HOSTNAME
 echo "File: $file_name"
 echo "Release: $release_directory"
@@ -193,14 +194,14 @@ if ! [ -z "$logdest" ]
 then
     cd ..
     ls -l
-    echo "copy ${config_file_stem}-${seg_str}.log to $logdest"
+    echo "copy $logfile to $logdest"
     mkdir -p $logdest
-    eos cp "${config_file_stem}-${seg_str}.log" $logdest
+    eos cp $logfile $logdest
 elif ! [ -z "$outdest" ]
 then 
     cd ..
     ls -l
-    echo "copy ${config_file_stem}-${seg_str}.log to $outdest"
+    echo "copy $logfile to $outdest"
     mkdir -p $outdest
-    eos cp "${config_file_stem}-${seg_str}.log" $outdest
+    eos cp $logfile $outdest
 fi
diff --git a/Control/CalypsoExample/Digitization/scripts/submit_faserMDC_digi_merge.sh b/Control/CalypsoExample/Digitization/scripts/submit_faserMDC_digi_merge.sh
index 08487ea2..e5d45909 100755
--- a/Control/CalypsoExample/Digitization/scripts/submit_faserMDC_digi_merge.sh
+++ b/Control/CalypsoExample/Digitization/scripts/submit_faserMDC_digi_merge.sh
@@ -123,7 +123,8 @@ mkdir -p "$output_directory"
 file_stem="$faser-$short-$run_number-RDO-merge-$slice"
 #
 # This magic redirects everything in this script to our log file
-exec >& "$output_directory/$file_stem.log"
+logfile="${file_stem}.rdo.log"
+exec >& "$output_directory/$logfile"
 echo `date` - $HOSTNAME
 echo "Directory: $dir_path"
 echo "Slice: $slice"
@@ -216,14 +217,14 @@ if ! [ -z "$logdest" ]
 then
     cd ..
     ls -l
-    echo "copy ${config_file_stem}-${seg_str}.log to $logdest"
+    echo "copy $logfile to $logdest"
     mkdir -p $logdest
-    eos cp "${config_file_stem}-${seg_str}.log" $logdest
+    eos cp $logfile $logdest
 elif ! [ -z "$outdest" ]
 then 
     cd ..
     ls -l
-    echo "copy ${config_file_stem}-${seg_str}.log to $outdest"
+    echo "copy $logfile to $outdest"
     mkdir -p $outdest
-    eos cp "${config_file_stem}-${seg_str}.log" $outdest
+    eos cp $logfile $outdest
 fi
diff --git a/Control/CalypsoExample/Generation/scripts/submit_faserMDC_foresee.sh b/Control/CalypsoExample/Generation/scripts/submit_faserMDC_foresee.sh
index 0629fe57..723ffb6d 100755
--- a/Control/CalypsoExample/Generation/scripts/submit_faserMDC_foresee.sh
+++ b/Control/CalypsoExample/Generation/scripts/submit_faserMDC_foresee.sh
@@ -119,7 +119,8 @@ fi
 mkdir -p "$output_directory"
 #
 # This magic redirects everything in this script to our log file
-exec >& "$output_directory/${config_file_stem}-${seg_str}.log"
+logfile="${config_file_stem}-${seg_str}.gen.log"
+exec >& "$output_directory/${logfile}"
 echo `date` - $HOSTNAME
 echo "File: $config_file"
 echo "Segment: $seg_str"
@@ -209,14 +210,14 @@ if ! [ -z "$logdest" ]
 then
     cd ..
     ls -l
-    echo "copy ${config_file_stem}-${seg_str}.log to $logdest"
+    echo "copy $logfile to $logdest"
     mkdir -p $logdest
-    eos cp "${config_file_stem}-${seg_str}.log" $logdest
+    eos cp $logfile $logdest
 elif ! [ -z "$outdest" ]
 then 
     cd ..
     ls -l
-    echo "copy ${config_file_stem}-${seg_str}.log to $outdest"
+    echo "copy $logffile to $outdest"
     mkdir -p $outdest
-    eos cp "${config_file_stem}-${seg_str}.log" $outdest
+    eos cp $logfile $outdest
 fi
diff --git a/Control/CalypsoExample/Generation/scripts/submit_faserMDC_particlegun.sh b/Control/CalypsoExample/Generation/scripts/submit_faserMDC_particlegun.sh
index f7d205ec..729d75c7 100755
--- a/Control/CalypsoExample/Generation/scripts/submit_faserMDC_particlegun.sh
+++ b/Control/CalypsoExample/Generation/scripts/submit_faserMDC_particlegun.sh
@@ -117,7 +117,8 @@ fi
 mkdir -p "$output_directory"
 #
 # This magic redirects everything in this script to our log file
-exec >& "$output_directory/${config_file_stem}-${seg_str}.log"
+logfile="${config_file_stem}-${seg_str}.gen.log"
+exec >& "$output_directory/${logfile}"
 echo `date` - $HOSTNAME
 echo "File: $config_file"
 echo "Segment: $seg_str"
@@ -207,14 +208,14 @@ if ! [ -z "$logdest" ]
 then
     cd ..
     ls -l
-    echo "copy ${config_file_stem}-${seg_str}.log to $logdest"
+    echo "copy $logfile to $logdest"
     mkdir -p $logdest
-    eos cp "${config_file_stem}-${seg_str}.log" $logdest
+    eos cp $logfile $logdest
 elif ! [ -z "$outdest" ]
 then 
     cd ..
     ls -l
-    echo "copy ${config_file_stem}-${seg_str}.log to $outdest"
+    echo "copy $logfile to $outdest"
     mkdir -p $outdest
-    eos cp "${config_file_stem}-${seg_str}.log" $outdest
+    eos cp $logfile $outdest
 fi
diff --git a/Control/CalypsoExample/Reconstruction/scripts/submit_faserMDC_reco.sh b/Control/CalypsoExample/Reconstruction/scripts/submit_faserMDC_reco.sh
index 9cba705f..819cfeb4 100755
--- a/Control/CalypsoExample/Reconstruction/scripts/submit_faserMDC_reco.sh
+++ b/Control/CalypsoExample/Reconstruction/scripts/submit_faserMDC_reco.sh
@@ -102,7 +102,8 @@ output_directory="$working_directory/${run_number}"
 mkdir -p "$output_directory"
 #
 # This magic redirects everything in this script to our log file
-exec >& "$output_directory/$file_stem.log"
+logfile="${file_stem}.rec.log"
+exec >& "$output_directory/${logfile}"
 echo `date` - $HOSTNAME
 echo "File: $file_name"
 echo "Release: $release_directory"
@@ -182,14 +183,14 @@ if ! [ -z "$logdest" ]
 then
     cd ..
     ls -l
-    echo "copy ${config_file_stem}-${seg_str}.log to $logdest"
+    echo "copy $logfile to $logdest"
     mkdir -p $logdest
-    eos cp "${config_file_stem}-${seg_str}.log" $logdest
+    eos cp $logfile $logdest
 elif ! [ -z "$outdest" ]
 then 
     cd ..
     ls -l
-    echo "copy ${config_file_stem}-${seg_str}.log to $outdest"
+    echo "copy $logfile to $outdest"
     mkdir -p $outdest
-    eos cp "${config_file_stem}-${seg_str}.log" $outdest
+    eos cp $logfile\ $outdest
 fi
diff --git a/Control/CalypsoExample/Reconstruction/scripts/submit_faser_reco.sh b/Control/CalypsoExample/Reconstruction/scripts/submit_faser_reco.sh
index 277d6eaa..e6f4fff1 100755
--- a/Control/CalypsoExample/Reconstruction/scripts/submit_faser_reco.sh
+++ b/Control/CalypsoExample/Reconstruction/scripts/submit_faser_reco.sh
@@ -4,6 +4,10 @@
 # Usage:
 # submit_faser_reco.sh file_path [release_directory] [working_directory] [nevents]
 # 
+# Options:
+#   --out - specify output location (in EOS) to copy output HITS file
+#   --log - specify output location (in EOS) for log file
+# 
 # file_path - full file name (with path)
 # release_directory - optional path to release install directory (default pwd)
 # working_directory - optional path to output directory location (default pwd)
@@ -16,8 +20,36 @@
 # If this matches reco/r???? it will be passed to the reco job
 #
 #----------------------------------------
+# Keep track of time
+SECONDS=0
 #
 # Parse command-line options
+while [ -n "$1" ]
+do 
+  case "$1" in
+      -l | --log)
+	  logdest="$2";
+	  shift;
+	  shift;; # Must eat 2 options here
+
+      -o | --out)
+	  outdest="$2";
+	  shift;
+	  shift;;
+
+      --) # End of options
+	  shift; # Eat this
+	  break;; # And stop parsing
+
+    -*) 
+	  echo "Unknown option $1"
+	  shift;;
+
+    *) break;;  # Not an option, don't shift
+  esac
+done
+#
+# Parse command-line arguments
 file_path=${1}
 release_directory=${2}
 working_directory=${3}
@@ -70,7 +102,8 @@ output_directory="$working_directory/Run-$run_number"
 mkdir -p "$output_directory"
 #
 # This magic redirects everything in this script to our log file
-exec >& "$output_directory/$file_stem.log"
+logfile="${file_stem}.rec.log"
+exec >& "$output_directory/$logfile"
 echo `date` - $HOSTNAME
 echo "File: $file_name"
 echo "Release: $release_directory"
@@ -85,12 +118,12 @@ source ${ATLAS_LOCAL_ROOT_BASE}/user/atlasLocalSetup.sh
 # Always go back to the starting directory in case paths are relative
 cd "$starting_directory"
 cd "$release_directory"
-asetup
-source build/x8*/setup.sh
+#asetup 
+#source build/x8*/setup.sh
 #
 # Do this by hand
-# asetup --input="$release_directory/calypso/asetup.faser" Athena,22.0.49
-# source "$release_directory/build/x8*/setup.sh"
+asetup --input=calypso/asetup.faser Athena,22.0.49
+source build/x86*/setup.sh
 #
 #
 # Try to find a release tag
@@ -102,7 +135,7 @@ if [[ "$recotag" == "reco/r"???? ]]; then
 fi
 if [[ "$recotag" == "reco/p"???? ]]; then
   tag=`echo "$recotag" | cut -c 6-11`
-  echo "Found reco tag: $tag"
+  echo "Found proc tag: $tag"
 fi
 #
 # Move to the run directory
@@ -132,3 +165,32 @@ fi
 #
 # Print out ending time
 date
+echo "Job finished after $SECONDS seconds"
+# 
+# Copy output to EOS if desired
+export EOS_MGM_URL=root://eospublic.cern.ch
+#
+if ! [ -z "$outdest" ]
+then
+    ls -l
+    echo "copy *-RDO.root to $outdest"
+    mkdir -p $outdest
+    eos cp *-xAOD.root $outdest
+fi
+#
+# Also copy log file
+if ! [ -z "$logdest" ]
+then
+    cd ..
+    ls -l
+    echo "copy $logfile to $logdest"
+    mkdir -p $logdest
+    eos cp $logfile $logdest
+elif ! [ -z "$outdest" ]
+then 
+    cd ..
+    ls -l
+    echo "copy $logfile to $outdest"
+    mkdir -p $outdest
+    eos cp $logfile\ $outdest
+fi
diff --git a/Control/CalypsoExample/Simulation/scripts/submit_faserMDC_simulate.sh b/Control/CalypsoExample/Simulation/scripts/submit_faserMDC_simulate.sh
index d16a8046..bedbb591 100755
--- a/Control/CalypsoExample/Simulation/scripts/submit_faserMDC_simulate.sh
+++ b/Control/CalypsoExample/Simulation/scripts/submit_faserMDC_simulate.sh
@@ -133,7 +133,8 @@ fi
 mkdir -p "$output_directory"
 #
 # This magic redirects everything in this script to our log file
-exec >& "$output_directory/${file_stem}.log"
+logfile=${file_stem}.sim.log
+exec >& "$output_directory/$logfile"
 echo `date` - $HOSTNAME
 echo "Input File: $infile"
 echo "Output File: $outfilename"
@@ -206,15 +207,15 @@ if ! [ -z "$logdest" ]
 then
     cd ..
     ls -l
-    echo "copy ${config_file_stem}-${seg_str}.log to $logdest"
+    echo "copy $logfile to $logdest"
     mkdir -p $logdest
-    eos cp "${config_file_stem}-${seg_str}.log" $logdest
+    eos cp $logfile $logdest
 elif ! [ -z "$outdest" ]
 then 
     cd ..
     ls -l
-    echo "copy ${config_file_stem}-${seg_str}.log to $outdest"
+    echo "copy $logfile to $outdest"
     mkdir -p $outdest
-    eos cp "${config_file_stem}-${seg_str}.log" $outdest
+    eos cp $logfile $outdest
 fi
 
-- 
GitLab