All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
LayoutBuilder.h
Go to the documentation of this file.
1// BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE
2
3#ifndef AWKWARD_LAYOUTBUILDER_H_
4#define AWKWARD_LAYOUTBUILDER_H_
5
8#include "awkward/utils.h"
9
10#include <map>
11#include <algorithm>
12#include <tuple>
13#include <string>
14#include <functional>
15
16namespace awkward {
17
18 namespace LayoutBuilder {
19
23
31 template <std::size_t ENUM, typename BUILDER>
32 class Field {
33 public:
34 using Builder = BUILDER;
35
37 std::string
39 return std::to_string(index);
40 }
41
43 const std::size_t index = ENUM;
46 };
47
54 template <typename PRIMITIVE>
55 class Numpy {
56 public:
60 : data_(
62 size_t id = 0;
63 set_id(id);
64 }
65
72 : data_(awkward::GrowableBuffer<PRIMITIVE>(options)) {
73 size_t id = 0;
74 set_id(id);
75 }
76
78 void
79 append(PRIMITIVE x) noexcept {
80 data_.append(x);
81 }
82
86 void
87 extend(PRIMITIVE* ptr, size_t size) noexcept {
88 data_.extend(ptr, size);
89 }
90
92 const std::string&
93 parameters() const noexcept {
94 return parameters_;
95 }
96
98 void
99 set_parameters(std::string parameter) noexcept {
100 parameters_ = parameter;
101 }
102
104 void
105 set_id(size_t& id) noexcept {
106 id_ = id;
107 id++;
108 }
109
111 void
112 clear() noexcept {
113 data_.clear();
114 }
115
117 size_t
118 length() const noexcept {
119 return data_.length();
120 }
121
123 bool
124 is_valid(std::string& /* error */) const noexcept {
125 return true;
126 }
127
129 void
130 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
131 noexcept {
132 names_nbytes["node" + std::to_string(id_) + "-data"] = data_.nbytes();
133 }
134
140 void
141 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
142 data_.concatenate(reinterpret_cast<PRIMITIVE*>(
143 buffers["node" + std::to_string(id_) + "-data"]));
144 }
145
150 void
151 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
152 data_.concatenate(reinterpret_cast<PRIMITIVE*>(
153 buffers["node" + std::to_string(id_) + "-data"]));
154 }
155
158 std::string
159 form() const {
160 std::stringstream form_key;
161 form_key << "node" << id_;
162
163 std::string params("");
164 if (parameters_ == "") {
165 } else {
166 params = std::string(", \"parameters\": { " + parameters_ + " }");
167 }
168
169 if (std::is_arithmetic<PRIMITIVE>::value) {
170 return "{ \"class\": \"NumpyArray\", \"primitive\": \"" +
171 type_to_name<PRIMITIVE>() + "\"" + params +
172 ", \"form_key\": \"" + form_key.str() + "\" }";
174 return "{ \"class\": \"NumpyArray\", \"primitive\": \"" +
175 type_to_name<PRIMITIVE>() + "\"" + params +
176 ", \"form_key\": \"" + form_key.str() + "\" }";
177 } else {
178 throw std::runtime_error("type " +
179 std::string(typeid(PRIMITIVE).name()) +
180 "is not supported");
181 }
182 }
183
184 private:
187
189 std::string parameters_;
190
192 size_t id_;
193 };
194
209 template <typename PRIMITIVE, typename BUILDER>
211 public:
215 : offsets_(
217 offsets_.append(0);
218 size_t id = 0;
219 set_id(id);
220 }
221
228 : offsets_(awkward::GrowableBuffer<PRIMITIVE>(options)) {
229 offsets_.append(0);
230 size_t id = 0;
231 set_id(id);
232 }
233
235 BUILDER&
236 content() noexcept {
237 return content_;
238 }
239
241 BUILDER&
242 begin_list() noexcept {
243 return content_;
244 }
245
248 void
249 end_list() noexcept {
250 offsets_.append(content_.length());
251 }
252
254 const std::string&
255 parameters() const noexcept {
256 return parameters_;
257 }
258
260 void
261 set_parameters(std::string parameter) noexcept {
262 parameters_ = parameter;
263 }
264
266 void
267 set_id(size_t& id) noexcept {
268 id_ = id;
269 id++;
270 content_.set_id(id);
271 }
272
274 void
275 clear() noexcept {
276 offsets_.clear();
277 offsets_.append(0);
278 content_.clear();
279 }
280
282 size_t
283 length() const noexcept {
284 return offsets_.length() - 1;
285 }
286
288 bool
289 is_valid(std::string& error) const noexcept {
290 if ((int64_t)content_.length() != (int64_t)offsets_.last()) {
291 std::stringstream out;
292 out << "ListOffset node" << id_ << "has content length "
293 << content_.length() << "but last offset " << offsets_.last()
294 << "\n";
295 error.append(out.str());
296
297 return false;
298 } else {
299 return content_.is_valid(error);
300 }
301 }
302
305 void
306 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
307 noexcept {
308 names_nbytes["node" + std::to_string(id_) + "-offsets"] =
309 offsets_.nbytes();
310 content_.buffer_nbytes(names_nbytes);
311 }
312
318 void
319 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
320 offsets_.concatenate(reinterpret_cast<PRIMITIVE*>(
321 buffers["node" + std::to_string(id_) + "-offsets"]));
322 content_.to_buffers(buffers);
323 }
324
329 void
330 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
331 offsets_.concatenate(reinterpret_cast<PRIMITIVE*>(
332 buffers["node" + std::to_string(id_) + "-offsets"]));
333 content_.to_char_buffers(buffers);
334 }
335
338 std::string
339 form() const noexcept {
340 std::stringstream form_key;
341 form_key << "node" << id_;
342 std::string params("");
343 if (parameters_ == "") {
344 } else {
345 params = std::string(", \"parameters\": { " + parameters_ + " }");
346 }
347 return "{ \"class\": \"ListOffsetArray\", \"offsets\": \"" +
348 type_to_numpy_like<PRIMITIVE>() +
349 "\", \"content\": " + content_.form() + params +
350 ", \"form_key\": \"" + form_key.str() + "\" }";
351 }
352
353 private:
358
360 BUILDER content_;
361
363 std::string parameters_;
364
366 size_t id_;
367 };
368
381 template <typename PRIMITIVE, typename BUILDER>
382 class List {
383 public:
387 : starts_(
389 stops_(
391 size_t id = 0;
392 set_id(id);
393 }
394
401 : starts_(awkward::GrowableBuffer<PRIMITIVE>(options)),
402 stops_(awkward::GrowableBuffer<PRIMITIVE>(options)) {
403 size_t id = 0;
404 set_id(id);
405 }
406
408 BUILDER&
409 content() noexcept {
410 return content_;
411 }
412
416 BUILDER&
417 begin_list() noexcept {
418 starts_.append(content_.length());
419 return content_;
420 }
421
424 void
425 end_list() noexcept {
426 stops_.append(content_.length());
427 }
428
430 const std::string&
431 parameters() const noexcept {
432 return parameters_;
433 }
434
436 void
437 set_parameters(std::string parameter) noexcept {
438 parameters_ = parameter;
439 }
440
442 void
443 set_id(size_t& id) noexcept {
444 id_ = id;
445 id++;
446 content_.set_id(id);
447 }
448
451 void
452 clear() noexcept {
453 starts_.clear();
454 stops_.clear();
455 content_.clear();
456 }
457
459 size_t
460 length() const noexcept {
461 return starts_.length();
462 }
463
465 bool
466 is_valid(std::string& error) const noexcept {
467 if (starts_.length() != stops_.length()) {
468 std::stringstream out;
469 out << "List node" << id_ << " has starts length " << starts_.length()
470 << " but stops length " << stops_.length() << "\n";
471 error.append(out.str());
472
473 return false;
474 } else if (stops_.length() > 0 && content_.length() != stops_.last()) {
475 std::stringstream out;
476 out << "List node" << id_ << " has content length "
477 << content_.length() << " but last stops " << stops_.last()
478 << "\n";
479 error.append(out.str());
480
481 return false;
482 } else {
483 return content_.is_valid(error);
484 }
485 }
486
489 void
490 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
491 noexcept {
492 names_nbytes["node" + std::to_string(id_) + "-starts"] =
493 starts_.nbytes();
494 names_nbytes["node" + std::to_string(id_) + "-stops"] = stops_.nbytes();
495 content_.buffer_nbytes(names_nbytes);
496 }
497
503 void
504 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
505 starts_.concatenate(reinterpret_cast<PRIMITIVE*>(
506 buffers["node" + std::to_string(id_) + "-starts"]));
507 stops_.concatenate(reinterpret_cast<PRIMITIVE*>(
508 buffers["node" + std::to_string(id_) + "-stops"]));
509 content_.to_buffers(buffers);
510 }
511
516 void
517 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
518 starts_.concatenate(reinterpret_cast<PRIMITIVE*>(
519 buffers["node" + std::to_string(id_) + "-starts"]));
520 stops_.concatenate(reinterpret_cast<PRIMITIVE*>(
521 buffers["node" + std::to_string(id_) + "-stops"]));
522 content_.to_char_buffers(buffers);
523 }
524
527 std::string
528 form() const noexcept {
529 std::stringstream form_key;
530 form_key << "node" << id_;
531 std::string params("");
532 if (parameters_ == "") {
533 } else {
534 params = std::string(", \"parameters\": { " + parameters_ + " }");
535 }
536 return "{ \"class\": \"ListArray\", \"starts\": \"" +
537 type_to_numpy_like<PRIMITIVE>() + "\", \"stops\": \"" +
538 type_to_numpy_like<PRIMITIVE>() +
539 "\", \"content\": " + content_.form() + params +
540 ", \"form_key\": \"" + form_key.str() + "\" }";
541 }
542
543 private:
548
553
555 BUILDER content_;
556
558 std::string parameters_;
559
561 size_t id_;
562 };
563
568 class Empty {
569 public:
572 size_t id = 0;
573 set_id(id);
574 }
575
577 const std::string&
578 parameters() const noexcept {
579 return parameters_;
580 }
581
583 void
584 set_parameters(std::string parameter) noexcept {
585 parameters_ = parameter;
586 }
587
588 void
589 set_id(size_t& /* id */) noexcept {}
590
591 void
592 clear() noexcept {}
593
595 size_t
596 length() const noexcept {
597 return 0;
598 }
599
601 bool
602 is_valid(std::string& /* error */) const noexcept {
603 return true;
604 }
605
606 void
607 buffer_nbytes(std::map<std::string, size_t>& /* names_nbytes */) const
608 noexcept {}
609
610 void
611 to_buffers(std::map<std::string, void*>& /* buffers */) const noexcept {}
612
617 void
618 to_char_buffers(std::map<std::string, uint8_t*>& /* buffers */) const noexcept {}
619
622 std::string
623 form() const noexcept {
624 std::string params("");
625 if (parameters_ == "") {
626 } else {
627 params = std::string(", \"parameters\": { " + parameters_ + " }");
628 }
629 return "{ \"class\": \"EmptyArray\"" + params + " }";
630 }
631
632 private:
634 std::string parameters_;
635
637 size_t id_;
638 };
639
648 template <bool IS_TUPLE>
650 public:
652 EmptyRecord() : length_(0) {
653 size_t id = 0;
654 set_id(id);
655 }
656
658 void
659 append() noexcept {
660 length_++;
661 }
662
666 void
667 extend(size_t size) noexcept {
668 length_ += size;
669 }
670
672 const std::string&
673 parameters() const noexcept {
674 return parameters_;
675 }
676
678 void
679 set_parameters(std::string parameter) noexcept {
680 parameters_ = parameter;
681 }
682
684 void
685 set_id(size_t& id) noexcept {
686 id_ = id;
687 id++;
688 }
689
691 void
692 clear() noexcept {
693 length_ = 0;
694 }
695
697 size_t
698 length() const noexcept {
699 return length_;
700 }
701
703 bool
704 is_valid(std::string& /* error */) const noexcept {
705 return true;
706 }
707
708 void
709 buffer_nbytes(std::map<std::string, size_t>& /* names_nbytes */) const
710 noexcept {}
711
712 void
713 to_buffers(std::map<std::string, void*>& /* buffers */) const noexcept {}
714
719 void
720 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {}
721
724 std::string
725 form() const noexcept {
726 std::stringstream form_key;
727 form_key << "node" << id_;
728 std::string params("");
729 if (parameters_ == "") {
730 } else {
731 params = std::string(", \"parameters\": { " + parameters_ + " }");
732 }
733
734 if (is_tuple_) {
735 return "{ \"class\": \"RecordArray\", \"contents\": []" + params +
736 ", \"form_key\": \"" + form_key.str() + "\" }";
737 } else {
738 return "{ \"class\": \"RecordArray\", \"contents\": {}" + params +
739 ", \"form_key\": \"" + form_key.str() + "\" }";
740 }
741 }
742
743 private:
745 std::string parameters_;
746
748 size_t id_;
749
751 size_t length_;
752
757 bool is_tuple_ = IS_TUPLE;
758 };
759
769 template <class MAP = std::map<std::size_t, std::string>,
770 typename... BUILDERS>
771 class Record {
772 public:
773 using RecordContents = typename std::tuple<BUILDERS...>;
774 using UserDefinedMap = MAP;
775
776 template <std::size_t INDEX>
777 using RecordFieldType = std::tuple_element_t<INDEX, RecordContents>;
778
781 size_t id = 0;
782 set_id(id);
783 map_fields(std::index_sequence_for<BUILDERS...>());
784 }
785
792 Record(UserDefinedMap user_defined_field_id_to_name_map)
793 : content_names_(user_defined_field_id_to_name_map) {
794 assert(content_names_.size() == fields_count_);
795 size_t id = 0;
796 set_id(id);
797 }
798
800 const std::vector<std::string>
801 field_names() const noexcept {
802 if (content_names_.empty()) {
803 return field_names_;
804 } else {
805 std::vector<std::string> result;
806 for (auto it : content_names_) {
807 result.emplace_back(it.second);
808 }
809 return result;
810 }
811 }
812
817 void
818 set_field_names(MAP user_defined_field_id_to_name_map) noexcept {
819 content_names_ = user_defined_field_id_to_name_map;
820 }
821
823 template <std::size_t INDEX>
824 typename RecordFieldType<INDEX>::Builder&
825 field() noexcept {
826 return std::get<INDEX>(contents).builder;
827 }
828
830 const std::string&
831 parameters() const noexcept {
832 return parameters_;
833 }
834
836 void
837 set_parameters(std::string parameter) noexcept {
838 parameters_ = parameter;
839 }
840
842 void
843 set_id(size_t& id) noexcept {
844 id_ = id;
845 id++;
846 for (size_t i = 0; i < fields_count_; i++) {
847 visit_at(contents, i, [&id](auto& content) {
848 content.builder.set_id(id);
849 });
850 }
851 }
852
857 void
858 clear() noexcept {
859 for (size_t i = 0; i < fields_count_; i++)
860 visit_at(contents, i, [](auto& content) {
861 content.builder.clear();
862 });
863 }
864
866 size_t
867 length() const noexcept {
868 return (std::get<0>(contents).builder.length());
869 }
870
872 bool
873 is_valid(std::string& error) const noexcept {
874 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
875
876 int64_t length = -1;
877 std::vector<size_t> lengths = field_lengths(index_sequence);
878 for (size_t i = 0; i < lengths.size(); i++) {
879 if (length == -1) {
880 length = lengths[i];
881 }
882 else if (length != (int64_t)lengths[i]) {
883 std::stringstream out;
884 out << "Record node" << id_ << " has field \""
885 << field_names().at(i) << "\" length " << lengths[i]
886 << " that differs from the first length " << length << "\n";
887 error.append(out.str());
888
889 return false;
890 }
891 }
892
893 std::vector<bool> valid_fields = field_is_valid(index_sequence, error);
894 return std::none_of(std::cbegin(valid_fields),
895 std::cend(valid_fields),
896 std::logical_not<bool>());
897 }
898
901 void
902 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
903 noexcept {
904 for (size_t i = 0; i < fields_count_; i++)
905 visit_at(contents, i, [&names_nbytes](auto& content) {
906 content.builder.buffer_nbytes(names_nbytes);
907 });
908 }
909
915 void
916 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
917 for (size_t i = 0; i < fields_count_; i++)
918 visit_at(contents, i, [&buffers](auto& content) {
919 content.builder.to_buffers(buffers);
920 });
921 }
922
927 void
928 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
929 for (size_t i = 0; i < fields_count_; i++)
930 visit_at(contents, i, [&buffers](auto& content) {
931 content.builder.to_char_buffers(buffers);
932 });
933 }
934
937 std::string
938 form() const noexcept {
939 std::stringstream form_key;
940 form_key << "node" << id_;
941 std::string params("");
942 if (parameters_ == "") {
943 } else {
944 params = std::string("\"parameters\": { " + parameters_ + " }, ");
945 }
946 std::stringstream out;
947 out << "{ \"class\": \"RecordArray\", \"contents\": { ";
948 for (size_t i = 0; i < fields_count_; i++) {
949 if (i != 0) {
950 out << ", ";
951 }
952 auto contents_form = [&](auto& content) {
953 out << "\""
954 << (!content_names_.empty() ? content_names_.at(content.index)
955 : content.index_as_field())
956 << +"\": ";
957 out << content.builder.form();
958 };
959 visit_at(contents, i, contents_form);
960 }
961 out << " }, ";
962 out << params << "\"form_key\": \"" << form_key.str() << "\" }";
963 return out.str();
964 }
965
968
969 private:
972 template <std::size_t... S>
973 void
974 map_fields(std::index_sequence<S...>) noexcept {
975 field_names_ = std::vector<std::string>(
976 {std::string(std::get<S>(contents).index_as_field())...});
977 }
978
981 template <std::size_t... S>
982 std::vector<size_t>
983 field_lengths(std::index_sequence<S...>) const noexcept {
984 return std::vector<size_t>({std::get<S>(contents).builder.length()...});
985 }
986
988 template <std::size_t... S>
989 std::vector<bool>
990 field_is_valid(std::index_sequence<S...>, std::string& error) const
991 noexcept {
992 return std::vector<bool>(
993 {std::get<S>(contents).builder.is_valid(error)...});
994 }
995
997 std::vector<std::string> field_names_;
998
1000 UserDefinedMap content_names_;
1001
1003 std::string parameters_;
1004
1006 size_t id_;
1007
1009 static constexpr size_t fields_count_ = sizeof...(BUILDERS);
1010 };
1011
1018 template <typename... BUILDERS>
1019 class Tuple {
1020 using TupleContents = typename std::tuple<BUILDERS...>;
1021
1022 template <std::size_t INDEX>
1023 using TupleContentType = std::tuple_element_t<INDEX, TupleContents>;
1024
1025 public:
1028 size_t id = 0;
1029 set_id(id);
1030 }
1031
1033 template <std::size_t INDEX>
1034 TupleContentType<INDEX>&
1035 index() noexcept {
1036 return std::get<INDEX>(contents);
1037 }
1038
1040 const std::string&
1041 parameters() const noexcept {
1042 return parameters_;
1043 }
1044
1046 void
1047 set_parameters(std::string parameter) noexcept {
1048 parameters_ = parameter;
1049 }
1050
1052 void
1053 set_id(size_t& id) noexcept {
1054 id_ = id;
1055 id++;
1056 for (size_t i = 0; i < fields_count_; i++) {
1057 visit_at(contents, i, [&id](auto& content) {
1058 content.set_id(id);
1059 });
1060 }
1061 }
1062
1066 void
1067 clear() noexcept {
1068 for (size_t i = 0; i < fields_count_; i++)
1069 visit_at(contents, i, [](auto& content) {
1070 content.clear();
1071 });
1072 }
1073
1075 size_t
1076 length() const noexcept {
1077 return (std::get<0>(contents).length());
1078 }
1079
1081 bool
1082 is_valid(std::string& error) const noexcept {
1083 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
1084
1085 int64_t length = -1;
1086 std::vector<size_t> lengths = content_lengths(index_sequence);
1087 for (size_t i = 0; i < lengths.size(); i++) {
1088 if (length == -1) {
1089 length = (int64_t)lengths[i];
1090 }
1091 else if (length != (int64_t)lengths[i]) {
1092 std::stringstream out;
1093 out << "Record node" << id_ << " has index \"" << i << "\" length "
1094 << lengths[i] << " that differs from the first length "
1095 << length << "\n";
1096 error.append(out.str());
1097
1098 return false;
1099 }
1100 }
1101
1102 std::vector<bool> valid_fields =
1103 content_is_valid(index_sequence, error);
1104 return std::none_of(std::cbegin(valid_fields),
1105 std::cend(valid_fields),
1106 std::logical_not<bool>());
1107 }
1108
1111 void
1112 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1113 noexcept {
1114 for (size_t i = 0; i < fields_count_; i++)
1115 visit_at(contents, i, [&names_nbytes](auto& content) {
1116 content.buffer_nbytes(names_nbytes);
1117 });
1118 }
1119
1125 void
1126 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1127 for (size_t i = 0; i < fields_count_; i++)
1128 visit_at(contents, i, [&buffers](auto& content) {
1129 content.to_buffers(buffers);
1130 });
1131 }
1132
1137 void
1138 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1139 for (size_t i = 0; i < fields_count_; i++)
1140 visit_at(contents, i, [&buffers](auto& content) {
1141 content.to_char_buffers(buffers);
1142 });
1143 }
1144
1147 std::string
1148 form() const noexcept {
1149 std::stringstream form_key;
1150 form_key << "node" << id_;
1151 std::string params("");
1152 if (parameters_ == "") {
1153 } else {
1154 params = std::string("\"parameters\": { " + parameters_ + " }, ");
1155 }
1156 std::stringstream out;
1157 out << "{ \"class\": \"RecordArray\", \"contents\": [";
1158 for (size_t i = 0; i < fields_count_; i++) {
1159 if (i != 0) {
1160 out << ", ";
1161 }
1162 auto contents_form = [&out](auto& content) {
1163 out << content.form();
1164 };
1165 visit_at(contents, i, contents_form);
1166 }
1167 out << "], ";
1168 out << params << "\"form_key\": \"" << form_key.str() << "\" }";
1169 return out.str();
1170 }
1171
1173 TupleContents contents;
1174
1175 private:
1178 template <std::size_t... S>
1179 std::vector<size_t>
1180 content_lengths(std::index_sequence<S...>) const noexcept {
1181 return std::vector<size_t>({std::get<S>(contents).length()...});
1182 }
1183
1185 template <std::size_t... S>
1186 std::vector<bool>
1187 content_is_valid(std::index_sequence<S...>, std::string& error) const
1188 noexcept {
1189 return std::vector<bool>({std::get<S>(contents).is_valid(error)...});
1190 }
1191
1193 std::vector<int64_t> field_index_;
1194
1196 std::string parameters_;
1197
1199 size_t id_;
1200
1202 static constexpr size_t fields_count_ = sizeof...(BUILDERS);
1203 };
1204
1218 template <unsigned SIZE, typename BUILDER>
1219 class Regular {
1220 public:
1222 Regular() : length_(0) {
1223 size_t id = 0;
1224 set_id(id);
1225 }
1226
1228 BUILDER&
1229 content() noexcept {
1230 return content_;
1231 }
1232
1235 BUILDER&
1236 begin_list() noexcept {
1237 return content_;
1238 }
1239
1241 void
1242 end_list() noexcept {
1243 length_++;
1244 }
1245
1247 const std::string&
1248 parameters() const noexcept {
1249 return parameters_;
1250 }
1251
1253 void
1254 set_parameters(std::string parameter) noexcept {
1255 parameters_ = parameter;
1256 }
1257
1259 void
1260 set_id(size_t& id) noexcept {
1261 id_ = id;
1262 id++;
1263 content_.set_id(id);
1264 }
1265
1267 void
1268 clear() noexcept {
1269 length_ = 0;
1270 content_.clear();
1271 }
1272
1274 size_t
1275 length() const noexcept {
1276 return length_;
1277 }
1278
1280 bool
1281 is_valid(std::string& error) const noexcept {
1282 if (content_.length() != length_ * size_) {
1283 std::stringstream out;
1284 out << "Regular node" << id_ << "has content length "
1285 << content_.length() << ", but length " << length_ << " and size "
1286 << size_ << "\n";
1287 error.append(out.str());
1288
1289 return false;
1290 } else {
1291 return content_.is_valid(error);
1292 }
1293 }
1294
1297 void
1298 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1299 noexcept {
1300 content_.buffer_nbytes(names_nbytes);
1301 }
1302
1308 void
1309 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1310 content_.to_buffers(buffers);
1311 }
1312
1317 void
1318 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1319 content_.to_char_buffers(buffers);
1320 }
1321
1324 std::string
1325 form() const noexcept {
1326 std::stringstream form_key;
1327 form_key << "node" << id_;
1328 std::string params("");
1329 if (parameters_ == "") {
1330 } else {
1331 params = std::string(", \"parameters\": { " + parameters_ + " }");
1332 }
1333 return "{ \"class\": \"RegularArray\", \"content\": " +
1334 content_.form() + ", \"size\": " + std::to_string(size_) +
1335 params + ", \"form_key\": \"" + form_key.str() + "\" }";
1336 }
1337
1338 private:
1340 BUILDER content_;
1341
1343 std::string parameters_;
1344
1346 size_t id_;
1347
1349 size_t length_;
1350
1352 size_t size_ = SIZE;
1353 };
1354
1365 template <typename PRIMITIVE, typename BUILDER>
1366 class Indexed {
1367 public:
1371 : index_(
1373 last_valid_(-1) {
1374 size_t id = 0;
1375 set_id(id);
1376 }
1377
1384 : index_(awkward::GrowableBuffer<PRIMITIVE>(options)),
1385 last_valid_(-1) {
1386 size_t id = 0;
1387 set_id(id);
1388 }
1389
1391 BUILDER&
1392 content() noexcept {
1393 return content_;
1394 }
1395
1398 BUILDER&
1399 append_index() noexcept {
1400 last_valid_ = content_.length();
1401 index_.append(last_valid_);
1402 return content_;
1403 }
1404
1409 BUILDER&
1410 extend_index(size_t size) noexcept {
1411 size_t start = content_.length();
1412 size_t stop = start + size;
1413 last_valid_ = stop - 1;
1414 for (size_t i = start; i < stop; i++) {
1415 index_.append(i);
1416 }
1417 return content_;
1418 }
1419
1421 const std::string&
1422 parameters() const noexcept {
1423 return parameters_;
1424 }
1425
1427 void
1428 set_parameters(std::string parameter) noexcept {
1429 parameters_ = parameter;
1430 }
1431
1433 void
1434 set_id(size_t& id) noexcept {
1435 id_ = id;
1436 id++;
1437 content_.set_id(id);
1438 }
1439
1442 void
1443 clear() noexcept {
1444 last_valid_ = -1;
1445 index_.clear();
1446 content_.clear();
1447 }
1448
1450 size_t
1451 length() const noexcept {
1452 return index_.length();
1453 }
1454
1456 bool
1457 is_valid(std::string& error) const noexcept {
1458 if (content_.length() != index_.length()) {
1459 std::stringstream out;
1460 out << "Indexed node" << id_ << " has content length "
1461 << content_.length() << " but index length " << index_.length()
1462 << "\n";
1463 error.append(out.str());
1464
1465 return false;
1466 } else if (content_.length() != last_valid_ + 1) {
1467 std::stringstream out;
1468 out << "Indexed node" << id_ << " has content length "
1469 << content_.length() << " but last valid index is " << last_valid_
1470 << "\n";
1471 error.append(out.str());
1472
1473 return false;
1474 } else {
1475 return content_.is_valid(error);
1476 }
1477 }
1478
1481 void
1482 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1483 noexcept {
1484 names_nbytes["node" + std::to_string(id_) + "-index"] = index_.nbytes();
1485 content_.buffer_nbytes(names_nbytes);
1486 }
1487
1493 void
1494 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1495 index_.concatenate(reinterpret_cast<PRIMITIVE*>(
1496 buffers["node" + std::to_string(id_) + "-index"]));
1497 content_.to_buffers(buffers);
1498 }
1499
1504 void
1505 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1506 index_.concatenate(reinterpret_cast<PRIMITIVE*>(
1507 buffers["node" + std::to_string(id_) + "-index"]));
1508 content_.to_char_buffers(buffers);
1509 }
1510
1513 std::string
1514 form() const noexcept {
1515 std::stringstream form_key;
1516 form_key << "node" << id_;
1517 std::string params("");
1518 if (parameters_ == "") {
1519 } else {
1520 params = std::string(", \"parameters\": { " + parameters_ + " }");
1521 }
1522 return "{ \"class\": \"IndexedArray\", \"index\": \"" +
1523 type_to_numpy_like<PRIMITIVE>() +
1524 "\", \"content\": " + content_.form() + params +
1525 ", \"form_key\": \"" + form_key.str() + "\" }";
1526 }
1527
1528 private:
1533
1535 BUILDER content_;
1536
1538 std::string parameters_;
1539
1541 size_t id_;
1542
1544 size_t last_valid_;
1545 };
1546
1557 template <typename PRIMITIVE, typename BUILDER>
1559 public:
1563 : index_(
1565 last_valid_(-1) {
1566 size_t id = 0;
1567 set_id(id);
1568 }
1569
1576 : index_(awkward::GrowableBuffer<PRIMITIVE>(options)),
1577 last_valid_(-1) {
1578 size_t id = 0;
1579 set_id(id);
1580 }
1581
1583 BUILDER&
1584 content() noexcept {
1585 return content_;
1586 }
1587
1590 BUILDER&
1591 append_index() noexcept {
1592 last_valid_ = content_.length();
1593 index_.append(last_valid_);
1594 return content_;
1595 }
1596
1601 BUILDER&
1602 extend_index(size_t size) noexcept {
1603 size_t start = content_.length();
1604 size_t stop = start + size;
1605 last_valid_ = stop - 1;
1606 for (size_t i = start; i < stop; i++) {
1607 index_.append(i);
1608 }
1609 return content_;
1610 }
1611
1613 void
1614 append_null() noexcept {
1615 index_.append(-1);
1616 }
1617
1621 void
1622 extend_null(size_t size) noexcept {
1623 for (size_t i = 0; i < size; i++) {
1624 index_.append(-1);
1625 }
1626 }
1627
1629 const std::string&
1630 parameters() const noexcept {
1631 return parameters_;
1632 }
1633
1635 void
1636 set_parameters(std::string parameter) noexcept {
1637 parameters_ = parameter;
1638 }
1639
1641 void
1642 set_id(size_t& id) noexcept {
1643 id_ = id;
1644 id++;
1645 content_.set_id(id);
1646 }
1647
1650 void
1651 clear() noexcept {
1652 last_valid_ = -1;
1653 index_.clear();
1654 content_.clear();
1655 }
1656
1658 size_t
1659 length() const noexcept {
1660 return index_.length();
1661 }
1662
1664 bool
1665 is_valid(std::string& error) const noexcept {
1666 if (content_.length() != last_valid_ + 1) {
1667 std::stringstream out;
1668 out << "IndexedOption node" << id_ << " has content length "
1669 << content_.length() << " but last valid index is " << last_valid_
1670 << "\n";
1671 error.append(out.str());
1672
1673 return false;
1674 } else {
1675 return content_.is_valid(error);
1676 }
1677 }
1678
1681 void
1682 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1683 noexcept {
1684 names_nbytes["node" + std::to_string(id_) + "-index"] = index_.nbytes();
1685 content_.buffer_nbytes(names_nbytes);
1686 }
1687
1693 void
1694 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1695 index_.concatenate(reinterpret_cast<PRIMITIVE*>(
1696 buffers["node" + std::to_string(id_) + "-index"]));
1697 content_.to_buffers(buffers);
1698 }
1699
1704 void
1705 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1706 index_.concatenate(reinterpret_cast<PRIMITIVE*>(
1707 buffers["node" + std::to_string(id_) + "-index"]));
1708 content_.to_char_buffers(buffers);
1709 }
1710
1713 std::string
1714 form() const noexcept {
1715 std::stringstream form_key;
1716 form_key << "node" << id_;
1717 std::string params("");
1718 if (parameters_ == "") {
1719 } else {
1720 params = std::string(", \"parameters\": { " + parameters_ + " }");
1721 }
1722 return "{ \"class\": \"IndexedOptionArray\", \"index\": \"" +
1723 type_to_numpy_like<PRIMITIVE>() +
1724 "\", \"content\": " + content_.form() + params +
1725 ", \"form_key\": \"" + form_key.str() + "\" }";
1726 }
1727
1728 private:
1733
1735 BUILDER content_;
1736
1738 std::string parameters_;
1739
1741 size_t id_;
1742
1744 size_t last_valid_;
1745 };
1746
1758 template <typename BUILDER>
1759 class Unmasked {
1760 public:
1763 size_t id = 0;
1764 set_id(id);
1765 }
1766
1768 BUILDER&
1769 content() noexcept {
1770 return content_;
1771 }
1772
1776 BUILDER&
1777 append_valid() noexcept {
1778 return content_;
1779 }
1785 BUILDER&
1786 extend_valid(size_t size) noexcept {
1787 return content_;
1788 }
1789
1791 const std::string&
1792 parameters() const noexcept {
1793 return parameters_;
1794 }
1795
1797 void
1798 set_parameters(std::string parameter) noexcept {
1799 parameters_ = parameter;
1800 }
1801
1803 void
1804 set_id(size_t& id) noexcept {
1805 id_ = id;
1806 id++;
1807 content_.set_id(id);
1808 }
1809
1811 void
1812 clear() noexcept {
1813 content_.clear();
1814 }
1815
1817 size_t
1818 length() const noexcept {
1819 return content_.length();
1820 }
1821
1823 bool
1824 is_valid(std::string& error) const noexcept {
1825 return content_.is_valid(error);
1826 }
1827
1830 void
1831 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1832 noexcept {
1833 content_.buffer_nbytes(names_nbytes);
1834 }
1835
1841 void
1842 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1843 content_.to_buffers(buffers);
1844 }
1845
1850 void
1851 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1852 content_.to_char_buffers(buffers);
1853 }
1854
1857 std::string
1858 form() const noexcept {
1859 std::stringstream form_key;
1860 form_key << "node" << id_;
1861 std::string params("");
1862 if (parameters_ == "") {
1863 } else {
1864 params = std::string(", \"parameters\": { " + parameters_ + " }");
1865 }
1866 return "{ \"class\": \"UnmaskedArray\", \"content\": " +
1867 content_.form() + params + ", \"form_key\": \"" +
1868 form_key.str() + "\" }";
1869 }
1870
1871 private:
1873 BUILDER content_;
1874
1876 std::string parameters_;
1877
1879 size_t id_;
1880 };
1881
1898 template <bool VALID_WHEN, typename BUILDER>
1900 public:
1904 : mask_(awkward::GrowableBuffer<int8_t>(default_options)) {
1905 size_t id = 0;
1906 set_id(id);
1907 }
1908
1915 : mask_(awkward::GrowableBuffer<int8_t>(options)) {
1916 size_t id = 0;
1917 set_id(id);
1918 }
1919
1921 BUILDER&
1922 content() noexcept {
1923 return content_;
1924 }
1925
1927 bool
1928 valid_when() const noexcept {
1929 return valid_when_;
1930 }
1931
1935 BUILDER&
1936 append_valid() noexcept {
1937 mask_.append(valid_when_);
1938 return content_;
1939 }
1940
1946 BUILDER&
1947 extend_valid(size_t size) noexcept {
1948 for (size_t i = 0; i < size; i++) {
1949 mask_.append(valid_when_);
1950 }
1951 return content_;
1952 }
1953
1957 BUILDER&
1958 append_null() noexcept {
1959 mask_.append(!valid_when_);
1960 return content_;
1961 }
1962
1968 BUILDER&
1969 extend_null(size_t size) noexcept {
1970 for (size_t i = 0; i < size; i++) {
1971 mask_.append(!valid_when_);
1972 }
1973 return content_;
1974 }
1975
1977 const std::string&
1978 parameters() const noexcept {
1979 return parameters_;
1980 }
1981
1983 void
1984 set_parameters(std::string parameter) noexcept {
1985 parameters_ = parameter;
1986 }
1987
1989 void
1990 set_id(size_t& id) noexcept {
1991 id_ = id;
1992 id++;
1993 content_.set_id(id);
1994 }
1995
1998 void
1999 clear() noexcept {
2000 mask_.clear();
2001 content_.clear();
2002 }
2003
2005 size_t
2006 length() const noexcept {
2007 return mask_.length();
2008 }
2009
2011 bool
2012 is_valid(std::string& error) const noexcept {
2013 if (content_.length() != mask_.length()) {
2014 std::stringstream out;
2015 out << "ByteMasked node" << id_ << "has content length "
2016 << content_.length() << "but mask length " << mask_.length()
2017 << "\n";
2018 error.append(out.str());
2019
2020 return false;
2021 } else {
2022 return content_.is_valid(error);
2023 }
2024 }
2025
2028 void
2029 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
2030 noexcept {
2031 names_nbytes["node" + std::to_string(id_) + "-mask"] = mask_.nbytes();
2032 content_.buffer_nbytes(names_nbytes);
2033 }
2034
2040 void
2041 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
2042 mask_.concatenate(reinterpret_cast<int8_t*>(
2043 buffers["node" + std::to_string(id_) + "-mask"]));
2044 content_.to_buffers(buffers);
2045 }
2046
2051 void
2052 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
2053 mask_.concatenate(reinterpret_cast<int8_t*>(
2054 buffers["node" + std::to_string(id_) + "-mask"]));
2055 content_.to_char_buffers(buffers);
2056 }
2057
2060 std::string
2061 form() const noexcept {
2062 std::stringstream form_key, form_valid_when;
2063 form_key << "node" << id_;
2064 form_valid_when << std::boolalpha << valid_when_;
2065 std::string params("");
2066 if (parameters_ == "") {
2067 } else {
2068 params = std::string(", \"parameters\": { " + parameters_ + " }");
2069 }
2070 return "{ \"class\": \"ByteMaskedArray\", \"mask\": \"i8\", "
2071 "\"content\": " +
2072 content_.form() + ", \"valid_when\": " + form_valid_when.str() +
2073 params + ", \"form_key\": \"" + form_key.str() + "\" }";
2074 }
2075
2076 private:
2081
2083 BUILDER content_;
2084
2086 std::string parameters_;
2087
2089 size_t id_;
2090
2092 bool valid_when_ = VALID_WHEN;
2093 };
2094
2111 template <bool VALID_WHEN, bool LSB_ORDER, typename BUILDER>
2113 public:
2117 : mask_(awkward::GrowableBuffer<uint8_t>(default_options)),
2118 current_byte_(uint8_t(0)),
2119 current_byte_ref_(mask_.append_and_get_ref(current_byte_)),
2120 current_index_(0) {
2121 size_t id = 0;
2122 set_id(id);
2123 if (lsb_order_) {
2124 for (size_t i = 0; i < 8; i++) {
2125 cast_[i] = 1 << i;
2126 }
2127 } else {
2128 for (size_t i = 0; i < 8; i++) {
2129 cast_[i] = 128 >> i;
2130 }
2131 }
2132 }
2133
2140 : mask_(awkward::GrowableBuffer<uint8_t>(options)),
2141 current_byte_(uint8_t(0)),
2142 current_byte_ref_(mask_.append_and_get_ref(current_byte_)),
2143 current_index_(0) {
2144 size_t id = 0;
2145 set_id(id);
2146 if (lsb_order_) {
2147 for (size_t i = 0; i < 8; i++) {
2148 cast_[i] = 1 << i;
2149 }
2150 } else {
2151 for (size_t i = 0; i < 8; i++) {
2152 cast_[i] = 128 >> i;
2153 }
2154 }
2155 }
2156
2158 BUILDER&
2159 content() noexcept {
2160 return content_;
2161 }
2162
2164 bool
2165 valid_when() const noexcept {
2166 return valid_when_;
2167 }
2168
2171 bool
2172 lsb_order() const noexcept {
2173 return lsb_order_;
2174 }
2175
2180 BUILDER&
2181 append_valid() noexcept {
2182 append_begin();
2183 current_byte_ |= cast_[current_index_];
2184 append_end();
2185 return content_;
2186 }
2187
2194 BUILDER&
2195 extend_valid(size_t size) noexcept {
2196 for (size_t i = 0; i < size; i++) {
2197 append_valid();
2198 }
2199 return content_;
2200 }
2201
2205 BUILDER&
2206 append_null() noexcept {
2207 append_begin();
2208 append_end();
2209 return content_;
2210 }
2211
2217 BUILDER&
2218 extend_null(size_t size) noexcept {
2219 for (size_t i = 0; i < size; i++) {
2220 append_null();
2221 }
2222 return content_;
2223 }
2224
2226 const std::string&
2227 parameters() const noexcept {
2228 return parameters_;
2229 }
2230
2232 void
2233 set_parameters(std::string parameter) noexcept {
2234 parameters_ = parameter;
2235 }
2236
2238 void
2239 set_id(size_t& id) noexcept {
2240 id_ = id;
2241 id++;
2242 content_.set_id(id);
2243 }
2244
2247 void
2248 clear() noexcept {
2249 mask_.clear();
2250 content_.clear();
2251 current_byte_ = 0;
2252 current_byte_ref_ = mask_.append_and_get_ref(current_byte_);
2253 current_index_ = 0;
2254 }
2255
2257 size_t
2258 length() const noexcept {
2259 return mask_.length() > 0 ?
2260 (mask_.length() - 1) * 8 + current_index_ : current_index_;
2261 }
2262
2264 bool
2265 is_valid(std::string& error) const noexcept {
2266 if (content_.length() != length()) {
2267 std::stringstream out;
2268 out << "BitMasked node" << id_ << "has content length "
2269 << content_.length() << "but bit mask length " << mask_.length()
2270 << "\n";
2271 error.append(out.str());
2272
2273 return false;
2274 } else {
2275 return content_.is_valid(error);
2276 }
2277 }
2278
2281 void
2282 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
2283 noexcept {
2284 names_nbytes["node" + std::to_string(id_) + "-mask"] = mask_.nbytes();
2285 content_.buffer_nbytes(names_nbytes);
2286 }
2287
2293 void
2294 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
2295 mask_.concatenate_from(reinterpret_cast<uint8_t*>(
2296 buffers["node" + std::to_string(id_) + "-mask"]), 0, 1);
2297 mask_.append(reinterpret_cast<uint8_t*>(
2298 buffers["node" + std::to_string(id_) + "-mask"]), mask_.length() - 1, 0, 1);
2299 content_.to_buffers(buffers);
2300 }
2301
2306 void
2307 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
2308 mask_.concatenate_from(reinterpret_cast<uint8_t*>(
2309 buffers["node" + std::to_string(id_) + "-mask"]), 0, 1);
2310 mask_.append(reinterpret_cast<uint8_t*>(
2311 buffers["node" + std::to_string(id_) + "-mask"]), mask_.length() - 1, 0, 1);
2312 content_.to_char_buffers(buffers);
2313 }
2314
2317 std::string
2318 form() const noexcept {
2319 std::stringstream form_key, form_valid_when, form_lsb_order;
2320 form_key << "node" << id_;
2321 form_valid_when << std::boolalpha << valid_when_;
2322 form_lsb_order << std::boolalpha << lsb_order_;
2323 std::string params("");
2324 if (parameters_ == "") {
2325 } else {
2326 params = std::string(", \"parameters\": { " + parameters_ + " }");
2327 }
2328 return "{ \"class\": \"BitMaskedArray\", \"mask\": \"u8\", "
2329 "\"content\": " +
2330 content_.form() + ", \"valid_when\": " + form_valid_when.str() +
2331 ", \"lsb_order\": " + form_lsb_order.str() + params +
2332 ", \"form_key\": \"" + form_key.str() + "\" }";
2333 }
2334
2335 private:
2339 void
2340 append_begin() {
2341 if (current_index_ == 8) {
2342 current_byte_ref_ = mask_.append_and_get_ref(current_byte_);
2343 current_byte_ = uint8_t(0);
2344 current_index_ = 0;
2345 }
2346 }
2347
2353 void
2354 append_end() {
2355 current_index_ += 1;
2356 if (valid_when_) {
2357 current_byte_ref_ = current_byte_;
2358 } else {
2359 current_byte_ref_ = ~current_byte_;
2360 }
2361 }
2362
2366 GrowableBuffer<uint8_t> mask_;
2367
2369 BUILDER content_;
2370
2372 std::string parameters_;
2373
2375 size_t id_;
2376
2378 uint8_t current_byte_;
2379
2381 uint8_t& current_byte_ref_;
2382
2384 size_t current_index_;
2385
2387 uint8_t cast_[8];
2388
2390 bool valid_when_ = VALID_WHEN;
2391
2394 bool lsb_order_ = LSB_ORDER;
2395 };
2396
2412 template <typename TAGS, typename INDEX, typename... BUILDERS>
2413 class Union {
2414 public:
2415 using Contents = typename std::tuple<BUILDERS...>;
2416
2417 template <std::size_t I>
2418 using ContentType = std::tuple_element_t<I, Contents>;
2419
2423 : tags_(awkward::GrowableBuffer<TAGS>(default_options)),
2424 index_(awkward::GrowableBuffer<INDEX>(default_options)) {
2425 size_t id = 0;
2426 set_id(id);
2427 for (size_t i = 0; i < contents_count_; i++)
2428 last_valid_index_[i] = -1;
2429 }
2430
2437 : tags_(awkward::GrowableBuffer<TAGS>(options)),
2438 index_(awkward::GrowableBuffer<INDEX>(options)) {
2439 size_t id = 0;
2440 set_id(id);
2441 for (size_t i = 0; i < contents_count_; i++)
2442 last_valid_index_[i] = -1;
2443 }
2444
2445 template <std::size_t I>
2446 ContentType<I>&
2447 content() noexcept {
2448 return std::get<I>(contents_);
2449 }
2450
2453 template <std::size_t TAG>
2454 ContentType<TAG>&
2455 append_index() noexcept {
2456 auto& which_content = std::get<TAG>(contents_);
2457 INDEX next_index = which_content.length();
2458
2459 TAGS tag = (TAGS)TAG;
2460 last_valid_index_[tag] = next_index;
2461 tags_.append(tag);
2462 index_.append(next_index);
2463
2464 return which_content;
2465 }
2466
2468 const std::string&
2469 parameters() const noexcept {
2470 return parameters_;
2471 }
2472
2474 void
2475 set_parameters(std::string parameter) noexcept {
2476 parameters_ = parameter;
2477 }
2478
2480 void
2481 set_id(size_t& id) noexcept {
2482 id_ = id;
2483 id++;
2484 auto contents_id = [&id](auto& content) {
2485 content.set_id(id);
2486 };
2487 for (size_t i = 0; i < contents_count_; i++)
2488 visit_at(contents_, i, contents_id);
2489 }
2490
2495 void
2496 clear() noexcept {
2497 for (size_t i = 0; i < contents_count_; i++)
2498 last_valid_index_[i] = -1;
2499 tags_.clear();
2500 index_.clear();
2501 auto clear_contents = [](auto& content) {
2502 content.clear();
2503 };
2504 for (size_t i = 0; i < contents_count_; i++)
2505 visit_at(contents_, i, clear_contents);
2506 }
2507
2509 size_t
2510 length() const noexcept {
2511 return tags_.length();
2512 }
2513
2515 bool
2516 is_valid(std::string& error) const noexcept {
2517 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
2518
2519 std::vector<size_t> lengths = content_lengths(index_sequence);
2520 for (size_t tag = 0; tag < contents_count_; tag++) {
2521 if (lengths[tag] != last_valid_index_[tag] + 1) {
2522 std::stringstream out;
2523 out << "Union node" << id_ << " has content length " << lengths[tag]
2524 << " but index length " << last_valid_index_[tag] << "\n";
2525 error.append(out.str());
2526
2527 return false;
2528 }
2529 }
2530
2531 std::vector<bool> valid_contents =
2532 content_is_valid(index_sequence, error);
2533 return std::none_of(std::cbegin(valid_contents),
2534 std::cend(valid_contents),
2535 std::logical_not<bool>());
2536 }
2537
2540 void
2541 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
2542 noexcept {
2543 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
2544
2545 names_nbytes["node" + std::to_string(id_) + "-tags"] = tags_.nbytes();
2546 names_nbytes["node" + std::to_string(id_) + "-index"] = index_.nbytes();
2547
2548 for (size_t i = 0; i < contents_count_; i++)
2549 visit_at(contents_, i, [&names_nbytes](auto& content) {
2550 content.buffer_nbytes(names_nbytes);
2551 });
2552 }
2553
2559 void
2560 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
2561 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
2562
2563 tags_.concatenate(reinterpret_cast<TAGS*>(
2564 buffers["node" + std::to_string(id_) + "-tags"]));
2565 index_.concatenate(reinterpret_cast<INDEX*>(
2566 buffers["node" + std::to_string(id_) + "-index"]));
2567
2568 for (size_t i = 0; i < contents_count_; i++)
2569 visit_at(contents_, i, [&buffers](auto& content) {
2570 content.to_buffers(buffers);
2571 });
2572 }
2573
2578 void
2579 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
2580 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
2581
2582 tags_.concatenate(reinterpret_cast<TAGS*>(
2583 buffers["node" + std::to_string(id_) + "-tags"]));
2584 index_.concatenate(reinterpret_cast<INDEX*>(
2585 buffers["node" + std::to_string(id_) + "-index"]));
2586
2587 for (size_t i = 0; i < contents_count_; i++)
2588 visit_at(contents_, i, [&buffers](auto& content) {
2589 content.to_char_buffers(buffers);
2590 });
2591 }
2592
2595 std::string
2596 form() const noexcept {
2597 std::stringstream form_key;
2598 form_key << "node" << id_;
2599 std::string params("");
2600 if (parameters_ == "") {
2601 } else {
2602 params = std::string(", \"parameters\": { " + parameters_ + " }");
2603 }
2604 std::stringstream out;
2605 out << "{ \"class\": \"UnionArray\", \"tags\": \"" +
2606 type_to_numpy_like<TAGS>() + "\", \"index\": \"" +
2607 type_to_numpy_like<INDEX>() + "\", \"contents\": [";
2608 for (size_t i = 0; i < contents_count_; i++) {
2609 if (i != 0) {
2610 out << ", ";
2611 }
2612 auto contents_form = [&](auto& content) {
2613 out << content.form();
2614 };
2615 visit_at(contents_, i, contents_form);
2616 }
2617 out << "], ";
2618 out << params << "\"form_key\": \"" << form_key.str() << "\" }";
2619 return out.str();
2620 }
2621
2622 private:
2625 template <std::size_t... S>
2626 std::vector<size_t>
2627 content_lengths(std::index_sequence<S...>) const {
2628 return std::vector<size_t>({std::get<S>(contents_).length()...});
2629 }
2630
2632 template <std::size_t... S>
2633 std::vector<bool>
2634 content_is_valid(std::index_sequence<S...>, std::string& error) const {
2635 return std::vector<bool>({std::get<S>(contents_).is_valid(error)...});
2636 }
2637
2641 GrowableBuffer<TAGS> tags_;
2642
2646 GrowableBuffer<INDEX> index_;
2647
2649 Contents contents_;
2650
2652 std::string parameters_;
2653
2655 size_t id_;
2656
2658 size_t last_valid_index_[sizeof...(BUILDERS)];
2659
2661 static constexpr size_t contents_count_ = sizeof...(BUILDERS);
2662 };
2663
2664 } // namespace LayoutBuilder
2665} // namespace awkward
2666
2667#endif // AWKWARD_LAYOUTBUILDER_H_
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:2112
bool valid_when() const noexcept
Determines when the builder content are valid.
Definition LayoutBuilder.h:2165
void clear() noexcept
Discards the accumulated mask and clears the content of the builder.
Definition LayoutBuilder.h:2248
bool lsb_order() const noexcept
Determines whether the position of each bit is in Least-Significant Bit order (LSB) or not.
Definition LayoutBuilder.h:2172
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:2195
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:2318
BUILDER & extend_null(size_t size) noexcept
Sets current_byte_ and cast_ default to null, no change in current_byte_.
Definition LayoutBuilder.h:2218
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:2227
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:2233
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:2159
size_t length() const noexcept
Current length of the mask buffer.
Definition LayoutBuilder.h:2258
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:2307
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:2239
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:2265
BitMasked(const awkward::BuilderOptions &options)
Creates a new BitMasked layout builder by allocating a new mask buffer, taking options from BuilderOp...
Definition LayoutBuilder.h:2139
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:2181
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:2282
BitMasked()
Creates a new BitMasked layout builder by allocating a new mask buffer, using default_options for ini...
Definition LayoutBuilder.h:2116
BUILDER & append_null() noexcept
Sets current_byte_ and cast_ default to null, no change in current_byte_.
Definition LayoutBuilder.h:2206
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:2294
Builds a ByteMaskedArray using a mask which is an array of booleans that determines whether the corre...
Definition LayoutBuilder.h:1899
bool valid_when() const noexcept
Determines when the builder content are valid.
Definition LayoutBuilder.h:1928
void clear() noexcept
Discards the accumulated mask and clears the content of the builder.
Definition LayoutBuilder.h:1999
BUILDER & extend_valid(size_t size) noexcept
Inserts size number of valid_when in the mask.
Definition LayoutBuilder.h:1947
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:2061
BUILDER & extend_null(size_t size) noexcept
Inserts size number of !valid_when in the mask.
Definition LayoutBuilder.h:1969
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1978
ByteMasked()
Creates a new ByteMasked layout builder by allocating a new mask buffer, using default_options for in...
Definition LayoutBuilder.h:1903
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1984
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1922
ByteMasked(const awkward::BuilderOptions &options)
Creates a new ByteMasked layout builder by allocating a new mask buffer, taking options from BuilderO...
Definition LayoutBuilder.h:1914
size_t length() const noexcept
Current length of the mask buffer.
Definition LayoutBuilder.h:2006
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:2052
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1990
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:2012
BUILDER & append_valid() noexcept
Inserts valid_when in the mask.
Definition LayoutBuilder.h:1936
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:2029
BUILDER & append_null() noexcept
Inserts !valid_when in the mask.
Definition LayoutBuilder.h:1958
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:2041
Builds an Empty RecordArray which has has zero contents. It still represents a non-empty array....
Definition LayoutBuilder.h:649
void clear() noexcept
Clears the builder contents, the length returns to zero.
Definition LayoutBuilder.h:692
bool is_valid(std::string &) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:704
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:725
void to_buffers(std::map< std::string, void * > &) const noexcept
Definition LayoutBuilder.h:713
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:673
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:679
void append() noexcept
Inserts an empty record.
Definition LayoutBuilder.h:659
size_t length() const noexcept
Current number of records.
Definition LayoutBuilder.h:698
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:720
void buffer_nbytes(std::map< std::string, size_t > &) const noexcept
Definition LayoutBuilder.h:709
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:685
void extend(size_t size) noexcept
Inserts size number of empty records.
Definition LayoutBuilder.h:667
EmptyRecord()
Creates a new EmptyRecord layout builder.
Definition LayoutBuilder.h:652
Builds an EmptyArray which has no content in it. It is used whenever an array's type is not known bec...
Definition LayoutBuilder.h:568
void clear() noexcept
Definition LayoutBuilder.h:592
bool is_valid(std::string &) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:602
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:623
void to_buffers(std::map< std::string, void * > &) const noexcept
Definition LayoutBuilder.h:611
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:578
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:584
Empty()
Creates a new Empty layout builder.
Definition LayoutBuilder.h:571
void set_id(size_t &) noexcept
Definition LayoutBuilder.h:589
size_t length() const noexcept
Current length of the content.
Definition LayoutBuilder.h:596
void buffer_nbytes(std::map< std::string, size_t > &) const noexcept
Definition LayoutBuilder.h:607
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:618
Helper class for sending a pair of field names (as enum) and field type as template parameters in Rec...
Definition LayoutBuilder.h:32
std::string index_as_field() const
Converts index as field string.
Definition LayoutBuilder.h:38
BUILDER Builder
Definition LayoutBuilder.h:34
const std::size_t index
The index of a Record field.
Definition LayoutBuilder.h:43
Builder builder
The content type of field in a Record.
Definition LayoutBuilder.h:45
Builds an IndexedOptionArray which consists of an index buffer. The negative values in the index are ...
Definition LayoutBuilder.h:1558
void clear() noexcept
Discards the accumulated index and clears the content of the builder. Also, last valid returns to -1.
Definition LayoutBuilder.h:1651
void extend_null(size_t size) noexcept
Inserts -1 in the index buffer size number of times.
Definition LayoutBuilder.h:1622
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:1714
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1630
BUILDER & append_index() noexcept
Inserts the last valid index in the index buffer and returns the reference to the builder content.
Definition LayoutBuilder.h:1591
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1636
IndexedOption(const awkward::BuilderOptions &options)
Creates a new IndexedOption layout builder by allocating a new index buffer, taking options from Buil...
Definition LayoutBuilder.h:1575
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1584
BUILDER & extend_index(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:1602
size_t length() const noexcept
Current length of the index buffer.
Definition LayoutBuilder.h:1659
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:1705
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1642
void append_null() noexcept
Inserts -1 in the index buffer.
Definition LayoutBuilder.h:1614
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1665
IndexedOption()
Creates a new IndexedOption layout builder by allocating a new index buffer, using default_options fo...
Definition LayoutBuilder.h:1562
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:1682
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:1694
Builds an IndexedArray which consists of an index buffer. It is a general-purpose tool for changing t...
Definition LayoutBuilder.h:1366
void clear() noexcept
Discards the accumulated index and clears the content of the builder. Also, last valid returns to -1.
Definition LayoutBuilder.h:1443
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:1514
Indexed(const awkward::BuilderOptions &options)
Creates a new Indexed layout builder by allocating a new index buffer, taking options from BuilderOpt...
Definition LayoutBuilder.h:1383
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1422
Indexed()
Creates a new Indexed layout builder by allocating a new index buffer, using default_options for init...
Definition LayoutBuilder.h:1370
BUILDER & append_index() noexcept
Inserts the last valid index in the index buffer and returns the reference to the builder content.
Definition LayoutBuilder.h:1399
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1428
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1392
BUILDER & extend_index(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:1410
size_t length() const noexcept
Current length of the content and the index buffer.
Definition LayoutBuilder.h:1451
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:1505
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1434
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1457
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:1482
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:1494
Builds a ListOffsetArray which describes unequal-length lists (often called a "jagged" or "ragged" ar...
Definition LayoutBuilder.h:210
void clear() noexcept
Discards the accumulated offsets and clears the builder content.
Definition LayoutBuilder.h:275
BUILDER & begin_list() noexcept
Begins a list and returns the reference to the builder content.
Definition LayoutBuilder.h:242
ListOffset()
Creates a new ListOffset layout builder by allocating a new offset buffer, using default_options for ...
Definition LayoutBuilder.h:214
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:339
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:255
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:261
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:236
size_t length() const noexcept
Current length of the content.
Definition LayoutBuilder.h:283
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:330
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:267
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:289
void end_list() noexcept
Ends a list and appends the current length of the list contents in the offsets buffer.
Definition LayoutBuilder.h:249
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:306
ListOffset(const awkward::BuilderOptions &options)
Creates a new ListOffset layout builder by allocating a new offset buffer, taking options from Builde...
Definition LayoutBuilder.h:227
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:319
Builds a ListArray which generalizes ListOffsetArray. Instead of a single offsets array,...
Definition LayoutBuilder.h:382
void clear() noexcept
Discards the accumulated starts and stops, and clears the builder content.
Definition LayoutBuilder.h:452
BUILDER & begin_list() noexcept
Begins a list, appends the current length of the list contents in the starts buffer and returns the r...
Definition LayoutBuilder.h:417
List()
Creates a new List layout builder by allocating new starts and stops buffer, using default_options fo...
Definition LayoutBuilder.h:386
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:528
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:431
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:437
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:409
size_t length() const noexcept
Current length of the content and starts buffer.
Definition LayoutBuilder.h:460
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:517
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:443
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:466
void end_list() noexcept
Ends a list and appends the current length of the list contents in the stops buffer.
Definition LayoutBuilder.h:425
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:490
List(const awkward::BuilderOptions &options)
Creates a new List layout builder by allocating new starts and stops buffer, taking options from Buil...
Definition LayoutBuilder.h:400
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:504
Builds a NumpyArray which describes multi-dimensional data of PRIMITIVE type.
Definition LayoutBuilder.h:55
void clear() noexcept
Discards the accumulated data in the builder.
Definition LayoutBuilder.h:112
bool is_valid(std::string &) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:124
Numpy(const awkward::BuilderOptions &options)
Creates a new Numpy layout builder by allocating a new buffer, taking options from BuilderOptions for...
Definition LayoutBuilder.h:71
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:93
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:99
size_t length() const noexcept
Current length of the data.
Definition LayoutBuilder.h:118
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:151
void append(PRIMITIVE x) noexcept
Inserts a PRIMITIVE type data.
Definition LayoutBuilder.h:79
Numpy()
Creates a new Numpy layout builder by allocating a new buffer, using default_options for initializing...
Definition LayoutBuilder.h:59
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:105
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:130
void extend(PRIMITIVE *ptr, size_t size) noexcept
Inserts an entire array of PRIMITIVE type data.
Definition LayoutBuilder.h:87
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:141
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:159
Builds a RecordArray which represents an array of records, which can be of same or different types....
Definition LayoutBuilder.h:771
void clear() noexcept
Clears the builder contents.
Definition LayoutBuilder.h:858
Record()
Creates a new Record layout builder.
Definition LayoutBuilder.h:780
MAP UserDefinedMap
Definition LayoutBuilder.h:774
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:938
std::tuple_element_t< INDEX, RecordContents > RecordFieldType
Definition LayoutBuilder.h:777
const std::vector< std::string > field_names() const noexcept
Returns a vector of strings sontaining all the field names.
Definition LayoutBuilder.h:801
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:792
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:831
typename std::tuple< BUILDERS... > RecordContents
Definition LayoutBuilder.h:773
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:837
void set_field_names(MAP user_defined_field_id_to_name_map) noexcept
Sets the field names.
Definition LayoutBuilder.h:818
size_t length() const noexcept
Current number of records in first field.
Definition LayoutBuilder.h:867
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:928
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:843
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:873
RecordFieldType< INDEX >::Builder & field() noexcept
Returns the reference to the builder contents at INDEX.
Definition LayoutBuilder.h:825
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:902
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:916
RecordContents contents
The contents of the RecordArray.
Definition LayoutBuilder.h:967
Builds a RegularArray that describes lists that have the same length, a single integer size....
Definition LayoutBuilder.h:1219
void clear() noexcept
Clears the builder content.
Definition LayoutBuilder.h:1268
BUILDER & begin_list() noexcept
Begins a list and returns the reference to the content of the builder.
Definition LayoutBuilder.h:1236
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:1325
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1248
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1254
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1229
size_t length() const noexcept
Current number of lists of length SIZE.
Definition LayoutBuilder.h:1275
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:1318
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1260
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1281
void end_list() noexcept
Ends a list and increments the number of lists.
Definition LayoutBuilder.h:1242
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:1298
Regular()
Creates a new Regular layout builder.
Definition LayoutBuilder.h:1222
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:1309
Builds a RecordArray which represents an array of tuples which can be of same or different types with...
Definition LayoutBuilder.h:1019
void clear() noexcept
Clears the builder contents.
Definition LayoutBuilder.h:1067
TupleContents contents
The contents of the RecordArray without fields.
Definition LayoutBuilder.h:1173
TupleContentType< INDEX > & index() noexcept
Returns the reference to the builder contents at INDEX.
Definition LayoutBuilder.h:1035
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:1148
Tuple()
Creates a new Tuple layout builder.
Definition LayoutBuilder.h:1027
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1041
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1047
size_t length() const noexcept
Current number of records in the first index of the tuple.
Definition LayoutBuilder.h:1076
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:1138
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1053
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1082
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:1112
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:1126
Builds a UnionArray which represents data drawn from an ordered list of contents, which can have diff...
Definition LayoutBuilder.h:2413
void clear() noexcept
Discards the accumulated tags and index, and clears the builder contents.
Definition LayoutBuilder.h:2496
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:2436
typename std::tuple< BUILDERS... > Contents
Definition LayoutBuilder.h:2415
std::tuple_element_t< I, Contents > ContentType
Definition LayoutBuilder.h:2418
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:2596
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:2469
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:2475
size_t length() const noexcept
Current length of the tags buffer.
Definition LayoutBuilder.h:2510
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:2579
Union()
Creates a new Union layout builder by allocating new tags and index buffers, using default_options fo...
Definition LayoutBuilder.h:2422
ContentType< I > & content() noexcept
Definition LayoutBuilder.h:2447
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:2481
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:2516
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:2541
ContentType< TAG > & append_index() noexcept
Inserts the current tag in the tags buffer and the next index in the index buffer and returns the ref...
Definition LayoutBuilder.h:2455
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:2560
Builds an UnmaskedArray which the values are never, in fact, missing. It exists to satisfy systems th...
Definition LayoutBuilder.h:1759
void clear() noexcept
Clears the builder content.
Definition LayoutBuilder.h:1812
Unmasked()
Creates a new Unmasked layout builder.
Definition LayoutBuilder.h:1762
BUILDER & extend_valid(size_t size) noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1786
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:1858
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1792
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1798
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1769
size_t length() const noexcept
Current length of the content.
Definition LayoutBuilder.h:1818
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:1851
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1804
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1824
BUILDER & append_valid() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1777
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:1831
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:1842
awkward::BuilderOptions default_options(1024, 1)
Object of BuilderOptions which sets the values of the default options.
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:262
Container for all configuration options needed by ArrayBuilder, GrowableBuffer, LayoutBuilder and the...
Definition BuilderOptions.h:20
Definition utils.h:167
std::map< std::size_t, std::string > UserDefinedMap
Definition test_1494-layout-builder.cpp:39