Esempio n. 1
0
 def run(self):
     self.dev.tree.normal()
     self.dev.DATA.beginSegment(0, 9, Int32Array(range(10)),
                                Int32Array([0] * 10))
     for i in range(10):
         time.sleep(.1)
         self.dev.DATA.putSegment(Int32Array([i]), i)
Esempio n. 2
0
 def segments(self):
     pytree = Tree('pytree', self.shot)
     signal = pytree.SIG01
     signal.record = None
     signal.compress_on_put = False
     for i in range(2000):
         signal.putRow(100, Range(1, 1000).data(), DateToQuad("now"))
     pytree.createPulse(self.shot + 2)
     signal.compress_segments = True
     pytree3 = Tree('pytree', self.shot + 2)
     pytree3.compressDatafile()
     self.assertEqual((signal.record == pytree3.SIG01.record).all(), True)
     signal.deleteData()
     # beginning a block set next_row to 0
     signal.beginTimestampedSegment(Int32Array([0, 7]))
     self.assertEqual(str(signal.record), "Build_Signal([], *, [])")
     self.assertEqual(str(signal.getSegment(0)), "Build_Signal([], *, [])")
     # beginning adding row increments next_row to 1
     signal.putRow(1, Int32Array([1]), -1)
     self.assertEqual(str(signal.record), "Build_Signal([1], *, [-1Q])")
     self.assertEqual(str(signal.getSegment(0)),
                      "Build_Signal([1], *, [-1Q])")
     # beginning a new block set next_row back to 0 of the new block
     # the previous block is assumed to be full as the tailing zero could be valid data
     signal.beginTimestampedSegment(Int32Array([0]))
     self.assertEqual(str(signal.record),
                      "Build_Signal([1,7], *, [-1Q,0Q])")
     self.assertEqual(str(signal.getSegment(0)),
                      "Build_Signal([1,7], *, [-1Q,0Q])")
Esempio n. 3
0
 def run(self):
     """Process data - streeam to DATA node."""
     self.dev.tree.normal()
     self.dev.channel.beginSegment(0, 9, Int32Array(range(10)),
                                   Int32Array([0] * 10))
     for i in range(10):
         time.sleep(.1)
         self.dev.channel.putSegment(Int32Array([i]), i)
Esempio n. 4
0
 def CompressSegments(self):
     from MDSplus import Tree,DateToQuad,ZERO,Int32,Int32Array,Int64Array,Range
     with Tree(self.tree,self.shot+9,'NEW') as ptree:
         node = ptree.addNode('S')
         node.compress_on_put = False
         ptree.write()
     ptree.cleanDatafile()
     ptree.normal()
     te = DateToQuad("now")
     sampperseg = 50
     data = ZERO(Int32Array([sampperseg]),Int32(0))
     numsegs = 128
     for i in range(numsegs):
         t0=te+1;te=t0+sampperseg-1
         node.makeSegment(t0,te,Int64Array(range(t0,te+1)),data+Int32(i))
     node.compress_segments=True
     ptree.createPulse(self.shot+11)
     Tree.compressDatafile(self.tree,self.shot+11)
     ptree1 = Tree(self.tree,self.shot+11)
     node1  = ptree1.S
     self.assertEqual(True,(node.record==node1.record).all())
     self.assertEqual(True,ptree.getDatafileSize()>ptree1.getDatafileSize())
     for i in range(numsegs):
         srt,end = node.getSegmentLimits(i)
         dim = Range(srt,end)
         node.updateSegment(srt,end,dim,i)
         if i%16==0:
             self.assertEqual(dim.decompile(),node.getSegmentDim(i).decompile())
     ptree.compressDatafile()
     ptree.readonly()
     self.assertEqual(numsegs,node1.getNumSegments())
     self.assertEqual(True,ptree.getDatafileSize()<ptree1.getDatafileSize())
     for i in range(numsegs):
         self.assertEqual(node.getSegmentDim(i).data().tolist(),node1.getSegmentDim(i).data().tolist())
