Skip to content

Commit e4c7d27

Browse files
authored
Merge pull request #2376 from willend/main
Prototype solution to allow 'append’ mode for datasets
2 parents be46b90 + 2601b94 commit e4c7d27

6 files changed

Lines changed: 41 additions & 14 deletions

File tree

.github/workflows/mcstas-basictest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
include:
2121
- { os: ubuntu-24.04, CC: gcc-13, CXX: g++-13, python: '3.12', mpi: 'openmpi' }
2222
- { os: ubuntu-24.04, CC: clang, CXX: clang++, python: '3.12', mpi: 'openmpi' }
23-
- { os: windows-11-arm, CC: cl.exe, CXX: cl.exe, python: "3.13", mpi: 'msmpi' }
23+
#- { os: windows-11-arm, CC: cl.exe, CXX: cl.exe, python: "3.13", mpi: 'msmpi' }
2424
- { os: windows-latest, CC: gcc.exe, CXX: g++.exe, python: "3.13", mpi: 'msmpi' }
2525

2626
name: ${{ matrix.os }}.${{ matrix.CC }}.${{ matrix.mpi }}.python-${{ matrix.python }}

.github/workflows/mcxtrace-basictest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
include:
2121
- { os: ubuntu-24.04, CC: gcc-13, CXX: g++-13, python: '3.12', mpi: 'openmpi' }
2222
- { os: ubuntu-24.04, CC: clang, CXX: clang++, python: '3.12', mpi: 'openmpi' }
23-
- { os: windows-11-arm, CC: cl.exe, CXX: cl.exe, python: "3.13", mpi: 'msmpi' }
23+
#- { os: windows-11-arm, CC: cl.exe, CXX: cl.exe, python: "3.13", mpi: 'msmpi' }
2424
- { os: windows-latest, CC: gcc.exe, CXX: g++.exe, python: "3.13", mpi: 'msmpi' }
2525

2626
name: ${{ matrix.os }}.${{ matrix.CC }}.${{ matrix.mpi }}.python-${{ matrix.python }}

common/lib/share/mccode-r.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
/** Include header files to avoid implicit declarations (not allowed on LLVM) */
4141
#include <ctype.h>
4242
#include <sys/types.h>
43+
#include <dirent.h>
44+
#include <errno.h>
4345

4446
// UNIX specific headers (non-Windows)
4547
#if defined(__unix__) || defined(__APPLE__)
@@ -61,6 +63,7 @@ static long mcstartdate = 0; /* start simulation time */
6163
static int mcdisable_output_files = 0; /* --no-output-files */
6264
mcstatic int mcgravitation = 0; /* use gravitation flag, for PROP macros */
6365
mcstatic int mcusedefaults = 0; /* assume default value for all parameters */
66+
mcstatic int mcappend = 0; /* flag to allow append mode on datasets/directories */
6467
mcstatic int mcdotrace = 0; /* flag for --trace and messages for DISPLAY */
6568
mcstatic int mcnexus_embed_idf = 0; /* flag to embed xml-formatted IDF file for Mantid */
6669
#pragma acc declare create ( mcdotrace )
@@ -2731,15 +2734,24 @@ mcuse_dir(char *dir)
27312734
#ifdef USE_MPI
27322735
if(mpi_node_rank == mpi_node_root) {
27332736
#endif
2737+
int exists=0;
2738+
DIR* handle = opendir(dirname);
2739+
if (handle) {
2740+
/* Directory exists. */
2741+
closedir(handle);
2742+
exists=1;
2743+
}
27342744
if(mkdir(dirname, 0777)) {
27352745
#ifndef DANSE
2736-
fprintf(stderr, "Error: unable to create directory '%s' (mcuse_dir)\n", dir);
2737-
fprintf(stderr, "(Maybe the directory already exists?)\n");
2746+
if(!mcappend) {
2747+
fprintf(stderr, "Error: unable to create directory '%s' (mcuse_dir)\n", dir);
2748+
fprintf(stderr, "(Maybe the directory already exists?)\n");
27382749
#endif
27392750
#ifdef USE_MPI
2740-
MPI_Abort(MPI_COMM_WORLD, -1);
2751+
MPI_Abort(MPI_COMM_WORLD, -1);
27412752
#endif
2742-
exit(-1);
2753+
exit(-1);
2754+
}
27432755
}
27442756
#ifdef USE_MPI
27452757
}
@@ -4492,6 +4504,7 @@ mchelp(char *pgmname)
44924504
" -s SEED --seed=SEED Set random seed (must be != 0)\n"
44934505
" -n COUNT --ncount=COUNT Set number of particles to simulate.\n"
44944506
" -d DIR --dir=DIR Put all data files in directory DIR.\n"
4507+
" -a --append Append data files to those in directory DIR.\n"
44954508
" -t --trace Enable trace of " MCCODE_PARTICLE "s through instrument.\n"
44964509
" (Use -t=2 or --trace=2 for modernised mcdisplay rendering)\n"
44974510
" -g --gravitation Enable gravitation for all trajectories.\n"
@@ -4745,6 +4758,10 @@ mcparseoptions(int argc, char *argv[])
47454758
usedir=&argv[i][2];
47464759
else if(!strcmp("--dir", argv[i]) && (i + 1) < argc)
47474760
usedir=argv[++i];
4761+
else if(!strncmp("-a", argv[i], 2))
4762+
mcappend = 1;
4763+
else if(!strcmp("--append", argv[i]))
4764+
mcappend = 1;
47484765
else if(!strncmp("--dir=", argv[i], 6))
47494766
usedir=&argv[i][6];
47504767
else if(!strcmp("-h", argv[i]))

