Skip to content

Commit

Permalink
[RNTuple] Update to Sep 2024 (#347)
Browse files Browse the repository at this point in the history
* update RNTuple Sep-2024

* add minimal RNTuple

* sync some bytes

* finish fixing
  • Loading branch information
Moelf authored Sep 26, 2024
1 parent fa0a5e3 commit 8a28452
Show file tree
Hide file tree
Showing 21 changed files with 221 additions and 260 deletions.
87 changes: 44 additions & 43 deletions src/RNTuple/Writing/Stubs.jl
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
module Stubs
using ..UnROOT

const WRITE_TIME = 0x7670F8CD

const file_preamble = [
0x72, 0x6F, 0x6F, 0x74, 0x00, 0x00, 0xF7, 0x45,
]

const fileheader = UnROOT.FileHeader32(100, 0x00000643, 0x00000604, 63, 1, 84, 0x04, 0, 0x00000461, 419, UInt8[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
const fileheader = UnROOT.FileHeader32(100, 0x00000638, 0x000005F9, 63, 1, 84, 0x04, 0, 0x00000465, 0x00000194, UInt8[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
const dummy_padding1 = [
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00,
]

const tkey32_tfile = UnROOT.TKey32(144, 4, 86, 0x7567176d, 58, 1, 100, 0, "TFile", "test_ntuple_minimal.root", "")
const tkey32_tfile = UnROOT.TKey32(144, 4, 86, WRITE_TIME, 58, 1, 100, 0, "TFile", "test_ntuple_minimal.root", "")
const tfile = UnROOT.TFile_write("test_ntuple_minimal.root", "")
const tdirectory32 = UnROOT.ROOTDirectoryHeader32(5, 0x7567176d, 0x7567176d, 121, 84, 100, 0, 1000)
const tdirectory32 = UnROOT.ROOTDirectoryHeader32(5, WRITE_TIME, WRITE_TIME, 121, 84, 100, 0, 0x000003ec)
const dummy_padding2 = [
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
]


const RBlob1 = UnROOT.RBlob(0x00DC, 0x0004, 0x000000BA, 0x7567176D, 0x0022, 0x0001, 244, 100, "RBlob", "", "")
const RBlob1 = UnROOT.RBlob(0x00DC, 0x0004, 0x000000BA, WRITE_TIME, 0x0022, 0x0001, 244, 100, "RBlob", "", "")
const rnt_header = UnROOT.RNTupleHeader(zero(UInt64), "myntuple", "", "ROOT v6.33.01", [
UnROOT.FieldRecord(zero(UInt32), zero(UInt32), zero(UInt32), zero(UInt16), zero(UInt16), 0, "one_uint", "std::uint32_t", "", ""),
], [UnROOT.ColumnRecord(0x14, 0x20, zero(UInt32), zero(UInt32), 0),], UnROOT.AliasRecord[], UnROOT.ExtraTypeInfo[])
UnROOT.FieldRecord(zero(UInt32), zero(UInt32), zero(UInt32), zero(UInt16), zero(UInt16), 0, -1, -1, "one_uint", "std::uint32_t", "", ""),
], [UnROOT.ColumnRecord(0x14, 0x20, zero(UInt32), 0x00, 0x00, 0),], UnROOT.AliasRecord[], UnROOT.ExtraTypeInfo[])


const RBlob2 = UnROOT.RBlob(0x0026, 0x0004, 0x00000004, 0x7567176D, 0x0022, 0x0001, 0x01D0, 100, "RBlob", "", "")
const RBlob2 = UnROOT.RBlob(0x002e, 0x0004, 0x00000004, WRITE_TIME, 0x0022, 0x0001, 0x01D0, 100, "RBlob", "", "")
const page1 = [
0xCE, 0xCE, 0xCE, 0xCE,
]

const RBlob3 = UnROOT.RBlob(0x009E, 0x0004, 0x0000007C, 0x7567176D, 0x0022, 0x0001, 0x01F6, 100, "RBlob", "", "")
const RBlob3 = UnROOT.RBlob(0x009E, 0x0004, 0x0000007C, WRITE_TIME, 0x0022, 0x0001, 0x01FE, 100, "RBlob", "", "")
const cluster_summary = UnROOT.Write_RNTupleListFrame([UnROOT.ClusterSummary(0, 1)])
const nested_page_locations =
UnROOT.RNTuplePageTopList([
Expand All @@ -44,54 +46,53 @@ UnROOT.RNTuplePageTopList([
])
const pagelink = UnROOT.PageLink(0x3dec59c009c67e28, cluster_summary.payload, nested_page_locations)

const RBlob4 = UnROOT.RBlob(0x00CE, 0x0004, 0x000000AC, 0x7567176D, 0x0022, 0x0001, 0x0294, 100, "RBlob", "", "")
const RBlob4 = UnROOT.RBlob(0x00C2, 0x0004, 0x000000A0, WRITE_TIME, 0x0022, 0x0001, 0x029c, 100, "RBlob", "", "")
const rnt_footer = UnROOT.RNTupleFooter(0, 0x3dec59c009c67e28, UnROOT.RNTupleSchemaExtension([], [], [], []), [], [
UnROOT.ClusterGroupRecord(0, 1, 1, UnROOT.EnvLink(0x000000000000007c, UnROOT.Locator(124, 0x0000000000000218, ))),
], UnROOT.EnvLink[])
const tkey32_anchor = UnROOT.TKey32(134, 4, 70, 0x7567176d, 64, 1, 866, 100, "ROOT::Experimental::RNTuple", "myntuple", "")
UnROOT.ClusterGroupRecord(0, 1, 1, UnROOT.EnvLink(0x000000000000007c, UnROOT.Locator(124, 0x0000000000000220, ))),
])
const tkey32_anchor = UnROOT.TKey32(134, 4, 70, WRITE_TIME, 64, 1, 866, 100, "ROOT::Experimental::RNTuple", "myntuple", "")
# these 6 bytes are between tkey32_anchor and the actual anchor
const magic_6bytes = [0x40, 0x00, 0x00, 0x42, 0x00, 0x04]
const magic_6bytes = [0x40, 0x00, 0x00, 0x42, 0x00, 0x06]

const rnt_anchor = UnROOT.ROOT_3a3a_Experimental_3a3a_RNTuple(0x0000, 0x0002, 0x0000, 0x0000, 0x0000000000000116, 0x00000000000000ba, 0x00000000000000ba, 0x00000000000002b6, 0x00000000000000ac, 0x00000000000000ac, 0xdc495fd01479af1b)
const tkey32_TDirectory = UnROOT.TKey32(121, 4, 68, 0x7567176d, 53, 1, 1000, 100, "", "test_ntuple_minimal.root", "")
const rnt_anchor = UnROOT.ROOT_3a3a_Experimental_3a3a_RNTuple(0x0000, 0x0002, 0x0000, 0x0000, 0x0000000000000116, 0x00000000000000ba, 0x00000000000000ba, 0x00000000000002be, 0x00000000000000a0, 0x00000000000000a0, 0x0000000040000000, 0xdc495fd01479af1b)
const tkey32_TDirectory = UnROOT.TKey32(121, 4, 68, WRITE_TIME, 53, 1, 0x000003ec, 100, "", "test_ntuple_minimal.root", "")
# 1 key, and it is the RNTuple Anchor
const n_keys = [
0x00, 0x00, 0x00, 0x01,
]


const tkey32_TStreamerInfo = UnROOT.TKey32(419, 4, 1266, 0x7567176d, 64, 1, 1121, 100, "TList", "StreamerInfo", "Doubly linked list")
const tkey32_TStreamerInfo = UnROOT.TKey32(0x00000194, 4, 0x000004f4, WRITE_TIME, 64, 1, 0x00000465, 100, "TList", "StreamerInfo", "Doubly linked list")

const tsreamerinfo_compressed = [
0x5A, 0x4C, 0x08, 0x5A, 0x01, 0x00, 0xF2, 0x04, 0x00, 0x78, 0x01, 0xBD, 0x92, 0x4D, 0x4E, 0xC2,
0x40, 0x1C, 0xC5, 0x1F, 0x05, 0x13, 0x91, 0x8F, 0xAD, 0x1A, 0x36, 0x6E, 0xBD, 0x42, 0x57, 0x15,
0x83, 0x91, 0x44, 0x29, 0x42, 0xC5, 0x68, 0x82, 0x66, 0x80, 0x29, 0x94, 0x8F, 0x99, 0x66, 0xDA,
0x26, 0xB2, 0x63, 0xE7, 0x69, 0xBC, 0x84, 0x97, 0xD0, 0x53, 0x78, 0x05, 0xFD, 0x77, 0x24, 0x04,
0x12, 0x89, 0x68, 0x83, 0x2F, 0x99, 0x69, 0x3B, 0xED, 0xBC, 0x5F, 0xFB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16, 0x20, 0xC6,
0x13, 0x53, 0x6E, 0x60, 0xF0, 0xCC, 0xFE, 0xCE, 0xFA, 0xCB, 0x52, 0x14, 0x52, 0x90, 0x06, 0x72,
0x37, 0x85, 0x34, 0x12, 0x48, 0x2D, 0x81, 0xEC, 0xCF, 0x7F, 0xC7, 0xAE, 0x7B, 0x41, 0x32, 0x0D,
0x61, 0x45, 0xA5, 0x4E, 0x94, 0x0A, 0xD7, 0xAE, 0x54, 0x1A, 0xC8, 0x6A, 0x4A, 0xA5, 0x21, 0xAC,
0xA0, 0x54, 0x45, 0x8C, 0xCE, 0x29, 0xB2, 0xBD, 0x27, 0x02, 0xC7, 0x2F, 0xFF, 0x29, 0x7C, 0x01,
0xAA, 0xFB, 0xC2, 0x3F,
]

const tfile_end = [
0x00, 0x00, 0x00, 0x3F, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0A, 0x75, 0x67, 0x17, 0x6D, 0x00, 0x35,
0x00, 0x01, 0x00, 0x00, 0x06, 0x04, 0x00, 0x00, 0x00, 0x64, 0x00, 0x18, 0x74, 0x65, 0x73, 0x74,
0x5F, 0x6E, 0x74, 0x75, 0x70, 0x6C, 0x65, 0x5F, 0x6D, 0x69, 0x6E, 0x69, 0x6D, 0x61, 0x6C, 0x2E,
0x72, 0x6F, 0x6F, 0x74, 0x00, 0x00, 0x01, 0x00, 0x00, 0x06, 0x43, 0x77, 0x35, 0x94, 0x00,
0x00, 0x00, 0x00, 0x3F, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0A, 0x76, 0x70, 0xF8, 0xCD, 0x00, 0x35,
0x00, 0x01, 0x00, 0x00, 0x05, 0xF9, 0x00, 0x00, 0x00, 0x64, 0x00, 0x18, 0x74, 0x65, 0x73, 0x74,
0x5F, 0x6E, 0x74, 0x75, 0x70, 0x6C, 0x65, 0x5F, 0x6D, 0x69, 0x6E, 0x69, 0x6D, 0x61, 0x6C, 0x2E,
0x72, 0x6F, 0x6F, 0x74, 0x00, 0x00, 0x01, 0x00, 0x00, 0x06, 0x38, 0x77, 0x35, 0x94, 0x00,
]
end
45 changes: 30 additions & 15 deletions src/RNTuple/Writing/TFileWriter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ function rnt_write(io::IO, x; legacy=false)
end
end

struct Page_write{T <: AbstractVector{UInt8}}
data::T
end

function rnt_write(io::IO, x::Page_write; checksum=true)
write(io, x.data)
if checksum
write(io, xxh3_64(x.data))
end
end

function rnt_write(io::IO, x::AbstractVector{UInt8}; legacy=false)
if legacy
write(io, reverse(x))
Expand Down Expand Up @@ -156,12 +167,15 @@ function rnt_write(io::IO, x::UnROOT.FieldRecord)
rnt_write(io, x.parent_field_id)
rnt_write(io, x.struct_role)
rnt_write(io, x.flags)
if !iszero(x.repetition)
if x.flags != 0x01
error("Repetition is set but flags is not 0x01")
end
if !iszero(0x0001 & x.flags)
rnt_write(io, x.repetition)
end
if !iszero(0x0002 & x.flags)
rnt_write(io, x.source_field_id)
end
if !iszero(0x0004 & x.flags)
rnt_write(io, x.root_streamer_checksum)
end
rnt_write(io, x.field_name)
rnt_write(io, x.type_name)
rnt_write(io, x.type_alias)
Expand All @@ -179,6 +193,7 @@ function rnt_write(io::IO, x::UnROOT.ColumnRecord)
end
rnt_write(io, x.first_ele_idx)
end
rnt_write(io, x.representation_idx)
end

function rnt_write(io::IO, x::RNTupleFrame{T}) where T
Expand Down Expand Up @@ -270,7 +285,7 @@ function rnt_write(io::IO, x::UnROOT.Locator)
end

function rnt_write(io::IO, x::PageDescription)
rnt_write(io, x.num_elements)
rnt_write(io, -x.num_elements)
rnt_write(io, x.locator)
end

Expand All @@ -294,7 +309,7 @@ function rnt_write(io::IO, x::UnROOT.RNTuplePageOuterList)
for x in ary
rnt_write(temp_io, x)
end
size = temp_io.size + sizeof(Int64) + sizeof(Int32)
size = position(temp_io) + sizeof(Int64) + sizeof(Int32)
write(io, Int64(-size))
write(io, Int32(N))
seekstart(temp_io)
Expand All @@ -310,7 +325,7 @@ function rnt_write(io::IO, x::UnROOT.RNTuplePageInnerList)
offset = zero(UInt64)
compression = zero(UInt32)
write(temp_io, offset, compression)
size = temp_io.size + sizeof(Int64) + sizeof(Int32)
size = position(temp_io) + sizeof(offset) + sizeof(compression)
write(io, Int64(-size))
write(io, Int32(N))
seekstart(temp_io)
Expand Down Expand Up @@ -381,7 +396,6 @@ function rnt_write(io::IO, x::UnROOT.RNTupleFooter; envelope=true)
rnt_write(temp_io, x.extension_header_links)
rnt_write(temp_io, Write_RNTupleListFrame(x.column_group_records))
rnt_write(temp_io, Write_RNTupleListFrame(x.cluster_group_records))
rnt_write(temp_io, Write_RNTupleListFrame(x.meta_data_links))

# add id_length size and checksum size
envelope_size = temp_io.size + sizeof(Int64) + sizeof(UInt64)
Expand Down Expand Up @@ -413,6 +427,7 @@ function rnt_write(io::IO, x::UnROOT.ROOT_3a3a_Experimental_3a3a_RNTuple)
rnt_write(temp_io, x.fSeekFooter; legacy=true)
rnt_write(temp_io, x.fNBytesFooter; legacy=true)
rnt_write(temp_io, x.fLenFooter; legacy=true)
rnt_write(temp_io, x.fMaxKeySize; legacy=true)
payload_ary = take!(temp_io)
checksum = xxh3_64(payload_ary)
rnt_write(io, payload_ary)
Expand Down Expand Up @@ -501,16 +516,16 @@ function write_rntuple(file::IO, table; file_name="test_ntuple_minimal.root", rn
RBlob1_obs = rnt_write_observe(file, Stubs.RBlob1)
rntAnchor_update[:fSeekHeader] = UInt32(position(file))
rnt_header = UnROOT.RNTupleHeader(zero(UInt64), rntuple_name, "", "ROOT v6.33.01", [
UnROOT.FieldRecord(zero(UInt32), zero(UInt32), zero(UInt32), zero(UInt16), zero(UInt16), 0, string(only(input_schema.names)), "std::uint32_t", "", ""),
], [UnROOT.ColumnRecord(0x14, 0x20, zero(UInt32), zero(UInt32), 0),], UnROOT.AliasRecord[], UnROOT.ExtraTypeInfo[])
UnROOT.FieldRecord(zero(UInt32), zero(UInt32), zero(UInt32), zero(UInt16), zero(UInt16), 0, -1, -1, string(only(input_schema.names)), "std::uint32_t", "", ""),
], [UnROOT.ColumnRecord(0x14, 0x20, zero(UInt32), 0x00, 0x00, 0),], UnROOT.AliasRecord[], UnROOT.ExtraTypeInfo[])

rnt_header_obs = rnt_write_observe(file, rnt_header)
rntAnchor_update[:fNBytesHeader] = rnt_header_obs.len
rntAnchor_update[:fLenHeader] = rnt_header_obs.len

RBlob2_obs = rnt_write_observe(file, Stubs.RBlob2)
page1 = reinterpret(UInt8, input_col)
page1_bytes = split4_encode(page1)
page1_bytes = Page_write(split4_encode(page1))
page1_position = position(file)
page1_obs = rnt_write_observe(file, page1_bytes)

Expand All @@ -534,13 +549,13 @@ function write_rntuple(file::IO, table; file_name="test_ntuple_minimal.root", rn
rntAnchor_update[:fSeekFooter] = UInt32(position(file))
rnt_footer = UnROOT.RNTupleFooter(0, _checksum(rnt_header_obs.object), UnROOT.RNTupleSchemaExtension([], [], [], []), [], [
UnROOT.ClusterGroupRecord(0, input_length, 1, UnROOT.EnvLink(0x000000000000007c, UnROOT.Locator(124, pagelink_position, ))),
], UnROOT.EnvLink[])
])
rnt_footer_obs = rnt_write_observe(file, rnt_footer)
rntAnchor_update[:fNBytesFooter] = 0xac
rntAnchor_update[:fLenFooter] = 0xac
rntAnchor_update[:fNBytesFooter] = 0xA0
rntAnchor_update[:fLenFooter] = 0xA0

tkey32_anchor_position = position(file)
tkey32_anchor = UnROOT.TKey32(134, 4, 70, 0x7567176d, 64, 1, tkey32_anchor_position, 100, "ROOT::Experimental::RNTuple", rntuple_name, "")
tkey32_anchor = UnROOT.TKey32(0x0000008E, 4, 0x0000004E, Stubs.WRITE_TIME, 64, 1, tkey32_anchor_position, 100, "ROOT::Experimental::RNTuple", rntuple_name, "")
tkey32_anchor_obs1 = rnt_write_observe(file, tkey32_anchor)
magic_6bytes_obs = rnt_write_observe(file, Stubs.magic_6bytes)
rnt_anchor_obs = rnt_write_observe(file, Stubs.rnt_anchor)
Expand Down
6 changes: 4 additions & 2 deletions src/RNTuple/bootstrap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ Base.@kwdef struct ROOT_3a3a_Experimental_3a3a_RNTuple <: ROOTStreamedObject
fSeekFooter::UInt64
fNBytesFooter::UInt64
fLenFooter::UInt64
fMaxKeySize::UInt64
fChecksum::UInt64
end

function ROOT_3a3a_Experimental_3a3a_RNTuple(io, tkey::TKey, refs)
local_io = datastream(io, tkey)
skip(local_io, 6)
_before_anchor = position(local_io)
anchor_checksum = xxh3_64(read(local_io, 2*4 + 6*8))
anchor_checksum = xxh3_64(read(local_io, 2*4 + 7*8))
seek(local_io, _before_anchor)
anchor = ROOT_3a3a_Experimental_3a3a_RNTuple(;
fVersionEpoch = readtype(local_io, UInt16),
Expand All @@ -30,6 +31,7 @@ function ROOT_3a3a_Experimental_3a3a_RNTuple(io, tkey::TKey, refs)
fSeekFooter = readtype(local_io, UInt64),
fNBytesFooter = readtype(local_io, UInt64),
fLenFooter = readtype(local_io, UInt64),
fMaxKeySize = readtype(local_io, UInt64),
fChecksum = readtype(local_io, UInt64),
)

Expand All @@ -50,7 +52,7 @@ function ROOT_3a3a_Experimental_3a3a_RNTuple(io, tkey::TKey, refs)

schema = parse_fields(header.payload)

rnt = RNTuple(io, header.payload, footer.payload, schema)
rnt = RNTuple(io, anchor, header.payload, footer.payload, schema)
return rnt
end

Expand Down
1 change: 0 additions & 1 deletion src/RNTuple/displays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ function Base.show(io::IO, footer::RNTupleFooter, indent=0)
println(io, "$ind extension_header_links: $(footer.extension_header_links)")
println(io, "$ind column_group_records: $(footer.column_group_records)")
println(io, "$ind cluster_group_records: $(footer.cluster_group_records)")
println(io, "$ind meta_data_links: $(footer.meta_data_links)")
end

function Base.show(io::IO, rn::RNTuple)
Expand Down
11 changes: 8 additions & 3 deletions src/RNTuple/fieldcolumn_reading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ _field_output_type(::Type{LeafField{Bool}}) = BitVector
function read_field(io, field::LeafField{Bool}, page_list)
cr = field.columnrecord
pages = page_list[field.content_col_idx]
total_num_elements = sum(p.num_elements for p in pages)
total_num_elements = sum(abs(p.num_elements) for p in pages)

# pad to nearest 8*k bytes because each chunk needs to be UInt64
bytes = read_pagedesc(io, pages, cr)
Expand Down Expand Up @@ -209,7 +209,12 @@ column since `pagedesc` only contains `num_elements` information.
function read_pagedesc(io, pagedescs::AbstractVector{PageDescription}, cr::ColumnRecord)
nbits = cr.nbits
split, zigzag, delta = _detect_encoding(cr.type)
output_L = div(sum(p.num_elements for p in pagedescs; init=UInt32(0))*nbits, 8, RoundUp)
list_num_elements = [-p.num_elements for p in pagedescs]
total_num_elements = sum(list_num_elements)
if any(<(0), total_num_elements)
error("Page checksum not implemented")
end
output_L = div(total_num_elements*nbits, 8, RoundUp)
res = Vector{UInt8}(undef, output_L)

# a page max size is 64KB
Expand All @@ -219,7 +224,7 @@ function read_pagedesc(io, pagedescs::AbstractVector{PageDescription}, cr::Colum
for i in eachindex(pagedescs)
pagedesc = pagedescs[i]
# when nbits == 1 for bits, need RoundUp
uncomp_size = div(pagedesc.num_elements * nbits, 8, RoundUp)
uncomp_size = div(list_num_elements[i] * nbits, 8, RoundUp)
dst = @view res[tip:tip+uncomp_size-1]
_read_locator!(tmp, io, pagedesc.locator, uncomp_size)
if split
Expand Down
3 changes: 1 addition & 2 deletions src/RNTuple/footer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ end
extension_header_links::RNTupleSchemaExtension
column_group_records::Vector{ColumnGroupRecord}
cluster_group_records::Vector{ClusterGroupRecord}
meta_data_links::Vector{EnvLink}
end

function _read_locator(io, locator, uncomp_size::Integer)
Expand All @@ -62,7 +61,7 @@ end
end

@SimpleStruct struct PageDescription
num_elements::UInt32
num_elements::Int32
locator::Locator
end

Expand Down
Loading

0 comments on commit 8a28452

Please sign in to comment.