コード例 #1
0
ファイル: grunsctrl.py プロジェクト: juskoa/trigger
def main():
  if not pydim.dis_get_dns_node():
    print "No DIM_DNS_node found env. variable defined"
    sys.exit(1)
  print "dns:",pydim.dis_get_dns_node()
  grs= GRUNS()
  while True:
    line= raw_input("a[dd] [runn] [t] d[elete]  D[elete all] Log Nolog r[andom automat] R[edis_test] p[rint]q[uit]>")
    if len(line)<1:break
    c= line[0]
    spl= string.split(line)
    arg1= "" ; arg2= False
    if len(spl)>=2: arg1= spl[1]
    if len(spl)>=3: arg2= True
    if c=='q': break
    if c=='a': grs.addrun(arg1, arg2)
    if c=='d': grs.delrun()
    if c=='D': grs.delall()
    if c=='p': grs.prtall()
    if c=='R': redis_test()
    if c=='L':
      grs.updatedims("L")
      print "Logging ON: v/vme/WORK/apmon4.log"
    if c=='N':
      grs.updatedims("N")
      print "Logging OFF: v/vme/WORK/apmon4.log"
    if c=='r':
      print " starting automatic random s/c..."
      automat(grs, 30, 20000)
コード例 #2
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)
コード例 #3
0
def main():
    if not pydim.dis_get_dns_node():
        print "No Dim DNS node found. Please set the environment variable DIM_DNS_NODE"
        sys.exit(1)
    print "dns:", pydim.dis_get_dns_node()
    scope = pydim.dic_info_service("TTCMI/SCOPE", "C", scope_cb)
    qpll = pydim.dic_info_service("TTCMI/QPLL", "C", qpll_cb)
    if not scope:
        print "There was an error registering the clients"
        sys.exit(1)
    while True:
        time.sleep(10)
コード例 #4
0
ファイル: gendimclient.py プロジェクト: AakaFosfor/trigger
def main():
  ddnode= pydim.dis_get_dns_node()
  print "DIM_DNS_NODE:", ddnode
  if not ddnode:
    print "Please set the environment variable DIM_DNS_NODE (aldaqecs)"
    sys.exit(1)
  #sid = pydim.dic_info_service("PHASE_SHIFT_BPTX1", "F", callback1)
  try:
    #sid = pydim.dic_info_service("PHASE_SHIFT_BPTX1", "F", callback1)
    sid = pydim.dic_info_service("TTCMI/SHIFT", "C", callbackC,
      service_type=pydim.ONCE_ONLY)
    sid = pydim.dic_info_service("TTCMI/MICLOCK", "C", callback2,
      service_type=pydim.ONCE_ONLY)
  except:
    print "sys.exc_info:",sys.exc_info()[0]
    sid=None
  if not sid:
    print "Error registering with info_services"
    sys.exit(1)
  print "sid:",sid
  #res= pydim.dic_cmnd_service("TTCMI/MICLOCK_SET", arg, "C")
  while True:
    a= raw_input("q to quit:")
    if a=='q': break
  pydim.dic_release_service(sid)
コード例 #5
0
ファイル: ttcmic.py プロジェクト: AakaFosfor/trigger
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_info_service("TTCMI/MICLOCK", "C", callback1)
  restran = pydim.dic_info_service("TTCMI/MICLOCK_TRANSITION", "C", cbtran)
  if not res or not restran:
    print "Error registering client"
    sys.exit(1)
  time.sleep(1)
  # authenticate:
  if os.environ['USER']=="trigger":
    pid= str(os.getpid())
    print "my pid:", pid
    if os.environ['VMESITE']=='ALICE':
      f= open("/data/ClientLocalRootFs/alidcsvme017/home/alice/trigger/v/vme/WORK/miclockid", "w")
    else:
      print "VMESITE:", os.environ['VMESITE']
      f= open("/home/trigger/v/vme/WORK/miclockid", "w")
    f.write(pid+'\n')
    f.close()
  while True:
    #time.sleep(10)
    a= raw_input('enter BEAM1 BEAM2 REF LOCAL or q:\n')
    if a=='q': break
    #print "entered:",a
    arg= (a,)
    res= pydim.dic_cmnd_service("TTCMI/MICLOCK_SET", arg, "C")
コード例 #6
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)

    # 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", "F:1;I:1;",
                                  client_callback2)

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

    # Wait for updates
    while True:
        time.sleep(10)
