Example #1
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 #2
0
 def __send_command(self, utgid, command, wait = True):
     if hasattr(pydim, "version") and float(pydim.version()) >= 0.4:
         command = (command,)
     else:
         command = (command + '\0',)
     if wait:
         self.condition().acquire()
         pydim.dic_cmnd_service(utgid, command, "C")
         self.condition().wait()
         self.condition().release()
     else:
         pydim.dic_cmnd_service(utgid, command, "C")
Example #3
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)
def command2():
    n = random.choice(range(5))
    text = random.choice(["hola", "hi", "bonjour"])

    args = (n, text)
    print "Calling command 2. Arguments: %s, %s" % args
    res = pydim.dic_cmnd_service("example-command-2", args, "I:1;C")
Example #5
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_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")
Example #6
0
def callback_bm(bm):
  #print "callback_bm: '%s' (%s)" % (bm, type(bm))
  #print "callback_bm: '%s' (%s)" % (p2, type(p2))
  #WEB.miclock= rmzero(now) ; WEB.save()
  if bm2clock.has_key(bm):
    i01= bm2clock[bm][0]
    if i01==0:
      expclock= "LOCAL"
    else:
      expclock= "BEAM1"
    bmname= bm2clock[bm][1]
  else:
    expclock= "?" ; bmname="???"
  WEB.lastbmname= bmname
  lt= time.localtime(); ltim= "%2d.%2d. %2d:%2d"%(lt[2], lt[1], lt[3], lt[4])
  if WEB.miclock==expclock:
    print "%s BEAM MODE:%s clock %s OK"%(ltim, bmname, expclock) 
  else:
    print "%s BEAM MODE:%s clock %s not correct. miclock mode:%s"%\
      (ltim, bmname, WEB.miclock,WEB.clockchangemode) 
    #print "%s bad clock:%s for beam mode:%s(%d) clock_change_mode:%s"%\
    #  (ltim, WEB.miclock, bmname,bm, WEB.clockchangemode)
    if WEB.clockchangemode=='auto':
      # change clock
      print "changing clock to %s. Wait 3 minutes please..."%(expclock)
      res= pydim.dic_cmnd_service("TTCMI/MICLOCK_SET", (expclock,), "C")
Example #7
0
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)
def command1():

    f = random.choice([math.pi, math.e, 42])

    #The argument must be a tuple
    args = (f, )
    print "Calling command 1. Arguments: %s" % args
    res = pydim.dic_cmnd_service("example-command-1", args, "F")
Example #9
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
Example #10
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_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)
Example #11
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()
  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..."
Example #12
0
DEBUG=6    
def stress_callback( *args):
    global i
    if i % 10000 == 0:        
       print "stress_callback: %d" % i
    i += 1

def service_callback(tag):
    global i
    if i % 10000 == 0:
        print "stress service updated: %d" % i
    return (i,)    
      
if __name__=='__main__':
    import sys
    n = 500000
    if len(sys.argv) > 1: n = int(sys.argv[1])
    si = dic_info_service("STRESS_SVC", "I", stress_callback)
    s = dis_add_service("PYSTRESS_SVC", "I", service_callback, 0)
    dis_start_serving("PYSTRESS") 
    while i < n or n == 0:
        res = dic_cmnd_service('STRESS_CMD', ('STRESSYOU!\0',), "C")
        dis_update_service(s)
        sleep(0.001)
    print "Stopping stress serving"
    dis_stop_serving()
    print "Stopping subscription"
    dic_release_service(si)
    print "Waiting for cleanup"
    sleep(5)
Example #13
0
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()
Example #14
0
  pydim.dis_start_serving()
  

