Ejemplo n.º 1
0
    def Process(self):

        if self.counter % 20 == 0:
            sframe = icetray.I3Frame('S')
            info = simclasses.I3CorsikaInfo()
            sframe['I3CorsikaInfo'] = info
            self.PushFrame(sframe)

        qframe = icetray.I3Frame('Q')
        eh = dataclasses.I3EventHeader()
        eh.run_id = 1
        eh.event_id = self.counter
        qframe['I3EventHeader'] = eh

        tree = dataclasses.I3MCTree()
        p1 = dataclasses.I3Particle()
        tree.insert(p1)

        if self.counter % 2 == 0:
            qframe['I3MCTree'] = tree
            qframe['I3MCPrimary'] = p1

        self.PushFrame(qframe)
        self.counter += 1

        if self.counter >= 100:
            self.RequestSuspension()
Ejemplo n.º 2
0
    def Process(self):
        if not self.geometry:
            self.geometry = True
            geometry = dc.I3Geometry()
            for string in self.strings:
                for dom in self.doms:
                    omkey= icetray.OMKey(string,dom)
                    geometry.omgeo[omkey] = dc.I3OMGeo()
                    x=random.uniform(-500,500)
                    y=random.uniform(-500,500)
                    z=random.uniform(-300,300)
                    geometry.omgeo[omkey].position = dc.I3Position(x,y,z)

            frame = icetray.I3Frame(icetray.I3Frame.Geometry);
            frame.Put('I3Geometry',geometry)
            self.PushFrame(frame)

        pulsesmap= dc.I3RecoPulseSeriesMap()
        for string in self.strings:
            for dom in self.doms:
                omkey= icetray.OMKey(string,dom)
                pulse= dc.I3RecoPulse()
                pulse.charge= random.uniform(0.3,6.)#pulses are not used in the algorithm of this module, 
                                                    #just put a single pulse with any value of the charge
                pulsesmap[omkey]= dc.I3RecoPulseSeries([pulse])
    
        frame = icetray.I3Frame(icetray.I3Frame.Physics);
        frame.Put("TestPulseSeriesMap",pulsesmap)
        self.PushFrame(frame)
Ejemplo n.º 3
0
    def DAQ(self, frame):
        # only inject it once
        if self.has_been_injected:
            self.PushFrame(frame)
            return
        self.has_been_injected = True

        geometry = dataclasses.I3Geometry()
        calibration = dataclasses.I3Calibration()
        detectorStatus = dataclasses.I3DetectorStatus()

        # fill the geometry map
        omgeomap = geometry.omgeo
        domcalmap = calibration.dom_cal
        domstatusmap = detectorStatus.dom_status

        for i, pos in enumerate(omPositions):
            shiftedPos = pos
            shiftedPos[0] += self.xCoord * I3Units.m
            shiftedPos[1] += self.yCoord * I3Units.m
            shiftedPos[2] += self.zCoord * I3Units.m

            omkey = omKeys[i]

            newomgeo = dataclasses.I3OMGeo()
            newomgeo.omtype = dataclasses.I3OMGeo.OMType.IceCube
            newomgeo.orientation = dataclasses.I3Orientation(
                dataclasses.I3Direction(0., 0., -1.))
            newomgeo.position = dataclasses.I3Position(shiftedPos[0],
                                                       shiftedPos[1],
                                                       shiftedPos[2])
            omgeomap[omkey] = newomgeo

            newdomcal = dataclasses.I3DOMCalibration()
            newdomcal.relative_dom_eff = 1.0
            domcalmap[omkey] = newdomcal

            newdomstatus = dataclasses.I3DOMStatus()
            newdomstatus.pmt_hv = 1345. * I3Units.V  # some arbitrary setting: >0 and not NaN
            domstatusmap[omkey] = newdomstatus

        # make GCD frames and fill them with objects
        Gframe = icetray.I3Frame(icetray.I3Frame.Geometry)
        Cframe = icetray.I3Frame(icetray.I3Frame.Calibration)
        Dframe = icetray.I3Frame(icetray.I3Frame.DetectorStatus)

        Gframe["I3Geometry"] = geometry
        Cframe["I3Calibration"] = calibration
        Dframe["I3DetectorStatus"] = detectorStatus

        # push the new GCD frames
        self.PushFrame(Gframe)
        self.PushFrame(Cframe)
        self.PushFrame(Dframe)

        # push the original Q-frame
        self.PushFrame(frame)
