If you cannot use an existing method to specify a property’s value or to modify it, you can
use the following static method to create Value objects:
Value.CreateValue(classTag)
classTag is a string that is a valid class tag.
Be aware that when you create Value objects this way, you must manually
destroy the new objects after use, except for ValueArrayValue values. You can use a helper
class called ValueHolder, which takes a Value object as
constructor parameter, and automatically calls the Value object’s
deleteInstance() method when it is destroyed.
Simple Values
For simple values (bool, str, int, float), use the methods of the
PropertyCollection and Value objects to manipulate their
data. The following example shows how to create simple values using the
PropertyCollection.defineXXXProperty()
methods:
def onProcess(ctxt, dr):
global file
global line
context= pilotpython.Context(ctxt)
data= pilotpython.DataRecord(dr)
props= data.getProperties();
state= pilotpython.DONE_PROCESSING_DATA
line= line[:-1]
frags = line.split(".")
props.defineStringProperty("smiles", line);
props.defineStringArrayProperty("Fragments", frags)
line= file.readline()
if (len(line) != 0):
state= pilotpython.READY_FOR_NEW_DATA;
return state
The following example shows how to modify an existing property’s value:
props= data.getProperties()
myVal= props.get("color").getValue()
myVal.setString("green")
Array Values
You implement data arrays using special subclasses of the Value class.
These subclasses, described below, all support operations to remove, append, count, and
insert elements.
There is an intermediary subclass, ArrayValue, between the
Value class and the type-specific array classes.
ArrayValue is the base class from which the type-specific array classes
are derived.
IntegerArrayValue, BooleanArrayValue, DoubleArrayValue, StringArrayValue
These classes have get()and set() operations that you can
use to quickly get or specify the contents of the entire array.
The get() operation returns a copy of the array's list of data. To update
the array list after modifying the local copy, you must send the modified list back to the
array using the set() method. The following snippet shows the use of
get() and set():
#use get/set to create yet another array value
strArrayList= props.get('python string array').getValue().get()
newSAValue= pilotpython.ValueHolder(pilotpython.Value.CreateValue('SciTegic.value.StringArrayValue'))
newSAValue.val().set(strArrayList)
props.define('yet another string array', newSAValue.val())
The lists passed into the set() methods must be homogeneous and of the
correct data type.
ValueArrayValue
Unlike other value types, ValueArrayValue takes ownership of the values
added to it. Therefore, errors occur if you try to wrap the value to add in a
ValueHolder. Since a ValueArrayValue can handle a
heterogeneous set of data, the set() method is not supported, and you must
append values individually using ValueArrayValue.appendValue().
HashTableValue
The HashTableValue object supports set() and
get() operations (see IntegerArrayValue, BooleanArrayValue,
DoubleArrayValue, StringArrayValue). It also has a
fromDictionary(dict) method that replaces
the existing hash table with the contents of the Python dictionary
dict.
The implementations of the HashTableValue.set() and
HashTableValue.fromDictionary() methods only support basic types. For
example, it is impossible to supply a dictionary whose items are arrays. When dealing with
such data, use the clear() method, followed by
addKeyAndItem() method calls to specify up the instance. The following
example demonstrates creating and populating a HashTableValue:
def appendKeyAndItem(htVal, key, item):
#create key value
keyValHolder= pilotpython.ValueHolder(pilotpython.Value.CreateValue('SciTegic.value.StringValue'))
keyValHolder.val().setString(key)
#create item value
itemValHolder= pilotpython.ValueHolder(pilotpython.Value.CreateValue('SciTegic.value.IntegerArrayValue'))
itemValHolder.val().set(item)
#add to HashTableValue
htVal.addKeyAndItem(keyValHolder.val(), itemValHolder.val())
def createAndFillHashTableValue():
htValHolder= pilotpython.ValueHolder(pilotpython.Value.CreateValue('SciTegic.value.HashTableValue'))
appendKeyAndItem(htValHolder.val(), 'first key', [1,2,3,4])
appendKeyAndItem(htValHolder.val(), 'second key', [5,6,7,8])
appendKeyAndItem(htValHolder.val(), 'third key', [9,10])
return htValHolder
ByteArrayValue
The ByteArrayValue object does not allow write access to individual bytes,
on the assumption that byte arrays are usually BLOBs that are not edited on a per-byte
basis. Therefore, its get() method returns a read-only
memoryview to the data stored in it. Copy this data into a modifiable
buffer to manipulate it.
Likewise, the set() method makes a copy of the data provided, and stores
that copy. The feature was implemented in this way to prevent conflicts of ownership of the
underlying memory.
DateTimeValue
Pipeline Creator supports the following Python classes as input for the DateTimeValue's
get() and set() operations:
datetime.date
datetime.time
datetime.datetime
You can supply an object of one of these classes as input to the
PropertyCollection.defineDateTimeProperty() method to specify a
DateTimeValue.
Pipeline Creator’s DateTimeValue does not support Python’s ability to set or get times in
microseconds. The smallest available time period is the millisecond.
Additional Methods
setFieldUndefined(field): Sets the field
field to not defined.
isFieldDefined(field): Returns a boolean
value specifying whether or not field is defined.
Supported classes
pilotpython.YEAR
pilotpython.MONTH
pilotpython.DAY
pilotpython.HOUR
pilotpython.MINUTE
pilotpython.SECOND
pilotpython.MILLISECOND
Type Mappings Between Python and Pipeline Creator
| Pipeline Creator property value type |
Python type |
Comment |
| SciTegic.value.IntegerValue |
int |
|
| SciTegic.value.DoubleValue |
float |
|
| SciTegic.value.NullValue |
None |
|
| SciTegic.value.StringValue |
str |
|
| SciTegic.value.DateTimeValue |
datetime.time, datetime.date, datetime.datetime |
For conversion from Pipeline Creator to Python, if all time-related fields are valid, the result is a datetime.time
object if all date-related fields are valid, the result is a datetime.date object if
all date- and time-related fields are valid, the result is a datetime.datetime
object |
| SciTegic.value.BooleanValue |
bool |
|
| SciTegic.value.ByteArrayValue |
From Pipeline Creator to Python: read-only memoryview. From Python to Pipeline Creator bytes/bytearray can be used. |
memoryview is used to prevent the copying of binary
data. |
| SciTegic.value.IntegerArrayValue |
list |
Homogeneous list of int |
| SciTegic.value.DoubleArrayValue |
list |
Homogeneous list of float |
| SciTegic.value.NullArrayValue |
list |
Homogeneous list of None |
| SciTegic.value.StringArrayValue |
list |
Homogeneous list of str |
| SciTegic.value.BooleanArrayValue |
list |
Homogeneous list of bool |
| SciTegic.value.ValueArrayValue |
tuple |
By convention, Python lists are homogeneous and tuples are meant for
heterogeneous collections. Exception: a ValueArrayValue consisting
of only DateTimeValue instances is converted to a list. |