Esempio n. 5
0
 def DimensionlessSegments(self):
     from MDSplus import Tree,Int32Array,numpy,TreeBUFFEROVF
     with Tree(self.tree,self.shot+8,'NEW') as ptree:
         ptree.addNode('S')
         ptree.write()
     ptree.normal()
     node = ptree.S
     len = 10
     seg0 = Int32Array(numpy.array(range(len)))
     for i in range(10):
         seg = seg0 + i*len
         start, end = seg[0],seg[len-1]
         node.makeSegment(start, end, None, seg)
     seg = seg0 + 10*len
     start, end = seg[0],seg[len-1]
     node.beginSegment(start, end, None, seg)
     node.putSegment(seg[0:1])
     self.assertEqual(node.record.data()[-5:].tolist(),[96,97,98,99,100])
     node.putSegment(seg[1:2])
     self.assertEqual(node.record.data()[-5:].tolist(),[97,98,99,100,101])
     self.assertEqual(node.getSegment(0).data().tolist(),seg0.tolist())
     self.assertEqual(node.record.data()[:10].tolist(),seg0.tolist())
     ptree.compressDatafile()
     ptree.normal()
     self.assertEqual(node.record.data()[-5:].tolist(),[97,98,99,100,101])
     try:   node.putSegment(seg[2:3]) # compress finalizes last segment, putSegment cannot put
     except TreeBUFFEROVF: pass
     else:  self.assertEqual(None,TreeBUFFEROVF)
     ptree.setTimeContext(17,21,None) # interval contained in segment 1 and 2
     self.assertEqual(node.record.data().tolist(),[17,18,19,20,21])
Esempio n. 6
0
 def BlockAndRows(self):
     from MDSplus import Tree,Int32Array
     with Tree(self.tree,self.shot+1,'NEW') as ptree:
         ptree.addNode('S')
         ptree.write()
     ptree.normal()
     node = ptree.S
     # beginning a block set next_row to 0
     node.beginTimestampedSegment(Int32Array([0,7]))
     self.assertEqual(str(node.record),       "Build_Signal([], *, [])")
     self.assertEqual(str(node.getSegment(0)),"Build_Signal([], *, [])")
     # beginning adding row increments next_row to 1
     node.putRow(1,Int32Array([1]),-1)
     self.assertEqual(str(node.record),       "Build_Signal([1], *, [-1Q])")
     self.assertEqual(str(node.getSegment(0)),"Build_Signal([1], *, [-1Q])")
     # beginning a new block set next_row back to 0 of the new block
     # the previous block is assumed to be full as the tailing zero could be valid data
     node.beginTimestampedSegment(Int32Array([0]))
     self.assertEqual(str(node.record),       "Build_Signal([1,7], *, [-1Q,0Q])")
     self.assertEqual(str(node.getSegment(0)),"Build_Signal([1,7], *, [-1Q,0Q])")
Esempio n. 7
0
        def test():
            from MDSplus import Tree, Int64, Int64Array, Int32Array, tdi, tcl
            #Tree.setTimeContext() # test initPinoDb
            #self.assertEquals(Tree.getTimeContext(),(None,None,None))
            with Tree(self.tree, self.shot, 'NEW') as ptree:
                node = ptree.addNode('S')
                ptree.write()
            node.tree = Tree(self.tree, self.shot)
            for i in range(-9, 9, 3):
                d = Int64Array(range(3)) * 10 + i * 10
                v = Int32Array(range(3)) + i
                node.beginSegment(d[0], d[2], d, v)
            self.assertEqual(
                node.getSegmentList(20, 59).dim_of(0).tolist(), [0, 30])
            self.assertEqual(
                node.getSegmentList(20, 60).dim_of(0).tolist(), [0, 30, 60])
            self.assertEqual(
                node.getSegmentList(21, 60).dim_of(0).tolist(), [30, 60])
            self.assertEqual(node.record.data().tolist(), list(range(-9, 9)))
            node.tree.setTimeContext(Int64(30), Int64(70), Int64(20))
            #        Tree.setTimeContext(1,2,3) # test privacy to Tree
            self.assertEquals(node.tree.getTimeContext(), (30, 70, 20))
            #       self.assertEquals(Tree.getTimeContext(),(1,2,3))
            self.assertEqual(node.record.data().tolist(),
                             [3, 5] + [6])  # delta is applied per segment
            node.tree.setTimeContext()

            self.assertEquals(node.tree.getTimeContext(), (None, None, None))
            self.assertEqual(node.record.data().tolist(), list(range(-9, 9)))

            #self.assertEquals(Tree.getTimeContext(),(1,2,3))
            tdi('treeopen($,$)', self.tree, self.shot)
            Tree.setTimeContext(1, 2, 3)  # test privacy to Tree
            self.assertEquals(Tree.getTimeContext(), (1, 2, 3))
            tdi('treeopennew($,$)', self.tree, self.shot + 1)
            self.assertEquals(Tree.getTimeContext(), (None, None, None))
            Tree.setTimeContext(2, 3, 4)  # test privacy to Tree
            self.assertEquals(Tree.getTimeContext(), (2, 3, 4))
            tdi('treeopen($,$)', self.tree, self.shot)
            self.assertEquals(Tree.getTimeContext(), (1, 2, 3))
            tdi('treeclose()')
            self.assertEquals(Tree.getTimeContext(), (2, 3, 4))
            tdi('treeclose()', self.tree, self.shot)
            self.assertEquals(Tree.getTimeContext(), (1, 2, 3))
