예제 #1
0
 def nodeLinkage(self):
     top=TreeNode(0,self.pytree)
     members=self.pytree.getNodeWild(':*')
     self.assertEqual((members==top.member_nids).all(),True)
     self.assertEqual((members==top.getMembers()).all(),True)
     self.assertEqual(top.member.nid_number,members[0].nid_number)
     member=top.member
     for idx in range(1,len(members)):
         self.assertEqual(member.brother.nid_number,members[idx].nid_number)
         member=member.brother
     children=self.pytree.getNodeWild('.*')
     self.assertEqual((children==top.children_nids).all(),True)
     self.assertEqual((children==top.getChildren()).all(),True)
     self.assertEqual(top.child.nid_number,children[0].nid_number)
     child=top.child
     for idx in range(1,len(children)):
         self.assertEqual(child.brother.nid_number,children[idx].nid_number)
         child=child.brother
     self.assertEqual(top.child.nid_number,self.pytree.getNode(str(top.child)).nid_number)
     self.assertEqual(top.child.child.parent.nid_number,top.child.nid_number)
     x=array(int32(0)).repeat(len(members)+len(children))
     x[0:len(members)]=members.nid_number.data()
     x[len(members):]=children.nid_number.data()
     self.assertEqual((makeArray(x)==top.descendants.nid_number).all(),True)
     self.assertEqual((top.descendants.nid_number==top.getDescendants().nid_number).all(),True)
     self.assertEqual(top.child.child.depth,3)
     self.assertEqual(top.getNumDescendants(),len(x))
     self.assertEqual(top.getNumMembers(),len(members))
     self.assertEqual(top.getNumChildren(),len(children))
     self.assertEqual(top.number_of_members,len(members))
     self.assertEqual(top.number_of_children,len(children))
     self.assertEqual(top.number_of_descendants,len(x))
     devs=self.pytree2.getNodeWild('\\PYTREESUB::TOP.***','DEVICE')
     dev=devs[0].conglomerate_nids
     self.assertEqual((dev.nid_number==devs[0].getConglomerateNodes().nid_number).all(),True)
     self.assertEqual((dev.conglomerate_elt==makeArray(array(range(len(dev)))+1)).all(),True)
     for idx in range(len(dev)):
         self.assertEqual(dev[idx].conglomerate_elt,idx+1)
         self.assertEqual(dev[idx].getConglomerateElt(),idx+1)
     self.assertEqual(top.child.is_child,True)
     self.assertEqual(top.child.is_member,False)
     self.assertEqual(top.member.is_child,False)
     self.assertEqual(top.member.is_member,True)
     self.assertEqual(top.child.is_child,top.child.isChild())
     self.assertEqual(top.child.is_member,top.child.isMember())
     ip=self.pytree2.getNode('\\ip')
     self.assertEqual(ip.fullpath,"\\PYTREE::TOP.PYTREESUB:IP")
     self.assertEqual(ip.fullpath,ip.getFullPath())
     self.assertEqual(ip.minpath,"\\IP")
     self.assertEqual(ip.minpath,ip.getMinPath())
     self.assertEqual(ip.node_name,'IP')
     self.assertEqual(ip.node_name,ip.getNodeName())
     self.assertEqual(ip.path,"\\PYTREESUB::IP")
     self.assertEqual(ip.path,ip.getPath())
     return
예제 #2
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)
예제 #3
0
def MdsDecompress(value):
    from _descriptor import descriptor_xd
    from mdsarray import makeArray
    xd=descriptor_xd()
    status = MdsShr.MdsDecompress(_C.pointer(value),_C.pointer(xd))
    if (status & 1) == 1:
        return makeArray(xd.value)
    else:
        raise MdsException,MdsGetMsg(status)
예제 #4
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
예제 #5
0
def TreePutTimestampedSegment(n,timestampArray,value):
    """Put a timestampedsegment"""
    from mdsarray import makeArray,Int64Array
    timestampArray=Int64Array(timestampArray)
    value=makeArray(value)
    try:
        n.tree.lock()
        status=__TreePutTimestampedSegment(n.tree.ctx,n.nid,descriptor_a(timestampArray).pointer,_C.pointer(descriptor_a(value)))
    finally:
        n.tree.unlock()
    if (status & 1):
        return status;
    else:
        raise TreeException(MdsGetMsg(status))
예제 #6
0
def TreePutRow(n,bufsize,array,timestamp):
    """Begin a segment."""
    from mdsdata import makeData
    from mdsarray import makeArray
    try:
        n.tree.lock()
        array=makeArray(array)
        status=__TreePutRow(n.tree.ctx,n.nid,bufsize,_C.pointer(_C.c_int64(int(timestamp))),
                             _C.pointer(descriptor_a(array)))
    finally:
        n.tree.unlock()
    if (status & 1):
        return status
    else:
        raise TreeException(MdsGetMsg(status))
    return None
예제 #7
0
def TreeFindNodeTags(n):
    from mdsarray import makeArray
    ctx=_C.c_void_p(0)
    tags=list()
    done=False
    while not done:
        tag_ptr=__TreeFindNodeTags(n.tree.ctx,n.nid,_C.pointer(ctx))
        try:
            tags.append(_C.cast(tag_ptr,_C.c_char_p).value.rstrip())
            TreeFree(tag_ptr)
        except:
            done=True
    if len(tags) > 0:
        tags=makeArray(tags).value
    else:
        tags=None
    return tags
예제 #8
0
def TreeFindTagWild(tree,wild):
    from mdsarray import makeArray
    nid=_C.c_int32(0)
    ctx=_C.c_void_p(0)
    tags=list()
    done=False
    while not done:
        tag_ptr=__TreeFindTagWild(tree.ctx,str.encode(wild),_C.pointer(nid),_C.pointer(ctx))
        try:
            tags.append(_C.cast(tag_ptr,_C.c_char_p).value.rstrip())
        except:
            TreeFindTagEnd(_C.pointer(ctx))
            done=True
    if len(tags) > 0:
        tags=makeArray(tags).value
    else:
        tags=None
    return tags
예제 #9
0
def makeData(value):
    """Convert a python object to a MDSobject Data object"""
    if value is None:
        return EmptyData()
    if isinstance(value,Data):
        return value
    if isinstance(value,numpy.generic) or isinstance(value,int) or isinstance(value,long) or isinstance(value,float) or isinstance(value,str):
        from mdsscalar import makeScalar
        return makeScalar(value)
    if isinstance(value,tuple) or isinstance(value,list):
        from apd import Apd,List
        apd = Apd(tuple(value),DTYPE_LIST)
        return List(apd)
    if isinstance(value,numpy.ndarray):
        from mdsarray import makeArray
        return makeArray(value)
    if isinstance(value,dict):
        from apd import Dictionary
        return Dictionary(value)
    else:
        raise TypeError,'Cannot make MDSplus data type from type: %s' % (str(type(value)),)
예제 #10
0
 def getData(self):
     """Return data transfered with the event.
     @rtype: Data
     """
     from mdsarray import makeArray
     return makeArray(self.getRaw()).deserialize()