Ejemplo n.º 4
0
    def select_frame(self, frame):
        '''
        Attempt to access the frame'th I3Frame in the file.  If 'frame' is
        negative, access in reverse order. If 'frame' is invalid, do nothing.
        '''
        if frame is None or frame < 0 or frame == self.active_view:
            return
        if frame == 'end':
            frame = -1

        # rather than checking against the maximum length of the list,
        # which is slow for sequential files, just try to access the frame
        try:
            self.framelist[frame]
        except IndexError:
            return

        if frame < 0:
            # reverse direction
            frame = len(self.framelist) + frame

        # iterate through the framelist to determine the frame hierarchy
        if frame < self.active_view:
            self.active_view = 0
            self.frame_hierarchy.reset()
            if isinstance(self.framelist[self.active_view],
                          fileadaptor.FrameWrapper):
                frame_obj = self.framelist[self.active_view].frame
            else:
                frame_obj = self.framelist[self.active_view]
            f = icetray.I3Frame(frame_obj)
            f.purge()
            self.frame_hierarchy.mix(f)
        while (self.active_view < frame):
            self.active_view += 1
            if isinstance(self.framelist[self.active_view],
                          fileadaptor.FrameWrapper):
                frame_obj = self.framelist[self.active_view].frame
            else:
                frame_obj = self.framelist[self.active_view]
            f = icetray.I3Frame(frame_obj)
            f.purge()
            self.frame_hierarchy.mix(f)

        old_widget = self.body
        self.maxkeylen = len(self.framelist[self.active_view])
        if self.key >= self.maxkeylen:
            self.key = self.maxkeylen - 1
        self.frame_viewer.set_view(self.framelist[self.active_view],
                                   self.active_view,
                                   key=self.key)
        self.footer.set_view(self.active_view, key=self.key)
        del old_widget
        self.drop_focus()
Ejemplo n.º 5
0
 def FramePacket(self,frames):
   originalFrame = icetray.I3Frame() #keep this pointer alive
   targetFrame = icetray.I3Frame()
   for oframe in frames:
     if oframe.Has("I3EventHeader") and oframe["I3EventHeader"].sub_event_stream==self.originalStream:
       originalFrame=oframe
       for tframe in frames:
         if tframe.Has("I3EventHeader") and tframe["I3EventHeader"].sub_event_stream==self.targetStream and tframe["I3EventHeader"].sub_event_id==oframe["I3EventHeader"].sub_event_id:
           targetFrame=tframe
           for key in self.moveObjects:
             targetFrame[key]=originalFrame[key]
           targetFrame.Put(self.flagName, icetray.I3Bool(True))
   for frame in frames:
     self.PushFrame(frame)
Ejemplo n.º 6
0
    def Process(self):
        try:
            c = next(self.lines)
        except StopIteration:
            self.RequestSuspension()
            return

        eq = astro.I3Equatorial(c[0] * I3Units.degree, c[1] * I3Units.degree)
        time = dataclasses.I3Time(2015, 0)
        direction = astro.I3GetDirectionFromEquatorial(eq, time)

        eqq = astro.I3GetEquatorialFromDirection(direction, time)

        particle = dataclasses.I3Particle()
        particle.dir = direction

        header = dataclasses.I3EventHeader()
        header.start_time = time

        frame = icetray.I3Frame("P")
        if self.evthdr:
            frame["I3EventHeader"] = header
        frame["Particle"] = particle

        self.PushFrame(frame)
Ejemplo n.º 7
0
    def Process(self):

        # get next frame
        frame = self.PopFrame()

        if not self._frame_has_been_pushed:

            # create settings frame and push it
            settings_frame = icetray.I3Frame('m')

            # add meta data on ranges
            settings_data = {}
            for key, value_range in self.proposal_storm.uniform_ranges.items():
                settings_data[key+'RangeMin'] = value_range[0]
                settings_data[key+'RangeMax'] = value_range[1]

            # write to frame
            settings_frame[self._output_key+'UniformRanges'] = (
                dataclasses.I3MapStringDouble(settings_data)
            )
            settings_frame[self._output_key] = dataclasses.I3MapStringDouble(
                self.proposal_storm.sampled_settings)

            self.PushFrame(settings_frame)

            self._frame_has_been_pushed = True

        self.PushFrame(frame)
