gain is read from code, loss from layerspec database table