Exemplo n.º 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)
Exemplo n.º 2
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")
Exemplo n.º 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)

    # 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)
Exemplo n.º 4
0
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)
Exemplo n.º 5
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)
Exemplo n.º 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)
    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)
Exemplo n.º 7
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)
Exemplo n.º 8
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)
Exemplo n.º 9
0
 def __init__(self, client, format='C'):
   log(INFO,"+++ Starting control object connected to %s"%(client,))
   self.__client = client
   self.__state = ''
   self.__lock = threading.Lock()
   self.__infoID = pydim.dic_info_service(self.__client,format,self.callback)
   self.__callbacks = {}
Exemplo n.º 10
0
    def initialize(self):
        utgid = self.utgid()
        svc = utgid + '/status'
        self.logger().debug("Subscribing to Iterator status service.")
        self.__dim_svc.append(pydim.dic_info_service(svc, "C", self.__callback, pydim.MONITORED, 0, 0, None))

        if type(self.__python) == str:
            p = self.__python
            gaudi = True
        else:
            p = self.__python()
            gaudi = self.__python.gaudi()

        if gaudi:
            python_cmd = ("import GaudiKernel.ProcessJobOptions; " +
                          "from Gaudi.Configuration import importOptions; " +
                          "GaudiKernel.ProcessJobOptions.printing_level=999; ")
            command = ('GaudiOnlineExe.exe libGaudiOnline.so OnlineTask -tasktype=LHCb::Class1Task' +
                       ' -msgsvc=LHCb::FmcMessageSvc -opt=command="{0}"' +
                       ' -main={1}').format(python_cmd + p, self.main_opts())
        else:
            command = 'python -c "{0}"'.format(p)
            
        ## Add this directory to the python path to get our OnlineEnvBase.py
        import inspect
        module = inspect.getfile(type(self))
        pd = os.path.dirname(module)
        env = {'LOGFIFO' : self.log_fifo(), 'PYTHONPATH' : '%s:%s' % (pd, os.environ['PYTHONPATH']),
               'TEMPDIR' : get_tmpdir(), 'PARTITION' : self.partition()}
        self.condition().acquire()
        self.launch(utgid, command, env)
        self.condition().wait()
        self.condition().release()
        self.logger().info("Iterator launched.")
Exemplo n.º 11
0
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) 
Exemplo n.º 12
0
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) 
Exemplo n.º 13
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)
Exemplo n.º 14
0
    def initialize(self):
        for n in range(self.__n_workers):
            utgid = self.utgid(n)
            svc = utgid + '/status'
            self.logger().debug("Subscribing to Alignment worker %d status service." % n)
            self.__dim_svc.append(pydim.dic_info_service(svc, "C", self.__callback, pydim.MONITORED, 0, n, None))

        ## Add this directory to the python path to get our OnlineEnvBase.py
        import inspect
        module = inspect.getfile(type(self))
        pd = os.path.dirname(module)
        env = {'LOGFIFO' : self.log_fifo(), 'PYTHONPATH' : '%s:%s' % (pd, os.environ['PYTHONPATH']),
               'TEMPDIR' : get_tmpdir(), 'PARTITION' : self.partition()}
        
        if type(self.__python) == str:
            gaudi = True
        else:
            gaudi = self.__python.gaudi()
        
        self.condition().acquire()
        for n in range(self.__n_workers):
            utgid = self.utgid(n)
            if type(self.__python) == str:
                if '{0}' in command:
                    p = self.__python.format(n)
                else:
                    p = self.__python
            else:
                p = self.__python(n)
            if gaudi:
                python_cmd = ("import GaudiKernel.ProcessJobOptions; " +
                              "from Gaudi.Configuration import importOptions; " +
                              "GaudiKernel.ProcessJobOptions.printing_level=999;")
                command = ('GaudiOnlineExe.exe libGaudiOnline.so OnlineTask -tasktype=LHCb::Class1Task' +
                           ' -msgsvc=LHCb::FmcMessageSvc -opt=command="{0}" -main={1}')
                command = command.format(python_cmd + ' ' + p, self.main_opts())
            else:
                command = 'python -c "{0}"'.format(p)
            self.launch(utgid, command, env, node = n % self.__n_nodes)

        # Wait for not ready
        self.__wait_all(State.NOT_READY)
        self.condition().release()
