Skip to content

Commit

Permalink
Setting default working area for each condor job to its log directory
Browse files Browse the repository at this point in the history
  • Loading branch information
atishelmanch committed Jan 31, 2024
1 parent 033d838 commit cb50159
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions python/run_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def create_subjob_script(local_dir: str,
process_name: str,
chunk_num: int,
chunk_list: list[list[str]],
log_dir: str,
anapath: str) -> str:
'''
Creates sub-job script to be run.
Expand All @@ -114,6 +115,7 @@ def create_subjob_script(local_dir: str,

scr = '#!/bin/bash\n\n'
scr += 'source ' + local_dir + '/setup.sh\n\n'
scr += 'cd ' + log_dir + ' \n'

# add userBatchConfig if any
if user_batch_config != '':
Expand Down Expand Up @@ -344,18 +346,15 @@ def run_rdf(rdf_module,


# _____________________________________________________________________________
def send_to_batch(rdf_module, chunk_list, process, anapath: str):
def send_to_batch(rdf_module, chunk_list, process, log_dir, anapath: str):
'''
Send jobs to HTCondor batch system.
'''
local_dir = os.environ['LOCAL_DIR']
current_date = datetime.datetime.fromtimestamp(
datetime.datetime.now().timestamp()).strftime('%Y-%m-%d_%H-%M-%S')
log_dir = os.path.join(local_dir, 'BatchOutputs', current_date, process)
if not os.path.exists(log_dir):
os.system(f'mkdir -p {log_dir}')

local_dir = os.environ['LOCAL_DIR']

# Making sure the FCCAnalyses libraries are compiled and installed

try:
subprocess.check_output(['make', 'install'],
cwd=local_dir+'/build',
Expand All @@ -380,6 +379,7 @@ def send_to_batch(rdf_module, chunk_list, process, anapath: str):
process,
ch,
chunk_list,
log_dir,
anapath)
ofile.write(subjob_script)
except IOError as e:
Expand Down Expand Up @@ -659,11 +659,19 @@ def run_stages(args, rdf_module, anapath):
if run_batch:
# Sending to the batch system
LOGGER.info('Running on the batch...')

if len(chunk_list) == 1:
LOGGER.warning('\033[4m\033[1m\033[91mRunning on batch with '
'only one chunk might not be optimal\033[0m')

send_to_batch(rdf_module, chunk_list, process_name, anapath)
local_dir = os.environ['LOCAL_DIR']
current_date = datetime.datetime.fromtimestamp(
datetime.datetime.now().timestamp()).strftime('%Y-%m-%d_%H-%M-%S')
log_dir = os.path.join(local_dir, 'BatchOutputs', current_date, process_name)
if not os.path.exists(log_dir):
os.system(f'mkdir -p {log_dir}')

send_to_batch(rdf_module, chunk_list, process_name, log_dir, anapath)

else:
# Running locally
Expand Down

0 comments on commit cb50159

Please sign in to comment.