diff --git a/src/iguana/algorithms/BankDefs.h b/src/iguana/algorithms/BankDefs.h index 1fca1b40..c094d9d0 100644 --- a/src/iguana/algorithms/BankDefs.h +++ b/src/iguana/algorithms/BankDefs.h @@ -2,13 +2,6 @@ #include -// FIXME -// This really ought to be a YAML file, however: -// - could be handled by `ConfigFileReader`, but need to prevent users from accidentally overriding this -// file with `IGUANA_CONFIG_PATH` -// - we could generate this header file, given a YAML file, with Python (not Ruby, since Meson already needs Python, but Ruby -// is only needed for Chameleon) - namespace iguana { struct BankColDef { diff --git a/src/iguana/bankdefs/generate.py b/src/iguana/bankdefs/generate.py new file mode 100755 index 00000000..180e9d06 --- /dev/null +++ b/src/iguana/bankdefs/generate.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 + +import sys +import json + +if(len(sys.argv) < 3): + print(f'USAGE {__file__} [INPUT_JSON] [OUTPUT]') + exit(2) +input_file_name = sys.argv[1] +output_file_name = sys.argv[2] + +def trailing_comma(arr, idx): + if(idx < len(arr)): + return ',' + else: + return '' + +with open(input_file_name) as input_file: + + try: + bank_defs = json.load(input_file) + + print(' std::vector const bank_defs{') + i_bank_def = 0 + for bank_def in bank_defs: + i_bank_def += 1 + trail_bank_def = trailing_comma(bank_defs, i_bank_def) + print(f' {{') + print(f' .name = "{bank_def["name"]}",') + print(f' .group = {bank_def["group"]},') + print(f' .item = {bank_def["item"]},') + print(f' .entries = {{') + i_entry = 0 + for entry in bank_def['entries']: + i_entry += 1 + trail_entry = trailing_comma(bank_def['entries'], i_entry) + print(f' {{ .name = "{entry["name"]}", .type = "{entry["type"]}" }}{trail_entry}') + print(f' }}') + print(f' }}{trail_bank_def}') + print(' };') + + except json.decoder.JSONDecodeError: + print(f'ERROR: failed to parse {input_file_name}; check its JSON syntax', file=sys.stderr) + exit(1) diff --git a/src/iguana/bankdefs/iguana_banks.json b/src/iguana/bankdefs/iguana_banks.json new file mode 100644 index 00000000..e1c48fbd --- /dev/null +++ b/src/iguana/bankdefs/iguana_banks.json @@ -0,0 +1,22 @@ +[ + { + "name": "physics::InclusiveKinematics", + "group": 30000, + "item": 1, + "info": "", + "entries": [ + { "name": "pindex", "type": "S", "info": ""}, + { "name": "Q2", "type": "D", "info": ""}, + { "name": "x", "type": "D", "info": ""}, + { "name": "y", "type": "D", "info": ""}, + { "name": "W", "type": "D", "info": ""}, + { "name": "nu", "type": "D", "info": ""}, + { "name": "qx", "type": "D", "info": ""}, + { "name": "qy", "type": "D", "info": ""}, + { "name": "qz", "type": "D", "info": ""}, + { "name": "qE", "type": "D", "info": ""}, + { "name": "beamPz", "type": "D", "info": ""}, + { "name": "targetM", "type": "D", "info": ""} + ] + } +]