File indexing completed on 2023-03-17 11:26:59
0001
0002
0003 import sys, os, re
0004
0005 from optparse import OptionParser
0006 usage = "usage: %prog summary files"
0007 version = "%prog."
0008 parser = OptionParser(usage=usage,version=version)
0009 parser.add_option("-p", "--printDataSets", action="store_true", dest="printDS", default=False, help="Print datasets without attempting to download.")
0010 parser.add_option("-M", "--MC", action="store_true", dest="getMC", default=False, help="Get DQM files for MC campaign.")
0011 parser.add_option("-D", "--DATA", action="store_true", dest="getDATA", default=False, help="Get DQM files for DATA campaign.")
0012 parser.add_option("-2", "--2023", action="store_true", dest="get2023", default=False, help="Get DQM files for 2023 campaign.")
0013 (options, args) = parser.parse_args()
0014
0015
0016
0017
0018
0019
0020 def getDataSets( dsFlags = {'RelValMinBias_13__':'MinBias'},
0021 curl = "/usr/bin/curl -O -L --capath %(CERT_DIR)s --key %(USER_PROXY)s --cert %(USER_PROXY)s https://cmsweb.cern.ch/dqm/relval/data/browse/ROOT/RelVal/%(relValDIR)s",
0022 ofnBlank = "HcalRecHitValidationRelVal_%(sample)s_%(label)s_%(info)s.root",
0023 label = "CMSSW_X_Y_Z",
0024 slabel = "XYZ",
0025 X509_CERT_DIR = os.getenv('X509_CERT_DIR', "/etc/grid-security/certificates"),
0026 X509_USER_PROXY = os.getenv('X509_USER_PROXY'),
0027 relValDIR = "CMSSW_?_?_x",
0028 printDS = False,
0029 camType = "MC"):
0030
0031 print ("Taking filenames from directory %s"%relValDIR)
0032
0033
0034 if not os.path.isfile(relValDIR):
0035 curlCommand = curl%{"CERT_DIR":X509_CERT_DIR, "USER_PROXY":X509_USER_PROXY, "relValDIR":relValDIR}
0036 print (curlCommand)
0037 os.system(curlCommand)
0038
0039
0040 fin = open(relValDIR, "r")
0041
0042
0043 for line in fin:
0044
0045 if label in line:
0046
0047 for str in dsFlags.keys():
0048 if str in line:
0049
0050 path = line.split('\'')[1].strip()
0051
0052 if (path.find("Ideal") > 0 or path.find("design") > 0 or path.find("FastSim") > 0 or path.find("DQM") < 0 or path.find("Pixel") > 0 ):
0053 continue
0054 print (path.split("/")[-1])
0055 if printDS:
0056 continue
0057
0058
0059 fname = path.split("/")[-1]
0060
0061
0062 info = fname.split("__")[2].replace(label, "").strip("-")
0063
0064
0065
0066 if camType == "DATA":
0067 iparts = info.split("_")
0068 info = ""
0069 skip = False
0070 for fragment in iparts:
0071 if skip:
0072 info = info.strip("_")
0073 skip = False
0074 continue
0075 if fragment == "RelVal":
0076 skip = True
0077 continue
0078 info += fragment
0079 info += "_"
0080 info = info.strip("_")
0081
0082 ofn = ofnBlank%{"sample":dsFlags[str],"label":slabel,"info":info}
0083 print ("ofn = ",ofn)
0084
0085 if not os.path.isfile(ofn):
0086
0087 curlCommand = curl%{"CERT_DIR":X509_CERT_DIR,"USER_PROXY":X509_USER_PROXY, "relValDIR":relValDIR} + "/" + fname
0088 print (curlCommand)
0089 os.system(curlCommand)
0090
0091
0092 mvCommand = "mv %(fn)s %(ofn)s"%{"fn":fname,"ofn":ofn}
0093 print (mvCommand)
0094 os.system(mvCommand)
0095
0096
0097 fin.close();
0098 rmCommand = "rm %(ofn)s"%{"ofn":relValDIR}
0099 print (rmCommand)
0100 os.system(rmCommand)
0101
0102 if printDS:
0103 return
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119 dsMCFlags = {'RelValTTbar_13__':'TTbar', 'RelValQCD_Pt_80_120_13__':'QCD', 'RelValQCD_Pt_3000_3500_13__':'HighPtQCD', 'RelValMinBias_13__':'MinBias'}
0120 ds2023Flags = {'RelValTTbar_14TeV__':'TTbar', 'RelValMinBias_14TeV__':'MinBias'}
0121
0122
0123
0124 dsDATAFlags = {'315489__JetHT__':'JetHT','315489__ZeroBias__':'ZeroBias'}
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140 curlMC = "/usr/bin/curl -O -L --capath %(CERT_DIR)s --key %(USER_PROXY)s --cert %(USER_PROXY)s https://cmsweb.cern.ch/dqm/relval/data/browse/ROOT/RelVal/%(relValDIR)s"
0141 curlDATA = "/usr/bin/curl -O -L --capath %(CERT_DIR)s --key %(USER_PROXY)s --cert %(USER_PROXY)s https://cmsweb.cern.ch/dqm/relval/data/browse/ROOT/RelValData/%(relValDIR)s"
0142
0143 ofnBlank = "HcalRecHitValidationRelVal_%(sample)s_%(label)s_%(info)s.root"
0144
0145
0146
0147 dfTextFile = "%s"
0148
0149
0150 if len(args) < 1:
0151 print ("Usage: ./RelValHarvest.py -M (or -D) fullReleaseName")
0152 print ("fullReleaseName : CMSSW_7_4_0_pre8")
0153 exit(0)
0154
0155
0156 if not options.getMC and not options.getDATA and not options.get2023:
0157 print ("You must specify a dataset:")
0158 print (" -M : Monte Carlo")
0159 print (" -D : Data")
0160 print (" -2 : 2023")
0161 exit(0)
0162
0163
0164 label = args[0]
0165
0166
0167 pattern = re.compile(r'CMSSW_\d{1,2}_\d{1,2}_\d{1,2}.*')
0168 match = pattern.match(label)
0169 if match:
0170 slabel = match.group().replace('CMSSW','').replace("_","")
0171 else:
0172 print (label, " is an invalid CMMSW release name.")
0173 print ("Please provide a release name in the form: CMSSW_X_Y_Z")
0174 exit(0)
0175
0176
0177 X509_CERT_DIR = os.getenv('X509_CERT_DIR', "/etc/grid-security/certificates")
0178 X509_USER_PROXY = os.getenv('X509_USER_PROXY')
0179
0180
0181
0182
0183
0184 clabel = label.split("_")
0185 relValDIR = "%s_%s_%s_x"%(clabel[0], clabel[1], clabel[2])
0186
0187 if options.getMC:
0188 getDataSets( dsFlags = dsMCFlags,
0189 curl = curlMC,
0190 label = label,
0191 slabel = slabel,
0192 relValDIR = relValDIR,
0193 printDS = options.printDS,
0194 camType = "MC")
0195
0196 if options.get2023:
0197 getDataSets( dsFlags = ds2023Flags,
0198 curl = curlMC,
0199 label = label,
0200 slabel = slabel,
0201 relValDIR = relValDIR,
0202 printDS = options.printDS,
0203 camType = "2023")
0204
0205 if options.getDATA:
0206 getDataSets( dsFlags = dsDATAFlags,
0207 curl = curlDATA,
0208 label = label,
0209 slabel = slabel,
0210 relValDIR = relValDIR,
0211 printDS = options.printDS,
0212 camType = "DATA")
0213