Ejemplo n.º 8
0
 def __init__(self, framelist, header, footer, ascii_only=False):
     self.framelist = framelist
     self.active_view = 0
     self.frame_hierarchy = icetray.I3FrameMixer(True)
     try:
         if isinstance(self.framelist[self.active_view],
                       fileadaptor.FrameWrapper):
             frame_obj = self.framelist[self.active_view].frame
         else:
             frame_obj = self.framelist[self.active_view]
         f = icetray.I3Frame(frame_obj)
         f.purge()
         self.frame_hierarchy.mix(f)
     except Exception:
         raise Exception('No frames in file!')
     self.key = 0
     self.maxkeylen = len(self.framelist[self.active_view])
     urwid.connect_signal(footer, 'select_frame', self.select_frame)
     urwid.connect_signal(footer, 'drop_focus', self.drop_focus)
     self.frame_viewer = FrameViewer(framelist[0], 0, ascii_only=ascii_only)
     urwid.Frame.__init__(self,
                          self.frame_viewer,
                          header=header,
                          footer=footer)
     urwid.connect_signal(self.frame_viewer, 'select_key', self.select_key)
     urwid.connect_signal(self.frame_viewer, 'update_status',
                          footer.update_status)
     urwid.connect_signal(self.frame_viewer, 'goto_matching_frame',
                          self.goto_matching_frame)
     self.popup = None
     self._ipy_namespace = dict()
Ejemplo n.º 9
0
    def DAQ(self, frame):
        """Inject casacdes into I3MCtree.

        Parameters
        ----------
        frame : icetray.I3Frame.DAQ
            An I3 q-frame.

        """

        trees = [frame[t] for t in self.mctree_keys]

        # oversampling
        for i in range(self.oversampling_factor):
            if i > 0:
                # create a new frame
                frame = icetray.I3Frame(frame)
                del frame['oversampling']

                for key, tree in zip(self.mctree_keys, trees):
                    del frame[key]
                    frame[key] = dataclasses.I3MCTree(tree)

            if self.oversampling_factor > 1:
                frame['oversampling'] = dataclasses.I3MapStringInt({
                    'event_num_in_run':
                    self.events_done,
                    'oversampling_num':
                    i,
                })
            self.PushFrame(frame)

        self.events_done += 1
Ejemplo n.º 10
0
def do_one(Type, name, gen, checksum):
    print("Writing %s" % Type)
    global is_fail
    name += '.i3'
    i3f = dataio.I3File(name, dataio.I3File.Mode.Writing)

    tinst = Type()
    i = 0
    for value in gen:
        tinst.append(value)
        i += 1
    print("%d entries" % i)
    frame = icetray.I3Frame()
    frame[name] = tinst

    i3f.push(frame)
    i3f.close()

    f = open(name, 'rb')
    data = f.read()
    hsh = hashlib.md5()
    hsh.update(data)
    hd = hsh.hexdigest()
    if (hd != checksum):
        print("****************** ERRORZ ERRORZ ***********************")
        print("%s != %s (file %s, %u bytes)" % (hd, checksum, name, len(data)))
        is_fail = True
    def setUp(self):
        self.frame = icetray.I3Frame(icetray.I3Frame.Physics)
        pulses = dataclasses.I3RecoPulseSeriesMap()
        key1 = icetray.OMKey(42, 7)
        vec = dataclasses.I3RecoPulseSeries()
        pulse = dataclasses.I3RecoPulse()
        pulse.time = 1.0
        pulse.charge = 2.3
        vec.append(pulse)
        pulse.time = 2.0
        vec.append(pulse)
        pulse.time = 15.0
        vec.append(pulse)
        pulses[key1] = vec

        key2 = icetray.OMKey(7, 7)
        vec = dataclasses.I3RecoPulseSeries()
        pulse.time = 1.0
        pulse.charge = 2.3
        vec.append(pulse)
        pulse.time = 2.0
        vec.append(pulse)
        pulse.time = 15.0
        vec.append(pulse)
        pulses[key2] = vec

        self.frame['Pulses'] = pulses

        mask1 = dataclasses.I3RecoPulseSeriesMapMask(self.frame, 'Pulses')
        mask1.set(key1, 1, False)
        self.frame['Mask1'] = mask1

        mask2 = dataclasses.I3RecoPulseSeriesMapMask(self.frame, 'Pulses')
        mask2.set(key2, 1, False)
        self.frame['Mask2'] = mask2
