Skip to content

Commit

Permalink
#13 option to use apptainer (#14)
Browse files Browse the repository at this point in the history
* add option to use apptainer image

* fix typo

* fix typo

* add option to pass script
  • Loading branch information
panta-123 committed May 20, 2024
1 parent 3ba39f8 commit e660dba
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
12 changes: 11 additions & 1 deletion hcswif.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ def parseArgs():
help='max run time per job in seconds allowed before killing jobs')
parser.add_argument('--shell', nargs=1, dest='shell',
help='Currently a shell cannot be specified in SWIF2')
parser.add_argument('--apptainer', nargs=1, dest='apptainer',
help='Specify path to apptainer image.')

# Check if any args specified
if len(sys.argv) < 2:
Expand Down Expand Up @@ -179,6 +181,11 @@ def getReplayJobs(parsed_args, wf_name):
batch = os.path.join(hcswif_dir, 'hcswif.sh')
elif re.search('csh', parsed_args.shell[0]):
batch = os.path.join(hcswif_dir, 'hcswif.csh')
if parsed_args.apptainer:
if not os.path.isdir(str(parsed_args.apptainer[0])):
warnings.warn("APPTAINER image not found.")
sys.exit()
batch = os.path.join(hcswif_dir, "hcswif_apptainer.sh")

# Create list of jobs for workflow
jobs = []
Expand Down Expand Up @@ -218,7 +225,10 @@ def getReplayJobs(parsed_args, wf_name):
job['inputs'][0]['remote'] = coda

# command for job is `/hcswifdir/hcswif.sh REPLAY RUN NUMEVENTS`
job['command'] = [" ".join([batch, replay_script, str(run), str(evts)])]
if parsed_args.apptainer:
job['command'] = [" ".join([batch, replay_script, str(run), str(evts), str(parsed_args.apptainer[0]), str(raw_dir)])]
else:
job['command'] = [" ".join([batch, replay_script, str(run), str(evts)])]

jobs.append(copy.deepcopy(job))

Expand Down
44 changes: 44 additions & 0 deletions hcswif_apptainer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/bash
ARGC=$#
if [[ $ARGC -ne 5 ]]; then
echo "Usage: hcswif.sh SCRIPT RUN EVENTS APPTAINER RAWDIR"
exit 1
fi;

script=$1 # script to run
run=$2 # RUN Number
evt=$3 # Number of events in that run
apptainer=$4
rawdir=$5

# Modify as you need
#--------------------------------------------------
HALLC_REPLAY_DIR="/home/$USER/hallc_replay" # my replay directory
DATA_DIR="${rawdir}"
ROOT_FILE="/path/to/rootfile/directory"
REPORT_OUTPUT="/path/to/REPORT_OTUPUT/directory"
APPTAINER_IMAGE="${apptainer}"
#--------------------------------------------------

cd $HALLC_REPLAY_DIR

# Check if apptainer is available
if command -v apptainer > /dev/null 2>&1; then
echo "apptainer is already available."
else
# Load apptainer if not available
echo "Loading apptainer..."
if ! eval module load apptainer; then
echo "Failed to load apptainer. Please check if the module is installed and accessible."
exit 1 # Exit the script with a non-zero exit code
fi
fi

echo
echo "---------------------------------------------------------------------------------------------"
echo "REPLAY for ${runNum}. NEvent=${nEvent} using container=${APPTAINER_IMAGE}"
echo "----------------------------------------------------------------------------------------------"
echo

runStr="apptainer exec --bind ${DATA_DIR} --bind ${APPTAINER_IMAGE}--bind ${ROOT_FILE} --bind ${REPORT_OUTPUT} --bind ${HALLC_REPLAY_DIR} ${APPTAINER_IMAGE} bash -c \"hcana -q ${script}\(${runNum},${nEvent}\)\""
eval ${runStr}

0 comments on commit e660dba

Please sign in to comment.