コード例 #7
0
ファイル: masksServer.py プロジェクト: AakaFosfor/trigger
def main():
  global mylog, services
  sids= {}
  mylogfn= os.path.join(os.environ["VMEWORKDIR"], "WORK/masksServer")
  #mylog= pylog.Pylog(None,"ttyYES")   # only tty (no file log)
  mylog= pylog.Pylog(mylogfn)
  dnsnode= pydim.dis_get_dns_node()
  if not dnsnode:
    mylog("No Dim DNS node found. Please set the environment variable DIM_DNS_NODE")
    sys.exit(1)
  mypid= str(os.getpid())
  mylog.logm("dns:"+dnsnode+ " mypid:"+mypid)
  mypidfn= os.path.join(os.environ["VMEWORKDIR"], "WORK/masksServer.pid")
  f= open(mypidfn,"w")
  f.write(mypid) ; f.close()
  signal.signal(signal.SIGUSR1, signal_handler)  # 10         SIGUSR1
  signal.signal(signal.SIGHUP, signal_handler)   # 1  kill -s SIGHUP mypid
  #signal.signal(signal.SIGKILL, signal_handler)   # ?
  signal.signal(signal.SIGQUIT, signal_handler)   # 3
  signal.signal(signal.SIGTERM, signal_handler)   # 15 -default
  signal.signal(signal.SIGINT, signal_handler)   # 2 CTRL C
  mtall= ['B','A','C','S','SA','SC','D','E','I']
  for mtag in range(len(mtall)):
    services.append(Service(mtall[mtag], mtag))
  updateAll()
  pydim.dis_start_serving("CTPBCM")
  mylog.logm("Starting the server ...")
  while True:
    a=""
    try:
      #a= raw_input('enter 1 2 3: update from VALID.BCMASKS or q:\n')
      time.sleep(600)
    except:
      mylog.logm("exception:"+str(sys.exc_info()[0]))
      if quit=='q':
        a='q'
      else:
        continue
    if a=='q' or quit=='q': break
    elif a=='1':   # case1
      tist= epochtime()
      mylog.logm("updating at time:%s = %s"%(loctime(tist), str(tist)))
      #pydim.dis_update_service(sids[mt])
      services[0].update()
    elif a=='2':   # case2, explicit update
      tist= epochtime()
      msg="update service directly,time:%s = %s"%(loctime(tist), str(tist))
      mylog.logm(msg)
      #pydim.dis_update_service(sids[mt],("%s"%(tist+"\0"),))
      services[0].update(msg)
    elif a=='3':   # read VALID.BCMASKS and update all service
      updateAll()
    else:
      #mylog.logm('bad input:%s'%a) ; continue
      pass
  pydim.dis_stop_serving()
  #sys.stdout.flush()
  mylog.close()
  os.remove(mypidfn)
コード例 #8
0
ファイル: miclock_noshift.py プロジェクト: AakaFosfor/trigger
def main():
  global WEB
  if not pydim.dis_get_dns_node():
    print "Please set the environment variable DIM_DNS_NODE (aldaqecs)"
    sys.exit(1)
  #signal.signal(signal.SIGKILL, signal_handler)
  # authenticate:
  if os.environ['USER']=="trigger":
    if os.path.exists(MICLOCKID):
      lsf= open(MICLOCKID,"r"); pid=lsf.read(); lsf.close; 
      pid= string.strip(pid,"\n")
      print """
It seems, miclock process already started, pid:%s
If you cannot locate window, where %s is started, please
remove file and kill miclock process, i.e.:
kill %s
rm %s

Than start miclock again.
"""%(pid,pid,pid,MICLOCKID)
      return
    pid= str(os.getpid())
    print "my pid:", pid, "MICLOCKID:",MICLOCKID
    f= open(MICLOCKID, "w"); f.write(pid+'\n'); f.close()
  time.sleep(2)   # 1sec was enough
  WEB=web()
  res = pydim.dic_info_service("TTCMI/MICLOCK", "C", callback1)
  restran = pydim.dic_info_service("TTCMI/MICLOCK_TRANSITION", "C", cbtran)
  # next line after res service (i.e. current clock retrieved already)
  resbm = pydim.dic_info_service("CTPDIM/BEAMMODE", "L:1", callback_bm)
  #print "res...:", resbm, res, restran
  if not res or not restran or not resbm:
    print "Error registering with info_services", resbm, res, restran
    sys.exit(1)
  while True:
    #time.sleep(10)
    try:
      a= raw_input('enter BEAM1 BEAM2 REF LOCAL man auto (now:%s) or q:\n'%\
        WEB.clockchangemode)
    except:
      a='q'
      print "exception:",sys.exc_info()[0]
    if (a!='q') and (a!='BEAM1') and (a!='BEAM2') and (a!='LOCAL') and \
      (a!='REF') and (a!='man') and (a!='auto') and (a!='show') :
      print 'bad input:%s...'%a ; continue
    if a=='q': break
    if a=='auto':
      WEB.clockchangemode='auto'
    elif a=='man':
      WEB.clockchangemode='man'
    elif a=='show':
      WEB.show()
    else:
      print "Wait 3 minutes till MICLOCK_TRANSITION is 0. Switching to ",a," ..."
      arg= (a,)
      res= pydim.dic_cmnd_service("TTCMI/MICLOCK_SET", arg, "C")
      time.sleep(1)
      WEB.newclock= a; WEB.save()
  os.remove(MICLOCKID)