if __name__ == '__main__':
  # Server configuration:
  server_create_command_services()
  
  # The client command execution
  counter = 0  
  while  counter<1000 or True:    
    counter += 1
    # executing the first command
    print ""
    tuple_args = ('Test call no. %03d' %counter, )
    res = pydim.dic_cmnd_service('test1', tuple_args, CMND1FORMAT)
    if res:   
      SAY('Client: Successfully executed command test1 (return code %d)' %res)
    else:
      SAY('Client: Command test1 execution failed (return code %d)' %res)
    sleep(COMMAND_DELAY)
  
    # second command
    print ""
    tuple_args = (counter, counter+1, counter*9, counter*1.9, counter, counter-1, 'ABRACADABRA')
    res = pydim.dic_cmnd_service('test2', tuple_args, CMND2FORMAT)
    if res:   
      SAY('Client: Successfully executed command test2 (return code %d)' %res)
    else:
      SAY('Client: Command test2 execution failed (return code %d)' %res)
    sleep(COMMAND_DELAY)
def reset():
    pydim.dic_cmnd_service(utgid, ('reset\0', ), "C")
Example #16
0
def main():
  arg=("none",)
  res= pydim.dic_cmnd_service("TTCMI/DLL_RESYNC", arg, "C")
  mylog.logm("dll_resync")
Example #17
0
 def setPeriod(self,t):
     tuple_args=(t,)
     dic_cmnd_service("/WIENER/SetPeriod",tuple_args,"I:1")
     dic_cmnd_service("/BMP183/%s/SETPERIOD" % self.bmphost,tuple_args,"I:1")
