Beispiel #1
0
def main():
  #if not pydim.dis_get_dns_node():
  #  print "Please set the environment variable DIM_DNS_NODE (aldaqecs)"
  #  #sys.exit(1)
  #res= pydim.dic_cmnd_service("TTCMI/MICLOCK_SET", arg, "C")
  if len(sys.argv)>1:
    shift= getShift(sys.argv[1])
    print shift
    return
  while True:
    a= raw_input("get, q to quit:")
    if a=='q': break
    if a=='g' or a=='get':
      sid=8
      if os.getenv("HOSTNAME")[:6] != "alidcs":
        print "not in the pit"
        continue
      pydim.dic_set_dns_node("alidcsdimdns.cern.ch")
      #os.environ['DIM_DNS_NODE']="alidcsdimdns"
      print "dns: alidcsdimdns"
      sid= pydim.dic_info_service("PHASE_SHIFT_BPTX1", "F:1", 
        callback1, service_type=pydim.ONCE_ONLY)
      #cshift= pydim.dic_sync_info_service("PHASE_SHIFT_BPTX1", "F:1")
      #print "cshift:",cshift
      if not sid:
        print "Error registering with info_service"
        break
      sid2= pydim.dic_info_service("TIMESTAMP_PHASE_SHIFT_BPTX1", "I:1", 
        callback1, service_type=pydim.ONCE_ONLY)
      if not sid2:
        print "Error registering with TIMESTAMP info_service"
        break
      time.sleep(1); 
      pydim.dic_release_service(sid)
      pydim.dic_release_service(sid2)
Beispiel #2
0
def getShift(what=None):
  """rc: +/-float in [ns]
         "old" if age of mesurement too old
  what:force
       rc: +/-float in [ns]

  """
  global gshift
  gshift=1000.0
  if os.getenv("HOSTNAME")[:6] != "alidcs":
    import random
    ips= random.randint(-640,640)   # -6400, 6400
    if abs(ips) >6360.0: return "old"
    return str(ips/1000.)
  pydim.dic_set_dns_node("alidcsdimdns.cern.ch")
  #sid= pydim.dic_info_service("PHASE_SHIFT_BPTX1", "F:1", callback1, service_type=pydim.ONCE_ONLY)
  #time.sleep(1); pydim.dic_release_service(sid)
  gshift= pydim.dic_sync_info_service("PHASE_SHIFT_BPTX1", "F:1", timeout=1, default_value=(1000.0,))
  ts= pydim.dic_sync_info_service("TIMESTAMP_PHASE_SHIFT_BPTX1", "I:1", timeout=1, default_value=(0,))
  #print "gshift:", gshift,type(gshift), 'ts:',ts, type(ts)
  if ts==None: return "old"
  age= time.time() - ts[0]
  if what != "force":
    if age>181: return "old"   # was 91 till 3.11.
  rcshift= gshift[0]
  #if (rcshift <= -1.16): return "old"
  if (rcshift <= -23.5) and (-24.95 <= rcshift):
    #rcshift = -24.95 - (rcshift)   # till 11.6.2016
    rcshift = -24.95 - (rcshift+1.16)   # phase_0:1.16ns from 11.6.2016 18:40
  return "%6.4f"%rcshift
Beispiel #3
0
def main():
  #if not pydim.dis_get_dns_node():
  #  print "Please set the environment variable DIM_DNS_NODE (aldaqecs)"
  #  #sys.exit(1)
  #res= pydim.dic_cmnd_service("TTCMI/MICLOCK_SET", arg, "C")
  if len(sys.argv)>1:
    shift= getShift()
    print shift
    return
  print """
 trying pydim.dic_info_service_stamped() -unsuccessfully
  """
  while True:
    a= raw_input("get, q to quit:")
    if a=='q': break
    if a=='g' or a=='get':
      sid=8
      pydim.dic_set_dns_node("alidcsdimdns.cern.ch")
      #os.environ['DIM_DNS_NODE']="alidcsdimdns"
      print "dns: alidcsdimdns"
      #sid= pydim.dic_info_service("PHASE_SHIFT_BPTX1", "F:1", callback1, service_type=pydim.ONCE_ONLY)
      sid= pydim.dic_info_service_stamped("PHASE_SHIFT_BPTX1", "F:1", 
        callback2) #, pydim.ONCE_ONLY)
      #cshift= pydim.dic_sync_info_service("PHASE_SHIFT_BPTX1", "F:1")
      #print "cshift:",cshift
      if not sid:
        print "Error registering with info_service"
        break
      #timestamp= pydim.dic_get_timestamp(sid)   #, secs, msecs)
      #print "timestamp:",timestamp, type(timestamp)
      time.sleep(2); pydim.dic_release_service(sid)
