From 6b5341688ffc4193685e7364b48f6d930b8f1baf Mon Sep 17 00:00:00 2001 From: Kid A Date: Wed, 10 Dec 2025 12:22:58 +0330 Subject: [PATCH 1/7] [fix]:461 fixed with a utility function that checks for booealn interpretation fo string and integer content. Raises error to the user otherwise --- .gitignore | 3 +++ python/do_plots.py | 8 ++++---- python/utils.py | 24 ++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) 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..855dd7de084 100644 --- a/python/do_plots.py +++ b/python/do_plots.py @@ -14,7 +14,7 @@ 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 +526,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']) hist_cfg 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..3fe68bc49cb 100644 --- a/python/utils.py +++ b/python/utils.py @@ -90,3 +90,27 @@ def random_string(length: int = 8): ''' return ''.join(random.choices(string.ascii_letters + string.digits, k=length)) + +def boolean_of(input, context: str) -> bool : + """ + 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", "F", "False", "0", 0, "no", "n"], + "trueStatements" : ["true", "t", "T", "True", "1", 1 "yes","y"] + } + + if input in booleanDictionary["falseStatements"]: + return False + elif input in booleanDictionary["trueStatements"]: + return True + else + raise Exception(f"In ${context} you provided ${input} which cannot be considered a boolean in our source-code please use: False : ${booleanDictionary["falseStatements"]} and True: ${booleanDictionary["trueStatements"]}.") From f2861cf44a8b95da0c3b73c8d6d5fa97ec15fcd9 Mon Sep 17 00:00:00 2001 From: Kid A Date: Wed, 10 Dec 2025 13:34:35 +0330 Subject: [PATCH 2/7] [fix] lowercased and stringified input for boolean_of() function in utilities. --- python/utils.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/python/utils.py b/python/utils.py index 3fe68bc49cb..0cd56a96130 100644 --- a/python/utils.py +++ b/python/utils.py @@ -104,13 +104,13 @@ def boolean_of(input, context: str) -> bool : @return boolean """ booleanDictionary = { - "falseStatements" : ["false", "f", "F", "False", "0", 0, "no", "n"], - "trueStatements" : ["true", "t", "T", "True", "1", 1 "yes","y"] + "falseStatements" : ["false", "f", "0", "no", "n"], + "trueStatements" : ["true", "t", "1","yes","y"] } - - if input in booleanDictionary["falseStatements"]: + statement = str(input) + if statement.lower() in booleanDictionary["falseStatements"]: return False - elif input in booleanDictionary["trueStatements"]: + elif statement.lower() in booleanDictionary["trueStatements"]: return True - else - raise Exception(f"In ${context} you provided ${input} which cannot be considered a boolean in our source-code please use: False : ${booleanDictionary["falseStatements"]} and True: ${booleanDictionary["trueStatements"]}.") + else: + LOGGER(f"In ${context} you provided ${input} which cannot be considered a boolean in our source-code please use: False : ${booleanDictionary["falseStatements"]} and True: ${booleanDictionary["trueStatements"]}.") From 24d1941f37195445412c29ab27d0b387d99119f0 Mon Sep 17 00:00:00 2001 From: Kid A Date: Wed, 10 Dec 2025 16:37:03 +0330 Subject: [PATCH 3/7] [fix] typo --- python/do_plots.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/do_plots.py b/python/do_plots.py index 855dd7de084..4c773b21b44 100644 --- a/python/do_plots.py +++ b/python/do_plots.py @@ -527,7 +527,7 @@ def runPlotsHistmaker(config: dict[str, Any], ymin = hist_cfg['ymin'] if 'ymin' in hist_cfg else -1 ymax = hist_cfg['ymax'] if 'ymax' in hist_cfg else -1 stack = boolean_of(hist_cfg['stack'],"histogram stack") if 'stack' in hist_cfg else False - logx = boolean_of(hist_cfg['logx'], hist_cfg['xtitle']) hist_cfg if 'logx' 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 "" From 9528e32efc8589f4e63463695ba7fc2a59ff20e9 Mon Sep 17 00:00:00 2001 From: Kid A Date: Wed, 10 Dec 2025 16:38:17 +0330 Subject: [PATCH 4/7] [fix] logger in boolean_of --- python/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/utils.py b/python/utils.py index 0cd56a96130..1e1c4ea281b 100644 --- a/python/utils.py +++ b/python/utils.py @@ -113,4 +113,4 @@ def boolean_of(input, context: str) -> bool : elif statement.lower() in booleanDictionary["trueStatements"]: return True else: - LOGGER(f"In ${context} you provided ${input} which cannot be considered a boolean in our source-code please use: False : ${booleanDictionary["falseStatements"]} and True: ${booleanDictionary["trueStatements"]}.") + LOGGER.warning(f"In ${context} you provided ${input} which cannot be considered a boolean in our source-code please use: False : ${booleanDictionary["falseStatements"]} and True: ${booleanDictionary["trueStatements"]}.") From c23071e62a55f93e5f9214aa659fee6c431785ee Mon Sep 17 00:00:00 2001 From: Kid A Date: Wed, 10 Dec 2025 17:30:41 +0330 Subject: [PATCH 5/7] [fix] issues with importing. --- python/do_plots.py | 1 + python/utils.py | 7 ++++--- python/utils.pyi | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/python/do_plots.py b/python/do_plots.py index 4c773b21b44..5aba5cab727 100644 --- a/python/do_plots.py +++ b/python/do_plots.py @@ -16,6 +16,7 @@ from utils import random_string, boolean_of + ROOT.gROOT.SetBatch(True) ROOT.gStyle.SetOptStat(0) ROOT.gStyle.SetOptTitle(0) diff --git a/python/utils.py b/python/utils.py index 1e1c4ea281b..9837c33a1f6 100644 --- a/python/utils.py +++ b/python/utils.py @@ -91,7 +91,7 @@ def random_string(length: int = 8): return ''.join(random.choices(string.ascii_letters + string.digits, k=length)) -def boolean_of(input, context: str) -> bool : +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. @@ -107,10 +107,11 @@ def boolean_of(input, context: str) -> bool : "falseStatements" : ["false", "f", "0", "no", "n"], "trueStatements" : ["true", "t", "1","yes","y"] } - statement = str(input) + 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 ${input} which cannot be considered a boolean in our source-code please use: False : ${booleanDictionary["falseStatements"]} and True: ${booleanDictionary["trueStatements"]}.") + 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(): ... From 6a0d105f44033d6c8f35d5697376372c218e26f1 Mon Sep 17 00:00:00 2001 From: Kid A Date: Wed, 10 Dec 2025 17:33:49 +0330 Subject: [PATCH 6/7] [fix] issues with importing. --- python/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/utils.py b/python/utils.py index 9837c33a1f6..df126587bfe 100644 --- a/python/utils.py +++ b/python/utils.py @@ -113,5 +113,5 @@ def boolean_of(inputStatement, context: str) -> bool | None: 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"]}.") + 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 From a266486fde1a767a67407721c0eade71fbbc5dc9 Mon Sep 17 00:00:00 2001 From: Kid A Date: Wed, 10 Dec 2025 17:40:43 +0330 Subject: [PATCH 7/7] [fix] issues with importing. --- python/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/utils.py b/python/utils.py index df126587bfe..dc98ecab952 100644 --- a/python/utils.py +++ b/python/utils.py @@ -113,5 +113,5 @@ def boolean_of(inputStatement, context: str) -> bool | None: 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"]}.") + 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