コード例 #9
0
ファイル: simpleClient.py プロジェクト: juskoa/trigger
def main():
  if not pydim.dis_get_dns_node():
    print "No Dim DNS node found. Please set the environment variable DIM_DNS_NODE"
    sys.exit(1)
  print "dns:",pydim.dis_get_dns_node()
  if len(sys.argv)>1:
    servicename= sys.argv[1]
    if len(sys.argv)>2:
      servicefmt= sys.argv[2]
    else:
      servicefmt= "C"
    print "connecting to %s service fmt: %s"%(servicename, servicefmt)
    try:
      serid = pydim.dic_info_service(servicename, servicefmt, service_cb)
      # seems always int returned (regardless of servicename status?)
    except:
      print "Error registering %s"%servicename
      #sys.exit(1)
    print "serid:", type(serid), serid
  else:
    print """
simpleClient.py service [fmt]
fmt default: "C" 
"""
    #sys.exit()
  while True:
    a= raw_input('enter q, cmd CTPDIM/DO XXX YYY, sec1 or sec60":\n')
    print a
    if a=='q': break
    asp= string.split(a)
    if asp[0]=="cmd":
      # cmd CTPDIM/DO W 3
      pydim.dic_cmnd_service(asp[1], (string.join(asp[2:])+"\x00",),"C")
    elif asp[0]=="sec1":
      pydim.dic_cmnd_service("CTPDIM/DO", ("SLEEP 1\x00",),"C")
    elif asp[0]=="sec60":
      pydim.dic_cmnd_service("CTPDIM/DO", ("SLEEP 60\x00",),"C")
    else:
      print "unknown input..."
コード例 #10
0
ファイル: service_client.py プロジェクト: huajieyu/SMC_LL
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)
コード例 #11
0
def subscribe(signal_update_delegate):
    if not pydim.dis_get_dns_node():
        print(
            "No Dim DNS node found. Please set the environment variable DIM_DNS_NODE"
        )
        sys.exit(1)

    # Register listeners
    subscribe_to_service("trdbox/RUN_NUMBER", "run-number",
                         signal_update_delegate)
    subscribe_to_service("ztt_dimfed_server_trd-fee_00_2_0_STATE", "ztt-state",
                         signal_update_delegate)
    subscribe_to_service("trd-fee_00_2_0_STATE", "state",
                         signal_update_delegate)
コード例 #12
0
ファイル: fsclient.py プロジェクト: juskoa/trigger
def main():
  global fsname
  if not pydim.dis_get_dns_node():
    print "No Dim DNS node found. Please set the environment variable DIM_DNS_NODE"
    sys.exit(1)
  #print "dns:",pydim.dis_get_dns_node()
  #if len(sys.argv)>1:
  #  servicename= sys.argv[1]
  #  if len(sys.argv)>2:
  #    servicefmt= sys.argv[2]
  #  else:
  servicefmt= "C"
  servicename1="ALICE/LHC/CIRCULATING_BUNCHES_B1"   # always tupple ('0,...')
  servicename2="ALICE/LHC/CIRCULATING_BUNCHES_B2"
  servicename3="ALICEDAQ_LHCFillingSchemeName"   # "" in "BEAM SETUP: NO BEAM"
  servicename4="ALICEDAQ_LHCFillNumber"   # service NOT AVAILABLE in "BEAM SETUP: NO BEAM"
  # I.e: first 3 services ALWAYS ON (server always active!)
  try:
    serid3 = pydim.dic_info_service(servicename3, servicefmt, service_cb3)
    serid4 = pydim.dic_info_service(servicename4, "L", service_cb4)
    serid1 = pydim.dic_info_service(servicename1, servicefmt, service_cb1)
    serid2 = pydim.dic_info_service(servicename2, servicefmt, service_cb2)
    # seems always int returned (regardless of servicename status?)
  except:
    print "Error registering %s"%servicename
    #sys.exit(1)
  #print "serid:", type(serid1), serid1, serid2
  time.sleep(2)
  if fsname == None: sys.exit(1)  # shoudl wake alarm
  if beamA == None: sys.exit(1)   # should wake alarm
  if beamC == None: sys.exit(1)   # should wake alarm
  dipname= fsname+'.dip'
  #print "dipname:%s: filln lengths A/C:"%dipname, filln, len(beamA), len(beamC)
  #print "type:",type(dipname)
  fsdip= open(dipname, "w")
  nwritten=0
  for ix in range(len(beamA)):
    fsdip.write("A " + beamA[ix]+'\n')
    nwritten= nwritten+1
  nwrittena= nwritten
  for ix in range(len(beamC)):
    fsdip.write("C " + beamC[ix]+'\n')
    nwritten= nwritten+1
  fsdip.close()
  print "fs %s %s %s %s"%(fsname, filln, nwrittena, nwritten) 
