ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/DataDiscovery.py
Revision: 1.20
Committed: Fri Jan 11 22:11:55 2008 UTC (17 years, 3 months ago) by afanfani
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_2_2_2_pre2, CRAB_2_2_2_pre1, CRAB_2_2_1, CRAB_2_2_1_pre6, CRAB_2_2_1_pre5, CRAB_2_2_1_pre4, PRODCOMMON_0_10_7_testCS2, CRAB_2_2_1_pre3, CRAB_2_2_1_pre2, CRAB_2_2_1_pre1, CRAB_2_2_0, CRAB_2_2_0_pre21, CRAB_2_2_0_pre19, CRAB_2_2_0_pre18, CRAB_2_2_0_pre17, CRAB_2_2_0_pre16, CRAB_2_2_0_pre15, CRAB_2_2_0_pre13, CRAB_2_2_0_pre12, CRAB_2_2_0_pre11, CRAB_2_2_0_pre10, bp_osg_bdii, CRAB_2_2_0_pre9, CRAB_2_2_0_pre8, CRAB_2_2_0_pre7, CRAB_2_1_2, CRAB_2_2_0_pre5, CRAB_2_1_2_pre2, CRAB_2_1_2_pre1, CRAB_2_2_0_pre4, CRAB_2_2_0_pre2, CRAB_2_1_1, CRAB_2_1_1_pre3, CRAB_2_2_0_pre1, CRAB_2_1_1_pre1, CRAB_2_1_0, CRAB_2_1_0_pre6, CRAB_2_1_0_pre5, CRAB_2_1_0_pre4, CRAB_2_1_0_pre3
Branch point for: osg_bdii, CRAB_2_1_2_br, CRAB_2_1_1_pre2
Changes since 1.19: +25 -28 lines
Log Message:
if runselection is provided switch to use listFiles DBS API with run option
since it's much faster.

File Contents

