Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-23 02:25:50

0001 from __future__ import print_function
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 # connection string
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 # if no arguments are given, query the top level keys only and exit
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.EMTF_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 # if an argument is given query the whole content of the key
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 # if the argument is the very top level key, querry the OMTF specific subkey
0046 queryKey = "select OMTF_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, INFRA
0058             from
0059                 CMS_TRG_L1_CONF.OMTF_KEYS
0060             where
0061                 ID = '{0}'
0062             """.format(key)
0063 
0064 # write results for specific configs to the following files
0065 batch = {
0066          'HW'     : 'hw.xml',
0067          'ALGO'   : 'algo.xml',
0068          'INFRA'  : 'infra.xml'
0069         }
0070 
0071 # do the main job here
0072 for config,fileName in batch.items():
0073 
0074     sqlplus = subprocess.Popen(sqlplusCmd, shell=False, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
0075     with open(fileName,'w') as f:
0076         query = """
0077                 select
0078                     CLOBS.CONF
0079                 from
0080                     CMS_TRG_L1_CONF.OMTF_CLOBS CLOBS, ({0}) KEY
0081                 where
0082                     CLOBS.ID = KEY.{1}
0083                 """.format(queryKeys, config)
0084 
0085         for line in re.split('\n',sqlplus.communicate('\n'.join(['set linesize 200', 'set longchunksize 200000 long 200000 pages 0',query+';']))[0]):
0086             f.write('\n')
0087             f.write(line)
0088         f.close()
0089 
0090 sqlplus = subprocess.Popen(sqlplusCmd, shell=False, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
0091 print('Following keys were found:')
0092 for line in re.split('\n',sqlplus.communicate(queryKeys+';')[0]):
0093     print(line)
0094 
0095 
0096 print('Results are saved in ' + ' '.join(batch.values()) + ' files')
0097