1 |
|
#!/usr/bin/env python |
2 |
|
import sys, os, string, re |
3 |
– |
import xml.sax |
4 |
– |
import urllib |
5 |
– |
|
6 |
– |
import sys |
3 |
|
sys.path.append('./DBSAPI') |
4 |
|
import dbsCgiApi |
5 |
+ |
import dbsApi |
6 |
|
|
7 |
|
class DBSError: |
8 |
< |
def __init__(self, owner, dataset): |
9 |
< |
print '\nERROR accessing DBS for Owner/Dataset: '+owner+'/'+dataset+'\n' |
8 |
> |
def __init__(self, dbspath): |
9 |
> |
print '\nERROR accessing DBS for dataset '+dbspath+'\n' |
10 |
|
pass |
11 |
|
|
12 |
|
class DBSInfoError: |
19 |
|
############################################################################### |
20 |
|
|
21 |
|
class DBSInfo: |
22 |
< |
def __init__(self, owner, dataset, dataTiers): |
23 |
< |
self.owner = owner |
27 |
< |
self.dataset = dataset |
22 |
> |
def __init__(self, dbspath, dataTiers): |
23 |
> |
self.dbspath=dbspath |
24 |
|
self.dataTiers = dataTiers |
29 |
– |
self.dbspath=dataset+'/datatier/'+owner |
25 |
|
|
26 |
|
self.api = dbsCgiApi.DbsCgiApi(cgiUrl="http://cern.ch/cms-dbs/cgi-bin") |
27 |
+ |
# self.api.setLogLevel(dbsApi.DBS_LOG_LEVEL_ALL_) |
28 |
|
|
29 |
|
# #################################### |
30 |
|
def getDatasetProvenance(self): |
31 |
|
""" |
32 |
|
query DBS to get provenance |
33 |
|
""" |
34 |
< |
datasetParentList = self.api.getDatasetProvenance(self.dbspath,self.dataTiers) |
35 |
< |
|
36 |
< |
parent = {} |
37 |
< |
for aparent in datasetParentList: |
38 |
< |
print "DBSInfo: parent path is "+aparent.getDatasetPath()+" datatier is: "+aparent.getDataTier() |
43 |
< |
parent[aparent.getDatasetPath()]=aparent.getDataTier() |
44 |
< |
|
45 |
< |
return parent |
46 |
< |
|
34 |
> |
try: |
35 |
> |
datasetParentList = self.api.getDatasetProvenance(self.dbspath,self.dataTiers) |
36 |
> |
except dbsCgiApi.DbsCgiApiException: |
37 |
> |
raise DBSError(self.dbspath) |
38 |
> |
return datasetParentList |
39 |
|
# #################################### |
40 |
|
def getDatasetContents(self): |
41 |
|
""" |
42 |
|
query DBS to get event collections |
43 |
|
""" |
44 |
< |
|
45 |
< |
fileBlockList = self.api.getDatasetContents(self.dbspath) |
46 |
< |
|
44 |
> |
try: |
45 |
> |
fileBlockList = self.api.getDatasetContents(self.dbspath) |
46 |
> |
except dbsCgiApi.DbsCgiApiException: |
47 |
> |
raise DBSError(self.dbspath) |
48 |
|
## get the fileblock and event collections |
49 |
|
nevtsbyblock= {} |
50 |
|
for fileBlock in fileBlockList: |
51 |
|
## get the event collections for each block |
52 |
< |
#print fileBlock.getBlockName() |
60 |
< |
#print fileBlock.getBlockId() |
52 |
> |
print "DBSInfo: --- block: "+fileBlock.getBlockName() |
53 |
|
eventCollectionList = fileBlock.getEventCollectionList() |
54 |
|
nevts=0 |
55 |
|
for eventCollection in eventCollectionList: |
56 |
|
#print "DBSInfo: evc: "+eventCollection.getCollectionName()+" nevts: %i"%eventCollection.getNumberOfEvents() |
57 |
|
nevts=nevts+eventCollection.getNumberOfEvents() |
58 |
|
print "DBSInfo: total nevts %i in block %s "%(nevts,fileBlock.getBlockName()) |
59 |
+ |
#common.logger.debug(6,"DBSInfo: total nevts %i in block %s "%(nevts,fileBlock.getBlockName())) |
60 |
|
nevtsbyblock[fileBlock.getBlockName()]=nevts |
61 |
|
|
62 |
|
# returning a map of fileblock-nevts will be enough for now |