Esempio n. 1
0
 def getNodeWild(self,name,*usage):
     """Find nodes in tree using a wildcard specification. Returns TreeNodeArray if nodes found.
     @param name: Node name. May include wildcards.
     @type name: str
     @param usage: Optional list of node usages (i.e. "Numeric","Signal",...). Reduces return set by including only nodes with these usages.
     @type usage: str
     @return: TreeNodeArray of nodes matching the wildcard path specification and usage types.
     @rtype: TreeNodeArray
     """
     from treenode import TreeNodeArray
     try:
         Tree.lock()
         self.restoreContext()
         if len(usage) > 0:
             from numpy import array
             for i in range(len(usage)):
                 if not isinstance(usage[i],str):
                     raise TypeError('Usage arguments must be strings')
                 usage=array(usage,dtype='S')
                 nids=Data.compile('getnci($,"NID_NUMBER",$)',name,usage).evaluate()
         else:
             nids=Data.compile('getnci($,"NID_NUMBER")',(name,)).evaluate()
     except Exception:
         import sys
         e=sys.exc_info()[1]
         if 'TreeNNF' in str(e):
             from mdsarray import makeArray
             nids=makeArray([])
         else:
             Tree.unlock()
             raise
     Tree.unlock()
     return TreeNodeArray(nids,self)
Esempio n. 2
0
 def __getitem__(self,idx):
     """Subscripting <==> signal[subscript]. Uses the dimension information for subscripting
     @param idx: index or Range used for subscripting the signal based on the signals dimensions
     @type idx: Data
     @rtype: Signal
     """
     return Data.execute('$[$]',self,idx)
Esempio n. 3
0
        def execute(self):
            """Execute the PutMany by sending the instructions to the remote server. The remote server will attempt to
            put the data in each of the nodes listed and after completion return a dict instance of the status of each put.
            @return: dict instance with status of each put. The key of the result will be the node name.
            """
            if self.connection is None:
                self.result=Dictionary()
                for val in self:
                    node=val['node']
                    try:
                        exp='TreePut($,$'
                        args=[node,val['exp']]
                        for i in range(len(val['args'])):
                            exp=exp+',$'
                            args.append(val['args'][i])
                        exp=exp+')'
                        status=Data.execute(exp,tuple(args))
                        if (status & 1) == 1:
                            self.result[node]='Success'
                        else:
                            self.result[node]=MdsGetMsg(status)
                    except Exception:
                        import sys
                        e=sys.exc_info()[1]
                        self.result[node]=str(e)
                return self.result
            else:
                ans=self.connection.get("PutManyExecute($)",self.serialize())
            if isinstance(ans,str):
                raise Exception("Error putting any data: "+ans)
#            self.result=ans.deserialize()
            self.result=ans.deserialize(ans)
            return self.result
Esempio n. 4
0
 def __processPutMany__(cls):
     try:
         cls.PutMany(value=Data.getTdiVar("__putManyIn__").deserialize()).execute().serialize().setTdiVar("__putManyOut__")
     except Exception:
         import sys
         e=sys.exc_info()[1]
         print(e)
         raise
Esempio n. 5
0
 def oplot(self,y,x=None,row=1,col=1,color="black"):
     """Overplot data in scope panel
     @param y: Y-axis of the data to plot
     @type y: Array
     @param x: X-axis of the data to plot in the panel
     @type x: Array
     @param row: Row of plot panel where row 1 is the top row
     @type row: int
     @param col: Column of plot panel where column 1 is the left column
     @type col: int
     @param color: Color of the plot line
     @type color: str
     @rtype: None
     """
     if x is None:
         x=Data.dim_of(y)
     Data.execute("JavaAddSignal($,$,$,$,$,$)",self.idx,y,x,row,col,color)
