Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-04-01 23:53:47

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     '''Wrapper for executing commands.
0014     '''
0015     if dryrun:
0016         print(command)
0017     else:
0018         print(" * Executing: %s ..." % (command))
0019         os.system(command)
0020         print(" * Executed!")
0021 
0022 ##############################################
0023 def main():
0024 ##############################################
0025 
0026     defaultGT='auto:run3_data_prompt'
0027     #defaultGT='123X_dataRun3_Prompt_v5'
0028     defaultRun=346512
0029     
0030     parser = optparse.OptionParser(usage = 'Usage: %prog [options] <file> [<file> ...]\n')
0031     
0032     parser.add_option('-G', '--inputGT',
0033                       dest = 'inputGT',
0034                       default = defaultGT,
0035                       help = 'Global Tag to get conditions',
0036                       )
0037 
0038     parser.add_option('-r', '--inputRun',
0039                       dest = 'inputRun',
0040                       default = defaultRun,
0041                       help = 'run to be used',
0042                       )
0043 
0044     (options, arguments) = parser.parse_args()
0045 
0046     print("Input configuration")
0047     print("globalTag: ",options.inputGT)
0048     print("runNumber: ",options.inputRun)
0049     
0050     con = conddb.connect(url = conddb.make_url())
0051     session = con.session()
0052     RunInfo = session.get_dbtype(conddb.RunInfo)
0053     
0054     bestRun = session.query(RunInfo.run_number,RunInfo.start_time, RunInfo.end_time).filter(RunInfo.run_number >= options.inputRun).first()
0055     if bestRun is None:
0056         raise Exception("Run %s can't be matched with an existing run in the database." %options.runNumber)
0057     
0058     start= bestRun[1]
0059     stop = bestRun[2]
0060     
0061     bestRunStartTime = calendar.timegm( bestRun[1].utctimetuple() ) << 32
0062     bestRunStopTime  = calendar.timegm( bestRun[2].utctimetuple() ) << 32
0063     
0064     print("run start time:",start,"(",bestRunStartTime,")")
0065     print("run stop time: ",stop,"(",bestRunStopTime,")")
0066     
0067     gtstring=str(options.inputGT)
0068     if('auto' in gtstring):
0069         from Configuration.AlCa import autoCond
0070         key=gtstring.replace('auto:','')
0071         print("An autoCond Global Tag was used, will use key %s" % key)
0072         gtstring=autoCond.autoCond[key]
0073         print("Will use the resolved key %s" % gtstring)
0074 
0075     command='cmsRun db_tree_dump.py outputRootFile=sistrip_db_tree_'+gtstring+'_'+str(options.inputRun)+'.root GlobalTag='+options.inputGT+' runNumber='+str(options.inputRun)+' runStartTime='+str(bestRunStartTime)
0076     
0077     execme(command)
0078 
0079 if __name__ == "__main__":        
0080     main()