Ejemplo n.º 12
0
def export_frame(frame, frame_list, mctree_name, keys_to_export, rename_dict):
    """Export frames and append them to the provided frame list.

    Parameters
    ----------
    frame : I3Frame
        The current I3Frame.
    frame_list : list
        The list to which to append the exported frames.
    mctree_name : str
        The name of the I3MCTree key.
    keys_to_export : list of str
        The keys to extract save to the exported frame
    rename_dict : dict
        A dictionary that defines the renaming of the keys.
        Signature: rename_dict[old_name] = new_name
    """

    # create a new DAQ frame
    fr = icetray.I3Frame(icetray.I3Frame.DAQ)

    # extract I3MCTree
    fr[mctree_name] = dataclasses.I3MCTree(frame[mctree_name])

    # extract specified keys
    for key in keys_to_export:

        if key in frame:
            new_name = rename_dict.get(key, key)
            fr[new_name] = frame[key]

    # append frame to list
    frame_list.append(fr)
Ejemplo n.º 13
0
 def DAQ(self, daq):
     from icecube import dataclasses
     physics = icetray.I3Frame(icetray.I3Frame.Physics)
     header = dataclasses.I3EventHeader(daq['I3EventHeader'])
     header.sub_event_stream = 'IceTop'
     physics.Put('I3EventHeader', header)
     self.PushFrame(daq)
     self.PushFrame(physics)
Ejemplo n.º 14
0
def write(fname='muongun_serialization_test.i3'):

    frame = icetray.I3Frame()
    frame['Generator'] = generator

    f = dataio.I3File(fname, 'w')
    f.push(frame)
    f.close()
Ejemplo n.º 15
0
    def test_fill(self):
        hm = DerivedHistogramModule()

        for i in range(10):
            hm.DAQ(icetray.I3Frame())

        h = hm.histograms["DilbertRNG"]
        self.assertEqual(h.bin_values[9], 10)
        self.assertEqual(len(h.bin_values), 10)
Ejemplo n.º 16
0
 def Process(self):
     frame = icetray.I3Frame(icetray.I3Frame.DAQ)        
     mcpes = simclasses.I3MCPESeries()
     for i in range(1000) :            
         mcpes.append(simclasses.I3MCPE(1))
     mcpemap = simclasses.I3MCPESeriesMap()
     mcpemap[icetray.OMKey(21,30)] = mcpes
     frame["I3MCPESeriesMap"] = mcpemap
     self.PushFrame(frame)
Ejemplo n.º 17
0
def generateCFrame(geometry):
    # intialize frame as a C frame
    frame = icetray.I3Frame(icetray.I3Frame.Calibration)

    # add key-value pairs
    frame["I3Geometry"] = geometry
    frame["I3Calibration"] = makeCalibrationObject(geometry)
    frame["SPEAbove"] = cdframe["SPEAbove"]
    frame["SPEScalingFactors"] = cdframe["SPEScalingFactors"]

    return frame
Ejemplo n.º 18
0
			def Physics(self, frame):
				frame.purge() # deletes all non-native items
				
				for name in frame.keys():
					frame.change_stream(name, self.new_stream)
				
				new_frame = icetray.I3Frame(self.new_stream)
				new_frame.merge(frame)
				del frame
				
				self.PushFrame(new_frame)
Ejemplo n.º 19
0
def rewrite_frame_stop(input_frame, new_stream):
    input_frame.purge()  # deletes all non-native items

    for key in input_frame.keys():
        input_frame.change_stream(key, new_stream)

    new_frame = icetray.I3Frame(new_stream)
    new_frame.merge(input_frame)
    del input_frame

    return new_frame
