File indexing completed on 2024-04-06 12:31:55
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 = {'RelValZTT_14TeV__':'ZTT'},
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 ",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
0053 if (path.find("2026") < 0):
0054 continue
0055 print(path.split("/")[-1])
0056 if printDS:
0057 continue
0058
0059
0060 fname = path.split("/")[-1]
0061
0062
0063 info = fname.split("__")[2].replace(label, "").strip("-")
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083 ofn = ofnBlank%{"sample":dsFlags[str],"label":slabel,"info":info}
0084 if camType == "DATA":
0085 ofn = ofn.replace("zb","")
0086 ofn = ofn.replace("jetHT","")
0087 print("ofn = ",ofn)
0088
0089 if not os.path.isfile(ofn):
0090
0091 curlCommand = curl%{"CERT_DIR":X509_CERT_DIR,"USER_PROXY":X509_USER_PROXY, "relValDIR":relValDIR} + "/" + fname
0092 print(curlCommand)
0093 os.system(curlCommand)
0094
0095
0096 mvCommand = "mv %(fn)s %(ofn)s"%{"fn":fname,"ofn":ofn}
0097 print(mvCommand)
0098 os.system(mvCommand)
0099 print("")
0100
0101
0102
0103 fin.close();
0104 rmCommand = "rm %(ofn)s"%{"ofn":relValDIR}
0105 print(rmCommand)
0106 os.system(rmCommand)
0107
0108 if printDS:
0109 return
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125 dsMCFlags = {'RelValTTbar_14TeV__':'TTbar', 'RelValZTT_14TeV__':'ZTT'}
0126
0127
0128 dsDATAFlags = {'297557__JetHT__':'JetHT','297557__ZeroBias__':'ZeroBias',
0129 '315489__JetHT__':'JetHT','315489__ZeroBias__':'ZeroBias',
0130 '317435__JetHT__':'JetHT','317435__ZeroBias__':'ZeroBias',
0131 '319450__JetHT__':'JetHT','319450__ZeroBias__':'ZeroBias',
0132 '320822__JetHT__':'JetHT','320822__ZeroBias__':'ZeroBias'}
0133
0134
0135
0136 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"
0137 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"
0138
0139 ofnBlank = "HcalRecHitValidationRelVal_%(sample)s_%(label)s_%(info)s.root"
0140
0141
0142
0143 dfTextFile = "%s"
0144
0145
0146 if len(args) < 1:
0147 print("Usage: ./RelValHarvest.py -M (or -D) fullReleaseName")
0148 print("fullReleaseName : CMSSW_7_4_0_pre8")
0149 exit(0)
0150
0151
0152 if not options.getMC and not options.getDATA and not options.get2023:
0153 print("You must specify a dataset:")
0154 print(" -M : Monte Carlo")
0155 print(" -D : Data")
0156 print(" -2 : 2023")
0157 exit(0)
0158
0159
0160 label = args[0]
0161
0162
0163 pattern = re.compile(r'CMSSW_\d{1,2}_\d{1,2}_\d{1,2}.*')
0164 match = pattern.match(label)
0165 if match:
0166 slabel = match.group().replace('CMSSW','').replace("_","")
0167 else:
0168 print(label, " is an invalid CMMSW release name.")
0169 print("Please provide a release name in the form: CMSSW_X_Y_Z")
0170 exit(0)
0171
0172
0173 X509_CERT_DIR = os.getenv('X509_CERT_DIR', "/etc/grid-security/certificates")
0174 X509_USER_PROXY = os.getenv('X509_USER_PROXY')
0175
0176
0177
0178
0179
0180 clabel = label.split("_")
0181 relValDIR = "%s_%s_%s_x"%(clabel[0], clabel[1], clabel[2])
0182
0183 if options.getMC:
0184 getDataSets( dsFlags = dsMCFlags,
0185 curl = curlMC,
0186 label = label,
0187 slabel = slabel,
0188 relValDIR = relValDIR,
0189 printDS = options.printDS,
0190 camType = "MC")
0191
0192 if options.get2023:
0193 getDataSets( dsFlags = ds2023Flags,
0194 curl = curlMC,
0195 label = label,
0196 slabel = slabel,
0197 relValDIR = relValDIR,
0198 printDS = options.printDS,
0199 camType = "2023")
0200
0201 if options.getDATA:
0202 getDataSets( dsFlags = dsDATAFlags,
0203 curl = curlDATA,
0204 label = label,
0205 slabel = slabel,
0206 relValDIR = relValDIR,
0207 printDS = options.printDS,
0208 camType = "DATA")
0209