ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/DataDiscovery.py
Revision: 1.18
Committed: Fri Nov 16 11:09:31 2007 UTC (17 years, 5 months ago) by slacapra
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_2_0_4, CRAB_2_0_4_pre2, CRAB_2_0_4_pre1, CRAB_2_0_3, CRAB_2_0_3_pre1, CRAB_2_0_2, CRAB_2_0_2_pre6
Changes since 1.17: +95 -33 lines
Log Message:
remove support for DBS1, and remove DBS2 string from  files/class

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     try:
92     dbs_url=self.cfg_params['CMSSW.dbs_url']
93     except KeyError:
94 slacapra 1.18 dbs_url="http://cmsdbsprod.cern.ch/cms_dbs_prod_global/servlet/DBSServlet"
95 afanfani 1.3
96 slacapra 1.18 common.logger.debug(3,"Accessing DBS at: "+dbs_url)
97    
98     ## check if runs are selected
99 slacapra 1.11 try:
100 slacapra 1.18 runselection = parseRange2(self.cfg_params['CMSSW.runselection'])
101     except:
102     runselection = []
103    
104     ## service API
105     args = {}
106     args['url'] = dbs_url
107     args['level'] = 'CRITICAL'
108    
109     api = DBSAPI.dbsApi.DbsApi(args)
110 afanfani 1.5 try:
111 slacapra 1.18 if len(runselection) <= 0 :
112     files = api.listDatasetFiles(self.datasetPath)
113     else :
114     files = api.listFiles(path=self.datasetPath, details=True)
115     except DbsBadRequest, msg:
116 slacapra 1.11 raise DataDiscoveryError(msg)
117 slacapra 1.13 except DBSError, msg:
118     raise DataDiscoveryError(msg)
119 slacapra 1.11
120 slacapra 1.18 # parse files and fill arrays
121     for file in files :
122     filename = file['LogicalFileName']
123     if filename.find('.dat') < 0 :
124     fileblock = file['Block']['Name']
125     events = file['NumberOfEvents']
126     continue_flag = 0
127     if len(runselection) > 0 :
128     runslist = file['RunsList']
129     for run in runslist :
130     runnumber = run['RunNumber']
131     for selected_run in runselection :
132     if runnumber == selected_run :
133     continue_flag = 1
134     else :
135     continue_flag = 1
136    
137     if continue_flag == 1 :
138     # number of events per block
139     if fileblock in self.eventsPerBlock.keys() :
140     self.eventsPerBlock[fileblock] += events
141     else :
142     self.eventsPerBlock[fileblock] = events
143    
144     # number of events per file
145     self.eventsPerFile[filename] = events
146    
147     # number of events per block
148     if fileblock in self.blocksinfo.keys() :
149     self.blocksinfo[fileblock].append(filename)
150     else :
151     self.blocksinfo[fileblock] = [filename]
152    
153     # total number of events
154     self.maxEvents += events
155 slacapra 1.11
156 slacapra 1.18 for block in self.eventsPerBlock.keys() :
157     common.logger.debug(6,"DBSInfo: total nevts %i in block %s "%(self.eventsPerBlock[block],block))
158 slacapra 1.11
159     if len(self.eventsPerBlock) <= 0:
160 slacapra 1.18 raise NotExistingDatasetError(("\nNo data for %s in DBS\nPlease check"
161 slacapra 1.11 + " dataset path variables in crab.cfg")
162 slacapra 1.18 % self.datasetPath)
163 afanfani 1.1
164    
165     # #################################################
166     def getMaxEvents(self):
167     """
168 slacapra 1.11 max events
169 afanfani 1.1 """
170 slacapra 1.18 return self.maxEvents
171 afanfani 1.1
172     # #################################################
173 slacapra 1.11 def getEventsPerBlock(self):
174 afanfani 1.1 """
175 slacapra 1.11 list the event collections structure by fileblock
176 afanfani 1.1 """
177 slacapra 1.11 return self.eventsPerBlock
178 afanfani 1.1
179     # #################################################
180 slacapra 1.11 def getEventsPerFile(self):
181 afanfani 1.1 """
182 slacapra 1.11 list the event collections structure by file
183 afanfani 1.1 """
184 slacapra 1.11 return self.eventsPerFile
185 afanfani 1.1
186     # #################################################
187 slacapra 1.11 def getFiles(self):
188 afanfani 1.1 """
189 slacapra 1.11 return files grouped by fileblock
190 afanfani 1.1 """
191 slacapra 1.11 return self.blocksinfo
192 afanfani 1.1
193     ########################################################################