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
|
11 |
|
12 |
class DBSInfoError:
|
13 |
def __init__(self, url):
|
14 |
print '\nERROR accessing DBS url : '+url+'\n'
|
15 |
pass
|
16 |
|
17 |
##################################################################################
|
18 |
# Class to extract info from DBS
|
19 |
###############################################################################
|
20 |
|
21 |
class DBSInfo:
|
22 |
def __init__(self, dbspath, dataTiers):
|
23 |
self.dbspath=dbspath
|
24 |
self.dataTiers = dataTiers
|
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 |
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 |
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 "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
|
63 |
# TODO: in future the EvC collections grouped by fileblock should be returned
|
64 |
|
65 |
return nevtsbyblock
|
66 |
|