SQL EXPLANATION
This SQL query returns the run, subrun, SM number, crystal number, and
the number of events over the low and hi threshold as written by the
DQM, given a minum number of events over the low and high thresholds.
SELECT riov.run_num run, miov.subrun_num subrun, rdat.id1 SM, cv.id2 crystal,
occ.events_over_low_threshold n_lo, occ.events_over_high_threshold n_hi
FROM run_iov riov
JOIN run_tag rtag ON rtag.tag_id = riov.tag_id
JOIN location_def ldef ON ldef.def_id = rtag.location_id
JOIN (SELECT iov_id, cv.id1 FROM run_dat rdat
JOIN channelview cv ON cv.logic_id = rdat.logic_id AND cv.name = cv.maps_to) rdat
ON rdat.iov_id = riov.iov_id
JOIN mon_run_iov miov ON miov.run_iov_id = riov.iov_id
JOIN mon_occupancy_dat occ ON occ.iov_id = miov.iov_id
JOIN channelview cv ON cv.logic_id = occ.logic_id AND cv.name = cv.maps_to
WHERE ldef.location = 'H4B'
AND occ.events_over_low_threshold >= ?
AND occ.events_over_high_threshold >= ?
ORDER BY run, SM, crystal
SEE ALSO: README