Optical switching using photoinduced holographic gratings