Example #18
0
def callback_bm(ecsbm):
  #print "callback_bm: '%s' (%s)" % (p2, type(p2))
  #WEB.miclock= rmzero(now) ; WEB.save()
  bmname= rmzero(ecsbm)
  #print "callback_bm: '%s' (%s)" % (bmname, type(bmname))
  bm= bm2clocknames[bmname]
  if bm2clock.has_key(bm):
    i01= bm2clock[bm][0]
    if i01==0:
      expclock= "LOCAL"
    else:
      expclock= "BEAM1"
    bmname= bm2clock[bm][1]
  else:
    expclock= "?" ; bmname="???"
  if bmname == WEB.lastbmname:
    #mylog.logm("No change in BM, no action")
    return
  prev_bmname= WEB.lastbmname
  WEB.lastbmname= bmname
  arg= ("%d %s"%(bm, bmname),)
  res= pydim.dic_cmnd_service("CTPRCFG/SETBM", arg, "C")
  mylog.logm("callback_bm:" + arg[0] + " " + str(res))
  ## 
  #mylog.logm("callback_bm: "+bmname)
  #if (prev_bmname=="RAMP") or (bmname=="FLAT TOP"):
  if (bmname=="PREPARE RAMP") or (bmname=="RAMP"):
    sys.path.append(os.path.join(os.environ['VMECFDIR'],"filling"))
    if os.environ['VMESITE'] != "ALICE":
      mylog.logm("lab env, 'getfsdip.py act' call skipped")
    else:
      import getfsdip
      reload(getfsdip)
      mylog.logm("getfsdip.py act...")
      getfsdip.main("act")
  if WEB.miclock==expclock:
    if bmname=="FLAT TOP":
      mylog.infolog("FLAT TOP: waiting 50secs before reading current clock shift...",level='w')
      time.sleep(50)   # give BPM 50 secs at least to measure the shift
      cshift= getShift()
    #if bmname=="SQUEEZE":  # used before 26.05.2017
    #if bmname=="ADJUST":   # from 7.11.-17.11. 2016 15:45 we used ADJUST
      if cshift!='old':
        if False:
          mylog.infolog("FLAT TOP: clock shift correction disabled",level='w')
        else:
          mylog.infolog("FLAT TOP: clock shift %s, applying correction ..."%cshift,level='w')
          checkandsave(cshift, bmname)   # fine shift
          #cst= threading.Timer(60.0, checkandsave,(cshift, bmname))   # from 29.5.2017
          #cst.start()
          # it should certainly be less then 100ps after adjustment:
          #t= threading.Timer(90.0, checkShift, (30,))   # 90= 60+30
          t= threading.Timer(30.0, checkShift, (30,))
          t.start()
      else:   # normally done in checkandsave
        mylog.infolog("FLAT TOP: clock shift %s, applying DLL_RESYNC instead of clock adjustment ..."%cshift,level='w')
        arg=("none",)
        res= pydim.dic_cmnd_service("TTCMI/DLL_RESYNC", arg, "C")
        #mylog.logm("DLL_RESYNC not started...")   # CJI
    if bmname=="RAMP_NOSCOPE":   # never do this (no scope)
      if os.environ['VMESITE']=='ALICE':
        import sctel
        reload(sctel)
        mininf= "INF"
        tn= sctel.TN()
        tn.setPersitence(mininf)
        tn.close()
        mylog.logm("alidcsaux008 scope persitence: "+mininf)
  else:
    #if (bm==13) or (bm==4): # BEAM DUMP/INJECTION SETUP BEAM adjust clock
    #if expclock != "LOCAL":
    #  checkandsave(cshift)   # not called from 29.6.
    #mylog.logm( "BEAM MODE:%s, clock %s not correct. miclock mode:%s shift:%s"%\
    #  (bmname, WEB.miclock,WEB.clockchangemode, cshift) )
    #print "%s bad clock:%s for beam mode:%s(%d) clock_change_mode:%s"%\
    #  (ltim, WEB.miclock, bmname,bm, WEB.clockchangemode)
    if (bm>=5) or (bm<=12):
      if WEB.clockchangemode=="AUTO":
        wf='f'
      else:
        wf='w'
      mylog.infolog( "BEAM MODE:%s, clock %s not correct. ALICE/LHC/TTCMI/CLOCK_MODE:%s"%\
      (bmname, WEB.miclock,WEB.clockchangemode), level='w')
    if WEB.clockchangemode=='AUTO_NEVERCHANGE':  # it is on lhcint now to change th clock
      # change clock
      mylog.logm("changing clock to %s. Wait 3 half-minutes please..."%(expclock))
      WEB.newclock= expclock; WEB.save()
      res= pydim.dic_cmnd_service("TTCMI/MICLOCK_SET", (expclock,), "C")
      mylog.logm("cmnd sent: TTCMI/MICLOCK_SET")
      mininf=""
      if expclock=="LOCAL":
        mininf= "MIN"
      else:
        if bmname=="RAMP":
           mininf= "INF"
      #if mininf!="":
      if mininf=="NOSCOPE":   # never do tis (no scope)
        if os.environ['VMESITE']=='ALICE':
          import sctel
          reload(sctel)
          tn= sctel.TN()
          mylog.logm("setting scope persitence: "+mininf)
          tn.setPersitence(mininf)
          tn.close()
          #mylog.logm("alidcsaux008 scope persitence: "+mininf)
      ##mylog.logm("NOT CHANGED ##")
  mylog.flush()
def start():
    pydim.dic_cmnd_service(utgid, ('start\0', ), "C")