Ejemplo n.º 20
0
    def CreatePFrame(self, nside, pixel):
        dec, ra = healpy.pix2ang(nside, pixel)
        dec = dec - numpy.pi / 2.
        zenith, azimuth = astro.equa_to_dir(ra, dec, self.event_mjd)
        zenith = float(zenith)
        azimuth = float(azimuth)
        direction = dataclasses.I3Direction(zenith, azimuth)

        position = self.seed_position
        time = self.seed_time
        energy = self.seed_energy

        variationDistance = 20. * I3Units.m
        posVariations = [
            dataclasses.I3Position(0., 0., 0.),
            dataclasses.I3Position(-variationDistance, 0., 0.),
            dataclasses.I3Position(variationDistance, 0., 0.),
            dataclasses.I3Position(0., -variationDistance, 0.),
            dataclasses.I3Position(0., variationDistance, 0.),
            dataclasses.I3Position(0., 0., -variationDistance),
            dataclasses.I3Position(0., 0., variationDistance)
        ]

        for i in range(0, len(posVariations)):
            posVariation = posVariations[i]
            p_frame = icetray.I3Frame(icetray.I3Frame.Physics)
            thisPosition = dataclasses.I3Position(position.x + posVariation.x,
                                                  position.y + posVariation.y,
                                                  position.z + posVariation.z)

            # generate the particle from scratch
            particle = dataclasses.I3Particle()
            particle.shape = dataclasses.I3Particle.ParticleShape.InfiniteTrack
            particle.fit_status = dataclasses.I3Particle.FitStatus.OK
            particle.pos = thisPosition
            particle.dir = direction
            particle.time = time
            particle.energy = energy
            p_frame[self.output_particle_name] = particle

            # generate a new event header
            eventHeader = dataclasses.I3EventHeader(self.event_header)
            eventHeader.sub_event_stream = "SCAN_nside%04u_pixel%04u_posvar%04u" % (
                nside, pixel, i)
            eventHeader.sub_event_id = pixel
            p_frame["I3EventHeader"] = eventHeader
            p_frame["SCAN_HealpixPixel"] = icetray.I3Int(int(pixel))
            p_frame["SCAN_HealpixNSide"] = icetray.I3Int(int(nside))
            p_frame["SCAN_PositionVariationIndex"] = icetray.I3Int(int(i))

            for frame in self.GCDQpFrames[0:-1]:
                self.PushFrame(frame)
            self.PushFrame(p_frame)
Ejemplo n.º 21
0
			def RFrame(self, frame):
				position = frame[self.input_pos_name]
				time = frame[self.input_time_name].value
				energy = float('NaN')

				self.PushFrame(frame)

				for pixel in self.pixels:
					p_frame = icetray.I3Frame(icetray.I3Frame.Physics)
				
					zenith, azimuth = healpy.pix2ang(self.nside, pixel)
					direction = dataclasses.I3Direction(zenith,azimuth)

					#print "reconstructing with fixed direction", direction, "(npixels=", self.npix, ", pixel=", pixel, ")"
				
				
					variationDistance = 20.*I3Units.m
					posVariations = [dataclasses.I3Position(0.,0.,0.),
									dataclasses.I3Position(-variationDistance,0.,0.),
									dataclasses.I3Position( variationDistance,0.,0.),
									dataclasses.I3Position(0.,-variationDistance,0.),
									dataclasses.I3Position(0., variationDistance,0.),
									dataclasses.I3Position(0.,0.,-variationDistance),
									dataclasses.I3Position(0.,0., variationDistance)]
				
					for i in range(len(posVariations)):
						thisPosition = dataclasses.I3Position(position.x + posVariations[i].x,position.y + posVariations[i].y,position.z + posVariations[i].z)
					
						# generate the particle from scratch
						particle = dataclasses.I3Particle()
						particle.shape = dataclasses.I3Particle.ParticleShape.Cascade
						particle.fit_status = dataclasses.I3Particle.FitStatus.OK
						particle.pos = thisPosition
						particle.dir = direction
						particle.time = time
						particle.energy = energy
					
						thisParticleName = self.output_particle_name
						if i>0: thisParticleName = thisParticleName+"_%i"%i
					
						p_frame[thisParticleName] = particle
					
					p_frame["HealpixPixel"] = icetray.I3Int(int(pixel))
					p_frame["HealpixNSide"] = icetray.I3Int(int(self.nside))
				
					# generate a new event header
					eventHeader = dataclasses.I3EventHeader(frame["I3EventHeader"])
					eventHeader.sub_event_stream = "millipede_scan_nside%04u" % self.nside
					eventHeader.sub_event_id = pixel
					p_frame["I3EventHeader"] = eventHeader
				
					self.PushFrame(p_frame)
