17 defaultRecoTagFilteringPattern =
"r7"
18 defaultSimTags = [
"s2608",
"s2726"]
20 defaultRecoTags = [
"r7772",
"r7725",
"a818",
"a821"]
21 defaultDerivationTags = [
"p2622",
"p2623",
"p2613",
"p2614"]
23 import sys, os, argparse, subprocess, re, pickle
27 print " Will run the following command: %s" % cmd
28 cmdResult = subprocess.Popen(cmd, shell=
True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
29 return cmdResult.stdout
32 projectTag = "mc15_13TeV",
33 simTags = defaultSimTags,
34 recoTags = defaultRecoTags,
36 format = "DAOD_SUSY1",
40 pattern = projectTag +
'.' + dsid +
'.*AOD*'
43 queryPattern = pattern + defaultRecoTagFilteringPattern +
"*"
44 cmd =
"rucio ls --short --filter type=CONTAINER %s | sort -r " % (queryPattern)
48 lines = [line.rstrip().
replace(projectTag+
":",
"")
for line
in queryResult.readlines()]
50 dsPattern = pattern.replace(defaultRecoTagFilteringPattern+
"*",
"").
replace(
"*",
".*")
51 dsRE = re.compile(dsPattern)
52 datasets =
filter(dsRE.match, lines)
54 print " Dataset regex: %s" % dsPattern
55 print " All datasets: "
59 aodPattern = dsPattern.replace(
"AOD.*",
"\.merge\.AOD\..*")
60 aodPattern +=
"("+
'|'.
join(simTags)+
")?.*("+
'|'.
join(recoTags)+
").*"
61 aodRE = re.compile(aodPattern)
62 aodDatasets =
filter(aodRE.match, datasets)
64 print " AOD regex: %s" % aodPattern
65 print " AOD datasets: "
66 for ds
in aodDatasets:
70 aodDatasets.append(
" N/A ")
72 daodPattern = aodPattern.replace(
"AOD", format)
73 daodPattern +=
"("+
'|'.
join(pTags)+
")"
74 daodRE = re.compile(daodPattern)
75 daodDatasets =
filter(daodRE.match, datasets)
77 print " DAOD regex: %s" % daodPattern
78 print " DAOD datasets:"
79 for ds
in daodDatasets:
82 if len(daodDatasets) > 1:
83 print "Found more than one:"
84 for ds
in daodDatasets:
87 if any(ds
for ds
in daodDatasets
if pTag
in ds):
88 daodDatasets = [
next(ds
for ds
in daodDatasets
if pTag
in ds)]
90 print "Was the right one selected?"
91 print " %s" % daodDatasets[0]
94 if len(daodDatasets) < 1:
95 daodDatasets.append(
" N/A ")
98 otherLines = [x
for x
in lines
if x
not in datasets]
99 if len(otherLines) > 0:
100 print "Other lines were found in the query output - there may have been a problem:"
101 for line
in otherLines:
104 returnDict = {
"AOD": aodDatasets[0],
"DAOD": daodDatasets[0]}
108 cmd =
"ami show dataset info %s | grep prodsysStatus" % ds
110 lines = [line.rstrip()
for line
in amiResult.readlines()]
115 amiStatus = lines[0].
split(
':')[1].strip()
117 print "Weird AMI status for %s (saving N/A):" % ds
121 print "No AMI status for %s" % ds
126 row_format =
"{0:<15}{1:^30}{2:^30}{3:<120}"
127 print row_format.format(
"=== DSID ===",
"=== AOD ===",
"=== DAOD (AOD) ===",
"=== DAOD dataset name ===")
129 dsName = s[ds][
"DAOD"]
130 if dsName ==
" N/A ":
131 dsName =
"(AOD: " + s[ds][
"AOD"] +
")"
132 print row_format.format(ds, s[ds][
"AODstatus"], s[ds][
"DAODstatus"], dsName)
136 parser = argparse.ArgumentParser(description=
'Check status of datasets based on DSIDs and AMI tags. Written by C. Ohm & M. Tripiana')
137 parser.add_argument(
'-p',
'--projectTag', type=str, nargs=
'?', help=
'Project tag, defaults to "mc15_13TeV"', default=
'mc15_13TeV')
138 parser.add_argument(
'-d',
'--dsids', type=str, nargs=
'?', help=
'Text file(s) containing DSIDs', default=
'')
139 parser.add_argument(
'-f',
'--format', type=str, help=
'Format: DAOD_SUSY1 (default), DAOD_SUSY2, ...', default=
'DAOD_SUSY1')
140 parser.add_argument(
'-v',
'--verbose', action=
'store_true', default=
False, help=
'Verbose mode, more detailed output and commands, etc')
141 parser.add_argument(
'-o',
'--outfile', nargs=
'?', type=argparse.FileType(
'w'), help=
'Save the dict holding the sample info to a pickle file')
142 parser.add_argument(
'-i',
'--infile', nargs=
'?', type=argparse.FileType(
'r'), help=
'Open a pickle file containing a dict from a previous session')
144 args = parser.parse_args()
149 with args.infile
as handle:
150 samples = pickle.load(handle)
160 dsids = [line.rstrip(
'\n')
for line
in f]
165 if not dsid
or dsid.startswith(
'#'):
168 print "Checking DSID %s..." % dsid
169 samples[dsid] =
getSamplesFromPattern(dsid.strip(), args.projectTag, defaultSimTags, defaultRecoTags, args.verbose, args.format, defaultDerivationTags)
172 print "These samples were found:"
174 print "DSID: %s" % dsid
175 for ds
in samples[dsid]:
176 print " %s: %s" % (ds, samples[dsid][ds])
180 for ds
in samples[dsid].
keys():
182 samples[dsid][ds+
"status"] =
" N/A "
183 samples[dsid][ds+
"status"] =
getAmiStatus(samples[dsid][ds], args.verbose)
185 print "Done, here is the status of your samples"
187 print "Here's the dict holding all the extracted info:"
191 with args.outfile
as handle:
192 pickle.dump(samples, handle)
193 print "Python dict with sample info saved to %s - you can read it in with the -i option" % args.outfile.name
197 if __name__ ==
'__main__':