Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:14:53

0001 #!/usr/bin/env python
0002 
0003 """ Helper functions for time conversions """
0004 from __future__ import print_function
0005 
0006 def pack(high,low):
0007     """pack high,low 32bit unsigned int to one unsigned 64bit long long
0008        Note:the print value of result number may appear signed, if the sign bit is used.
0009     """
0010     h=high<<32
0011     return (h|low)
0012 
0013 def secondsFromString(i):
0014     """convert from a string in the format output from timeStamptoDate to a 32bit seconds from the epoch.
0015     The format accepted is \"DD/MM/YYYY HH:MM:SS\". The year must be the full number.
0016     """
0017     import time
0018     return int(time.mktime(time.strptime(i, "%d/%m/%Y %H:%M:%S")))
0019 
0020 def packFromString(i):
0021     """pack from a string in the format output from timeStamptoUTC to a 64bit timestamp
0022     the format accepted is \"DD/MM/YYYY HH:MM:SS\" . The year must be the full number.
0023     """
0024     return pack(secondsFromString(i), 0)
0025 
0026 def intervalSinceEpoch(i):
0027     """ compute the interval of time is seconds since the Epoch and return the packed 64bit value.
0028     """
0029     return( packFromString(i) - packFromString("01/01/1970 00:00:00") )
0030 
0031 def unpack(i):
0032     """unpack 64bit unsigned long long into 2 32bit unsigned int, return tuple (high,low)
0033     """
0034     high=i>>32
0035     low=i&0xFFFFFFFF
0036     return(high,low)
0037 
0038 def timeStamptoDate(i):
0039     """convert 64bit timestamp to local date in string format
0040     """
0041     import time
0042     return time.ctime(unpack(i)[0])
0043 
0044 """ This script does the following:
0045 1- reads the list of iovs (by timestamp) in a sqlite file
0046 2- creates a cfg for each iov and runs them
0047 3- takes the output of each job and builds a single output with the content of each iov
0048 It is recommended to redirect the output to a file.
0049 """
0050 
0051 import os
0052 import re
0053 import sys
0054 
0055 # The first parameter is the name of the script
0056 if len(sys.argv) < 3:
0057     print("Please provide the name of the sqlite file and the tag as in: ", end=' ')
0058     print("./CheckAllIOVs.py Example1a.db SiStripDetVOff_Fake_31X")
0059     sys.exit(1)
0060 
0061 print("Reading all IOVs")
0062 
0063 # Example1a.db
0064 # SiStripDetVOff_Fake_31X
0065 
0066 database = sys.argv[1]
0067 iovs = os.popen("cmscond_list_iov -c sqlite_file:"+database+" -t "+sys.argv[2])
0068 iovsList = iovs.read()
0069 splittedList = re.split("payloadToken",iovsList)
0070 splittedList = re.split("Total",splittedList[1])
0071 splittedList = re.split("\[DB|\]\[.*\]\[.*\]\[.*\]\[.*\]", splittedList[0])
0072 # Loop on even numbers
0073 for i in range(0, len(splittedList), 2):
0074     # print splittedList[i]
0075     iov = re.split(" ", splittedList[i])
0076     if len(iov) > 1:
0077         start = iov[0].strip("\n")
0078         end = iov[2].strip("\n")
0079         # print "iov = ", iov
0080         # print "start =", start,
0081         # print ", end =", end
0082         startDate = timeStamptoDate(int(start))
0083         endDate = timeStamptoDate(int(end))
0084         if end == "18446744073709551615":
0085             end = str(int(start) + 1)
0086         print("start date = ", startDate, end=' ')
0087         print(", end date = ", endDate)
0088         fullDates="_FROM_"+startDate.replace(" ", "_").replace(":", "_")+"_TO_"+endDate.replace(" ", "_").replace(":", "_")
0089         fileName="DetVOffPrint"+fullDates+"_cfg.py"
0090         os.system("cat templateCheckAllIOVs_cfg.py | sed -e \"s/STARTTIME/"+start+"/g\" | sed -e \"s/ENDTIME/"+end+"/g\" | sed -e \"s/DATE/"+fullDates+"/g\" | sed -e \"s/DATABASE/sqlite_file:"+database+"/g\" > "+fileName)
0091         # run = os.popen("cmsRun "+fileName+" > /dev/null")
0092         os.system("cmsRun "+fileName+" > /dev/null")
0093 
0094         for line in open("DetVOffReaderDebug_"+fullDates+".log", "r"):
0095             if "IOV" in line or "OFF" in line or "ON" in line:
0096                 print(line.strip("\n"))
0097 
0098 # # Do it afterwards because popen does not wait for the end of the job.
0099 # for i in range(0, len(splittedList), 2):
0100 #     iov = re.split(" ", splittedList[i])
0101 #     if len(iov) > 1:
0102 #         for line in open("DetVOffReaderDebug_"+fullDates+".log", "r"):
0103 #             if "IOV" in line or "OFF" in line or "ON" in line:
0104 #                 print line.strip("\n")