Esempio n. 8
0
 def test():
     from MDSplus import Tree, Int64, Int64Array, Int32Array
     with Tree(self.tree, self.shot, 'NEW') as ptree:
         node = ptree.addNode('S')
         ptree.write()
     node.tree = Tree(self.tree, self.shot)
     for i in range(-9, 9, 3):
         d = Int64Array(range(3)) * 10 + i * 10
         v = Int32Array(range(3)) + i
         node.beginSegment(d[0], d[2], d, v)
     self.assertEqual(
         node.getSegmentList(20, 59).dim_of(0).tolist(), [0, 30])
     self.assertEqual(
         node.getSegmentList(20, 60).dim_of(0).tolist(), [0, 30, 60])
     self.assertEqual(
         node.getSegmentList(21, 60).dim_of(0).tolist(), [30, 60])
     self.assertEqual(node.record.data().tolist(), list(range(-9, 9)))
     node.tree.setTimeContext(Int64(30), Int64(70), Int64(20))
     self.assertEqual(node.record.data().tolist(),
                      [3, 5] + [6])  # delta is applied per segment
     node.tree.setTimeContext()
     self.assertEqual(node.record.data().tolist(), list(range(-9, 9)))
Esempio n. 9
0
 def test():
     from MDSplus import Tree, DateToQuad, ZERO, Int32, Int32Array, Int64Array, Range
     with Tree('seg_tree', self.shot, 'NEW') as ptree:
         node = ptree.addNode('S')
         node.compress_on_put = False
         ptree.write()
     ptree.normal()
     ptree.compressDatafile()
     te = DateToQuad("now")
     sampperseg = 50
     data = ZERO(Int32Array([sampperseg]), Int32(0))
     for i in range(513):
         t0 = te + 1
         te = t0 + sampperseg - 1
         node.makeSegment(t0, te, Int64Array(range(t0, te + 1)),
                          data + Int32(i))
     node.compress_segments = True
     ptree.createPulse(self.shot + 1)
     Tree.compressDatafile(self.tree, self.shot + 1)
     ptree1 = Tree(self.tree, self.shot + 1)
     node1 = ptree1.S
     self.assertEqual(True, (node.record == node1.record).all())
     self.assertEqual(
         True,
         ptree.getDatafileSize() > ptree1.getDatafileSize())
     for i in range(node.getNumSegments()):
         str, end = node.getSegmentLimits(i)
         node.updateSegment(str, end, Range(str, end), i)
     ptree.close()
     ptree.compressDatafile()
     ptree.readonly()
     self.assertEqual(
         True,
         ptree.getDatafileSize() < ptree1.getDatafileSize())
     for i in range(node1.getNumSegments()):
         self.assertEqual(
             node.getSegmentDim(i).data().tolist(),
             node1.getSegmentDim(i).data().tolist())
