#!/usr/bin/env python # # $Id: start_hdview2 16249 2014-11-02 11:48:52Z davidl $ # $HeadURL: https://halldsvn.jlab.org/repos/trunk/online/packages/monitoring/src/scripts/start_hdview2 $ # # # Script to start epics2et # # Usage: # run_epics2et [SOURCE] # import sys import os import subprocess import glob # In case PYTHONPATH not set DAQ_HOME = os.getenv('DAQ_HOME') if DAQ_HOME!=None: sys.path.append('%s/tools/pymods' % DAQ_HOME) import coolutils # ----- Global parameters ----- user_args = [] source = None what = 'Starting' ETpeb_conn = '' ETseb_conn = '' ETer_conn = '' TEST_MODE = False #------------------------------ #----------------------- # Usage #----------------------- def Usage(): print '' print ' Script to start epics2et in the online environment' print '' print ' Usage:' print ' run_epics2et [ETsystem]' print '' print '' print ' -h,--help help (prints this usage statement)' print ' -e Exit (kill any existing program)' print ' -t Test mode (don\'t actually start program)' print ' ' print '' print ' If no arguments are given, then the script will exam the current COOL' print ' configuration to figure out the parameters needed to connect to the' print ' ET system for the current run.' print ' If an argument is given, it is passed to epics2et as the even source.' print ' For example:' print ' run_epics2et ET:/tmp/et_sys_hdops::gluonraid1' print '' sys.exit(0) #----------------------- # MapHostName #----------------------- def MapHostName(node): # This is here for the reason described in the original comment below. # This was actually copied from the start_monitoring script where it # makes sense to use the infiniband interface. However, hdview2 may be # run on gluon0X machines with no infiniband so it we *don't* want to # make the substitution. I'm leaving it here in case there is a need at # some point in the future to make some other type of host name mapping. # 11/2/2014 DL # # The COOL configuration will probably list the host as something like # "gluonraid1". However, we want the monitoring processes to connect # via the infiniband interface which is dnsname "gluonraid1-ib". This # function allows us to substitute host names for ones found in the COOL # configuration. #if node == 'gluonraid1' : return 'gluonraid1-ib' return node #----------------------- # ReadCOOLconfiguration #----------------------- def ReadCOOLconfiguration(): global ETpeb_conn, ETseb_conn, ETer_conn # If the user didn't specify the source AND we are starting the monitoring # programs up, then we need to figure it out from the COOL configuration # Require env. vars. be set if coolutils.COOL_HOME==None: print "You must set your COOL_HOME environment variable!" sys.exit(-1) if coolutils.EXPID==None: print "You must set your EXPID environment variable!" sys.exit(-1) if coolutils.CONFIG==None: print "You must set your CODA_CONFIG environment variable!" sys.exit(-1) print 'Reading COOL configuration from:' print ' %s' % coolutils.COOL_HOME print '' # Check that configuration was able to be read in if not coolutils.configDataValid: print 'Unable to read COOL configuration.' print 'make sure COOL_HOME, EXPID' print 'environment variables are set properly.' print 'You may also need to set CODA_CONFIG if' print 'the configuration can\t be extracted from' print 'COOL_HOME.' sys.exit(-1) #----------------------------------------------- # ET system created by PEB if len(coolutils.pebs) > 0: PEB = coolutils.pebs[0] ETpeb = coolutils.GetETInfo(PEB) ETpeb['host'] = MapHostName(ETpeb['host']) ETpeb_conn = 'ET:%s:MON:%s:%s' % (ETpeb['etName'], ETpeb['host'], ETpeb['port']) # ET system created by SEB if len(coolutils.sebs) > 0: SEB = coolutils.sebs[0] ETseb = coolutils.GetETInfo(SEB) if ETseb != None: if 'host' in ETseb and 'etName' in ETseb and 'port' in ETseb: ETseb['host'] = MapHostName(ETseb['host']) ETseb_conn = 'ET:%s:MON:%s:%s' % (ETseb['etName'], ETseb['host'], ETseb['port']) # ET system created by ER if len(coolutils.ers) > 0: ER = coolutils.ers[0] ETer = coolutils.GetETInfo(ER) if ETer != None: ETer['host'] = MapHostName(ETer['host']) ETer_conn = 'ET:%s:MON:%s:%s' % (ETer['etName'], ETer['host'], ETer['port']) print ' EXPID = %s' % coolutils.EXPID print ' SESSION = %s' % coolutils.SESSION print ' CONFIG = %s' % coolutils.CONFIG print '' print ' ET systems:' if len(ETpeb_conn)>0 : print ' PEB [%s]' % ETpeb_conn if len(ETseb_conn)>0 : print ' SEB [%s]' % ETseb_conn if len(ETer_conn )>0 : print ' ER [%s]' % ETer_conn print '' #----------------------- # ParseCommandLineArguments #----------------------- def ParseCommandLineArguments(): global what, source, user_specified_nodes, mon_levels, TEST_MODE, VERBOSE # Parse the command line arguments leaving results in global parameters levels = [] for arg in sys.argv[1:]: if arg == '-h' : Usage() elif arg == '--help' : Usage() elif arg == '-e' : what = 'Stopping' elif arg == '-t' : TEST_MODE = True elif not arg.startswith('-' ) : user_args.append(arg) else: print 'Unknown option "' + arg + '"!' sys.exit(-1) # Read in COOL configuration if needed if len(user_args)==0 : ReadCOOLconfiguration() # Make final decision on source that will be used # (it's possible source could still be left unset i.e. None) if len(ETer_conn)> 0 : source = ETer_conn elif len(ETpeb_conn)> 0 : source = ETpeb_conn elif len(ETseb_conn)> 0 : source = ETseb_conn #----------------------------------------------- # :::::::::: Main script starts here :::::::::: print '' print '----------------- Starting epics2et -------------' # Parse command line and read in configurations from various files ParseCommandLineArguments() cmd = ['epics2et'] if what=='Starting': if source != None: cmd.extend(['-et', source]) if len(user_args)>0 : cmd.extend(user_args) cmd = ['hdlog', '-c', '-s', '10240'] + cmd else: cmd = ['pkill'] + cmd #print cmd for arg in cmd: sys.stdout.write(arg+' ') print '\n' if TEST_MODE : print 'TEST MODE: No commands were actually run' else: subprocess.Popen(cmd)