Tcl Interface to Various Set Operations
List Sets
Use vtk_trace_list_sets to list all the sets. Usage details can be found in the VOV Reference Guide.
# -- List sets alphabetically
foreach set [lsort [vtk_trace_list_sets]] {
puts "Set: $set"
}
Find Sets by Name
set setId [vtk_set_find $setName]
This procedure returns zero (actually 00000000) if there is no set by the given name. All usage details of API procedures for sets are located in the VOV Reference Guide.
List Set Elements
To list the elements of a given set, use vtk_set_get_elements. This procedure requires at least two arguments, the VovId of a set and a formatting string.
Example:
set setId [vtk_set_find "System:files"]
foreach info [vtk_set_get_elements $setId "@ID@ @NAME@"] {
puts "$info"
}
Smart Sets
Smart sets are sets that automatically update after every node change and include all nodes based on a selection rule given at set creation time. This feature can be very powerful, but very expensive.
Smart sets created with the -smartc argument only update on node creation, reducing the load created by smart sets.
Create Sets
From a Tcl script, use the procedure vtk_set_create, which requires two arguments, the name of the new set and the selection rule.
The procedure returns the VovId of the new set. If a set by the same name exists already, it is forgotten and a new set with a new VovId is created.
# Create an empty set by using "" (the null string) as the selection rule.
set setId [vtk_set_create "tmp:myNewSet" ""]
# Create a set of all jobs that are FAILED at the moment of the
# creation of the set
set setId [vtk_set_create "my_failed_jobs" "isjob status==FAILED"]
# Create a set of all jobs that are not VALID at the moment of the
# creation of the set. The set will be destroyed when the calling
# process exists (-client). The set creation will not create events (-transient).
set setId [vtk_set_create -client -transient "tmp:failed" "isjob status!=VALID"]
# Create a smart set of all jobs that are SUSPENDED.
# The smart set is updated automatically by vovserver.
# The set expires after 5 minutes from the creation.
set setId [vtk_set_create -smart -expire 5m "My:Suspended" "isjob status==SUSPENDED"]
# Create a hierarchical set. In the following example, MySet and Subset are created,
# Subset becomes the subset of MySet.
set setId [vtk_set_create -hier MySet:Subset ""]
Forget Sets and Elements of Sets
vtk_set_forget $setId
vtk_set_forget -elements $setId
vtk_set_forget -hier $setId
vtk_set_forget -hier -elements $setId
Rename Sets
vtk_set_rename $setId "new set name"
Operations on Sets
Many operations may be performed on sets. All operations can be performed from the Tcl interface using a procedure called vtk_set_operation. Many operations are also available from the CLI and from the GUI. This section deals only with the Tcl interface.
- Attaching and detaching nodes
- To attach and detach nodes from a set, you need the VovId of the set and the
VovId of the node you want to attach or detach. Then you use one of these
two forms:
vtk_set_operation $setId $nodeId ATTACH vtk_set_operation $setId $nodeId DETACH
- Testing for membership
- To test for membership of a node in a set, you need the VovId of the set and
the VovId of the node. The following expression returns 1 if the node is a
member of the set, and 0 otherwise: Note: in 2015.03 and later releases,
ISMEMBER may be used as an alternate to CONTAINS.
vtk_set_operation $setId $nodeId CONTAINS
- Intersection and union of sets
- To intersect or unite two sets you need the VovId's of both sets. One of the
sets will be the "accumulator" set, because it collects the result of the
operation. In the case of intersection, all elements in the accumulator that
do not belong in the other set are detached from the accumulator set. In the
case of union, all elements in the other set are attached to the accumulator
set.
vtk_set_operation $accId $setId INTERSECTION vtk_set_operation $accId $setId UNION
- Complement of a set
- This operation also requires two sets. The result, stored into the
accumulator set, is effectively the intersection of the accumulator with the
complement of the other set.
vtk_set_operation $accId $setId COMPLEMENT
- Input set, Output set and cones
- These operations are similar to union and intersection. Upon entry, the
accumulator set, which collects the result, should be an empty set.
vtk_set_operation $accId $setId INPUTS vtk_set_operation $accId $setId OUTPUTS vtk_set_operation $accId $setId UPCONE vtk_set_operation $accId $setId DOWNCONE
- Subselection
- Given a set, you can subselect the elements from the set that satisfy a
selection rule using vtk_set_subselect. The result is a
new set. For the original set, you can use either the name or the VovId.
set newSetId [vtk_set_subselect $nameOrIdOfSet $rule]