9 from itertools
import chain
11 sys.path.append(
'$TestArea/../')
15 return os.stat(path).st_size == 0
21 DAOD_types.append(d.split(
'.')[4])
22 short_DAOD =
list(
set(DAOD_types))
26 def validate(testSampleDir, thisSampleName, testSamplePath, weight_database, outputSamples):
27 for dirName
in os.listdir(testSampleDir):
28 if thisSampleName.split(
":")[1]
in dirName:
29 testSamplePath = testSampleDir +
"/" + dirName
30 if (testSamplePath
is None):
31 print(
"[INFO] do not currently have a test sample for ", thisSampleName)
32 rucioCommand =
"rucio download --nrandom 1 %s --dir %s " % (thisSampleName, opts.testSampleDir)
33 print(
"[INFO] --> downloading one using this command \n ", rucioCommand)
34 os.system(rucioCommand)
35 testSamplePath = testSampleDir +
"/" + thisSampleName.split(
":")[1]
36 if not os.path.exists(testSamplePath):
37 print(
"[ERROR INFO] No such directory: %s OR downloading Failed" % (testSamplePath))
39 if not os.listdir(testSamplePath):
40 print(
"[ERROR INFO] Downloading Failed for ", testSamplePath)
42 for fileName
in os.listdir(testSamplePath):
43 if fileName.endswith(
'part'):
44 print(
"[ERROR INFO] Downloading Failed for ", testSamplePath)
45 rmdir =
"rm -r %s" % (testSamplePath)
48 testSamplePath = testSamplePath +
"/" + fileName
50 print(
"[SUCCESS] found test file ", testSamplePath)
51 athenaCommand =
"athena --filesInput=%s --evtMax = 1 MyPackage/MyPackageAlgJobOptions.py" % (testSamplePath)
52 print(
"[INFO] running athena weight retrieving tool using \n", athenaCommand)
53 os.system(athenaCommand)
54 if not os.path.exists(
'weight.txt'):
55 print(
'[INFO] Athena Tool failed to retrieve weights')
57 wfile =
open(
'weight.txt',
'r')
58 ofile =
open(outputSamples,
'a+')
59 weightFile = wfile.read().splitlines()
60 if set(weight_database) ==
set(weightFile):
61 print(
'%s is Validated' % (thisSampleName))
62 ofile.write(thisSampleName.split(
":")[1] +
' ' +
'PASSED' +
'\n')
64 print(
'%s is NOT Validated' % (thisSampleName))
65 ofile.write(thisSampleName.split(
":")[1] +
' ' +
'FAILED')
68 rmcommand =
"rm weight.txt"
70 rmsample =
"rm -r %s" % (testSampleDir +
"/" + thisSampleName.split(
":")[1])
74 parser = optparse.OptionParser(usage=
"%prog [options]")
75 parser.add_option(
"-i",
"--inputSamples", help=
"list of samples. One per line", dest=
"inputSamples", default=
"../toValidate_samples.txt")
76 parser.add_option(
"--testSampleDir", help=
"where to store the test samples.", dest=
"testSampleDir", default=
"../validSamples")
77 parser.add_option(
"-o",
"--outputSamples", help=
"list of validated samples. One per line, with tag as PASSED/FAILED", dest=
"outputSamples", default=
"../validated_samples.txt")
78 (opts, args) = parser.parse_args()
80 os.system(
"mkdir -p %s" % opts.testSampleDir)
81 f =
open(opts.inputSamples)
82 for line
in f.readlines():
84 if line[0] ==
"#" or line ==
'':
continue
85 SampleName = line.split()[0]
86 dsid = SampleName.split(
".")[1]
89 print(
'[FAIL] DSID %s not found in Database' % (dsid))
92 weight_database.append(dictionary[key][
'weights'])
93 weight_database =
list(chain.from_iterable(weight_database))
95 if 'DAOD' in SampleName:
96 ofile =
open(opts.outputSamples,
'a+')
97 if any(SampleName.split(
":")[1]
in oline
for oline
in ofile.readlines()):
98 print(
'[INFO] sample already checked')
101 validate(opts.testSampleDir, SampleName, testSamplePath, weight_database, opts.outputSamples)
103 ruciolist =
"rucio list-dids %s*DAOD* --filter type = CONTAINER --short > list_DAOD.txt" % (SampleName.split(
"_")[0] +
'_' + SampleName.split(
"_")[1] +
'_' + SampleName.split(
"_")[2])
104 ruciolist = ruciolist.replace(
'mc15',
'mc16')
105 print(
"[INFO] rucio listing DAODs using this command \n ", ruciolist)
108 print(
'No DAODs found for the given sample: ', SampleName)
110 lfile =
open(
'list_DAOD.txt',
'r')
111 list_DAOD = lfile.readlines()
113 for DAOD
in shortDAOD:
114 d_list =
list(element
for element
in list_DAOD
if DAOD
in element)
116 thisSampleName = d_list[-1].
split()[0]
117 testSamplePath =
None
118 ofile =
open(opts.outputSamples,
'a+')
119 if any(thisSampleName.split(
":")[1]
in oline
for oline
in ofile.readlines()):
120 print(
'[INFO] sample already checked')
123 validate(opts.testSampleDir, thisSampleName, testSamplePath, weight_database, opts.outputSamples)