diff --git a/.gitignore b/.gitignore index dae4b5b6557..3241bee3b09 100644 --- a/.gitignore +++ b/.gitignore @@ -72,6 +72,9 @@ venv/ ENV/ env.bak/ venv.bak/ +# For IntelliJIDEA folder that is made once you open the directory in that editory +.idea/ + # Prerequisites *.d diff --git a/python/do_plots.py b/python/do_plots.py index f98f604f7a5..5aba5cab727 100644 --- a/python/do_plots.py +++ b/python/do_plots.py @@ -14,7 +14,8 @@ import ROOT # type: ignore -from utils import random_string +from utils import random_string, boolean_of + ROOT.gROOT.SetBatch(True) ROOT.gStyle.SetOptStat(0) @@ -526,9 +527,9 @@ def runPlotsHistmaker(config: dict[str, Any], xmax = hist_cfg['xmax'] if 'xmax' in hist_cfg else -1 ymin = hist_cfg['ymin'] if 'ymin' in hist_cfg else -1 ymax = hist_cfg['ymax'] if 'ymax' in hist_cfg else -1 - stack = hist_cfg['stack'] if 'stack' in hist_cfg else False - logx = hist_cfg['logx'] if 'logx' in hist_cfg else False - logy = hist_cfg['logy'] if 'logy' in hist_cfg else False + stack = boolean_of(hist_cfg['stack'],"histogram stack") if 'stack' in hist_cfg else False + logx = boolean_of(hist_cfg['logx'], hist_cfg['xtitle']) if 'logx' in hist_cfg else False + logy = boolean_of(hist_cfg['logy'], hist_cfg['ytitle']) if 'logy' in hist_cfg else False extralab = hist_cfg['extralab'] if 'extralab' in hist_cfg else "" intLumi = f'L = {param.intLumi / 1e+06:.0f} ab^{{-1}}' diff --git a/python/utils.py b/python/utils.py index 5730099f153..dc98ecab952 100644 --- a/python/utils.py +++ b/python/utils.py @@ -90,3 +90,28 @@ def random_string(length: int = 8): ''' return ''.join(random.choices(string.ascii_letters + string.digits, k=length)) + +def boolean_of(inputStatement, context: str) -> bool | None: + """ + given an string checks in true and false statements dictionary + to see if the user wants True or False. + + raises error if the string input cannot be considered a boolean! + + @param input: the input of the user + @param context: the context of the boolean (used for giving better errors to the user for debugging. + + @return boolean + """ + booleanDictionary = { + "falseStatements" : ["false", "f", "0", "no", "n"], + "trueStatements" : ["true", "t", "1","yes","y"] + } + statement = str(inputStatement) + if statement.lower() in booleanDictionary["falseStatements"]: + return False + elif statement.lower() in booleanDictionary["trueStatements"]: + return True + else: + LOGGER.warning(f"In {context} you provided {inputStatement} which cannot be considered a boolean in our source-code please use: False : {booleanDictionary['falseStatements']} and True: {booleanDictionary['trueStatements']}.") + return None diff --git a/python/utils.pyi b/python/utils.pyi index b9939a251e6..282af1ff913 100644 --- a/python/utils.pyi +++ b/python/utils.pyi @@ -5,3 +5,4 @@ import logging LOGGER: logging.Logger def generate_graph(dframe, args, suffix: str | None = None) -> None: ... +def boolean_of(): ...