Skip to content

Commit

Permalink
feat: switch to JSON format
Browse files Browse the repository at this point in the history
  • Loading branch information
c-dilks committed Oct 30, 2024
1 parent fd7a058 commit f251c50
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 7 deletions.
7 changes: 0 additions & 7 deletions src/iguana/algorithms/BankDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@
#include <string>


// 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 {
Expand Down
44 changes: 44 additions & 0 deletions src/iguana/bankdefs/generate.py
Original file line number Diff line number Diff line change
@@ -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<BankDef> 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)
22 changes: 22 additions & 0 deletions src/iguana/bankdefs/iguana_banks.json
Original file line number Diff line number Diff line change
@@ -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": ""}
]
}
]

0 comments on commit f251c50

Please sign in to comment.