Ejemplo n.º 22
0
def setUpModule():
    """
     Generate .i3 file (borrowed from dataio test_randomaccess_file)
    """
    i3f = dataio.I3File(test_filename, dataio.I3File.Mode.Writing)
    frames = test_frames

    for pr in frames:
        frame = icetray.I3Frame(icetray.I3Frame.Stream(pr[0]))
        frame[pr[0]] = icetray.I3Int(pr[1])
        i3f.push(frame)

    i3f.close()
Ejemplo n.º 23
0
 def Process(self):
   """ deliver frames QP with only a bit of rudamentary information """
   #make a Q-frame
   Qframe = icetray.I3Frame(icetray.I3Frame.DAQ)
   Qeh = dataclasses.I3EventHeader()
   Qeh.start_time = (dataclasses.I3Time(2011, 0))
   Qeh.end_time = (dataclasses.I3Time(2011, 2))
   Qeh.run_id = 1
   Qeh.event_id = 1
   Qframe.Put("I3EventHeader", Qeh)
   Qrecomap = dataclasses.I3RecoPulseSeriesMap()
   recopulse1 = dataclasses.I3RecoPulse()
   recopulse1.time = 0
   recopulse1.charge = 1
   recopulse2 = dataclasses.I3RecoPulse()
   recopulse2.time = 1
   recopulse2.charge = 2
   Qrecomap[icetray.OMKey(1,1)] = [recopulse1]
   Qrecomap[icetray.OMKey(2,2)] = [recopulse2]
   Qframe.Put(OrgPulses, Qrecomap)
   Qframe.Put(SplitName+"SplitCount", icetray.I3Int(1))
   self.PushFrame(Qframe)
   #now make the first p-frame containing one I3RecoPulse
   P1frame = icetray.I3Frame(icetray.I3Frame.Physics)
   P1eh = dataclasses.I3EventHeader()
   P1eh.start_time = (dataclasses.I3Time(2011, 0))
   P1eh.end_time = (dataclasses.I3Time(2011, 1))
   P1eh.run_id = 1
   P1eh.event_id = 1
   P1eh.sub_event_stream = "split"
   P1eh.sub_event_id = 0
   P1frame.Put("I3EventHeader", P1eh)
   P1recomap = dataclasses.I3RecoPulseSeriesMap()
   P1recomap[icetray.OMKey(1,1)] = [recopulse1]
   P1recomask = dataclasses.I3RecoPulseSeriesMapMask(Qframe, OrgPulses, Qrecomap)
   P1frame.Put(SplitPulses, P1recomask)
   self.PushFrame(P1frame)
   
   self.RequestSuspension()
Ejemplo n.º 24
0
    def test_default(self):
        h = PhysicsHistogram(0,
                             10,
                             10,
                             "DerivedHistogram",
                             expression="frame['integer'].value")

        for i in range(10):
            frame = icetray.I3Frame()
            frame["integer"] = icetray.I3Int(i)
            h.Physics(frame)

        for bin_value in h.bin_values:
            self.assertEqual(bin_value, 1)