Esempio n. 6
0
 def nciInfo(self):
     ip=self.pytree2.getNode('\\ip')
     self.assertEqual(ip.getUsage(),'SIGNAL')
     self.assertEqual(ip.usage,ip.getUsage())
     if ip.getClass() != 'CLASS_R':
         print( "ip.nid=%d" % (ip.nid,))
         print( "Error with ip in %s" % (str(ip.tree),))
         from os import _exit
         _exit(1)
     self.assertEqual(ip.getClass(),'CLASS_R')
     self.assertEqual(ip.class_str,'CLASS_R')
     self.assertEqual(ip.compressible,False)
     self.assertEqual(ip.compressible,ip.isCompressible())
     self.assertEqual(ip.compress_on_put,True)
     self.assertEqual(ip.compress_on_put,ip.isCompressOnPut())
     self.assertEqual(ip.data_in_nci,False)
     self.assertEqual(ip.on,True)
     self.assertEqual(ip.on,ip.isOn())
     self.assertEqual(ip.do_not_compress,False)
     self.assertEqual(ip.do_not_compress,ip.isDoNotCompress())
     self.assertEqual(ip.dtype_str,'DTYPE_SIGNAL')
     self.assertEqual(ip.dtype_str,ip.getDtype())
     self.assertEqual(ip.essential,False)
     self.assertEqual(ip.essential,ip.isEssential())
     mhdtree=self.pytree2.getNode('\\PYTREESUB::TOP')
     self.assertEqual(mhdtree.include_in_pulse,True)
     self.assertEqual(mhdtree.include_in_pulse,mhdtree.isIncludedInPulse())
     self.assertEqual(ip.length,int(Data.execute('getnci($,"LENGTH")',ip)))
     self.assertEqual(ip.length,ip.getLength())
     self.assertEqual(ip.no_write_shot,False)
     self.assertEqual(ip.no_write_shot,ip.isNoWriteShot())
     self.assertEqual(ip.no_write_model,False)
     self.assertEqual(ip.no_write_model,ip.isNoWriteModel())
     self.assertEqual(ip.write_once,False)
     self.assertEqual(ip.write_once,ip.isWriteOnce())
     devs=self.pytree2.getNodeWild('\\PYTREESUB::TOP.***','DEVICE')
     dev=devs[0].conglomerate_nids
     self.assertEqual(dev[3].original_part_name,':COMMENT')
     self.assertEqual(dev[3].original_part_name,dev[3].getOriginalPartName())
     """
     self.assertEqual(ip.owner_id,Uint32(65602548))
     """
     self.assertEqual(ip.owner_id,ip.getOwnerId())
     self.assertEqual(ip.rlength,168)
     self.assertEqual(ip.rlength,ip.getCompressedLength())
     self.assertEqual(ip.setup_information,False)
     self.assertEqual(ip.setup_information,ip.isSetup())
     self.assertEqual(ip.status,0)
     self.assertEqual(ip.status,ip.getStatus())
     self.assertEqual((ip.tags==makeArray(['IP','MAGNETICS_IP','MAG_IP','MAGNETICS_PLASMA_CURRENT','MAG_PLASMA_CURRENT'])).all(),True)
     self.assertEqual((ip.tags==ip.getTags()).all(),True)
     """
     self.assertEqual(ip.time_inserted.date,' 4-FEB-2005 16:55:28.00')
     """
     self.assertEqual(ip.time_inserted,ip.getTimeInserted())
     return
Esempio n. 7
0
def test_all(*arg):
    warnings.filterwarnings("ignore","tmpnam",RuntimeWarning,__name__)
    dir=os.tmpnam()
    print "Creating trees in %s" % (dir,)
    cleanup.dir=dir
    try:
      os.mkdir(dir)
    except:
      pass
    Data.execute('setenv("pytree_path='+dir.replace('\\','\\\\')+'")')
    Data.execute('setenv("pytreesub_path='+dir.replace('\\','\\\\')+'")')
    tests=list()
    tests.append(treeUnitTest.suite())
    if os.getenv('TEST_THREADS') is not None:
	tests.append(threadsUnitTest.suite())
    tests.append(dataUnitTest.suite())
    tests.append(TestSuite([cleanup('cleanup')]))
    ans = TestSuite(tests)
    return ans
Esempio n. 8
0
 def execute(self):
     """Execute the list. Send the list to the remote server for evaluation and return the answer as a dict instance."""
     if self.connection is None:
         self.result=Dictionary()
         for val in self:
             name=val['name']
             try:
                 self.result[name]=Dictionary({'value':Data.execute('data('+val['exp']+')',tuple(val['args']))})
             except Exception,e:
                 self.result[name]=Dictionary({'error':str(e)})
         return self.result
Esempio n. 9
0
 def __init__(self,title='',x=100,y=100,width=400,height=300):
     """Initialize a Scope instance
     @param title: Title of scop window
     @type title: string
     @param x: X location on screen of scope window in pixels from left edge
     @type x: int
     @param y: Y location on screen of scope window in pixels from the top edge
     @type y: int
     @param width: Width of the scope window in pixels
     @type width: int
     @param height: Height of the scope window in pixels
     @type height: int
     @rtype: None
     """
     self.idx=Data.execute("JavaNewWindow($,-1)",title)
     self.x=x
     self.y=y
     self.width=width
     self.height=height
Esempio n. 10
0
        def execute(self):
            """Execute the list. Send the list to the remote server for evaluation and return the answer as a dict instance."""
            if self.connection is None:
                self.result=Dictionary()
                for val in self:
                    name=val['name']
                    try:
                        self.result[name]=Dictionary({'value':Data.execute('data('+val['exp']+')',tuple(val['args']))})
                    except Exception:
                        import sys
                        e=sys.exc_info()[1]
                        self.result[name]=Dictionary({'error':str(e)})
                return self.result
            else:
                ans=self.connection.get("GetManyExecute($)",self.serialize())
            if isinstance(ans,str):
                raise Exception("Error fetching data: "+ans)
            self.result=ans.deserialize(ans)
#            self.result=ans.deserialize()
            return self.result
