def getPackagePath2(self, name, var, force=False): """ Return a path to the package for specified environment variable. For example: _getPackagePath('x','LD_LIBRARY_PATH') returns a LD_LIBRARY_PATH for the package (if defined). The value may be a string or a list of strings - in the later case the individual path components will be separated by colons (':'). If the path is not defined (see getPackagePath()) then return an empty string. """ import os path, tarball = self.getPackagePath(name, force) if path and var in self.packages[name]: from Ganga.Utility.util import isStringLike ppath = self.packages[name][var] if isStringLike(ppath): ppath = [ppath] return ':'.join(map(lambda p: os.path.join(path, p), ppath)) # for p in ppath: ## result += os.path.join(path,p) # return result else: return ''
def __makeList__(self, element): if isStringLike(element): myList = [element] elif canLoopOver(element): myList = element else: myList = [element] return myList
def __makeList__(self,element): if isStringLike(element): myList = [element] elif canLoopOver(element): myList = element else: myList = [element] return myList
def __defaultSubtitle__(self, titleAttr): """ compose the subtitle according to the given titleAttr. """ if isStringLike(titleAttr): ## a string return titleAttr elif canLoopOver(titleAttr): ## a list return self.__defaultSubtitle__(titleAttr[0]) elif inspect.isfunction( titleAttr): ## other things: function, object ... return 'user function %s' % titleAttr.__name__
def __defaultSubtitle__(self,titleAttr): """ compose the subtitle according to the given titleAttr. """ if isStringLike(titleAttr): ## a string return titleAttr elif canLoopOver(titleAttr): ## a list return self.__defaultSubtitle__(titleAttr[0]) elif inspect.isfunction(titleAttr): ## other things: function, object ... return 'user function %s' % titleAttr.__name__
def __makeJobInfo__(job, attrNameList): '''make complete jobinfo according to the given list of job attributs''' jobInfo = [] for attrName in attrNameList: try: if isStringLike(attrName): attrValue, attrClass = __getJobAttribute__(job, attrName) else: attrValue, attrClass = attrName(job), None jobInfo.append(attrValue) except Exception as x: logger.warning('Ignoring job %d: %s' % (job.id, str(x))) jobInfo.append(NOT_APPLICABLE) return jobInfo
def __makeJobInfo__(job,attrNameList): '''make complete jobinfo according to the given list of job attributs''' jobInfo = [] for attrName in attrNameList: try: if isStringLike(attrName): attrValue, attrClass = __getJobAttribute__(job,attrName) else: attrValue, attrClass = attrName(job), None jobInfo.append(attrValue) except Exception as x: logger.warning('Ignoring job %d: %s'%(job.id,str(x))) jobInfo.append(NOT_APPLICABLE) return jobInfo
def histogram(self, jobs, attr, **keywords): """ The plotter's interface for generating one or multiple histograms in one chart. usage: >>> plotter.histogram(jobs,attr,**keywords) Generate a histogram catogorized by the attr among the given jobs. required arguments: jobs: A GANGA's job table attr: A string or a user defined function, the corresponding value of which will be extracted from the given jobs to generate the histogram. optional arguments: colormap: A list of values representing the colors that will be picked to paint the histogram bars. The supported description of color can be found at http://matplotlib.sourceforge.net/matplotlib.pylab.html#-colors normalize: Sets if doing histogram normalization. Default is "False" numbins: Sets the number of bins in the histogram. Default is 50 title: A string specifying the title of the histogram. xlabel: A string specifying the xlabel of the histogram. label: A string specifying the lable of the histogram displayed on the legend. xmin: A number specifying the lower bound of the histogram range. xmax: A number specifying the upper bound of the histogram range. output: A name of file where the pie chart plot will be exported. The format is auto-determinated by the extension of the given name. dataproc: An user-defined function which will be applied to process the value of attr before plotting the histogram. deep: Sets if looping over all the subjob levels. Default is "True" """ # default keyword arguments subtitle = self.__defaultSubtitle__(attr) # default subtitle xlabel = self.__defaultSubtitle__(attr) # default xlabel label = self.__defaultSubtitle__(attr) # default label colormap = None # colormap output = None # the output file of the picture attrext = None # trigger the build-in data processing function dataproc = None # function for data processing (cannot work together with 'attrext') deep = True # deep looping over all the subjob levels normalize = False # histogram normalization numbins = 50 # number of bins in the histogram xmin = -1 # lower bound of the histogram xmax = -1 # upper bound of the histogram # update keyword arguments with the given values if 'title' in keywords: subtitle = keywords['title'] if 'colormap' in keywords: colormap = keywords['colormap'] if 'xlabel' in keywords: xlabel = keywords['xlabel'] if 'label' in keywords: label = keywords['label'] if 'output' in keywords: output = keywords['output'] if 'dataproc' in keywords: dataproc = keywords['dataproc'] if 'deep' in keywords: deep = keywords['deep'] if 'normalize' in keywords: normalize = keywords['normalize'] if 'numbins' in keywords: numbins = keywords['numbins'] if 'xmin' in keywords: xmin = keywords['xmin'] if 'xmax' in keywords: xmax = keywords['xmax'] jlist = [] for j in jobs: jlist.append(j) attr_spec = self.__makeList__(attr) logger.debug('attribute specification: %s' % repr(attr_spec)) # special build-in dataprocs for the CE-based pie chart dataproc = self.__setDataProcessor__(attr, attrext, dataproc) dataTable = getJobInfoTable(jlist, attr_spec, deep) logger.debug('internal data table: %s' % repr(dataTable)) # make the plot title title = __makePlotTitle__(len(dataTable[1:]), deep, subtitle) pltColIdList = range(len(dataTable[0])) if not canLoopOver(dataproc): dataproc = len(dataTable[0]) * [dataproc] elif len(dataproc) != len(dataTable[0]): logger.error( 'dataproc requires a list with %d elements, %d are given' % (len(dataTable[0]), len(dataproc))) return False if (not canLoopOver(label)) or (isStringLike(label)): label = len(dataTable[0]) * [label] elif len(label) != len(dataTable[0]): logger.error( 'label requires a list with %d elements, %d are given' % (len(dataTable[0]), len(label))) return False # make the plot self.__makeMultiHistograms__(dataTable,pltColIdList=pltColIdList,pltDataProcList=dataproc,pltLabelList=label, \ pltTitle=title,pltNumBins=numbins,pltRange=(xmin,xmax), pltXLabel=xlabel, \ pltColorMap=colormap,pltNormalize=normalize, \ pltOutput=output)
def histogram(self,jobs,attr,**keywords): """ The plotter's interface for generating one or multiple histograms in one chart. usage: >>> plotter.histogram(jobs,attr,**keywords) Generate a histogram catogorized by the attr among the given jobs. required arguments: jobs: A GANGA's job table attr: A string or a user defined function, the corresponding value of which will be extracted from the given jobs to generate the histogram. optional arguments: colormap: A list of values representing the colors that will be picked to paint the histogram bars. The supported description of color can be found at http://matplotlib.sourceforge.net/matplotlib.pylab.html#-colors normalize: Sets if doing histogram normalization. Default is "False" numbins: Sets the number of bins in the histogram. Default is 50 title: A string specifying the title of the histogram. xlabel: A string specifying the xlabel of the histogram. label: A string specifying the lable of the histogram displayed on the legend. xmin: A number specifying the lower bound of the histogram range. xmax: A number specifying the upper bound of the histogram range. output: A name of file where the pie chart plot will be exported. The format is auto-determinated by the extension of the given name. dataproc: An user-defined function which will be applied to process the value of attr before plotting the histogram. deep: Sets if looping over all the subjob levels. Default is "True" """ # default keyword arguments subtitle = self.__defaultSubtitle__(attr) # default subtitle xlabel = self.__defaultSubtitle__(attr) # default xlabel label = self.__defaultSubtitle__(attr) # default label colormap = None # colormap output = None # the output file of the picture attrext = None # trigger the build-in data processing function dataproc = None # function for data processing (cannot work together with 'attrext') deep = True # deep looping over all the subjob levels normalize = False # histogram normalization numbins = 50 # number of bins in the histogram xmin = -1 # lower bound of the histogram xmax = -1 # upper bound of the histogram # update keyword arguments with the given values if 'title' in keywords: subtitle = keywords['title'] if 'colormap' in keywords: colormap = keywords['colormap'] if 'xlabel' in keywords: xlabel = keywords['xlabel'] if 'label' in keywords: label = keywords['label'] if 'output' in keywords: output = keywords['output'] if 'dataproc' in keywords: dataproc = keywords['dataproc'] if 'deep' in keywords: deep = keywords['deep'] if 'normalize' in keywords: normalize= keywords['normalize'] if 'numbins' in keywords: numbins = keywords['numbins'] if 'xmin' in keywords: xmin = keywords['xmin'] if 'xmax' in keywords: xmax = keywords['xmax'] jlist = [] for j in jobs: jlist.append(j) attr_spec = self.__makeList__(attr) logger.debug('attribute specification: %s' % repr(attr_spec)) # special build-in dataprocs for the CE-based pie chart dataproc = self.__setDataProcessor__(attr,attrext,dataproc) dataTable = getJobInfoTable(jlist,attr_spec,deep) logger.debug('internal data table: %s' % repr(dataTable)) # make the plot title title = __makePlotTitle__(len(dataTable[1:]),deep,subtitle) pltColIdList = range(len(dataTable[0])) if not canLoopOver(dataproc): dataproc = len( dataTable[0] ) * [dataproc] elif len(dataproc) != len(dataTable[0]): logger.error('dataproc requires a list with %d elements, %d are given' % (len(dataTable[0]),len(dataproc)) ) return False if (not canLoopOver(label)) or (isStringLike(label)): label = len( dataTable[0] ) * [label] elif len(label) != len(dataTable[0]): logger.error('label requires a list with %d elements, %d are given' % (len(dataTable[0]), len(label)) ) return False # make the plot self.__makeMultiHistograms__(dataTable,pltColIdList=pltColIdList,pltDataProcList=dataproc,pltLabelList=label, \ pltTitle=title,pltNumBins=numbins,pltRange=(xmin,xmax), pltXLabel=xlabel, \ pltColorMap=colormap,pltNormalize=normalize, \ pltOutput=output)