Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:36:49

0001 import datetime
0002 
0003 datetime_string_fmt = '%Y-%m-%d %H:%M:%S.%f'
0004 
0005 def to_lumi_time( runNumber, lumiSectionId ):
0006     return (runNumber<<32) + lumiSectionId
0007 
0008 def from_lumi_time( lumiTime ):
0009     run = lumiTime>>32
0010     lumisection_id = lumiTime-( run << 32 )
0011     return run, lumisection_id
0012 
0013 def to_timestamp( dt ):
0014     timespan_from_epoch = dt - datetime.datetime(1970,1,1)
0015     seconds_from_epoch = int( timespan_from_epoch.total_seconds() )
0016     nanoseconds_from_epoch = timespan_from_epoch.microseconds * 1000
0017     return ( seconds_from_epoch << 32 ) + nanoseconds_from_epoch
0018 
0019 def from_timestamp( ts ):
0020     seconds_from_epoch = ts >> 32
0021     nanoseconds_from_epoch = ts - ( seconds_from_epoch << 32 )
0022     dt = datetime.datetime.utcfromtimestamp(seconds_from_epoch)
0023     return dt + datetime.timedelta( microseconds=int(nanoseconds_from_epoch/1000) )
0024 
0025 def string_to_timestamp( sdt ):
0026     dt = datetime.datetime.strptime( sdt, datetime_string_fmt )
0027     return to_timestamp( dt )
0028 
0029 def string_from_timestamp( ts ):
0030     dt = from_timestamp( ts )
0031     return dt.strftime( datetime_string_fmt )
0032 
0033