# This script demonstrates how to create and run a correlator that posts a # correlation events. The correlator posts events until it is explicitly stopped. # A filter is added to the correlator that accepts correlations with at most one # missing channel. A filter is added to a channel to restrict the accepted # value within the specified range. # As soon as a full correlation is caught it is posted immediately. If no full # correlation is caught within the specified timeout, a partial correlation # (if any) which satisfies the filters is posted. Regardless of how a an # event is generated (including a no-correlation event), the timeout timer is # reset thus starting a new cylce of events. import sys from jarray import * from java.lang import * from java.util import * from gov.sns.tools.correlator import * from gov.sns.ca.correlator import * # CorrelationMonitor sets up the correlator and listens for correlation events class CorrelationMonitor(CorrelationNotice): correlator = 0 def __init__(self): # accept correlations with at most one missing channel correlation_filter = CorrelationFilterFactory.maxMissingFilter(1) # create a correlator with the filter and a 0.1 second correlation time span self.correlator = ChannelCorrelator(0.1, correlation_filter) self.correlator.addListener(self) # add the channels to monitor self.correlator.addChannel("snsWPMQ1_sine") self.correlator.addChannel("snsWPMQ2_sine") self.correlator.addChannel("snsWPMQ3_sine") self.correlator.addChannel("snsWPMQ4_sine") # add a filter to channel 5 to limit its acceptable range between 0 and 1 self.correlator.addChannel("snsWPMQ5_sine", RecordFilterFactory.rangeDoubleFilter(0,1)) self.correlator.addChannel("snsWPMQ6_sine") self.correlator.addChannel("snsWPMQ7_sine") self.correlator.addChannel("snsWPMQ8_sine") def monitorWithTimeout(self, timeout): self.correlator.monitorWithTimeout(timeout) def newCorrelation(self, sender, correlation): print "Captured correlation at: ", correlation.meanDate() print correlation def noCorrelationCaught(self, sender): print "No correlation found!" # create a monitor and start monitoring the channels monitor = CorrelationMonitor() monitor.monitorWithTimeout(5.0)