File indexing completed on 2025-01-17 09:03:00
0001
0002
0003
0004
0005
0006 require 'yaml'
0007 require 'optparse'
0008 require 'ostruct'
0009
0010
0011 options = OpenStruct.new
0012 options.sim_file = 'out/sim.edm4hep.root'
0013 options.rec_file = 'out/rec.edm4hep.root'
0014 options.config_file = 'config/recon_main.yaml'
0015 options.dry_run = false
0016 options.debug_run = false
0017 options.eicrecon_bin = 'eicrecon'
0018
0019
0020 OptionParser.new do |o|
0021 o.banner = "USAGE: #{$0} [OPTIONS]..."
0022 o.separator('')
0023 o.separator('OPTIONS:')
0024 o.on("-c", "--config [FILE]", "Configuration YAML file", "Default: #{options.config_file}"){ |a| options.config_file = a }
0025 o.separator('')
0026 o.on("-s", "--sim [FILE]", "Simulation input file", "Default: #{options.sim_file}"){ |a| options.sim_file = a }
0027 o.separator('')
0028 o.on("-r", "--rec [FILE]", "Reconstruction output file", "Default: #{options.rec_file}"){ |a| options.rec_file = a }
0029 o.separator('')
0030 o.on("-d", "--dry-run", "Dry run: just print the EICrecon command and exit"){ options.dry_run = true }
0031 o.separator('')
0032 o.on("-D", "--debug", "Run in GDB debugger"){
0033 options.debug_run = true
0034 options.eicrecon_bin = 'gdb --args eicrecon'
0035 }
0036 o.separator('')
0037 o.on_tail("-h", "--help", "Show this message") do
0038 puts o
0039 exit 2
0040 end
0041 end.parse!(ARGV)
0042
0043
0044
0045 [
0046 options.sim_file,
0047 options.config_file,
0048 ].each do |name|
0049 unless File.exist? name
0050 $stderr.puts "ERROR: file '#{name}' does not exist"
0051 exit 1
0052 end
0053 end
0054
0055
0056 config_yaml = YAML.load_file options.config_file
0057
0058
0059
0060
0061
0062 def traverse(tree, tree_name='')
0063 case tree.class.name
0064 when 'Hash'
0065 tree.map do |branch_name, branch|
0066 next_name = [tree_name, branch_name].join(':').sub /^:/, ''
0067 traverse branch, next_name
0068 end.flatten
0069 when 'Array'
0070 "#{tree_name}=#{tree.join ','}"
0071 else
0072 [tree_name, tree.to_s].join '='
0073 end
0074 end
0075
0076
0077 arg_list = traverse config_yaml
0078
0079
0080 arg_list.map! do |it|
0081 if it.match? /^log_levels:/
0082 it.sub(/^log_levels:/,'').sub(/\=/,':LogLevel=')
0083 else
0084 it
0085 end
0086 end
0087
0088
0089 arg_list += traverse({
0090 "podio:output_file" => options.rec_file,
0091 })
0092
0093
0094 arg_list += traverse({ "jana:timeout" => "0" }) if options.debug_run
0095
0096
0097 arg_list.map! do |it|
0098 '-P' + it.sub(/.*\=/, '\0"') + '"'
0099 end
0100
0101
0102 arg_list << options.sim_file
0103
0104
0105 eicrecon_cmd = [options.eicrecon_bin, *arg_list].join ' '
0106
0107
0108 puts """
0109 EICRECON ARGUMENTS: ["""
0110 arg_list.each{ |it| puts " #{it}," }
0111 puts """]
0112
0113 EICRECON COMMAND:
0114 #{eicrecon_cmd}
0115 """
0116
0117
0118 if options.dry_run
0119 puts "\nThis is a dry run: stopping before running the above command\n\n"
0120 exit
0121 end
0122
0123
0124 exec eicrecon_cmd