コード例 #13
0
ファイル: fsclient.py プロジェクト: AakaFosfor/trigger
def main():
  global fsname
  if not pydim.dis_get_dns_node():
    print "No Dim DNS node found. Please set the environment variable DIM_DNS_NODE"
    sys.exit(1)
  #print "dns:",pydim.dis_get_dns_node()
  #if len(sys.argv)>1:
  #  servicename= sys.argv[1]
  #  if len(sys.argv)>2:
  #    servicefmt= sys.argv[2]
  #  else:
  servicefmt= "C"
  servicename1="ALICE/LHC/CIRCULATING_BUNCHES_B1"
  servicename2="ALICE/LHC/CIRCULATING_BUNCHES_B2"
  servicename3="ALICEDAQ_LHCFillingSchemeName"
  servicename4="ALICEDAQ_LHCFillNumber"
  #print "connecting to %s service fmt: %s"%(servicename1, servicefmt)
  try:
    serid3 = pydim.dic_info_service(servicename3, servicefmt, service_cb3)
    serid4 = pydim.dic_info_service(servicename4, "L", service_cb4)
    serid1 = pydim.dic_info_service(servicename1, servicefmt, service_cb1)
    serid2 = pydim.dic_info_service(servicename2, servicefmt, service_cb2)
    # seems always int returned (regardless of servicename status?)
  except:
    print "Error registering %s"%servicename
    #sys.exit(1)
  #print "serid:", type(serid1), serid1, serid2
  time.sleep(2)
  if fsname == "": exit
  dipname= fsname+'.dip'
  #print "dipname:%s: filln lengths A/C:"%dipname, filln, len(beamA), len(beamC)
  #print "type:",type(dipname)
  fsdip= open(dipname, "w")
  nwritten=0
  for ix in range(len(beamA)):
    fsdip.write("A " + beamA[ix]+'\n')
    nwritten= nwritten+1
  nwrittena= nwritten
  for ix in range(len(beamC)):
    fsdip.write("C " + beamC[ix]+'\n')
    nwritten= nwritten+1
  fsdip.close()
  print "fs %s %s %s %s"%(fsname, filln, nwrittena, nwritten) 
コード例 #14
0
ファイル: calclient.py プロジェクト: AakaFosfor/trigger
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_info_service("TTCMI/MICLOCK", "C", callback1)
  #if not res:
  #  print "Error registering client"
  #  sys.exit(1)
  time.sleep(1)
  # authenticate:
  while True:
    #time.sleep(10)
    a= raw_input('[a|d] 1 2..., u, p, help or q:\n')
    if (a[0]!='q') and (a[0]!='a') and (a[0]!='d') and (a[0]!='p') \
      and (a[0]!='u') and (a[0]!='h'):
      print 'bad input:%s. Not sent.'%a ; continue
    if a[0]=='h': 
      print """
SDD:2 
TOF:5 
MTR:11
T00:13
ZDC:15
EMC:18
Examples:
a 2 5     -add SDD+TOF to the list of calibrated detectors
d 13 15   -delete T0+ZDC from the list of calibrated detectors
u         -update the list of calibrated detectors from current global runs
p         -print status into alidcsvme001:v/vme/WORK/gcalib.log file
h         -this message
q         -quit this DIM client
"""
      continue
    if a[0]=='q': break
    if (a[0]=='a')or (a[0]=='d'): 
      print "Add/Del dets:",a
    arg= (a,)
    res= pydim.dic_cmnd_service("CTPCALIB/DO", arg, "C")
    time.sleep(1)
