Skip to content

Commit e9b3e0c

Browse files
committed
feat: qtl xtrain for multiple train dirs
1 parent a930c0d commit e9b3e0c

1 file changed

Lines changed: 69 additions & 51 deletions

File tree

bin/qtl-xtrain

Lines changed: 69 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -7,67 +7,85 @@ unless ARGV.length == 2
77
Verify that a directory of a train's skim files has the same list of
88
run numbers as a directory of DST-file run directories.
99
10-
USAGE: qtl xtrain [TRAIN_DIR] [DST_DIR]
10+
USAGE: qtl xtrain [TRAIN_DIR(S)] [DST_DIR]
1111
1212
Both directories must be on /mss
13+
14+
Use globs to specify multiple TRAIN_DIRS (surround in quotes)
1315
"""
1416
exit 2
1517
end
16-
train_dir, dst_dir = ARGV
1718

18-
# function to get a set of run numbers from one of the argument dirs
19-
def get_runnums(path, type)
20-
runnums = Set.new
21-
raise "#{type} dir `#{path}` is not on /mss" unless path.match? /^\/mss\//
22-
raise "#{type} dir `#{path}` does not exist" unless Dir.exist? path
19+
train_dirs, dst_dir = ARGV
20+
num_failures = 0
2321

24-
# get list of files/directories within
25-
files = []
26-
case type
27-
when :train
28-
files = Dir.glob File.join(path, '*.hipo')
29-
when :DST
30-
files = Dir.glob File.join(path, '*/')
31-
else
32-
raise 'bad type'
33-
end
34-
raise "no #{type} files found in #{type} dir `#{path}`" if files.empty?
22+
# loop over train directories glob
23+
Dir.glob(train_dirs).each do |train_dir|
24+
25+
# function to get a set of run numbers from one of the argument dirs
26+
def get_runnums(path, type)
27+
runnums = Set.new
28+
raise "#{type} dir `#{path}` is not on /mss" unless path.match? /^\/mss\//
29+
raise "#{type} dir `#{path}` does not exist" unless Dir.exist? path
3530

36-
# extract their run numbers
37-
files.each do |file|
38-
nums = File.basename(file).scan(/\d+/).map &:to_i
39-
raise "failed to get run number from #{type} object `#{file}`" unless nums.length == 1
40-
runnums << nums[0]
31+
# get list of files/directories within
32+
files = []
33+
case type
34+
when :train
35+
files = Dir.glob File.join(path, '*.hipo')
36+
when :DST
37+
files = Dir.glob File.join(path, '*/')
38+
else
39+
raise 'bad type'
40+
end
41+
raise "no #{type} files found in #{type} dir `#{path}`" if files.empty?
42+
43+
# extract their run numbers
44+
files.each do |file|
45+
nums = File.basename(file).scan(/\d+/).map &:to_i
46+
raise "failed to get run number from #{type} object `#{file}`" if nums.empty?
47+
runnums << nums[-1]
48+
end
49+
raise "failed to get run numbers from #{type} dir `#{path}`" if runnums.empty?
50+
runnums
4151
end
42-
raise "failed to get run numbers from #{type} dir `#{path}`" if runnums.empty?
43-
runnums
44-
end
4552

46-
# get runnum lists
47-
train_runs = get_runnums train_dir, :train
48-
dst_runs = get_runnums dst_dir, :DST
49-
puts """----------------------------------------------------------------------------------
50-
train dir run list:
51-
#{train_runs}
52-
DST dir run list:
53-
#{dst_runs}
54-
----------------------------------------------------------------------------------"""
53+
# get runnum lists
54+
train_runs = get_runnums train_dir, :train
55+
dst_runs = get_runnums dst_dir, :DST
56+
puts """
57+
==================================================================================
58+
train dir: #{train_dir}
59+
run list: #{train_runs}
60+
-----
61+
DST dir: #{dst_dir}
62+
run list: #{dst_runs}
63+
=================================================================================="""
5564

56-
# compare runnum sets
57-
only_in_trains = train_runs - dst_runs
58-
only_in_dsts = dst_runs - train_runs
65+
# compare runnum sets
66+
only_in_trains = train_runs - dst_runs
67+
only_in_dsts = dst_runs - train_runs
5968

60-
# return results
61-
code = 0
62-
unless only_in_trains.empty?
63-
$stderr.puts "ERROR: there are runs with skim files, but no corresponding DST-file directories:"
64-
$stderr.puts only_in_trains
65-
code = 1
66-
end
67-
unless only_in_dsts.empty?
68-
$stderr.puts "ERROR: there are runs with DST-file directories, but no corresponding skim files:"
69-
$stderr.puts only_in_dsts
70-
code = 1
69+
# print results
70+
$stdout.flush
71+
$stderr.flush
72+
code = 0
73+
unless only_in_trains.empty?
74+
$stderr.puts "ERROR: there are runs with skim files, but no corresponding DST-file directories:"
75+
$stderr.puts only_in_trains
76+
code = 1
77+
end
78+
unless only_in_dsts.empty?
79+
$stderr.puts "ERROR: there are runs with DST-file directories, but no corresponding skim files:"
80+
$stderr.puts only_in_dsts
81+
code = 1
82+
end
83+
84+
# handle exit code
85+
if code == 0
86+
puts "All good"
87+
else
88+
num_failures += 1
89+
end
7190
end
72-
puts "All good" if code == 0
73-
exit code
91+
exit num_failures > 0 ? 1 : 0

0 commit comments

Comments
 (0)