Esempio n. 10
0
    def store(self):
        print('************ START STORE ************')
        # Get IP Address
        try:
            ipAddr = self.ip_addr.data()
        except:
            Data.execute('DevLogErr($1,$2)', self.nid,
                         'Invalid Remote IP Address')
            raise mdsExceptions.TclFAILED_ESSENTIAL
    # Get Base Address
        try:
            baseAddr = self.base_addr.data()
        except:
            Data.execute('DevLogErr($1,$2)', self.nid,
                         'Invalid Base Address specification')
            raise mdsExceptions.TclFAILED_ESSENTIAL
    # Get Scan Count
        try:
            scanCount = self.scan_count.data()
        except:
            Data.execute('DevLogErr($1,$2)', self.nid, 'Invalid Scan Count')
            raise mdsExceptions.TclFAILED_ESSENTIAL
        print('Scan Count=', scanCount)
        # Get LNE Mode
        lneModeDict = {
            'VME': 0,
            'CONTROL SIGNAL': 1,
            'INTERNAL 10MHZ': 2,
            'CHANNEL N': 3,
            'PRESET': 4
        }
        try:
            lneMode = lneModeDict[self.lne_mode.data()]
        except:
            Data.execute('DevLogErr($1,$2)', self.nid, 'Invalid LNE Mode')
            raise mdsExceptions.TclFAILED_ESSENTIAL
        print('LNE Mode=', lneMode)
        # Get LNE Source
        try:
            lneSource = self.lne_source.data()
        except:
            Data.execute('DevLogErr($1,$2)', self.nid, 'Invalid LNE Source')
            raise mdsExceptions.TclFAILED_ESSENTIAL
        print('LNE Source=', lneSource)
        # Get Channels Setup
        channelMask = 0
        for a in range(0, 32):
            if a < 10:
                if getattr(self, 'channel_0%d' % (a)).isOn():
                    print('Channel_0' + str(a) + ' IS ON')
                    channelMask = channelMask | (1 << a)
            else:
                if getattr(self, 'channel_%d' % (a)).isOn():
                    print('Channel_' + str(a) + ' IS ON')
                    channelMask = channelMask | (1 << a)
        del a
        print('Channel Mask= ', channelMask)
        # Connect to SIS3820 via MDS IP
        status = Data.execute('MdsConnect("' + ipAddr + '")')
        if status == 0:
            Data.execute('MdsDisconnect()')
            Data.execute('DevLogErr($1,$2)', self.nid,
                         'Cannot Connect to VME. See VME console for details')
            raise mdsExceptions.TclFAILED_ESSENTIAL
    # Wait End Acquisition
        status = Data.execute(
            'MdsValue("SIS3820->sis3820_waitEndAcquisition(val($1), val($2))", $1, $2)',
            baseAddr, scanCount)
        if status != 0:
            Data.execute('MdsDisconnect()')
            Data.execute(
                'DevLogErr($1,$2)', self.nid,
                'Cannot execute HW Acquisition. See VME console for details')
            raise mdsExceptions.TclFAILED_ESSENTIAL

    # Pre Store Fase
        status = Data.execute(
            'MdsValue("SIS3820->sis3820_preStore(val($1), val($2))", $1, $2)',
            baseAddr, channelMask)
        if status != 0:
            Data.execute('MdsDisconnect()')
            Data.execute(
                'DevLogErr($1,$2)', self.nid,
                'Cannot execute HW Acquisition. See VME console for details')
            raise mdsExceptions.TclFAILED_ESSENTIAL

        DataArray = c_int * scanCount
        rawChan = []
        rawChan = DataArray()

        if lneMode == 2:
            trigTime = 0
            clockPeriod = 10e-6
        else:
            try:
                clk = self.lne_source.evaluate()
                clockPeriod = clk.delta
                trigTime = clk.begin
                #ending = clk.end
            except:
                Data.execute('DevLogErr($1,$2)', self.nid,
                             'Invalid LNE Source')
                raise mdsExceptions.TclFAILED_ESSENTIAL

        for chan in range(0, 32):
            if channelMask & (1 << chan):
                # Read Chan Data
                rawChan = Data.execute(
                    'MdsValue("SIS3820->sis3820_readChData:dsc( val($1))", $1)',
                    chan)
                # Build the Dimension object in a single call
                dim = Dimension(Window(0, scanCount, trigTime),
                                Range(None, None, clockPeriod))
                # Put all togenther in a "Signal" object.
                convExpr = Data.compile("$VALUE")
                # Use MDSplus Int32Array object
                rawMdsData = Int32Array(rawChan)
                # Every MDSplus data type can have units associated with it
                rawMdsData.setUnits("Count")
                convExpr.setUnits("Count")
                # Build the signal object
                signal = Signal(convExpr, rawMdsData, dim)
                # Write the signal in the tree
                if chan < 10:
                    try:
                        self.__getattr__('channel_0%d_data' %
                                         (chan)).putData(signal)
                    except:
                        Data.execute('DevLogErr($1,$2)', self.nid,
                                     'Cannot write Signal in the tree')
                        print('Cannot write Signal in the tree')
                else:
                    try:
                        self.__getattr__('channel_%d_data' %
                                         (chan)).putData(signal)
                    except:
                        Data.execute('DevLogErr($1,$2)', self.nid,
                                     'Cannot write Signal in the tree')
                        print('Cannot write Signal in the tree')

        Data.execute('MdsDisconnect()')
        del chan
        print('************ END STORE ************')
        return


########################################### END STORE #######################################