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