def test_I3Trigger_equality(self): key1 = dataclasses.TriggerKey() key1.source = key1.source.IN_ICE key1.type = key1.type.MIN_BIAS key1.subtype = key1.subtype.M18 key1.config_id = 101 trig1 = dataclasses.I3Trigger() trig1.time = 350 * I3Units.ns trig1.length = 6.55 * I3Units.microsecond trig1.fired = False trig1.key = key1 key2 = dataclasses.TriggerKey() key2.source = key2.source.IN_ICE key2.type = key2.type.MIN_BIAS key2.subtype = key2.subtype.M18 key2.config_id = 101 trig2 = dataclasses.I3Trigger() trig2.time = 350 * I3Units.ns trig2.length = 6.55 * I3Units.microsecond trig2.fired = False trig2.key = key2 self.assertEqual(trig1, trig2, "these should be the same.") trig3 = dataclasses.I3Trigger() self.assertNotEqual(trig1, trig3, "these should not be the same.")
def test_example(self): t = dataclasses.TriggerKey() print(t) t2 = dataclasses.TriggerKey(dataclasses.EXTERNAL, dataclasses.STRING) print(t2) t3 = dataclasses.TriggerKey(dataclasses.AMANDA_MUON_DAQ, dataclasses.STRING) print(t3) t4 = dataclasses.TriggerKey(dataclasses.AMANDA_TWR_DAQ, dataclasses.STRING) print(t4)
def test_example(self): t = dataclasses.TriggerKey() print t t2 = dataclasses.TriggerKey(dataclasses.I3Trigger.EXTERNAL, dataclasses.I3Trigger.STRING) print t2 t3 = dataclasses.TriggerKey(dataclasses.I3Trigger.AMANDA_MUON_DAQ, dataclasses.I3Trigger.STRING) print t3 t4 = dataclasses.TriggerKey(dataclasses.I3Trigger.AMANDA_TWR_DAQ, dataclasses.I3Trigger.STRING) print t4
def test_put_triggerstatus(self): tkey = dataclasses.TriggerKey() tkey.source = dataclasses.I3Trigger.IN_ICE tkey.type = dataclasses.I3Trigger.SIMPLE_MULTIPLICITY tkey.config_id = 999 tstat = dataclasses.I3TriggerStatus() tstat.trigger_name = "MyNewTrigger" tstat.trigger_settings["threshold"] = '3' tstat.trigger_settings["timeWindow"] = '2500' tstat.trigger_settings["domSet"] = '5' roc = dataclasses.I3TriggerStatus.I3TriggerReadoutConfig() roc.readout_time_minus = 10000 roc.readout_time_plus = 10000 roc.readout_time_offset = 0 # add the readout config to the trigger status tstat.readout_settings[dataclasses.I3TriggerStatus.ALL] = roc tstat_map = dataclasses.I3TriggerStatusMap() tstat_map[tkey] = tstat obj = gcd_utils.put_triggerstatus(tstat_map, self.gcd_file, "./newGCD.i3.gz") self.assertNotEqual(obj, None, "fail")
def DAQ(self, frame): print("TestModule : DAQ!!!") if frame.Has(self.triggerName): triggers = frame.Get(self.triggerName) else: print("FAIL : trigger hierarchy not found in the frame") print(str(frame)) sys.exit() print(str(triggers)) test_key = dataclasses.TriggerKey(self.sourceID, self.typeID, self.configID) t = find_triggers(triggers, test_key) if not self.trigger: # we're testing for the lack of a trigger if t: print("FAIL: this was not supposed to trigger") sys.exit(1) else: if not t: print("FAIL : trigger (%d,%d,%d) not found in the heirarchy" % \ (self.sourceID, self.typeID, self.configID)) sys.exit(1) if not t[0].fired: print("FAIL : trigger not fired") sys.exit(1) self.PushFrame(frame)
def test_get_type_string(self): tk = dataclasses.TriggerKey() self.assertEqual(tk.get_type_string(dataclasses.SIMPLE_MULTIPLICITY), "SIMPLE_MULTIPLICITY", "Should be SIMPLE_MULTIPLICITY") self.assertEqual(tk.get_type_string(dataclasses.CALIBRATION), "CALIBRATION", "Should be CALIBRATION") self.assertEqual(tk.get_type_string(dataclasses.MIN_BIAS), "MIN_BIAS", "Should be MIN_BIAS") self.assertEqual(tk.get_type_string(dataclasses.THROUGHPUT), "THROUGHPUT", "Should be THROUGHPUT") self.assertEqual(tk.get_type_string(dataclasses.TWO_COINCIDENCE), "TWO_COINCIDENCE", "Should be TWO_COINCIDENCE") self.assertEqual(tk.get_type_string(dataclasses.THREE_COINCIDENCE), "THREE_COINCIDENCE", "Should be THREE_COINCIDENCE") self.assertEqual(tk.get_type_string(dataclasses.MERGED), "MERGED", "Should be MERGED") self.assertEqual(tk.get_type_string(dataclasses.SLOW_PARTICLE), "SLOW_PARTICLE", "Should be SLOW_PARTICLE") self.assertEqual(tk.get_type_string(dataclasses.FRAGMENT_MULTIPLICITY), "FRAGMENT_MULTIPLICITY", "Should be FRAGMENT_MULTIPLICITY") self.assertEqual(tk.get_type_string(dataclasses.STRING), "STRING", "Should be STRING") self.assertEqual(tk.get_type_string(dataclasses.VOLUME), "VOLUME", "Should be VOLUME") self.assertEqual(tk.get_type_string(dataclasses.SPHERE), "SPHERE", "Should be SPHERE") self.assertEqual(tk.get_type_string(dataclasses.UNBIASED), "UNBIASED", "Should be UNBIASED") self.assertEqual(tk.get_type_string(dataclasses.SPASE_2), "SPASE_2", "Should be SPASE_2") self.assertEqual(tk.get_type_string(dataclasses.UNKNOWN_TYPE), "UNKNOWN_TYPE", "Should be UNKNOWN_TYPE")
def test_get_source_string(self): tk = dataclasses.TriggerKey() self.assertEqual(tk.get_source_string(dataclasses.IN_ICE), "IN_ICE", "Should be IN_ICE") self.assertEqual(tk.get_source_string(dataclasses.ICE_TOP), "ICE_TOP", "Should be ICE_TOP") self.assertEqual(tk.get_source_string(dataclasses.AMANDA_TWR_DAQ), "AMANDA_TWR_DAQ", "Should be AMANDA_TWR_DAQ") self.assertEqual(tk.get_source_string(dataclasses.EXTERNAL), "EXTERNAL", "Should be EXTERNAL") self.assertEqual(tk.get_source_string(dataclasses.GLOBAL), "GLOBAL", "Should be GLOBAL") self.assertEqual(tk.get_source_string(dataclasses.AMANDA_MUON_DAQ), "AMANDA_MUON_DAQ", "Should be AMANDA_MUON_DAQ") self.assertEqual(tk.get_source_string(dataclasses.SPASE), "SPASE", "Should be SPASE") self.assertEqual(tk.get_source_string(dataclasses.UNKNOWN_SOURCE), "UNKNOWN_SOURCE", "Should be UNKNOWN_SOURCE")
def test_get_source_from_string(self): tk = dataclasses.TriggerKey() self.assertEqual(tk.get_source_from_string("IN_ICE"), dataclasses.IN_ICE, "Should be IN_ICE") self.assertEqual(tk.get_source_from_string("ICE_TOP"), dataclasses.ICE_TOP, "Should be ICE_TOP") self.assertEqual(tk.get_source_from_string("AMANDA_TWR_DAQ"), dataclasses.AMANDA_TWR_DAQ, "Should be AMANDA_TWR_DAQ") self.assertEqual(tk.get_source_from_string("EXTERNAL"), dataclasses.EXTERNAL, "Should be EXTERNAL") self.assertEqual(tk.get_source_from_string("GLOBAL"), dataclasses.GLOBAL, "Should be GLOBAL") self.assertEqual(tk.get_source_from_string("AMANDA_MUON_DAQ"), dataclasses.AMANDA_MUON_DAQ, "Should be AMANDA_MUON_DAQ") self.assertEqual(tk.get_source_from_string("SPASE"), dataclasses.SPASE, "Should be SPASE") self.assertEqual(tk.get_source_from_string("UNKNOWN_SOURCE"), dataclasses.UNKNOWN_SOURCE, "Should be UNKNOWN_SOURCE")
def test_get_type_from_string(self): tk = dataclasses.TriggerKey() self.assertEqual(tk.get_type_from_string("SIMPLE_MULTIPLICITY"), dataclasses.I3Trigger.SIMPLE_MULTIPLICITY, "Should be SIMPLE_MULTIPLICITY") self.assertEqual(tk.get_type_from_string("CALIBRATION"), dataclasses.I3Trigger.CALIBRATION, "Should be CALIBRATION") self.assertEqual(tk.get_type_from_string("MIN_BIAS"), dataclasses.I3Trigger.MIN_BIAS, "Should be MIN_BIAS") self.assertEqual(tk.get_type_from_string("THROUGHPUT"), dataclasses.I3Trigger.THROUGHPUT, "Should be THROUGHPUT") self.assertEqual(tk.get_type_from_string("TWO_COINCIDENCE"), dataclasses.I3Trigger.TWO_COINCIDENCE, "Should be TWO_COINCIDENCE") self.assertEqual(tk.get_type_from_string("THREE_COINCIDENCE"), dataclasses.I3Trigger.THREE_COINCIDENCE, "Should be THREE_COINCIDENCE") self.assertEqual(tk.get_type_from_string("MERGED"), dataclasses.I3Trigger.MERGED, "Should be MERGED") self.assertEqual(tk.get_type_from_string("SLOW_PARTICLE"), dataclasses.I3Trigger.SLOW_PARTICLE, "Should be SLOW_PARTICLE") self.assertEqual(tk.get_type_from_string("FRAGMENT_MULTIPLICITY"), dataclasses.I3Trigger.FRAGMENT_MULTIPLICITY, "Should be FRAGMENT_MULTIPLICITY") self.assertEqual(tk.get_type_from_string("STRING"), dataclasses.I3Trigger.STRING, "Should be STRING") self.assertEqual(tk.get_type_from_string("VOLUME"), dataclasses.I3Trigger.VOLUME, "Should be VOLUME") self.assertEqual(tk.get_type_from_string("SPHERE"), dataclasses.I3Trigger.SPHERE, "Should be SPHERE") self.assertEqual(tk.get_type_from_string("UNBIASED"), dataclasses.I3Trigger.UNBIASED, "Should be UNBIASED") self.assertEqual(tk.get_type_from_string("SPASE_2"), dataclasses.I3Trigger.SPASE_2, "Should be SPASE_2") self.assertEqual(tk.get_type_from_string("UNKNOWN_TYPE"), dataclasses.I3Trigger.UNKNOWN_TYPE, "Should be UNKNOWN_TYPE")
def generate_trigger_key(key_str): """This function generates a TriggerKey from the string output. This function takes a string of the form "[<source>:<type>:<config_id>]" and is useful for generating a TriggerKey after printing one from a GCD file. Example : In [1]: from icecube import dataclasses In [2]: from icecube import dataio In [3]: from icecube.sim_services.sim_utils.gcd_utils import get_triggerstatus In [4]: f = dataio.I3File(<path_to_gcd_file>) In [5]: ts = get_triggerstatus(f) In [6]: for key in ts.keys() : print key [IN_ICE:SIMPLE_MULTIPLICITY:1006] [IN_ICE:SIMPLE_MULTIPLICITY:1011] [IN_ICE:SLOW_PARTICLE:24002] [IN_ICE:STRING:1007] [IN_ICE:VOLUME:21001] [ICE_TOP:SIMPLE_MULTIPLICITY:102] In [7]: from icecube.trigger_sim.trigger_hierarchy_recipes import generate_trigger_key In [8]: key = generate_trigger_key('[IN_ICE:SIMPLE_MULTIPLICITY:1006]') In [9]: trigger_config = ts[key] In [10]: for setting in trigger_config.trigger_settings : print setting (threshold, 8) (timeWindow, 5000) """ if not key_str.startswith('[') or \ not key_str.endswith(']') or \ key_str.count(':') != 2 : print("ERROR : Malformed string '%s'" % key_str) print("Expecting a string of the form '[<source>:<type>:<config_id>]'") return None s = key_str.strip('[').strip(']').split(':') source = getattr(dataclasses.I3Trigger, s[0]) ttype = getattr(dataclasses.I3Trigger, s[1]) config_id = int(s[2]) return dataclasses.TriggerKey(source, ttype, config_id)
import numpy from I3Tray import I3Units from icecube import icetray, dataclasses from icecube.icetray.I3Test import ENSURE # # This file is not a hard test per-say, but just exercises some of the # python bindings for dataclasses. Might be useful for example usage. # Is there an interface you see missing? Add it, and if it doesn't work # properly, report it via Trac: http://code.icecube.wisc.edu/projects/icecube # # No attempt to use all interfaces for each class has been made print('Testing TriggerKey pybindings') tk = dataclasses.TriggerKey(dataclasses.IN_ICE, dataclasses.SIMPLE_MULTIPLICITY, 1002) ENSURE(tk.check_config_id() == True, "CheckConfigID fail") ENSURE(tk.config_id == 1002, "Wrong ConfigID") ENSURE(tk.source == dataclasses.IN_ICE, "Wrong Trigger Source") ENSURE(tk.type == dataclasses.SIMPLE_MULTIPLICITY, "Wrong Trigger Type") print(tk) tk.reset_config_id() ENSURE(tk.check_config_id() == False, "CheckConfigID fail") mytrig = dataclasses.I3Trigger() mytrig.fired = True mytrig.time = 5.0 * icetray.I3Units.microsecond mytrig.length = 1.0 * icetray.I3Units.microsecond
def DAQ(self, frame): print("DAQ!!!") det_stat = frame.Get("I3DetectorStatus") trigger_status = det_stat.triggerStatus tkey = dataclasses.TriggerKey() tkey.Source = self.sourceID tkey.Type = self.typeID tkey.ConfigID = self.configID if not tkey in trigger_status: print("trigger not found in the detector status") print(" Source ID = ",tkey.Source) print(" Type ID = ",tkey.Type) print(" Config ID = ",tkey.ConfigID) for k,v in trigger_status.items(): print("%d %d %d" % (k.Source,k.Type,k.ConfigID)) sys.exit(1) i3ts = trigger_status[tkey] for p in i3ts.TriggerSettings: print(p) ### # test the trigger name ### if i3ts.TriggerName != self.triggerName : print("FAILED : trigger name %s != %s" % (i3ts.TriggerName,self.triggerName)) sys.exit(1) ### # test the trigger settings ### if len(i3ts.TriggerSettings ) != len(self.valueNameList) : print("FAILED : len settings %d %d " % \ (len(i3ts.TriggerSettings ),len(self.valueNameList))) sys.exit(1) ### # test that the names and values are set correctly ### for name, value in zip(self.valueNameList, self.valueList): found = False valid = False for test_name, test_value in i3ts.TriggerSettings : if name == test_name : found = True if test_value != value : print("FAILED : value mismatch") sys.exit(1) if not found : print("FAILED : value not found") sys.exit(1) ### # test the readout windows ### readouts = i3ts.ReadoutSettings print("len(readouts) = ",len(readouts)) print("len(self.readoutWindowConfigs) = ",len(self.readoutWindowConfigs)) if len(readouts) != len(self.readoutWindowConfigs) : print("FAILED : ReadoutWindowConfigs len settings %d %d " % \ (len(readouts),len(self.readoutWindowConfigs))) sys.exit(1) for e in readouts: k = e.key() v = e.data() if not k in self.readoutWindowConfigs : print("FAILED : key %d not found readout window config") sys.exit(1) test_ro_config = self.readoutWindowConfigs[k] if v.readoutTimeMinus != test_ro_config.readoutTimeMinus and \ v.readoutTimePlus != test_ro_config.readoutTimePlus and \ v.readoutTimeOffset != test_ro_config.readoutTimeOffset : print("FAILED : readout window values not set properly") print(v.readoutTimeMinus, v.readoutTimePlus, v.readoutTimeOffset) print(test_ro_config.readoutTimeMinus, test_ro_config.readoutTimePlus, test_ro_config.readoutTimeOffset) sys.exit(1)
### loop over the frames until you find the one with the geometry in it while oldgcd.more(): frame = oldgcd.pop_frame() if frame.Has("I3DetectorStatus"): ### get the geometry from the frame i3ds = frame.Get("I3DetectorStatus") ## clear the the old triggers i3ds.trigger_status.clear() ## Setup the SMT 8 trigger smt_ts = dataclasses.I3TriggerStatus() smt_tk = dataclasses.TriggerKey( dataclasses.I3Trigger.IN_ICE, dataclasses.I3Trigger.SIMPLE_MULTIPLICITY, 1006) smt_ts.trigger_name = 'SimpleMajorityTrigger' try: trigSet = smt_ts.trigger_settings except TypeError: print('Boost has borked itself') sys.exit(0) trigSet['threshold'] = "8" trigSet['timeWindow'] = "5000" inice_trc = dataclasses.I3TriggerStatus.I3TriggerReadoutConfig() inice_trc.readout_time_minus = 4000