def parse_inputs ( argv_ ) : # Get arguments try : opts, rest = getopt.getopt(argv_,"hrv:",["help","recursive","verbosity=","yaml=","compare=",""]) except getopt.GetoptError as err : msg.error("validate_yaml_files.py","The following error was thrown whilst parsing command-line arguments") print(">>>>>>>>\n",err,"\n<<<<<<<<") msg.error("validate_yaml_files.py","Falling back to to --help...") print_help() msg.fatal("validate_yaml_files.py","Command-line arguments not recognised.") # Parse arguments do_recurse = False for opt, arg in opts: if opt in ['-h',"--help"] : print_help() sys.exit(0) if opt in ['-r',"--recursive",] : msg.info("validate_yaml_files.py","Config: using recursion if needed",verbose_level=0) do_recurse = True if opt in ['-v',"--verbosity"] : msg.info("validate_yaml_files.py","Config: setting verbosity to {0}".format(arg),verbose_level=0) try : msg.VERBOSE_LEVEL = int(arg) except : msg.fatal("validate_yaml_files.py","Could not cast verbosity level {0} to integer".format(arg)) yaml_files = hlp.keep_only_yaml_files(get_argument_list(argv_,"--yaml"),recurse=do_recurse) root_files = hlp.keep_only_root_files(get_argument_list(argv_,"--compare"),recurse=do_recurse) if len(yaml_files) == 0 : msg.fatal("validate_yaml_files.py","Please provide at least one yaml file using the --yaml option") if len(root_files) == 0 : msg.fatal("validate_yaml_files.py","Please provide at least one root file using the --compare option") # Return return yaml_files, root_files
def load_all_root_files ( dataset_ , path_ , **kwargs ) : do_recurse = kwargs.get("recurse",True) path_ = hlp.remove_subleading(path_,"/") if hlp.is_directory(path_) : root_files = hlp.keep_only_root_files(path_,recurse=do_recurse) if len(root_files) == 0 : msg.error("HEP_data_utils.ROOT_helpers.load_all_root_files","Directory {0} has no root files... returning with nothing done.".format(path_),verbose_level=-1) return for f in root_files : load_all_root_files(dataset_,f,**kwargs) return if not hlp.is_root_file(path_) : msg.error("HEP_data_utils.ROOT_helpers.load_all_root_files","Path {0} is not a directory or root file... returning with nothing done.".format(path_),verbose_level=-1) return load_root_file(dataset_,path_,**kwargs)
def parse_inputs(argv_): # Get arguments try: opts, rest = getopt.getopt(argv_, "hrps:t:v:", [ "help", "recursive", "default-2D-bins", "print", "show", "save=", "type=", "verbosity=" ]) except getopt.GetoptError as err: msg.error( "inspect_yaml.py", "The following error was thrown whilst parsing command-line arguments" ) print(">>>>>>>>\n", err, "\n<<<<<<<<") msg.error("inspect_yaml.py", "Falling back to to --help...") print_help() msg.fatal("inspect_yaml.py", "Command-line arguments not recognised.") # Parse arguments do_recurse = False do_print_all = False do_not_make_matrix = False do_show = False save_file = "" restrict_type = None for opt, arg in opts: if opt in ['-h', "--help"]: print_help() sys.exit(0) if opt in [ '-r', "--recursive", ]: msg.info("inspect_yaml.py", "Config: using recursion if needed", verbose_level=0) do_recurse = True if opt in ["--default-2D-bins"]: msg.info( "inspect_yaml.py", "Config: I will *not* try to convert 2D binning into matrix format", verbose_level=0) do_not_make_matrix = True if opt in ["--print"]: msg.info("inspect_yaml.py", "Config: printing all distributions found", verbose_level=0) do_print_all = True if opt in ["--show"]: msg.info("inspect_yaml.py", "Config: showing all distributions found", verbose_level=0) do_show = True if opt in ['-s', "--save"]: save_file = str(arg) if save_file[-4:] != ".pdf": save_file = save_file + ".pdf" msg.info("inspect_yaml.py", "Config: saving plots to {0}".format(save_file), verbose_level=0) if opt in ['-t', "--type"]: arg = str(arg) if arg not in ["root", "yaml"]: msg.error( "inspect_yaml.py", "{0} option {1} not allowed: allowed inputs are \"root\" or \"yaml\" (deafult is both)" ) else: restrict_type = arg msg.info("inspect_yaml.py", "Config: only reading files of type {0}".format( restrict_type), verbose_level=0) if opt in ['-v', "--verbosity"]: msg.info("inspect_yaml.py", "Config: setting verbosity to {0}".format(arg), verbose_level=0) try: msg.VERBOSE_LEVEL = int(arg) except: msg.fatal( "inspect_yaml.py", "Could not cast verbosity level {0} to integer".format( arg)) # Check that the remaining argument is valid if len(rest) == 0: msg.error("inspect_yaml.py", "No argument provided") print_help() msg.fatal("inspect_yaml.py", "No input yaml file or directory provided") if len(rest) == 1 and hlp.is_directory(rest[0]): msg.info("inspect_yaml.py", "Opening input directory {0}...".format(rest[0]), verbose_level=0) rest = [rest[0] + "/" + f for f in os.listdir(rest[0])] yaml_files = [] if restrict_type == None or restrict_type == "yaml": yaml_files = hlp.keep_only_yaml_files(rest, recurse=do_recurse) root_files = [] if restrict_type == None or restrict_type == "root": root_files = hlp.keep_only_root_files(rest, recurse=do_recurse) if len(yaml_files + root_files) == 0: msg.fatal( "inspect_yaml.py", "No input yaml or root files found from the inputs provided") for f in rest: msg.info("inspect_yaml.py", "Registered input file {0}".format(f), verbose_level=0) # Return return yaml_files, root_files, do_show, do_print_all, do_not_make_matrix, save_file
def parse_inputs(argv_): # Get arguments try: opts, rest = getopt.getopt(argv_, "hrv:s:", [ "help", "recursive", "show", "save=", "verbosity=", "num=", "den=" ]) except getopt.GetoptError as err: msg.error( "plot_ratios.py", "The following error was thrown whilst parsing command-line arguments" ) print(">>>>>>>>\n", err, "\n<<<<<<<<") msg.error("plot_ratios.py", "Falling back to to --help...") print_help() msg.fatal("plot_ratios.py", "Command-line arguments not recognised.") # Parse arguments do_recurse = False do_show = False save_file = "" num_tag, den_tag = None, None for opt, arg in opts: if opt in ['-h', "--help"]: print_help() sys.exit(0) if opt in [ '-r', "--recursive", ]: msg.info("plot_ratios.py", "Config: using recursion if needed", verbose_level=0) do_recurse = True if opt in [ "--num", ]: num_tag = str(arg) msg.info("plot_ratios.py", "Config: numerators will be identified using the tag {0}". format(num_tag), verbose_level=0) if opt in [ "--den", ]: den_tag = str(arg) msg.info( "plot_ratios.py", "Config: denominators will be identified using the tag {0}". format(den_tag), verbose_level=0) if opt in ["--show"]: msg.info("plot_contents_of_yaml.py", "Config: showing all distributions found", verbose_level=0) do_show = True if opt in ['-s', "--save"]: save_file = str(arg) if save_file[-4:] != ".pdf": save_file = save_file + ".pdf" msg.info("plot_contents_of_yaml.py", "Config: saving plots to {0}".format(save_file), verbose_level=0) if opt in ['-v', "--verbosity"]: msg.info("plot_ratios.py", "Config: setting verbosity to {0}".format(arg), verbose_level=0) try: msg.VERBOSE_LEVEL = int(arg) except: msg.fatal( "plot_ratios.py", "Could not cast verbosity level {0} to integer".format( arg)) yaml_files = hlp.keep_only_yaml_files(argv_, recurse=do_recurse) root_files = hlp.keep_only_root_files(argv_, recurse=do_recurse) if num_tag is None: num_tag = "measured" msg.warning( "plot_ratios.py", "No --num provided, falling back to \"{0}\"".format(num_tag)) if den_tag is None: den_tag = "expected" msg.warning( "plot_ratios.py", "No --den provided, falling back to \"{0}\"".format(den_tag)) # Return return num_tag, den_tag, do_show, save_file, yaml_files, root_files