Beispiel #1
0
class Plot:
	def __init__(self,filename = None,data = False, debug = False):
		setPlotStyle()
		self.commandLine = CommandLineHandler('[' + self.__class__.__name__ + '] ')
		self.key = 'L1MuonPresent' if data else 'L1MuonTruth'
		self.data = data
		self.DEBUG = debug
		if filename != None:
			self.fileHandler = self.createFileHandler(filename)
		pass
	
	def createFileHandler(self,filename):
		fh = RootFileHandler(filename)
		fh.printStatus()
		return fh
	
	def createPlotSubdir(self,subdirname):
		if( not os.path.exists('plots')):
			os.mkdir('plots')
		if( not os.path.exists('plots/' + subdirname)):
			os.mkdir('plots/' + subdirname)
		self.plotSubdir = 'plots/' + subdirname
		return
	
	#Save a canvas as gif file with the source data file name attached
	def storeCanvas(self,canvas,plotname):
		if(plotname.find('/') != -1):
			if( not os.path.exists(self.plotSubdir + '/' + plotname[0:plotname.rfind('/')])):
				os.makedirs(self.plotSubdir + '/' + plotname[0:plotname.rfind('/')])
				
		canvas.SaveAs('%s/%s_%s.gif'%(self.plotSubdir,plotname,self.fileHandler.filename))
		canvas.SaveAs('%s/%s_%s.png'%(self.plotSubdir,plotname,self.fileHandler.filename))
		return
	
	def drawLabel(self):
		label = None
		if self.data:
			label = drawLabelCmsPrivateData()
		else:
			label = drawLabelCmsPrivateSimulation()
		return label
	
	def debug(self,string):
		self.commandLine.debug(string)
	
	def warning(self,string):
		self.commandLine.warning(string)
		
	def error(self,string):
		self.commandLine.error(string)
		
	def output(self,string):
		self.commandLine.output(string)
Beispiel #2
0
class Plot:
	def __init__(self,filename = None,data = False, debug = False):
		setPlotStyle()
		self.commandLine = CommandLineHandler('[' + self.__class__.__name__ + ']')
		self.key = 'L1MuonPresent' if data else 'L1MuonTruth'
		self.data = data
		self.DEBUG = debug
		self.filename = filename
		if self.DEBUG:
			self.debug("Creating plot module %s" % self.__class__.__name__)
		if filename != None:
			self.fileHandler = self.createFileHandler(filename)
		pass
	
	def setModuleName(self,moduleName):
		self.fileHandler.setModuleName(moduleName)
	
	def createFileHandler(self,filename):
		fh = RootFileHandler(filename,debug=self.DEBUG)
		fh.printStatus()
		return fh
	
	def getGitCommitHash(self):
		cmd = shlex.split("git show --abbrev-commit")
		process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
		gitOutput,err = process.communicate()
		gch = 'None'
		firstLine = gitOutput.split('\n')[0]
		if firstLine.find('commit') != -1:
			gch = firstLine.split(' ')[-1]
		return gch
	
	def createPlotSubdir(self,subdirname):
		if( not os.path.exists('plots')):
			if self.DEBUG:
				self.debug('Creating dir plots')
			os.mkdir('plots')
		gitCommitHash = self.getGitCommitHash()
		if( not os.path.exists('plots/' + gitCommitHash)):
			if self.DEBUG: self.debug('Creating dir plots/' + gitCommitHash)
			os.mkdir('plots/' + gitCommitHash)
		if( not os.path.exists('plots/' + gitCommitHash + '/' + subdirname)):
			if self.DEBUG: self.debug('Creating dir plots/' + gitCommitHash + '/' + subdirname)
			os.mkdir('plots/' + gitCommitHash + '/' + subdirname)
		self.plotSubdir = 'plots/' + gitCommitHash + '/' + subdirname
		return
	
	#Save a canvas as gif file with the source data file name attached
	def storeCanvas(self,canvas,plotname,drawMark = True, drawLabel = True, markPosition = None, labelPosition = None,
				marginRight=0.1, marginLeft=0.1,marginTop=.05):
		# Do the following to overcome the late binding in python which evaluates
		# the default objects only once and persists the information
		if markPosition == None:
			markPosition = {'x1ndc' : marginLeft - 0.007, 'y1ndc' : 0.95, 'x2ndc' : marginLeft + 0.226, 'y2ndc' : 0.99}
			
		if labelPosition == None:
			labelPosition = {'x1ndc' : .7 - marginRight, 'y1ndc' : 0.95, 'x2ndc' : 1 - marginRight, 'y2ndc' : 0.98}
		
		if(plotname.find('/') != -1):
			if( not os.path.exists(self.plotSubdir + '/' + plotname[0:plotname.rfind('/')])):
				os.makedirs(self.plotSubdir + '/' + plotname[0:plotname.rfind('/')])
				
		canvas.cd().SetTopMargin(marginTop)
		canvas.cd().SetRightMargin(marginRight)
		canvas.cd().SetLeftMargin(marginLeft)

		if drawMark:
			mark = drawWaterMark(markPosition = markPosition)
		if drawLabel:		
			label = self.drawLabel(labelPosition = labelPosition)
		
		canvas.Update()
		canvas.SaveAs('%s/%s_%s.gif'%(self.plotSubdir,plotname,self.fileHandler.filename))
		canvas.SaveAs('%s/%s_%s.png'%(self.plotSubdir,plotname,self.fileHandler.filename))
		canvas.SaveAs('%s/%s_%s.pdf'%(self.plotSubdir,plotname,self.fileHandler.filename))
				
		return
	
	def drawLabel(self,labelPosition = {'x1ndc' : 0.6, 'y1ndc' : 0.95, 'x2ndc' : 0.9, 'y2ndc' : 0.98}):
		if self.data:
			label = drawLabelCmsPrivateData(labelPosition['x1ndc'],labelPosition['y1ndc'],labelPosition['x2ndc'],labelPosition['y2ndc'])
		else:
			label = drawLabelCmsPrivateSimulation(labelPosition['x1ndc'],labelPosition['y1ndc'],labelPosition['x2ndc'],labelPosition['y2ndc'])
		return label
	
	def debug(self,string):
		self.commandLine.debug(string)
	
	def warning(self,string):
		self.commandLine.warning(string)
		
	def error(self,string):
		self.commandLine.error(string)
		
	def output(self,string):
		self.commandLine.output(CliColors.BOLD + '<' + inspect.stack()[1][3] + '>  ' + CliColors.ENDC + str(string))
		
	def printProgress(self,done,total,updateEvery = 1000):
		if done == total or not (done % updateEvery):
			self.commandLine.printProgress(done, total)