Ejemplo n.º 25
0
def generateDFrame(geometry):
    # intialize frame as a D frame
    frame = icetray.I3Frame(icetray.I3Frame.DetectorStatus)

    # add key-value pairs
    frame["I3Geometry"] = geometry
    frame["I3Calibration"] = makeCalibrationObject(geometry)
    frame["SPEAbove"] = cdframe["SPEAbove"]
    frame["SPEScalingFactors"] = cdframe["SPEScalingFactors"]
    frame["I3DetectorStatus"] = makeDSObject(geometry)
    frame["BadDomsList"] = cdframe["BadDomsList"]
    frame["BadDomsListSLC"] = cdframe["BadDomsListSLC"]

    return frame
    def Process(self):
        frame = icetray.I3Frame(icetray.I3Frame.DAQ)
        mctree = dataclasses.I3MCTree()

        cascade = dataclasses.I3Particle(dataclasses.I3Particle.Primary,
                                         dataclasses.I3Particle.EPlus)
        muon = dataclasses.I3Particle(dataclasses.I3Particle.Primary,
                                      dataclasses.I3Particle.MuPlus)

        mctree.add_primary(cascade)
        mctree.add_primary(muon)

        frame["I3MCTree"] = mctree
        self.PushFrame(frame)
Ejemplo n.º 27
0
    def Process(self):
        try:
            t = self.times.next()
        except StopIteration:
            self.RequestSuspension()
            return

        header = dataclasses.I3EventHeader()
        header.start_time = dataclasses.make_I3Time(t)

        frame = icetray.I3Frame("P")
        frame["I3EventHeader"] = header

        self.PushFrame(frame)
Ejemplo n.º 28
0
    def test_fill(self):
        h = DerivedHistogram(0, 10, 10, "DerivedHistogram")

        for i in range(10):
            frame = icetray.I3Frame()
            frame["integer"] = icetray.I3Int(i)
            h.DAQ(frame)

        frame = icetray.I3Frame()
        frame["integer"] = icetray.I3Int(-1)
        h.DAQ(frame)

        frame = icetray.I3Frame()
        frame["integer"] = icetray.I3Int(10)
        h.DAQ(frame)

        self.assertEqual(len(h.bin_values), 10)
        self.assertEqual(h.name, "DerivedHistogram")

        for bin_value in h.bin_values:
            self.assertEqual(bin_value, 1)

        self.assertEqual(h.overflow, 1)
        self.assertEqual(h.underflow, 1)
Ejemplo n.º 29
0
    def retrieve_metadata_frame_from_pulsar(self, topic):
        metadata_reader = None

        retries = 10
        while True:
            msg = None
            try:
                icetray.logging.log_debug("Need to (re-)subscribe to metadata stream: {}".format(topic), unit=__name__)
                
                # (re-)subscribe through Pulsar
                if metadata_reader is None:
                    metadata_reader = self.receiver_service.client().create_reader(
                      topic=topic,
                      start_message_id=pulsar.MessageId.earliest,
                      receiver_queue_size=1)

                if not metadata_reader.has_message_available():
                    raise RuntimeError("No metadata message available")
                    
                icetray.logging.log_debug("Reading metadata frame from topic {}..".format(topic), unit=__name__)
                msg = metadata_reader.read_next()
                icetray.logging.log_debug("Metadata frame read from topic {}.".format(topic), unit=__name__)
            except:
                if retries > 0:
                    icetray.logging.log_warn("Metadata read failed! Retrying. {}".format(topic), unit=__name__)
                    retries -= 1
                    time.sleep(0.5)
                else:
                    icetray.logging.log_warn("Metadata read failed! Throwing exception. {}".format(topic), unit=__name__)
                    raise

            if msg is not None:
                break
            
        frame = icetray.I3Frame()
        frame.loads(msg.data())
        icetray.logging.log_debug("Loaded {} frame from pulsar".format(frame.Stop), unit=__name__)
        
        # add a I3String items to the frame to mark where we got it from
        frame['__msgtopic'] = dataclasses.I3String( topic )

        if metadata_reader is not None:
            metadata_reader.close()
            del metadata_reader
        
        return frame
Ejemplo n.º 30
0
    def testRoundTrip(self):
        """
		I3Matrix serializes and deserializes properly.
		"""
        fname = 'i3matrix_test.i3'
        orig = numpy.pi * numpy.ones((3, 3))
        frame = icetray.I3Frame()
        frame['foo'] = I3Matrix(orig)
        f = dataio.I3File(fname, 'w')
        f.push(frame)
        f.close()

        frame = dataio.I3File(fname).pop_frame()
        view = numpy.asarray(frame['foo'])
        self.assertEquals(view.shape, orig.shape)
        self.assert_((view == orig).all())

        os.unlink(fname)