17 from argparse
import RawTextHelpFormatter
19 parser = argparse.ArgumentParser(description=__doc__,formatter_class=RawTextHelpFormatter)
20 parser.add_argument(
'--outPRWFile',action=
"store",help=
"OPTIONAL Name of the output prw file containing valid configs",required=
False)
21 parser.add_argument(
'--outputSuspect',action=
"store_true",help=
"allow for suspect channels to be included in the output prw file",default=
False)
22 parser.add_argument(
'--inDsTxt',action=
"store",help=
"text file containing datasets to make PRW for (one per line)",required=
True)
23 parser.add_argument(
'prwFiles',nargs=
"+",help=
"PRW Config files to scan")
25 args = parser.parse_args()
29 import pyAMI.atlas.api
as atlasAPI
32 print(
"Could not import pyAMI ... please do: lsetup pyAMI")
33 print(
"Also ensure you have a valid certificate (voms-proxy-init -voms atlas)")
36 client = pyAMI.client.Client([
'atlas',
'atlas-replica'])
41 for txtFile
in args.inDsTxt.split(
","):
42 with open(txtFile)
as f: datasets += f.read().splitlines()
45 print(
"Determining provenances of %d datasets ..." % len(datasets))
48 for dataset
in datasets:
50 if dataset.startswith(
"#"):
continue
51 dataset = dataset.rsplit(
":")[-1].strip()
52 if len(dataset)==0:
continue
54 print(
"Doing %s" % dataset)
56 if ".DAOD_PHYS." in dataset:
57 print(
"INFO: Assuming %s is unskimmed because it is DAOD_PHYS" % dataset)
59 theParentSize =
int(atlasAPI.list_datasets(client, theParent,fields=
'ldn,events')[0][
u'events'])
61 prov = atlasAPI.get_dataset_prov(client, dataset )
62 if 'node' not in prov:
63 print(
"ERROR: Could not determine provenance of %s, skipping!" % dataset)
66 for ds
in prov[
'node']:
67 if ds[
u'dataType']!=
u'AOD':
continue
68 dsName = ds[
u'logicalDatasetName']
69 if 'recon.AOD' not in ds[
u'logicalDatasetName']:
continue
70 etags = re.findall(
'e[0-9]+_', dsName)
71 stags = re.findall(
's[0-9]+_', dsName)
72 astags = re.findall(
'a[0-9]+_s[0-9]+', dsName)
73 if len(etags) == 2
or len(stags) == 2
or len(astags) == 1:
75 print(
"INFO: Found a double e-tag container %s!" % dsName)
76 dsName = dsName.replace(etags[1],
"")
78 print(
"INFO: Found a double s-tag container %s!" % dsName)
79 dsName = dsName.replace(stags[1],
"")
80 if len(astags) == 1
and len(stags) == 1:
81 print(
"INFO: Found an a+s-tag container %s!" % dsName)
82 dsName = dsName.replace(stags[0],
"")
83 singleTagName = dsName
85 theParent =
str(dsName)
86 theParentSize =
int(ds[
u'events'])
90 if singleTagName ==
"":
91 print(
"ERROR: No single-tag name available for %s, skipping!" % dataset)
94 print(
"INFO: Trying with single-tag containers manually %s!" % singleTagName)
96 prov = atlasAPI.get_dataset_prov(client, singleTagName)
97 except pyAMI.exception.Error:
98 print(
"ERROR: Could not determine provenance of %s, skipping!" % dataset)
101 for ds
in prov[
'node']:
102 if ds[
u'logicalDatasetName'] == singleTagName:
103 theParent = singleTagName
104 theParentSize =
int(ds[
u'events'])
106 print(
"ERROR: key 'node' not found for %s, skipping!" % dataset)
110 print(
"ERROR: Could not determine provenance of %s, skipping!" % dataset)
114 theParent = theParent.split(
".")[1]
116 if theParent
in aodDatasets: aodDatasets[theParent] += theParentSize
117 else: aodDatasets[theParent] = theParentSize
123 out = ROOT.CP.TPileupReweighting(
"out")
124 for f
in args.prwFiles:
126 out.ResetCountingMode()
129 periodNumbers = out.GetPeriodNumbers()
131 for dsid,nevents
in aodDatasets.items():
135 for p
in periodNumbers:
137 hist = out.GetInputHistogram(
int(dsid),p)
138 if hist: total += hist.GetEntries()
141 print(
"channel %s is ok" % dsid)
143 print(
"channel %s is incomplete (missing %d events from config files)" % (dsid,nevents-total))
144 out.RemoveChannel(
int(dsid))
146 print(
"channel %s is suspect! (config files have additional %d events)" % (dsid,total-nevents))
147 if not args.outputSuspect:
148 out.RemoveChannel(
int(dsid))
154 out.WriteToFile(args.outPRWFile);