Skip to content

Commit 6672d8f

Browse files
committed
doc: add documentation for each bank
1 parent 687d628 commit 6672d8f

File tree

2 files changed

+89
-16
lines changed

2 files changed

+89
-16
lines changed

docs/mkdocs/generate.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ top_dir=$src_dir/../..
2525
# generate build files
2626
cp $src_dir/mkdocs.yaml $build_dir/
2727
cp -r $src_dir/docs $build_dir/
28-
$src_dir/src/banks.rb $top_dir/etc/bankdefs/hipo4 > $build_dir/docs/banks.md
28+
$src_dir/src/banks.rb $top_dir/etc/bankdefs/hipo4 $build_dir/docs
2929
tree $build_dir
3030

3131
# build

docs/mkdocs/src/banks.rb

Lines changed: 88 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,30 @@
44
#
55

66
require 'json'
7+
require 'fileutils'
78

8-
if ARGV.empty?
9+
IguanaGroupNum = 30000
10+
CommonBanks = [
11+
'REC::Particle',
12+
'RUN::config',
13+
'REC::Calorimeter',
14+
'REC::Traj',
15+
] # FIXME: add more, or take inspiration from DST schema
16+
17+
unless ARGV.size == 2
918
puts """
10-
USAGE: #{$0} [DIRECTORY]
19+
USAGE: #{$0} [INPUT_JSON_DIR] [OUTPUT_DIR]
1120
12-
Dumps the bank names and ID information for all JSON files in [DIRECTORY]
21+
Dumps the bank names and ID information for all JSON files in [INPUT_JSON_DIR]
22+
Output files will appear in [OUTPUT_DIR]
1323
"""
1424
exit 2
1525
end
16-
SpecDir = ARGV[0]
26+
InputJsonDir = ARGV[0]
27+
OutputDir = ARGV[1]
1728

1829
# parse the JSON files
19-
specs = Dir.glob(File.join SpecDir, '*.json').map do |spec_file_name|
30+
specs = Dir.glob(File.join InputJsonDir, '*.json').map do |spec_file_name|
2031
JSON.parse File.read(spec_file_name)
2132
end.flatten
2233

@@ -43,26 +54,61 @@
4354
# then sort each group's item IDs
4455
specs_fully_sorted = Hash.new
4556
specs_grouped_sorted.each do |group_id, spec_list|
57+
raise "do not define a bank with group ID #{IguanaGroupNum}, since that is reserved for Iguana" if group_id==IguanaGroupNum
4658
specs_fully_sorted[group_id] = spec_list.sort do |spec_a, spec_b|
4759
spec_a['item'].to_i <=> spec_b['item'].to_i
4860
end
4961
end
5062

51-
# dump a table
52-
puts """# Bank Group and Item IDs
63+
# functions to give bank details markdown file name and link
64+
BanksSubDir = 'banks'
65+
def bank_md_name(name)
66+
File.join(BanksSubDir, name.gsub(/::/,'_')) + '.md'
67+
end
68+
def bank_md_link(name)
69+
"[`#{name}`](#{bank_md_name name})"
70+
end
71+
72+
# data type hash
73+
TypeHash = {
74+
'B' => 'byte',
75+
'D' => 'double',
76+
'F' => 'float',
77+
'I' => 'int',
78+
'L' => 'long',
79+
'S' => 'short',
80+
}
81+
82+
# output tables
83+
FileUtils.mkdir_p OutputDir
84+
outMain = File.open File.join(OutputDir, "banks.md"), 'w'
85+
outMain.puts """# HIPO Banks
86+
87+
## Common Banks
88+
89+
"""
90+
CommonBanks.each do |name|
91+
outMain.puts "- #{bank_md_link name}"
92+
end
93+
94+
outMain.puts """
95+
## Full List of Banks
5396
54-
> **NOTE:** Iguana banks, which are defined in the Iguana repository, use group number 30000.
97+
Organized by group and item ID
5598
99+
> **NOTE:** Iguana banks, which are defined in the Iguana repository, use group number #{IguanaGroupNum}.
56100
"""
57101

58-
def row(cols)
59-
puts "| #{cols.join ' | '} |"
102+
def table_row(out, cols)
103+
out.puts "| #{cols.join ' | '} |"
60104
end
61105
specs_fully_sorted.each do |group_id, spec_list|
62-
puts "\n## Group #{group_id}\n\n"
63-
row ['Item ID', 'Name', 'Description']
64-
row ['---', '---', '---']
106+
outMain.puts "\n## Group #{group_id}\n\n"
107+
table_row outMain, ['Item ID', 'Name', 'Description']
108+
table_row outMain, ['---', '---', '---']
65109
spec_list.each do |spec|
110+
111+
# clean up description
66112
desc = spec['info'].split.map do |word|
67113
if word.include? '::'
68114
"`#{word}`"
@@ -72,10 +118,37 @@ def row(cols)
72118
word
73119
end
74120
end.join(' ')
75-
row [
121+
122+
# output main table row
123+
table_row outMain, [
76124
spec['item'],
77-
'`' + spec['name'] + '`',
125+
bank_md_link(spec['name']),
78126
desc,
79127
]
128+
129+
# generate detailed table
130+
outBank = File.open File.join(OutputDir, bank_md_name(spec['name'])), 'w'
131+
outBank.puts """# `#{spec['name']}` Bank Details
132+
133+
#{desc}
134+
135+
[Return to main tables](../banks.md)
136+
137+
"""
138+
table_row outBank, ['Item Name', 'Type', 'Description']
139+
table_row outBank, ['---', '---', '---']
140+
spec['entries'].each do |entry|
141+
datatype = TypeHash[entry['type']]
142+
raise "unknown datatype '#{datatype}'" if datatype.nil?
143+
table_row outBank, [
144+
"`#{entry['name']}`",
145+
"`#{datatype}`",
146+
entry['info']
147+
]
148+
end
149+
outBank.close
80150
end
81151
end
152+
outMain.close
153+
154+
puts "OUTPUT FILES WRITTEN TO #{OutputDir}"

0 commit comments

Comments
 (0)