def getShift():
  global gshift
  gshift=1000.0
  pydim.dic_set_dns_node("alidcsdimdns.cern.ch")
  #sid= pydim.dic_info_service("PHASE_SHIFT_BPTX1", "F:1", callback1, service_type=pydim.ONCE_ONLY)
  #time.sleep(1); pydim.dic_release_service(sid)
  gshift= pydim.dic_sync_info_service("PHASE_SHIFT_BPTX1", "F:1", timeout=1, default_value=1000.0)
  #von pydim.dic_set_dns_node("aldaqecs.cern.ch")
  return "%6.4f"%gshift[0]
Beispiel #5
0
 def writeDevice(self, msg):
     # Simple file device
     if self.handler:
         result, msg = self.handler(msg)
         if result == COMMAND_TERMINATE:
             self.enabled = False
             return self
         elif result == COMMAND_HANDLED:
             return self
     if self.dns:
         pydim.dic_set_dns_node(self.dns)
     if self.service:
         ret = pydim.dic_cmnd_service(self.service, (msg, ), self.format)
     return self
Beispiel #6
0
 def __init__(self,
              service,
              output,
              format='C',
              handler=None,
              first=True,
              raw_handler=None):
     dns, svc = service
     self.first = first
     self.service = svc
     self.output = output
     self.handler = handler
     pydim.dic_set_dns_node(dns)
     if not raw_handler: raw_handler = self.dim_input_handler
     self.svcID = pydim.dic_info_service(svc, format, raw_handler)
Beispiel #7
0
 def __init__(self, client, node, dns):
     self.dns = dns
     self.node = node
     self.mode = MODE_LOCAL
     self.client = client
     self.terminate = False
     self.worker_log = None
     self.worker_cmd = None
     self.dim_output_buffer = ''
     helper = Helper(self.client, self.node, self.dns)
     pydim.dis_set_dns_node(helper.dns)
     pydim.dic_set_dns_node(helper.dns)
     self.serviceID = pydim.dis_add_service(helper.proc_all, 'C',
                                            self.dim_output_handler, 1)
     self.publish_common('')
     pydim.dis_start_serving('MASTER/' + helper.proc_all)
     output('++ DIM common  service: %s->%s\n' % (
         helper.dns,
         helper.proc_all,
     ))
Beispiel #8
0
 def run(self):
     helper = Helper(self.client, _host(), self.dns)
     self.process = helper.process
     self.output('++ Start serving: %s->%s\n' % (
         helper.dns,
         helper.process,
     ))
     pydim.dis_set_dns_node(helper.dns)
     pydim.dic_set_dns_node(helper.dns)
     pydim.dis_start_serving(self.process)
     self.cmd_common = DimServiceClient((helper.dns, helper.proc_all),
                                        output=sys.stdout,
                                        raw_handler=self.common_handler)
     while self.enabled:
         try:
             self.startMe()
             self.app.wait()
         except Exception, X:
             self.output('Server Exception: %s' % (str(X), ))
             self.enabled = False
Beispiel #9
0
def getShift(what=None):
    global gshift
    gshift = 1000.0
    if os.getenv("HOSTNAME")[:6] != "alidcs":
        import random

        ips = random.randint(-640, 640)  # -6400, 6400
        if abs(ips) > 6360.0:
            return "old"
        return str(ips / 1000.0)
    pydim.dic_set_dns_node("alidcsdimdns.cern.ch")
    # sid= pydim.dic_info_service("PHASE_SHIFT_BPTX1", "F:1", callback1, service_type=pydim.ONCE_ONLY)
    # time.sleep(1); pydim.dic_release_service(sid)
    gshift = pydim.dic_sync_info_service("PHASE_SHIFT_BPTX1", "F:1", timeout=1, default_value=(1000.0,))
    ts = pydim.dic_sync_info_service("TIMESTAMP_PHASE_SHIFT_BPTX1", "I:1", timeout=1, default_value=(0,))
    # print "gshift:", gshift,type(gshift), 'ts:',ts, type(ts)
    if ts == None:
        return "old"
    age = time.time() - ts[0]
    if what != "force":
        if age > 181:
            return "old"  # was 91 till 3.11.
    return "%6.4f" % gshift[0]