File indexing completed on 2024-11-25 02:29:11
0001
0002
0003
0004 """ This script does the following:
0005 1- reads the list of iovs (by timestamp) in a sqlite file or in the Offline DB
0006 2- creates a cfg for each iov and runs them
0007 3- creates 2 log files per IOV (Summary/Debug) with all the SiStripDetVOff information in ASCII format
0008 It is recommended to redirect the output to a file.
0009 """
0010
0011
0012 import os
0013 import re
0014 import sys
0015 import time
0016
0017 """ Helper functions for time conversions """
0018
0019 def pack(high,low):
0020 """pack high,low 32bit unsigned int to one unsigned 64bit long long
0021 Note:the print value of result number may appear signed, if the sign bit is used.
0022 """
0023 h=high<<32
0024 return (h|low)
0025
0026 def secondsFromString(i):
0027 """convert from a string in the format output from timeStamptoDate to a 32bit seconds from the epoch.
0028 The format accepted is \"DD/MM/YYYY HH:MM:SS\". The year must be the full number.
0029 """
0030 return int(time.mktime(time.strptime(i, "%d/%m/%Y %H:%M:%S")))
0031
0032 def packFromString(i):
0033 """pack from a string in the format output from timeStamptoUTC to a 64bit timestamp
0034 the format accepted is \"DD/MM/YYYY HH:MM:SS\" . The year must be the full number.
0035 """
0036 return pack(secondsFromString(i), 0)
0037
0038 def intervalSinceEpoch(i):
0039 """ compute the interval of time is seconds since the Epoch and return the packed 64bit value.
0040 """
0041 return( packFromString(i) - packFromString("01/01/1970 00:00:00") )
0042
0043 def unpack(i):
0044 """unpack 64bit unsigned long long into 2 32bit unsigned int, return tuple (high,low)
0045 """
0046 high=i>>32
0047 low=i&0xFFFFFFFF
0048 return(high,low)
0049
0050 def timeStamptoDate(i):
0051 """convert 64bit timestamp to local date in string format
0052 """
0053
0054 try:
0055 date=time.ctime(unpack(i)[0])
0056 except:
0057
0058 print("Could not unpack time stamp %s, unpacked to %s!"%(i,unpack(i)[0]))
0059 date=-1
0060 return date
0061
0062
0063
0064
0065 if len(sys.argv) < 3:
0066 print("Please provide the name of the sqlite file and the tag as in: ")
0067 print("./CheckAllIOVs.py dbfile.db SiStripDetVOff_Fake_31X")
0068 print("OR to access directly the Offline DB with a time bracket:")
0069 print("./CheckAllIOVs.py CMS_COND_31X_STRIP SiStripDetVOff_v1_offline DD/MM/YYYY HH:MM:SS DD/MM/YYYY HH:MM:SS")
0070 sys.exit(1)
0071
0072 print("Reading all IOVs")
0073
0074 database= sys.argv[1]
0075
0076 if "COND" in database and "STRIP" in database:
0077 DBConnection="frontier://PromptProd/"+database
0078
0079 else:
0080 DBConnection="sqlite_file:"+database
0081
0082 tag=sys.argv[2]
0083
0084
0085 startFrom = 0
0086 if len(sys.argv) > 3:
0087 startFrom = packFromString(sys.argv[3])
0088 endAt = 0
0089 if len(sys.argv) > 4:
0090 endAt = packFromString(sys.argv[4])
0091
0092
0093
0094 iovs = os.popen("cmscond_list_iov -c "+DBConnection+" -t "+tag)
0095 cmscond_list_iov_output = iovs.readlines()
0096 for line in cmscond_list_iov_output:
0097 print(line)
0098 if "[DB=" in line:
0099 (start,end)=line.split()[0:2]
0100 if long(startFrom) > long(start):
0101 print("Skipping IOV =", start, " before requested =", startFrom)
0102 continue
0103 if (endAt != 0) and (long(endAt) < long(end)):
0104 print("Skipping IOV =", end, " after requested =", endAt)
0105 continue
0106
0107
0108
0109 if long(startFrom) > long(start):
0110 print("Skipping IOV =", start, " before requested =", startFrom)
0111 continue
0112 if (endAt != 0) and (long(endAt) < long(end)):
0113 print("Skipping IOV =", end, " after requested =", endAt)
0114 continue
0115
0116
0117 if end == "18446744073709551615":
0118 end = str(int(start) + 1)
0119
0120 startDate = timeStamptoDate(int(start))
0121 endDate = timeStamptoDate(int(end))
0122
0123 if endDate==-1:
0124 endDate=timeStamptoDate(int(start)+1)
0125
0126 print("start date = ", startDate, end=' ')
0127 print(", end date = ", endDate)
0128 fullDates="_FROM_"+startDate.replace(" ", "_").replace(":", "_")+"_TO_"+endDate.replace(" ", "_").replace(":", "_")
0129 fileName="DetVOffPrint"+fullDates+"_cfg.py"
0130 CfgFile=open(fileName,"w")
0131
0132 for cfgline in open(os.path.join(os.getenv("CMSSW_RELEASE_BASE"),"src/CalibTracker/SiStripDCS/test","templateCheckAllIOVs_cfg.py"),"r"):
0133
0134 if "STARTTIME" in cfgline:
0135 cfgline=cfgline.replace("STARTTIME",start)
0136 elif "ENDTIME" in cfgline:
0137 cfgline=cfgline.replace("ENDTIME",end)
0138 elif "DATE" in cfgline:
0139 cfgline=cfgline.replace("DATE",fullDates)
0140 elif "DATABASECONNECTION" in cfgline:
0141 cfgline=cfgline.replace("DATABASECONNECTION",DBConnection)
0142 elif "TAG" in cfgline:
0143 cfgline=cfgline.replace("TAG",tag)
0144
0145 CfgFile.write(cfgline)
0146 CfgFile.close()
0147
0148
0149 os.system("cmsRun "+fileName+" > /dev/null")
0150
0151 for logline in open("DetVOffReaderDebug_"+fullDates+".log", "r"):
0152 if "IOV" in logline or "OFF" in logline or "ON" in logline:
0153 print(logline.strip("\n"))
0154 else:
0155 print(line)