コード例 #15
0
ファイル: miclock_shift.py プロジェクト: AakaFosfor/trigger
def main():
  global WEB,mylog
  if not pydim.dis_get_dns_node():
    print "Please set the environment variable DIM_DNS_NODE (aldaqecs)"
    sys.exit(1)
  #signal.signal(signal.SIGKILL, signal_handler)
  #signal.signal(signal.SIGUSR1, signal_handler)
  for bmix in bm2clock.keys():
    bmnamx= bm2clock[bmix][1]
    bm2clocknames[bmnamx]= bmix
  if os.path.exists(MICLOCKID):
    lsf= open(MICLOCKID,"r"); pid=lsf.read(); lsf.close; 
    pid= string.strip(pid,"\n")
    print """
It seems, miclock process already started, pid:%s
If you cannot locate window, where %s is started, please
remove file and kill miclock process, i.e.:
kill %s
rm %s

Than start miclock again.
"""%(pid,pid,pid,MICLOCKID)
    sys.exit(1)
  mylog= pylog.Pylog("miclock","ttyYES")
  pid= str(os.getpid())
  mylog.logm("my pid:"+ pid+ " MICLOCKID:"+ MICLOCKID)
  f= open(MICLOCKID, "w"); f.write(pid+'\n'); f.close()
  # authenticate:
  if os.environ['USER']!="trigger" and os.environ['USER']!="oerjan":
    print "Warning: not trigger account:",os.environ['USER']
  ##mylog.logm("## vesion -i.e. miclock_shift.py")
  mylog.logm("miclock.py started...")
  time.sleep(2)   # 1sec was enough
  WEB=web()
  res = pydim.dic_info_service("TTCMI/MICLOCK", "C", callback1)
  restran = pydim.dic_info_service("TTCMI/MICLOCK_TRANSITION", "C", cbtran)
  # next line after res service (i.e. current clock retrieved already)
  resbmold = pydim.dic_info_service("CTPDIM/BEAMMODE", "L:1", callback_bmold)
  if os.environ['VMESITE']=='ALICE':
    maid = pydim.dic_info_service("ALICE/LHC/TTCMI/CLOCK_MODE", "C", callback_manauto)
    # following returns '' between fills
    resbm = pydim.dic_info_service("ALICEDAQ_LHCBeamMode", "C:100", callback_bm)
    # following commented, when not available (between fills) message:
    # DIM Wrapper: src/dimmodule.cpp:1588 :: dic_ino_service_dummy: ERROR: Could not get new data to update service
    #resfn = pydim.dic_info_service("ALICEDAQ_LHCFillNumber", "C:100", callback_fsn)
  # ALICEDAQ_LHCFillNumber not available after dump (availablebe after INJECTION PROBE...)
    resfsn= pydim.dic_info_service("ALICEDAQ_LHCFillingSchemeName", "C:100", callback_fsn)
    #print "res...:", resbm, res, restran
    if not res or not restran or not resbm:
      mylog.logm("Error registering with info_services"%d(resbm, res, restran))
      sys.exit(1)
  while True:
    #time.sleep(10)
    #man/auto     -change operation mode (manual or automatic) now:%s
    #             auto is forbidden from 28.4.2015
    try:
      #a= raw_input(  enter BEAM1 BEAM2 REF LOCAL man auto (now:%s)
      a= raw_input("""
   enter:
   BEAM1       	-change the ALICE clock to BEAM1
   LOCAL       	-change the ALICE clock to LOCAL
   getshift    	-display current clock shift
   reset       	-reset current clock shift to 0
   q            -quit this script
""")
      #%WEB.clockchangemode)
    except:
      a='q'
      mylog.logm("exception:"+str(sys.exc_info()[0]))
    if string.find("getshift",a)==0: a="getshift"
    if (a!='q') and (a!='') and \
      (a!='BEAM1') and (a!='BEAM2') and (a!='LOCAL') and \
      (a!='getshift') and (a!='reset') and (a!='resetforce') and \
      (a!='REF') and (a!='man') and (a!='auto') and (a!='show') :
      mylog.logm('bad input:%s'%a) ; continue
    if a=='q': break
    if a=='': continue
    if a=='auto':
      mylog.logm("Attempt to go to auto... Forbidden, no action")
      #WEB.clockchangemode='auto'
      #WEB.save()
    elif a=='man':
      WEB.clockchangemode='MANUAL'
      WEB.save()
    elif a=='show':
      WEB.show()
    elif (a=='getshift'):
      cshift= getShift()
      if cshift != "old":
        mylog.logm("Clock shift: %s ns."%cshift)
      else:
        mylog.logm("Clock shift not measured (too old).")
    elif a=='resetforce':
      cshift= getShift("force")
      if cshift != "old":
        mylog.logm("Clock shift (%s ns) reset..."%cshift)
        checkandsave(cshift,"fineyes", force='yes')
      else:
        mylog.logm("Clock shift measurement is too old, reset not done")
    elif a=='reset':
      cshift= getShift()
      if cshift != "old":
        mylog.logm("Clock shift (%s ns) reset..."%cshift)
        checkandsave(cshift,"fineyes", force='yes')
      else:
        mylog.logm("Clock shift measurement is too old, reset not done")
    else:
      mylog.logm("Wait 3 half-minutes till MICLOCK_TRANSITION is 0. Switching to "+a+" ...");
      ##mylog.logm("not supported... ##, i.e. miclock_shift debug version")
      ##continue
      WEB.newclock= a; WEB.save()
      arg= (a,)
      res= pydim.dic_cmnd_service("TTCMI/MICLOCK_SET", arg, "C")
      mylog.logm("TTCMI/MICLOCK_SET "+a, 1)
      mylog.flush()
      time.sleep(1)
  ##os.remove(MICLOCKID)
  os.remove(MICLOCKID)
  #pydim.dic_release_service(resbm)    -Segmentation fault when 'q'
  #pydim.dic_release_service(res)
  #pydim.dic_release_service(restran)
  mylog.close()
コード例 #16
0
ファイル: miclock_fifo.py プロジェクト: AakaFosfor/trigger
def main():
  global WEB,mylog
  if not pydim.dis_get_dns_node():
    print "Please set the environment variable DIM_DNS_NODE (aldaqecs)"
    sys.exit(1)
  #signal.signal(signal.SIGKILL, signal_handler)
  #signal.signal(signal.SIGUSR1, signal_handler)
  # authenticate:
  ##if os.environ['USER']=="##trigger":
  if os.environ['USER']=="trigger" or os.environ['USER']=="oerjan":
    if os.path.exists(MICLOCKID):
      lsf= open(MICLOCKID,"r"); pid=lsf.read(); lsf.close; 
      pid= string.strip(pid,"\n")
      print """
It seems, miclock process already started, pid:%s
If you cannot locate window, where %s is started, please
remove file and kill miclock process, i.e.:
kill %s
rm %s

Than start miclock again.
"""%(pid,pid,pid,MICLOCKID)
      sys.exit(1)
    mylog= pylog.Pylog("miclock","ttyYES")
    pid= str(os.getpid())
    mylog.logm("my pid:"+ pid+ " MICLOCKID:"+ MICLOCKID)
    f= open(MICLOCKID, "w"); f.write(pid+'\n'); f.close()
  else:
    print "can be started only from trigger account..."
    return
  micfifo= None
  if len(sys.argv)>1 and sys.argv[1]=="fifo":
    micfifo= open("/tmp/micfifo", "r")
    mylog.logm("/tmp/micfifo input...")
  else:
    mylog.logm("miclock.py started from cmdline...")
  time.sleep(1)   # 1sec was enough
  WEB=web()
  res = pydim.dic_info_service("TTCMI/MICLOCK", "C", callback1)
  restran = pydim.dic_info_service("TTCMI/MICLOCK_TRANSITION", "C", cbtran)
  # next line after res service (i.e. current clock retrieved already)
  resbm = pydim.dic_info_service("CTPDIM/BEAMMODE", "L:1", callback_bm)
  #print "res...:", resbm, res, restran
  if not res or not restran or not resbm:
    mylog.logm("Error registering with info_services"%d(resbm, res, restran))
    sys.exit(1)
  while True:
    #time.sleep(10)
    if micfifo:
      a= micfifo.readline()
      if a=="":
        if (sleeploop%10)==0:
          mylog.logm("micfifo closed, sleeping %d..."%(sleeploop*10))
        time.sleep(1)
        sleeploop= sleeploop+1
        continue
      else:
        sleeploop=0
        a= string.strip(a)
    #else:
    elif False:
      try:
        #a= raw_input(  enter BEAM1 BEAM2 REF LOCAL man auto (now:%s)
        a= raw_input("""
   enter:
   BEAM1       	-change the ALICE clock to BEAM1
   LOCAL       	-change the ALICE clock to LOCAL
   man/auto     -change operation mode (manual or automatic) now:%s
   getshift    	-display current clock shift
   reset       	-reset current clock shift to 0
   q            -quit this script
"""%\
          WEB.clockchangemode)
      except:
        a='q'
        mylog.logm("exception:"+str(sys.exc_info()[0]))
    else:
      print "micfifo: None"
      break
    if string.find("getshift",a)==0: 
      #print "getshift:%s:"%a
      a="getshift"
    if (a!='q') and (a!='') and \
      (a!='BEAM1') and (a!='BEAM2') and (a!='LOCAL') and \
      (a!='getshift') and (a!='reset') and \
      (a!='REF') and (a!='man') and (a!='auto') and (a!='show') :
      mylog.logm('bad input:%s'%a) ; continue
    if a=='q':
      mylog.logm("quit.")
      break
    if a=='': continue
    if a=='auto':
      WEB.clockchangemode='auto'
      WEB.save()
      mylog.logm("Clock change mode: %s"%a)
    elif a=='man':
      WEB.clockchangemode='man'
      WEB.save()
      mylog.logm("Clock change mode: %s"%a)
    elif a=='show':
      WEB.show()
      mylog.logm("Clock change mode: %s"%WEB.clockchangemode)
    elif (a=='getshift'):
      cshift= getShift()
      if cshift != "old":
        mylog.logm("Clock shift: %s ns."%cshift)
      else:
        mylog.logm("Clock shift not measured (too old).")
    elif a=='reset':
      cshift= getShift()
      if cshift != "old":
        mylog.logm("Clock shift (%s ns) reset..."%cshift)
        checkandsave(cshift,"fineyes", force='yes')
      else:
        mylog.logm("Clock shift measurement is too old, reset not done")
    else:
      mylog.logm("Wait 3 half-minutes till MICLOCK_TRANSITION is 0. Switching to "+a+" ...");
      ##mylog.logm("not supported... ##, i.e. miclock_shift debug version")
      ##continue
      WEB.newclock= a; WEB.save()
      arg= (a,)
      res= pydim.dic_cmnd_service("TTCMI/MICLOCK_SET", arg, "C")
      mylog.logm("TTCMI/MICLOCK_SET "+a, 1)
      mylog.flush()
      time.sleep(1)
  ##os.remove(MICLOCKID)
  if micfifo: micfifo.close()
  os.remove(MICLOCKID)
  #pydim.dic_release_service(resbm)    -Segmentation fault when 'q'
  #pydim.dic_release_service(res)
  #pydim.dic_release_service(restran)
  mylog.close()
コード例 #17
0
    " will be put in that directory.")
