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.12 by gutsche, Fri Sep 22 14:49:17 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines