Skip to content

Commit

Permalink
Entry points with gt and era history (#46)
Browse files Browse the repository at this point in the history
Co-authored-by: Antonio <[email protected]>
  • Loading branch information
LinaresToine and Antonio authored Sep 19, 2023
1 parent 660ced3 commit 942a892
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/python/Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
})
55 changes: 55 additions & 0 deletions src/python/DataEraHistory.py
Original file line number Diff line number Diff line change
@@ -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


80 changes: 80 additions & 0 deletions src/python/DataGlobalTagHistory.py
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions src/python/Regexps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]+")

0 comments on commit 942a892

Please sign in to comment.