parser.add_argument(
    "--task-log",
    dest="task_log",
    type=str,
    default="log",
    help="Write Iterator and Worker tasks output to (split) log file;" +
    " may contain a directory.")
parser.add_argument("--viewers",
                    action="store_true",
                    dest="viewers",
                    help="Run the LogViewer in an xterm.")
args = parser.parse_args()

os.environ["DIM_DNS_NODE"] = args.dim_dns_node
if not pydim.dis_get_dns_node():
    print "No Dim DNS node found, problem with DIM_DNS_NODE??"
    sys.exit(1)

# if the default fifo isn't there, stuff doesn't work. Create it in that case.
if not os.path.exists("/tmp/logSrv.fifo"):
    os.mkfifo("/tmp/logSrv.fifo")

# Write log in directory
if os.path.sep in args.task_log:
    d, f = args.task_log.rsplit(os.path.sep, 1)
    if not os.path.exists(d):
        os.makedirs(d)
    log_file = os.path.join(d, args.log)
else:
    log_file = args.log
コード例 #18
0
def test_dis_interface():
    print 80 * '-'
    x = pydim.dis_get_dns_node()
    pydim.dis_set_dns_node('tralala')
    if not pydim.dis_get_dns_node() == 'tralala':
        ERORR('get/set dns failed')
        sys.exit(1)
    pydim.dis_set_dns_node(x)
    print 'dis_get/dns_node functions tested'

    print 80 * '-'
    x = pydim.dis_get_dns_port()
    pydim.dis_set_dns_port(-2525)
    if not pydim.dis_get_dns_port() == 2525:
        ERROR('get/set dns port failed. Received ports', x,
              pydim.dis_get_dns_port())
    pydim.dis_set_dns_port(x)
    print 'dis_get/dns_port functions tested'

    s = Struct()

    pydim.dis_add_exit_handler(dummy)
    pydim.dis_add_exit_handler(s.dummy)

    pydim.dis_add_error_handler(dummy)
    pydim.dis_add_error_handler(s.dummy)

    pydim.dis_add_client_exit_handler(dummy)
    pydim.dis_add_client_exit_handler(s.dummy)

    pydim.dis_start_serving()
    pydim.dis_stop_serving()

    print 'dis_update_service', pydim.dis_update_service(1)
    print 'dis_selective_update_service', pydim.dis_selective_update_service(
        1, (1, 2, 3))
    print 'dis_selective_update_service', pydim.dis_selective_update_service(
        1, [1, 2, 3])

    print 'dis_set_quality', pydim.dis_set_quality(1, 10)
    print 'dis_set_timestamp: ', pydim.dis_set_timestamp(1, 1, 1)
    print 'dis_remove_service: ', pydim.dis_remove_service(1)

    print 'dis_get_next_cmnd: ', pydim.dis_get_next_cmnd(10)
    print 'dis_get_client: ', pydim.dis_get_client('fdas')
    print 'dis_get_conn_id: ', pydim.dis_get_conn_id()
    print 'dis_get_timeout: ', pydim.dis_get_timeout(1, 1)
    print 'dis_get_client_services: ', pydim.dis_get_client_services(10)
    print 'dis_set_client_exit_handler', pydim.dis_set_client_exit_handler(
        1, 1)
    print 'dis_get_error_services', pydim.dis_get_error_services()
    i = 1
    sleep(1)
    pydim.dis_add_cmnd('test1', "C:20", dummy, 1)
    pydim.dis_add_cmnd('test2', "F:2;D:2;I:3;S:1;C:5;C:1", Struct().dummy, 2)

    svc1 = pydim.dis_add_service('Test Service Nr.1', "F:1;I:1;D:2;C:1;C:1;",
                                 service1, 1)
    svc2 = pydim.dis_add_service('Test Service Nr.2', "D:1",
                                 Struct().service2, 2)

    print("Starting serving services 1 and 2. Their ids are", svc1, svc2)
    pydim.dis_start_serving()
    while True:
        global counter
        if counter % 2:
            counter += 1
            print("Updating service nr. 1")
            print pydim.dis_update_service(
                svc1, (counter, counter + 1, 999.0, 999.0, 'BAU', 'B'))
            print("Updating service nr. 2")
            print pydim.dis_update_service(svc2, 100)
        else:
            print("Updating service nr. 1")
            print pydim.dis_update_service(svc1)
            print("Updating service nr. 2")
            print pydim.dis_update_service(svc2)
        sleep(5)
