File indexing completed on 2024-11-26 02:34:21
0001
0002
0003
0004
0005
0006
0007
0008 from optparse import OptionParser
0009 import os, time, re
0010
0011 jobHash = "%s_%s_%s" % (os.getuid(), os.getpid(), int(time.time()))
0012
0013 usage = '%prog [options]. \n\t-a and -k required, -h for help.'
0014 parser = OptionParser(usage)
0015 parser.add_option("-a", "--analysis", dest="analysis",
0016 help="analysis configuration file")
0017
0018
0019
0020 parser.add_option("-k", "--hltkey", dest="hltkey",
0021 help="ignore RunRegistry and force the use of HLT key KEY",
0022 metavar="KEY")
0023 parser.add_option("-c", "--hltcff", dest="hltcff",
0024 help="use the config fragment CFF to define HLT configuration",
0025 metavar="CFF")
0026 parser.add_option("-f", "--frontier", dest="frontier",
0027 help="frontier connection string to use, defaults to frontier://FrontierProd/CMS_COND_21X_GLOBALTAG",
0028 default="frontier://FrontierProd/CMS_COND_31X_GLOBALTAG")
0029
0030
0031 (options, args) = parser.parse_args()
0032
0033 if options.hltkey == None and options.hltcff == None:
0034 parser.error("I don't have all the required options.")
0035 raise SystemExit(
0036 "Please specify one of --hltkey (-k) or --hltcff (-s)")
0037 if options.hltkey != None and options.hltcff != None:
0038 raise SystemExit("Please only specify --hltkey (-k) or --hltcff (-c)")
0039
0040
0041
0042
0043 if options.analysis == None:
0044 raise SystemExit(
0045 "Please specify an analysis configuration: -a or --analysis")
0046
0047
0048 def CheckEnvironment():
0049 cwd = os.getcwd()
0050 t = cwd.split("/")
0051 if t[-1] != "python":
0052 raise SystemExit("Must run from a Module/Package/python directory")
0053
0054
0055 def ConvertHltOnlineToOffline(config, frontierString):
0056
0057 onlineFrontier = re.search('"(frontier:.*)"', config)
0058 if not onlineFrontier:
0059 print("WARNING: Could not find Frontier string in HLT configuration. Will ignore.")
0060 else:
0061 config = config.replace(onlineFrontier.group(1), frontierString)
0062
0063
0064 config = config.replace("H::All", "P::All")
0065
0066
0067
0068 config = RemovePSet(config, "MessageLogger")
0069
0070 config = RemovePSet(config, "DQM")
0071 config = RemovePSet(config, "FUShmDQMOutputService")
0072
0073 return config
0074
0075 def RemovePSet(config, pset):
0076 startLoc = config.find(pset)
0077 started = False
0078 count = 0
0079 curLoc = startLoc
0080 endLoc = 0
0081
0082
0083 while not started:
0084 if config[curLoc] == "(":
0085 started = True
0086 count = 1
0087 curLoc += 1
0088
0089
0090 while endLoc == 0:
0091 if config[curLoc] == "(":
0092 count += 1
0093 elif config[curLoc] == ")":
0094 count -= 1
0095 if count == 0:
0096 endLoc = curLoc
0097 curLoc += 1
0098
0099 config = config.replace(config[startLoc:endLoc + 1], "")
0100
0101 return config
0102
0103
0104 def GetHltConfiguration(hltKey, frontierString):
0105
0106 cwd = os.getcwd()
0107 t = cwd.split("/")
0108 module = t[-3]
0109 package = t[-2]
0110
0111
0112 config = os.popen2('wget "http://cms-project-confdb-hltdev.web.cern.ch/cms-project-confdb-hltdev/get.jsp?dbName=ORCOFF&configName=%s&cff=&nooutput=&format=Python" -O- -o /dev/null' % hltKey)[1].read()
0113
0114 configName = "JobHLTConfig_%s_cff.py" % jobHash
0115
0116
0117 config = ConvertHltOnlineToOffline(config, frontierString)
0118
0119
0120 f = open(configName, "w")
0121 f.write(config)
0122 f.close()
0123
0124 return 'process.load("%s.%s.%s")' % (module, package, configName.split(".")[0])
0125
0126
0127 def GetHltKeyForRun(run):
0128 raise SystemExit("Not implemented yet")
0129
0130
0131 def FormatHltCff(cffPath):
0132 pathParts = cffPath.split(".")
0133 if not re.match("^[_A-Za-z0-9]*\\.[_A-Za-z0-9]*\\.[_A-Za-z0-9]*$", cffPath):
0134 raise SystemExit("Expected cff in form Package.Module.configName_cff")
0135 return 'process.load("%s")' % cffPath
0136
0137
0138 def GetHltCompileCode(subsystem, package, hltConfig):
0139 tmpCode = compileCode.replace("SUBSYSTEM", subsystem)
0140 tmpCode = tmpCode.replace("PACKAGE", package)
0141 tmpCode = tmpCode.replace("CONFIG", hltConfig + "c")
0142 return tmpCode
0143
0144
0145 def CreateAnalysisConfig(analysis, hltInclude):
0146 anaName = "JobAnalysisConfig_%s_cfg.py" % jobHash
0147 f = open(analysis)
0148 g = open(anaName, "w")
0149 g.write(f.read())
0150 g.write("\n")
0151 g.write(hltInclude)
0152 g.close()
0153 f.close()
0154 return anaName
0155
0156
0157 CheckEnvironment()
0158
0159
0160 hltConfig = None
0161 if options.hltkey != None:
0162 hltConfig = GetHltConfiguration(options.hltkey, options.frontier)
0163 elif options.hltcff != None:
0164 hltConfig = FormatHltCff(options.hltcff)
0165 else:
0166 hltKey = GetHltKeyForRun(0)
0167 hltConfig = GetHltConfiguration(hltKey)
0168
0169
0170 anaConfig = CreateAnalysisConfig(options.analysis, hltConfig)
0171
0172 if options.hltcff:
0173 print("Using HLT configuration: %s" % hltConfig)
0174 else:
0175 print("Created HLT configuration: %s" % hltConfig)
0176 print("Created analysis configuration: %s" % anaConfig)
0177