Example #1
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
Example #2
0
def i2c_writeread(*args, regulator=ddr, **kwargs):
    # FIXME: The operation order doesn't make sense.
    i2c_op(SCA_OP_MODE['writeread'], *args, **kwargs)
    pydim.dic_sync_info_service('{}/{}/SrvcI2CRead'.format(GBT_PREF, GBT_SERV),
                                'I:1;C')
    ret = pydim.dic_sync_info_service(
        '{}/{}/SrvcI2CRead'.format(GBT_PREF, GBT_SERV), 'I:1;C')
    return dim_dic_err(regulator(ret), I2C_ERR_CODE)
Example #3
0
def getlumi():
  """ set 2 globals: lumi + lumi_source
  lumi: float number, luminosity in hz/ub
  lumi_source: how lumi was acquired
     dim:     dim
     default: dim was not available, or dip published number <1.0
     None:    not initialized (i.e. getlumi not called)
  """
  global lumi,lumi_source
  import pydim
  rc=None
  try:
    #Enabled 13.11.2015 and changed 1.0E30 -> 1.0E27 for HI run
    #rclumi = pydim.dic_sync_info_service("IR_MONITOR/CTP/Luminosity", ("F",), 2)
    #rclumi= None
    # In run1 next line invoked 'TypeError: argument list must be a tuple' stdout line
    # when dim service not available.
    rclumi = pydim.dic_sync_info_service("IR_MONITOR/CTP/Luminosity", "F", 2)
    if rclumi!=None:
      lumidim= rclumi[3]
      if lumidim>1.0:
        lumi_source= "dim"
        lumi=lumidim/1.0E27    # hz/ub (was 1.E30 before 13.11.2015)
      else:
        lumi_source= "default"
        lumi= DEFLUMI
    else:
      lumi_source= "default"
      lumi= DEFLUMI
      print "preproc.getlumi: IR_MONITOR/CTP/Luminosity not available, default:%f taken."%lumi
  except:
    print "Except: in dic_sync_info_service(IR_MONITOR/CTP/Luminosity)"
    lumi_source= "default"
    lumi= DEFLUMI
Example #4
0
def gpio_getdir(*args, regulator=ddr, **kwargs):
    gpio_op(SCA_OP_MODE['gpio_getdir'], *args, **kwargs)
    ret = pydim.dic_sync_info_service(
        '{}/{}/SrvcGPIORead'.format(GBT_PREF, GBT_SERV),
        'I:1;C'
    )
    return int(dim_dic_err(regulator(ret), GPIO_ERR_CODE), base=16)
Example #5
0
def gpio_write(*args, regulator=ddr, **kwargs):
    gpio_op(SCA_OP_MODE['write'], *args, **kwargs)
    ret = pydim.dic_sync_info_service(
        '{}/{}/SrvcGPIOWrite'.format(GBT_PREF, GBT_SERV),
        'I:1'
    )
    return dim_dic_err(regulator(ret), GPIO_ERR_CODE)
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]
Example #7
0
def main():
    """
    A client for subscribing to two DIM services
    """

    # Again, check if a Dim DNS node has been configured.
    # Normally this is done by setting an environment variable named DIM_DNS_NODE
    # with the host name, e.g. 'localhost'.
    #
    if not pydim.dis_get_dns_node():
        print("No Dim DNS node found. Please set the environment variable DIM_DNS_NODE")
        sys.exit(1)
    if not pydim.dis_get_dns_port():
        print("No Dim DNS port found. Please set the environment variable DIM_DNS_PORT")
        sys.exit(1)


    print ("dns node is ", pydim.dis_get_dns_node())
    print ("dns port is ", pydim.dis_get_dns_port())
    print ("dns conn id is ", pydim.dic_get_conn_id())
    #pydim.dic_get_server(DIMSERVERNAME@NODENAME)
    #print ("dns server name ", pydim.dic_get_server("server-name@localhost"))


    # The function `dic_info_service` allows to subscribe to a service.
    # The arguments are the following:
    # 1. The name of the service.
    # 2. Service description string
    # 3. Callback function that will be called when the service is
    #    updated.
    '''res1 = pydim.dic_info_service("example-service-1", "C", client_callback1)
    res2 = pydim.dic_info_service("example-service-2", "D:1;I:1;", client_callback2)'''

    res1 = pydim.dic_info_service("example-service-1", client_callback1)
    res2 = pydim.dic_info_service("example-service-2", client_callback2)

    if not res1 or not res2:
        print("There was an error registering the clients")
        sys.exit(1)

    #print("calling example-service-sync that waits 5 seconds to return the number 42")
    #dic_sync_info_service(name, description, timeout = None, default_value =None
    res3 = pydim.dic_sync_info_service("example-service-sync", None, 5)

    if not res3:
        print("There was an error registering the clients (service sync)")
        sys.exit(1)
    print(str(res3))
    print("example-service-sync returned %s" % str(res3))

    # Wait for updates
    while True:
        pydim.dic_cmnd_service("int_cmnd",(5,))
        pydim.dic_cmnd_service("string_cmnd",("Hello world !",))
        time.sleep(5)
