ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/DBSInfo_EDM.py
Revision: 1.5
Committed: Tue Jun 20 09:39:22 2006 UTC (18 years, 10 months ago) by slacapra
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_1_2_1, CRAB_1_2_0, CRAB_1_2_0_pre9, CRAB_1_2_0_pre8, CRAB_1_2_0_pre7
Branch point for: CRAB_BOSS4_v1, CRAB_BOSS4
Changes since 1.4: +97 -98 lines
Log Message:
indenting in python is 4 spaces

File Contents

# User Rev Content
1 gutsche 1.1 #!/usr/bin/env python
2 afanfani 1.3 import sys, os, string, re, commands
3 gutsche 1.1 import exceptions
4 afanfani 1.4 import common
5     from crab_exceptions import *
6 gutsche 1.1 try:
7 afanfani 1.3 import dbsCgiApi
8     import dbsApi
9 gutsche 1.1 except:
10 afanfani 1.3 try:
11     Crabpydir=commands.getoutput('which crab')
12     Topdir=string.replace(Crabpydir,'/python/crab','')
13     sys.path.append(Topdir+'/DBSAPI')
14     import dbsCgiApi
15     import dbsApi
16     except:
17     msg="ERROR no DBS API available"
18     raise CrabException(msg)
19    
20     ## for python 2.2 add the pyexpat.so to PYTHONPATH
21     pythonV=sys.version.split(' ')[0]
22     if pythonV.find('2.2') >= 0 :
23 slacapra 1.5 Crabpydir=commands.getoutput('which crab')
24     Topdir=string.replace(Crabpydir,'/python/crab','')
25     extradir=Topdir+'/DLSAPI/extra'
26     if sys.path.count(extradir) <= 0:
27     if os.path.exists(extradir):
28     sys.path.insert(0, extradir)
29 gutsche 1.1
30     # #######################################
31     class DBSError(exceptions.Exception):
32 slacapra 1.5 def __init__(self, errorName, errorMessage):
33     args='\nERROR DBS %s : %s \n'%(errorName,errorMessage)
34     exceptions.Exception.__init__(self, args)
35     pass
36    
37     def getErrorMessage(self):
38     """ Return error message """
39     return "%s" % (self.args)
40 gutsche 1.1
41     # #######################################
42     class DBSInvalidDataTierError(exceptions.Exception):
43 slacapra 1.5 def __init__(self, errorName, errorMessage):
44     args='\nERROR DBS %s : %s \n'%(errorName,errorMessage)
45     exceptions.Exception.__init__(self, args)
46     pass
47    
48     def getErrorMessage(self):
49     """ Return error message """
50     return "%s" % (self.args)
51 gutsche 1.1
52     # #######################################
53     class DBSInfoError:
54 slacapra 1.5 def __init__(self, url):
55     print '\nERROR accessing DBS url : '+url+'\n'
56     pass
57 gutsche 1.1
58     ##################################################################################
59     # Class to extract info from DBS
60     ###############################################################################
61    
62     class DBSInfo_EDM:
63 slacapra 1.5 def __init__(self, dbs_instance):
64     """
65     Construct api object.
66     """
67     ## cgi service API
68     DEFAULT_URL = "http://cmsdoc.cern.ch/cms/aprom/DBS/CGIServer/prodquery"
69     args = {}
70     args['instance']=dbs_instance
71    
72     self.api = dbsCgiApi.DbsCgiApi(DEFAULT_URL, args)
73     ## set log level
74     # self.api.setLogLevel(dbsApi.DBS_LOG_LEVEL_INFO_)
75     #self.api.setLogLevel(dbsApi.DBS_LOG_LEVEL_QUIET_)
76    
77     def getMatchingDatasets (self, datasetPath):
78     """ Query DBS to get provenance """
79     try:
80     list = self.api.listProcessedDatasets("%s" %datasetPath)
81     except dbsApi.InvalidDataTier, ex:
82     raise DBSInvalidDataTierError(ex.getClassName(),ex.getErrorMessage())
83     except dbsApi.DbsApiException, ex:
84     raise DBSError(ex.getClassName(),ex.getErrorMessage())
85     except dbsCgiApi.DbsCgiToolError , ex:
86     raise DBSError(ex.getClassName(),ex.getErrorMessage())
87    
88     return list
89    
90    
91     def getDatasetProvenance(self, path, dataTiers):
92     """ Query DBS to get provenance """
93     try:
94     datasetParentList = self.api.getDatasetProvenance(path,dataTiers)
95     except dbsApi.InvalidDataTier, ex:
96     raise DBSInvalidDataTierError(ex.getClassName(),ex.getErrorMessage())
97     except dbsApi.DbsApiException, ex:
98     raise DBSError(ex.getClassName(),ex.getErrorMessage())
99     return datasetParentList
100    
101     def getDatasetContents(self, path):
102     """ Query DBS to get event collections """
103     # count events per block
104     nevtsbyblock = {}
105     try:
106     for fileBlock in self.api.getDatasetContents (path):
107     ## get the event collections for each block
108     nevts = 0
109     for evc in fileBlock.get('eventCollectionList'):
110     nevts = nevts + evc.get('numberOfEvents')
111     common.logger.debug(6,"DBSInfo: total nevts %i in block %s "%(nevts,fileBlock.get('blockName')))
112     nevtsbyblock[fileBlock.get('blockName')]=nevts
113     except dbsApi.DbsApiException, ex:
114     raise DBSError(ex.getClassName(),ex.getErrorMessage())
115    
116     # returning a map of fileblock-nevts will be enough for now
117     # TODO: in future the EvC collections grouped by fileblock should be returned
118     return nevtsbyblock
119    
120    
121     def getDatasetFileBlocks(self, path):
122     """ Query DBS to get files/fileblocks """
123     try:
124     FilesbyBlock={}
125     for fileBlock in self.api.getDatasetFileBlocks(path):
126     blockname=fileBlock.get('blockName')
127     filesinblock=[]
128     for files in fileBlock.get('fileList'):
129     #print " block %s has file %s"%(blockname,files.getLogicalFileName())
130     filesinblock.append(files.get('logicalFileName'))
131     FilesbyBlock[blockname]=filesinblock
132     except dbsApi.DbsApiException, ex:
133     raise DBSError(ex.getClassName(),ex.getErrorMessage())
134 gutsche 1.1
135 slacapra 1.5 return FilesbyBlock