-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.#treenode.py.1.36
1386 lines (1239 loc) · 46.9 KB
/
.#treenode.py.1.36
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import mdsdata as _data
import mdsscalar as _scalar
import mdsarray as _array
import tree as _tree
import builtins as _builtins
import compound as _compound
import sys as _sys
import _mdsdtypes as _dtypes
import _mdsshr
nciAttributes = ('BROTHER','CACHED','CHILD','CHILDREN_NIDS','MCLASS','CLASS_STR',
'COMPRESSIBLE','COMPRESS_ON_PUT','CONGLOMERATE_ELT','CONGLOMERATE_NIDS',
'DATA_IN_NCI','DEPTH','DISABLED','DO_NOT_COMPRESS','DTYPE','DTYPE_STR',
'ERROR_ON_PUT','ESSENTIAL','FULLPATH','GET_FLAGS','INCLUDE_IN_PULSE',
'IO_STATUS','IO_STV','IS_CHILD','IS_MEMBER','LENGTH','MEMBER','MEMBER_NIDS',
'MINPATH','NID_NUMBER','NID_REFERENCE','NODE_NAME','NO_WRITE_MODEL',
'NO_WRITE_SHOT','NUMBER_OF_CHILDREN','NUMBER_OF_ELTS','NUMBER_OF_MEMBERS','ON',
'ORIGINAL_PART_NAME','OWNER_ID','PARENT','PARENT_DISABLED','PARENT_RELATIONSHIP',
'PARENT_STATE','PATH','PATH_REFERENCE','RECORD','RFA','RLENGTH','SEGMENTED',
'SETUP_INFORMATION','STATE','STATUS','TIME_INSERTED','USAGE','USAGE_ANY',
'USAGE_AXIS','USAGE_COMPOUND_DATA','USAGE_DEVICE','USAGE_DISPATCH','USAGE_NONE',
'USAGE_NUMERIC','USAGE_STR','USAGE_STRUCTURE','USAGE_SUBTREE','USAGE_TASK',
'USAGE_TEXT','USAGE_WINDOW','VERSIONS','WRITE_ONCE')
usage_table={'ANY':0,'NONE':1,'STRUCTURE':1,'ACTION':2,'DEVICE':3,'DISPATCH':4,'NUMERIC':5,'SIGNAL':6,
'TASK':7,'TEXT':8,'WINDOW':9,'AXIS':10,'SUBTREE':11,'COMPOUND_DATA':12,'SUBTREE':-1}
def _tcl(cmd):
return _builtins.EXT_FUNCTION(None,'tcl',cmd.replace('\\','\\\\')).evaluate()
class TreeNode(_data.Data):
"""Class to represent an MDSplus node reference (nid).
@ivar nid: node index of this node.
@type nid: int
@ivar tree: Tree instance that this node belongs to.
@type tree: Tree
"""
mdsclass=1
mdsdtype=_dtypes.DTYPE_NID
def __hasBadTreeReferences__(self,tree):
return self.tree != tree
def __fixTreeReferences__(self,tree):
if (self.nid >> 24) != 0:
return TreePath(str(self))
else:
relpath=str(self.fullpath)
relpath=relpath[relpath.find('::TOP')+5:]
path='\\%s::TOP%s' % (tree.tree,relpath)
try:
ans=tree.getNode(str(self))
except:
ans=TreePath(path,tree)
return ans
def __getattr__(self,name):
"""
Implements value=node.attribute
Attributes defined:
- brother - TreeNode,Next node in tree
- child - TreeNode,First ancestor
- children_nids - TreeNodeArray, Children nodes
- mclass - Uint8, Internal numeric MDSplus descriptor class
- class_str - String, Name of MDSplus descriptor class
- compressible - Bool, Flag indicating node contains compressible data
- compress_on_put - Bool, Flag indicating automatic compression
- conglomerate_elt - Int32, Index of node in a conglomerate
- conglomerate_nids - TreeNodeArray, Nodes in same conglomerate
- data_in_nci - Uint32, Flag indicating data stored in nci record
- descendants - TreeNodeArray, One level descendants of this node
- depth - Int32, Level of node from the top node of the tree
- disabled - Bool, Opposite of on flag
- do_not_compress - Bool, Flag indicating data should not be compressed
- dtype - Uint8, Internal numeric MDSplus data type
- dtype_str - String, Name of MDSplus data type
- essential - Bool, Flag indicating node is essential, used for actions
- fullpath - String, Full absolute path of node in tree
- include_in_pulse - Bool, Flag indicating node should be included in pulse
- is_child - Bool, Flag indicating node is a child node
- is_member - Bool, Flag indicating node is a member bnode
- length - Int32, Length of data in bytes (uncompressed)
- local_path - str, path to node relative to top of tree containing this node
- local_tree - str, Name of tree containing this node
- member - TreeNode, First member of this node
- member_nids - TreeNodeArray, Members nodes
- minpath - String, Minimum length string representing path to node
- nid_number - Int32, Internal index to node in tree
- nid_reference - Bool, Flag indicating that data contains references to nodes
- node_name - String, This nodes name
- no_write_model - Bool, Flag indicating that data cannot be written into model
- no_write_shot - Bool, Flag indicating that data cannot be written into shot
- number_of_children - Int32, Number of children of this node
- number_of_descentants - Int32, Numer of first level descendants
- number_of elts - Int32, Number of nodes in this conglomerate
- number_of_members - Int32, Number of members of this node
- on - Bool, Flag indicating if this node is turned on
- original_part_name - String, Original node name when conglomerate was created
- owner_id - Int32, Id/gid of account which stored the data
- parent - TreeNode, Parent of this node
- parent_disabled - Bool, Flag indicating parent is turned off
- path - String, Path to this node
- path_reference - Bool, Flag indicating that data contains references to nodes
- record - Data, Contents of this node
- rfa - Int64, Byte offset to this node
- rlength - Int32, Data length in bytes (compressed)
- segmented - Bool, Flag indicating node contains segmented records
- setup_information - Bool, Flag indicating node contains setup information
- status - Int32, Completion status of action
- tags - StringArray, List of tagnames for this node
- time_inserted - Uint64, Time data was inserted
- usage - String, Usage of this node
- versions - Bool, Flag indicating that data contains versions
- write_once - Bool, Flag indicating that data can only be written if node is empty.
@param name: Name of attribute
@type name: str
@return: Value of attribute
@rtype: various
"""
if name.lower() == 'nid':
try:
return self.__dict__['nid']
except KeyError:
try:
return self.tree.getNode(self.tree_path)
except:
return None
return self.tree.getNode(str(self))
try:
return self.__dict__[name]
except:
pass
if name.lower() == 'record':
return self.getData()
if name.lower() == 'tags':
return self.getTags()
if name.lower() == 'usage':
return _scalar.String(self.usage_str.value[10:])
if name.lower() == 'descendants':
return self.getDescendants()
if name.lower() == 'number_of_descendants':
return self.number_of_members+self.number_of_children
if name.lower() == 'segmented':
return self.getNumSegments().value > 0
if name.lower() == 'local_tree':
return self.getLocalTree()
if name.lower() == 'local_path':
return self.getLocalPath()
if name.upper() in nciAttributes:
try:
if name.lower() == 'mclass':
name='class';
_tree.Tree.lock()
self.restoreContext()
try:
ans = _builtins.GETNCI(self,self.makeData(name)).evaluate()
if isinstance(ans,_scalar.Uint8):
if name not in ('class','dtype'):
ans = bool(ans)
except _tdishr.TdiException:
e=_sys.exc_info()[1]
if 'TreeNNF' in str(e):
ans=None
else:
raise
finally:
_tree.Tree.unlock()
if isinstance(ans,_scalar.String):
return _scalar.String(ans.rstrip())
return ans
raise AttributeError('Attribute %s is not defined' % (name,))
def __init__(self,n,tree=None):
"""Initialze TreeNode
@param n: Index of the node in the tree.
@type n: int
@param tree: Tree associated with this node
@type tree: Tree
"""
self.__dict__['nid']=int(n);
if tree is None:
try:
self.tree=_tree.Tree.getActiveTree()
except:
self.tree=_tree.Tree()
else:
self.tree=tree
def __setattr__(self,name,value):
"""
Implements node.attribute=value
Attributes which can be set:
- compress_on_put - Bool, Flag indicating whether data should be compressed when written
- do_not_compress - Bool, Flag to disable compression
- essential - Bool, Flag indicating successful action completion required
- include_in_pulse - Bool, Flag to include in pulse
- no_write_model - Bool, Flag to disable writing in model
- no_write_shot - Bool, Flag to disable writing in pulse file
- record - Data, Data contents of node
- subtree - Bool, Set node to be subtree or not (edit mode only)
- tag - str, Add tag to node (edit mode only)
- write_once - Bool, Flag to only allow writing to empty node
@param name: Name of attribute
@type name: str
@param value: Value for attribute
@type value: various
@rtype: None
"""
uname=name.upper()
if uname=="RECORD":
self.putData(value)
elif uname=="ON":
self.setOn(value)
elif uname=="NO_WRITE_MODEL":
self.setNoWriteModel(value)
elif uname=="NO_WRITE_SHOT":
self.setNoWriteShot(value)
elif uname=="WRITE_ONCE":
self.setWriteOnce(value)
elif uname=="INCLUDE_IN_PULSE":
self.setIncludedInPulse(value)
elif uname=="COMPRESS_ON_PUT":
self.setCompressOnPut(value)
elif uname=="DO_NOT_COMPRESS":
self.setDoNotCompress(value)
elif uname=="ESSENTIAL":
self.setEssential(value)
elif uname=="SUBTREE":
self.setSubtree(value)
elif uname=="USAGE":
self.setUsage(value)
elif uname=="TAG":
self.addTag(value)
elif uname in nciAttributes:
raise AttributeError('Attribute %s is read only' %(name,))
elif uname == "NID":
raise AttributeError('Attribute nid is read only')
else:
self.__dict__[name]=value
def __setNode(self,qualifier,flag,reversed=False):
"""For internal use only"""
if flag is True or flag is False:
if reversed is True:
flag = not flag
if flag is True:
switch="/"
else:
if flag is False:
switch="/no"
else:
raise TypeError('Argument must be True or False')
try:
_tree.Tree.lock()
self.restoreContext()
cmd='set node %s%s%s'% (self.fullpath,switch,qualifier)
status=_tcl(cmd)
if not (status & 1):
import _descriptor
msg="Error executing command: %s, returned error: %s" % (cmd,str(_mdsshr.MdsGetMsg(int(status))))
if 'TreeFAILURE' in msg:
raise __import__('_treeshr').TreeException('Error writing to tree, possibly file protection problem')
else:
raise __import__('_treeshr').TreeException(msg)
finally:
_tree.Tree.unlock()
return
def __str__(self):
"""Convert TreeNode to string."""
if self.nid is None:
ans="NODEREF(*)"
else:
ans=__import__('_treeshr').TreeGetPath(self)
return ans
def addDevice(self,name,model):
"""Add device descendant.
@param name: Node name of device. 1-12 characters, no path delimiters
@type name: str
@param model: Type of device to add
@type model: str
@return: Head node of device
@rtype: TreeNode
"""
if name.find(':') >=0 or name.find('.') >= 0:
raise __import__('_treeshr').TreeException("Invalid node name, do not include path delimiters in nodename")
return self.tree.addDevice(self.fullpath+":"+name.upper(),model)
def addNode(self,name,usage='ANY'):
"""Add node
@param name: Node name of new node to add
@type name: str
@param usage: Usage of the new node. If omitted set to ANY.
@type usage: str
@return: New now added
@rtype: TreeNode
"""
try:
usagenum=usage_table[usage.upper()]
except KeyError:
raise KeyError('Invalid usage specified. Use one of %s' % (str(usage_table.keys()),))
name=str(name).upper()
if name[0]==':' or name[0]=='.':
name=str(self.fullpath)+name
elif name[0] != "\\":
if usagenum==1 or usagenum==-1:
name=str(self.fullpath)+"."+name
else:
name=self.fullpath+":"+name
return self.tree.addNode(name,usage)
def addTag(self,tag):
"""Add a tagname to this node
@param tag: tagname for this node
@type tag: str
@rtype: None
"""
__import__('_treeshr').TreeAddTag(self.tree,self.nid,str(tag))
def beginSegment(self,start,end,dimension,initialValueArray,idx=-1):
"""Begin a record segment
@param start: Index of first row of data
@type start: Data
@param end: Index of last row of data
@type end: Data
@param dimension: Dimension information of segment
@type dimension: Dimension
@param initialValueArray: Initial data array. Defines shape of segment
@type initialValueArray: Array
@rtype: None
"""
__import__('_treeshr').TreeBeginSegment(self,start,end,dimension,initialValueArray,idx)
def beginTimestampedSegment(self,array,idx=-1):
"""Allocate space for a timestamped segment
@param array: Initial data array to define shape of segment
@type array: Array
@param idx: Optional segment index. Defaults to -1 meaning next segment.
@type idx: int
@rtype: None
"""
__import__('_treeshr').TreeBeginTimestampedSegment(self,array,idx)
def compare(self,value):
"""Returns True if this node contains the same data as specified in the value argument
@param value: Value to compare contents of the node with
@type value: Data
@rtype: Bool
"""
try:
oldval=self.record
except:
oldval=None
status = _mdsshr.MdsCompareXd(self.makeData(oldval),self.makeData(value))
if status == 1:
return True
else:
return False
def containsVersions(self):
"""Return true if this node contains data versions
@return: True if node contains versions
@rtype: bool
"""
return self.versions
def delete(self):
"""Delete this node from the tree
@rtype: None
"""
self.tree.deleteNode(self.fullpath)
def deleteData(self):
"""Delete data from this node
@rtype: None
"""
self.putData(None)
return
def dispatch(self,wait=True):
"""Dispatch an action node
@rtype: None
"""
a=self.record
if not isinstance(a,_compound.Action):
raise Exception("Node does not contain an action description")
else:
if wait:
status=_tcl("dispatch/wait "+str(self.fullpath))
else:
status=_tcl("dispatch/nowait "+str(self.fullpath))
if not (status & 1):
import _descriptor
raise Exception(_mdsshr.MdsGetMsg(status,"Error dispatching node"))
def doMethod(self,method,arg=None):
"""Execute method on conglomerate element
@param method: method name to perform
@type method: str
@param arg: Optional argument for method
@type arg: Data
@rtype: None
"""
try:
_tree.Tree.lock()
self.restoreContext()
__import__('_treeshr').TreeDoMethod(self,str(method),arg)
finally:
_tree.Tree.unlock()
return
def getBrother(self):
"""Return sibling of this node
@return: Sibling of this node
@rtype: TreeNode
"""
return self.brother
def getChild(self):
"""Return first child of this node.
@return: Return first child of this node or None if it has no children.
@rtype: TreeNode
"""
return self.child
def getChildren(self):
"""Return TreeNodeArray of children nodes.
@return: Children of this node
@rtype: TreeNodeArray
"""
return self.children_nids
def getClass(self):
"""Return MDSplus class name of this node
@return: MDSplus class name of the data stored in this node.
@rtype: String
"""
return self.class_str
def getCompressedLength(self):
"""Return compressed data length of this node
@return: Compress data length of this node
@rtype: int
"""
return self.rlength
def getConglomerateElt(self):
"""Return index of this node in a conglomerate
@return: element index of this node in a conglomerate. 0 if not in a conglomerate.
@rtype: Int32
"""
return self.conglomerate_elt
def getConglomerateNodes(self):
"""Return TreeNodeArray of conglomerate elements
@return: Nodes in this conglomerate.
@rtype: TreeNodeArray
"""
return self.conglomerate_nids
def getData(self):
"""Return data
@return: data stored in this node
@rtype: Data
"""
return __import__('_treeshr').TreeGetRecord(self)
def getDepth(self):
"""Get depth of this node in the tree
@return: number of levels between this node and the top of the currently opened tree.
@rtype: Int32
"""
return self.depth
def getDescendants(self):
"""Return TreeNodeArray of first level descendants (children and members).
@return: First level descendants of this node
@rtype: TreeNodeArray
"""
ans=None
members=self.member_nids
children=self.children_nids
if members is None:
ans=children
elif children is None:
ans=members
else:
nids=list()
for node in members:
nids.append(node.nid)
for node in children:
nids.append(node.nid)
ans=TreeNodeArray(_array.Int32Array(nids))
return ans
def getDtype(self):
"""Return the name of the data type stored in this node
@return: MDSplus data type name of data stored in this node.
@rtype: String
"""
return self.dtype_str
def getFullPath(self):
"""Return full path of this node
@return: full path specification of this node.
@rtype: String
"""
return self.fullpath
def getLength(self):
"""Return uncompressed data length of this node
@return: Uncompressed data length of this node
@rtype: int
"""
return self.length
def getLocalTree(self):
"""Return tree containing this node
@return: Name of tree containing this node
@rtype: str
"""
top=self
while top.nid & 0xffffff:
top=top.parent
if top.node_name == 'TOP':
return self.tree.tree
else:
return top.node_name
def getLocalPath(self):
"""Return path relative to top of local tree
@return: Path relative to top of local tree
@rtype: str
"""
path=''
top=self
while top.nid & 0xffffff:
if top.is_member:
delim=':'
else:
delim='.'
path=delim + top.node_name + path
top=top.parent
return path
def getMember(self):
"""Return first member node
@return: First member of thie node
@rtype: TreeNode
"""
return self.member
def getMembers(self):
"""Return TreeNodeArray of this nodes members
@return: members of this node
@rtype: TreeNodeArray
"""
return self.member_nids
def getMinPath(self):
"""Return shortest path string for this node
@return: shortest path designation depending on the current node default and whether the node has tag names or not.
@rtype: String
"""
return self.minpath
def getNid(self):
"""Return node index
@return: Internal node index of this node
@rtype: int
"""
return self.nid
def getNode(self,path):
"""Return tree node where path is relative to this node
@param path: Path relative to this node
@type path: str
@return: node matching path
@rtype: TreeNode
"""
if path[0] == '\\':
return self.tree.getNode(path)
else:
if path[0] != ':' and path[0] != '.':
path=':'+path
return self.tree.getNode(self.fullpath+path)
def getNodeName(self):
"""Return node name
@return: Node name of this node. 1 to 12 characters
@rtype: String
"""
return self.node_name
def getNodeWild(self,path):
"""Return tree nodes where path is relative to this node
@param path: Path relative to this node
@type path: str
@return: node matching path
@rtype: TreeNodeArray
"""
if path[0] == '\\':
return self.tree.getNode(path)
else:
if path[0] != ':' and path[0] != '.':
path=':'+path
return self.tree.getNodeWild(self.fullpath+path)
def getNumChildren(self):
"""Return number of children nodes.
@return: Number of children
@rtype: Int32
"""
return self.number_of_children
def getNumDescendants(self):
"""Return number of first level descendants (children and members)
@return: total number of first level descendants of this node
@rtype: int
"""
return self.number_of_descendants
def getNumElts(self):
"""Return number of nodes in this conglomerate
@return: Number of nodes in this conglomerate or 0 if not in a conglomerate.
@rtype: Int32
"""
return self.number_of_elts
def getNumMembers(self):
"""Return number of members
@return: number of members
@rtype: int
"""
return self.number_of_members
def getNumSegments(self):
"""return number of segments contained in this node
@rtype: int
"""
return self.makeData(__import__('_treeshr').TreeGetNumSegments(self))
def getOriginalPartName(self):
"""Return the original part name of node in conglomerate
@return: Original part name of this node when conglomerate was first instantiated.
@rtype: String
"""
return self.original_part_name
def getOwnerId(self):
"""Get id/gid value of account which wrote data to this node
@return: Return user id of last account used to write data to this node
@rtype: int
"""
return self.owner_id
def getParent(self):
"""Return parent of this node
@return: Parent of this node
@rtype: TreeNode
"""
return self.parent
def getPath(self):
"""Return path of this node
@return: Path to this node.
@rtype: String
"""
return self.path
def getSegment(self,idx):
"""Return segment
@param idx: The index of the segment to return. Indexes start with 0.
@type idx: int
@return: Data segment
@rtype: Signal | None
"""
num=self.getNumSegments()
if num > 0 and idx < num:
return __import__('_treeshr').TreeGetSegment(self,idx)
else:
return None
def getSegmentDim(self,idx):
"""Return dimension of segment
@param idx: The index of the segment to return. Indexes start with 0.
@type idx: int
@return: Segment dimension
@rtype: Dimension
"""
num=self.getNumSegments()
if num > 0 and idx < num:
return self.getSegment(idx).getDimension(0)
else:
return None
def getSegmentEnd(self,idx):
"""return end of segment
@param idx: segment index to query
@type idx: int
@rtype: Data
"""
num=self.getNumSegments()
if num > 0 and idx < num:
limits=__import__('_treeshr').TreeGetSegmentLimits(self,idx)
if limits is not None:
return limits[1]
else:
return None
else:
return None
def getSegmentStart(self,idx):
"""return start of segment
@param idx: segment index to query
@type idx: int
@rtype: Data
"""
num=self.getNumSegments()
if num > 0 and idx < num:
limits=__import__('_treeshr').TreeGetSegmentLimits(self,idx)
if limits is not None:
return limits[0]
else:
return None
else:
return None
def getStatus(self):
"""Return action completion status
@return: action completion status stored by dispatcher if this node is a dispacted action. Low bit set is success.
@rtype: int
"""
return self.status
def getTimeInserted(self):
"""Return time data was written
@return: time data was written to this node as Uint64. Use answer.date to retrieve date/time string
@rtype: Uint64
"""
return self.time_inserted
def getTags(self):
"""Return tags of this node
@return: Tag names pointing to this node
@rtype: ndarray
"""
try:
_tree.Tree.lock()
ans=__import__('_treeshr').TreeFindNodeTags(self)
finally:
_tree.Tree.unlock()
return ans
def getTree(self):
"""Return Tree associated with this node
@return: Tree associated with this node
@rtype: Tree
"""
return self.tree
def getUsage(self):
"""Return usage of this node
@return: usage of this node
@rtype: str
"""
return self.usage
def isChild(self):
"""Return true if this is a child node
@return: True if this is a child node instead of a member node.
@rtype: bool
"""
return self.is_child
def isCompressible(self):
"""Return true if node contains data which can be compressed
@return: True of this node contains compressible data
@rtype: bool
"""
return self.compressible
def isCompressOnPut(self):
"""Return true if node is set to compress on put
@return: True if compress on put
@rtype: bool
"""
return self.compress_on_put
def isDoNotCompress(self):
"""Return true of compression is disabled for this node
@return: True if this node has compression disabled
@rtype: bool
"""
return self.do_not_compress
def isEssential(self):
"""Return true if successful action completion is essential
@return: True if this node is marked essential.
@rtype: bool
"""
return self.essential
def isIncludedInPulse(self):
"""Return true if this subtree is to be included in pulse file
@return: True if subtree is to be included in pulse file creation.
@rtype: bool
"""
return self.include_in_pulse
def isMember(self):
"""Return true if this is a member node
@return: True if this is a member node
@rtype: bool
"""
return self.is_member
def isNoWriteModel(self):
"""Return true if data storage to model is disabled for this node
@return: Return True if storing data in this node in the model tree is disabled
@rtype: bool
"""
return self.no_write_model
def isNoWriteShot(self):
"""Return true if data storage to pulse file is disabled for this node
@return: Return True if storing data in this node in the pulse tree is disabled
@rtype: bool
"""
return self.no_write_shot
def isOn(self):
"""Return True if node is turned on, False if not.
@return: Return True if node is turned on
@rtype: bool
"""
return self.on
def isSegmented(self):
"""Return true if this node contains segmented records
@return: True if node contains segmented records
@rtype: bool
"""
return self.segmented
def isSetup(self):
"""Return true if data is setup information.
@return: True if data is setup information (originally written in the model)
@rtype: bool
"""
return self.setup_information
def isWriteOnce(self):
"""Return true if node is set write once
@return: Return True if data overwrite in this node is disabled
@rtype: bool
"""
return self.write_once
def makeSegment(self,start,end,dimension,valueArray,idx=-1):
"""Make a record segment
@param start: Index of first row of data
@type start: Data
@param end: Index of last row of data
@type end: Data
@param dimension: Dimension information of segment
@type dimension: Dimension
@param valueArray: Contents of segment
@type valueArray: Array
@rtype: None
"""
__import__('_treeshr').TreeMakeSegment(self,start,end,dimension,valueArray,idx)
def move(self,parent,newname=None):
"""Move node to another location in the tree and optionally rename the node
@param parent: New parent of this node
@type parent: TreeNode
@param newname: Optional new node name of this node. 1-12 characters, no path delimiters.
@type newname: str
@rtype: None
"""
if newname is None:
newname=str(self.node_name)
if self.usage=='SUBTREE' or self.usage=='STRUCTURE':
__import__('_treeshr').TreeRenameNode(self,str(parent.fullpath)+"."+newname)
else:
__import__('_treeshr').TreeRenameNode(self,str(parent.fullpath)+":"+newname)
def putData(self,data):
"""Store data
@param data: Data to store in this node.
@type data: Data
@rtype: None
"""
try:
if isinstance(data,_data.Data) and data.__hasBadTreeReferences__(self.tree):
data=data.__fixTreeReferences__(self.tree)
_tree.Tree.lock()
__import__('_treeshr').TreePutRecord(self,data)
finally:
_tree.Tree.unlock()
return
def putRow(self,bufsize,array,timestamp):
"""Load a timestamped segment row
@param bufsize: number of rows in segment
@type bufsize: int
@param array: data for this row
@type array: Array or Scalar
@param timestamp: Timestamp of this row
@type timestamp: Uint64
@rtype: None
"""
__import__('_treeshr').TreePutRow(self,bufsize,array,timestamp)
def putSegment(self,data,idx):
"""Load a segment in a node
@param data: data to load into segment
@type data: Array or Scalar
@param idx: index into segment to load data
@type idx: int
@rtype: None
"""
__import__('_treeshr').TreePutSegment(self,data,idx)
def putTimestampedSegment(self,timestampArray,array):
"""Load a timestamped segment
@param timestampArray: Array of time stamps
@type timestampArray: Uint64Array
@param array: Data to load into segment
@type array: Array
@rtype: None
"""
__import__('_treeshr').TreePutTimestampedSegment(self,timestampArray,array)
def makeTimestampedSegment(self,timestampArray,array,idx,rows_filled):
"""Load a timestamped segment
@param timestampArray: Array of time stamps
@type timestampArray: Uint64Array
@param array: Data to load into segment
@type array: Array
@param idx: Segment number
@param idx: int
@param rows_filled: Number of rows of segment filled with data
@type rows_filled: int
@rtype: None
"""
__import__('_treeshr').TreeMakeTimestampedSegment(self,timestampArray,array,idx,rows_filled)
def removeTag(self,tag):
"""Remove a tagname from this node
@param tag: Tagname to remove from this node
@type tag: str
@rtype: None
"""
try:
n=self.tree.getNode('\\'+str(tag))
if n.nid != self.nid:
raise __import__('_treeshr').TreeException("Node %s does not have a tag called %s. That tag refers to %s" % (str(self),str(tag),str(n)))
except TreeException:
e=_sys.exc_info()[1]
if str(e).find('TreeNNF') > 0:
raise __import__('_treeshr').TreeException("Tag %s is not defined" % (str(tag),))
else:
raise
self.tree.removeTag(tag)
def rename(self,newname):
"""Rename node this node
@param newname: new name of this node. 1-12 characters, no path delimiters.
@type newname: str
@rtype: None
"""
if newname.find(':') >=0 or newname.find('.') >= 0:
raise __import__('_treeshr').TreeException("Invalid node name, do not include path delimiters in nodename")
try:
olddefault=self.tree.default
self.tree.setDefault(self.parent)
if self.isChild():
newname="."+str(newname)
__import__('_treeshr').TreeRenameNode(self,str(newname))
finally:
self.tree.setDefault(olddefault)
def restoreContext(self):
"""Restore tree context. Used by internal functions.
@rtype: None
"""
if self.tree is not None:
self.tree.restoreContext()
def setCompressOnPut(self,flag):
"""Set compress on put state of this node
@param flag: State to set the compress on put characteristic
@type flag: bool
@rtype: None