-
Ruud Overeem authoredRuud Overeem authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
createPICfile 9.04 KiB
#!/usr/bin/env python
#
# $Id$
#
# Syntax: createPICFile ( -a | stationname [stationame ...])
#
# Makea a file with PVSS(!) datapoints that must be monitored in SAS.
import re, sys
from optparse import OptionParser
def expandRCUMarker(dataPoint, nrRSP):
"""
Expands the lines that only contain markers up to @rcu@.
"""
for rcu in range(0, nrRSP * 8):
rsp = rcu / 8
subrack = rsp / 4
cabinet = rsp / 8
print "21 "+dataPoint.replace("@cabinet@","Cabinet"+str(cabinet)) \
.replace("@subrack@","Subrack"+str(subrack)) \
.replace("@RSPBoard@", "RSPBoard"+str(rsp)) \
.replace("@rcu@", "RCU"+str(rcu))+".status.state"
def expandRSPBoardMarker(dataPoint, nrRSP):
"""
Expands the lines that only contain markers up to @rcu@.
"""
for rsp in range(0, nrRSP):
subrack = rsp / 4
cabinet = rsp / 8
print "21 "+dataPoint.replace("@cabinet@","Cabinet"+str(cabinet)) \
.replace("@subrack@","Subrack"+str(subrack)) \
.replace("@RSPBoard@", "RSPBoard"+str(rsp))+".status.state"
def expandTBBoardMarker(dataPoint, nrTBB):
"""
Expands the lines that only contain markers up to @rcu@.
"""
for tbb in range(0, nrTBB):
subrack = tbb / 2
cabinet = tbb / 4
print "21 "+dataPoint.replace("@cabinet@","Cabinet"+str(cabinet)) \
.replace("@subrack@","Subrack"+str(subrack)) \
.replace("@TBBoard@", "TBBoard"+str(tbb))+".status.state"
def expandSubrackMarker(dataPoint, nrRSP):
"""
Expands the lines that only contain markers up to @rcu@.
"""
nrSubracks = nrRSP / 4
if nrRSP % 4: nrSubracks += 1
for subrack in range(0, nrSubracks):
cabinet = subrack / 2
print "21 "+dataPoint.replace("@cabinet@","Cabinet"+str(cabinet)) \
.replace("@subrack@","Subrack"+str(subrack))+".status.state"
def expandCabinetMarker(dataPoint, nrRSP):
"""
Expands the lines that only contain the @cabinet@ marker with all cabinet numbers
"""
nrCabinets = nrRSP / 8
if nrRSP % 8: nrCabinets += 1
for cabinet in range(0, nrCabinets):
print "21 "+dataPoint.replace("@cabinet@","Cabinet"+str(cabinet))+".status.state"
def expandLBAMarker(dataPoint, nrLBA):
"""
Expands the lines that only contain the @lbaantenna@ marker with all cabinet numbers
"""
for lba in range(0, nrLBA):
print "21 "+dataPoint.replace("@lbaantenna@","LBA%03d"%lba)+".status.state"
def expandHBAMarker(dataPoint, nrHBA):
"""
Expands the lines that only contain the @hbaantenna@ marker with all cabinet numbers
"""
for lba in range(0, nrHBA):
print "21 "+dataPoint.replace("@hbaantenna@","HBA%02d"%lba)+".status.state"
# MAIN
# all the files we are using
# We can start this from a SVN tree, or from the install location (/opt/lofar)
# This is indicated by the "-l" command line option.
parser = OptionParser()
parser.add_option("-l", "--local", action="store_true", dest="isLocal", default=False,
help="Run createPICFile in situ (in a svn checkout tree, not an in install tree [default!]")
(options, args) = parser.parse_args()
if (options.isLocal):
PVSSbasefile= "../PVSS/data/PVSSDataPoints.base"
StationFile = "../StaticMetaData/StationInfo.dat"
ControlFile = "../StaticMetaData/ControlInfo.dat"
RingFile = "../PVSS/data/Rings.list"
ClusterFile = "../PVSS/data/Clusters.list"
else:
PVSSbasefile= "/opt/lofar/pvss/dpdef/PVSSDataPoints.base"
StationFile = "/opt/lofar/etc/StationInfo.dat"
ControlFile = "/opt/lofar/etc/ControlInfo.dat"
RingFile = "/opt/lofar/pvss/dpdef/Rings.list"
ClusterFile = "/opt/lofar/pvss/dpdef/Clusters.list"
filledLine = re.compile("^[^#].*", re.MULTILINE)
# construct a dictionary from the rings file: key is first character, value is ringname
ringDict = {}
for line in filledLine.findall(open(RingFile).read()):
ringDict[line[0]] = line
#print "ringDict =", ringDict
# construct a list with all ring_station combinations
ringStations = []
stations = []
for line in filledLine.findall(open(StationFile).read()):
# print "line: =",line
if (line.strip() and len(line.split()) == 12):
(name, stationID, stnType, long, lat, height, nrRSP, nrTBB, nrLBA, nrHBA, HBAsplit, LBAcal ) = line.split()
if (height != "0"):
ringStations.append(ringDict[stnType]+"_"+name)
stations.append(name)
#print "ringStations =", ringStations
#print "stations =", stations
# construct a dictionary for the clusters
clusterDict = {}
for line in filledLine.findall(open(ClusterFile).read()):
(mnemonic, prefix, count) = line.split()
clusterDict[mnemonic] = (prefix, count)
#print "clusterDict =", clusterDict
# construct a list for the control-machines
controlList = []
for line in filledLine.findall(open(ControlFile).read()):
(name, ipaddr, macaddr) = line.split()
controlList.append(name)
#print "controlList =", controlList
# open outputfile and write top-node of PIC
print "21 LOFAR.status.state"
print "21 LOFAR_PIC.status.state"
print "21 LOFAR_PermSW.status.state"
# construct the rings with stations and the clusters with their nodes
# ??? ??? C P ??? ???_PIC_@???@
ringStationMask=""
central=re.compile("^\w+[ \t]+[^ \t]+[ \t]+M[ \t]+[YN][ \t]+([A-Za-z_]+_(?:PIC|PermSW)_@.*)", \
re.IGNORECASE | re.MULTILINE)
for line in central.findall(open(PVSSbasefile).read()):
# print "line =",line
if line.find("@station@") >= 0:
ringStationMask=line.replace("LOFAR_","")
for RS in ringStations:
print "21 "+line.replace("@ring@_@station@", RS)+".status.state"
# ---
elif line.find("@ring@") >= 0:
# for all rings
for ring in ringDict.keys():
print "21 "+line.replace("@ring@", ringDict[ring])+".status.state"
# ---
elif line.find("@node@") >= 0:
# for all nodes in each cluster
for cluster in clusterDict.keys():
(name, count) = clusterDict[cluster]
for nodeNr in range(1, int(count)+1):
nodename = "%s%03d" % (name, nodeNr)
print "21 "+line.replace("@cluster@_@node@", cluster+"_"+nodename)+".status.state"
# for all nodes
# for all clusters
# also add= the control 'cluster' at this place
for node in controlList:
print "21 "+line.replace("@cluster@_@node@", "Control_"+node)+".status.state"
# ---
elif line.find("@cluster@") >= 0:
# for all clusters
for cluster in clusterDict.keys():
print "21 "+line.replace("@cluster@", cluster)+".status.state"
# and the control-section
print "21 "+line.replace("@cluster@", "Control")+".status.state"
# ---
elif line.find("@") < 0:
print "21 "+line+".status.state"
# for all expandable lines
# Permanent software on MCU
software=re.compile("^\w+[ \t]+[^ \t]+[ \t]+M[ \t]+[YN][ \t]+([A-Za-z_]+_PermSW_[^@].*)", \
re.IGNORECASE | re.MULTILINE)
for line in software.findall(open(PVSSbasefile).read()):
print "21 MCU001:%s.status.state" % line
# generate the hardware on each station
for line in filledLine.findall(open(StationFile).read()):
# print "line: =",line
if (line.strip() and len(line.split()) == 12):
(name, stationID, stnType, long, lat, height, nrRSP, nrTBB, nrLBA, nrHBA, HBAsplit, LBAcal ) = line.split()
if ( height == "0" ):
continue
# Find all expandable hardware elements on a station. The line syntax is:
# ??? ??? S P ??? ???_PIC_@...@
# we are only interested in the @...@ part.
station=re.compile("^\w+[ \t]+[^ \t]+[ \t]+S[ \t]+[YN][ \t]+[A-Za-z_]+_PIC_(@.*)", \
re.IGNORECASE | re.MULTILINE)
for line in station.findall(open(PVSSbasefile).read()):
prefix="@station@:LOFAR_PIC_".replace("@station@", name)
if line.find("@rcu@") >= 0:
expandRCUMarker(prefix+line, int(nrRSP))
elif line.find("@RSPBoard@") >= 0:
expandRSPBoardMarker(prefix+line, int(nrRSP))
elif line.find("@TBBoard@") >= 0:
expandTBBoardMarker(prefix+line, int(nrTBB))
elif line.find("@subrack@") >= 0:
expandSubrackMarker(prefix+line, int(nrRSP))
elif line.find("@cabinet@") >= 0:
expandCabinetMarker(prefix+line, int(nrRSP))
elif line.find("@lbaantenna@") >= 0:
expandLBAMarker(prefix+line, int(nrLBA))
elif line.find("@hbaantenna@") >= 0:
expandHBAMarker(prefix+line, int(nrHBA))
# for all expandable lines
# Permanent software on the stations
software=re.compile("^\w+[ \t]+[^ \t]+[ \t]+S[ \t]+[YN][ \t]+([A-Za-z_]+_PermSW_.*)", \
re.IGNORECASE | re.MULTILINE)
for line in software.findall(open(PVSSbasefile).read()):
if line.find("@") < 0:
print "21 %s:%s.status.state" % (name, line)
#for all stations