From: Jérémie Galarneau Date: Fri, 22 Nov 2013 05:02:33 +0000 (-0500) Subject: Python-bindings: Refactor the CTFWriter API X-Git-Tag: v1.2.0-rc1~42 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=140012777ec3bdfa257600915f55c8aa274c8140;ds=sidebyside Python-bindings: Refactor the CTFWriter API Refactor the CTFWriter API to be more in line with the reader modifications. Signed-off-by: Jérémie Galarneau --- diff --git a/bindings/python/babeltrace.i.in b/bindings/python/babeltrace.i.in index df739c9c..aaa400aa 100644 --- a/bindings/python/babeltrace.i.in +++ b/bindings/python/babeltrace.i.in @@ -1387,68 +1387,126 @@ class CTFWriter: def __del__(self): _bt_ctf_clock_put(self._c) + """ + Get the clock's description. + """ + @property + def description(self): + raise NotImplementedError("Getter not implemented.") + """ Set the clock's description. The description appears in the clock's TSDL meta-data. """ - def set_description(self, desc): - ret = _bt_ctf_clock_set_description(self._c, desc) + @description.setter + def description(self, desc): + ret = _bt_ctf_clock_set_description(self._c, str(desc)) if ret < 0: raise ValueError("Invalid clock description.") + """ + Get the clock's frequency (Hz). + """ + @property + def frequency(self): + raise NotImplementedError("Getter not implemented.") + """ Set the clock's frequency (Hz). """ - def set_frequency(self, freq): + @frequency.setter + def frequency(self, freq): ret = _bt_ctf_clock_set_frequency(self._c, freq) if ret < 0: raise ValueError("Invalid frequency value.") + """ + Get the clock's precision (in clock ticks). + """ + @property + def precision(self): + raise NotImplementedError("Getter not implemented.") + """ Set the clock's precision (in clock ticks). """ - def set_precision(self, precision): + @precision.setter + def precision(self, precision): ret = _bt_ctf_clock_set_precision(self._c, precision) + """ + Get the clock's offset in seconds from POSIX.1 Epoch. + """ + @property + def offset_seconds(self): + raise NotImplementedError("Getter not implemented.") + """ Set the clock's offset in seconds from POSIX.1 Epoch. """ - def set_offset_seconds(self, offset_s): + @offset_seconds.setter + def offset_seconds(self, offset_s): ret = _bt_ctf_clock_set_offset_s(self._c, offset_s) if ret < 0: raise ValueError("Invalid offset value.") + """ + Get the clock's offset in ticks from POSIX.1 Epoch + offset in seconds. + """ + @property + def offset(self): + raise NotImplementedError("Getter not implemented.") + """ Set the clock's offset in ticks from POSIX.1 Epoch + offset in seconds. """ - def set_offset_seconds(self, offset): + @offset.setter + def offset(self, offset): ret = _bt_ctf_clock_set_offset(self._c, offset) if ret < 0: raise ValueError("Invalid offset value.") + """ + Get a clock's absolute attribute. A clock is absolute if the clock + is a global reference across the trace's other clocks. + """ + @property + def absolute(self): + raise NotImplementedError("Getter not implemented.") + """ Set a clock's absolute attribute. A clock is absolute if the clock is a global reference across the trace's other clocks. """ - def set_is_absolute(self, is_absolute): - ret = _bt_ctf_clock_set_is_absolute(self._c, is_absolute) + @absolute.setter + def absolute(self, is_absolute): + ret = _bt_ctf_clock_set_is_absolute(self._c, int(is_absolute)) if ret < 0: raise ValueError("Could not set the clock's absolute attribute.") + """ + Get the current time in nanoseconds since the clock's origin (offset and + offset_s attributes). + """ + @property + def time(self): + raise NotImplementedError("Getter not implemented.") + """ Set the current time in nanoseconds since the clock's origin (offset and offset_s attributes). The clock's value will be sampled as events are appended to a stream. """ - def set_time(self, time): + @time.setter + def time(self, time): ret = _bt_ctf_clock_set_time(self._c, time) if ret < 0: raise ValueError("Invalid time value.") - class FieldType: + class FieldDeclaration: """ - FieldType should not be instantiated directly. Please instantiate - one of the concrete FieldType classes. + FieldDeclaration should not be instantiated directly. Please instantiate + one of the concrete FieldDeclaration classes. """ class IntegerBase: # These values are based on the bt_ctf_integer_base enum @@ -1461,31 +1519,47 @@ class CTFWriter: def __init__(self): if self._ft is None: - raise ValueError("FieldType creation failed.") + raise ValueError("FieldDeclaration creation failed.") def __del__(self): _bt_ctf_field_type_put(self._ft) + """ + Get the field type's alignment. + """ + @property + def alignment(self): + raise NotImplementedError("Getter not implemented.") + """ Set the field type's alignment. Defaults to 1 (bit-aligned). However, some types, such as structures and string, may impose other alignment constraints. """ - def set_alignment(self, alignment): + @alignment.setter + def alignment(self, alignment): ret = _bt_ctf_field_type_set_alignment(self._ft, alignment) if ret < 0: raise ValueError("Invalid alignment value.") + """ + Get the field type's byte order. One of the ByteOrder's constant. + """ + @property + def byte_order(self): + raise NotImplementedError("Getter not implemented.") + """ Set the field type's byte order. Use constants defined in the ByteOrder class. """ - def set_byte_order(self, byte_order): + @byte_order.setter + def byte_order(self, byte_order): ret = _bt_ctf_field_type_set_byte_order(self._ft, byte_order) if ret < 0: raise ValueError("Could not set byte order value.") - class FieldTypeInteger(FieldType): + class IntegerFieldDeclaration(FieldDeclaration): """ Create a new integer field type of the given size. """ @@ -1494,37 +1568,62 @@ class CTFWriter: super().__init__() """ - Set an integer type's signedness attribute. + Get an integer's signedness attribute. + """ + @property + def signed(self): + raise NotImplementedError("Getter not implemented.") + + """ + Set an integer's signedness attribute. """ - def set_signed(self, signed): + @signed.setter + def signed(self, signed): ret = _bt_ctf_field_type_integer_set_signed(self._ft, signed) if ret < 0: raise ValueError("Could not set signed attribute.") """ - Set the integer type's base used to pretty-print the resulting trace. + Get the integer's base used to pretty-print the resulting trace. + """ + @property + def base(self): + raise NotImplementedError("Getter not implemented.") + + """ + Set the integer's base used to pretty-print the resulting trace. The base must be a constant of the IntegerBase class. """ - def set_base(self, base): + @base.setter + def base(self, base): ret = _bt_ctf_field_type_integer_set_base(self._ft, base) if ret < 0: raise ValueError("Could not set base value.") + """ + Get the integer's encoding (one of the constants of the + CTFStringEncoding class). + """ + @property + def encoding(self): + raise NotImplementedError("Getter not implemented.") + """ An integer encoding may be set to signal that the integer must be printed as a text character. Must be a constant from the CTFStringEncoding class. """ - def set_encoding(self, encoding): + @encoding.setter + def encoding(self, encoding): ret = _bt_ctf_field_type_integer_set_encoding(self._ft, encoding) if ret < 0: raise ValueError("Could not set integer encoding.") - class FieldTypeEnumeration(FieldType): + class EnumerationFieldDeclaration(FieldDeclaration): """ Create a new enumeration field type with the given underlying type. """ def __init__(self, integer_type): - if integer_type is None or not isinstance(integer_type, CTFWriter.FieldTypeInteger): + if integer_type is None or not isinstance(integer_type, CTFWriter.IntegerFieldDeclaration): raise TypeError("Invalid integer container.") self._ft = _bt_ctf_field_type_enumeration_create(integer_type._ft) @@ -1534,11 +1633,11 @@ class CTFWriter: Add a mapping to the enumeration. The range's values are inclusive. """ def add_mapping(self, name, range_start, range_end): - ret = _bt_ctf_field_type_enumeration_add_mapping(self._ft, name, range_start, range_end) + ret = _bt_ctf_field_type_enumeration_add_mapping(self._ft, str(name), range_start, range_end) if ret < 0: raise ValueError("Could not add mapping to enumeration type.") - class FieldTypeFloatingPoint(FieldType): + class FloatFieldDeclaration(FieldDeclaration): FLT_EXP_DIG = 8 DBL_EXP_DIG = 11 FLT_MANT_DIG = 24 @@ -1552,26 +1651,42 @@ class CTFWriter: super().__init__() """ - Set the number of exponent digits to use to store the floatingpoint field. + Get the number of exponent digits to use to store the floating point field. + """ + @property + def exponent_digits(self): + raise NotImplementedError("Getter not implemented.") + + """ + Set the number of exponent digits to use to store the floating point field. The only values currently supported are FLT_EXP_DIG and DBL_EXP_DIG which are defined as constants of this class. """ - def set_exponent_digits(self, exponent_digits): + @exponent_digits.setter + def exponent_digits(self, exponent_digits): ret = _bt_ctf_field_type_floating_point_set_exponent_digits(self._ft, exponent_digits) if ret < 0: raise ValueError("Could not set exponent digit count.") """ - Set the numberof mantissa digits to use to store the floatingpoint field. + Get the number of mantissa digits to use to store the floating point field. + """ + @property + def mantissa_digits(self): + raise NotImplementedError("Getter not implemented.") + + """ + Set the number of mantissa digits to use to store the floating point field. The only values currently supported are FLT_MANT_DIG and DBL_MANT_DIG which are defined as constants of this class. """ - def set_mantissa_digits(self, mantissa_digits): + @mantissa_digits.setter + def mantissa_digits(self, mantissa_digits): ret = _bt_ctf_field_type_floating_point_set_mantissa_digits(self._ft, mantissa_digits) if ret < 0: raise ValueError("Could not set mantissa digit count.") - class FieldTypeStructure(FieldType): + class StructureFieldDeclaration(FieldDeclaration): """ Create a new structure field type. """ @@ -1583,30 +1698,30 @@ class CTFWriter: Add a field of type "field_type" to the structure. """ def add_field(self, field_type, field_name): - ret = _bt_ctf_field_type_structure_add_field(self._ft, field_type._ft, field_name) + ret = _bt_ctf_field_type_structure_add_field(self._ft, field_type._ft, str(field_name)) if ret < 0: raise ValueError("Could not add field to structure.") - class FieldTypeVariant(FieldType): + class VariantFieldDeclaration(FieldDeclaration): """ Create a new variant field type. """ def __init__(self, enum_tag, tag_name): - if enum_tag is None or not isinstance(enum_tag, CTFWriter.FieldTypeEnumeration): - raise TypeError("Invalid tag type; must be of type FieldTypeEnumeration.") + if enum_tag is None or not isinstance(enum_tag, CTFWriter.EnumerationFieldDeclaration): + raise TypeError("Invalid tag type; must be of type EnumerationFieldDeclaration.") - self._ft = _bt_ctf_field_type_variant_create(enum_tag._ft, tag_name) + self._ft = _bt_ctf_field_type_variant_create(enum_tag._ft, str(tag_name)) super().__init__() """ Add a field of type "field_type" to the variant. """ def add_field(self, field_type, field_name): - ret = _bt_ctf_field_type_variant_add_field(self._ft, field_type._ft, field_name) + ret = _bt_ctf_field_type_variant_add_field(self._ft, field_type._ft, str(field_name)) if ret < 0: raise ValueError("Could not add field to variant.") - class FieldTypeArray(FieldType): + class ArrayFieldDeclaration(FieldDeclaration): """ Create a new array field type. """ @@ -1614,15 +1729,15 @@ class CTFWriter: self._ft = _bt_ctf_field_type_array_create(element_type._ft, length) super().__init__() - class FieldTypeSequence(FieldType): + class SequenceFieldDeclaration(FieldDeclaration): """ Create a new sequence field type. """ def __init__(self, element_type, length_field_name): - self._ft = _bt_ctf_field_type_sequence_create(element_type._ft, length_field_name) + self._ft = _bt_ctf_field_type_sequence_create(element_type._ft, str(length_field_name)) super().__init__() - class FieldTypeString(FieldType): + class StringFieldDeclaration(FieldDeclaration): """ Create a new string field type. """ @@ -1630,10 +1745,18 @@ class CTFWriter: self._ft = _bt_ctf_field_type_string_create() super().__init__() + """ + Get a string type's encoding (a constant from the CTFStringEncoding class). + """ + @property + def encoding(self): + raise NotImplementedError("Getter not implemented.") + """ Set a string type's encoding. Must be a constant from the CTFStringEncoding class. """ - def set_encoding(self, encoding): + @encoding.setter + def encoding(self, encoding): ret = _bt_ctf_field_type_string_set_encoding(self._ft, encoding) if ret < 0: raise ValueError("Could not set string encoding.") @@ -1643,32 +1766,32 @@ class CTFWriter: """ @staticmethod def create_field(self, field_type): - if field_type is None or not isinstance(field_type, CTFWriter.FieldType): - raise TypeError("Invalid field_type. Type must be a FieldType-derived class.") - - if isinstance(field_type, CTFWriter.FieldTypeInteger): - return CTFWriter.FieldInteger(field_type) - elif isinstance(field_type, CTFWriter.FieldTypeEnumeration): - return CTFWriter.FieldEnumeration(field_type) - elif isinstance(field_type, CTFWriter.FieldTypeFloatingPoint): - return CTFWriter.FieldFloatingPoint(field_type) - elif isinstance(field_type, CTFWriter.FieldTypeStructure): - return CTFWriter.FieldStructure(field_type) - elif isinstance(field_type, CTFWriter.FieldTypeVariant): - return CTFWriter.FieldVariant(field_type) - elif isinstance(field_type, CTFWriter.FieldTypeArray): - return CTFWriter.FieldArray(field_type) - elif isinstance(field_type, CTFWriter.FieldTypeSequence): - return CTFWriter.FieldSequence(field_type) - elif isinstance(field_type, CTFWriter.FieldTypeString): - return CTFWriter.FieldString(field_type) + if field_type is None or not isinstance(field_type, CTFWriter.FieldDeclaration): + raise TypeError("Invalid field_type. Type must be a FieldDeclaration-derived class.") + + if isinstance(field_type, CTFWriter.IntegerFieldDeclaration): + return CTFWriter.IntegerField(field_type) + elif isinstance(field_type, CTFWriter.EnumerationFieldDeclaration): + return CTFWriter.EnumerationField(field_type) + elif isinstance(field_type, CTFWriter.FloatFieldDeclaration): + return CTFWriter.FloatFieldingPoint(field_type) + elif isinstance(field_type, CTFWriter.StructureFieldDeclaration): + return CTFWriter.StructureField(field_type) + elif isinstance(field_type, CTFWriter.VariantFieldDeclaration): + return CTFWriter.VariantField(field_type) + elif isinstance(field_type, CTFWriter.ArrayFieldDeclaration): + return CTFWriter.ArrayField(field_type) + elif isinstance(field_type, CTFWriter.SequenceFieldDeclaration): + return CTFWriter.SequenceField(field_type) + elif isinstance(field_type, CTFWriter.StringFieldDeclaration): + return CTFWriter.StringField(field_type) class Field: """ Base class, do not instantiate. """ def __init__(self, field_type): - if not isinstance(field_type, CTFWriter.FieldType): + if not isinstance(field_type, CTFWriter.FieldDeclaration): raise TypeError("Invalid field_type argument.") self._f = _bt_ctf_field_create(field_type._ft) @@ -1681,14 +1804,14 @@ class CTFWriter: @staticmethod def _create_field_from_native_instance(native_field_instance): type_dict = { - CTFTypeId.INTEGER : CTFWriter.FieldInteger, - CTFTypeId.FLOAT : CTFWriter.FieldFloatingPoint, - CTFTypeId.ENUM : CTFWriter.FieldEnumeration, - CTFTypeId.STRING : CTFWriter.FieldString, - CTFTypeId.STRUCT : CTFWriter.FieldStructure, - CTFTypeId.VARIANT : CTFWriter.FieldVariant, - CTFTypeId.ARRAY : CTFWriter.FieldArray, - CTFTypeId.SEQUENCE : CTFWriter.FieldSequence + CTFTypeId.INTEGER : CTFWriter.IntegerField, + CTFTypeId.FLOAT : CTFWriter.FloatFieldingPoint, + CTFTypeId.ENUM : CTFWriter.EnumerationField, + CTFTypeId.STRING : CTFWriter.StringField, + CTFTypeId.STRUCT : CTFWriter.StructureField, + CTFTypeId.VARIANT : CTFWriter.VariantField, + CTFTypeId.ARRAY : CTFWriter.ArrayField, + CTFTypeId.SEQUENCE : CTFWriter.SequenceField } field_type = _bt_python_get_field_type(native_field_instance) @@ -1700,11 +1823,19 @@ class CTFWriter: field.__class__ = type_dict[field_type] return field - class FieldInteger(Field): + class IntegerField(Field): + """ + Get an integer field's value. + """ + @property + def value(self): + raise NotImplementedError("Getter not implemented.") + """ Set an integer field's value. """ - def set_value(self, value): + @value.setter + def value(self, value): signedness = _bt_python_field_integer_get_signedness(self._f) if signedness < 0: raise TypeError("Invalid integer instance.") @@ -1717,62 +1848,79 @@ class CTFWriter: if ret < 0: raise ValueError("Could not set integer field value.") - class FieldEnumeration(Field): + class EnumerationField(Field): """ Return the enumeration's underlying container field (an integer field). """ - def get_container(self): - container = CTFWriter.FieldInteger.__new__(CTFWriter.FieldInteger) + @property + def container(self): + container = CTFWriter.IntegerField.__new__(CTFWriter.IntegerField) container._f = _bt_ctf_field_enumeration_get_container(self._f) if container._f is None: raise TypeError("Invalid enumeration field type.") return container - class FieldFloatingPoint(Field): + class FloatFieldingPoint(Field): + """ + Get a floating point field's value. + """ + @property + def value(self): + raise NotImplementedError("Getter not implemented.") + """ Set a floating point field's value. """ - def set_value(self, value): - ret = _bt_ctf_field_floating_point_set_value(self._f, value) + @value.setter + def value(self, value): + ret = _bt_ctf_field_floating_point_set_value(self._f, float(value)) if ret < 0: raise ValueError("Could not set floating point field value.") - class FieldStructure(Field): + class StructureField(Field): """ Get the structure's field corresponding to the provided field name. """ - def get_field(self, field_name): - native_instance = _bt_ctf_field_structure_get_field(self._f, field_name) + def field(self, field_name): + native_instance = _bt_ctf_field_structure_get_field(self._f, str(field_name)) if native_instance is None: raise ValueError("Invalid field_name provided.") return CTFWriter.Field._create_field_from_native_instance(native_instance) - class FieldVariant(Field): + class VariantField(Field): """ Return the variant's selected field. The "tag" field is the selector enum field. """ - def get_field(self, tag): + def field(self, tag): native_instance = _bt_ctf_field_variant_get_field(self._f, tag._f) if native_instance is None: raise ValueError("Invalid tag provided.") return CTFWriter.Field._create_field_from_native_instance(native_instance) - class FieldArray(Field): + class ArrayField(Field): """ Return the array's field at position "index". """ - def get_field(self, index): + def field(self, index): native_instance = _bt_ctf_field_array_get_field(self._f, index) if native_instance is None: raise IndexError("Invalid index provided.") return CTFWriter.Field._create_field_from_native_instance(native_instance) - class FieldSequence(Field): + class SequenceField(Field): + """ + Get the sequence's length field (IntegerField). + """ + @property + def length(self): + raise NotImplementedError("Getter not implemented.") + """ Set the sequence's length field (IntegerField). """ - def set_length(self, length): - if not isinstance(length, CTFWriter.FieldInteger): + @length.setter + def length(self, length_field): + if not isinstance(length, CTFWriter.IntegerField): raise TypeError("Invalid length field.") ret = _bt_ctf_field_sequence_set_length(self._f, length._f) if ret < 0: @@ -1781,18 +1929,26 @@ class CTFWriter: """ Return the sequence's field at position "index". """ - def get_field(self, index): + def field(self, index): native_instance = _bt_ctf_field_sequence_get_field(self._f, index) if native_instance is None: raise ValueError("Could not get sequence element at index.") return CTFWriter.Field._create_field_from_native_instance(native_instance) - class FieldString(Field): + class StringField(Field): + """ + Get a string field's value. + """ + @property + def value(self): + raise NotImplementedError("Getter not implemented.") + """ Set a string field's value. """ - def set_value(self, value): - ret = _bt_ctf_field_string_set_value(self._f, value) + @value.setter + def value(self, value): + ret = _bt_ctf_field_string_set_value(self._f, str(value)) if ret < 0: raise ValueError("Could not set string field value.") @@ -1812,7 +1968,7 @@ class CTFWriter: Add a field of type "field_type" to the event class. """ def add_field(self, field_type, field_name): - ret = _bt_ctf_event_class_add_field(self._ec, field_type._ft, field_name) + ret = _bt_ctf_event_class_add_field(self._ec, field_type._ft, str(field_name)) if ret < 0: raise ValueError("Could not add field to event class.") @@ -1834,18 +1990,18 @@ class CTFWriter: """ Set a manually created field as an event's payload. """ - def set_payload(self, field_name, value): + def set_payload(self, field_name, value_field): if not isinstance(value, CTFWriter.Field): raise TypeError("Invalid value type.") - ret = _bt_ctf_event_set_payload(self._e, field_name, value._f) + ret = _bt_ctf_event_set_payload(self._e, str(field_name), value._f) if ret < 0: raise ValueError("Could not set event field payload.") """ - Set a manually created field as an event's payload. + Get a field from event. """ - def get_payload(self, field_name): - native_instance = _bt_ctf_event_get_payload(self._e, field_name) + def payload(self, field_name): + native_instance = _bt_ctf_event_get_payload(self._e, str(field_name)) if native_instance is None: raise ValueError("Could not get event payload.") return CTFWriter.Field._create_field_from_native_instance(native_instance) @@ -1862,10 +2018,18 @@ class CTFWriter: def __del__(self): _bt_ctf_stream_class_put(self._sc) + """ + Get a stream class' clock. + """ + @property + def clock(self): + raise NotImplementedError("Getter not implemented.") + """ Assign a clock to a stream class. """ - def set_clock(self, clock): + @clock.setter + def clock(self, clock): if not isinstance(clock, CTFWriter.Clock): raise TypeError("Invalid clock type.") @@ -1875,7 +2039,7 @@ class CTFWriter: """ Add an event class to a stream class. New events can be added even after a - stream has beem instanciated and events have been appended. However, a stream + stream has been instantiated and events have been appended. However, a stream will not accept events of a class that has not been registered beforehand. """ def add_event_class(self, event_class): @@ -1955,7 +2119,7 @@ class CTFWriter: Add an environment field to the trace. """ def add_environment_field(self, name, value): - ret = _bt_ctf_writer_add_environment_field(self._w, name, value) + ret = _bt_ctf_writer_add_environment_field(self._w, str(name), str(value)) if ret < 0: raise ValueError("Could not add environment field to trace.") @@ -1971,7 +2135,8 @@ class CTFWriter: """ Get the trace's TSDL meta-data. """ - def get_metadata(self): + @property + def metadata(self): return _bt_ctf_writer_get_metadata_string(self._w) """ @@ -1980,11 +2145,20 @@ class CTFWriter: def flush_metadata(self): _bt_ctf_writer_flush_metadata(self._w) + """ + Get the trace's byte order. Must be a constant from the ByteOrder + class. + """ + @property + def byte_order(self): + raise NotImplementedError("Getter not implemented.") + """ Set the trace's byte order. Must be a constant from the ByteOrder class. Defaults to BYTE_ORDER_NATIVE, the host machine's endianness. """ - def set_byte_order(self, byte_order): + @byte_order.setter + def byte_order(self, byte_order): ret = _bt_ctf_writer_set_byte_order(self._w, byte_order) if ret < 0: raise ValueError("Could not set trace's byte order.") diff --git a/bindings/python/examples/ctf_writer.py b/bindings/python/examples/ctf_writer.py index 50819504..e3d48fc1 100644 --- a/bindings/python/examples/ctf_writer.py +++ b/bindings/python/examples/ctf_writer.py @@ -27,45 +27,45 @@ print("Writing trace at {}".format(trace_path)) writer = CTFWriter.Writer(trace_path) clock = CTFWriter.Clock("A_clock") -clock.set_description("Simple clock") +clock.description = "Simple clock" writer.add_clock(clock) writer.add_environment_field("Python_version", str(sys.version_info)) stream_class = CTFWriter.StreamClass("test_stream") -stream_class.set_clock(clock) +stream_class.clock = clock event_class = CTFWriter.EventClass("SimpleEvent") # Create a int32_t equivalent type -int32_type = CTFWriter.FieldTypeInteger(32) -int32_type.set_signed(True) +int32_type = CTFWriter.IntegerFieldDeclaration(32) +int32_type.signed = True # Create a string type -string_type = CTFWriter.FieldTypeString() +string_type = CTFWriter.StringFieldDeclaration() # Create a structure type containing both an integer and a string -structure_type = CTFWriter.FieldTypeStructure() +structure_type = CTFWriter.StructureFieldDeclaration() structure_type.add_field(int32_type, "an_integer") structure_type.add_field(string_type, "a_string_field") event_class.add_field(structure_type, "structure_field") # Create a floating point type -floating_point_type = CTFWriter.FieldTypeFloatingPoint() -floating_point_type.set_exponent_digits(CTFWriter.FieldTypeFloatingPoint.FLT_EXP_DIG) -floating_point_type.set_mantissa_digits(CTFWriter.FieldTypeFloatingPoint.FLT_MANT_DIG) +floating_point_type = CTFWriter.FloatFieldDeclaration() +floating_point_type.exponent_digits = CTFWriter.FloatFieldDeclaration.FLT_EXP_DIG +floating_point_type.mantissa_digits = CTFWriter.FloatFieldDeclaration.FLT_MANT_DIG event_class.add_field(floating_point_type, "float_field") # Create an enumeration type -int10_type = CTFWriter.FieldTypeInteger(10) -enumeration_type = CTFWriter.FieldTypeEnumeration(int10_type) +int10_type = CTFWriter.IntegerFieldDeclaration(10) +enumeration_type = CTFWriter.EnumerationFieldDeclaration(int10_type) enumeration_type.add_mapping("FIRST_ENTRY", 0, 4) enumeration_type.add_mapping("SECOND_ENTRY", 5, 5) enumeration_type.add_mapping("THIRD_ENTRY", 6, 10) event_class.add_field(enumeration_type, "enum_field") # Create an array type -array_type = CTFWriter.FieldTypeArray(int10_type, 5) +array_type = CTFWriter.ArrayFieldDeclaration(int10_type, 5) event_class.add_field(array_type, "array_field") stream_class.add_event_class(event_class) @@ -74,24 +74,25 @@ stream = writer.create_stream(stream_class) for i in range(100): event = CTFWriter.Event(event_class) - structure_field = event.get_payload("structure_field") - integer_field = structure_field.get_field("an_integer") - integer_field.set_value(i) + clock.time = i * 1000 + structure_field = event.payload("structure_field") + integer_field = structure_field.field("an_integer") + integer_field.value = i - string_field = structure_field.get_field("a_string_field") - string_field.set_value("Test string.") + string_field = structure_field.field("a_string_field") + string_field.value = "Test string." - float_field = event.get_payload("float_field") - float_field.set_value(float(i) + (float(i) / 100.0)) + float_field = event.payload("float_field") + float_field.value = float(i) + (float(i) / 100.0) - array_field = event.get_payload("array_field") + array_field = event.payload("array_field") for j in range(5): - element = array_field.get_field(j) - element.set_value(i+j) + element = array_field.field(j) + element.value = i + j - enumeration_field = event.get_payload("enum_field") - integer_field = enumeration_field.get_container() - integer_field.set_value(i % 10) + enumeration_field = event.payload("enum_field") + integer_field = enumeration_field.container + integer_field.value = i % 10 stream.append_event(event)