# User Rev Content
1 gutsche 1.6 #!/usr/bin/env python
2 slacapra 1.18 import exceptions
3     import DBSAPI.dbsApi
4     from DBSAPI.dbsApiException import *
5     import common
6     from crab_util import *
7 afanfani 1.1
8 afanfani 1.3
9 slacapra 1.18 # #######################################
10     class DBSError(exceptions.Exception):
11     def __init__(self, errorName, errorMessage):
12     args='\nERROR DBS %s : %s \n'%(errorName,errorMessage)
13     exceptions.Exception.__init__(self, args)
14     pass
15    
16     def getErrorMessage(self):
17     """ Return error message """
18     return "%s" % (self.args)
19    
20     # #######################################
21     class DBSInvalidDataTierError(exceptions.Exception):
22     def __init__(self, errorName, errorMessage):
23     args='\nERROR DBS %s : %s \n'%(errorName,errorMessage)
24     exceptions.Exception.__init__(self, args)
25     pass
26    
27     def getErrorMessage(self):
28     """ Return error message """
29     return "%s" % (self.args)
30    
31     # #######################################
32     class DBSInfoError:
33     def __init__(self, url):
34     print '\nERROR accessing DBS url : '+url+'\n'
35     pass
36    
37 afanfani 1.1 # ####################################
38 afanfani 1.3 class DataDiscoveryError(exceptions.Exception):
39 slacapra 1.7 def __init__(self, errorMessage):
40 gutsche 1.15 self.args=errorMessage
41 slacapra 1.14 exceptions.Exception.__init__(self, self.args)
42 slacapra 1.7 pass
43    
44     def getErrorMessage(self):
45     """ Return exception error """
46     return "%s" % (self.args)
47 afanfani 1.3
48 afanfani 1.1 # ####################################
49 afanfani 1.3 class NotExistingDatasetError(exceptions.Exception):
50 slacapra 1.7 def __init__(self, errorMessage):
51 gutsche 1.15 self.args=errorMessage
52 slacapra 1.14 exceptions.Exception.__init__(self, self.args)
53 slacapra 1.7 pass
54    
55     def getErrorMessage(self):
56     """ Return exception error """
57     return "%s" % (self.args)
58 afanfani 1.1
59     # ####################################
60 afanfani 1.3 class NoDataTierinProvenanceError(exceptions.Exception):
61 slacapra 1.7 def __init__(self, errorMessage):
62 gutsche 1.15 self.args=errorMessage
63 slacapra 1.14 exceptions.Exception.__init__(self, self.args)
64 slacapra 1.7 pass
65    
66     def getErrorMessage(self):
67     """ Return exception error """
68     return "%s" % (self.args)
69 afanfani 1.1
70     # ####################################
71     # class to find and extact info from published data
72     class DataDiscovery:
73 gutsche 1.15 def __init__(self, datasetPath, cfg_params):
74 afanfani 1.1
75 slacapra 1.18 # Attributes
76 slacapra 1.11 self.datasetPath = datasetPath
77 afanfani 1.1 self.cfg_params = cfg_params
78    
79 slacapra 1.11 self.eventsPerBlock = {} # DBS output: map fileblocks-events for collection
80     self.eventsPerFile = {} # DBS output: map files-events
81 slacapra 1.18 self.blocksinfo = {} # DBS output: map fileblocks-files
82     self.maxEvents = 0 # DBS output: max events
83 afanfani 1.1
84     # ####################################
85     def fetchDBSInfo(self):
86     """
87     Contact DBS
88     """
89    
90 slacapra 1.11 ## get DBS URL
91 slacapra 1.19 dbs_url="http://cmsdbsprod.cern.ch/cms_dbs_prod_global/servlet/DBSServlet"
92     if (self.cfg_params.has_key('CMSSW.dbs_url')):
93 slacapra 1.11 dbs_url=self.cfg_params['CMSSW.dbs_url']
94 afanfani 1.3
95 slacapra 1.18 common.logger.debug(3,"Accessing DBS at: "+dbs_url)
96    
97     ## check if runs are selected
98 slacapra 1.19 runselection = []
99     if (self.cfg_params.has_key('CMSSW.runselection')):
100 slacapra 1.18 runselection = parseRange2(self.cfg_params['CMSSW.runselection'])
101    
102 afanfani 1.20 common.logger.debug(6,"runselection is: %s"%runselection)
103 slacapra 1.18 ## service API
104     args = {}
105     args['url'] = dbs_url
106     args['level'] = 'CRITICAL'
107    
108     api = DBSAPI.dbsApi.DbsApi(args)
109 afanfani 1.5 try:
110 slacapra 1.18 if len(runselection) <= 0 :
111     files = api.listDatasetFiles(self.datasetPath)
112     else :
113 afanfani 1.20 files=[]
114     for arun in runselection:
115     try:
116     filesinrun = api.listFiles(path=self.datasetPath, details=True,runNumber=arun)
117     files.extend(filesinrun)
118     except:
119     msg="WARNING: problem extracting info from DBS for run %s "%arun
120     common.logger.message(msg)
121     pass
122    
123 slacapra 1.18 except DbsBadRequest, msg:
124 slacapra 1.11 raise DataDiscoveryError(msg)
125 slacapra 1.13 except DBSError, msg:
126     raise DataDiscoveryError(msg)
127 slacapra 1.11
128 slacapra 1.18 # parse files and fill arrays
129     for file in files :
130     filename = file['LogicalFileName']
131     if filename.find('.dat') < 0 :
132     fileblock = file['Block']['Name']
133     events = file['NumberOfEvents']
134 afanfani 1.20 # number of events per block
135     if fileblock in self.eventsPerBlock.keys() :
136     self.eventsPerBlock[fileblock] += events
137     else :
138     self.eventsPerBlock[fileblock] = events
139     # number of events per file
140     self.eventsPerFile[filename] = events
141    
142     # number of events per block
143     if fileblock in self.blocksinfo.keys() :
144     self.blocksinfo[fileblock].append(filename)
145 slacapra 1.18 else :
146 afanfani 1.20 self.blocksinfo[fileblock] = [filename]
147 slacapra 1.18
148 afanfani 1.20 # total number of events
149     self.maxEvents += events
150 slacapra 1.11
151 slacapra 1.18 for block in self.eventsPerBlock.keys() :
152     common.logger.debug(6,"DBSInfo: total nevts %i in block %s "%(self.eventsPerBlock[block],block))
153 slacapra 1.11
154     if len(self.eventsPerBlock) <= 0:
155 slacapra 1.18 raise NotExistingDatasetError(("\nNo data for %s in DBS\nPlease check"
156 slacapra 1.11 + " dataset path variables in crab.cfg")
157 slacapra 1.18 % self.datasetPath)
158 afanfani 1.1
159    
160     # #################################################
161     def getMaxEvents(self):
162     """
163 slacapra 1.11 max events
164 afanfani 1.1 """
165 slacapra 1.18 return self.maxEvents
166 afanfani 1.1
167     # #################################################
168 slacapra 1.11 def getEventsPerBlock(self):
169 afanfani 1.1 """
170 slacapra 1.11 list the event collections structure by fileblock
171 afanfani 1.1 """
172 slacapra 1.11 return self.eventsPerBlock
173 afanfani 1.1
174     # #################################################
175 slacapra 1.11 def getEventsPerFile(self):
176 afanfani 1.1 """
177 slacapra 1.11 list the event collections structure by file
178 afanfani 1.1 """
179 slacapra 1.11 return self.eventsPerFile
180 afanfani 1.1
181     # #################################################
182 slacapra 1.11 def getFiles(self):
183 afanfani 1.1 """
184 slacapra 1.11 return files grouped by fileblock
185 afanfani 1.1 """
186 slacapra 1.11 return self.blocksinfo
187 afanfani 1.1
188     ########################################################################