#!/bin/env python """ A simple script to process a TestDAQ XML steering file and the attendant domcal XML files to produce a file for input into the daq-config script. This script strips the PMT gain information from the domcal files and rewrites the doctree representation of the steering file. % ./mksteering2.py [ domcal-1.xml domcal-2.xml ... ] Author: K. Hanson (kael.hanson@icecube.wisc.edu) Date: 2006-01-02 """ import os, sys, math import xml.sax, xml.dom.minidom from xml.sax.handler import ContentHandler import time def log(s, level=0): if level > 1: print >>sys.stderr, "[%s] LOG LEVEL=%d: %s" % \ (time.strftime("%c"), level, s) pass def set_dom_param(dom_node, name, value): par = [ p for p in dom_node.getElementsByTagName('param') \ if p.attributes['name'].value == name ][0] par.attributes['value'].value = value class FitGetter(ContentHandler): def startDocument(self): self.state = 0 self.slope_string = '' self.inter_string = '' self.slope = 0.0 self.intercept = 0.0 def startElement(self, name, attrs): if name == 'hvGainCal': self.state = 1 log("set state to 1") elif name == 'param' and self.state == 1: if attrs['name'] == 'slope': self.state = 2 log("set state to 2") elif attrs['name'] == 'intercept': self.state = 3 log("set state to 3") def endElement(self, name): if name == 'hvGainCal': self.state = 0 log("set state to 0") self.intercept = float(self.inter_string) self.slope = float(self.slope_string) if name == 'param' and self.state in (2,3): self.state = 1 def characters(self, content): if self.state == 2: self.slope_string += content elif self.state == 3: self.inter_string += content if __name__ == "__main__": target_gain = 3.3e+06 args = sys.argv[1:] fg = FitGetter() # 1st argument is the steering file XML steering_xml = args.pop(0) steering_doc = xml.dom.minidom.parse(steering_xml) # Parse the HV Gain fits hv = dict() while len(args) > 0: filename = args.pop(0) xml.sax.parse(filename, fg) mbid = filename[7:19] if fg.slope > 0: hv[mbid] = math.pow(10.0, (math.log10(target_gain)-fg.intercept)/fg.slope) else: hv[mbid] = 1000.0 log("Bad fit for mbid %s" % mbid, 3) for dom in steering_doc.getElementsByTagName('dom'): mbid = dom.attributes['domId'].value dom.attributes['card'].value = u'-1' dom.attributes['pair'].value = u'-1' dom.attributes['domhub'].value = u'unknown-domhub' if mbid in hv: set_dom_param(dom, 'PMT_HV_DAC', unicode(int(2*hv[mbid]+0.5))) set_dom_param(dom, 'ANALOG_MUX_SELECT', u'255') set_dom_param(dom, 'DAC_SINGLE_SPE_THRESH', u'943') set_dom_param(dom, 'FE_PULSER_RATE', u'4') steering_doc.writexml(sys.stdout)