Skip to content
Snippets Groups Projects
Commit 0bde8a2e authored by Christopher Dilks's avatar Christopher Dilks
Browse files

feat: more step control

parent 173bf614
Branches
No related tags found
2 merge requests!309Irt algo,!293feat: dRICH benchmarks
...@@ -18,13 +18,14 @@ IdealParticle = 'pi+' ...@@ -18,13 +18,14 @@ IdealParticle = 'pi+'
# default opt # default opt
opt = OpenStruct.new opt = OpenStruct.new
opt.evgen = '' opt.evgen = ''
opt.ana_only = false opt.sim_file = 'out/sim.edm4hep.root'
opt.sim_file = 'sim.edm4hep.root' opt.rec_file = 'out/rec.edm4hep.root'
opt.rec_file = 'rec.edm4hep.root' opt.ana_file = 'out/ana.edm4hep.root'
opt.ana_file = 'ana.edm4hep.root'
opt.run_sim = true opt.run_sim = true
opt.run_rec = true opt.run_rec = true
opt.run_ana = true opt.run_ana = true
opt.run_rec_down = false
opt.run_ana_down = false
opt.num_events = 10 opt.num_events = 10
opt.benchmark_exe = 'benchmark_rich_reconstruction' opt.benchmark_exe = 'benchmark_rich_reconstruction'
opt.algos = Array.new opt.algos = Array.new
...@@ -40,19 +41,30 @@ avail_evgens = [ ...@@ -40,19 +41,30 @@ avail_evgens = [
] ]
# parse options # parse options
required_set = false
OptionParser.new do |o| OptionParser.new do |o|
o.banner = "USAGE: #{$0} [OPTIONS]..." o.banner = "USAGE: #{$0} [OPTIONS]..."
o.separator '' o.separator ''
o.separator 'required options, one of either:'.upcase o.separator 'required options, one of either:'.upcase
o.separator '' o.separator ''
o.on("-b", "--benchmark-only", "Run only the analysis benchmark") { |a| opt.ana_only=true } o.on("-r", "--rec-only", "Run only the reconstruction, then the analysis benchmark") do |a|
opt.run_rec_down = true
required_set = true
end
o.separator ''
o.on("-b", "--ana-only", "Run only the analysis benchmark") do |a|
opt.run_ana_down = true
required_set = true
end
o.separator '' o.separator ''
o.on("-e", "--evgen [EVGEN_MODE]", "Event generation mode, one of:") do |a| o.on("-e", "--evgen [EVGEN_MODE]", "Run the event generation, reconstruction, and analysis",
"[EVGEN_MODE] must be one of:") do |a|
unless avail_evgens.include? a unless avail_evgens.include? a
$stderr.puts "ERROR: unknown event generation mode '#{a}'" $stderr.puts "ERROR: unknown event generation mode '#{a}'"
exit 1 exit 1
end end
opt.evgen = a opt.evgen = a
required_set = true
end end
avail_evgens.each{ |it| o.separator ' '*40+it } avail_evgens.each{ |it| o.separator ' '*40+it }
o.separator '' o.separator ''
...@@ -91,12 +103,26 @@ opt.each_pair { |k,v| puts "#{k.to_s.rjust(20)} => #{v}" } ...@@ -91,12 +103,26 @@ opt.each_pair { |k,v| puts "#{k.to_s.rjust(20)} => #{v}" }
puts '}' puts '}'
# check for required options # check for required options
if opt.evgen=='' and opt.ana_only==false unless required_set
$stderr.puts "ERROR: required options have not been set" $stderr.puts "ERROR: required options have not been set"
$stderr.puts "run '#{$0} --help' for guidance" $stderr.puts "run '#{$0} --help' for guidance"
exit 1 exit 1
end end
# figure out which steps to run
run_step = { :sim=>false, :rec=>false, :ana=>false, }
if opt.run_ana_down
run_step[:ana] = true
elsif opt.run_rec_down
run_step[:rec] = true
run_step[:ana] = true
else
run_step[:sim] = opt.run_sim
run_step[:rec] = opt.run_rec
run_step[:ana] = opt.run_ana
end
puts "steps to run: #{run_step}"
# get compact file # get compact file
if ENV['DETECTOR_PATH'].nil? or ENV['DETECTOR_CONFIG'].nil? if ENV['DETECTOR_PATH'].nil? or ENV['DETECTOR_CONFIG'].nil?
$stderr.puts "ERROR: unknown DETECTOR_PATH or DETECTOR_CONFIG" $stderr.puts "ERROR: unknown DETECTOR_PATH or DETECTOR_CONFIG"
...@@ -105,7 +131,7 @@ end ...@@ -105,7 +131,7 @@ end
compact_file = "#{ENV['DETECTOR_PATH']}/#{ENV['DETECTOR_CONFIG']}.xml" compact_file = "#{ENV['DETECTOR_PATH']}/#{ENV['DETECTOR_CONFIG']}.xml"
# helper functions # event generator command generators
# --------------------------------------------------- # ---------------------------------------------------
def theta2xyz(theta) def theta2xyz(theta)
rad = theta * Math::PI / 180 rad = theta * Math::PI / 180
...@@ -136,7 +162,7 @@ case opt.evgen ...@@ -136,7 +162,7 @@ case opt.evgen
when 'idealAngle' when 'idealAngle'
evgen_cmd = evgen_fixed_angle.call IdealTheta, IdealEnergy, IdealParticle evgen_cmd = evgen_fixed_angle.call IdealTheta, IdealEnergy, IdealParticle
else else
exit 1 unless opt.ana_only exit 1 if run_step[:sim]
end end
...@@ -177,28 +203,28 @@ analysis_cmd.append '-' + 'v'*opt.verbosity if opt.verbosity > 0 ...@@ -177,28 +203,28 @@ analysis_cmd.append '-' + 'v'*opt.verbosity if opt.verbosity > 0
# execute commands # execute commands
# --------------------------------------------------- # ---------------------------------------------------
exe = Proc.new do |cmd_args, name| # proc: execute a command; raise runtime exception if failure (exit nonzero)
cmd = cmd_args.join ' ' exe = Proc.new do |cmd_args, name, step|
puts "#{name} command:".upcase if run_step[step]
cmd_args.each_with_index do |arg,i| cmd = cmd_args.join ' '
line = i==0 ? '' : ' ' puts "benchmark #{name} command:".upcase
line += arg cmd_args.each_with_index do |arg,i|
line += ' \\' unless i+1==cmd_args.size line = i==0 ? '' : ' '
puts line line += arg
end line += ' \\' unless i+1==cmd_args.size
unless opt.dry_run puts line
end
unless opt.dry_run
puts '-'*50
puts "#{name} execution:".upcase
system cmd or raise "benchmark #{name} failed!".upcase
end
puts '-'*50 puts '-'*50
puts "#{name} execution:".upcase
system cmd or raise "#{name} failed!"
end end
puts '-'*50
end end
puts '-'*50 puts '-'*50
unless opt.ana_only
exe.call evgen_cmd, 'event generator' if opt.run_sim # execute the commands
exe.call recon_cmd, 'reconstruction' if opt.run_rec exe.call evgen_cmd, 'event generation', :sim
end exe.call recon_cmd, 'reconstruction', :rec
if opt.ana_only or opt.run_ana exe.call analysis_cmd, 'analysis', :ana
exe.call analysis_cmd, 'benchmark analysis'
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment