00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 from optparse import OptionParser
00015 import os, time, re
00016
00017 jobHash = "%s_%s_%s" % (os.getuid(), os.getpid(), int(time.time()))
00018
00019 usage = '%prog [options]. \n\t-a and -k required, -h for help.'
00020 parser = OptionParser(usage)
00021 parser.add_option("-a", "--analysis", dest="analysis",
00022 help="analysis configuration file")
00023
00024
00025
00026 parser.add_option("-k", "--hltkey", dest="hltkey",
00027 help="ignore RunRegistry and force the use of HLT key KEY",
00028 metavar="KEY")
00029 parser.add_option("-c", "--hltcff", dest="hltcff",
00030 help="use the config fragment CFF to define HLT configuration",
00031 metavar="CFF")
00032 parser.add_option("-f", "--frontier", dest="frontier",
00033 help="frontier connection string to use, defaults to frontier://FrontierProd/CMS_COND_21X_GLOBALTAG",
00034 default="frontier://FrontierProd/CMS_COND_31X_GLOBALTAG")
00035
00036
00037 (options, args) = parser.parse_args()
00038
00039 if options.hltkey == None and options.hltcff == None:
00040 parser.error("I don't have all the required options.")
00041 raise SystemExit(
00042 "Please specify one of --hltkey (-k) or --hltcff (-s)")
00043 if options.hltkey != None and options.hltcff != None:
00044 raise SystemExit("Please only specify --hltkey (-k) or --hltcff (-c)")
00045
00046
00047
00048
00049 if options.analysis == None:
00050 raise SystemExit(
00051 "Please specify an analysis configuration: -a or --analysis")
00052
00053
00054 def CheckEnvironment():
00055 cwd = os.getcwd()
00056 t = cwd.split("/")
00057 if t[-1] != "python":
00058 raise SystemExit("Must run from a Module/Package/python directory")
00059
00060
00061 def ConvertHltOnlineToOffline(config, frontierString):
00062
00063 onlineFrontier = re.search('"(frontier:.*)"', config)
00064 if not onlineFrontier:
00065 print "WARNING: Could not find Frontier string in HLT configuration. Will ignore."
00066 else:
00067 config = config.replace(onlineFrontier.group(1), frontierString)
00068
00069
00070 config = config.replace("H::All", "P::All")
00071
00072
00073
00074 config = RemovePSet(config, "MessageLogger")
00075
00076 config = RemovePSet(config, "DQM")
00077 config = RemovePSet(config, "FUShmDQMOutputService")
00078
00079 return config
00080
00081 def RemovePSet(config, pset):
00082 startLoc = config.find(pset)
00083 started = False
00084 count = 0
00085 curLoc = startLoc
00086 endLoc = 0
00087
00088
00089 while not started:
00090 if config[curLoc] == "(":
00091 started = True
00092 count = 1
00093 curLoc += 1
00094
00095
00096 while endLoc == 0:
00097 if config[curLoc] == "(":
00098 count += 1
00099 elif config[curLoc] == ")":
00100 count -= 1
00101 if count == 0:
00102 endLoc = curLoc
00103 curLoc += 1
00104
00105 config = config.replace(config[startLoc:endLoc + 1], "")
00106
00107 return config
00108
00109
00110 def GetHltConfiguration(hltKey, frontierString):
00111
00112 cwd = os.getcwd()
00113 t = cwd.split("/")
00114 module = t[-3]
00115 package = t[-2]
00116
00117
00118 config = os.popen2('wget "https://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()
00119
00120 configName = "JobHLTConfig_%s_cff.py" % jobHash
00121
00122
00123 config = ConvertHltOnlineToOffline(config, frontierString)
00124
00125
00126 f = open(configName, "w")
00127 f.write(config)
00128 f.close()
00129
00130 return 'process.load("%s.%s.%s")' % (module, package, configName.split(".")[0])
00131
00132
00133 def GetHltKeyForRun(run):
00134 raise SystemExit("Not implemented yet")
00135
00136
00137 def FormatHltCff(cffPath):
00138 pathParts = cffPath.split(".")
00139 if not re.match("^[_A-Za-z0-9]*\.[_A-Za-z0-9]*\.[_A-Za-z0-9]*$", cffPath):
00140 raise SystemExit("Expected cff in form Package.Module.configName_cff")
00141 return 'process.load("%s")' % cffPath
00142
00143
00144 def GetHltCompileCode(subsystem, package, hltConfig):
00145 tmpCode = compileCode.replace("SUBSYSTEM", subsystem)
00146 tmpCode = tmpCode.replace("PACKAGE", package)
00147 tmpCode = tmpCode.replace("CONFIG", hltConfig + "c")
00148 return tmpCode
00149
00150
00151 def CreateAnalysisConfig(analysis, hltInclude):
00152 anaName = "JobAnalysisConfig_%s_cfg.py" % jobHash
00153 f = open(analysis)
00154 g = open(anaName, "w")
00155 g.write(f.read())
00156 g.write("\n")
00157 g.write(hltInclude)
00158 g.close()
00159 f.close()
00160 return anaName
00161
00162
00163 CheckEnvironment()
00164
00165
00166 hltConfig = None
00167 if options.hltkey != None:
00168 hltConfig = GetHltConfiguration(options.hltkey, options.frontier)
00169 elif options.hltcff != None:
00170 hltConfig = FormatHltCff(options.hltcff)
00171 else:
00172 hltKey = GetHltKeyForRun(0)
00173 hltConfig = GetHltConfiguration(hltKey)
00174
00175
00176 anaConfig = CreateAnalysisConfig(options.analysis, hltConfig)
00177
00178 if options.hltcff:
00179 print "Using HLT configuration: %s" % hltConfig
00180 else:
00181 print "Created HLT configuration: %s" % hltConfig
00182 print "Created analysis configuration: %s" % anaConfig
00183