Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print function migration for CalibTracker_SiStripDCS #23904

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions CalibTracker/SiStripDCS/test/ChangeToHVmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
map derived from pedestal runs studies with the old db map into a new
accurate map.
"""
from __future__ import print_function

import sys

print "Reading psu-detId map from map.txt"
print("Reading psu-detId map from map.txt")

inputMap = open("map.txt", "r")

Expand All @@ -29,10 +30,10 @@

if channel == "" or "undefined" in channel:
if channel == "":
print "channel not found for detId = ", detId
print("channel not found for detId = ", detId)
else:
print "channel is undefined in HV map ",
print "leaving channel 0"
print("channel is undefined in HV map ", end=' ')
print("leaving channel 0")
outputFile.write(line)
# break
else:
Expand Down
31 changes: 16 additions & 15 deletions CalibTracker/SiStripDCS/test/CheckAllIOVs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
3- creates 2 log files per IOV (Summary/Debug) with all the SiStripDetVOff information in ASCII format
It is recommended to redirect the output to a file.
"""
from __future__ import print_function
#3- takes the output of each job and builds a single output with the content of each iov

import os
Expand Down Expand Up @@ -55,21 +56,21 @@ def timeStamptoDate(i):
date=time.ctime(unpack(i)[0])
except:
#Handle the case of last IOV (or any IOV) timestamp being "out of range" by returning -1 instead of the date...
print "Could not unpack time stamp %s, unpacked to %s!"%(i,unpack(i)[0])
print("Could not unpack time stamp %s, unpacked to %s!"%(i,unpack(i)[0]))
date=-1
return date



# The first parameter is the name of the script
if len(sys.argv) < 3:
print "Please provide the name of the sqlite file and the tag as in: "
print "./CheckAllIOVs.py dbfile.db SiStripDetVOff_Fake_31X"
print "OR to access directly the Offline DB with a time bracket:"
print "./CheckAllIOVs.py CMS_COND_31X_STRIP SiStripDetVOff_v1_offline DD/MM/YYYY HH:MM:SS DD/MM/YYYY HH:MM:SS"
print("Please provide the name of the sqlite file and the tag as in: ")
print("./CheckAllIOVs.py dbfile.db SiStripDetVOff_Fake_31X")
print("OR to access directly the Offline DB with a time bracket:")
print("./CheckAllIOVs.py CMS_COND_31X_STRIP SiStripDetVOff_v1_offline DD/MM/YYYY HH:MM:SS DD/MM/YYYY HH:MM:SS")
sys.exit(1)

print "Reading all IOVs"
print("Reading all IOVs")

database= sys.argv[1]
#Offline DB case (e.g. user would write ./CheckAllIOVs.py CMS_COND_31X_STRIP SiStripDetVOff_v1_offline):
Expand All @@ -94,23 +95,23 @@ def timeStamptoDate(i):
iovs = os.popen("cmscond_list_iov -c "+DBConnection+" -t "+tag)
cmscond_list_iov_output = iovs.readlines()
for line in cmscond_list_iov_output:
print line
print(line)
if "[DB=" in line:
(start,end)=line.split()[0:2]
if long(startFrom) > long(start):
print "Skipping IOV =", start, " before requested =", startFrom
print("Skipping IOV =", start, " before requested =", startFrom)
continue
if (endAt != 0) and (long(endAt) < long(end)):
print "Skipping IOV =", end, " after requested =", endAt
print("Skipping IOV =", end, " after requested =", endAt)
continue
# print "start =", start,
# print ", end =", end

if long(startFrom) > long(start):
print "Skipping IOV =", start, " before requested =", startFrom
print("Skipping IOV =", start, " before requested =", startFrom)
continue
if (endAt != 0) and (long(endAt) < long(end)):
print "Skipping IOV =", end, " after requested =", endAt
print("Skipping IOV =", end, " after requested =", endAt)
continue

##TODO:Should we investigate this issue? Is it going to be an issue in the DB?
Expand All @@ -123,8 +124,8 @@ def timeStamptoDate(i):
if endDate==-1:
endDate=timeStamptoDate(int(start)+1)

