From bdb7edd1ec77108d138fd9bd6292a79a438ce44b Mon Sep 17 00:00:00 2001 From: Antonio Linares Sancho <132582167+LinaresToine@users.noreply.github.com> Date: Thu, 21 Sep 2023 10:30:47 -0500 Subject: [PATCH] Gt and era history (#48) * Entry points with gt and era history * Modify Era History * Update new entry points * Update Regexps.py to fix global tag queries --------- Co-authored-by: Antonio --- src/python/DataEraHistory.py | 5 ++- src/python/DataGlobalTagHistory.py | 54 ++++++++++++------------------ src/python/Regexps.py | 7 ++-- 3 files changed, 28 insertions(+), 38 deletions(-) diff --git a/src/python/DataEraHistory.py b/src/python/DataEraHistory.py index 09adf5c..d29adf2 100644 --- a/src/python/DataEraHistory.py +++ b/src/python/DataEraHistory.py @@ -21,7 +21,7 @@ def get(self, era): sql_with_era = """ SELECT acq_era, MAX(run) max_run, MIN(run) min_run FROM run_config - WHERE acq_era LIKE :acq_era + WHERE acq_era LIKE :acq_era GROUP BY acq_era ORDER BY max_run DESC, min_run DESC """ @@ -35,8 +35,7 @@ def get(self, era): if era is not None: - acq_era = "{}%".format(era) - c, _ = self.api.execute(sql_with_era, acq_era) + c, _ = self.api.execute(sql_with_era, acq_era = '%' + str(era) + '%') else: c, _ = self.api.execute(sql_no_era) diff --git a/src/python/DataGlobalTagHistory.py b/src/python/DataGlobalTagHistory.py index 310bd3b..8631894 100644 --- a/src/python/DataGlobalTagHistory.py +++ b/src/python/DataGlobalTagHistory.py @@ -19,52 +19,42 @@ def get(self, express_global_tag, prompt_global_tag): :arg str era: the acquisition era :returns: global tags, minimum run, and maximum run""" + sql = """ + SELECT express_config.global_tag gt_express, reco_config.global_tag gt_prompt, MAX(run_config.run) AS max_run, MIN(run_config.run) AS min_run + FROM run_config + JOIN express_config ON express_config.run = run_config.run + JOIN reco_config ON reco_config.run = run_config.run + """ sql_express = """ - SELECT global_tag gt_express, MAX(run) max_run, MIN(run) min_run - FROM express_config - WHERE global_tag LIKE :gt_express - GROUP BY global_tag + WHERE express_config.global_tag LIKE :gt_express + """ + sql_ = """ + GROUP BY express_config.global_tag, reco_config.global_tag ORDER BY max_run DESC, min_run DESC """ sql_prompt = """ - SELECT global_tag gt_prompt, MAX(run) max_run, MIN(run) min_run - FROM reco_config - WHERE global_tag LIKE :gt_prompt - GROUP BY global_tag - ORDER BY max_run DESC, min_run DESC + WHERE reco_config.global_tag LIKE :gt_prompt """ sql_both = """ - SELECT reco_config.global_tag gt_prompt, express_config.global_tag gt_express, MAX(run_config.run) AS max_run, MIN(run_config.run) AS min_run - FROM run_config - JOIN express_config ON express_config.run = run_config.run - JOIN reco_config ON reco_config.run = run_config.run - WHERE global_tag LIKE :gt_express AND global_tag LIKE :gt_prompt - GROUP BY reco_config.global_tag, express_config.global_tag - ORDER BY max_run DESC, min_run DESC - """ - sql_none = """ - SELECT reco_config.global_tag gt_prompt, express_config.global_tag gt_express, MAX(run_config.run) AS max_run, MIN(run_config.run) AS min_run - FROM run_config - JOIN express_config ON express_config.run = run_config.run - JOIN reco_config ON reco_config.run = run_config.run - GROUP BY reco_config.global_tag, express_config.global_tag - ORDER BY max_run DESC, min_run DESC + WHERE reco_config.global_tag LIKE :gt_prompt AND express_config.global_tag LIKE :gt_express """ + if express_global_tag is not None and prompt_global_tag is not None: - gt_express = '{}%'.format(express_global_tag) - gt_prompt = '{}%'.format(prompt_global_tag) - c, _ = self.api.execute(sql_both, gt_express, gt_prompt) + sq = sql + sql_both + sql_ + c, _ = self.api.execute(sq, gt_express = '%' + str(express_global_tag) + '%', gt_prompt = '%' + str(prompt_global_tag) + '%') elif express_global_tag is not None and prompt_global_tag is None: - gt_express = '{}%'.format(express_global_tag) - c, _ = self.api.execute(sql_express, gt_express) + sq = sql + sql_express + sql_ + c, _ = self.api.execute(sq, gt_express = '%' + str(express_global_tag) + '%') elif express_global_tag is None and prompt_global_tag is not None: - gt_prompt = '{}%'.format(prompt_global_tag) - c, _ = self.api.execute(sql_prompt, gt_prompt) + sq = sql + sql_prompt + sql_ + c, _ = self.api.execute(sq, gt_prompt = '%' + str(prompt_global_tag) + '%') else: - c, _ = self.api.execute(sql_none) + sq = sql + sql_ + c, _ = self.api.execute(sq) + configs = [] for result in c.fetchall(): diff --git a/src/python/Regexps.py b/src/python/Regexps.py index 0adf1fc..dd5cae1 100644 --- a/src/python/Regexps.py +++ b/src/python/Regexps.py @@ -6,6 +6,7 @@ RX_STREAM = re.compile(r"[A-Z][0-9a-zA-Z]+") RX_PRIMARY_DATASET = re.compile(r"[A-Z][0-9a-zA-Z]+") RX_SCENARIO = re.compile(r"[a-zA-Z][0-9a-zA-Z]+") -RX_ERA = re.compile(r"[a-zA-Z][0-9a-zA-Z]+") -RX_EXPRESS_GLOBAL_TAG = re.compile(r"[1-9][0-9a-zA-Z]+") -RX_PROMPT_GLOBAL_TAG = re.compile(r"[1-9][0-9a-zA-Z]+") +RX_ERA = re.compile(r"[0-9_a-zA-Z]+") +RX_EXPRESS_GLOBAL_TAG = re.compile(r"[0-9_a-zA-Z]+") +RX_PROMPT_GLOBAL_TAG = re.compile(r"[0-9_a-zA-Z]+") +