Exemplo n.º 15
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..."
Exemplo n.º 16
0
    def run(self):
        dis_start_serving(self.name)
        print self.clients
        for x in self.clients:
            DEBUG("DIMTASK %s : Registering to service %s" %
                  (self.name, DimTask.SRV1NAME + x))
            dic_info_service(DimTask.SRV1NAME + x, DimTask.SRV1FORMAT,
                             self.client_callback1)
            DEBUG("DIMTASK %s : Registering to service %s" %
                  (self.name, DimTask.SRV2NAME + x))
            dic_info_service(DimTask.SRV2NAME + x, DimTask.SRV2FORMAT,
                             self.client_callback2)
            DEBUG("DIMTASK %s : Registering to service %s" %
                  (self.name, DimTask.SRV3NAME + x))
            dic_info_service(DimTask.SRV3NAME + x, DimTask.SRV3FORMAT,
                             self.client_callback3)
        counter = 0
        DEBUG("DIMTASK %s : Starting service update " % self.name)
        while counter < self.updates:
            counter += 1

            SAY("DIMTASK %s : Updating service nr. 1" % self.name)
            values = (counter, counter + 1, 999.0, 999.0, 'BAU', 'B')
            SAY('DIMTASK %s : Updated %d clients' %
                (self.name, dis_update_service(self.svc1, values)))

            SAY("DIMTASK %s : Updating service nr. 2" % self.name)
            values = (counter, )
            SAY('DIMTASK %s : Updated %d clients' \
                %(self.name, dis_update_service(self.svc2, values)))

            SAY("DIMTASK %s : Updating service nr. 3" % self.name)
            values = ('ALABALAP\x00ORTOCALA', )
            SAY('DIMTASK %s : Updated %d clients' \
                %(self.name, dis_update_service(self.svc3, values)))
            sleep(DimTask.DELAY)
        dis_stop_serving()
Exemplo n.º 17
0
 def register(self):
     dic_info_service(self.bmptname, ScStorage.BMP183TFORMAT,self.BMPTHandler)
     dic_info_service(self.bmppname, ScStorage.BMP183PFORMAT,self.BMPPHandler)
     for x in self.wienernames:
         dic_info_service(x,ScStorage.WIENERFORMAT,self.wienerHandler)
     self.registered=True
Exemplo n.º 18
0
	def start(self):
                self.FirstSOB = True 
                self.FirstEOB = True 
		self.SOB = pydim.dic_info_service(self.serverName + "/SOB", "L:1", self.sob_callback)
		self.EOB = pydim.dic_info_service(self.serverName + "/EOB", "L:1", self.eob_callback)
Exemplo n.º 19
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)
Exemplo n.º 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)
  # 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()
Exemplo n.º 21
0
def test_dic_interface():
    pydim.dic_info_service('SERVICE_NO_FUNC', 'C:1;F:1;C:20',
                           dic_command_callback)
    while not __dic_service_refreshed:
        sleep(1)
Exemplo n.º 22
0
 def __init__(self, name, format='C'):
   self.lastData = None
   self.__lock = threading.Lock()
   self.__runs = {}
   self.__infoID = pydim.dic_info_service(name,format,self.callback)
Exemplo n.º 23
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()
Exemplo n.º 24
0
def subscribe_to_service(service_name, state_name, signal_update_delegate):
    print("Subscribing to service: {0}".format(service_name))
    callback = get_service_callback(state_name, signal_update_delegate)
    pydim.dic_info_service(service_name, callback)
Exemplo n.º 25
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()
  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