Skip to content

Commit 41bbc35

Browse files
authored
feat: use RCDB to get the beam energy (#256)
1 parent be9fa15 commit 41bbc35

File tree

22 files changed

+255
-97
lines changed

22 files changed

+255
-97
lines changed

.github/install-dependency-packages.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ GENERAL_PACKAGE_LIST_LINUX=(
3434
openssl
3535
gsl
3636
davix
37+
### RCDB dependencies
38+
mariadb
3739
)
3840
IGUANA_PACKAGE_LIST_LINUX=(
3941
fmt
@@ -56,6 +58,8 @@ GENERAL_PACKAGE_LIST_MACOS=(
5658
libxext
5759
openssl
5860
gsl
61+
### RCDB dependencies
62+
mariadb
5963
)
6064
IGUANA_PACKAGE_LIST_MACOS=(
6165
fmt
@@ -139,6 +143,8 @@ case $runner in
139143
### link homebrew's gcc, for gfortran
140144
brew unlink gcc
141145
brew link gcc
146+
### kluge ssl linker issue (see, e.g., https://github.com/brianmario/mysql2/issues/795)
147+
echo "LIBRARY_PATH=${LIBRARY_PATH:+${LIBRARY_PATH}:}$(pkg-config libssl --variable libdir)" | tee -a $GITHUB_ENV
142148
;;
143149

144150
*)

.github/workflows/ci.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,14 +351,28 @@ jobs:
351351
- name: set ROOT environment
352352
if: ${{ matrix.id != 'noROOT' }}
353353
run: iguana_src/.github/source-ROOT.sh root
354+
###### RCDB
355+
- name: get RCDB
356+
uses: actions/checkout@v4
357+
with:
358+
repository: JeffersonLab/rcdb
359+
ref: main
360+
path: rcdb_src
361+
- name: set RCDB CI vars
362+
id: rcdb
363+
working-directory: rcdb_src
364+
run: |
365+
echo prefix=$(pwd) >> $GITHUB_OUTPUT
366+
echo ver=$(git rev-parse HEAD) >> $GITHUB_OUTPUT
354367
###### summarize dependencies
355368
- name: summarize dependencies
356369
if: ${{ matrix.id == 'cpp' }}
357370
run: |
358371
echo '### Dependencies' >> $GITHUB_STEP_SUMMARY
359372
echo '| Dependency | Version |' >> $GITHUB_STEP_SUMMARY
360373
echo '| --- | --- |' >> $GITHUB_STEP_SUMMARY
361-
echo "| \`hipo\` | ${{ env.hipo_ref }} |" >> $GITHUB_STEP_SUMMARY
374+
echo "| \`hipo\` | \`${{ env.hipo_ref }}\` |" >> $GITHUB_STEP_SUMMARY
375+
echo "| \`rcdb\` | \`${{ steps.rcdb.outputs.ver }}\` |" >> $GITHUB_STEP_SUMMARY
362376
echo "| \`root\` | $(root --version 2>&1 | head -n1) |" >> $GITHUB_STEP_SUMMARY
363377
echo "| \`ruby\` | $(ruby --version) |" >> $GITHUB_STEP_SUMMARY
364378
cat pkg_summary.md >> $GITHUB_STEP_SUMMARY
@@ -368,6 +382,8 @@ jobs:
368382
meson setup iguana_build iguana_src \
369383
--prefix=$(pwd)/iguana \
370384
--pkg-config-path=$(pwd)/hipo/lib/pkgconfig \
385+
-Drcdb:home=${{ steps.rcdb.outputs.prefix }} \
386+
-Dz_require_rcdb=true \
371387
-Dwerror=true \
372388
-Dinstall_examples=true \
373389
-Dtest_data_file=$(pwd)/test_data.hipo \

doc/gen/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ doc_tgt = custom_target(
2121
build_by_default: true,
2222
command: [ prog_doxygen, doxyfile ],
2323
install: true,
24-
install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()),
24+
install_dir: get_option('datadir') / 'doc' / meson.project_name(),
2525
)

doc/ifarm.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
```bash
66
meson/resolve-dependencies.py --help # prints the usage guide
77
```
8-
Use the `--env` option and set the resulting environment variables.
8+
Use the resulting arguments when setting up or configuring your build directory.
99

1010
## Build and Install
1111

doc/setup.md

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ cmake --install build-hipo
7070
- After installation, depending on ROOT's installation prefix you may also need to set your environment so
7171
ROOT may be found; this is typically done by `source /path/to/root/bin/thisroot.sh`
7272

73+
### 🟩 Optional: `RCDB`: Run Condition Database
74+
<https://github.com/JeffersonLab/rcdb>
75+
- RCDB is optional, but needed for algorithms that use, _e.g._, the beam energy
76+
- You do not need to compile RCDB, just clone the repository
77+
- You may need to use the latest version on the main branch, rather than the most recent tag
78+
- Iguana uses `mysql` for RCDB; you may need to install `mariadb` or `mysql` client on your system
79+
- [`mariadb` is an open source fork of `mysql`](https://mariadb.org/)
80+
- depending on your OS's packages, you may need the "dev" version, _e.g._, `libmariadb-dev`
81+
7382
<a name="building"></a>
7483
## 🟠 Building and Installing
7584

@@ -87,10 +96,9 @@ Use [`meson/resolve-dependencies.py`](../meson/resolve-dependencies.py) to help
8796
/path/to/iguana-source/meson/resolve-dependencies.py --help # prints the usage guide
8897
```
8998
Tell it where your dependencies are installed and it will tell you the build options
90-
that you need for Step 2; you can also choose to write those build options to an INI (native) file.
99+
that you need for Step 2.
91100

92-
Alternatively, you may use environment variables; see the [note on dependency
93-
resolution](dependency_resolution.md) for more general guidance.
101+
See the [note on dependency resolution](dependency_resolution.md) for more general guidance.
94102

95103

96104
### 🟩 Step 2: Generate a build directory
@@ -118,9 +126,11 @@ All build options, their current values, and their descriptions may be found by
118126
meson configure # outputs in a pager (`less`); you may scroll, or press 'q' to quit
119127
meson configure --no-pager # do not use a pager
120128
```
121-
**but that's a _lot_ of text!** The _most important_ build options are near the bottom, under **"Project options"**.
129+
**but that's a _lot_ of text!** The _most important_ build options are under the **"Project options"**
130+
sections: the first such section is for `iguana`, and the rest are for subprojects (_e.g._, `rcdb`).
131+
122132
To see _just_ the project options, run the following (which requires [`jq`](https://jqlang.github.io/jq/)):
123-
```
133+
```bash
124134
/path/to/iguana-source/meson/dump-build-options.sh .
125135
```
126136

@@ -130,6 +140,9 @@ meson configure -Dinstall_examples=true
130140
```
131141
You can add as many `-D<option>=<value>` arguments as you need.
132142

143+
> [!NOTE]
144+
> To set a subproject's option, you must prefix the subproject name. For example, for `rcdb`, use `-Drcdb:<option>=<value>`.
145+
133146
### 🟩 Step 4: Compile and Install
134147
Now compile and install Iguana:
135148
```bash

examples/iguana_ex_fortran_01_action_functions.f

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,10 @@ program iguana_ex_fortran_01_action_functions
190190
c 'key_vz_filter' must be passed to the action function;
191191
call iguana_clas12_zvertexfilter_prepareevent(
192192
& algo_vz_filter, runnum(1), key_vz_filter)
193-
c similarly for the inclusive kinematics algorithm
193+
c similarly for the inclusive kinematics algorithm; use '-1'
194+
c for the beam energy, so RCDB is used to get the energy
194195
call iguana_physics_inclusivekinematics_prepareevent(
195-
& algo_inc_kin, runnum(1), key_inc_kin)
196+
& algo_inc_kin, runnum(1), -1, key_inc_kin)
196197
197198
c call iguana filters
198199
c - the `logical` variable `accept` must be initialized to

meson.build

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ project(
1010
'libdir': 'lib',
1111
'licensedir': 'share/licenses/iguana',
1212
'pkgconfig.relocatable': 'true',
13+
'force_fallback_for': ['rcdb'],
1314
},
1415
version: run_command(
1516
meson.project_source_root() / 'meson' / 'detect-version.sh',
@@ -27,6 +28,9 @@ use_chameleon = get_option('bind_fortran')
2728
pkg = import('pkgconfig')
2829
fs = import('fs')
2930

31+
# build subprojects
32+
rcdb_subproj = subproject('rcdb', required: get_option('z_require_rcdb'))
33+
3034
# resolve dependencies
3135
prog_minver = find_program('meson' / 'minimum-version.sh')
3236
# NOTE: those that are typically installed by package managers should use `meson/minimum-version.sh`
@@ -56,13 +60,23 @@ prog_ruby = find_program(
5660
version: '>=' + run_command(prog_minver, 'ruby', check: true).stdout().strip(),
5761
required: use_chameleon,
5862
)
63+
rcdb_dep = dependency(
64+
'rcdb',
65+
fallback: ['rcdb', 'rcdb_dep'],
66+
required: get_option('z_require_rcdb'),
67+
)
68+
thread_dep = dependency(
69+
'threads',
70+
required: true, # FIXME: actually, it's only needed for multi-threading tests/examples
71+
)
5972

6073
# list of dependencies
6174
# FIXME: for users which use LD_LIBRARY_PATH, we should try to keep this list
6275
# ordered such that the ones users are *least likely* to try to build
6376
# themselves are listed last (see FIXME in meson/this_iguana.sh.in)
77+
# NOTE: omit ROOT (handled differently, and most ROOT users already have it in their environment)
6478
dep_list = []
65-
foreach dep : [ hipo_dep, fmt_dep, yamlcpp_dep, ROOT_dep ]
79+
foreach dep : [ hipo_dep, fmt_dep, yamlcpp_dep, rcdb_dep ]
6680
if dep.found()
6781
dep_list += dep
6882
endif
@@ -75,9 +89,6 @@ dep_pkgconfig_dirs = []
7589
foreach dep : dep_list
7690

7791
# get library and include dirs
78-
if dep.name() == 'ROOT'
79-
continue # skip ROOT (handled differently, and most ROOT users already have it in their environment)
80-
endif
8192
if dep.type_name() == 'pkgconfig'
8293
libdirs = [ dep.get_variable(pkgconfig: 'libdir') ]
8394
incdirs = [ dep.get_variable(pkgconfig: 'includedir') ]
@@ -88,7 +99,13 @@ foreach dep : dep_list
8899
endforeach
89100
incdirs = ROOT_dep.get_variable(cmake: 'PACKAGE_INCLUDE_DIRS').split(';')
90101
else
91-
error('Cannot determine how dependency "' + dep.name() + '" was found')
102+
name = dep.get_variable(internal: 'name', default_value: dep.name())
103+
if name == 'rcdb'
104+
incdirs = [ dep.get_variable(internal: 'includedir') ]
105+
else
106+
warning(f'Unknown dependency "@name@"')
107+
continue
108+
endif
92109
endif
93110

94111
# append to `dep_*_dirs` arrays, uniquely
@@ -148,7 +165,7 @@ endif
148165
# general project vars
149166
project_inc = include_directories('src')
150167
project_libs = []
151-
project_deps = declare_dependency(dependencies: [ fmt_dep, yamlcpp_dep, hipo_dep ]) # do NOT include ROOT here
168+
project_deps = declare_dependency(dependencies: dep_list) # do NOT include ROOT here
152169
project_etc = get_option('sysconfdir') / meson.project_name()
153170
project_test_env = environment()
154171
project_pkg_vars = [

meson.options

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ option('test_multithreading', type: 'integer', value: 4, min: 0, descriptio
1616
# expert options: the defaults should be reasonable for a local installation; different values may be preferred for installation in common areas
1717
option('z_install_envfile', type: 'boolean', value: true, description: 'Install a sourceable environment variable file')
1818
option('z_require_root', type: 'boolean', value: false, description: 'Fail if ROOT is not found')
19+
option('z_require_rcdb', type: 'boolean', value: false, description: 'Fail if RCDB is not found')

meson/release/install-cvmfs.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ msg "meson setup"
7070
meson setup $buildDir $sourceDir \
7171
--native-file=$nativeFile \
7272
--prefix=$installDir \
73+
-Drcdb:home=$RCDB_HOME \
7374
-Dtest_data_file=$testFile
7475
msg "meson install"
7576
meson install -C $buildDir

meson/resolve-dependencies.py

Lines changed: 40 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,20 @@ class Formatter(argparse.ArgumentDefaultsHelpFormatter, argparse.RawDescriptionH
2222
parser_deps.add_argument('--fmt', default=SYSTEM_ASSUMPTION, type=str, help='path to `fmt` installation')
2323
parser_deps.add_argument('--yaml', default=SYSTEM_ASSUMPTION, type=str, help='path to `yaml-cpp` installation')
2424
parser_deps.add_argument('--root', default=SYSTEM_ASSUMPTION, type=str, help='path to `ROOT` installation')
25+
parser_deps.add_argument('--rcdb', default='$RCDB_HOME', type=str, help='path to `RCDB` installation')
2526
parser_output = parser.add_argument_group('output control')
26-
parser_output.add_argument('--cli', default=False, action=argparse.BooleanOptionalAction, help='only print the `meson` CLI options, and nothing else')
27-
parser_output.add_argument('--env', default=False, action=argparse.BooleanOptionalAction, help='generate environment variable `export` commands instead')
28-
parser_output.add_argument('--ini', default=NOT_USED, type=str, help='if set, generate an INI file (meson native file) with this name; you may then use it with `meson setup --native-file=_____`')
27+
parser_output.add_argument('--verbose', default=False, action=argparse.BooleanOptionalAction, help='verbose output')
2928
args = parser.parse_args()
3029

3130
# verbosity
32-
verbose = not args.cli
3331
def print_verbose(message):
34-
if(verbose):
32+
if(args.verbose):
3533
print(message)
3634

3735
# functions to set dependency paths
3836
pkg_config_path = set()
3937
cmake_prefix_path = set()
38+
extra_args = []
4039
def use_system(dep):
4140
print_verbose(f'{dep}: {SYSTEM_ASSUMPTION}')
4241
def use_pkg_config(dep, pc_file, arg):
@@ -63,71 +62,49 @@ def use_cmake(dep, arg):
6362
cmake_prefix_path.add(path)
6463
else:
6564
use_system(dep)
65+
def use_env_var(dep, build_var_name, user_val, env_var_name):
66+
if(user_val == f'${env_var_name}'):
67+
if env_var_name in os.environ:
68+
print_verbose(f'{dep}: using environment variable "{env_var_name}" for build variable "{build_var_name}"')
69+
extra_args.append([build_var_name, os.environ[env_var_name]])
70+
else:
71+
print(f'{dep}: you did not specify where {dep} is found, and the fallback environment variable "${env_var_name}" is not set; {dep} will be ignored', file=sys.stderr)
72+
else:
73+
print_verbose(f'{dep}: using user value "{user_val}" for build variable "{build_var_name}"')
74+
extra_args.append([build_var_name, user_val])
6675

6776
# resolve dependencies #########################
6877
use_pkg_config('hipo', 'hipo4.pc', args.hipo)
6978
use_pkg_config('fmt', 'fmt.pc', args.fmt)
7079
use_pkg_config('yaml', 'yaml-cpp.pc', args.yaml)
7180
use_cmake('ROOT', args.root)
81+
use_env_var('rcdb', 'rcdb:home', args.rcdb, 'RCDB_HOME')
7282
################################################
7383

7484

75-
# generate a native file
76-
if(args.ini!=NOT_USED):
77-
def ini_string_arr(arr):
78-
contents = ','.join(map(lambda s: f'\'{s}\'', arr))
79-
return f'[{contents}]'
80-
ini_config = ConfigParser(allow_no_value=True)
81-
ini_config.add_section('built-in options')
82-
if(len(cmake_prefix_path) > 0):
83-
ini_config.set('built-in options', 'cmake_prefix_path', ini_string_arr(cmake_prefix_path))
84-
if(len(pkg_config_path) > 0):
85-
ini_config.set('built-in options', 'pkg_config_path', ini_string_arr(pkg_config_path))
86-
with open(args.ini, 'w') as fp:
87-
ini_config.write(fp)
88-
8985
# generate CLI options
90-
if(verbose or args.cli):
91-
if(len(pkg_config_path)==0 and len(cmake_prefix_path)==0):
92-
print_verbose(textwrap.dedent(f'''
93-
==========================================================================================
94-
All of your dependencies are assumed to be in the system default locations.
95-
- If they are not, please run:
96-
{sys.argv[0]} --help
97-
- Otherwise, you do not need to set or modify any build options for dependency resolution.
98-
==========================================================================================
99-
'''))
100-
exit(0)
101-
else:
102-
if(args.env):
103-
print_verbose(textwrap.dedent('''
104-
==================================================
105-
| Here are the environment variables you need: |
106-
==================================================
107-
'''))
108-
else:
109-
print_verbose(textwrap.dedent('''
110-
===============================================
111-
| Here are the build options that you need: |
112-
===============================================
113-
'''))
114-
cli_opts = []
115-
if(len(pkg_config_path) > 0):
116-
if(args.env):
117-
cli_opts.append(f'export PKG_CONFIG_PATH={":".join(pkg_config_path)}' + '${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}')
118-
else:
119-
cli_opts.append(f'--pkg-config-path={",".join(pkg_config_path)}')
120-
if(len(cmake_prefix_path) > 0):
121-
if(args.env):
122-
cli_opts.append(f'export CMAKE_PREFIX_PATH={":".join(cmake_prefix_path)}' + '${CMAKE_PREFIX_PATH:+:${CMAKE_PREFIX_PATH}}')
123-
else:
124-
cli_opts.append(f'--cmake-prefix-path={",".join(cmake_prefix_path)}')
125-
if(args.ini==NOT_USED):
126-
if(args.env):
127-
for cli_opt in cli_opts:
128-
print(cli_opt)
129-
else:
130-
print(f'{" ".join(cli_opts)}')
131-
else:
132-
print(f'--native-file={args.ini}')
133-
print_verbose('\n')
86+
if(len(pkg_config_path)==0 and len(cmake_prefix_path)==0 and len(extra_args)==0):
87+
print_verbose(textwrap.dedent(f'''
88+
==========================================================================================
89+
All of your dependencies are assumed to be in the system default locations.
90+
- If they are not, please run:
91+
{sys.argv[0]} --help
92+
- Otherwise, you do not need to set or modify any build options for dependency resolution.
93+
==========================================================================================
94+
'''))
95+
else:
96+
print_verbose(textwrap.dedent('''
97+
===============================================
98+
| Here are the build options that you need: |
99+
===============================================
100+
'''))
101+
cli_opts = []
102+
if(len(pkg_config_path) > 0):
103+
cli_opts.append(f'--pkg-config-path={",".join(pkg_config_path)}')
104+
if(len(cmake_prefix_path) > 0):
105+
cli_opts.append(f'--cmake-prefix-path={",".join(cmake_prefix_path)}')
106+
if(len(extra_args) > 0):
107+
for extra_arg in extra_args:
108+
cli_opts.append(f'-D{extra_arg[0]}={extra_arg[1]}')
109+
print(f'{" ".join(cli_opts)}')
110+
print_verbose('\n')

0 commit comments

Comments
 (0)