CMS 3D CMS Logo

utils.py
Go to the documentation of this file.
1 """
2 File that contains utility functions used by various modules, but that do not fit into any single module.
3 """
4 import datetime
5 
6 def to_timestamp(obj):
7  """
8  Takes a datetime object and outputs a timestamp string with the format Y-m-d H:m:S.f
9  """
10  return obj.strftime('%Y-%m-%d %H:%M:%S.%f') if isinstance(obj, datetime.datetime) else obj
11 
12 def to_datetime(date_string):
13  """
14  Takes a date string with the format Y-m-d H:m:S.f and gives back a datetime.datetime object
15  """
16  return datetime.datetime.strptime(date_string.replace(",", "."), "%Y-%m-%d %H:%M:%S.%f")
17 
18 def friendly_since(time_type, since):
19  """
20  Takes a since and, if it is Run-based expressed as Lumi-based,
21  returns the run number.
22  Otherwise, returns the since without transformations.
23  """
24  if time_type == "Run" and (since & 0xffffff) == 0:
25  return since >> 32
26  else:
27  return since
def to_timestamp(obj)
Definition: utils.py:6
def friendly_since(time_type, since)
Definition: utils.py:18
def to_datetime(date_string)
Definition: utils.py:12