tools/Python/mcrun/mccode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ def run(self, pipe=False, extra_opts=None, override_mpi=None):
385385
args.extend([f'--{opt}=' + str(val)])
386386

387387
# Handle proxy options without values (flags)
388-
proxy_opts_flags = ['no-output-files', 'info', 'list-parameters', 'meta-list', 'yes']
388+
proxy_opts_flags = ['no-output-files', 'info', 'list-parameters', 'meta-list', 'yes','append']
389389
if mccode_config.configuration["MCCODE"] == 'mcstas':
390390
proxy_opts_flags.append('gravitation')
391391

tools/Python/mcrun/mcrun.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,12 @@ def is_valid(path):
310310

311311
add('-d', '--dir',
312312
metavar='DIR', type=str,
313-
action='callback', callback=check_file(exist=False),
314313
help='Put all data files in directory DIR')
315314

315+
add('-a', '--append',
316+
action='store_true', default=False,
317+
help='Append data files to those already in directory DIR')
318+
316319
add('--format',
317320
metavar='FORMAT', default='McCode',
318321
help='Output data files using format FORMAT, usually McCode or NeXus '
@@ -406,6 +409,7 @@ def expand_options(options):
406409
datetime.strftime(datetime.now(), DATE_FORMAT_PATH))
407410
# alert user
408411
LOG.info('No output directory specified (--dir)')
412+
409413
# Output file
410414
if options.optimise_file is None:
411415
# use mccode.dat when unspecified

tools/Python/mcrun/optimisation.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@ def run(self):
285285
mcstas_dir = self.mcstas.options.dir
286286
if mcstas_dir == '':
287287
mcstas_dir = '.'
288-
289288

290289
with open(self.outfile, 'w') as outfile:
291290
for i, point in enumerate(self.points):
@@ -295,11 +294,18 @@ def run(self):
295294
LOG.debug("%s: %s", key, point[key])
296295
par_values.append(point[key])
297296

298-
LOG.info(', '.join(f'{name}: {value}' for name, value in point.items()))
299-
# Change subdirectory as an extra option (dir/1 -> dir/2)
300-
current_dir = f'{mcstas_dir}/{i}'
301-
LOG.info(f"Output step into scan directory {current_dir}")
302-
self.mcstas.run(pipe=False, extra_opts={'dir': current_dir})
297+
if not self.mcstas.options.format.lower() == 'nexus':
298+
LOG.info(', '.join(f'{name}: {value}' for name, value in point.items()))
299+
# Change subdirectory as an extra option (dir/1 -> dir/2)
300+
current_dir = f'{mcstas_dir}/{i}'
301+
LOG.info(f"Output step into scan directory {current_dir}")
302+
self.mcstas.run(pipe=False, extra_opts={'dir': current_dir})
303+
else:
304+
current_dir = mcstas_dir
305+
LOG.info(f"NeXus output step into scan directory {current_dir}")
306+
self.mcstas.options.append=True
307+
self.mcstas.run(pipe=False, extra_opts={'dir': current_dir})
308+
303309
LOG.info("Finish running step, get detectors")
304310
detectors = mcsimdetectors(current_dir)
305311
if detectors is not None:

0 commit comments

Comments
 (0)