forked from CMSCompOps/WmAgentScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunprocessedBlocks.py
91 lines (81 loc) · 2.78 KB
/
unprocessedBlocks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python
import urllib2,urllib, httplib, sys, re, os, json, phedexSubscription, dbsTest
from xml.dom.minidom import getDOMImplementation
from das_client import get_data
#das_host='https://das.cern.ch'
#das_host='https://cmsweb.cern.ch'
das_host='https://cmsweb-testbed.cern.ch'
#das_host='https://das-dbs3.cern.ch'
def getBlocksLumi(dataset):
Blockslumis=[]
query="block, run, lumi dataset="+dataset
das_data = get_data(das_host,query,0,0,0)
if isinstance(das_data, basestring):
result = json.loads(das_data)
else:
result = das_data
if result['status'] == 'fail' :
print 'DAS query failed with reason:',result['reason']
else:
preresult=result['data']
for block in preresult:
lumisBlock=block['lumi'][0]['number']
lumis=[]
for lumiRange in lumisBlock:
if lumiRange[0]==lumiRange[1]:
lumis.append(lumiRange[0])
else:
lumis=lumis+range(lumiRange[0], lumiRange[1])
Blockslumis.append((block['block'][0]['name'],lumis))
return Blockslumis
def getLumisInDataset(dataset):
lumis=[]
query="run lumi dataset="+dataset
das_data = get_data(das_host,query,0,0,0)
if isinstance(das_data, basestring):
result = json.loads(das_data)
else:
result = das_data
if result['status'] == 'fail' :
print 'DAS query failed with reason:',result['reason']
else:
#preresult=result['data'][0]['lumi'][[0]['number'][0]
#print result
preresult=result['data'][0]['lumi'][0]['number']
for lumiRange in preresult:
if lumiRange[0]==lumiRange[1]:
lumis.append(lumiRange[0])
else:
lumis=lumis+range(lumiRange[0], lumiRange[1])
return lumis
def getBlocksNotProcessed(lumisOutput, BlockLumisInput):
BlocksNotProcessed=[]
for blockLumiPair in BlockLumisInput:
BlockProcessed=False
lumisBlock=blockLumiPair[1]
for lumi in lumisBlock:
if lumi in lumisOutput:
BlockProcessed=True
if BlockProcessed==False:
BlocksNotProcessed.append(blockLumiPair[0])
return [x.encode() for x in BlocksNotProcessed]
def getListUnprocessedBlocks(url, workflow):
outputDataSets=phedexSubscription.outputdatasetsWorkflow(url, workflow)
inputDataset=dbsTest.getInputDataSet(url, workflow)
lumisOutput=getLumisInDataset(outputDataSets[0])
BlockLumisInput=getBlocksLumi(inputDataset)
BlocksNotProcessed=getBlocksNotProcessed(lumisOutput, BlockLumisInput)
return BlocksNotProcessed
def main():
args=sys.argv[1:]
if not len(args)==1:
print "usage:unprocessedBlocks workflowname"
sys.exit(0)
workflow=args[0]
url='cmsweb.cern.ch'
BlocksNotProcessed=getListUnprocessedBlocks(url, workflow)
print "Number of blocks not processed", str(len(BlocksNotProcessed))
print [x.encode() for x in BlocksNotProcessed]
sys.exit(0);
if __name__ == "__main__":
main()