1 |
|
#!/usr/bin/env python |
2 |
|
import sys, os, string, re |
3 |
< |
sys.path.append('./DBSAPI') |
4 |
< |
import dbsCgiApi |
5 |
< |
import dbsApi |
6 |
< |
|
7 |
< |
class DBSError: |
8 |
< |
def __init__(self, dbspath): |
9 |
< |
print '\nERROR accessing DBS for dataset '+dbspath+'\n' |
10 |
< |
pass |
3 |
> |
import exceptions |
4 |
> |
try: |
5 |
> |
sys.path.append('./DBSAPI') |
6 |
> |
import dbsCgiApi |
7 |
> |
import dbsApi |
8 |
> |
except: |
9 |
> |
msg="ERROR no DBS API available" |
10 |
> |
raise CrabException(msg) |
11 |
> |
|
12 |
> |
|
13 |
> |
# ####################################### |
14 |
> |
class DBSError(exceptions.Exception): |
15 |
> |
def __init__(self, errorName, errorMessage): |
16 |
> |
args='\nERROR DBS %s : %s \n'%(errorName,errorMessage) |
17 |
> |
exceptions.Exception.__init__(self, args) |
18 |
> |
pass |
19 |
> |
|
20 |
> |
def getErrorMessage(self): |
21 |
> |
""" Return error message """ |
22 |
> |
return "%s" % (self.args) |
23 |
> |
|
24 |
> |
# ####################################### |
25 |
> |
class DBSInvalidDataTierError(exceptions.Exception): |
26 |
> |
def __init__(self, errorName, errorMessage): |
27 |
> |
args='\nERROR DBS %s : %s \n'%(errorName,errorMessage) |
28 |
> |
exceptions.Exception.__init__(self, args) |
29 |
> |
pass |
30 |
> |
|
31 |
> |
def getErrorMessage(self): |
32 |
> |
""" Return error message """ |
33 |
> |
return "%s" % (self.args) |
34 |
|
|
35 |
+ |
# ####################################### |
36 |
|
class DBSInfoError: |
37 |
|
def __init__(self, url): |
38 |
|
print '\nERROR accessing DBS url : '+url+'\n' |
46 |
|
def __init__(self, dbspath, dataTiers): |
47 |
|
self.dbspath=dbspath |
48 |
|
self.dataTiers = dataTiers |
49 |
< |
|
49 |
> |
# Construct api object |
50 |
|
self.api = dbsCgiApi.DbsCgiApi(cgiUrl="http://cern.ch/cms-dbs/cgi-bin") |
51 |
< |
# self.api.setLogLevel(dbsApi.DBS_LOG_LEVEL_ALL_) |
51 |
> |
# Configure api logging |
52 |
> |
self.api.setLogLevel(dbsApi.DBS_LOG_LEVEL_ALL_) |
53 |
> |
self.api.setLogLevel(dbsApi.DBS_LOG_LEVEL_INFO_) |
54 |
> |
# lower log level |
55 |
|
|
56 |
|
# #################################### |
57 |
|
def getDatasetProvenance(self): |
60 |
|
""" |
61 |
|
try: |
62 |
|
datasetParentList = self.api.getDatasetProvenance(self.dbspath,self.dataTiers) |
63 |
< |
except dbsCgiApi.DbsCgiApiException: |
64 |
< |
raise DBSError(self.dbspath) |
63 |
> |
except dbsApi.InvalidDataTier, ex: |
64 |
> |
raise DBSInvalidDataTierError(ex.getClassName(),ex.getErrorMessage()) |
65 |
> |
except dbsApi.DbsApiException, ex: |
66 |
> |
raise DBSError(ex.getClassName(),ex.getErrorMessage()) |
67 |
|
return datasetParentList |
68 |
+ |
#parent = {} |
69 |
+ |
#for aparent in datasetParentList: |
70 |
+ |
# common.logger.debug(6, "DBSInfo: parent path is "+aparent.getDatasetPath()+" datatier is "+aparent.getDataTier()) |
71 |
+ |
# parent[aparent.getDatasetPath()]=aparent.getDataTier() |
72 |
+ |
# |
73 |
+ |
#return parent |
74 |
+ |
|
75 |
|
# #################################### |
76 |
|
def getDatasetContents(self): |
77 |
|
""" |
79 |
|
""" |
80 |
|
try: |
81 |
|
fileBlockList = self.api.getDatasetContents(self.dbspath) |
82 |
< |
except dbsCgiApi.DbsCgiApiException: |
83 |
< |
raise DBSError(self.dbspath) |
82 |
> |
except dbsApi.DbsApiException, ex: |
83 |
> |
raise DBSError(ex.getClassName(),ex.getErrorMessage()) |
84 |
|
## get the fileblock and event collections |
85 |
|
nevtsbyblock= {} |
86 |
|
for fileBlock in fileBlockList: |
87 |
|
## get the event collections for each block |
88 |
< |
print "DBSInfo: --- block: "+fileBlock.getBlockName() |
88 |
> |
#print fileBlock.getBlockName() |
89 |
> |
#print fileBlock.getBlockId() |
90 |
|
eventCollectionList = fileBlock.getEventCollectionList() |
91 |
|
nevts=0 |
92 |
|
for eventCollection in eventCollectionList: |
93 |
|
#print "DBSInfo: evc: "+eventCollection.getCollectionName()+" nevts: %i"%eventCollection.getNumberOfEvents() |
94 |
+ |
#common.logger.debug(20,"DBSInfo: evc: "+eventCollection.getCollectionName()+" nevts:%i"%eventCollection.getNumberOfEvents()) |
95 |
+ |
#print "DBSInfo: evc: "+eventCollection.getCollectionName()+" nevts:%i"%eventCollection.getNumberOfEvents() |
96 |
|
nevts=nevts+eventCollection.getNumberOfEvents() |
58 |
– |
print "DBSInfo: total nevts %i in block %s "%(nevts,fileBlock.getBlockName()) |
97 |
|
#common.logger.debug(6,"DBSInfo: total nevts %i in block %s "%(nevts,fileBlock.getBlockName())) |
98 |
+ |
print "DBSInfo: total nevts %i in block %s "%(nevts,fileBlock.getBlockName()) |
99 |
|
nevtsbyblock[fileBlock.getBlockName()]=nevts |
100 |
|
|
101 |
|
# returning a map of fileblock-nevts will be enough for now |