Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: recon.rb configuration file overrides #92

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions config/noise.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DRICH:
DRICHRawHits:
enableNoise: true
56 changes: 0 additions & 56 deletions config/recon_irt_noise.yaml

This file was deleted.

24 changes: 10 additions & 14 deletions config/recon_sandbox.yaml → config/sandbox.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
###############################################################################
# DRICH Configuration Parameters Sandbox
# - eventually we will have a proper config file in EICrecon itself,
# but already here we can demonstrate that capability, as shown below
# - once we have such config files in EICrecon, we will likely not need to have
# this `recon.rb` wrapper and our own `yaml` files
# - any settings below will override the current default settings, which are
# stored in `EICrecon/src/detectors/DRICH/DRICH.cc`
# - demonstration of configuration parameter overrides for the dRICH
# - the ability to parse units in EICrecon may not yet be merged to `main`
###############################################################################

### DRICH Configuration #####################
DRICH:
### digitizer
DRICHRawHits:
Expand Down Expand Up @@ -38,11 +34,11 @@ DRICH:
- 4
- 5


################################################################################
# Common configuration parameters (collections, plugins, log levels, etc.)
################################################################################

#
# (see other config files)
#
### Output Collections ######################
podio:
output_include_collections:
- DRICHAerogelIrtCherenkovParticleID
- DRICHGasIrtCherenkovParticleID
- ReconstructedChargedParticles
- ReconstructedChargedParticleAssociations
- ReconstructedChargedParticleIDs
2 changes: 1 addition & 1 deletion doc/tutorials/3-running-reconstruction.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ Notice there are significantly fewer hits after digitization:

Now re-run the reconstruction, turning on the noise, and be sure to produce a differently named output file
```bash
recon.rb -c config/recon_irt_noise.yaml -r out/rec.noise.edm4hep.root
recon.rb -c config/noise.yaml -r out/rec.noise.edm4hep.root
```
At the time of writing this, the IRT usage is not really capable of handling the noise, but we can still take a look at the event display:
```bash
Expand Down
75 changes: 53 additions & 22 deletions recon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,26 @@

# default CLI options
options = OpenStruct.new
options.sim_file = 'out/sim.edm4hep.root'
options.rec_file = 'out/rec.edm4hep.root'
options.config_file = 'config/recon_irt.yaml'
options.dry_run = false
options.debug_run = false
options.eicrecon_bin = 'eicrecon'
options.sim_file = 'out/sim.edm4hep.root'
options.rec_file = 'out/rec.edm4hep.root'
options.config_main = 'config/irt.yaml'
options.config_overrides = Array.new
options.dry_run = false
options.debug_run = false
options.eicrecon_bin = 'eicrecon'

# parse CLI options
OptionParser.new do |o|
o.banner = "USAGE: #{$0} [OPTIONS]..."
o.separator('')
o.separator('OPTIONS:')
o.on("-c", "--config [FILE]", "Configuration YAML file", "Default: #{options.config_file}"){ |a| options.config_file = a }
o.on("-m", "--main-config [FILE]", "Main Configuration YAML file", "Default: #{options.config_main}"){ |a| options.config_main = a }
o.separator('')
o.on("-c", "--configs [FILES]...", Array,
"Configuration YAML file(s), which override the main configuration file",
"delimit by commas, no spaces",
"Default: no overriding files"
) { |a| options.config_overrides = a }
o.separator('')
o.on("-s", "--sim [FILE]", "Simulation input file", "Default: #{options.sim_file}"){ |a| options.sim_file = a }
o.separator('')
Expand All @@ -39,23 +46,29 @@
exit 2
end
end.parse!(ARGV)
# puts "OPTIONS: #{options}"
puts "\nOPTIONS: {"
options.each_pair do |k,v|
puts k.to_s.rjust(20) + " => #{v},"
end
puts "}\n\n"

# check for existence of input files
[
options.sim_file,
options.config_file,
options.config_main,
*options.config_overrides,
].each do |name|
if name.nil?
$stderr.puts "ERROR: option for a filename used, but no file was specified"
exit 1
end
unless File.exist? name
$stderr.puts "ERROR: file '#{name}' does not exist"
exit 1
end
end

# parse configuration file to Hash
config_yaml = YAML.load_file options.config_file

# parse a YAML tree of settings, returning an Array of strings with:
# function to parse a YAML tree of settings, returning an Array of strings with:
# - list of node path keys combined with `String.join ':'`
# - leaf node appended as "=#{leaf}"
# - Array leaves will be returned as `String.join ','`
Expand All @@ -73,17 +86,34 @@ def traverse(tree, tree_name='')
end
end

# convert parsed config file settings into 'key=value' pairs JANA can use
arg_list = traverse config_yaml
# parse configuration files, starting with the main file, followed by the overrides
arg_list_parsed = Array.new
[ options.config_main, *options.config_overrides ].each do |config_file|

# fix: key name of log level settings
arg_list.map! do |it|
if it.match? /^log_levels:/
it.sub(/^log_levels:/,'').sub(/\=/,':LogLevel=')
else
it
# parse configuration file to Hash
config_yaml = YAML.load_file config_file

# convert parsed configuration file settings into 'key=value' pairs JANA can use
arg_list_parsed += traverse config_yaml

# fix: key name of log level settings
arg_list_parsed.map! do |it|
if it.match? /^log_levels:/
it.sub(/^log_levels:/,'').sub(/\=/,':LogLevel=')
else
it
end
end

end # parsing configuration files

# for any parameter that was specified more than once, be sure to take only the last specification
arg_hash = Hash.new
arg_list_parsed.each do |it|
k, v = it.split '='
arg_hash[k] = v
end
arg_list = arg_hash.map{ |k, v| "#{k}=#{v}" }

# append CLI settings
arg_list += traverse({
Expand Down Expand Up @@ -120,5 +150,6 @@ def traverse(tree, tree_name='')
exit
end

# run eicrecon: `exec` hands process control over to `eicrecon_cmd`
# run eicrecon: `exec` hands process control over to `eicrecon_cmd`;
# the ruby process will be replaced by the eicrecon process
exec eicrecon_cmd