Skip to content

Commit 763cb48

Browse files
authored
Allowing a timestamp in output-dir-eos (#492)
* Allowing a timestamp in output-dir-eos * Do not check if EOS output directory exists when running analysis
1 parent ac97bbb commit 763cb48

4 files changed

Lines changed: 42 additions & 33 deletions

File tree

examples/FCCee/higgs/mH-recoil/mumu/analysis_stage1_batch.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
This analysis stage runs on HTCondor.
44
'''
55
from argparse import ArgumentParser
6+
from string import Template
67

78

89
# Mandatory: Analysis class where the user defines the operations on the
@@ -52,9 +53,15 @@ def __init__(self, cmdline_args):
5253
# is 'group_u_FCC.local_gen'
5354
self.comp_group = 'group_u_FCC.local_gen'
5455

55-
# Optional: output directory on eos, if specified files will be copied
56+
# Optional: output directory on EOS, if specified files will be copied
5657
# there once the batch job is done, default is empty
5758
self.output_dir_eos = '/eos/user/j/jsmiesko/mH-recoil-output'
59+
# or it could also be a template:
60+
# self.output_dir_eos = Template(
61+
# '/eos/user/j/jsmiesko/mH-recoil-output/$timestamp'
62+
# )
63+
# variable $timestamp is internally defined to have this form:
64+
# '%Y-%m-%d_%H-%M-%S'
5865

5966
# Optional: type of EOS proxy used when <outputDirEos> is specified.
6067
# The default is eosuser

man/man7/fccanalysis-script.7

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,12 @@ Computing account when running on HTCondor.
164164
Default value: "group_u_FCC.local_gen"
165165
.TP
166166
\fBoutput_dir_eos\fR (optional)
167-
Output directory on EOS, if specified files will be copied there once the batch
168-
job is done.
167+
Output directory on EOS, recognized only when submitting to HTCondor. If
168+
specified files will be copied there once the batch job is done. A string
169+
(\fBstr\fR) or a template (\fBstring.Template\fR) can be provided. In case of
170+
the template only one variable is currently supported: \fB$timestamp\fR.
169171
.br
170-
Default value: empty string
172+
Default value: None
171173
.TP
172174
\fBeos_type\fR (optional)
173175
Type of the EOS proxy to be used.
@@ -177,7 +179,7 @@ Default value: user
177179
\fBtest_file\fR (optional)
178180
Location of the test file provided as a string (\fBstr\fR) or a template
179181
(\fBstring.Template\fR). In case of the template two variables are supported:
180-
\fBkey4hep_os\fR and \fBkey4hep_stack\fR.
182+
\fB$key4hep_os\fR and \fB$key4hep_stack\fR.
181183
.br
182184
Default value: empty string
183185
.TP

python/batch.py

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import subprocess
1010
import datetime
1111
import argparse
12+
import string
1213
from typing import Any
1314

1415
from process import get_process_info
@@ -53,15 +54,16 @@ def determine_os(fccana_dir: str) -> str | None:
5354
def create_condor_config(config: dict[str, Any],
5455
batch_dir: str,
5556
sample_name: str,
56-
subjob_scripts: list[str]) -> str:
57+
subjob_scripts: list[str],
58+
output_dir_eos: str | None) -> str:
5759
'''
5860
Creates contents of HTCondor submit description file.
5961
'''
6062
cfg = 'executable = $(scriptfile)\n'
6163

6264
cfg += f'log = {batch_dir}/condor_job.{sample_name}.$(ClusterId).log\n'
6365

64-
if config['output-dir-eos'] is None:
66+
if output_dir_eos is None:
6567
cfg += f'output = {config["output-dir"]}/log/{sample_name}/'
6668
cfg += f'condor_job.{sample_name}.$(ClusterId).$(ProcId).out\n'
6769
cfg += f'error = {config["output-dir"]}/log/{sample_name}/'
@@ -95,13 +97,13 @@ def create_condor_config(config: dict[str, Any],
9597
cfg += 'when_to_transfer_output = on_exit\n'
9698
cfg += f'transfer_output_files = {sample_name}\n'
9799

98-
if config['output-dir-eos'] is None:
100+
if output_dir_eos is None:
99101
cfg += 'transfer_output_remaps = '
100102
cfg += f'"{sample_name}={config["output-dir"]}/{sample_name}"\n'
101103
else:
102104
cfg += 'output_destination = '
103105
cfg += f'root://{config["eos-type"]}.cern.ch/'
104-
cfg += f'{config["output-dir-eos"]}\n'
106+
cfg += f'{output_dir_eos}\n'
105107
cfg += 'MY.XRDCP_CREATE_DIR = True\n\n'
106108

107109
# Add user batch configuration if any.
@@ -292,11 +294,11 @@ def send_sample(config: dict[str, Any],
292294
'''
293295
sample_dict = config['sample-list'][sample_name]
294296

295-
# Create log directory
296-
current_date = datetime.datetime.fromtimestamp(
297+
timestamp = datetime.datetime.fromtimestamp(
297298
datetime.datetime.now().timestamp()).strftime('%Y-%m-%d_%H-%M-%S')
298-
batch_dir = os.path.join('batch-submission-files',
299-
current_date, sample_name)
299+
300+
# Create log directory
301+
batch_dir = os.path.join('batch-submission-files', timestamp, sample_name)
300302
if not os.path.exists(batch_dir):
301303
os.system(f'mkdir -p {batch_dir}')
302304

@@ -373,21 +375,24 @@ def send_sample(config: dict[str, Any],
373375

374376
condor_config_path = f'{batch_dir}/job_desc_{sample_name}.cfg'
375377

376-
for i in range(3):
377-
try:
378-
with open(condor_config_path, 'w', encoding='utf-8') as cfgfile:
379-
condor_config = create_condor_config(config,
380-
batch_dir,
381-
sample_name,
382-
subjob_scripts)
383-
cfgfile.write(condor_config)
384-
except IOError as err:
385-
LOGGER.warning('I/O error(%i): %s', err.errno, err.strerror)
386-
if i == 2:
387-
sys.exit(3)
388-
else:
389-
break
390-
time.sleep(10)
378+
# Convert possible output-dir-eos template to string
379+
if isinstance(config['output-dir-eos'], string.Template):
380+
output_dir_eos = config['output-dir-eos'].substitute(
381+
timestamp=timestamp)
382+
else:
383+
output_dir_eos = config['output-dir-eos']
384+
385+
# Check if EOS output directory exist and if not create it
386+
if output_dir_eos is not None and not os.path.exists(output_dir_eos):
387+
os.system(f'mkdir -p {output_dir_eos}')
388+
389+
with open(condor_config_path, 'w', encoding='utf-8') as cfgfile:
390+
condor_config = create_condor_config(config,
391+
batch_dir,
392+
sample_name,
393+
subjob_scripts,
394+
output_dir_eos)
395+
cfgfile.write(condor_config)
391396

392397
if config['submission-filesystem-type'] == 'eos':
393398
batch_cmd = f'condor_submit -spool {condor_config_path}'

python/run_fccanalysis.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -477,11 +477,6 @@ def run_fccanalysis(args, analysis_module):
477477
if output_dir is not None and not os.path.exists(output_dir):
478478
os.system(f'mkdir -p {output_dir}')
479479

480-
# Check if EOS output directory exist and if not create it
481-
output_dir_eos = get_attribute(analysis, 'output_dir_eos', None)
482-
if output_dir_eos is not None and not os.path.exists(output_dir_eos):
483-
os.system(f'mkdir -p {output_dir_eos}')
484-
485480
if config['do-weighted']:
486481
LOGGER.info('Using generator weights...')
487482

0 commit comments

Comments
 (0)