ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/DBS/Clients/CRABStandalone/DBSInfo.py
Revision: 1.4
Committed: Sat Jan 28 23:09:20 2006 UTC (19 years, 3 months ago) by afanfani
Content type: text/x-python
Branch: MAIN
CVS Tags: AfterJan2006SchemaChanges_v01_00_01, AfterJan2006SchemaChanges_v01_00_00, AfterJan2006SchemaChanges, BeforeJan2006SchemaChanges
Branch point for: BranchForCPPWebServiceTesting
Changes since 1.3: +55 -16 lines
Log Message:
update to API changes and improved error handling

File Contents

# Content
1 #!/usr/bin/env python
2 import sys, os, string, re
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'
39 pass
40
41 ##################################################################################
42 # Class to extract info from DBS
43 ###############################################################################
44
45 class DBSInfo:
46 def __init__(self, dbspath, dataTiers):
47 self.dbspath=dbspath
48 self.dataTiers = dataTiers
49 # Construct api object
50 self.api = dbsCgiApi.DbsCgiApi(cgiUrl="http://cern.ch/cms-dbs/cgi-bin")
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):
58 """
59 query DBS to get provenance
60 """
61 try:
62 datasetParentList = self.api.getDatasetProvenance(self.dbspath,self.dataTiers)
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 """
78 query DBS to get event collections
79 """
80 try:
81 fileBlockList = self.api.getDatasetContents(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 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()
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
102 # TODO: in future the EvC collections grouped by fileblock should be returned
103
104 return nevtsbyblock
105