import re import json #Discover camera server forwarding cs = CameraClient("http://sf-daqsync-01:8888") cameras = cs.getCameras() camserver_cameras = [] for c in cameras: try: cfg=cs.getConfig(c) if cfg.get("forwarder_port"): if cfg["forwarder_port"]>0: if cfg["source_type"] == "bsread": camserver_cameras.append(c) except: pass #Discover store pipelines pc = ProxyClient("http://sf-daqsync-01:8889") permanent_pipelines = pc.getPemanentInstances() pc = PipelineClient("http://sf-daqsync-01:8889") for p in permanent_pipelines.keys(): if not p.startswith("#"): try: cfg = pc.getConfig(permanent_pipelines[p]) if cfg.get("pipeline_type") == "store": camserver_cameras.append(cfg["camera_name"]) except: pass #Resolve URLs camserver_sources = {} for c in camserver_cameras: url=caget(c+":BSREADCONFIG") url = url.lower().replace(".psi.ch", "") camserver_sources[url] = c print c, url camserver_cfg_urls = [str(x) for x in camserver_sources.keys()] #Enter direct URLS from ImageBuffer ConfigL file images.source def remove_comments(input_string): pattern = r'/\*.*?\*/' result = re.sub(pattern, '', input_string, flags=re.DOTALL) return result file_name = os.path.abspath(expand_path("{script}/test/image.sources")) file_name = "/afs/psi.ch/user/g/gobbo_a/dev/config/sf_imagebuffer/sources/image.sources" try: f=open(file_name,"r") text =f.read() finally: f.close() text = remove_comments(text) image_buffer_urls_file = json.loads(text) image_buffer_urls = [str(x["stream"].lower().replace(".psi.ch", "")) for x in image_buffer_urls_file["sources"]] for url in image_buffer_urls: print url direct_urls = [] cam_server_urls = [] for x in image_buffer_urls: if "daqsync" in x: cam_server_urls.append(str(x)) else: direct_urls.append(str(x)) conflicts = False #Verify conficts for url in direct_urls: if url in cam_server_urls: print "Conflict: ", url, (camserver_sources[url] if camserver_sources.get(url) else "?") conflicts=True elif url in camserver_cfg_urls: print "Potential conflict: ", url, camserver_cfg_urls[url] conflicts=True if not conflicts: print "No conflicts" #Utility: get camera_name from direft URLs #url = direct_urls[0] #url="tcp://daqsf-sioc-cs-74:9130" def get_direct_camera_names(): camera_names = {} for url in direct_urls: add_device(Stream("st1",url.replace("tcp://daqsf", "tcp://sf"), SocketType.PULL), True) try: st1.start() st1.waitCacheChange(1000) try: camera=st1.take().getKeys()[0].replace(":FPICTURE", "") except: camera=None finally: st1.close() camera_names[url]=camera print url, camera return camera_names def get_streaming_cameras(): camera_names = {} for url in image_buffer_urls: add_device(Stream("st1",url.replace("tcp://daqsf", "tcp://sf"), SocketType.PULL), True) try: st1.start() st1.waitCacheChange(1000) try: v=st1.take() camera=v.getKeys()[0].replace(":FPICTURE", "") shape = v.getShape(0) camera_names[url]=camera print url, camera, shape except: pass finally: st1.close() return camera_names def get_camera_urls(): cs = CameraClient("http://sf-daqsync-01:8888") cameras = cs.getCameras() for camera in cameras: try: url = caget(camera+":BSREADCONFIG") except: url = None print camera, url