ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/DataDiscovery.py
Revision: 1.15
Committed: Thu Feb 1 16:12:40 2007 UTC (18 years, 2 months ago) by gutsche
Content type: text/x-python
Branch: MAIN
Changes since 1.14: +5 -6 lines
Log Message:
Move DBS-1 APIs to DBS1API namespace. This requires preparation of special DBS checkouts:

- checkout DBSAPIs
    - create directory DBSAPI in $CRABDIR
    - check out COMP/DBS/Clients/PythonAPI into DBSAPI/DBS1API
    - check out COMP/DBS/Clients/Python into DBSAPI/DBS2API
    - create namespace __init__.py in both subdirectories DBS1API and DBS2API
- change configure to add $CRABDIR/DBSAPI to PYTHONPATH and to set
  DBS_CLIENT_CONFIG

File Contents

# User Rev Content
1 gutsche 1.6 #!/usr/bin/env python
2 afanfani 1.1 from DBSInfo import *
3    
4 afanfani 1.3
5 afanfani 1.1 # ####################################
6 afanfani 1.3 class DataDiscoveryError(exceptions.Exception):
7 slacapra 1.7 def __init__(self, errorMessage):
8 gutsche 1.15 self.args=errorMessage
9 slacapra 1.14 exceptions.Exception.__init__(self, self.args)
10 slacapra 1.7 pass
11    
12     def getErrorMessage(self):
13     """ Return exception error """
14     return "%s" % (self.args)
15 afanfani 1.3
16 afanfani 1.1 # ####################################
17 afanfani 1.3 class NotExistingDatasetError(exceptions.Exception):
18 slacapra 1.7 def __init__(self, errorMessage):
19 gutsche 1.15 self.args=errorMessage
20 slacapra 1.14 exceptions.Exception.__init__(self, self.args)
21 slacapra 1.7 pass
22    
23     def getErrorMessage(self):
24     """ Return exception error """
25     return "%s" % (self.args)
26 afanfani 1.1
27     # ####################################
28 afanfani 1.3 class NoDataTierinProvenanceError(exceptions.Exception):
29 slacapra 1.7 def __init__(self, errorMessage):
30 gutsche 1.15 self.args=errorMessage
31 slacapra 1.14 exceptions.Exception.__init__(self, self.args)
32 slacapra 1.7 pass
33    
34     def getErrorMessage(self):
35     """ Return exception error """
36     return "%s" % (self.args)
37 afanfani 1.1
38     # ####################################
39     # class to find and extact info from published data
40     class DataDiscovery:
41 gutsche 1.15 def __init__(self, datasetPath, cfg_params):
42 afanfani 1.1
43     # Attributes
44 slacapra 1.11 self.datasetPath = datasetPath
45 afanfani 1.1 self.cfg_params = cfg_params
46    
47 slacapra 1.11 self.eventsPerBlock = {} # DBS output: map fileblocks-events for collection
48     self.eventsPerFile = {} # DBS output: map files-events
49     self.blocksinfo = {} # DBS output: map fileblocks-files
50 afanfani 1.1 #DBS output: max events computed by method getMaxEvents
51    
52     # ####################################
53     def fetchDBSInfo(self):
54     """
55     Contact DBS
56     """
57    
58 slacapra 1.11 ## get DBS URL
59     try:
60     dbs_url=self.cfg_params['CMSSW.dbs_url']
61     except KeyError:
62     dbs_url="http://cmsdoc.cern.ch/cms/test/aprom/DBS/CGIServer/prodquery"
63 afanfani 1.3
64 slacapra 1.11 ## get info about the requested dataset
65     try:
66     dbs_instance=self.cfg_params['CMSSW.dbs_instance']
67     except KeyError:
68 gutsche 1.12 dbs_instance="MCGlobal/Writer"
69 slacapra 1.11
70     dbs = DBSInfo(dbs_url, dbs_instance)
71 afanfani 1.5 try:
72 slacapra 1.11 self.datasets = dbs.getMatchingDatasets(self.datasetPath)
73 gutsche 1.15 except DBS1API.dbsCgiApi.DbsCgiExecutionError, msg:
74 slacapra 1.11 raise DataDiscoveryError(msg)
75 slacapra 1.13 except DBSError, msg:
76     raise DataDiscoveryError(msg)
77 slacapra 1.11
78 afanfani 1.4 if len(self.datasets) == 0:
79 slacapra 1.11 raise DataDiscoveryError("DatasetPath=%s unknown to DBS" %self.datasetPath)
80 afanfani 1.4 if len(self.datasets) > 1:
81 slacapra 1.11 raise DataDiscoveryError("DatasetPath=%s is ambiguous" %self.datasetPath)
82    
83 afanfani 1.1 try:
84 slacapra 1.7 self.dbsdataset = self.datasets[0].get('datasetPathName')
85 slacapra 1.11
86     self.eventsPerBlock = dbs.getEventsPerBlock(self.dbsdataset)
87     self.blocksinfo = dbs.getDatasetFileBlocks(self.dbsdataset)
88     self.eventsPerFile = dbs.getEventsPerFile(self.dbsdataset)
89 afanfani 1.3 except DBSError, ex:
90 slacapra 1.7 raise DataDiscoveryError(ex.getErrorMessage())
91 afanfani 1.3
92 slacapra 1.11 if len(self.eventsPerBlock) <= 0:
93     raise NotExistingDatasetError (("\nNo data for %s in DBS\nPlease check"
94     + " dataset path variables in crab.cfg")
95     % self.dbsdataset)
96 afanfani 1.1
97    
98     # #################################################
99     def getMaxEvents(self):
100     """
101 slacapra 1.11 max events
102 afanfani 1.1 """
103 slacapra 1.11 ## loop over the event collections
104 afanfani 1.1 nevts=0
105 slacapra 1.11 for evc_evts in self.eventsPerBlock.values():
106     nevts=nevts+evc_evts
107 afanfani 1.1
108     return nevts
109    
110     # #################################################
111 slacapra 1.11 def getEventsPerBlock(self):
112 afanfani 1.1 """
113 slacapra 1.11 list the event collections structure by fileblock
114 afanfani 1.1 """
115 slacapra 1.11 return self.eventsPerBlock
116 afanfani 1.1
117     # #################################################
118 slacapra 1.11 def getEventsPerFile(self):
119 afanfani 1.1 """
120 slacapra 1.11 list the event collections structure by file
121 afanfani 1.1 """
122 slacapra 1.11 return self.eventsPerFile
123 afanfani 1.1
124     # #################################################
125 slacapra 1.11 def getFiles(self):
126 afanfani 1.1 """
127 slacapra 1.11 return files grouped by fileblock
128 afanfani 1.1 """
129 slacapra 1.11 return self.blocksinfo
130 afanfani 1.1
131     ########################################################################