From 942a89229883bb28823bd72221c9fc10e838942c Mon Sep 17 00:00:00 2001 From: Antonio Linares Sancho <132582167+LinaresToine@users.noreply.github.com> Date: Tue, 19 Sep 2023 04:29:12 -0500 Subject: [PATCH] Entry points with gt and era history (#46) Co-authored-by: Antonio --- src/python/Data.py | 6 ++- src/python/DataEraHistory.py | 55 ++++++++++++++++++++ src/python/DataGlobalTagHistory.py | 80 ++++++++++++++++++++++++++++++ src/python/Regexps.py | 3 ++ 4 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 src/python/DataEraHistory.py create mode 100644 src/python/DataGlobalTagHistory.py diff --git a/src/python/Data.py b/src/python/Data.py index d4a801e..b7a3fc7 100644 --- a/src/python/Data.py +++ b/src/python/Data.py @@ -13,6 +13,8 @@ from T0WmaDataSvc.DataRunStreamSkippedLumis import * from T0WmaDataSvc.DataRecoConfigHistory import * from T0WmaDataSvc.DataExpressConfigHistory import * +from T0WmaDataSvc.DataEraHistory import * +from T0WmaDataSvc.DataGlobalTagHistory import * class Data(DatabaseRESTApi): """Server object for REST data access API.""" def __init__(self, app, config, mount): @@ -36,5 +38,7 @@ def __init__(self, app, config, mount): "repack_stats": RepackStats(app, self, config, mount), "skipped_streamers": RunStreamSkippedLumis(app, self, config, mount), "reco_config_history": RecoConfigHistory(app, self, config, mount), - "express_config_history": ExpressConfigHistory(app, self, config, mount) + "express_config_history": ExpressConfigHistory(app, self, config, mount), + "era_history": EraHistory(app, self, config, mount), + "global_tag_history": GlobalTagHistory(app, self, config, mount) }) diff --git a/src/python/DataEraHistory.py b/src/python/DataEraHistory.py new file mode 100644 index 0000000..09adf5c --- /dev/null +++ b/src/python/DataEraHistory.py @@ -0,0 +1,55 @@ +from WMCore.REST.Server import RESTEntity, restcall, rows +from WMCore.REST.Tools import tools +from WMCore.REST.Validation import * +from WMCore.REST.Format import JSONFormat, PrettyJSONFormat +from T0WmaDataSvc.Regexps import * +from operator import itemgetter + +class EraHistory(RESTEntity): + """REST entity for retrieving a specific primary dataset.""" + def validate(self, apiobj, method, api, param, safe): + """Validate request input data.""" + validate_str('era', param, safe, RX_ERA, optional = True) + @restcall(formats=[('text/plain', PrettyJSONFormat()), ('application/json', JSONFormat())]) + @tools.expires(secs=300) + def get(self, era): + """Retrieve Era history + + :arg str era: the acquisition era + :returns: Acquisition era, minimum run, and maximum run""" + + sql_with_era = """ + SELECT acq_era, MAX(run) max_run, MIN(run) min_run + FROM run_config + WHERE acq_era LIKE :acq_era + GROUP BY acq_era + ORDER BY max_run DESC, min_run DESC + """ + + sql_no_era = """ + SELECT acq_era, MAX(run) max_run, MIN(run) min_run + FROM run_config + GROUP BY acq_era + ORDER BY max_run DESC, min_run DESC + """ + + + if era is not None: + acq_era = "{}%".format(era) + c, _ = self.api.execute(sql_with_era, acq_era) + else: + c, _ = self.api.execute(sql_no_era) + + configs = [] + for result in c.fetchall(): + + (acq_era, max_run, min_run) = result + + config = { "era" : acq_era, + "max_run" : max_run, + "min_run" : min_run } + configs.append(config) + + return configs + + \ No newline at end of file diff --git a/src/python/DataGlobalTagHistory.py b/src/python/DataGlobalTagHistory.py new file mode 100644 index 0000000..310bd3b --- /dev/null +++ b/src/python/DataGlobalTagHistory.py @@ -0,0 +1,80 @@ +from WMCore.REST.Server import RESTEntity, restcall, rows +from WMCore.REST.Tools import tools +from WMCore.REST.Validation import * +from WMCore.REST.Format import JSONFormat, PrettyJSONFormat +from T0WmaDataSvc.Regexps import * +from operator import itemgetter + +class GlobalTagHistory(RESTEntity): + """REST entity for retrieving a specific primary dataset.""" + def validate(self, apiobj, method, api, param, safe): + """Validate request input data.""" + validate_str('express_global_tag', param, safe, RX_EXPRESS_GLOBAL_TAG, optional = True) + validate_str('prompt_global_tag', param, safe, RX_PROMPT_GLOBAL_TAG, optional = True) + @restcall(formats=[('text/plain', PrettyJSONFormat()), ('application/json', JSONFormat())]) + @tools.expires(secs=300) + def get(self, express_global_tag, prompt_global_tag): + """Retrieve Global tag history + + :arg str era: the acquisition era + :returns: global tags, minimum run, and maximum 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 + 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 + """ + 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 + """ + + + 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) + 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) + 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) + else: + c, _ = self.api.execute(sql_none) + + configs = [] + for result in c.fetchall(): + + (gt_express, gt_prompt, max_run, min_run) = result + + config = { "express_global_tag" : gt_express, + "prompt_global_tag" : gt_prompt, + "max_run" : max_run, + "min_run" : min_run } + configs.append(config) + + return configs \ No newline at end of file diff --git a/src/python/Regexps.py b/src/python/Regexps.py index bfff718..0adf1fc 100644 --- a/src/python/Regexps.py +++ b/src/python/Regexps.py @@ -6,3 +6,6 @@ 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]+")