CMS 3D CMS Logo

conddb_time.py
Go to the documentation of this file.
1 import datetime
2 
3 datetime_string_fmt = '%Y-%m-%d %H:%M:%S.%f'
4 
5 def to_lumi_time( runNumber, lumiSectionId ):
6  return (runNumber<<32) + lumiSectionId
7 
8 def from_lumi_time( lumiTime ):
9  run = lumiTime>>32
10  lumisection_id = lumiTime-( run << 32 )
11  return run, lumisection_id
12 
13 def to_timestamp( dt ):
14  timespan_from_epoch = dt - datetime.datetime(1970,1,1)
15  seconds_from_epoch = int( timespan_from_epoch.total_seconds() )
16  nanoseconds_from_epoch = timespan_from_epoch.microseconds * 1000
17  return ( seconds_from_epoch << 32 ) + nanoseconds_from_epoch
18 
19 def from_timestamp( ts ):
20  seconds_from_epoch = ts >> 32
21  nanoseconds_from_epoch = ts - ( seconds_from_epoch << 32 )
22  dt = datetime.datetime.utcfromtimestamp(seconds_from_epoch)
23  return dt + datetime.timedelta( microseconds=int(nanoseconds_from_epoch/1000) )
24 
26  dt = datetime.datetime.strptime( sdt, datetime_string_fmt )
27  return to_timestamp( dt )
28 
30  dt = from_timestamp( ts )
31  return dt.strftime( datetime_string_fmt )
32 
33 
conddb_time.string_from_timestamp
def string_from_timestamp(ts)
Definition: conddb_time.py:29
conddb_time.to_timestamp
def to_timestamp(dt)
Definition: conddb_time.py:13
conddb_time.from_timestamp
def from_timestamp(ts)
Definition: conddb_time.py:19
conddb_time.to_lumi_time
def to_lumi_time(runNumber, lumiSectionId)
Definition: conddb_time.py:5
conddb_time.from_lumi_time
def from_lumi_time(lumiTime)
Definition: conddb_time.py:8
conddb_time.string_to_timestamp
def string_to_timestamp(sdt)
Definition: conddb_time.py:25
createfilelist.int
int
Definition: createfilelist.py:10