File indexing completed on 2023-03-17 10:48:51
0001 import os
0002 import sys
0003 import calendar
0004 import optparse
0005 import importlib
0006 import sqlalchemy
0007 import subprocess
0008 import CondCore.Utilities.conddblib as conddb
0009
0010
0011 def execme(command, dryrun=False):
0012
0013 """This function executes `command` and returns it output.
0014 Arguments:
0015 - `command`: Shell command to be invoked by this function.
0016 """
0017 if dryrun:
0018 print(command)
0019 return None
0020 else:
0021 child = os.popen(command)
0022 data = child.read()
0023 err = child.close()
0024 if err:
0025 raise Exception('%s failed w/ exit code %d' % (command, err))
0026 return data
0027
0028
0029 def main():
0030
0031
0032 defaultGT='auto:run3_data_prompt'
0033
0034 defaultRun=346512
0035
0036 parser = optparse.OptionParser(usage = 'Usage: %prog [options] <file> [<file> ...]\n')
0037
0038 parser.add_option('-G', '--inputGT',
0039 dest = 'inputGT',
0040 default = defaultGT,
0041 help = 'Global Tag to get conditions',
0042 )
0043
0044 parser.add_option('-r', '--inputRun',
0045 dest = 'inputRun',
0046 default = defaultRun,
0047 help = 'run to be used',
0048 )
0049
0050 (options, arguments) = parser.parse_args()
0051
0052 print("Input configuration")
0053 print("globalTag: ",options.inputGT)
0054 print("runNumber: ",options.inputRun)
0055
0056 con = conddb.connect(url = conddb.make_url())
0057 session = con.session()
0058 RunInfo = session.get_dbtype(conddb.RunInfo)
0059
0060 bestRun = session.query(RunInfo.run_number,RunInfo.start_time, RunInfo.end_time).filter(RunInfo.run_number >= options.inputRun).first()
0061 if bestRun is None:
0062 raise Exception("Run %s can't be matched with an existing run in the database." %options.runNumber)
0063
0064 start= bestRun[1]
0065 stop = bestRun[2]
0066
0067 bestRunStartTime = calendar.timegm( bestRun[1].utctimetuple() ) << 32
0068 bestRunStopTime = calendar.timegm( bestRun[2].utctimetuple() ) << 32
0069
0070 print("run start time:",start,"(",bestRunStartTime,")")
0071 print("run stop time: ",stop,"(",bestRunStopTime,")")
0072
0073 gtstring=str(options.inputGT)
0074 if('auto' in gtstring):
0075 from Configuration.AlCa import autoCond
0076 key=gtstring.replace('auto:','')
0077 print("An autoCond Global Tag was used, will use key %s" % key)
0078 gtstring=autoCond.autoCond[key]
0079 print("Will use the resolved key %s" % gtstring)
0080
0081 command='cmsRun $CMSSW_BASE/src/CondTools/SiStrip/test/db_tree_dump.py outputRootFile=sistrip_db_tree_'+gtstring+'_'+str(options.inputRun)+'.root GlobalTag='+options.inputGT+' runNumber='+str(options.inputRun)+' runStartTime='+str(bestRunStartTime)
0082
0083 data = execme(command)
0084 print("\n output of execution: \n\n",data)
0085
0086 if __name__ == "__main__":
0087 main()