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.7.2.1 by spiga, Thu Jul 20 12:03:48 2006 UTC vs.
Revision 1.12 by gutsche, Fri Sep 22 14:49:17 2006 UTC

# Line 39 | Line 39 | class NoDataTierinProvenanceError(except
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.owner = owner
46 <        self.dataset = dataset
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 58 | Line 57 | class DataDiscovery:
57          Contact DBS
58          """
59  
60 <        ## add the PU among the required data tiers if the Digi are requested
62 <        if (self.dataTiers.count('Digi')>0) & (self.dataTiers.count('PU')<=0) :
63 <            self.dataTiers.append('PU')
64 <
65 <        ## get info about the requested dataset
66 <        dbs=DBSInfo()
60 >        ## get DBS URL
61          try:
62 <            self.datasets = dbs.getMatchingDatasets(self.owner, self.dataset)
63 <        except DBSError, ex:
64 <            raise DataDiscoveryError(ex.getErrorMessage())
71 <        if len(self.datasets) == 0:
72 <            raise DataDiscoveryError("Owner=%s, Dataset=%s unknown to DBS" % (self.owner, self.dataset))
73 <        if len(self.datasets) > 1:
74 <            raise DataDiscoveryError("Owner=%s, Dataset=%s is ambiguous" % (self.owner, self.dataset))
75 <        try:
76 <            self.dbsdataset = self.datasets[0].get('datasetPathName')
77 <            self.blocksinfo = dbs.getDatasetContents(self.dbsdataset)
78 <            self.allblocks.append (self.blocksinfo.keys ()) # add also the current fileblocksinfo
79 <            self.dbspaths.append(self.dbsdataset)
80 <        except DBSError, ex:
81 <            raise DataDiscoveryError(ex.getErrorMessage())
82 <        
83 <        if len(self.blocksinfo)<=0:
84 <            msg="\nERROR Data for %s do not exist in DBS! \n Check the dataset/owner variables in crab.cfg !"%self.dbsdataset
85 <            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 <
67 <        ## get info about the parents
66 >        ## get info about the requested dataset
67 >        try:
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 <            parents=dbs.getDatasetProvenance(self.dbsdataset, self.dataTiers)
75 <        except DBSInvalidDataTierError, ex:
92 <            msg=ex.getErrorMessage()+' \n Check the data_tier variable in crab.cfg !\n'
74 >            self.datasets = dbs.getMatchingDatasets(self.datasetPath)
75 >        except dbsCgiApi.DbsCgiExecutionError, msg:
76              raise DataDiscoveryError(msg)
94        except DBSError, ex:
95            raise DataDiscoveryError(ex.getErrorMessage())
77  
78 <        ## check that the user asks for parent Data Tier really existing in the DBS provenance
79 <        self.checkParentDataTier(parents, self.dataTiers)
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  
100        ## for each parent get the corresponding fileblocks
83          try:
84 <            for p in parents:
85 <                ## fill a list of dbspaths
86 <                parentPath = p.get('parent').get('datasetPathName')
87 <                self.dbspaths.append (parentPath)
88 <                parentBlocks = dbs.getDatasetContents (parentPath)
107 <                self.allblocks.append (parentBlocks.keys ())  # add parent fileblocksinfo
84 >            self.dbsdataset = self.datasets[0].get('datasetPathName')
85 >
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 < # #################################################
93 <    def checkParentDataTier(self, parents, dataTiers):
94 <        """
95 <        check that the data tiers requested by the user really exists in the provenance of the given dataset
115 <        """
116 <        startType = string.split(self.dbsdataset,'/')[2]
117 <        # for example 'type' is PU and 'dataTier' is Hit
118 <        parentTypes = map(lambda p: p.get('type'), parents)
119 <        for tier in dataTiers:
120 <            if parentTypes.count(tier) <= 0 and tier != startType:
121 <                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 !"%(self.dbsdataset,tier)
122 <                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... "
150 <        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   ########################################################################

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines