1 |
afanfani |
1.1 |
#!/usr/bin/env python
|
2 |
|
|
import sys, os, string, re
|
3 |
|
|
import xml.sax
|
4 |
|
|
import urllib
|
5 |
afanfani |
1.2 |
|
6 |
|
|
import sys
|
7 |
|
|
sys.path.append('./DBSAPI')
|
8 |
|
|
import dbsCgiApi
|
9 |
afanfani |
1.1 |
|
10 |
|
|
class DBSError:
|
11 |
|
|
def __init__(self, owner, dataset):
|
12 |
|
|
print '\nERROR accessing DBS for Owner/Dataset: '+owner+'/'+dataset+'\n'
|
13 |
|
|
pass
|
14 |
|
|
|
15 |
|
|
class DBSInfoError:
|
16 |
|
|
def __init__(self, url):
|
17 |
|
|
print '\nERROR accessing DBS url : '+url+'\n'
|
18 |
|
|
pass
|
19 |
|
|
|
20 |
|
|
##################################################################################
|
21 |
|
|
# Class to extract info from DBS
|
22 |
|
|
###############################################################################
|
23 |
|
|
|
24 |
|
|
class DBSInfo:
|
25 |
|
|
def __init__(self, owner, dataset, dataTiers):
|
26 |
|
|
self.owner = owner
|
27 |
|
|
self.dataset = dataset
|
28 |
|
|
self.dataTiers = dataTiers
|
29 |
afanfani |
1.2 |
self.dbspath=dataset+'/datatier/'+owner
|
30 |
|
|
|
31 |
|
|
self.api = dbsCgiApi.DbsCgiApi(cgiUrl="http://cern.ch/cms-dbs/cgi-bin")
|
32 |
afanfani |
1.1 |
|
33 |
|
|
# ####################################
|
34 |
|
|
def getDatasetProvenance(self):
|
35 |
|
|
"""
|
36 |
|
|
query DBS to get provenance
|
37 |
|
|
"""
|
38 |
afanfani |
1.2 |
datasetParentList = self.api.getDatasetProvenance(self.dbspath,self.dataTiers)
|
39 |
|
|
|
40 |
|
|
parent = {}
|
41 |
|
|
for aparent in datasetParentList:
|
42 |
|
|
print "DBSInfo: parent path is "+aparent.getDatasetPath()+" datatier is: "+aparent.getDataTier()
|
43 |
|
|
parent[aparent.getDatasetPath()]=aparent.getDataTier()
|
44 |
afanfani |
1.1 |
|
45 |
afanfani |
1.2 |
return parent
|
46 |
afanfani |
1.1 |
|
47 |
|
|
# ####################################
|
48 |
|
|
def getDatasetContents(self):
|
49 |
|
|
"""
|
50 |
|
|
query DBS to get event collections
|
51 |
|
|
"""
|
52 |
afanfani |
1.2 |
|
53 |
|
|
fileBlockList = self.api.getDatasetContents(self.dbspath)
|
54 |
afanfani |
1.1 |
|
55 |
|
|
## get the fileblock and event collections
|
56 |
|
|
nevtsbyblock= {}
|
57 |
afanfani |
1.2 |
for fileBlock in fileBlockList:
|
58 |
|
|
## get the event collections for each block
|
59 |
|
|
#print fileBlock.getBlockName()
|
60 |
|
|
#print fileBlock.getBlockId()
|
61 |
|
|
eventCollectionList = fileBlock.getEventCollectionList()
|
62 |
|
|
nevts=0
|
63 |
|
|
for eventCollection in eventCollectionList:
|
64 |
|
|
#print "DBSInfo: evc: "+eventCollection.getCollectionName()+" nevts: %i"%eventCollection.getNumberOfEvents()
|
65 |
|
|
nevts=nevts+eventCollection.getNumberOfEvents()
|
66 |
|
|
print "DBSInfo: total nevts %i in block %s "%(nevts,fileBlock.getBlockName())
|
67 |
|
|
nevtsbyblock[fileBlock.getBlockName()]=nevts
|
68 |
afanfani |
1.1 |
|
69 |
|
|
# returning a map of fileblock-nevts will be enough for now
|
70 |
|
|
# TODO: in future the EvC collections grouped by fileblock should be returned
|
71 |
afanfani |
1.2 |
|
72 |
afanfani |
1.1 |
return nevtsbyblock
|
73 |
|
|
|