From 73c48427e7678b3ab74fc38b483fc500d0a194f5 Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Tue, 4 Jul 2023 12:37:00 -0400 Subject: [PATCH] feat: `recon.rb` configuration file overrides --- config/{recon_irt.yaml => irt.yaml} | 0 config/{recon_main.yaml => main.yaml} | 0 config/noise.yaml | 3 + config/recon_irt_noise.yaml | 56 --------------- config/{recon_sandbox.yaml => sandbox.yaml} | 24 +++---- doc/tutorials/3-running-reconstruction.md | 2 +- recon.rb | 75 +++++++++++++++------ 7 files changed, 67 insertions(+), 93 deletions(-) rename config/{recon_irt.yaml => irt.yaml} (100%) rename config/{recon_main.yaml => main.yaml} (100%) create mode 100644 config/noise.yaml delete mode 100644 config/recon_irt_noise.yaml rename config/{recon_sandbox.yaml => sandbox.yaml} (52%) diff --git a/config/recon_irt.yaml b/config/irt.yaml similarity index 100% rename from config/recon_irt.yaml rename to config/irt.yaml diff --git a/config/recon_main.yaml b/config/main.yaml similarity index 100% rename from config/recon_main.yaml rename to config/main.yaml diff --git a/config/noise.yaml b/config/noise.yaml new file mode 100644 index 0000000..0f27baf --- /dev/null +++ b/config/noise.yaml @@ -0,0 +1,3 @@ +DRICH: + DRICHRawHits: + enableNoise: true diff --git a/config/recon_irt_noise.yaml b/config/recon_irt_noise.yaml deleted file mode 100644 index 979544a..0000000 --- a/config/recon_irt_noise.yaml +++ /dev/null @@ -1,56 +0,0 @@ -################################################################################ -# CONFIGURATION FILE FOR DRICH EICrecon USAGE -# - use with EICrecon `git` branch `irt-algo` or `irt-algo-stable` -################################################################################ - -### EICrecon plugins -plugins: - - janadot - # - dump_flags - -### PODIO collections to include in the output -podio: - output_include_collections: - ### simulation - - DRICHHits - - MCParticles - ### digitization - - DRICHRawHits - - DRICHRawHitsAssociations - ### track projections - - DRICHAerogelTracks - - DRICHGasTracks - - DRICHMergedTracks - ### IRT PID - - DRICHAerogelIrtCherenkovParticleID - - DRICHGasIrtCherenkovParticleID - - DRICHMergedIrtCherenkovParticleID - ### Reconstructed Particles - - ReconstructedChargedParticles - - ReconstructedChargedParticleAssociations - - ReconstructedChargedParticleIDs - -### EICrecon log levels -log_levels: - eicrecon: info - richgeo: info - DRICH: - DRICHRawHits: debug - DRICHTracks: info - DRICHMergedTracks: info - DRICHIrtCherenkovParticleID: info - DRICHMergedIrtCherenkovParticleID: info - pid: - ChargedParticlesWithAssociations: info - -### common settings -jana: - nevents: 0 - debug_plugin_loading: 1 -acts: - MaterialMap: calibrations/materials-map.cbor - -### DRICH Configuration Overrides -DRICH: - DRICHRawHits: - enableNoise: true diff --git a/config/recon_sandbox.yaml b/config/sandbox.yaml similarity index 52% rename from config/recon_sandbox.yaml rename to config/sandbox.yaml index 80ac2bc..150156b 100644 --- a/config/recon_sandbox.yaml +++ b/config/sandbox.yaml @@ -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: @@ -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 diff --git a/doc/tutorials/3-running-reconstruction.md b/doc/tutorials/3-running-reconstruction.md index d5fa127..6d84a0e 100644 --- a/doc/tutorials/3-running-reconstruction.md +++ b/doc/tutorials/3-running-reconstruction.md @@ -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 diff --git a/recon.rb b/recon.rb index 54e8b57..da30300 100755 --- a/recon.rb +++ b/recon.rb @@ -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('') @@ -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 ','` @@ -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({ @@ -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