diff --git a/analysis/data/hdf.py b/analysis/data/hdf.py index 0b485184ad24e5f40cc3a6e2e0b603b4cf9f5e0a..02981183ae782a7e180f908029dd6c5452ef5327 100644 --- a/analysis/data/hdf.py +++ b/analysis/data/hdf.py @@ -60,9 +60,14 @@ def modify_hdf(file_name, compress=True): out = subprocess.check_output(cmd) if not os.path.exists(compressed_file): # Something went wrong raise subprocess.CalledProcessError(0, ' '.join(cmd), output=out) - shutil.move(compressed_file, file_name) except subprocess.CalledProcessError as error: logger.warning("Error compressing -> %s", error.output) + else: + try: + shutil.move(compressed_file, file_name) + except IOError as error: + logger.warning("Error moving (copying) compressed file -> %s", error) + finally: if os.path.exists(compressed_file): os.remove(compressed_file) diff --git a/analysis/physics/factory.py b/analysis/physics/factory.py index 6878c11350be7589b6e59959839d983a3b2be261..47cf5e7f616f21dce8660fd80e380187908fc32b 100644 --- a/analysis/physics/factory.py +++ b/analysis/physics/factory.py @@ -427,6 +427,8 @@ class BaseFactory(object): new_config[3] = max_ if obs_id in self: self._objects[obs_id].setRange(range_name, min_, max_) + self._objects[obs_id].setMin(min_) + self._objects[obs_id].setMax(max_) if units: new_config[4] = units if obs_id in self: diff --git a/analysis/toys/fit_toys.py b/analysis/toys/fit_toys.py index 2e95fb7801d432b2ac184ee594ca260dbc2e2678..e66ef4e9665a5138309119f7e4b0e04315c5386f 100644 --- a/analysis/toys/fit_toys.py +++ b/analysis/toys/fit_toys.py @@ -90,10 +90,15 @@ def get_datasets(data_frames, acceptance, fit_models): # Add category column if category: # By default the label is stored in the 'category' column - if 'category' in rows and not all(rows['category']==category): - logger.error("Data %s contains categories not matching the specified category: ", - rows, set(rows['category']) - {category}) - raise ValueError("Data {} has categories different to the specified one".format(data_name)) # TODO: replace with DataError + if 'category' in rows: + if len(set(rows['category'])) > 1: + logger.error("Data %s contains more then one category: %s!", + rows, set(rows['category'])) + raise ValueError("Data {} contains more then one category: ".format(data_name)) # TODO: replace with DataError + elif not rows['category'].iloc[0] == category: + logger.info("Data %s contains a category %s, dropping it and " + "replacing it with the specified one %s", rows, + rows['category'].iloc[0], category) rows['category'] = category elif 'category' in rows: logger.warning("Data %s contains a 'category' column but no category was specified" diff --git a/analysis/toys/generate_toys.py b/analysis/toys/generate_toys.py index 0f1d64f692e890f148f0f9710fb772d3350e5369..ed4552d09284e27be71d1f358ec66ab345fae133 100644 --- a/analysis/toys/generate_toys.py +++ b/analysis/toys/generate_toys.py @@ -206,6 +206,9 @@ def main(): """ parser = argparse.ArgumentParser() + parser.add_argument('-v', '--verbose', + action='store_true', + help="Verbose output") parser.add_argument('--link-from', action='store', type=str, default='', help="Folder to actually store the toy files") @@ -213,6 +216,9 @@ def main(): action='store', type=str, nargs='+', help="Configuration files") args = parser.parse_args() + if args.verbose: + get_logger('analysis').setLevel(1) + logger.setLevel(1) try: run(args.config, args.link_from) exit_status = 0 diff --git a/analysis/toys/submit_toys.py b/analysis/toys/submit_toys.py index 7c875ef7ee05bee0fb08ade59d0074ac1c29623e..5a9f4ad8b161133f642252e4e623e36da13873f0 100644 --- a/analysis/toys/submit_toys.py +++ b/analysis/toys/submit_toys.py @@ -197,6 +197,9 @@ def main(): return list(sum(list_, typ_)) parser = argparse.ArgumentParser() + parser.add_argument('-v', '--verbose', + action='store_true', + help="Verbose output") parser.add_argument('--link-from', action='store', type=str, help="Folder to actually store the toy files") @@ -210,6 +213,9 @@ def main(): action='store', type=str, nargs='+', help="Configuration file") args = parser.parse_args() + if args.verbose: + get_logger('analysis').setLevel(1) + logger.setLevel(1) try: config = _config.load_config(*args.config) # Which type of toy are we running? @@ -250,9 +256,8 @@ def main(): temp_config['name'], ", ".join('{}: {}'.format(*val) for val in values.items())) # Write temp_file - file_ = tempfile.NamedTemporaryFile(delete=False) - file_name = file_.name - file_.close() + with tempfile.NamedTemporaryFile(delete=False) as file_: + file_name = file_.name _config.write_config(_config.fold_config(list(temp_config.items())), file_name) config_files.append(file_name) else: @@ -266,10 +271,11 @@ def main(): 'toys', script_to_run) for config_file in config_files: - submitter([config_file], - args.link_from, - args.extend, - args.overwrite).run(script_to_run) + submitter(config_files=[config_file], + link_from=args.link_from, + extend=args.extend, + overwrite=args.overwrite, + verbose=args.verbose).run(script_to_run,) if scan_config: os.remove(config_file) exit_status = 0 diff --git a/analysis/toys/submitter.py b/analysis/toys/submitter.py index b0d6f3dfcc11ae0cb2a97366645babe16f390e77..f14f1867a6464d8b4177181cb8a722f8d85fbcb1 100644 --- a/analysis/toys/submitter.py +++ b/analysis/toys/submitter.py @@ -47,7 +47,7 @@ class ToySubmitter(object): NTOYS_KEY = None NTOYS_PER_JOB_KEY = None - def __init__(self, config_files, link_from, extend, overwrite): + def __init__(self, config_files, link_from, extend, overwrite, verbose=False): """Configure the toy submitter. Arguments: @@ -96,6 +96,7 @@ class ToySubmitter(object): self.link_from = link_from self.extend = extend self.overwrite = overwrite + self.verbose = verbose # Get the batch system self.batch_system = get_batch_system() @@ -152,6 +153,8 @@ class ToySubmitter(object): script_args = [] if self.config['link-from']: script_args.append('--link-from={}'.format(self.config['link-from'])) + if self.verbose: + script_args.append('--verbose') script_args.append(config_file_dest) # Prepare paths # pylint: disable=E1101