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 CondTools_Ecal #23934

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
117 changes: 59 additions & 58 deletions CondTools/Ecal/python/EcalCondDB.py
Expand Up @@ -5,57 +5,58 @@
# Main script to list, plot, draw, dump Ecal conditions
#
#
from __future__ import print_function
import os,sys,getopt


def usage():
print
print "NAME "
print " EcalCondDB - inpect EcalCondDB"
print
print "SYNOPSIS"
print " EcalCondDB [options] [command] [command_options]"
print
print "OPTIONS"
print
print "Specify short options as '-o foo', long options as '--option=foo'"
print
print " -c, --connect= [connectstring]"
print " specify database, default frontier://FrontierProd/CMS_COND_31X_ECAL"
print
print " -P, --authpath= [authenticationpath], default /afs/cern.ch/cms/DB/conddb "
print
print "COMMAND OPTIONS"
print
print " -t, --tag= [tag,file] specify tag or xml file (histo,compare)"
print
print " -s, --since= [runnumber] specify since"
print()
print("NAME ")
print(" EcalCondDB - inpect EcalCondDB")
print()
print("SYNOPSIS")
print(" EcalCondDB [options] [command] [command_options]")
print()
print("OPTIONS")
print()
print("Specify short options as '-o foo', long options as '--option=foo'")
print()
print(" -c, --connect= [connectstring]")
print(" specify database, default frontier://FrontierProd/CMS_COND_31X_ECAL")
print()
print(" -P, --authpath= [authenticationpath], default /afs/cern.ch/cms/DB/conddb ")
print()
print("COMMAND OPTIONS")
print()
print(" -t, --tag= [tag,file] specify tag or xml file (histo,compare)")
print()
print(" -s, --since= [runnumber] specify since")

print "COMMANDS"
print("COMMANDS")

print " -l, --listtags list all tags and exit"
print
print " -m, --listiovs list iovs for a given tag"
print " Example EcalCondDB.py -t tag"
print
print " -d, --dump= [file] dump record to xml file"
print " Example EcalCondDB.py -d file.xml -t tag -s since"
print
print " -p, --plot= [file] plot record to file, extension specifies ",\
"format (.root,.png,.jpg,.gif,.svg)"
print " Example: EcalCondDB.py -p=plot.png -t tag -s since"
print
print(" -l, --listtags list all tags and exit")
print()
print(" -m, --listiovs list iovs for a given tag")
print(" Example EcalCondDB.py -t tag")
print()
print(" -d, --dump= [file] dump record to xml file")
print(" Example EcalCondDB.py -d file.xml -t tag -s since")
print()
print(" -p, --plot= [file] plot record to file, extension specifies ",\
"format (.root,.png,.jpg,.gif,.svg)")
print(" Example: EcalCondDB.py -p=plot.png -t tag -s since")
print()

print " -q, --compare= [file]"
print " compare two tags and write histograms to file, extension",\
" specifies format."
print " Example:"
print " EcalCondDB -q=h.root -t tag1 -s since1 -t tag2 -s since2"
print
print " -g, --histo= [file] make histograms and write to file"
print " Example : "
print " EcalCondDB -g=h.png -t tag1 -s since1 "
print
print(" -q, --compare= [file]")
print(" compare two tags and write histograms to file, extension",\
" specifies format.")
print(" Example:")
print(" EcalCondDB -q=h.root -t tag1 -s since1 -t tag2 -s since2")
print()
print(" -g, --histo= [file] make histograms and write to file")
print(" Example : ")
print(" EcalCondDB -g=h.png -t tag1 -s since1 ")
print()