Example #20
0
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()
Example #21
0
def checkandsave(csf_string, fineshift="None", force=None):
  """csf_string: clock shift (float string:  e.g.: '0.923819' )
  fineshift: 
  "None"   change $dbctp/clockshift (if change is different from the last one!)
  != 'None' apply also CORDE modification
  force:
  None (default) -apply change only when outside of MIN,MAX interval
  !=None         -apply any change (still the check for difference is done)
          force option is used from ttcmidaemons/apply_any_shift.py 
          to change corde shift in $dbctp/clockshift

  Operation:
  If clock shift too big and last applied change was different: 
     modify $dbctp/clockshift file
  If we arrange this function to be called in time of clock change,
  the registers on CORDE board will be changed 3min later -when clock
  is changed
  29.6.: logic changed:
  - checkandsave(csf_string, beammode) is called only once: at SQUEEZE
    (i.e. ALWAYS fine shift done (if change too big)
  - no action in time of the clock change (BEAM1/LOCAL)
  - check if 'changed' removed (see: 'if False'...)
  """
  csps= int(eval(csf_string)*1000)   #ns-> ps
  csps_applied_new= int(eval(csf_string)*10000)   #ns-> 0.1ps
  #if ((csps < -250) or (csps > 250)) or (force != None):
  if ((csps < -10) or (csps > 10)) or (force != None):
    if ((csps < -1500) or (csps > 1500)) and (force == None):
      mylog.logm("csps:%dps too big (max 1500(now 1500) ps allowed). No action."%csps)
    else:
      fn= os.path.join(os.environ['dbctp'],"clockshift")
      f= open(fn,"r")
      (ttcmi_hns, corde_10ps_str, last_applied)= f.readline().split()     
      corde_10ps= int(corde_10ps_str)
      f.close()
      mylog.logm("csps:%d _applied_new:%d"%(csps, csps_applied_new))
      if last_applied:
        if False:   #do not check change! #eval(last_applied)==csps_applied_new:
          mylog.logm("db (%s %d %s) not changed, already applied. "%\
            (ttcmi_hns, corde_10ps, last_applied))
        else:
          newcorde= corde_10ps - csps/10
          #f= open(fn,"w")   -written in .c (CORDE_SET)
          #line= "%s %d %s"%(ttcmi_hns,newcorde, csps_applied_new); f.write(line)
          #f.close()
          if fineshift != "None":
            f= open(fn,"r"); line= f.readline(); f.close()
            mylog.logm("Clock shift in db before SET: %s"%line)
            corde_shift= "%d"%(-csps/10)
            arg= (corde_shift,)
            res= pydim.dic_cmnd_service("TTCMI/CORDE_SET", arg, "C")
            mylog.logm("dim TTCMI/CORDE_SET "+corde_shift, 1)
            #time.sleep(1)
      else:
          mylog.logm("bad $dbctp/clockshift 3rd number (last_applied) missing(%s %d)."%\
            (ttcmi_hns, corde_10ps))
  else:
    mylog.logm("Measured clock shift: %dps left unchaged (%s) "%(csps,str(fineshift)))
  # always apply DLL_RESYNC:
  if force != None:
    mylog.logm("DLL_RESYNC not done (force option).")
  else:
    arg=("none",)
    res= pydim.dic_cmnd_service("TTCMI/DLL_RESYNC", arg, "C")
Example #22
0
 def setVoltage(self,chan,vset):
     tuple_args=(chan,vset)
     dic_cmnd_service("/WIENER/SetVoltage",tuple_args,"I:1;F:1")
Example #23
0
 def ReadChannel(self,t):
     tuple_args=(t,)
     dic_cmnd_service("/WIENER/ReadChannel",tuple_args,"I:1")
def stop():
    pydim.dic_cmnd_service(utgid, ('stop\0', ), "C")
Example #25
0
 def setCurrentLimit(self,chan,iset):
     tuple_args=(chan,iset*1E-6)
     dic_cmnd_service("/WIENER/SetCurrent",tuple_args,"I:1;F:1")
Example #26
0
 def updatedims(self, msg):
   pydim.dic_cmnd_service("CTPRCFG/RCFG", ("grunsup "+msg+"\x00",),"C")