print "start date = ", startDate,
print ", end date = ", endDate
print("start date = ", startDate, end=' ')
print(", end date = ", endDate)
fullDates="_FROM_"+startDate.replace(" ", "_").replace(":", "_")+"_TO_"+endDate.replace(" ", "_").replace(":", "_")
fileName="DetVOffPrint"+fullDates+"_cfg.py"
CfgFile=open(fileName,"w")
Expand All @@ -150,6 +151,6 @@ def timeStamptoDate(i):

for logline in open("DetVOffReaderDebug_"+fullDates+".log", "r"):
if "IOV" in logline or "OFF" in logline or "ON" in logline:
print logline.strip("\n")
print(logline.strip("\n"))
else:
print line
print(line)
13 changes: 7 additions & 6 deletions CalibTracker/SiStripDCS/test/CheckLogs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#! /usr/bin/env python
#Quick and dirty script to "analyze" the log of the CheckAllIOVs.py to validate
#plotting macro ExtractTrends.C
from __future__ import print_function
import sys
#print "Opening logfile %s"%sys.argv[1]
log=open(sys.argv[1])
Expand All @@ -9,9 +10,9 @@
LVOff=0
for line in log:
if "start" in line:
print "%s modules with HV off"%HVOff
print "%s modules with LV off\n"%LVOff
print line
print("%s modules with HV off"%HVOff)
print("%s modules with LV off\n"%LVOff)
print(line)
HVOff=0
LVOff=0
else:
Expand All @@ -22,7 +23,7 @@
if LVStatus=="OFF":
LVOff=LVOff+1
except:
print "Line read did not contain the IOV or the Voltage status:\n%s"%line
print("Line read did not contain the IOV or the Voltage status:\n%s"%line)
if HVOff or LVOff: #Catch the case of the last IOV when there are no exception lines ;)
print "%s modules with HV off"%HVOff
print "%s modules with LV off"%LVOff
print("%s modules with HV off"%HVOff)
print("%s modules with LV off"%LVOff)
3 changes: 2 additions & 1 deletion CalibTracker/SiStripDCS/test/MakeList.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#! /usr/bin/env python
#Quick and dirty script to provide the necessary (ordered by timestamp list of logs in the) list.txt file used by the ExtractTrends.C root macro
from __future__ import print_function
import os
import time

Expand All @@ -13,5 +14,5 @@
TimesLogs.sort()
listfile=open("list.txt","w")
for log in TimesLogs:
print log[1]
print(log[1])
listfile.write(log[1]+"\n")
25 changes: 13 additions & 12 deletions CalibTracker/SiStripDCS/test/MakeTkMaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#TODO:
#In the future can put it in scripts/ and take dir to run from and write to as options.

from __future__ import print_function
import os, subprocess