コード例 #19
0
def main():
    """
    A simple DIM server with two services.
    """
    #Server configuration

    # First of all 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'.
    #
    pydim.dis_set_dns_node("localhost")
    
    pydim.dis_set_dns_port(631)

    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(pydim.dis_get_dns_port())
    print(pydim.dis_get_dns_node())




    # The function dis_add_service is used to register the service in DIM
    # The arguments used are the following:
    #  1. Service name. It must be a unique name within a DNS server.
    #  2. Service description string.
    #  3. A callback function that will be executed for getting the value of
    #     the service.
    #  4. Tag. A parameter to be sent to the callback in order to identify
    #     the service. Normally this parameter is rarely used (but it's still
    #     mandatory, though).
   
    svc = pydim.dis_add_service("example-service-1", "C", service_callback, 0) #original
    # Register another service
    svc2 = pydim.dis_add_service("example-service-2", "D:1;I:1;", service_callback2, 0)

    svc3 = pydim.dis_add_service("example-service-sync","I",service_sync_callback,0)

    # The return value is the service identifier. It can be used to check
    # if the service was registered correctly.
    if not svc or not svc2 or not svc3:
      sys.stderr.write("An error occurred while registering the service\n")
      sys.exit(1)

    print("Services correctly registered")



    # A service must be updated before using it.
    print("Updating the services ...")
    pydim.dis_update_service(svc)
    pydim.dis_update_service(svc2)
    pydim.dis_update_service(svc3)
    print("")

    # Start the DIM server.
    pydim.dis_start_serving("server-name")
    print("Starting the server ...")

    # Initial values for the service 2. Please see below.
    val1 = 3.11
    val2 = 0
    # starting the loop
    while True:
      # Update the services periodically (each 5 seconds)
      time.sleep(5)

      print("")

      # Case 1: When `dis_update_service` is called without arguments the
      # callback function will be executed and its return value
      # will be sent to the clients.
      print("Updating the service 1 with the callback function")
      #update service 1 every 5 seconds
      pydim.dis_update_service(svc)


      # Case 2: When `dis_update_service` is called with arguments, they are
      # sent directly to the clients as the service value, *without* executing the
      # callback function. Please note that the number and the type of the
      # arguments must correspond to the service description.
      #

      # Update the second server each 10 seconds/time interval = 5 seconds
      #
      if val2 % 2:
          print("Updating the service 2 with direct values")
          pydim.dis_update_service(svc2, (val1, val2))

      

      # For the sake of the example, update the values passed to svc2:
      val1 = val1 + 11.30
      val2 = val2 + 1
コード例 #20
0
ファイル: sctelServer.py プロジェクト: AakaFosfor/trigger
def main():
  if not pydim.dis_get_dns_node():
    print "No Dim DNS node found. Please set the environment variable DIM_DNS_NODE"
    sys.exit(1)
  print "dns:",pydim.dis_get_dns_node()
  scopes = pydim.dis_add_service("TTCMI/SCOPE", "C", scope_cb, 0)
  if not scopes:
    sys.stderr.write("Error registering the service TTCMI/SCOPE\n")
    sys.exit(1)
  miclock = pydim.dic_info_service("TTCMI/MICLOCK", "C", miclock_cb)
  beammode = pydim.dic_info_service("CTPDIM/BEAMMODE", "L:1", beammode_cb)
  if not miclock:
    print "Error registering TTCMI/MICLOCK"
    sys.exit(1)
  # A service must be updated before using it.
  print "Updating the services ..."
  pydim.dis_update_service(scopes)
  pydim.dis_start_serving("TTCMISCOPE")
  print "Starting the server ..."
  npass=0; tn=None    # i.e. telnet closed
  while True:
    # Update the services periodically
    # Case 1: When `dis_update_service` is called without arguments the 
    # callback function will be executed and its return value
    # will be sent to the clients.
    #pydim.dis_update_service(scopes)
    #time.sleep(1)
    # Case 2: When `dis_update_service` is called with arguments, they are
    # sent directly to the clients as the service value, *without* executing the
    # callback function. Please note that the number and the type of the 
    # arguments must correspond to the service description. 
    #
    #print "pass:"******"BEAM1") and ((BeamMode>="9") and (BeamMode<=11)):
    #
    # in dbg mode: alwasy with BEAM1 and flip/flop with LOCAL:
    if ((AliceClock=="LOCAL") and ((npass % 10)<5)) or\
        (AliceClock=="BEAM1"):
      if tn == None:
        print "opening telnet..."
        tn= sctel.TN()
        if tn.prompt1=="":
          tn= None
          # can't open telnet, it's time to restart infinium:
          tist= epochtime()
          print "%s restart:"%loctime(tist), tist
          pydim.dis_update_service(scopes,("%s"%(tist+"\0"),))
      else:
        scopedata= tn.measure()
        sd_ar= string.split(scopedata)
        print "%s measured:"%loctime(sd_ar[0]), scopedata
        if len(sd_ar)<4:
          print "restarting telnet (close + open with next measurement)..."
          tn.close() 
          tn= None
        else:
          pydim.dis_update_service(scopes,("%s"%(scopedata+"\0"),))
    else:
      if tn != None:
        print "not closing telnet..."
        #tn.close() ; tn= None
    #ts= time.strftime("%X")   # hh:mm:ss
    #pydim.dis_update_service(scopes,("%s %s %s"%(ts, AliceClock,BeamMode),))
    sys.stdout.flush()
    time.sleep(10) ; npass= npass+1