Example #27
0
def callback_bm(ecsbm):
  #print "callback_bm: '%s' (%s)" % (p2, type(p2))
  #WEB.miclock= rmzero(now) ; WEB.save()
  bmname= rmzero(ecsbm)
  #print "callback_bm: '%s' (%s)" % (bmname, type(bmname))
  bm= bm2clocknames[bmname]
  if bm2clock.has_key(bm):
    i01= bm2clock[bm][0]
    if i01==0:
      expclock= "LOCAL"
    else:
      expclock= "BEAM1"
    bmname= bm2clock[bm][1]
  else:
    expclock= "?" ; bmname="???"
  if bmname == WEB.lastbmname:
    #mylog.logm("No change in BM, no action")
    return
  prev_bmname= WEB.lastbmname
  WEB.lastbmname= bmname
  arg= ("%d %s"%(bm, bmname),)
  res= pydim.dic_cmnd_service("CTPRCFG/SETBM", arg, "C")
  mylog.logm("callback_bm:" + arg[0] + " " + str(res))
  ## 
  #mylog.logm("callback_bm: "+bmname)
  #if (prev_bmname=="RAMP") or (bmname=="FLAT TOP"):
  if (bmname=="PREPARE RAMP") or (bmname=="RAMP"):
    sys.path.append(os.path.join(os.environ['VMECFDIR'],"filling"))
    import getfsdip
    reload(getfsdip)
    mylog.logm("getfsdip.py act...")
    getfsdip.main("act")
  cshift= getShift()
  if WEB.miclock==expclock:
    if bmname=="SQUEEZE":
      if cshift!='old':
        checkandsave(cshift, bmname)   # fine shift
        # it should certainly be less then 100ps after adjustment:
        t= threading.Timer(10.0, checkShift)
        t.start()
      else:
        arg=("none",)
        res= pydim.dic_cmnd_service("TTCMI/DLL_RESYNC", arg, "C")
        #mylog.logm("DLL_RESYNC after clock shift NOT started...")   # CJI
    mylog.logm("BEAM MODE:%s, clock: %s OK, shift:%s"%(bmname, expclock, cshift))
    if bmname=="RAMP_NOSCOPE":   # never do this (no scope)
      if os.environ['VMESITE']=='ALICE':
        import sctel
        reload(sctel)
        mininf= "INF"
        tn= sctel.TN()
        tn.setPersitence(mininf)
        tn.close()
        mylog.logm("alidcsaux008 scope persitence: "+mininf)
  else:
    #if (bm==13) or (bm==4): # BEAM DUMP/INJECTION SETUP BEAM adjust clock
    #if expclock != "LOCAL":
    #  checkandsave(cshift)   # not called from 29.6.
    #mylog.logm( "BEAM MODE:%s, clock %s not correct. miclock mode:%s shift:%s"%\
    #  (bmname, WEB.miclock,WEB.clockchangemode, cshift) )
    #print "%s bad clock:%s for beam mode:%s(%d) clock_change_mode:%s"%\
    #  (ltim, WEB.miclock, bmname,bm, WEB.clockchangemode)
    if (bm>=5) or (bm<=12):
      if WEB.clockchangemode=="AUTO":
        wf='f'
      else:
        wf='w'
      mylog.infolog( "BEAM MODE:%s, clock %s not correct. miclock mode:%s"%\
      (bmname, WEB.miclock,WEB.clockchangemode), level=wf )
    if WEB.clockchangemode=='AUTO_NEVERCHANGE':  # it is on lhcint now to change th clock
      # change clock
      mylog.logm("changing clock to %s. Wait 3 half-minutes please..."%(expclock))
      WEB.newclock= expclock; WEB.save()
      res= pydim.dic_cmnd_service("TTCMI/MICLOCK_SET", (expclock,), "C")
      mylog.logm("cmnd sent: TTCMI/MICLOCK_SET")
      mininf=""
      if expclock=="LOCAL":
        mininf= "MIN"
      else:
        if bmname=="RAMP":
           mininf= "INF"
      #if mininf!="":
      if mininf=="NOSCOPE":   # never do tis (no scope)
        if os.environ['VMESITE']=='ALICE':
          import sctel
          reload(sctel)
          tn= sctel.TN()
          mylog.logm("setting scope persitence: "+mininf)
          tn.setPersitence(mininf)
          tn.close()
          #mylog.logm("alidcsaux008 scope persitence: "+mininf)
      ##mylog.logm("NOT CHANGED ##")
  mylog.flush()
Example #28
0
 def HVOff(self,chan):
     tuple_args=(chan,0)
     dic_cmnd_service("/WIENER/Switch",tuple_args,"I:2")
Example #29
0
def ConfigureFero(tag):
    pydim.dic_cmnd_service("ConfigureFero", ("trd-fee_00_2_0", tag))
def config():
    pydim.dic_cmnd_service(utgid, ('configure\0', ), "C")