Beispiel #3
0
parser.add_argument('--lumiFile'
				,dest='lumiFile'
				,type = str
				,help='Provide json file with lumi sections when running on data')

parser.add_argument('--sourceFiles'
				,dest='sourceFiles'
				,type = str
				,help='Choose a different file that contains the list of the source files.'\
				'By default the script looks for a file named ' + cmsswSourceFiles + '.')

args = parser.parse_args()

if not args.nJobs and not args.test and not args.collect:
	cli.error('If no test run is requested, the number of jobs has to be set!')
	print
	parser.print_help()
	sys.exit(1)

nJobs = 0
if args.test:
	nJobs = 10
else:
	nJobs = args.nJobs

def hasJobFailed(resultsPath):
	outTxtFilePath = os.path.abspath(resultsPath) + '/out.txt'
	if not os.path.isfile(outTxtFilePath):
		cli.warning('File does not exist: %s' % outTxtFilePath)
		return True
Beispiel #4
0
class Plot:
	def __init__(self,filename = None,data = False, debug = False):
		setPlotStyle()
		self.commandLine = CommandLineHandler('[' + self.__class__.__name__ + ']')
		self.key = 'L1MuonPresent' if data else 'L1MuonTruth'
		self.data = data
		self.DEBUG = debug
		if filename != None:
			self.fileHandler = self.createFileHandler(filename)
		pass
	
	def createFileHandler(self,filename):
		fh = RootFileHandler(filename)
		fh.printStatus()
		return fh
	
	def getGitCommitHash(self):
		cmd = shlex.split("git show --abbrev-commit")
		process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
		gitOutput,err = process.communicate()
		gch = 'None'
		firstLine = gitOutput.split('\n')[0]
		if firstLine.find('commit') != -1:
			gch = firstLine.split(' ')[-1]
		return gch
	
	def createPlotSubdir(self,subdirname):
		if( not os.path.exists('plots')):
			self.debug('Creating dir plots')
			os.mkdir('plots')
		gitCommitHash = self.getGitCommitHash()
		if( not os.path.exists('plots/' + gitCommitHash)):
			self.debug('Creating dir plots/' + gitCommitHash)
			os.mkdir('plots/' + gitCommitHash)
		if( not os.path.exists('plots/' + gitCommitHash + '/' + subdirname)):
			self.debug('Creating dir plots/' + gitCommitHash + '/' + subdirname)
			os.mkdir('plots/' + gitCommitHash + '/' + subdirname)
		self.plotSubdir = 'plots/' + gitCommitHash + '/' + subdirname
		return
	
	#Save a canvas as gif file with the source data file name attached
	def storeCanvas(self,canvas,plotname):
		if(plotname.find('/') != -1):
			if( not os.path.exists(self.plotSubdir + '/' + plotname[0:plotname.rfind('/')])):
				os.makedirs(self.plotSubdir + '/' + plotname[0:plotname.rfind('/')])
				
		canvas.SaveAs('%s/%s_%s.gif'%(self.plotSubdir,plotname,self.fileHandler.filename))
		canvas.SaveAs('%s/%s_%s.png'%(self.plotSubdir,plotname,self.fileHandler.filename))
		return
	
	def drawLabel(self):
		label = None
		if self.data:
			label = drawLabelCmsPrivateData()
		else:
			label = drawLabelCmsPrivateSimulation()
		return label
	
	def debug(self,string):
		self.commandLine.debug(string)
	
	def warning(self,string):
		self.commandLine.warning(string)
		
	def error(self,string):
		self.commandLine.error(string)
		
	def output(self,string):
		self.commandLine.output(CliColors.BOLD + '<' + inspect.stack()[1][3] + '>  ' + CliColors.ENDC + str(string))