Example #8
0
def mem_mon_options_read(tell40=TELL40, regulator=ddr):
    ret = pydim.dic_sync_cmnd_service(
        '{}/{}/CmndOperation/{}.top_tell40.monitoring_options'.format(
            GBT_PREF, GBT_SERV, tell40), (FPGA_REG_OP_MODE['read'], '0'),
        'C:1;C')
    dim_cmd_err(ret)

    ret = pydim.dic_sync_info_service(
        '{}/{}/SrvcReadings/{}.top_tell40.monitoring_options'.format(
            GBT_PREF, GBT_SERV, tell40), 'I:1;C')
    return dim_dic_err(regulator(ret), FPGA_REG_ERR_CODE)
Example #9
0
def main():
    """
    A client for subscribing to two DIM services
    """

    # Again, check if a Dim DNS node has been configured.
    # Normally this is done by setting an environment variable named DIM_DNS_NODE
    # with the host name, e.g. 'localhost'.
    #
    if not pydim.dis_get_dns_node():
        print("No Dim DNS node found. Please set the environment variable DIM_DNS_NODE")
        sys.exit(1)

#    pydim.dic_set_dns_node("localhost")
#    dic_node = pydim.dic_get_dns_node()
#    print("dic_node set to ")
#    print(dic_node)
#    dicportsetting = pydim.dic_set_dns_port(8088)
#    if(dicportsetting):
#        print("Client port is set to 8088")

    # The function `dic_info_service` allows to subscribe to a service.
    # The arguments are the following:
    # 1. The name of the service.
    # 2. Service description string
    # 3. Callback function that will be called when the service is
    #    updated.
    res1 = pydim.dic_info_service("example-service-1", "C", client_callback1)
    res2 = pydim.dic_info_service("example-service-2", "D:1;I:1;", client_callback2)

    #res1 = pydim.dic_info_service("example-service-1", client_callback1)
    #res2 = pydim.dic_info_service("example-service-2", client_callback2)

    if not res1 or not res2:
        print("There was an error registering the clients")
        sys.exit(1)

    print("calling example-service-sync that waits 5 seconds to return the number 42")
    res3 = pydim.dic_sync_info_service("example-service-sync",None,5)
    print("example-service-sync returned %s" % str(res3))



    # Wait for updates
    while True:
        tuple_args = ('Test call no. 5')
#        pydim.dic_cmnd_service("int_cmnd",(5,))
        pydim.dic_cmnd_service("int_cmnd",tuple_args,"C")
#        pydim.dic_cmnd_service("string_cmnd",("Hello world !",))
        print("test")
        time.sleep(5)
Example #10
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]