def ProduceTkMapVoltageInputFiles(workdir=os.getcwd()): #Setting the dir by default to the current working directory...
Expand All @@ -21,12 +22,12 @@ def ProduceTkMapVoltageInputFiles(workdir=os.getcwd()): #Setting the dir by defa
The function returns the 2 lists of HV and LV files.
"""
#Get all the files in the directory workdir (1 file per IOV):
print "Analysing %s directory"%workdir
print("Analysing %s directory"%workdir)
logfilenames=[x for x in os.listdir(workdir) if x.startswith("DetVOffReaderDebug")]
if logfilenames:
print "Processing %s logfiles..."%len(logfilenames)
print("Processing %s logfiles..."%len(logfilenames))
else:
print "No DetVIfReaderDebug files found!\nPlease run this script in the same dir you have run CheckAllIOVS.py, or in the dir where you store the output logfiles."
print("No DetVIfReaderDebug files found!\nPlease run this script in the same dir you have run CheckAllIOVS.py, or in the dir where you store the output logfiles.")

#Let's dump for each IOV a TkVoltageMapCreator ready input file, i.e. with 1 entry per detID...
#Need to read in our usual pkl to get all the strip detids
Expand All @@ -46,7 +47,7 @@ def ProduceTkMapVoltageInputFiles(workdir=os.getcwd()): #Setting the dir by defa
LVFilenames=[]
HVFilenames=[]
for logfilename in logfilenames:
print logfilename
print(logfilename)
#Create LV/HV filenames for the input files we will write
#TODO:
#Could add here the possibility of writing in a different dir, by adding an extra outdir argument to the function
Expand Down Expand Up @@ -106,10 +107,10 @@ def runcmd(command):
cmdout = process.stdout.read()
exitstat = process.returncode
except OSError as detail:
print "Race condition in subprocess.Popen has robbed us of the exit code of the %s process (PID %s).Assume it failed!\n %s\n"%(command,pid,detail)
print("Race condition in subprocess.Popen has robbed us of the exit code of the %s process (PID %s).Assume it failed!\n %s\n"%(command,pid,detail))
exitstat=999
if exitstat == None:
print "Something strange is going on! Exit code was None for command %s: check if it really ran!"%command
print("Something strange is going on! Exit code was None for command %s: check if it really ran!"%command)
exitstat=0
return exitstat

Expand All @@ -132,8 +133,8 @@ def CreateTkVoltageMapsCfgs(workdir=os.getcwd()): #Default to current working di
#Check if the corresponding LV log is there!
LVlog=os.path.join(workdir,HVlog.replace("HV","LV"))
if not os.path.exists(LVlog):
print "ARGH! Missing LV file for file %s"%HVlog
print "Will not process the HV file either!"
print("ARGH! Missing LV file for file %s"%HVlog)
print("Will not process the HV file either!")
TkMapCfgFilename=os.path.join(workdir,HVlog.replace("HV","TkVoltageMap").replace(".log","_cfg.py"))
TkMapCfgFilenames.append(TkMapCfgFilename)
TkMapCfg=open(TkMapCfgFilename,"w")
Expand Down Expand Up @@ -162,11 +163,11 @@ def CreateTkVoltageMaps(workdir=os.getcwd()): #Default to current working direct
#Make sure we run the cfg in the workdir and also the logfile is saved there...
TkMapCfg=os.path.join(workdir,TkMapCfg)
cmsRunCmd="cmsRun %s >& %s"%(TkMapCfg,TkMapCfg.replace(".py",".log"))
print cmsRunCmd
print(cmsRunCmd)
exitstat=runcmd(cmsRunCmd)
if exitstat != 0:
print "Uh-Oh!"
print "Command %s FAILED!"%cmsRunCmd
print("Uh-Oh!")
print("Command %s FAILED!"%cmsRunCmd)

#Could put in a def main...

Expand All @@ -177,7 +178,7 @@ def CreateTkVoltageMaps(workdir=os.getcwd()): #Default to current working direct

#Create the actual TkVoltageMaps!
TkMapCfgFilenames=CreateTkVoltageMapsCfgs()
print TkMapCfgFilenames
print(TkMapCfgFilenames)
CreateTkVoltageMaps()

#Finish this up, so that it can be committed, but above all use it!
Expand Down
5 changes: 3 additions & 2 deletions CalibTracker/SiStripDCS/test/ManualO2OForRestart.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
By splitting it in smaller intervals of a given DeltaT it is possible to keep
under control the memory used.
"""
from __future__ import print_function

import os
import datetime
Expand Down Expand Up @@ -73,11 +74,11 @@ def main():
targetFile = 'dcs_%s_to_%s_cfg.py' % (dt_begin.strftime('%Y-%m-%d__%H_%M_%S'), dt_next.strftime('%Y-%m-%d__%H_%M_%S'))
replace_dict={'_TMIN_':tmin_str, '_TMAX_':tmax_str, '_DBFILE_':args.dbfile, '_TAG_':args.tag}
insert_to_file(args.template, targetFile, replace_dict)
print 'Running %s' % targetFile
print('Running %s' % targetFile)
command = 'cmsRun %s' % targetFile
#print command
subprocess.Popen(command, shell=True).communicate()
print '='*50
print('='*50)
dt_begin = dt_next

if __name__ == '__main__':
Expand Down