try:
opts, args = getopt.getopt(sys.argv[1:],
Expand All @@ -69,8 +70,8 @@ def usage():
sys.exit(0)

except getopt.GetoptError as ex:
print
print ex," , use -h or --help for help"
print()
print(ex," , use -h or --help for help")
sys.exit(0)

dbName = "frontier://FrontierProd/CMS_COND_31X_ECAL"
Expand Down Expand Up @@ -108,8 +109,8 @@ def usage():
if opt in ("-t","--tag"):
tags.append(arg)
if arg.find(".xml")>0 :
print "WARNING : plot from XML is not protected against changes"
print " in DetId or CondFormats"
print("WARNING : plot from XML is not protected against changes")
print(" in DetId or CondFormats")

if opt in ("-l","--listtags"):
do_list=1
Expand Down Expand Up @@ -157,44 +158,44 @@ def usage():

if do_dump :
if not len(tags):
print "Must specify tag with -t"
print("Must specify tag with -t")
sys.exit(0)
EcalCondTools.dumpXML(db,tags[0],sinces[0],outfilename)

if do_plot:
if not len(tags) or not len (sinces):
print "Must specify tag with -t [tag] -s [since]"
print("Must specify tag with -t [tag] -s [since]")
sys.exit(0)
EcalCondTools.plot(db,tags[0],sinces[0],outfilename)

if do_comp:
if len(tags) != 2 :
print "Must give exactly two tags to compare: -t tag1 -t tag2"
print("Must give exactly two tags to compare: -t tag1 -t tag2")
sys.exit(0)
if tags[0].find('.xml')<0 and len(sinces)!=2 :
print "Must specify tag, since to compare with -t [tag1] \
-s [since1] -t [tag2] -s [since2] "
print("Must specify tag, since to compare with -t [tag1] \
-s [since1] -t [tag2] -s [since2] ")
sys.exit(0)

EcalCondTools.compare(tags[0],db,sinces[0],
tags[1],db,sinces[1],outfilename)

if do_hist:
if not len(tags):
print "Must specify tag, since, with -t [tag] \
-s [runsince] (since not needed for xml)"
print("Must specify tag, since, with -t [tag] \
-s [runsince] (since not needed for xml)")
sys.exit(0)

if tags[0].find('.xml')<0 and not len(sinces) :
print "Must specify tag, since, with -t [tag] \
-s [runsince] "
print("Must specify tag, since, with -t [tag] \
-s [runsince] ")
sys.exit(0)

EcalCondTools.histo(db,tags[0],sinces[0],outfilename)

if do_liio:
if not len(tags):
print "Must specify tag with -t [tag]"
print("Must specify tag with -t [tag]")
sys.exit(0)
EcalCondTools.listIovs(db,tags[0])

Expand Down
45 changes: 23 additions & 22 deletions CondTools/Ecal/python/EcalCondTools.py
@@ -1,3 +1,4 @@
from __future__ import print_function
#
# Misc functions to manipulate Ecal records
# author: Stefano Argiro
Expand All @@ -22,7 +23,7 @@ def listTags(db):
tags = db.allTags()
db.commitTransaction()
for tag in tags.split():
print tag
print(tag)
except:
return ""

Expand All @@ -32,12 +33,12 @@ def listIovs(db,tag):
try :
iov = inspect.Iov(db,tag)
iovlist = iov.list()
print "Available iovs for tag: ",tag
print("Available iovs for tag: ",tag)
for p in iovlist:
print " Since " , p[1], " Till " , p[2]
print(" Since " , p[1], " Till " , p[2])

except Exception as er :
print " listIovs exception ",er
print(" listIovs exception ",er)

def dumpXML(db,tag,since,filename='dump.xml'):
'''Dump record in XML format for a given tag '''
Expand All @@ -56,10 +57,10 @@ def dumpXML(db,tag,since,filename='dump.xml'):
db.commitTransaction()
payload = inspect.PayLoad(db, tag, elem)
out = open(filename,'w')
print >> out, payload
print(payload, file=out)

except Exception as er :
print " dumpXML exception ",er
print(" dumpXML exception ",er)

def plot (db, tag,since,filename='plot.root'):
'''Invoke the plot function from the wrapper and save to the specified \
Expand All @@ -82,14 +83,14 @@ def plot (db, tag,since,filename='plot.root'):
payload.plot(filename,"",[],[])

except Exception as er :
print " plot exception ",er
print(" plot exception ",er)


def compare(tag1,db1,since1,
tag2,db2,since2,filename='compare.root'):
'''Produce comparison plots for two records. Save plots to file \
according to format. tag can be an xml file'''
print "EcalCondTools.py compare tag1 ", tag1, "since1 : ", since1, " tag2 ", tag2," s2 ", since2
print("EcalCondTools.py compare tag1 ", tag1, "since1 : ", since1, " tag2 ", tag2," s2 ", since2)

coeff_1_b=[]
coeff_2_b=[]
Expand All @@ -112,7 +113,7 @@ def compare(tag1,db1,since1,
exe = Plug.Extractor(w)
# p = getObject(db1,tag1,since1,ex)
# p.extract(ex)
print " before loop"
print(" before loop")
for elem in db1.iov(tag1).elements :
if str(elem.since())==str(since1):
found=1
Expand All @@ -124,9 +125,9 @@ def compare(tag1,db1,since1,
db1.commitTransaction()

except Exception as er :
print " compare first set exception ",er
print(" compare first set exception ",er)
if not found :
print "Could not retrieve payload for tag: " , tag1, " since: ", since1
print("Could not retrieve payload for tag: " , tag1, " since: ", since1)
sys.exit(0)

else:
Expand Down Expand Up @@ -156,9 +157,9 @@ def compare(tag1,db1,since1,
db2.commitTransaction()

except Exception as er :
print " compare second set exception ",er
print(" compare second set exception ",er)
if not found :
print "Could not retrieve payload for tag: " , tag2, " since: ", since2
print("Could not retrieve payload for tag: " , tag2, " since: ", since2)
sys.exit(0)

else:
Expand Down Expand Up @@ -263,9 +264,9 @@ def histo (db, tag,since,filename='histo.root'):
db.commitTransaction()

except Exception as er :
print " histo exception ",er
print(" histo exception ",er)
if not found :
print "Could not retrieve payload for tag: " , tag, " since: ", since
print("Could not retrieve payload for tag: " , tag, " since: ", since)
sys.exit(0)

else :
Expand Down Expand Up @@ -338,11 +339,11 @@ def getToken(db,tag,since):
tmpsince=p[1]
if str(tmpsince)==str(since) :
return p[0]
print "Could not retrieve token for tag: " , tag, " since: ", since
print("Could not retrieve token for tag: " , tag, " since: ", since)
sys.exit(0)

except Exception as er :
print er
print(er)


def getObject(db,tag,since):
Expand All @@ -352,23 +353,23 @@ def getObject(db,tag,since):
# exec('import '+db.moduleName(tag)+' as Plug')
db.startReadOnlyTransaction()
Plug = __import__(str(db.payloadModules(tag)[0]))
print " getObject Plug"
print(" getObject Plug")
payload = Plug.Object(db)
db.commitTransaction()
listOfIovElem= [iovElem for iovElem in db.iov(tag).elements]
print " getObject before loop"
print(" getObject before loop")
for elem in db.iov(tag).elements :
if str(elem.since())==str(since):
found=1
print " getObject found ", elem.since()
print(" getObject found ", elem.since())
# return Plug.Object(elem)
return elem

except Exception as er :
print " getObject exception ",er
print(" getObject exception ",er)

if not found :
print "Could not retrieve payload for tag: " , tag, " since: ", since
print("Could not retrieve payload for tag: " , tag, " since: ", since)
sys.exit(0)


Expand Down
13 changes: 7 additions & 6 deletions CondTools/Ecal/python/SplitLinear.py
Expand Up @@ -2,14 +2,15 @@
#from G.Benelli and Arun Mittal
# 2016 November 17
#Quick script to split a large sqlite file (holding all of our Noise payloads (Run1+Run2) into a set of smaller ones.
from __future__ import print_function
import subprocess
IOVs=[]
for line in subprocess.Popen("conddb --noLimit --db Linear.db list EcalLinearCorrections_from2011_offline",shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT).stdout.readlines():
if "EcalTimeDependentCorrections" in line:
# IOVs.append(line.split()[0]) # for run based IOVs
IOVs.append((line.split()[2].strip(')')).strip('(')) # for timestamp based IOVs
print IOVs
print "There are %s IOVs!"%len(IOVs)
print(IOVs)
print("There are %s IOVs!"%len(IOVs))
#Prepare the conddb_import commands template:
#CommandTemplate="conddb_import -f sqlite:SiStripNoise_GR10_v3_offline.db -c sqlite:SiStripNoise_GR10_v3_offline_%s_%s.db -i SiStripNoise_GR10_v4_offline -t SiStripNoise_GR10_v4_offline -b %s -e %s"

Expand All @@ -19,15 +20,15 @@

RelevantIOVs.append((RelevantIOVs[-1][2],IOVs[-1],IOVs[-1]))

print RelevantIOVs
print(RelevantIOVs)
for i,splitIOVs in enumerate(RelevantIOVs):
begin=splitIOVs[0]
end=splitIOVs[1]
upperLimit=splitIOVs[1]
print i,begin,end,upperLimit
print(i,begin,end,upperLimit)
command = "conddb_import -f sqlite:Linear.db -c sqlite:Linear_"+str(begin)+"_"+str(end)+".db -i EcalLinearCorrections_from2011_offline -t EcalLinearCorrections_from2011_offline -b "+str(begin)+" -e "+str(end)
print command
print(command)

#Now if we want to execute it inside Python uncomment the following two lines:
STDOUT=subprocess.Popen(command,shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT).stdout.read()
print STDOUT
print(STDOUT)