#!/usr/bin/env python # # $Id$ # $HeadURL$ # # # Script to start hdview2 # # Usage: # start_hdview2 [SOURCE] # import sys import os import subprocess import glob # Check that we are running on a GENERAL type machine GLUON_TYPE = os.getenv('GLUON_TYPE', 'unknown') if GLUON_TYPE != 'GENERAL': print 'This needs to be run from a computer with an IB network' print 'connection. Try running from gluon48. Alternatively, you' print 'can run the start_hdview2.sh wrapper script that will' print 'ssh to an appropriate computer and run start_hdview2 for' print 'you.' sys.exit(0) # 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 = '' ETsecondary = '' ET_FILENAME = '/tmp/et_sys_monitoring' ET_PORT = 11122 #------------------------------ #----------------------- # Usage #----------------------- def Usage(): print '' print ' Script to start hdview2 in the online environment' print '' print ' Usage:' print ' start_hdview2 [ETsystem]' print '' print '' print ' -h,--help help (prints this usage statement)' 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 hdview2 as the even source.' print ' For example:' print ' start_hdview2 ET:/tmp/et_sys_hdops:MON: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) if ETpeb != None: 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: 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 '' #----------------------- # ReadNodesConfiguration #----------------------- def ReadNodesConfiguration(): global ETsecondary, ET_FILENAME # If user did not specify which nodes to run on, get them from config. file fname = '%s/config/monitoring/nodes.conf' % DAQ_HOME if os.path.exists(fname): print 'Reading monitoring node assignments from:' print ' %s' % fname print '' file = open(fname, 'r') for line in file: vals = line.split() if line.find('#') == 0 : continue # skip comment lines if len(vals)==0 : continue # skip empty lines # ---- ET if vals[0]=='ET' : if len(vals)>=2 : host_file = vals[1].split(':') host = host_file[0] if len(host_file)>1 : ET_FILENAME = host_file[1] ETsecondary = 'ET:%s:MON_hdview:%s:%d' % (ET_FILENAME, host, ET_PORT) #----------------------- # 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 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() # Read in nodes file if needed if len(user_args)==0 : ReadNodesConfiguration() # Make final decision on source that will be used # (it's possible source could still be left unset i.e. None) if len(ETsecondary)> 0 : source = ETsecondary elif len(ETer_conn )> 0 : source = ETer_conn elif len(ETpeb_conn )> 0 : source = ETpeb_conn elif len(ETseb_conn )> 0 : source = ETseb_conn print 'ETsecondary: ' + ETsecondary print ' ETer_conn: ' + ETer_conn print ' ETpeb_conn: ' + ETpeb_conn print ' ETseb_conn: ' + ETseb_conn print ' source: ' + source #----------------------------------------------- # :::::::::: Main script starts here :::::::::: print '' print '----------------- Starting hdview2 -------------' # Parse command line and read in configurations from various files ParseCommandLineArguments() # We need to ensure the gcc 4.9.2 libraries are in LD_LIBRARY_PATH # This should be the case for the "GENERAL" computers (gluonXX where # XX>=40) For the "CONTROLS" computers it must be added. Therefore # we must explicitly set the run time environment modified_env = os.environ.copy() LD_LIBRARY_PATH = os.getenv('LD_LIBRARY_PATH','.') if '/apps/gcc/4.9.2/lib64' not in LD_LIBRARY_PATH: print 'Adding /apps/gcc/4.9.2/lib64 to LD_LIBRARY_PATH' modified_env['LD_LIBRARY_PATH']=LD_LIBRARY_PATH + ':' + '/apps/gcc/4.9.2/lib64' cmd = ['hdview2'] if source != None: cmd.append(source) if len(user_args)>0 : cmd.extend(user_args) #print cmd for arg in cmd: sys.stdout.write(arg+' ') print '\n' print '(this may take several seconds for the window to open)\n' try: subprocess.Popen(cmd, env=modified_env) except Exception as e: print('Exception caught when trying to run external proccess: ' + cmd) print(e)