@@ -14,8 +14,9 @@ def create_datastore(region):
1414 ds = pysidre .DataStore ()
1515 root = ds .getRoot ()
1616
17- # TODO - Implement Attributes for python
1817 # Create two attributes
18+ ds .createAttributeScalar ("vis" , 0 )
19+ ds .createAttributeScalar ("restart" , 1 )
1920
2021 # Create group children of root group
2122 state = root .createGroup ("state" )
@@ -56,6 +57,10 @@ def create_datastore(region):
5657 temp = fields .createViewAndAllocate ("temp" , pysidre .TypeID .DOUBLE_ID , eltcount )
5758 rho = fields .createViewAndAllocate ("rho" , pysidre .TypeID .DOUBLE_ID , eltcount )
5859
60+ # Explicitly set values for the "vis" Attribute on the "temp" and "rho" buffers.
61+ temp .setAttributeScalar ("vis" , 1 )
62+ rho .setAttributeScalar ("vis" , 1 )
63+
5964 # The "fields" Group also contains a child Group "ext" which holds a pointer
6065 # to an externally owned integer array. Although Sidre does not own the
6166 # data, the data can still be described to Sidre.
@@ -101,8 +106,48 @@ def access_datastore(ds):
101106
102107 return ds
103108
109+ def iterate_datastore (ds ):
110+ fill_line = "=" * 80
111+ print (fill_line )
112+
113+ # iterate through the attributes in ds
114+ print ("The datastore has the following attributes:" )
115+ for attr in ds .attributes ():
116+ print (f"* [{ attr .getIndex ()} ] '{ attr .getName ()} ' of type "
117+ f"{ attr .getTypeID ()} "
118+
119+ # Requires conduit::Node information
120+ # f"and default value: {attr.getDefaultNodeRef().to_yaml()}\n"
121+ )
122+
123+ # iterate through the buffers in ds
124+ print (fill_line )
125+ print ("The datastore has the following buffers:" )
126+ for buff in ds .buffers ():
127+ print (f"* [{ buff .getIndex ()} ] "
128+ f"{ 'Allocated' if buff .isAllocated () else 'Unallocated' } buffer with "
129+ f"{ buff .getNumElements ()} elements of type { buff .getTypeID ()} with "
130+ f"{ buff .getNumViews ()} views" )
131+ print (fill_line )
132+
133+ # iterate through the groups of the root group
134+ print ("The root group has the following groups:" )
135+ for grp in ds .getRoot ().groups ():
136+ print (f"* [{ grp .getIndex ()} ] '{ grp .getName ()} ' with "
137+ f"{ grp .getNumGroups ()} groups and { grp .getNumViews ()} views" )
138+ print (fill_line )
139+
140+ # iterate through the views of the 'state' group
141+ print ("The 'state' group has the following views:" )
142+ for view in ds .getRoot ().getGroup ("state" ).views ():
143+ print (f"* [{ view .getIndex ()} ] '{ view .getName ()} ' -- "
144+ f"{ 'Allocated' if view .isAllocated () else 'Unallocated' } view of type "
145+ f"{ view .getTypeID ()} and { view .getNumElements ()} elements" )
146+ print (fill_line )
147+
104148
105149if __name__ == "__main__" :
106150 region = np .zeros (3375 , dtype = int )
107151 ds = create_datastore (region )
108152 access_datastore (ds )
153+ iterate_datastore (ds )
0 commit comments