ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/DataDiscovery.py
(Generate patch)

Comparing COMP/CRAB/python/DataDiscovery.py (file contents):
Revision 1.3 by afanfani, Sun Jan 29 01:46:08 2006 UTC vs.
Revision 1.14 by slacapra, Wed Jan 17 18:17:58 2007 UTC

# Line 1 | Line 1
1 < #!/usr/bin/env python2
2 < import sys, os, string, re
1 > #!/usr/bin/env python
2   from DBSInfo import *
3  
4  
5   # ####################################
6   class DataDiscoveryError(exceptions.Exception):
7 <  def __init__(self, errorMessage):
8 <   args=errorMessage
9 <   exceptions.Exception.__init__(self, args)
10 <   pass
11 <
12 <  def getErrorMessage(self):
13 <   """ Return exception error """
14 <   return "%s" % (self.args)
7 >    def __init__(self, errorMessage):
8 >        exceptions.Exception.__init__(self, self.args)
9 >        self.args=errorMessage
10 >        pass
11 >
12 >    def getErrorMessage(self):
13 >        """ Return exception error """
14 >        return "%s" % (self.args)
15  
16   # ####################################
17   class NotExistingDatasetError(exceptions.Exception):
18 <  def __init__(self, errorMessage):
19 <   args=errorMessage
20 <   exceptions.Exception.__init__(self, args)
21 <   pass
22 <
23 <  def getErrorMessage(self):
24 <   """ Return exception error """
25 <   return "%s" % (self.args)
18 >    def __init__(self, errorMessage):
19 >        exceptions.Exception.__init__(self, self.args)
20 >        self.args=errorMessage
21 >        pass
22 >
23 >    def getErrorMessage(self):
24 >        """ Return exception error """
25 >        return "%s" % (self.args)
26  
27   # ####################################
28   class NoDataTierinProvenanceError(exceptions.Exception):
29 <  def __init__(self, errorMessage):
30 <   args=errorMessage
31 <   exceptions.Exception.__init__(self, args)
32 <   pass
33 <
34 <  def getErrorMessage(self):
35 <   """ Return exception error """
36 <   return "%s" % (self.args)
29 >    def __init__(self, errorMessage):
30 >        exceptions.Exception.__init__(self, self.args)
31 >        self.args=errorMessage
32 >        pass
33 >
34 >    def getErrorMessage(self):
35 >        """ Return exception error """
36 >        return "%s" % (self.args)
37  
38   # ####################################
39   # class to find and extact info from published data
40   class DataDiscovery:
41 <    def __init__(self, owner, dataset, dataTiers, cfg_params):
41 >    def __init__(self, datasetPath, dataTiers, cfg_params):
42  
43   #       Attributes
44 <        self.dbsdataset='/'+dataset+'/datatier/'+owner
44 >        self.datasetPath = datasetPath
45          self.dataTiers = dataTiers
46          self.cfg_params = cfg_params
47  
48 <        self.dbspaths= []     # DBS output: list of dbspaths for all data
49 <        self.allblocks = []   # DBS output: list of map fileblocks-totevts for all dataset-owners
50 <        self.blocksinfo = {}  # DBS output: map fileblocks-totevts for the primary block, used internally to this class
48 >        self.eventsPerBlock = {}  # DBS output: map fileblocks-events for collection
49 >        self.eventsPerFile = {}   # DBS output: map files-events
50 >        self.blocksinfo = {}  # DBS output: map fileblocks-files
51   #DBS output: max events computed by method getMaxEvents
52  
53   # ####################################
# Line 56 | Line 55 | class DataDiscovery:
55          """
56          Contact DBS
57          """
59        parents = []
60        parentsblocksinfo = {}
58  
59 <        ## add the PU among the required data tiers if the Digi are requested
63 <        if (self.dataTiers.count('Digi')>0) & (self.dataTiers.count('PU')<=0) :
64 <          self.dataTiers.append('PU')
65 <
66 <        ## get info about the requested dataset
67 <        dbs=DBSInfo(self.dbsdataset,self.dataTiers)
59 >        ## get DBS URL
60          try:
61 <          self.blocksinfo=dbs.getDatasetContents()
62 <        except DBSError, ex:
63 <          raise DataDiscoveryError(ex.getErrorMessage())
72 <        
73 <        if len(self.blocksinfo)<=0:
74 <         msg="\nERROR Data %s do not exist in DBS! \n Check the dataset/owner variables in crab.cfg !"%self.dbsdataset
75 <         raise NotExistingDatasetError(msg)
61 >            dbs_url=self.cfg_params['CMSSW.dbs_url']
62 >        except KeyError:
63 >            dbs_url="http://cmsdoc.cern.ch/cms/test/aprom/DBS/CGIServer/prodquery"
64  
65 <        currentdatatier=string.split(self.blocksinfo.keys()[0],'/')[2]
78 <        fakedatatier=string.split(self.dbsdataset,'/')[2]
79 <        currentdbsdataset=string.replace(self.dbsdataset, fakedatatier, currentdatatier)  
80 <
81 <        self.dbspaths.append(currentdbsdataset)    # add the requested dbspath
82 <
83 <        ## get info about the parents
65 >        ## get info about the requested dataset
66          try:
67 <          parents=dbs.getDatasetProvenance()
68 <        except DBSInvalidDataTierError, ex:
69 <          msg=ex.getErrorMessage()+' \n Check the data_tier variable in crab.cfg !\n'
70 <          raise DataDiscoveryError(msg)
71 <        except DBSError, ex:
72 <          raise DataDiscoveryError(ex.getErrorMessage())
67 >            dbs_instance=self.cfg_params['CMSSW.dbs_instance']
68 >        except KeyError:
69 >            dbs_instance="MCGlobal/Writer"
70 >
71 >        dbs = DBSInfo(dbs_url, dbs_instance)
72 >        try:
73 >            self.datasets = dbs.getMatchingDatasets(self.datasetPath)
74 >        except dbsCgiApi.DbsCgiExecutionError, msg:
75 >            raise DataDiscoveryError(msg)
76 >        except DBSError, msg:
77 >            raise DataDiscoveryError(msg)
78 >
79 >        if len(self.datasets) == 0:
80 >            raise DataDiscoveryError("DatasetPath=%s unknown to DBS" %self.datasetPath)
81 >        if len(self.datasets) > 1:
82 >            raise DataDiscoveryError("DatasetPath=%s is ambiguous" %self.datasetPath)
83  
84 <        ## check that the user asks for parent Data Tier really existing in the DBS provenance
85 <        self.checkParentDataTier(parents, self.dataTiers, currentdbsdataset)
84 >        try:
85 >            self.dbsdataset = self.datasets[0].get('datasetPathName')
86  
87 <        ## for each parent get the corresponding fileblocks
88 <        for aparent in parents:
89 <           ## fill a list of dbspaths
90 <           parentdbsdataset=aparent.getDatasetPath()
99 <           self.dbspaths.append(parentdbsdataset)
100 <           pdbs=DBSInfo(parentdbsdataset,[])
101 <           try:
102 <             parentsblocksinfo=pdbs.getDatasetContents()
103 <           except DBSError, ex:
87 >            self.eventsPerBlock = dbs.getEventsPerBlock(self.dbsdataset)
88 >            self.blocksinfo = dbs.getDatasetFileBlocks(self.dbsdataset)
89 >            self.eventsPerFile = dbs.getEventsPerFile(self.dbsdataset)
90 >        except DBSError, ex:
91              raise DataDiscoveryError(ex.getErrorMessage())
92 <
93 <           self.allblocks.append(parentsblocksinfo.keys()) # add parent fileblocksinfo
94 <
95 <        ## all the required blocks
96 <        self.allblocks.append(self.blocksinfo.keys()) # add also the current fileblocksinfo
110 <
111 <
112 < # #################################################
113 <    def checkParentDataTier(self, parents, user_datatiers, currentdbsdataset ):
114 <        """
115 <         check that the data tiers requested by the user really exists in the provenance of the given dataset
116 <        """
117 <
118 <        current_datatier=string.split(currentdbsdataset,'/')[2]
119 <
120 <        parent_datatypes=[]
121 <        for aparent in parents:
122 <          parent_datatypes.append(aparent.getDataType())
123 <
124 <        for datatier in user_datatiers:
125 <          if parent_datatypes.count(datatier)<=0:
126 <             # the current datatier is not supposed to be in the provenance
127 <             if not (datatier == current_datatier):  
128 <              msg="\nERROR Data %s not published in DBS with asked data tiers : the data tier not found is %s !\n  Check the data_tier variable in crab.cfg !"%(currentdbsdataset,datatier)
129 <              raise  NoDataTierinProvenanceError(msg)
92 >        
93 >        if len(self.eventsPerBlock) <= 0:
94 >            raise NotExistingDatasetError (("\nNo data for %s in DBS\nPlease check"
95 >                                            + " dataset path variables in crab.cfg")
96 >                                            % self.dbsdataset)
97  
98  
99   # #################################################
100      def getMaxEvents(self):
101          """
102 <         max events of the primary dataset-owner
102 >        max events
103          """
104 <        ## loop over the fileblocks of the primary dataset-owner
104 >        ## loop over the event collections
105          nevts=0      
106 <        for blockevts in self.blocksinfo.values():
107 <          nevts=nevts+blockevts
106 >        for evc_evts in self.eventsPerBlock.values():
107 >            nevts=nevts+evc_evts
108  
109          return nevts
110  
111   # #################################################
112 <    def getDBSPaths(self):
112 >    def getEventsPerBlock(self):
113          """
114 <         list the DBSpaths for all required data
114 >        list the event collections structure by fileblock
115          """
116 <        return self.dbspaths
116 >        return self.eventsPerBlock
117  
118   # #################################################
119 <    def getEVC(self):
119 >    def getEventsPerFile(self):
120          """
121 <         list the event collections structure by fileblock
121 >        list the event collections structure by file
122          """
123 <        print "To be used by a more complex job splitting... TODO later... "
157 <        print "it requires changes in what's returned by DBSInfo.getDatasetContents and then fetchDBSInfo"
123 >        return self.eventsPerFile
124  
125   # #################################################
126 <    def getFileBlocks(self):
126 >    def getFiles(self):
127          """
128 <         fileblocks for all required dataset-owners
128 >        return files grouped by fileblock
129          """
130 <        return self.allblocks        
130 >        return self.blocksinfo        
131  
132   ########################################################################
167
168

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines