def __str__(self): from ostap.logger.utils import rootWarning with rootWarning() : nf = len ( self.files ) nf2 = len ( self.files2 ) nc = '??' nc2 = '??' if not self.silent : chain1 = self.chain1 nc = len ( chain1 ) del chain1 chain2 = self.chain2 nc = len ( chain2 ) del chain2 ne = len ( self.bad_files1 ) ne2 = len ( self.bad_files2 ) sf = set(self.files) == set(self.files2) if not self.bad_files1 and not self.bad_files2 : return "<#files: {}; Entries: {}/{}>" .format ( nf, nc , nc2 ) if sf else \ "<#files: {}/{}; Entries: {}/{}>".format ( nf , nf2 , nc , nc2 ) else : return "<#files: {}; Entries: {}/{}; No/empty :{}/{}>" .format ( nf , nc , nc2 , ne , ne2 ) if sf else \ "<#files: {}/{}; Entries: {}/{}; No/empty :{}/{}>".format ( nf , nf2 , nc , nc2 , ne , ne2 )
def __str__(self): from ostap.logger.utils import rootWarning with rootWarning(): nf = len(self.files) nc = len(self.chain) ne = len(self.e_list1) return "<#files: {}; Entries: {}>" .format ( nf , nc ) if not self.e_list1 else \ "<#files: {}; Entries: {}; No/empty: {}>".format ( nf , nc , ne )
def _to_draw_(obj, *args, **kwargs): """ (silent) Draw of ROOT object >>> obj >>> obj.Draw() ## >>> obj.draw() ## ditto """ from ostap.logger.utils import rootWarning with rootWarning(): return obj.Draw(*args, **kwargs)
def __str__(self): from ostap.logger.utils import rootWarning with rootWarning() : nf = len ( self.files ) nc = '??' if not self.silent : chain = self.chain nc = len ( chain ) del chain ne = len ( self.bad_files ) return "<#files: {}; Entries: {}>" .format ( nf , nc ) if not self.bad_files else \ "<#files: {}; Entries: {}; No/empty: {}>".format ( nf , nc , ne )
def _cnv_print_ ( cnv , fname , exts = ( 'pdf' , 'png' , 'eps', 'C' ) ) : """A bit simplified version for TCanvas print >>> canvas.print ( 'fig' ) """ # cnv.Update () from ostap.logger.utils import rootWarning n,d,e = fname.rpartition('.') if d and e.lower() in all_extensions : with rootWarning () : cnv.Update () cnv.Print ( fname ) logger.debug ( 'Canvas --> %s' % fname ) return cnv for ext in exts : with rootWarning () : name = fname + '.' + ext cnv.Print ( name ) logger.debug('Canvas --> %s' % name ) return cnv
def __str__(self): from ostap.logger.utils import rootWarning with rootWarning(): nf = len(self.files) nf2 = len(self.files2) nc = len(self.chain) nc2 = len(self.chain2) ne = len(self.e_list1) ne2 = len(self.e_list2) sf = set(self.files) == set(self.files2) if not self.e_list1 and not self.e_list2: return "<#files: {}; Entries: {}/{}>" .format ( nf, nc , nc2 ) if sf else \ "<#files: {}/{}; Entries: {}/{}>".format ( nf , nf2 , nc , nc2 ) else: return "<#files: {}; Entries: {}/{}; No/empty :{}/{}>" .format ( nf , nc , nc2 , ne , ne2 ) if sf else \ "<#files: {}/{}; Entries: {}/{}; No/empty :{}/{}>".format ( nf , nf2 , nc , nc2 , ne , ne2 )
def _TO_draw_ ( obj , *args , **kwargs ) : """ (silent) Draw of ROOT object >>> obj >>> obj.Draw() ## >>> obj.draw() ## ditto """ from ostap.logger.utils import rootWarning, rooSilent with rootWarning() , rooSilent ( 2 ) : result = obj.Draw ( *args , **kwargs ) pad = ROOT.gROOT.GetSelectedPad() if pad and not ROOT.gPad : c = pad.GetCanvas() if c : c.Update() if ROOT.gPad : c = ROOT.gPad if c : c.Update() plot = AutoPlots.plot() if plot : ROOT.gPad >> plot return result
def _TO_draw_(obj, option='', *args, **kwargs): """ (silent) Draw of ROOT object, optionally setting the drawing attributes when applicable: - LineColor - LineStyle - LineWidth - MarkerColor - MarkerStyle - MarkerSize - FillColor - FillStyle - Min/Minimal - Max/Maximal - see ROOT.TAttLine, ROOT.TAttMarker and ROOT.TAttFill (case-insensitive and underscore-blind) >>> obj >>> obj.draw () ## >>> obj.draw ( linecolor = 2 ) >>> obj.draw ( LineColor = 2 , fill_style = 1003 ) >>> obj.draw ( markerStyle = 22 ) >>> obj.draw ( minimal = -1 ) >>> obj.draw ( max = 100 ) """ from ostap.utils.cidict import cidict kw = cidict(transform=lambda k: k.lower().replace('_', ''), **kwargs) ## Line if 'LineColor' in kw and hasattr(obj, 'SetLineColor'): obj.SetLineColor(kw.pop('LineColor')) if 'LineStyle' in kw and hasattr(obj, 'SetLineStyle'): obj.SetLineStyle(kw.pop('LineStyle')) if 'LineWidth' in kw and hasattr(obj, 'SetLineWidth'): obj.SetLineWidth(kw.pop('LineWidth')) ## Marker if 'MarkerColor' in kw and hasattr(obj, 'SetMarkerColor'): obj.SetMarkerColor(kw.pop('MarkerColor')) if 'MarkerStyle' in kw and hasattr(obj, 'SetMarkerStyle'): obj.SetMarkerStyle(kw.pop('MarkerStyle')) if 'MarkerSize' in kw and hasattr(obj, 'SetMarkerSize'): obj.SetMarkerSize(kw.pop('MarkerSize')) ## Area if 'FillColor' in kw and hasattr(obj, 'SetFillColor'): obj.SetFillColor(kw.pop('FillColor')) if 'FillStyle' in kw and hasattr(obj, 'SetFillStyle'): obj.SetFillStyle(kw.pop('FillStyle')) ## Min/max values if 'Minimum' in kw and hasattr(obj, 'SetMinimum'): obj.SetMinimum(kw.pop('Minimum')) elif 'Min' in kw and hasattr(obj, 'SetMinimum'): obj.SetMinimum(kw.pop('Min')) if 'Maximum' in kw and hasattr(obj, 'SetMaximum'): obj.SetMaximum(kw.pop('Maximum')) elif 'Max' in kw and hasattr(obj, 'SetMaximum'): obj.SetMaximum(kw.pop('Max')) if kw: logger.warning('draw: unknown attributes: %s' % kw.keys()) from ostap.logger.utils import rootWarning, rooSilent with rootWarning(), rooSilent(2): result = obj.Draw(option, *args) pad = ROOT.gROOT.GetSelectedPad() if pad and not ROOT.gPad: c = pad.GetCanvas() if c: c.Update() elif ROOT.gPad: c = ROOT.gPad if c: c.Update() return result
def _cnv_print_(cnv, fname, exts=('pdf', 'png', 'eps', 'C', 'jpg', 'gif', 'json', 'svg')): """A bit simplified version for TCanvas print It Alows to create several output file types at once - if extension is equal to `tar` or `tgz`, single (gzipped) tar-files is created - if extension is equal to `zip`, single zip-archive is created >>> canvas.print_ ( 'A' ) >>> canvas.save ( 'A' ) ## ditto >>> canvas >> 'fig' ## ditto """ # cnv.Update() dirname = os.path.dirname(fname) if dirname and not os.path.exists(dirname): from ostap.utils.basic import make_dirs dirname = os.path.abspath(dirname) logger.debug("create directory %s" % os.path.abspath(dirname)) make_dirs(dirname) from ostap.logger.utils import rootWarning n, e = os.path.splitext(fname) el = e.lower() if el.startswith('.'): el = el[1:] if n and el and (el in all_extensions): with rootWarning(): cnv.Update() cnv.Print(fname) logger.debug('Canvas --> %s' % fname) return cnv if n and el in ('tgz', 'gztar', 'targz', 'tar', 'zip', 'tbz', 'tbz2', 'tarbz', 'tarbz2', 'bztar', 'bz2tar', 'txz', 'tlz', 'tarxz', 'tarlz', 'xztar', 'lztar'): files = [] for ext in exts: with rootWarning(): name = n + '.' + ext cnv.Print(name) logger.debug('Canvas --> %s' % name) if os.path.exists(name) and os.path.isfile(name): files.append(name) if files and el in ('tgz', 'targz', 'gztar'): import tarfile with tarfile.open(fname, "w:gz") as output: for f in files: output.add(f) if os.path.exists(fname): logger.debug('tgz-archive created %s' % fname) elif files and el in ('tar', ): import tarfile with tarfile.open(fname, "w") as output: for f in files: output.add(f) if os.path.exists(fname): logger.debug('tar-archive created %s' % fname) elif files and el in ('tbz', 'tarbz', 'tarbz2', 'tbz2', 'bztar', 'bz2tar'): import tarfile with tarfile.open(fname, "w:bz2") as output: for f in files: output.add(f) if os.path.exists(fname): logger.debug('tbz-archive created %s' % fname) elif files and el in ('txz', 'tlz', 'tarxz', 'tarlz', 'xztar', 'lztar') and 3 <= python_version.major: import tarfile with tarfile.open(fname, "w:xz") as output: for f in files: output.add(f) if os.path.exists(fname): logger.debug('txz-archive created %s' % fname) elif files and el in ('zip', ): import zipfile with zipfile.ZipFile(fname, "w") as output: for f in files: output.write(f) if os.path.exists(fname): logger.debug('zip-archive created %s' % fname) for f in files: try: os.remove(f) except OSError: pass return cnv for ext in exts: with rootWarning(): name = fname + '.' + ext cnv.Print(name) logger.debug('Canvas --> %s' % name) return cnv
def _TO_draw_ ( obj , option = '', *args , **kwargs ) : """ (silent) Draw of ROOT object, optionally setting the drawing attributes when applicable: - LineColor - LineStyle - LineWidth - MarkerColor - MarkerStyle - MarkerSize - FillColor - FillStyle - Min/Minimal - Max/Maximal - see ROOT.TAttLine, ROOT.TAttMarker and ROOT.TAttFill (case-insensitive and underscore-blind) >>> obj >>> obj.draw () ## >>> obj.draw ( linecolor = 2 ) >>> obj.draw ( LineColor = 2 , fill_style = 1003 ) >>> obj.draw ( markerStyle = 22 ) >>> obj.draw ( minimal = -1 ) >>> obj.draw ( max = 100 ) """ from ostap.utils.cidict import cidict kw = cidict ( transform = cidict_fun , **kwargs ) ## Line if 'LineColor' in kw and hasattr ( obj , 'SetLineColor' ) : obj.SetLineColor ( kw.pop('LineColor' ) ) if 'LineStyle' in kw and hasattr ( obj , 'SetLineStyle' ) : obj.SetLineStyle ( kw.pop('LineStyle' ) ) if 'LineWidth' in kw and hasattr ( obj , 'SetLineWidth' ) : obj.SetLineWidth ( kw.pop('LineWidth' ) ) ## Marker if 'MarkerColor' in kw and hasattr ( obj , 'SetMarkerColor' ) : obj.SetMarkerColor ( kw.pop('MarkerColor' ) ) if 'MarkerStyle' in kw and hasattr ( obj , 'SetMarkerStyle' ) : obj.SetMarkerStyle ( kw.pop('MarkerStyle' ) ) if 'MarkerSize' in kw and hasattr ( obj , 'SetMarkerSize' ) : obj.SetMarkerSize ( kw.pop('MarkerSize' ) ) ## Area if 'FillColor' in kw and hasattr ( obj , 'SetFillColor' ) : obj.SetFillColor ( kw.pop('FillColor' ) ) if 'FillStyle' in kw and hasattr ( obj , 'SetFillStyle' ) : obj.SetFillStyle ( kw.pop('FillStyle' ) ) ## Min/max values if 'Minimum' in kw and hasattr ( obj , 'SetMinimum' ) : obj.SetMinimum ( kw.pop ( 'Minimum' ) ) elif 'Min' in kw and hasattr ( obj , 'SetMinimum' ) : obj.SetMinimum ( kw.pop ( 'Min' ) ) if 'Maximum' in kw and hasattr ( obj , 'SetMaximum' ) : obj.SetMaximum ( kw.pop ( 'Maximum' ) ) elif 'Max' in kw and hasattr ( obj , 'SetMaximum' ) : obj.SetMaximum ( kw.pop ( 'Max' ) ) if 'LabelSize' in kw or 'LabelFont' in kw or 'LabelScale' in kw : axis = [] if hasattr ( obj , 'GetXaxis' ) : xa = obj.GetXaxis() if xa : axis.append ( xa ) if hasattr ( obj , 'GetYaxis' ) : ya = obj.GetYaxis() if ya : axis.append ( ya ) if hasattr ( obj , 'GetZaxis' ) : za = obj.GetZaxis() if za : axis.append ( za ) if axis and 'LabelSize' in kw : ls = kw.pop ( 'LabelSize' ) for a in axis : a.SetLabelSize ( ls ) if axis and 'LabelFont' in kw : lf = kw.pop ( 'LabelFont' ) for a in axis : a.SetLabelFont ( lf ) if axis and 'LabelScale' in kw : ls = kw.pop ( 'LabelScale' ) for a in axis : a.SetLabelSize ( ls * a.GetLabelSize () ) if 'XaxisLabelOffset' in kw and hasattr ( obj , 'GetXaxis' ) : xa = obj.GetXaxis() if xa : xa.SetLabelOffset ( kw.pop ( 'XaxisLabelOffset' ) ) if 'YaxisLabelOffset' in kw and hasattr ( obj , 'GetYaxis' ) : ya = obj.GetYaxis() if ya : ya.SetLabelOffset ( kw.pop ( 'YaxisLabelOffset' ) ) if 'ZaxisLabelOffset' in kw and hasattr ( obj , 'GetZaxis' ) : za = obj.GetZaxis() if za : za.SetLabelOffset ( kw.pop ( 'ZaxisLabelOffset' ) ) if kw : logger.warning('draw: unknown attributes: %s' % kw.keys() ) from ostap.logger.utils import rootWarning, rooSilent with rootWarning() , rooSilent ( 2 ) : result = obj.Draw( option , *args ) groot = ROOT.ROOT.GetROOT () pad = groot.GetSelectedPad() if pad and not ROOT.gPad : c = pad.GetCanvas() if c : c.Update() elif ROOT.gPad : c = ROOT.gPad if c : c.Update() return result