|
| 1 | +#!/usr/bin/env ruby |
| 2 | + |
| 3 | +require 'set' |
| 4 | + |
| 5 | +unless ARGV.length == 2 |
| 6 | + puts """ |
| 7 | + Verify that a directory of a train's skim files has the same list of |
| 8 | + run numbers as a directory of DST-file run directories. |
| 9 | +
|
| 10 | + USAGE: qtl xtrain [TRAIN_DIR] [DST_DIR] |
| 11 | +
|
| 12 | + Both directories must be on /mss |
| 13 | + """ |
| 14 | + exit 2 |
| 15 | +end |
| 16 | +train_dir, dst_dir = ARGV |
| 17 | + |
| 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 |
| 23 | + |
| 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? |
| 35 | + |
| 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] |
| 41 | + end |
| 42 | + raise "failed to get run numbers from #{type} dir `#{path}`" if runnums.empty? |
| 43 | + runnums |
| 44 | +end |
| 45 | + |
| 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 | +----------------------------------------------------------------------------------""" |
| 55 | + |
| 56 | +# compare runnum sets |
| 57 | +only_in_trains = train_runs - dst_runs |
| 58 | +only_in_dsts = dst_runs - train_runs |
| 59 | + |
| 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 |
| 71 | +end |
| 72 | +puts "All good" if code == 0 |
| 73 | +exit code |
0 commit comments