Beispiel #5
0
parser.add_argument(
    '--lumiFile',
    dest='lumiFile',
    type=str,
    help='Provide json file with lumi sections when running on data')

parser.add_argument('--sourceFiles'
    ,dest='sourceFiles'
    ,type = str
    ,help='Choose a different file that contains the list of the source files.'\
    'By default the script looks for a file named ' + cmsswSourceFiles + '.')

args = parser.parse_args()

if not args.nJobs and not args.test and not args.collect:
    cli.error('If no test run is requested, the number of jobs has to be set!')
    print
    parser.print_help()
    sys.exit(1)

nJobs = 0
if args.test:
    nJobs = 10
else:
    nJobs = args.nJobs


def hasJobFailed(resultsPath):
    outTxtFilePath = os.path.abspath(resultsPath) + '/out.txt'
    if not os.path.isfile(outTxtFilePath):
        cli.warning('File does not exist: %s' % outTxtFilePath)
Beispiel #6
0
class Plot:
    def __init__(self, filename=None, data=False, debug=False):
        setPlotStyle()
        self.commandLine = CommandLineHandler('[' + self.__class__.__name__ +
                                              ']')
        self.key = 'L1MuonPresent' if data else 'L1MuonTruth'
        self.data = data
        self.DEBUG = debug
        self.filename = filename
        if self.DEBUG:
            self.debug("Creating plot module %s" % self.__class__.__name__)
        if filename != None:
            self.fileHandler = self.createFileHandler(filename)
        pass

    def setModuleName(self, moduleName):
        self.fileHandler.setModuleName(moduleName)

    def createFileHandler(self, filename):
        fh = RootFileHandler(filename, debug=self.DEBUG)
        fh.printStatus()
        return fh

    def getGitCommitHash(self):
        cmd = shlex.split("git show --abbrev-commit")
        process = subprocess.Popen(cmd,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE)
        gitOutput, err = process.communicate()
        gch = 'None'
        firstLine = gitOutput.split('\n')[0]
        if firstLine.find('commit') != -1:
            gch = firstLine.split(' ')[-1]
        return gch

    def createPlotSubdir(self, subdirname):
        if (not os.path.exists('plots')):
            if self.DEBUG:
                self.debug('Creating dir plots')
            os.mkdir('plots')
        gitCommitHash = self.getGitCommitHash()
        if (not os.path.exists('plots/' + gitCommitHash)):
            if self.DEBUG: self.debug('Creating dir plots/' + gitCommitHash)
            os.mkdir('plots/' + gitCommitHash)
        if (not os.path.exists('plots/' + gitCommitHash + '/' + subdirname)):
            if self.DEBUG:
                self.debug('Creating dir plots/' + gitCommitHash + '/' +
                           subdirname)
            os.mkdir('plots/' + gitCommitHash + '/' + subdirname)
        self.plotSubdir = 'plots/' + gitCommitHash + '/' + subdirname
        return

    #Save a canvas as gif file with the source data file name attached
    def storeCanvas(self,
                    canvas,
                    plotname,
                    drawMark=True,
                    markPosition={
                        'x1ndc': 0.093,
                        'y1ndc': 0.898,
                        'x2ndc': 0.319,
                        'y2ndc': 0.940
                    }):
        if (plotname.find('/') != -1):
            if (not os.path.exists(self.plotSubdir + '/' +
                                   plotname[0:plotname.rfind('/')])):
                os.makedirs(self.plotSubdir + '/' +
                            plotname[0:plotname.rfind('/')])

        canvas.cd()

        if drawMark:
            mark = drawWaterMark(markPosition=markPosition)

        canvas.Update()
        canvas.SaveAs('%s/%s_%s.gif' %
                      (self.plotSubdir, plotname, self.fileHandler.filename))
        canvas.SaveAs('%s/%s_%s.png' %
                      (self.plotSubdir, plotname, self.fileHandler.filename))
        return

    def drawLabel(self, x1ndc=0.6, y1ndc=0.90, x2ndc=0.9, y2ndc=0.93):
        label = None
        if self.data:
            label = drawLabelCmsPrivateData(x1ndc, y1ndc, x2ndc, y2ndc)
        else:
            label = drawLabelCmsPrivateSimulation(x1ndc, y1ndc, x2ndc, y2ndc)
        return label

    def debug(self, string):
        self.commandLine.debug(string)

    def warning(self, string):
        self.commandLine.warning(string)

    def error(self, string):
        self.commandLine.error(string)

    def output(self, string):
        self.commandLine.output(CliColors.BOLD + '<' + inspect.stack()[1][3] +
                                '>  ' + CliColors.ENDC + str(string))

    def printProgress(self, done, total, updateEvery=1000):
        if done == total or not (done % updateEvery):
            self.commandLine.printProgress(done, total)