3#ifndef AWKWARD_LAYOUTBUILDER_H_
4#define AWKWARD_LAYOUTBUILDER_H_
18#define AWKWARD_LAYOUTBUILDER_DEFAULT_OPTIONS awkward::BuilderOptions(1024, 1)
22 namespace LayoutBuilder {
31 template <
class CONTENT>
33 content.builder.set_id(id_);
47 template <std::
size_t ENUM,
typename BUILDER>
55 return std::to_string(
index);
70 template <
typename PRIMITIVE>
103 extend(PRIMITIVE* ptr,
size_t size)
noexcept {
104 data_.extend(ptr, size);
116 parameters_ = parameter;
135 return data_.length();
148 names_nbytes[
"node" + std::to_string(id_) +
"-data"] = data_.nbytes();
157 to_buffers(std::map<std::string, void*>& buffers)
const noexcept {
158 data_.concatenate(
reinterpret_cast<PRIMITIVE*
>(
159 buffers[
"node" + std::to_string(id_) +
"-data"]));
166 to_buffer(
void* buffer,
const char* name)
const noexcept {
167 if (std::string(name) == std::string(
"node" + std::to_string(id_) +
"-data")) {
168 data_.concatenate(
reinterpret_cast<PRIMITIVE*
>(buffer));
178 data_.concatenate(
reinterpret_cast<PRIMITIVE*
>(
179 buffers[
"node" + std::to_string(id_) +
"-data"]));
186 std::stringstream form_key;
187 form_key <<
"node" << id_;
189 std::string params(
"");
190 if (parameters_ ==
"") {
192 params = std::string(
", \"parameters\": { " + parameters_ +
" }");
195 if (std::is_arithmetic<PRIMITIVE>::value) {
196 return "{ \"class\": \"NumpyArray\", \"primitive\": \"" +
197 type_to_name<PRIMITIVE>() +
"\"" + params +
198 ", \"form_key\": \"" + form_key.str() +
"\" }";
200 return "{ \"class\": \"NumpyArray\", \"primitive\": \"" +
201 type_to_name<PRIMITIVE>() +
"\"" + params +
202 ", \"form_key\": \"" + form_key.str() +
"\" }";
204 throw std::runtime_error(
"type " +
205 std::string(
typeid(PRIMITIVE).name()) +
215 std::string parameters_;
235 template <
typename PRIMITIVE,
typename BUILDER>
276 offsets_.append(content_.length());
288 parameters_ = parameter;
310 return offsets_.length() - 1;
316 if ((int64_t)content_.length() != (int64_t)offsets_.last()) {
317 std::stringstream out;
318 out <<
"ListOffset node" << id_ <<
"has content length "
319 << content_.length() <<
"but last offset " << offsets_.last()
321 error.append(out.str());
325 return content_.is_valid(error);
334 names_nbytes[
"node" + std::to_string(id_) +
"-offsets"] =
336 content_.buffer_nbytes(names_nbytes);
345 to_buffers(std::map<std::string, void*>& buffers)
const noexcept {
346 offsets_.concatenate(
reinterpret_cast<PRIMITIVE*
>(
347 buffers[
"node" + std::to_string(id_) +
"-offsets"]));
348 content_.to_buffers(buffers);
356 to_buffer(
void* buffer,
const char* name)
const noexcept {
357 if (std::string(name) == std::string(
"node" + std::to_string(id_) +
"-offsets")) {
358 offsets_.concatenate(
reinterpret_cast<PRIMITIVE*
>(buffer));
360 content_.to_buffer(buffer, name);
369 offsets_.concatenate(
reinterpret_cast<PRIMITIVE*
>(
370 buffers[
"node" + std::to_string(id_) +
"-offsets"]));
371 content_.to_char_buffers(buffers);
378 std::stringstream form_key;
379 form_key <<
"node" << id_;
380 std::string params(
"");
381 if (parameters_ ==
"") {
383 params = std::string(
", \"parameters\": { " + parameters_ +
" }");
385 return "{ \"class\": \"ListOffsetArray\", \"offsets\": \"" +
386 type_to_numpy_like<PRIMITIVE>() +
387 "\", \"content\": " + content_.form() + params +
388 ", \"form_key\": \"" + form_key.str() +
"\" }";
401 std::string parameters_;
411 template<
class PRIMITIVE>
421 for (
const auto& c: value) {
479 return "{ \"class\": \"EmptyArray\" }";
497 template <
class MAP = std::map<std::
size_t, std::
string>,
498 typename... BUILDERS>
504 template <std::
size_t INDEX>
511 map_fields(std::index_sequence_for<BUILDERS...>());
521 : content_names_(user_defined_field_id_to_name_map) {
522 assert(content_names_.size() == fields_count_);
528 const std::vector<std::string>
530 if (content_names_.empty()) {
533 std::vector<std::string> result;
534 for (
auto it : content_names_) {
535 result.emplace_back(it.second);
547 content_names_ = user_defined_field_id_to_name_map;
551 template <std::
size_t INDEX>
552 typename RecordFieldType<INDEX>::Builder&
554 return std::get<INDEX>(
contents).builder;
566 parameters_ = parameter;
576 for (
size_t i = 0; i < fields_count_; i++) {
588 template <
class CONTENT>
597 for (
size_t i = 0; i < fields_count_; i++) {
604 return (std::get<0>(
contents).builder.length());
610 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
613 std::vector<size_t> lengths = field_lengths(index_sequence);
614 for (
size_t i = 0; i < lengths.size(); i++) {
618 else if (
length != (int64_t)lengths[i]) {
619 std::stringstream out;
620 out <<
"Record node" << id_ <<
" has field \""
621 <<
fields().at(i) <<
"\" length " << lengths[i]
622 <<
" that differs from the first length " <<
length <<
"\n";
623 error.append(out.str());
629 std::vector<bool> valid_fields = field_is_valid(index_sequence, error);
630 return std::none_of(std::cbegin(valid_fields),
631 std::cend(valid_fields),
632 std::logical_not<bool>());
641 : names_nbytes_(names_nbytes) { }
644 template <
class CONTENT>
646 content.builder.buffer_nbytes(names_nbytes_);
650 std::map<std::string, size_t>& names_nbytes_;
656 for (
size_t i = 0; i < fields_count_; i++) {
670 : buffers_(buffers) { }
673 template <
class CONTENT>
679 std::map<std::string, void*>& buffers_;
683 to_buffers(std::map<std::string, void*>& buffers)
const noexcept {
685 for (
size_t i = 0; i < fields_count_; i++) {
696 : buffer_(buffer), name_(name) { }
699 template <
class CONTENT>
701 content.builder.to_buffer(buffer_, name_);
710 to_buffer(
void* buffer,
const char* name)
const noexcept {
712 for (
size_t i = 0; i < fields_count_; i++) {
726 : buffers_(buffers) { }
729 template <
class CONTENT>
731 content.builder.to_char_buffers(buffers_);
735 std::map<std::string, uint8_t*>& buffers_;
741 for (
size_t i = 0; i < fields_count_; i++) {
753 : out_(out), content_names_(content_names) {}
756 template <
class CONTENT>
759 auto it = content_names_.find(index);
761 if (it != content_names_.end()) {
762 out_ <<
"\"" << it->second <<
"\": ";
764 out_ <<
"\"" << index <<
"\": ";
767 out_ <<
content.builder.form();
771 std::stringstream& out_;
772 const std::map<unsigned long, std::string>& content_names_;
776 std::string
form() const noexcept {
777 std::stringstream form_key;
778 form_key <<
"node" << id_;
780 std::string params(
"");
781 if (!parameters_.empty()) {
782 params =
"\"parameters\": { " + parameters_ +
" }, ";
785 std::stringstream out;
786 out <<
"{ \"class\": \"RecordArray\", \"contents\": { ";
788 for (
size_t i = 0; i < fields_count_; i++) {
797 out << params <<
"\"form_key\": \"" << form_key.str() <<
"\" }";
807 template <std::size_t... S>
809 map_fields(std::index_sequence<S...>)
noexcept {
810 fields_ = std::vector<std::string>(
811 {std::string(std::get<S>(
contents).index_as_field())...});
816 template <std::size_t... S>
818 field_lengths(std::index_sequence<S...>)
const noexcept {
819 return std::vector<size_t>({std::get<S>(
contents).builder.length()...});
823 template <std::size_t... S>
825 field_is_valid(std::index_sequence<S...>, std::string& error)
const
827 return std::vector<bool>(
828 {std::get<S>(
contents).builder.is_valid(error)...});
832 std::vector<std::string> fields_;
838 std::string parameters_;
844 static constexpr size_t fields_count_ =
sizeof...(BUILDERS);
853 template <
typename... BUILDERS>
855 using TupleContents =
typename std::tuple<BUILDERS...>;
857 template <std::
size_t INDEX>
858 using TupleContentType = std::tuple_element_t<INDEX, TupleContents>;
868 template <std::
size_t INDEX>
869 TupleContentType<INDEX>&
883 parameters_ = parameter;
893 template <
class CONTENT>
907 for (
size_t i = 0; i < fields_count_; i++) {
919 template <
class CONTENT>
927 for (
size_t i = 0; i < fields_count_; i++) {
941 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
944 std::vector<size_t> lengths = content_lengths(index_sequence);
945 for (
size_t i = 0; i < lengths.size(); i++) {
947 length = (int64_t)lengths[i];
949 else if (
length != (int64_t)lengths[i]) {
950 std::stringstream out;
951 out <<
"Record node" << id_ <<
" has index \"" << i <<
"\" length "
952 << lengths[i] <<
" that differs from the first length "
954 error.append(out.str());
960 std::vector<bool> valid_fields =
961 content_is_valid(index_sequence, error);
962 return std::none_of(std::cbegin(valid_fields),
963 std::cend(valid_fields),
964 std::logical_not<bool>());
973 : names_nbytes_(names_nbytes) { }
976 template <
class CONTENT>
978 content.buffer_nbytes(names_nbytes_);
982 std::map<std::string, size_t>& names_nbytes_;
988 for (
size_t i = 0; i < fields_count_; i++) {
1003 : buffers_(buffers) { }
1006 template <
class CONTENT>
1012 std::map<std::string, void*>& buffers_;
1016 to_buffers(std::map<std::string, void*>& buffers)
const noexcept {
1018 for (
size_t i = 0; i < fields_count_; i++) {
1031 : buffer_(buffer), name_(name) { }
1034 template <
class CONTENT>
1036 content.to_buffer(buffer_, name_);
1047 for (
size_t i = 0; i < fields_count_; i++) {
1061 : buffers_(buffers) { }
1064 template <
class CONTENT>
1066 content.to_char_buffers(buffers_);
1070 std::map<std::string, uint8_t*>& buffers_;
1076 for (
size_t i = 0; i < fields_count_; i++) {
1102 : out_(out), content_names_(content_names) {}
1105 template <
class CONTENT>
1107 unsigned long index =
content.index;
1108 auto it = content_names_.find(index);
1110 if (it != content_names_.end()) {
1111 out_ <<
"\"" << it->second <<
"\": ";
1113 out_ <<
"\"" << index <<
"\": ";
1116 out_ <<
content.builder.form();
1120 std::stringstream& out_;
1121 const std::map<unsigned long, std::string>& content_names_;
1127 std::stringstream form_key;
1128 form_key <<
"node" << id_;
1129 std::string params(
"");
1130 if (!parameters_.empty()) {
1131 params =
"\"parameters\": { " + parameters_ +
" }, ";
1133 std::stringstream out;
1134 out <<
"{ \"class\": \"RecordArray\", \"contents\": [";
1135 for (
size_t i = 0; i < fields_count_; i++) {
1143 out << params <<
"\"form_key\": \"" << form_key.str() <<
"\" }";
1153 template <std::size_t... S>
1155 content_lengths(std::index_sequence<S...>)
const noexcept {
1156 return std::vector<size_t>({std::get<S>(
contents).length()...});
1160 template <std::size_t... S>
1162 content_is_valid(std::index_sequence<S...>, std::string& error)
const
1164 return std::vector<bool>({std::get<S>(
contents).is_valid(error)...});
1168 std::vector<int64_t> field_index_;
1171 std::string parameters_;
1177 static constexpr size_t fields_count_ =
sizeof...(BUILDERS);
1193 template <
unsigned SIZE,
typename BUILDER>
1230 parameters_ = parameter;
1238 content_.set_id(
id);
1257 if (content_.length() != length_ * size_) {
1258 std::stringstream out;
1259 out <<
"Regular node" << id_ <<
"has content length "
1260 << content_.length() <<
", but length " << length_ <<
" and size "
1262 error.append(out.str());
1266 return content_.is_valid(error);
1275 content_.buffer_nbytes(names_nbytes);
1284 to_buffers(std::map<std::string, void*>& buffers)
const noexcept {
1285 content_.to_buffers(buffers);
1293 content_.to_buffer(buffer, name);
1302 content_.to_char_buffers(buffers);
1309 std::stringstream form_key;
1310 form_key <<
"node" << id_;
1311 std::string params(
"");
1312 if (parameters_ ==
"") {
1314 params = std::string(
", \"parameters\": { " + parameters_ +
" }");
1316 return "{ \"class\": \"RegularArray\", \"content\": " +
1317 content_.form() +
", \"size\": " + std::to_string(size_) +
1318 params +
", \"form_key\": \"" + form_key.str() +
"\" }";
1326 std::string parameters_;
1335 size_t size_ = SIZE;
1348 template <
typename PRIMITIVE,
typename BUILDER>
1391 if (i > max_index_) {
1394 max_index_ = UINTMAX_MAX;
1405 size_t start = content_.length();
1406 size_t stop = start + size;
1407 if (stop - 1 > max_index_) {
1408 max_index_ = stop - 1;
1410 for (
size_t i = start; i < stop; i++) {
1425 parameters_ = parameter;
1433 content_.set_id(
id);
1448 return index_.length();
1456 names_nbytes[
"node" + std::to_string(id_) +
"-index"] = index_.nbytes();
1457 content_.buffer_nbytes(names_nbytes);
1464 if (max_index_ == UINTMAX_MAX) {
1465 std::stringstream out;
1466 out <<
"Indexed node" << id_ <<
" has a negative index\n";
1467 error.append(out.str());
1469 }
else if ((content_.length() == 0) && (max_index_ == 0)) {
1470 }
else if (max_index_ >= content_.length()) {
1471 std::stringstream out;
1472 out <<
"Indexed node" << id_ <<
" has index " << max_index_
1473 <<
" but content has length "
1474 << content_.length() <<
"\n";
1475 error.append(out.str());
1478 return content_.is_valid(error);
1487 to_buffers(std::map<std::string, void*>& buffers)
const noexcept {
1488 index_.concatenate(
reinterpret_cast<PRIMITIVE*
>(
1489 buffers[
"node" + std::to_string(id_) +
"-index"]));
1490 content_.to_buffers(buffers);
1499 if (std::string(name) == std::string(
"node" + std::to_string(id_) +
"-index")) {
1500 index_.concatenate(
reinterpret_cast<PRIMITIVE*
>(buffer));
1502 content_.to_buffer(buffer, name);
1511 index_.concatenate(
reinterpret_cast<PRIMITIVE*
>(
1512 buffers[
"node" + std::to_string(id_) +
"-index"]));
1513 content_.to_char_buffers(buffers);
1520 std::stringstream form_key;
1521 form_key <<
"node" << id_;
1522 std::string params(
"");
1523 if (parameters_ ==
"") {
1525 params = std::string(
", \"parameters\": { " + parameters_ +
" }");
1527 return "{ \"class\": \"IndexedArray\", \"index\": \"" +
1528 type_to_numpy_like<PRIMITIVE>() +
1529 "\", \"content\": " + content_.form() + params +
1530 ", \"form_key\": \"" + form_key.str() +
"\" }";
1543 std::string parameters_;
1562 template <
typename PRIMITIVE,
typename BUILDER>
1599 last_valid_ = content_.length();
1607 last_valid_ = content_.length();
1609 if (i > max_index_) {
1621 size_t start = content_.length();
1622 size_t stop = start + size;
1623 last_valid_ = stop - 1;
1624 if (last_valid_ > max_index_) {
1625 max_index_ = last_valid_;
1627 for (
size_t i = start; i < stop; i++) {
1644 for (
size_t i = 0; i < size; i++) {
1658 parameters_ = parameter;
1666 content_.set_id(
id);
1681 return index_.length();
1687 if ((content_.length() == 0) && (max_index_ == 0)) {
1688 }
else if (max_index_ >= content_.length()) {
1689 std::stringstream out;
1690 out <<
"IndexedOption node" << id_ <<
" has index " << max_index_
1691 <<
" but content has length "
1692 << content_.length() <<
"\n";
1693 error.append(out.str());
1697 return content_.is_valid(error);
1705 names_nbytes[
"node" + std::to_string(id_) +
"-index"] = index_.nbytes();
1706 content_.buffer_nbytes(names_nbytes);
1715 to_buffers(std::map<std::string, void*>& buffers)
const noexcept {
1716 index_.concatenate(
reinterpret_cast<PRIMITIVE*
>(
1717 buffers[
"node" + std::to_string(id_) +
"-index"]));
1718 content_.to_buffers(buffers);
1727 if (std::string(name) == std::string(
"node" + std::to_string(id_) +
"-index")) {
1728 index_.concatenate(
reinterpret_cast<PRIMITIVE*
>(buffer));
1730 content_.to_buffer(buffer, name);
1739 index_.concatenate(
reinterpret_cast<PRIMITIVE*
>(
1740 buffers[
"node" + std::to_string(id_) +
"-index"]));
1741 content_.to_char_buffers(buffers);
1748 std::stringstream form_key;
1749 form_key <<
"node" << id_;
1750 std::string params(
"");
1751 if (parameters_ ==
"") {
1753 params = std::string(
", \"parameters\": { " + parameters_ +
" }");
1755 return "{ \"class\": \"IndexedOptionArray\", \"index\": \"" +
1756 type_to_numpy_like<PRIMITIVE>() +
1757 "\", \"content\": " + content_.form() + params +
1758 ", \"form_key\": \"" + form_key.str() +
"\" }";
1771 std::string parameters_;
1794 template <
typename BUILDER>
1818 parameters_ = parameter;
1826 content_.set_id(
id);
1838 return content_.length();
1844 return content_.is_valid(error);
1852 content_.buffer_nbytes(names_nbytes);
1861 to_buffers(std::map<std::string, void*>& buffers)
const noexcept {
1862 content_.to_buffers(buffers);
1870 content_.to_buffer(buffer, name);
1879 content_.to_char_buffers(buffers);
1886 std::stringstream form_key;
1887 form_key <<
"node" << id_;
1888 std::string params(
"");
1889 if (parameters_ ==
"") {
1891 params = std::string(
", \"parameters\": { " + parameters_ +
" }");
1893 return "{ \"class\": \"UnmaskedArray\", \"content\": " +
1894 content_.form() + params +
", \"form_key\": \"" +
1895 form_key.str() +
"\" }";
1903 std::string parameters_;
1925 template <
bool VALID_WHEN,
typename BUILDER>
1964 mask_.
append(valid_when_);
1975 for (
size_t i = 0; i < size; i++) {
1976 mask_.
append(valid_when_);
1986 mask_.
append(!valid_when_);
1997 for (
size_t i = 0; i < size; i++) {
1998 mask_.
append(!valid_when_);
2012 parameters_ = parameter;
2020 content_.set_id(
id);
2040 if (content_.length() != mask_.
length()) {
2041 std::stringstream out;
2042 out <<
"ByteMasked node" << id_ <<
"has content length "
2043 << content_.length() <<
"but mask length " << mask_.
length()
2045 error.append(out.str());
2049 return content_.is_valid(error);
2058 names_nbytes[
"node" + std::to_string(id_) +
"-mask"] = mask_.
nbytes();
2059 content_.buffer_nbytes(names_nbytes);
2068 to_buffers(std::map<std::string, void*>& buffers)
const noexcept {
2070 buffers[
"node" + std::to_string(id_) +
"-mask"]));
2071 content_.to_buffers(buffers);
2080 if (std::string(name) == std::string(
"node" + std::to_string(id_) +
"-mask")) {
2081 mask_.
concatenate(
reinterpret_cast<int8_t*
>(buffer));
2083 content_.to_buffer(buffer, name);
2093 buffers[
"node" + std::to_string(id_) +
"-mask"]));
2094 content_.to_char_buffers(buffers);
2101 std::stringstream form_key, form_valid_when;
2102 form_key <<
"node" << id_;
2103 form_valid_when << std::boolalpha << valid_when_;
2104 std::string params(
"");
2105 if (parameters_ ==
"") {
2107 params = std::string(
", \"parameters\": { " + parameters_ +
" }");
2109 return "{ \"class\": \"ByteMaskedArray\", \"mask\": \"i8\", "
2111 content_.form() +
", \"valid_when\": " + form_valid_when.str() +
2112 params +
", \"form_key\": \"" + form_key.str() +
"\" }";
2125 std::string parameters_;
2131 bool valid_when_ = VALID_WHEN;
2150 template <
bool VALID_WHEN,
bool LSB_ORDER,
typename BUILDER>
2157 current_byte_(uint8_t(0)),
2158 current_byte_ref_(mask_.append_and_get_ref(current_byte_)),
2163 for (
size_t i = 0; i < 8; i++) {
2167 for (
size_t i = 0; i < 8; i++) {
2168 cast_[i] = 128 >> i;
2180 current_byte_(uint8_t(0)),
2181 current_byte_ref_(mask_.append_and_get_ref(current_byte_)),
2186 for (
size_t i = 0; i < 8; i++) {
2190 for (
size_t i = 0; i < 8; i++) {
2191 cast_[i] = 128 >> i;
2222 current_byte_ |= cast_[current_index_];
2235 for (
size_t i = 0; i < size; i++) {
2258 for (
size_t i = 0; i < size; i++) {
2273 parameters_ = parameter;
2281 content_.set_id(
id);
2298 return mask_.
length() > 0 ?
2299 (mask_.
length() - 1) * 8 + current_index_ : current_index_;
2305 if (content_.length() !=
length()) {
2306 std::stringstream out;
2307 out <<
"BitMasked node" << id_ <<
"has content length "
2308 << content_.length() <<
"but bit mask length " << mask_.
length()
2310 error.append(out.str());
2314 return content_.is_valid(error);
2323 names_nbytes[
"node" + std::to_string(id_) +
"-mask"] = mask_.
nbytes();
2324 content_.buffer_nbytes(names_nbytes);
2333 to_buffers(std::map<std::string, void*>& buffers)
const noexcept {
2335 buffers[
"node" + std::to_string(id_) +
"-mask"]), 0, 1);
2336 mask_.
append(
reinterpret_cast<uint8_t*
>(
2337 buffers[
"node" + std::to_string(id_) +
"-mask"]), mask_.
length() - 1, 0, 1);
2338 content_.to_buffers(buffers);
2347 if (std::string(name) == std::string(
"node" + std::to_string(id_) +
"-mask")) {
2349 mask_.
append(
reinterpret_cast<uint8_t*
>(buffer), mask_.
length() - 1, 0, 1);
2351 content_.to_buffer(buffer, name);
2361 buffers[
"node" + std::to_string(id_) +
"-mask"]), 0, 1);
2362 mask_.
append(
reinterpret_cast<uint8_t*
>(
2363 buffers[
"node" + std::to_string(id_) +
"-mask"]), mask_.
length() - 1, 0, 1);
2364 content_.to_char_buffers(buffers);
2371 std::stringstream form_key, form_valid_when, form_lsb_order;
2372 form_key <<
"node" << id_;
2373 form_valid_when << std::boolalpha << valid_when_;
2374 form_lsb_order << std::boolalpha << lsb_order_;
2375 std::string params(
"");
2376 if (parameters_ ==
"") {
2378 params = std::string(
", \"parameters\": { " + parameters_ +
" }");
2380 return "{ \"class\": \"BitMaskedArray\", \"mask\": \"u8\", "
2382 content_.form() +
", \"valid_when\": " + form_valid_when.str() +
2383 ", \"lsb_order\": " + form_lsb_order.str() + params +
2384 ", \"form_key\": \"" + form_key.str() +
"\" }";
2393 if (current_index_ == 8) {
2395 current_byte_ = uint8_t(0);
2407 current_index_ += 1;
2409 current_byte_ref_ = current_byte_;
2411 current_byte_ref_ = ~current_byte_;
2418 GrowableBuffer<uint8_t> mask_;
2424 std::string parameters_;
2430 uint8_t current_byte_;
2433 uint8_t& current_byte_ref_;
2436 size_t current_index_;
2442 bool valid_when_ = VALID_WHEN;
2446 bool lsb_order_ = LSB_ORDER;
2464 template <
typename TAGS,
typename INDEX,
typename... BUILDERS>
2469 template <std::
size_t I>
2479 for (
size_t i = 0; i < contents_count_; i++) {
2480 last_valid_index_[i] = -1;
2494 for (
size_t i = 0; i < contents_count_; i++) {
2495 last_valid_index_[i] = -1;
2499 template <std::
size_t I>
2502 return std::get<I>(contents_);
2507 template <std::
size_t TAG>
2510 auto& which_content = std::get<TAG>(contents_);
2511 INDEX next_index = which_content.length();
2513 TAGS tag = (TAGS)TAG;
2514 last_valid_index_[tag] = next_index;
2516 index_.
append(next_index);
2518 return which_content;
2530 parameters_ = parameter;
2540 template <
class CONTENT>
2554 for (
size_t i = 0; i < contents_count_; i++) {
2555 visit_at(contents_, i, setIdFunctor);
2567 template <
class CONTENT>
2575 for (
size_t i = 0; i < contents_count_; i++) {
2576 last_valid_index_[i] = -1;
2582 for (
size_t i = 0; i < contents_count_; i++) {
2583 visit_at(contents_, i, clearContentsFunctor);
2597 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
2599 std::vector<size_t> lengths = content_lengths(index_sequence);
2600 std::unique_ptr<INDEX[]> index_ptr(
new INDEX[index_.
length()]);
2602 std::unique_ptr<TAGS[]> tags_ptr(
new TAGS[tags_.
length()]);
2604 for (
size_t i = 0; i < index_.
length(); i++) {
2605 if (index_ptr.get()[i] < 0 || index_ptr.get()[i] >= lengths[tags_ptr.get()[i]]) {
2606 std::stringstream out;
2607 out <<
"Union node" << id_ <<
" has index " << index_ptr.get()[i]
2608 <<
" at position " << i <<
" but content has length "
2609 << lengths[tags_ptr.get()[i]] <<
"\n";
2610 error.append(out.str());
2616 std::vector<bool> valid_contents =
2617 content_is_valid(index_sequence, error);
2618 return std::none_of(std::cbegin(valid_contents),
2619 std::cend(valid_contents),
2620 std::logical_not<bool>());
2629 : names_nbytes_(names_nbytes) {}
2632 template <
class CONTENT>
2634 content.buffer_nbytes(names_nbytes_);
2638 std::map<std::string, size_t>& names_nbytes_;
2643 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
2646 names_nbytes[
"node" + std::to_string(id_) +
"-tags"] = tags_.
nbytes();
2647 names_nbytes[
"node" + std::to_string(id_) +
"-index"] = index_.
nbytes();
2652 for (
size_t i = 0; i < contents_count_; i++) {
2653 visit_at(contents_, i, bufferNBytesFunctor);
2667 : buffers_(buffers) { }
2670 template <
class CONTENT>
2676 std::map<std::string, void*>& buffers_;
2680 to_buffers(std::map<std::string, void*>& buffers)
const noexcept {
2681 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
2685 buffers[
"node" + std::to_string(id_) +
"-tags"]));
2687 buffers[
"node" + std::to_string(id_) +
"-index"]));
2692 for (
size_t i = 0; i < contents_count_; i++) {
2693 visit_at(contents_, i, toBuffersFunctor);
2706 : buffer_(buffer), name_(name) { }
2709 template <
class CONTENT>
2711 content.to_buffer(buffer_, name_);
2721 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
2723 if (std::string(name) == std::string(
"node" + std::to_string(id_) +
"-tags")) {
2724 tags_.
concatenate(
reinterpret_cast<TAGS*
>(buffer));
2726 else if (std::string(name) == std::string(
"node" + std::to_string(id_) +
"-index")) {
2727 index_.
concatenate(
reinterpret_cast<INDEX*
>(buffer));
2733 for (
size_t i = 0; i < contents_count_; i++) {
2734 visit_at(contents_, i, toBufferFunctor);
2747 : buffers_(buffers) { }
2750 template <
class CONTENT>
2752 content.to_char_buffers(buffers_);
2756 std::map<std::string, uint8_t*>& buffers_;
2761 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
2765 buffers[
"node" + std::to_string(id_) +
"-tags"]));
2767 buffers[
"node" + std::to_string(id_) +
"-index"]));
2772 for (
size_t i = 0; i < contents_count_; i++) {
2773 visit_at(contents_, i, toCharBuffersFunctor);
2784 : out_(out), content_names_(content_names) {}
2787 template <
class CONTENT>
2789 unsigned long index =
content.index;
2790 auto it = content_names_.find(index);
2792 if (it != content_names_.end()) {
2793 out_ <<
"\"" << it->second <<
"\": ";
2795 out_ <<
"\"" << index <<
"\": ";
2798 out_ <<
content.builder.form();
2802 std::stringstream& out_;
2803 const std::map<unsigned long, std::string>& content_names_;
2809 std::stringstream form_key;
2810 form_key <<
"node" << id_;
2811 std::string params(
"");
2812 if (!parameters_.empty()) {
2813 params =
", \"parameters\": { " + parameters_ +
" }";
2815 std::stringstream out;
2816 out <<
"{ \"class\": \"UnionArray\", \"tags\": \"" +
2817 type_to_numpy_like<TAGS>() +
"\", \"index\": \"" +
2818 type_to_numpy_like<INDEX>() +
"\", \"contents\": [";
2819 for (
size_t i = 0; i < contents_count_; i++) {
2824 visit_at(contents_, i, contentsFormFunctor);
2827 out << params <<
"\"form_key\": \"" << form_key.str() <<
"\" }";
2835 template <std::size_t... S>
2837 content_lengths(std::index_sequence<S...>)
const {
2838 return std::vector<size_t>({std::get<S>(contents_).length()...});
2842 template <std::size_t... S>
2844 content_is_valid(std::index_sequence<S...>, std::string& error)
const {
2845 return std::vector<bool>({std::get<S>(contents_).is_valid(error)...});
2851 GrowableBuffer<TAGS> tags_;
2856 GrowableBuffer<INDEX> index_;
2862 std::string parameters_;
2868 size_t last_valid_index_[
sizeof...(BUILDERS)];
2871 static constexpr size_t contents_count_ =
sizeof...(BUILDERS);
#define AWKWARD_LAYOUTBUILDER_DEFAULT_OPTIONS
Object of BuilderOptions which sets the values of the default options.
Definition LayoutBuilder.h:18
virtual const std::string to_buffers(BuffersContainer &container, int64_t &form_key_id) const =0
Copy the current snapshot into the BuffersContainer and return a Form as a std::string (JSON).
virtual void clear()=0
Removes all accumulated data without resetting the type knowledge.
virtual const BuilderPtr index(int64_t index)=0
Sets the pointer to a given tuple field index; the next command will fill that slot.
Discontiguous, one-dimensional buffer (which consists of multiple contiguous, one-dimensional panels)...
Definition GrowableBuffer.h:233
void concatenate_from(PRIMITIVE *external_pointer, size_t to, size_t from) const noexcept
Copies and concatenates all accumulated data from multiple panels to one contiguously allocated exter...
Definition GrowableBuffer.h:517
size_t nbytes() const
Currently used number of bytes.
Definition GrowableBuffer.h:440
void concatenate(PRIMITIVE *external_pointer) const noexcept
Copies and concatenates all accumulated data from multiple panels to one contiguously allocated exter...
Definition GrowableBuffer.h:492
PRIMITIVE & append_and_get_ref(PRIMITIVE datum)
Like append, but the type signature returns the reference to PRIMITIVE.
Definition GrowableBuffer.h:484
size_t length() const
Currently used number of elements.
Definition GrowableBuffer.h:408
void append(PRIMITIVE datum)
Inserts one datum into the panel, possibly triggering allocation of a new panel.
Definition GrowableBuffer.h:450
void clear()
Discards accumulated data, the #reserved returns to options.initial(), and a new #ptr is allocated.
Definition GrowableBuffer.h:421
Builds a BitMaskedArray in which mask values are packed into a bitmap.
Definition LayoutBuilder.h:2151
bool valid_when() const noexcept
Determines when the builder content are valid.
Definition LayoutBuilder.h:2204
void clear() noexcept
Discards the accumulated mask and clears the content of the builder.
Definition LayoutBuilder.h:2287
bool lsb_order() const noexcept
Determines whether the position of each bit is in Least-Significant Bit order (LSB) or not.
Definition LayoutBuilder.h:2211
BUILDER & append_invalid() noexcept
Sets current_byte_ and cast_ default to null, no change in current_byte_.
Definition LayoutBuilder.h:2245
BUILDER & extend_valid(size_t size) noexcept
Sets size number of bits in the mask. If current_byte_ and cast_: 0 indicates null,...
Definition LayoutBuilder.h:2234
std::string form() const noexcept
Generates a unique description of the builder and its contents in the form of a JSON-like string.
Definition LayoutBuilder.h:2370
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:2266
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:2272
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:2198
size_t length() const noexcept
Current length of the mask buffer.
Definition LayoutBuilder.h:2297
void to_char_buffers(std::map< std::string, uint8_t * > &buffers) const noexcept
Copies and concatenates all the accumulated data in the builder to a map of user-allocated buffers.
Definition LayoutBuilder.h:2359
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:2278
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:2304
BitMasked(const awkward::BuilderOptions &options)
Creates a new BitMasked layout builder by allocating a new mask buffer, taking options from BuilderOp...
Definition LayoutBuilder.h:2178
BUILDER & append_valid() noexcept
Sets a bit in the mask. If current_byte_ and cast_: 0 indicates null, 1 indicates valid and vice vers...
Definition LayoutBuilder.h:2220
void buffer_nbytes(std::map< std::string, size_t > &names_nbytes) const noexcept
Retrieves the names and sizes (in bytes) of the buffers used in the builder and its contents.
Definition LayoutBuilder.h:2321
BUILDER & extend_invalid(size_t size) noexcept
Sets current_byte_ and cast_ default to null, no change in current_byte_.
Definition LayoutBuilder.h:2257
void to_buffer(void *buffer, const char *name) const noexcept
Copies and concatenates the accumulated data in the builder buffer to a user-defined pointer if the g...
Definition LayoutBuilder.h:2346
BitMasked()
Creates a new BitMasked layout builder by allocating a new mask buffer, using AWKWARD_LAYOUTBUILDER_D...
Definition LayoutBuilder.h:2155
void to_buffers(std::map< std::string, void * > &buffers) const noexcept
Copies and concatenates all the accumulated data in each of the buffers of the builder and its conten...
Definition LayoutBuilder.h:2333
Functor for setting the ids of all nodes in a layout tree.
Definition LayoutBuilder.h:27
BuilderSetId(size_t &id)
Definition LayoutBuilder.h:29
void operator()(CONTENT &content)
Definition LayoutBuilder.h:32
Builds a ByteMaskedArray using a mask which is an array of booleans that determines whether the corre...
Definition LayoutBuilder.h:1926
bool valid_when() const noexcept
Determines when the builder content are valid.
Definition LayoutBuilder.h:1955
void clear() noexcept
Discards the accumulated mask and clears the content of the builder.
Definition LayoutBuilder.h:2026
BUILDER & append_invalid() noexcept
Inserts !valid_when in the mask.
Definition LayoutBuilder.h:1985
BUILDER & extend_valid(size_t size) noexcept
Inserts size number of valid_when in the mask.
Definition LayoutBuilder.h:1974
std::string form() const noexcept
Generates a unique description of the builder and its contents in the form of a JSON-like string.
Definition LayoutBuilder.h:2100
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:2005
ByteMasked()
Creates a new ByteMasked layout builder by allocating a new mask buffer, using AWKWARD_LAYOUTBUILDER_...
Definition LayoutBuilder.h:1930
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:2011
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1949
ByteMasked(const awkward::BuilderOptions &options)
Creates a new ByteMasked layout builder by allocating a new mask buffer, taking options from BuilderO...
Definition LayoutBuilder.h:1941
size_t length() const noexcept
Current length of the mask buffer.
Definition LayoutBuilder.h:2033
void to_char_buffers(std::map< std::string, uint8_t * > &buffers) const noexcept
Copies and concatenates all the accumulated data in the builder to a map of user-allocated buffers.
Definition LayoutBuilder.h:2091
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:2017
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:2039
BUILDER & append_valid() noexcept
Inserts valid_when in the mask.
Definition LayoutBuilder.h:1963
void buffer_nbytes(std::map< std::string, size_t > &names_nbytes) const noexcept
Retrieves the names and sizes (in bytes) of the buffers used in the builder and its contents.
Definition LayoutBuilder.h:2056
BUILDER & extend_invalid(size_t size) noexcept
Inserts size number of !valid_when in the mask.
Definition LayoutBuilder.h:1996
void to_buffer(void *buffer, const char *name) const noexcept
Copies and concatenates the accumulated data in the builder buffer to a user-defined pointer if the g...
Definition LayoutBuilder.h:2079
void to_buffers(std::map< std::string, void * > &buffers) const noexcept
Copies and concatenates all the accumulated data in each of the buffers of the builder and its conten...
Definition LayoutBuilder.h:2068
Builds an EmptyArray which has no content in it. It is used whenever an array's type is not known bec...
Definition LayoutBuilder.h:432
void clear() noexcept
Definition LayoutBuilder.h:444
bool is_valid(std::string &) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:454
std::string form() const noexcept
Generates a unique description of the builder and its contents in the form of a JSON-like string.
Definition LayoutBuilder.h:478
void to_buffers(std::map< std::string, void * > &) const noexcept
Definition LayoutBuilder.h:463
void to_buffer(void *, const char *) const noexcept
Definition LayoutBuilder.h:466
Empty()
Creates a new Empty layout builder.
Definition LayoutBuilder.h:435
void set_id(size_t &) noexcept
Definition LayoutBuilder.h:441
size_t length() const noexcept
Current length of the content.
Definition LayoutBuilder.h:448
void buffer_nbytes(std::map< std::string, size_t > &) const noexcept
Definition LayoutBuilder.h:459
void to_char_buffers(std::map< std::string, uint8_t * > &) const noexcept
Copies and concatenates all the accumulated data in the builder to a map of user-allocated buffers.
Definition LayoutBuilder.h:473
Helper class for sending a pair of field names (as enum) and field type as template parameters in Rec...
Definition LayoutBuilder.h:48
std::string index_as_field() const
Converts index as field string.
Definition LayoutBuilder.h:54
BUILDER Builder
Definition LayoutBuilder.h:50
const std::size_t index
The index of a Record field.
Definition LayoutBuilder.h:59
Builder builder
The content type of field in a Record.
Definition LayoutBuilder.h:61
Builds an IndexedOptionArray which consists of an index buffer. The negative values in the index are ...
Definition LayoutBuilder.h:1563
void clear() noexcept
Discards the accumulated index and clears the content of the builder. Also, last valid returns to -1.
Definition LayoutBuilder.h:1672
void extend_invalid(size_t size) noexcept
Inserts -1 in the index buffer size number of times.
Definition LayoutBuilder.h:1643
BUILDER & extend_valid(size_t size) noexcept
Inserts size number of valid index in the index buffer and returns the reference to the builder conte...
Definition LayoutBuilder.h:1620
std::string form() const noexcept
Generates a unique description of the builder and its contents in the form of a JSON-like string.
Definition LayoutBuilder.h:1747
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1651
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1657
IndexedOption(const awkward::BuilderOptions &options)
Creates a new IndexedOption layout builder by allocating a new index buffer, taking options from Buil...
Definition LayoutBuilder.h:1581
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1591
BUILDER & append_valid(size_t i) noexcept
Inserts an explicit value in the index buffer and returns the reference to the builder content.
Definition LayoutBuilder.h:1606
size_t length() const noexcept
Current length of the index buffer.
Definition LayoutBuilder.h:1680
void to_char_buffers(std::map< std::string, uint8_t * > &buffers) const noexcept
Copies and concatenates all the accumulated data in the builder to a map of user-allocated buffers.
Definition LayoutBuilder.h:1738
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1663
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1686
IndexedOption()
Creates a new IndexedOption layout builder by allocating a new index buffer, using AWKWARD_LAYOUTBUIL...
Definition LayoutBuilder.h:1567
BUILDER & append_valid() noexcept
Inserts the last valid index in the index buffer and returns the reference to the builder content.
Definition LayoutBuilder.h:1598
void buffer_nbytes(std::map< std::string, size_t > &names_nbytes) const noexcept
Retrieves the names and sizes (in bytes) of the buffers used in the builder and its contents.
Definition LayoutBuilder.h:1703
void append_invalid() noexcept
Inserts -1 in the index buffer.
Definition LayoutBuilder.h:1635
void to_buffer(void *buffer, const char *name) const noexcept
Copies and concatenates the accumulated data in the builder buffer to a user-defined pointer if the g...
Definition LayoutBuilder.h:1726
void to_buffers(std::map< std::string, void * > &buffers) const noexcept
Copies and concatenates all the accumulated data in each of the buffers of the builder and its conten...
Definition LayoutBuilder.h:1715
Builds an IndexedArray which consists of an index buffer.
Definition LayoutBuilder.h:1349
void clear() noexcept
Discards the accumulated index and clears the content of the builder.
Definition LayoutBuilder.h:1439
std::string form() const noexcept
Generates a unique description of the builder and its contents in the form of a JSON-like string.
Definition LayoutBuilder.h:1519
Indexed(const awkward::BuilderOptions &options)
Creates a new Indexed layout builder by allocating a new index buffer, taking options from BuilderOpt...
Definition LayoutBuilder.h:1366
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1418
Indexed()
Creates a new Indexed layout builder by allocating a new index buffer, using AWKWARD_LAYOUTBUILDER_DE...
Definition LayoutBuilder.h:1353
BUILDER & append_index() noexcept
Inserts the last valid index in the index buffer and returns the reference to the builder content.
Definition LayoutBuilder.h:1382
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1424
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1375
BUILDER & extend_index(size_t size) noexcept
Inserts size number indices in the index buffer and returns the reference to the builder content.
Definition LayoutBuilder.h:1404
size_t length() const noexcept
Current length of the index buffer.
Definition LayoutBuilder.h:1447
void to_char_buffers(std::map< std::string, uint8_t * > &buffers) const noexcept
Copies and concatenates all the accumulated data in the builder to a map of user-allocated buffers.
Definition LayoutBuilder.h:1510
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1430
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1462
void buffer_nbytes(std::map< std::string, size_t > &names_nbytes) const noexcept
Retrieves the names and sizes (in bytes) of the buffers used in the builder and its contents.
Definition LayoutBuilder.h:1454
void to_buffer(void *buffer, const char *name) const noexcept
Copies and concatenates the accumulated data in the builder buffer to a user-defined pointer if the g...
Definition LayoutBuilder.h:1498
void to_buffers(std::map< std::string, void * > &buffers) const noexcept
Copies and concatenates all the accumulated data in each of the buffers of the builder and its conten...
Definition LayoutBuilder.h:1487
BUILDER & append_index(size_t i) noexcept
Inserts an explicit value in the index buffer and returns the reference to the builder content.
Definition LayoutBuilder.h:1389
Builds a ListOffsetArray which describes unequal-length lists (often called a "jagged" or "ragged" ar...
Definition LayoutBuilder.h:236
void clear() noexcept
Discards the accumulated offsets and clears the builder content.
Definition LayoutBuilder.h:301
BUILDER & begin_list() noexcept
Begins a list and returns the reference to the builder content.
Definition LayoutBuilder.h:268
ListOffset()
Creates a new ListOffset layout builder by allocating a new offset buffer, using AWKWARD_LAYOUTBUILDE...
Definition LayoutBuilder.h:240
std::string form() const noexcept
Generates a unique description of the builder and its contents in the form of a JSON-like string.
Definition LayoutBuilder.h:377
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:281
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:287
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:262
size_t length() const noexcept
Current length of the content.
Definition LayoutBuilder.h:309
void to_char_buffers(std::map< std::string, uint8_t * > &buffers) const noexcept
Copies and concatenates all the accumulated data in the builder to a map of user-allocated buffers.
Definition LayoutBuilder.h:368
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:293
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:315
void end_list() noexcept
Ends a list and appends the current length of the list contents in the offsets buffer.
Definition LayoutBuilder.h:275
void buffer_nbytes(std::map< std::string, size_t > &names_nbytes) const noexcept
Retrieves the names and sizes (in bytes) of the buffers used in the builder and its contents.
Definition LayoutBuilder.h:332
void to_buffer(void *buffer, const char *name) const noexcept
Copies and concatenates the accumulated data in the builder buffer to a user-defined pointer if the g...
Definition LayoutBuilder.h:356
ListOffset(const awkward::BuilderOptions &options)
Creates a new ListOffset layout builder by allocating a new offset buffer, taking options from Builde...
Definition LayoutBuilder.h:253
void to_buffers(std::map< std::string, void * > &buffers) const noexcept
Copies and concatenates all the accumulated data in each of the buffers of the builder and its conten...
Definition LayoutBuilder.h:345
Builds a NumpyArray which describes multi-dimensional data of PRIMITIVE type.
Definition LayoutBuilder.h:71
void clear() noexcept
Discards the accumulated data in the builder.
Definition LayoutBuilder.h:128
bool is_valid(std::string &) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:140
Numpy(const awkward::BuilderOptions &options)
Creates a new Numpy layout builder by allocating a new buffer, taking options from BuilderOptions for...
Definition LayoutBuilder.h:87
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:109
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:115
size_t length() const noexcept
Current length of the data.
Definition LayoutBuilder.h:134
void to_char_buffers(std::map< std::string, uint8_t * > &buffers) const noexcept
Copies and concatenates all the accumulated data in the builder to a map of user-allocated buffers.
Definition LayoutBuilder.h:177
void append(PRIMITIVE x) noexcept
Inserts a PRIMITIVE type data.
Definition LayoutBuilder.h:95
Numpy()
Creates a new Numpy layout builder by allocating a new buffer, using AWKWARD_LAYOUTBUILDER_DEFAULT_OP...
Definition LayoutBuilder.h:75
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:121
void buffer_nbytes(std::map< std::string, size_t > &names_nbytes) const noexcept
Retrieves the name and size (in bytes) of the buffer.
Definition LayoutBuilder.h:146
void extend(PRIMITIVE *ptr, size_t size) noexcept
Inserts an entire array of PRIMITIVE type data.
Definition LayoutBuilder.h:103
void to_buffer(void *buffer, const char *name) const noexcept
Copies and concatenates the accumulated data in the builder buffer to a user-defined pointer if the g...
Definition LayoutBuilder.h:166
void to_buffers(std::map< std::string, void * > &buffers) const noexcept
Copies and concatenates all the accumulated data in the builder to a user-defined pointer.
Definition LayoutBuilder.h:157
std::string form() const
Generates a unique description of the builder and its contents in the form of a JSON-like string.
Definition LayoutBuilder.h:185
Retrieves the names and sizes (in bytes) of the buffers used in the builder and its contents.
Definition LayoutBuilder.h:637
BufferNBytesFunctor(std::map< std::string, size_t > &names_nbytes)
Definition LayoutBuilder.h:640
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:645
Clears the builder contents.
Definition LayoutBuilder.h:586
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:589
Generates a unique description of the builder and its contents in the form of a JSON-like string.
Definition LayoutBuilder.h:749
ContentsFormFunctor(std::stringstream &out, const std::map< unsigned long, std::string > &content_names)
Definition LayoutBuilder.h:752
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:757
Copies and concatenates the accumulated data in the buffers of the builder contents to user-defined p...
Definition LayoutBuilder.h:692
ToBufferFunctor(void *buffer, const char *name)
Definition LayoutBuilder.h:695
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:700
Copies and concatenates all the accumulated data in each of the buffers of the builder and its conten...
Definition LayoutBuilder.h:666
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:674
ToBuffersFunctor(std::map< std::string, void * > &buffers)
Definition LayoutBuilder.h:669
Copies and concatenates all the accumulated data in the builder to a map of user-allocated buffers.
Definition LayoutBuilder.h:722
ToCharBuffersFunctor(std::map< std::string, uint8_t * > &buffers)
Definition LayoutBuilder.h:725
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:730
Builds a RecordArray which represents an array of records, which can be of same or different types....
Definition LayoutBuilder.h:499
void clear() noexcept
Definition LayoutBuilder.h:595
Record()
Creates a new Record layout builder.
Definition LayoutBuilder.h:508
MAP UserDefinedMap
Definition LayoutBuilder.h:502
std::string form() const noexcept
Definition LayoutBuilder.h:776
RecordFieldType< INDEX >::Builder & content() noexcept
Returns the reference to the builder contents at INDEX.
Definition LayoutBuilder.h:553
std::tuple_element_t< INDEX, RecordContents > RecordFieldType
Definition LayoutBuilder.h:505
Record(UserDefinedMap user_defined_field_id_to_name_map)
Creates a new Record layout builder, taking a user-defined map with enumerated type field ID as keys ...
Definition LayoutBuilder.h:520
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:559
typename std::tuple< BUILDERS... > RecordContents
Definition LayoutBuilder.h:501
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:565
size_t length() const noexcept
Current number of records in first field.
Definition LayoutBuilder.h:603
void to_char_buffers(std::map< std::string, uint8_t * > &buffers) const noexcept
Definition LayoutBuilder.h:739
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:570
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:609
void buffer_nbytes(std::map< std::string, size_t > &names_nbytes) const noexcept
Definition LayoutBuilder.h:654
void set_fields(MAP user_defined_field_id_to_name_map) noexcept
Sets the field names.
Definition LayoutBuilder.h:546
void to_buffer(void *buffer, const char *name) const noexcept
Definition LayoutBuilder.h:710
const std::vector< std::string > fields() const noexcept
Returns a vector of strings sontaining all the field names.
Definition LayoutBuilder.h:529
void to_buffers(std::map< std::string, void * > &buffers) const noexcept
Definition LayoutBuilder.h:683
RecordContents contents
The contents of the RecordArray.
Definition LayoutBuilder.h:802
Builds a RegularArray that describes lists that have the same length, a single integer size....
Definition LayoutBuilder.h:1194
void clear() noexcept
Clears the builder content.
Definition LayoutBuilder.h:1243
BUILDER & begin_list() noexcept
Begins a list and returns the reference to the content of the builder.
Definition LayoutBuilder.h:1211
std::string form() const noexcept
Generates a unique description of the builder and its contents in the form of a JSON-like string.
Definition LayoutBuilder.h:1308
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1223
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1229
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1204
size_t length() const noexcept
Current number of lists of length SIZE.
Definition LayoutBuilder.h:1250
void to_char_buffers(std::map< std::string, uint8_t * > &buffers) const noexcept
Copies and concatenates all the accumulated data in the builder to a map of user-allocated buffers.
Definition LayoutBuilder.h:1301
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1235
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1256
void end_list() noexcept
Ends a list and increments the number of lists.
Definition LayoutBuilder.h:1217
void buffer_nbytes(std::map< std::string, size_t > &names_nbytes) const noexcept
Retrieves the names and sizes (in bytes) of the buffers used in the builder and its contents.
Definition LayoutBuilder.h:1273
void to_buffer(void *buffer, const char *name) const noexcept
Copies and concatenates the accumulated data in the buffers of the builder content to user-defined po...
Definition LayoutBuilder.h:1292
Regular()
Creates a new Regular layout builder.
Definition LayoutBuilder.h:1197
void to_buffers(std::map< std::string, void * > &buffers) const noexcept
Copies and concatenates all the accumulated data in each of the buffers of the builder and its conten...
Definition LayoutBuilder.h:1284
Helper for building an array of strings with a similar API as a Numpy builder.
Definition LayoutBuilder.h:412
void append(const std::string &value)
Definition LayoutBuilder.h:419
String()
Definition LayoutBuilder.h:414
Retrieves the names and sizes (in bytes) of the buffers used in the builder and its contents.
Definition LayoutBuilder.h:969
BufferNBytesFunctor(std::map< std::string, size_t > &names_nbytes)
Definition LayoutBuilder.h:972
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:977
Clears the builder contents.
Definition LayoutBuilder.h:916
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:920
Generates a unique description of the builder and its contents in the form of a JSON-like string.
Definition LayoutBuilder.h:1098
ContentsFormFunctor(std::stringstream &out, const std::map< unsigned long, std::string > &content_names)
Definition LayoutBuilder.h:1101
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:1106
Assigns a unique ID to each node.
Definition LayoutBuilder.h:887
SetIdFunctor(size_t &id)
Definition LayoutBuilder.h:890
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:894
Copies and concatenates the accumulated data in the buffers of the builder contents to user-defined p...
Definition LayoutBuilder.h:1027
ToBufferFunctor(void *buffer, const char *name)
Definition LayoutBuilder.h:1030
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:1035
Copies and concatenates all the accumulated data in each of the buffers of the builder and its conten...
Definition LayoutBuilder.h:999
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:1007
ToBuffersFunctor(std::map< std::string, void * > &buffers)
Definition LayoutBuilder.h:1002
Copies and concatenates all the accumulated data in the builder to a map of user-allocated buffers.
Definition LayoutBuilder.h:1057
ToCharBuffersFunctor(std::map< std::string, uint8_t * > &buffers)
Definition LayoutBuilder.h:1060
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:1065
Builds a RecordArray which represents an array of tuples which can be of same or different types with...
Definition LayoutBuilder.h:854
void clear() noexcept
Definition LayoutBuilder.h:925
TupleContents contents
The contents of the RecordArray without fields.
Definition LayoutBuilder.h:1148
std::string form() const noexcept
Definition LayoutBuilder.h:1126
Tuple()
Creates a new Tuple layout builder.
Definition LayoutBuilder.h:862
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:876
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:882
size_t length() const noexcept
Current number of records in the first index of the tuple.
Definition LayoutBuilder.h:934
void to_char_buffers(std::map< std::string, uint8_t * > &buffers) const noexcept
Definition LayoutBuilder.h:1074
TupleContentType< INDEX > & content() noexcept
Returns the reference to the builder contents at INDEX.
Definition LayoutBuilder.h:870
void set_id(size_t &id) noexcept
Definition LayoutBuilder.h:903
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:940
void buffer_nbytes(std::map< std::string, size_t > &names_nbytes) const noexcept
Definition LayoutBuilder.h:986
void to_buffer(void *buffer, const char *name) const noexcept
Definition LayoutBuilder.h:1045
void to_buffers(std::map< std::string, void * > &buffers) const noexcept
Definition LayoutBuilder.h:1016
Retrieves the names and sizes (in bytes) of the buffers used in the builder and its contents.
Definition LayoutBuilder.h:2625
BufferNBytesFunctor(std::map< std::string, size_t > &names_nbytes)
Definition LayoutBuilder.h:2628
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:2633
Discards the accumulated tags and index, and clears the builder contents.
Definition LayoutBuilder.h:2564
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:2568
Generates a unique description of the builder and its contents in the form of a JSON-like string.
Definition LayoutBuilder.h:2780
ContentsFormFunctor(std::stringstream &out, const std::map< unsigned long, std::string > &content_names)
Definition LayoutBuilder.h:2783
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:2788
Assigns a unique ID to each node.
Definition LayoutBuilder.h:2534
SetIdFunctor(size_t &id)
Definition LayoutBuilder.h:2537
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:2541
Copies and concatenates the accumulated data in the builder buffers to user-defined pointers if the g...
Definition LayoutBuilder.h:2702
ToBufferFunctor(void *buffer, const char *name)
Definition LayoutBuilder.h:2705
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:2710
Copies and concatenates all the accumulated data in each of the buffers of the builder and its conten...
Definition LayoutBuilder.h:2663
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:2671
ToBuffersFunctor(std::map< std::string, void * > &buffers)
Definition LayoutBuilder.h:2666
Copies and concatenates all the accumulated data in the builder to a map of user-allocated buffers.
Definition LayoutBuilder.h:2743
ToCharBuffersFunctor(std::map< std::string, uint8_t * > &buffers)
Definition LayoutBuilder.h:2746
void operator()(CONTENT &content) const
Definition LayoutBuilder.h:2751
Builds a UnionArray which represents data drawn from an ordered list of contents, which can have diff...
Definition LayoutBuilder.h:2465
void clear() noexcept
Definition LayoutBuilder.h:2574
Union(const awkward::BuilderOptions &options)
Creates a new Union layout builder by allocating new tags and index buffers, taking options from Buil...
Definition LayoutBuilder.h:2489
typename std::tuple< BUILDERS... > Contents
Definition LayoutBuilder.h:2467
std::tuple_element_t< I, Contents > ContentType
Definition LayoutBuilder.h:2470
ContentType< TAG > & append_content() noexcept
Inserts the current tag in the tags buffer and the next index in the index buffer and returns the ref...
Definition LayoutBuilder.h:2509
std::string form() const noexcept
Definition LayoutBuilder.h:2808
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:2523
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:2529
size_t length() const noexcept
Current length of the tags buffer.
Definition LayoutBuilder.h:2590
void to_char_buffers(std::map< std::string, uint8_t * > &buffers) const noexcept
Definition LayoutBuilder.h:2760
Union()
Creates a new Union layout builder by allocating new tags and index buffers, using AWKWARD_LAYOUTBUIL...
Definition LayoutBuilder.h:2474
ContentType< I > & content() noexcept
Definition LayoutBuilder.h:2501
void set_id(size_t &id) noexcept
Definition LayoutBuilder.h:2550
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:2596
void buffer_nbytes(std::map< std::string, size_t > &names_nbytes) const noexcept
Definition LayoutBuilder.h:2642
void to_buffer(void *buffer, const char *name) const noexcept
Definition LayoutBuilder.h:2720
void to_buffers(std::map< std::string, void * > &buffers) const noexcept
Definition LayoutBuilder.h:2680
Builds an UnmaskedArray which the values are never, in fact, missing. It exists to satisfy systems th...
Definition LayoutBuilder.h:1795
void clear() noexcept
Clears the builder content.
Definition LayoutBuilder.h:1831
Unmasked()
Creates a new Unmasked layout builder.
Definition LayoutBuilder.h:1798
std::string form() const noexcept
Generates a unique description of the builder and its contents in the form of a JSON-like string.
Definition LayoutBuilder.h:1885
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1811
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1817
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1805
size_t length() const noexcept
Current length of the content.
Definition LayoutBuilder.h:1837
void to_char_buffers(std::map< std::string, uint8_t * > &buffers) const noexcept
Copies and concatenates all the accumulated data in the builder to a map of user-allocated buffers.
Definition LayoutBuilder.h:1878
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1823
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1843
void buffer_nbytes(std::map< std::string, size_t > &names_nbytes) const noexcept
Retrieves the names and sizes (in bytes) of the buffers used in the builder and its contents.
Definition LayoutBuilder.h:1850
void to_buffer(void *buffer, const char *name) const noexcept
Copies and concatenates the accumulated data in the buffers of the builder content to user-defined po...
Definition LayoutBuilder.h:1869
void to_buffers(std::map< std::string, void * > &buffers) const noexcept
Copies and concatenates all the accumulated data in each of the buffers of the builder and its conten...
Definition LayoutBuilder.h:1861
Definition ArrayBuilder.h:14
void visit_at(std::tuple< CONTENTs... > const &contents, size_t index, FUNCTION fun)
Visits the tuple contents at index.
Definition utils.h:263
Container for all configuration options needed by ArrayBuilder, GrowableBuffer, LayoutBuilder and the...
Definition BuilderOptions.h:20
std::map< std::size_t, std::string > UserDefinedMap
Definition test_1494-layout-builder.cpp:39