Esempio n. 11
0
 def editTrees(self):
     pytree=Tree('pytree',self.shot,'new')
     pytree_top=pytree.default
     subtree=pytree_top.addNode('pytreesub','subtree')
     for i in range(10):
         node=pytree_top.addNode('val%02d' % (i,),'numeric')
         node.record=i
         node=pytree_top.addNode('sig%02d' % (i,),'signal')
         node.record=Signal(i,None,i)
         node=pytree_top.addNode('child%02d' % (i,),'structure')
         node.addNode('text','text')
         node.addNode('child','structure')
     pytreesub=Tree('pytreesub',self.shot,'new')
     if pytreesub.shot != self.shot:
         raise Exception("Shot number changed! tree.shot=%d, thread.shot=%d" % (pytreesub.shot, self.shot))
     pytreesub_top=pytreesub.default
     node=pytreesub_top.addNode('.rog','structure')
     for i in range(10):
         node=node.addNode('.child','structure')
     node=node.addNode('rogowski','structure')
     node.tag='MAG_ROGOWSKI'
     node=node.addNode('signals','structure')
     node=node.addNode('rog_fg','signal')
     node.record=Signal(Range(1.,1000.),None,Range(1.,100.,.1))
     node=pytreesub_top.addNode('btor','signal')
     node.tag='BTOR'
     node.compress_on_put=True
     node.record=Signal(Range(2.,2000.,2.),None,Range(1.,1000.))
     ip=pytreesub_top.addNode('ip','signal')
     rec=Data.compile("""Build_Signal(Build_With_Units(\\MAG_ROGOWSKI.SIGNALS:ROG_FG + 2100. * \\BTOR, "ampere"), *, DIM_OF(\\BTOR))""")
     ip.record=rec
     ip.tag='MAG_PLASMA_CURRENT'
     ip.tag='MAGNETICS_PLASMA_CURRENT'
     ip.tag='MAG_IP'
     ip.tag='MAGNETICS_IP'
     ip.tag='IP'
     for i in range(10):
         node=pytreesub_top.addNode('child%02d' % (i,),'structure')
         node.addDevice('dt200_%02d' % (i,),'dt200')
     pytree.write()
     pytreesub.write()
Esempio n. 12
0
    def doMethod(self,nid,method):
        """For internal use only. Support for PyDoMethod.fun used for python device support"""
        from treenode import TreeNode
        n=TreeNode(nid,self)
        top=n.conglomerate_nids[0]
        c=top.record
        q=c.qualifiers
        model=c.model

        for i in range(len(q)):
            exec( str(q[0]))
        try:
            exec( str('makeData('+model+'(n).'+method+'(Data.getTdiVar("__do_method_arg__"))).setTdiVar("_result")'))
            makeData(1).setTdiVar("_method_status")
            
        except AttributeError:
            makeData(0xfd180b0).setTdiVar("_method_status")
        except Exception:
            print("Error doing %s on node %s" % (str(method),str(n)))
            makeData(0).setTdiVar("_method_status")
            raise
        return Data.getTdiVar("_result")
Esempio n. 13
0
 def execute(self):
     """Execute the PutMany by sending the instructions to the remote server. The remote server will attempt to
     put the data in each of the nodes listed and after completion return a dict instance of the status of each put.
     @return: dict instance with status of each put. The key of the result will be the node name.
     """
     if self.connection is None:
         self.result=Dictionary()
         for val in self:
             node=val['node']
             try:
                 exp='TreePut($,$'
                 args=[node,val['exp']]
                 for i in range(len(val['args'])):
                     exp=exp+',$'
                     args.append(val['args'][i])
                 exp=exp+')'
                 status=Data.execute(exp,tuple(args))
                 if (status & 1) == 1:
                     self.result[node]='Success'
                 else:
                     self.result[node]=MdsGetMsg(status)
             except Exception,e:
                 self.result[node]=str(e)
         return self.result
Esempio n. 14
0
def test_all(*arg):
    import tempfile
    dir=tempfile.mkdtemp()
    print ("Creating trees in %s" % (dir,))
    cleanup.dir=dir
    if (str(Data.execute('getenv("TEST_DISTRIBUTED_TREES")')) == ""):
        hostpart=""
    else:
        hostpart="localhost::" 
    Data.execute('setenv("pytree_path='+hostpart+dir.replace('\\','\\\\')+'")')
    Data.execute('setenv("pytreesub_path='+hostpart+dir.replace('\\','\\\\')+'")')
    print (Data.execute('getenv("pytree_path")'))
    tests=list()
    tests.append(treeTests())
    if os.getenv('TEST_THREADS') is not None:
        tests.append(threadsSuite())
    tests.append(dataSuite())
    tests.append(TestSuite([cleanup('cleanup')]))
    return TestSuite(tests)
Esempio n. 15
0
 def show(self):
     """Show the scope window
     @rtype: None
     """
     Data.execute("JavaShowWindow($,$,$,$,$)",self.idx,self.x,self.y,self.width,self.height)
Esempio n. 16
0
 def deserialize(self):
     """Return data item if this array was returned from serialize.
     @rtype: Data
     """
     return Data.deserialize(self)
Esempio n. 17
0
 def __processPutMany__(cls):
     try:
         cls.PutMany(value=Data.getTdiVar("__putManyIn__").deserialize()).execute().serialize().setTdiVar("__putManyOut__")
     except Exception,e:
         print e
         raise