Skip to content
Snippets Groups Projects
Commit 77a003f2 authored by Walter Lampl's avatar Walter Lampl
Browse files

LArCalorimeter/LArCondUtils: (late) migration of scripts to python3, enable flake8

parent a09543cf
2 merge requests!718572024-05-31: merge of 24.0 into main,!71764LArCalorimeter/LArCondUtils: (late) migration of scripts to python3, enable flake8
......@@ -19,5 +19,10 @@ atlas_add_component( LArCondUtils
# Install files from the package:
atlas_install_runtime( share/LArEmLvl1.data share/LArHecLvl1.data share/LArFcalLvl1.data )
atlas_install_scripts( share/LArBuildHVPathologies.sh share/fillPileUpNoiseLumi.py share/dumpHVPathFromNtuple.py )
atlas_install_scripts( share/LArBuildHVPathologies.sh )
atlas_install_scripts(
share/fillPileUpNoiseLumi.py
share/dumpHVPathFromNtuple.py
POST_BUILD_CMD ${ATLAS_FLAKE8} )
#!/bin/env python
# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
import os,re
import sys
from os import popen
import string
import commands
import ROOT
def DumpPathology(inf, hvline, outfile, append):
try:
if not inf.IsOpen():
print 'File not open ?'
return
except:
return
if not inf.IsOpen():
print('File not open ?')
return
try:
if append:
fout=open(outfile,'a')
else:
fout=open(outfile,'w')
except:
print 'Could not open output file ',outfile
except Exception as e:
print('Could not open output file ',outfile)
print (e)
return
tree=inf.Get("hv/mytree")
......@@ -30,7 +25,7 @@ def DumpPathology(inf, hvline, outfile, append):
br_hvline=tree.GetBranch("HVline")
hvdict={}
for i in range(0,tree.GetEntries()):
if i%10000 == 0: print i
if i%10000 == 0: print(i)
br_hvline.GetEntry(i)
if tree.HVline != hvline: continue
tree.GetEntry(i)
......@@ -49,10 +44,10 @@ def DumpPathology(inf, hvline, outfile, append):
#print hvdict
# now write to a file
if not append: fout.write('/LAR/HVPathologiesOfl/Pathologies\n')
for k in hvdict.keys():
for k in list(hvdict.keys()):
ll=hvdict[k]
if len(ll) != 6:
print 'Wrong list: ',ll,' continue to next!!!'
print('Wrong list: ',ll,' continue to next!!!')
continue
wstr=str(ll[0])+' '+str(ll[1])+' '+str(ll[2])+' '+str(ll[3])+' '+str(ll[4])+' '+str(hvline/1000)+' '+str(hvline%1000)+' '+str((ihv<<4)&0xFFF0)+'\n'
fout.write(wstr)
......@@ -66,20 +61,22 @@ if __name__=="__main__":
try:
infile = sys.argv[1]
inf = ROOT.TFile(infile,'read')
except:
print 'HV ntuple ',infile,' doesnt exist ?'
except Exception as e:
print('HV ntuple ',infile,' doesnt exist ?')
print(e)
sys.exit()
print 'HV ntuple file: ',infile
print('HV ntuple file: ',infile)
try:
hvline = int(sys.argv[2])
except:
print 'HVline number doesnt exist ?'
except Exception as e:
print('HVline number doesnt exist ?')
print (e)
sys.exit()
if hvline < 1000 or hvline > 400000:
print 'wrong HV line number: ',hvline
print('wrong HV line number: ',hvline)
sys.exit()
if len(sys.argv) > 3:
......@@ -87,7 +84,7 @@ if __name__=="__main__":
else:
outfile='hvpat.txt'
print 'Output file: ',outfile
print('Output file: ',outfile)
if len(sys.argv) > 4:
if int(sys.argv[4])==0:
......@@ -97,7 +94,7 @@ if __name__=="__main__":
else:
append=False
print 'Append to out file: ',append
print('Append to out file: ',append)
DumpPathology(inf, hvline, outfile, append)
inf.Close()
......
#!/bin/env python
# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
from PyCool import cool
from time import asctime,gmtime
def createFolder(db,name):
desc='<timeStamp>run-lumi</timeStamp><addrHeader><address_header service_type="71" clid="1238547719" /></addrHeader><typeName>CondAttrListCollection</typeName>'
......@@ -24,7 +23,7 @@ def fillPileUpNoiseLumi(db,tag,dataIn, folderName="/CALO/Ofl/Noise/PileUpNoiseLu
folder = db.getFolder(folderName)
else:
#create new folder
print "Folder", folderName,"does not exit yet. Creating it now."
print("Folder", folderName,"does not exit yet. Creating it now.")
folder=createFolder(db,folderName)
since=cool.ValidityKeyMin
......@@ -40,45 +39,45 @@ def fillPileUpNoiseLumi(db,tag,dataIn, folderName="/CALO/Ofl/Noise/PileUpNoiseLu
if __name__=='__main__':
import os,sys,getopt
import os,sys
if len(sys.argv)<2 or sys.argv[1]=="-h" or sys.argv[1]=="--help":
print "Usage:"
print("Usage:")
print "fillPileUpNoiseLumi.py lumi"
print("fillPileUpNoiseLumi.py lumi")
sys.exit(-1)
from LArConditionsCommon.getCurrentFolderTag import getCurrentFolderTag
(current,next)=getCurrentFolderTag("COOLOFL_CALO/CONDBR2","/CALO/Ofl/Noise/PileUpNoiseLumi")
if current is None:
print "Failed to get CURRENT folder level tag!"
print("Failed to get CURRENT folder level tag!")
sys.exit(-1)
try:
float(sys.argv[1])
except ValueError:
print "Argument is not a float"
print("Argument is not a float")
newlumi=float(sys.argv[1])
sqlitename="PileUpNoiseLumi.db"
if os.access(sqlitename,os.F_OK):
print "ERROR: File",sqlitename,"exists already. Please delete!"
print("ERROR: File",sqlitename,"exists already. Please delete!")
sys.exit(-1)
print "Using folder-level tag:",current
print("Using folder-level tag:",current)
connect="sqlite://;schema="+sqlitename+";dbname=CONDBR2"
dbSvc = cool.DatabaseSvcFactory.databaseService()
try:
db = dbSvc.openDatabase(connect,False)
except Exception:
print "Database does not exist, try to create it ..."
print("Database does not exist, try to create it ...")
try:
db=dbSvc.createDatabase(connect)
except Exception,e:
print e
print "Could not create database"
except Exception as e:
print(e)
print("Could not create database")
sys.exit(-1)
pass
pass
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment