def tempdir(cls, suffix='=db-dir', prefix='compress-shelve-dir-', date=True): """Create the temporary directory The directory will be cleaned-up and deleted at-exit. """ from ostap.utils.cleanup import CleanUp as CU return CU.tempdir(suffix=suffix, prefix=prefix, date=date)
def make_build_dir ( build = None ) : """Create proper temporary directory for ROOT builds """ if not build or not writeable ( build ) : from ostap.utils.cleanup import CleanUp build = CleanUp.tempdir ( prefix = 'ostap-build-' ) if not os.path.exists ( build ) : make_dir ( build ) return build
"H:!V:Gamma=0.25:Tol=0.001:VarTransform=Norm"), (ROOT.TMVA.Types.kLikelihood, "Likelihood", "H:!V:TransformOutput:PDFInterpol=Spline2:NSmoothSig[0]=30:NSmoothBkg[0]=30:NSmoothBkg[1]=30:NSmooth=1:NAvEvtPerBin=50:VarTransform=G,D" ), ## ## ( ROOT.TMVA.Types.kPDERS , 'PDERS' , "H:!V:NormTree=T:VolumeRangeMode=Adaptive:KernelEstimator=Gauss:GaussSigma=0.3:NEventsMin=400:NEventsMax=600" ) , ## ( ROOT.TMVA.Types.kKNN , 'KNN' , "H:!V:nkNN=20:ScaleFrac=0.8:SigmaFact=1.0:Kernel=Gaus:UseKernel=F:UseWeight=T:!Trim" ) , ## ], variables=['var1', 'var2', 'var3'], ## Variables for training signal=tSignal, ## ``Signal'' sample background=tBkg, ## ``Background'' sample verbose=True, signal_train_fraction=0.75, background_train_fraction=0.75, workdir=CleanUp.tempdir( prefix='ostap-tmva-workdir-')) ## working directory from ostap.utils.timing import timing with timing('for TMVA training', logger): weights_files = trainer.train() tar_file = trainer.tar_file # ============================================================================= ## if os.path.exists ( trainer.output_file ) : ## os.remove ( trainer.output_file ) # ============================================================================= ## Use trained TMVA # There are two alternatives # - usage of TMVA Reader : it can be rather slow, # but it is very flexible and powerful with respect to variable transformations
## 2) check the configuration file import ostap.core.config as OCC build_dir = OCC.general.get ( 'BUILD_DIR' , None ) del OCC if build_dir and not os.path.exists ( build_dir ) : build_dir = make_dir ( build_dir ) if build_dir and not writeable ( build_dir ) : logger.warning ('Directory %s is not writeable!' % tmp_dir ) build_dir = None ## 3) Construct something temporary and unique if not build_dir : from ostap.utils.cleanup import CleanUp build_dir = CleanUp.tempdir ( prefix = 'ostap-build-' ) # ============================================================================== ## Context manager to use certain build build directory # (useful for multiprocessing environment) # @code # with UseBuildDir() : # ... # @endcode class UseBuildDir ( object ) : """Context manager to use certain build build directory (useful for multiprocessing environment) >>> with UseBuildDir() : >>> ... """
variables=['var1', 'var2', 'var3'], ## Variables for training signal=tSignal, ## ``Signal'' sample background=tBkg, ## ``Background'' sample verbose=True, ## make_plots = False , logging=True, ## produce log-files parallel=True, ## parallel training prefilter='var1>-1.8', ## chop_signal=True, chop_background=True, ## signal_train_fraction=0.85, background_train_fraction=0.85, ## workdir=CleanUp.tempdir( prefix='ostap-chopping-workdir-'), ## working directory ## parallel_conf = { 'ncpus' : 0 , 'ppservers' : 'auto' } ) from ostap.utils.timing import timing # train it! with timing('for TMVA/Chopping training', logger): trainer.train() tar_file = trainer.tar_file # ============================================================================= # remove unnesessary output files for f in trainer.output_files: if os.path.exists(f) and os.path.isfile(f): try:
import ostap.core.config as _CONFIG if 'BUILD_DIR' in _CONFIG.general: bdir = _CONFIG.general.get('BUILD_DIR', fallback='') if good_dir(bdir): build_dir = bdir elif bdir and not os.path.exists(bdir): make_dir(bdir) if good_dir(bdir): build_dir = bdir # ============================================================================== # 3) use the temporary directory if not build_dir: from ostap.utils.cleanup import CleanUp as _CU bdir = _CU.tempdir(prefix='build_') if good_dir(bdir): build_dir = bdir del _CU # ============================================================================= if build_dir and good_dir(build_dir): ROOT.gSystem.SetBuildDir(build_dir) build_dir = ROOT.gSystem.GetBuildDir() # ============================================================================= if '__main__' == __name__: # ========================================================================= # logging # =========================================================================