1 |
afanfani |
1.1 |
#!/usr/bin/env python
|
2 |
|
|
import sys, os, string, re
|
3 |
afanfani |
1.4 |
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 |
afanfani |
1.1 |
|
35 |
afanfani |
1.4 |
# #######################################
|
36 |
afanfani |
1.1 |
class DBSInfoError:
|
37 |
|
|
def __init__(self, url):
|
38 |
|
|
print '\nERROR accessing DBS url : '+url+'\n'
|
39 |
|
|
pass
|
40 |
|
|
|
41 |
|
|
##################################################################################
|
42 |
|
|
# Class to extract info from DBS
|
43 |
|
|
###############################################################################
|
44 |
|
|
|
45 |
|
|
class DBSInfo:
|
46 |
afanfani |
1.3 |
def __init__(self, dbspath, dataTiers):
|
47 |
|
|
self.dbspath=dbspath
|
48 |
afanfani |
1.1 |
self.dataTiers = dataTiers
|
49 |
afanfani |
1.4 |
# Construct api object
|
50 |
afanfani |
1.2 |
self.api = dbsCgiApi.DbsCgiApi(cgiUrl="http://cern.ch/cms-dbs/cgi-bin")
|
51 |
afanfani |
1.4 |
# 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 |
afanfani |
1.1 |
|
56 |
|
|
# ####################################
|
57 |
|
|
def getDatasetProvenance(self):
|
58 |
|
|
"""
|
59 |
|
|
query DBS to get provenance
|
60 |
|
|
"""
|
61 |
afanfani |
1.3 |
try:
|
62 |
|
|
datasetParentList = self.api.getDatasetProvenance(self.dbspath,self.dataTiers)
|
63 |
afanfani |
1.4 |
except dbsApi.InvalidDataTier, ex:
|
64 |
|
|
raise DBSInvalidDataTierError(ex.getClassName(),ex.getErrorMessage())
|
65 |
|
|
except dbsApi.DbsApiException, ex:
|
66 |
|
|
raise DBSError(ex.getClassName(),ex.getErrorMessage())
|
67 |
afanfani |
1.3 |
return datasetParentList
|
68 |
afanfani |
1.4 |
#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 |
afanfani |
1.1 |
# ####################################
|
76 |
|
|
def getDatasetContents(self):
|
77 |
|
|
"""
|
78 |
|
|
query DBS to get event collections
|
79 |
|
|
"""
|
80 |
afanfani |
1.3 |
try:
|
81 |
|
|
fileBlockList = self.api.getDatasetContents(self.dbspath)
|
82 |
afanfani |
1.4 |
except dbsApi.DbsApiException, ex:
|
83 |
|
|
raise DBSError(ex.getClassName(),ex.getErrorMessage())
|
84 |
afanfani |
1.1 |
## get the fileblock and event collections
|
85 |
|
|
nevtsbyblock= {}
|
86 |
afanfani |
1.2 |
for fileBlock in fileBlockList:
|
87 |
|
|
## get the event collections for each block
|
88 |
afanfani |
1.4 |
#print fileBlock.getBlockName()
|
89 |
|
|
#print fileBlock.getBlockId()
|
90 |
afanfani |
1.2 |
eventCollectionList = fileBlock.getEventCollectionList()
|
91 |
|
|
nevts=0
|
92 |
|
|
for eventCollection in eventCollectionList:
|
93 |
|
|
#print "DBSInfo: evc: "+eventCollection.getCollectionName()+" nevts: %i"%eventCollection.getNumberOfEvents()
|
94 |
afanfani |
1.4 |
#common.logger.debug(20,"DBSInfo: evc: "+eventCollection.getCollectionName()+" nevts:%i"%eventCollection.getNumberOfEvents())
|
95 |
|
|
#print "DBSInfo: evc: "+eventCollection.getCollectionName()+" nevts:%i"%eventCollection.getNumberOfEvents()
|
96 |
afanfani |
1.2 |
nevts=nevts+eventCollection.getNumberOfEvents()
|
97 |
afanfani |
1.4 |
#common.logger.debug(6,"DBSInfo: total nevts %i in block %s "%(nevts,fileBlock.getBlockName()))
|
98 |
afanfani |
1.2 |
print "DBSInfo: total nevts %i in block %s "%(nevts,fileBlock.getBlockName())
|
99 |
|
|
nevtsbyblock[fileBlock.getBlockName()]=nevts
|
100 |
afanfani |
1.1 |
|
101 |
|
|
# returning a map of fileblock-nevts will be enough for now
|
102 |
|
|
# TODO: in future the EvC collections grouped by fileblock should be returned
|
103 |
afanfani |
1.2 |
|
104 |
afanfani |
1.1 |
return nevtsbyblock
|
105 |
|
|
|