#!/bin/env python """ A DOM configuration module for DAQ Author: K. Hanson (kael.hanson@icecube.wisc.edu) Date: 2006-01-08 """ import os, sys, math import xml.sax, xml.dom.minidom from xml.sax.handler import ContentHandler import time hvmap = dict() def log(s, level=0): if level > 1: print >>sys.stderr, "[%s] LOG LEVEL=%d: %s" % \ (time.strftime("%c"), level, s) pass def generateDOMConfiguration(mbid, string, module, runtype): """ Generate an XML string that represents the DOM configuration. Arguments are DOM mainboard ID, deployed string, deployed module location (1-64) and runtype: = 1 --> beacon run without HV = 2 --> dark noise run with elevated thresholds = 3 --> standard LC run """ if mbid == '57bb7c43b042': hvlimit = 2500 else: hvlimit = 4095 if runtype == 1: # HV OFF - beacons only hv = 0 samples = 4*(128,) fadc = 250 spe = 560 lcmode = 0 else: # These runs do require HV set to 1.0E+07 but put in # reasonable default (1400 V) if you can't find the DOMCal hv = 2800 if mbid in hvmap: hv = hvmap[mbid] samples = (128, 32, 32, 0) fadc = 50 if runtype == 2: # Dark run /w/ elevated SPE spe = 750 lcmode = 0 elif runtype == 3: # Standard LC type run spe = 560 if module == 1: # Want DN ONLY LC lcmode = 3 elif module == 60: # Want UP ONLY LC lcmode = 2 return '\n' % mbid + \ ' \n' % samples[0] + \ ' \n' % samples[1] + \ ' \n' % samples[2] + \ ' \n' % samples[3] + \ ' \n' + \ ' \n' + \ ' \n' + \ ' \n' + \ ' \n' % fadc + \ ' \n' + \ ' \n' + \ ' \n' + \ ' \n' + \ ' \n' + \ ' \n' + \ ' \n' + \ ' \n' + \ ' \n' + \ ' \n' % spe + \ ' \n' + \ ' \n' + \ ' \n' + \ ' \n' + \ ' \n' + \ ' \n' + \ ' \n' % hvlimit + \ ' \n' % hv + \ ' \n' + \ ' \n' % lcmode + \ ' \n' + \ ' \n' + \ '' 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 def process_domcals(xmls, target_gain=1.0E+07): """ Parses the gain vs. HV information from the DOMCal XMLs """ fg = FitGetter() # Parse the HV Gain fits for filename in xmls: xml.sax.parse(filename, fg) mbid = filename[7:19] if fg.slope > 0: hvmap[mbid] = math.pow( 10.0, (math.log10(target_gain)-fg.intercept)/fg.slope ) else: log("Bad fit for mbid %s" % mbid, 3)