Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:22:27

0001 from __future__ import print_function
0002 # select CALOL2_KEY from CMS_TRG_L1_CONF.L1_TRG_CONF_KEYS where ID='collisions2016_TSC/v206' ;
0003 import re
0004 import os, sys, shutil
0005 import subprocess
0006 """
0007 A simple helper script that provided with no arguments dumps a list of
0008 top-level keys, and provided with any key from this list as an argument,
0009 dumps a list of sub-keys and saves corresponding configuration to local
0010 files.
0011 """
0012 
0013 # connection string
0014 sqlplusCmd = ['env',
0015               'sqlplus',
0016               '-S',
0017               'cms_trg_r/@cms_omds_adg'
0018              ]
0019 
0020 if hash( sqlplusCmd[-1] ) != 1687624727082866629:
0021     print('Do not forget to plug password to this script')
0022     print('Exiting.')
0023     exit(0)
0024 
0025 myre = re.compile(r'(ID)|(-{80})')
0026 
0027 # if no arguments are given, query the top level keys only and exit
0028 if len(sys.argv) == 1:
0029     sqlplus = subprocess.Popen(sqlplusCmd, shell=False, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
0030     print('No args specified, querying and printing only top-level keys:')
0031     for line in re.split('\n',sqlplus.communicate('select unique ID from CMS_TRG_L1_CONF.CALOL2_KEYS;')[0]):
0032         if myre.search(line) == None :
0033             print(line)
0034     print('Pick any of these keys as an argument next time you run this script')
0035     exit(0)
0036 
0037 # if an argument is given query the whole content of the key
0038 key = sys.argv[1]
0039 
0040 sqlplus = subprocess.Popen(sqlplusCmd,
0041                            shell=False,
0042                            stdout=subprocess.PIPE,
0043                            stdin=subprocess.PIPE
0044                           )
0045 
0046 queryKey = "select CALOL2_KEY from CMS_TRG_L1_CONF.L1_TRG_CONF_KEYS where ID='{0}'".format(key)
0047 
0048 for line in re.split('\n',sqlplus.communicate(queryKey+';')[0]):
0049     print(line)
0050     if re.search('/v',line) :
0051         key=line
0052 
0053 print(key)
0054 
0055 queryKeys = """
0056             select
0057                 HW, ALGO
0058             from
0059                 CMS_TRG_L1_CONF.CALOL2_KEYS
0060             where
0061                 ID = '{0}'
0062             """.format(key)
0063 
0064 queryAlgoKeys = """
0065                 select
0066                     ALGO_KEYS.{0} as {0}_KEY
0067                 from
0068                     CMS_TRG_L1_CONF.CALOL2_ALGO_KEYS ALGO_KEYS, ({1}) KEYS
0069                 where
0070                     ALGO_KEYS.ID = KEYS.ALGO
0071                 """
0072 
0073 # write results for specific configs to the following files
0074 batch = {
0075          'DEMUX'      : 'demux.xml',
0076          'MPS_COMMON' : 'mps_common.xml',
0077          'MPS_JET'    : 'mps_jet.xml',
0078          'MP_EGAMMA'  : 'mp_egamma.xml',
0079          'MP_SUM'     : 'mp_sum.xml',
0080          'MP_TAU'     : 'mp_tau.xml'
0081         }
0082 
0083 # do the main job here
0084 for config,fileName in batch.items():
0085     sqlplus = subprocess.Popen(sqlplusCmd, shell=False, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
0086 
0087     query = queryAlgoKeys.format(config,queryKeys)
0088     for line in re.split('\n',sqlplus.communicate(query+';')[0]):
0089         if myre.search(line) == None :
0090             print(line)
0091  
0092     sqlplus = subprocess.Popen(sqlplusCmd, shell=False, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
0093     with open(fileName,'w') as f:
0094         query = """
0095                 select
0096                     ALGO.CONF
0097                 from
0098                     CMS_TRG_L1_CONF.CALOL2_CLOBS ALGO, ({0}) KEY
0099                 where
0100                     ALGO.ID = KEY.{1}_KEY
0101                 """.format(queryAlgoKeys.format(config,queryKeys), config)
0102 
0103         for line in re.split('\n',sqlplus.communicate('\n'.join(['set linesize 200', 'set longchunksize 200000 long 200000 pages 0',query+';']))[0]):
0104             f.write('\n')
0105             f.write(line)
0106         f.close()
0107 
0108 sqlplus = subprocess.Popen(sqlplusCmd, shell=False, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
0109 print('Following keys were found:')
0110 for line in re.split('\n',sqlplus.communicate(queryKeys+';')[0]):
0111     print(line)
0112 
0113 
0114 print('Results are saved in ' + ' '.join(batch.values()) + ' files')
0115