create view ht_rich700_lookup_data
  (vers_id, det_part_id, backplane, pmt,trbnet_address, channel, pixel_column, pixel_row)
as
  select a.vers_id, -1, d.backplane_id, a.pmt_id, '0x'||to_char(a.trbnet_address,'fmxxxx'), a.channel_id,
         c.pixel_x, c.pixel_y
    from rich700_trb3lookup_data a,
         rich700_pixel b,
         rich700_pixel_grid c,
         rich700_pmt d
    where a.pmt_id = b.pmt_id and a.pmt_pixel = b.pmt_pixel and b.pixel_id = c.pixel_id and a.pmt_id = d.pmt_id;

COMMENT ON TABLE ht_rich700_lookup_data IS 'Lookup table used by the TRB3 unpacker of the rich700 detector (used in web interface)';
COMMENT ON COLUMN ht_rich700_lookup_data.vers_id IS 'Identifier for the version of the parameter set, references rich700_trb3lookup_vers.vers_id';
COMMENT ON COLUMN ht_rich700_lookup_data.det_part_id IS 'Not used';
COMMENT ON COLUMN ht_rich700_lookup_data.backplane IS 'Backplane global index  (1...80)';
COMMENT ON COLUMN ht_rich700_lookup_data.pmt IS 'PMT global index  (1...480)';
COMMENT ON COLUMN ht_rich700_lookup_data.trbnet_address IS 'Trbnet address (0x1000..0x2000, preliminary for photon beam time)';
COMMENT ON COLUMN ht_rich700_lookup_data.channel IS 'Channel id (0..31)';
COMMENT ON COLUMN ht_rich700_lookup_data.pixel_column IS 'Global pixel column (x) on detector plane (1...2000)';
COMMENT ON COLUMN ht_rich700_lookup_data.pixel_row IS 'Global pixel row (y) on detector plane (1...2000)';
