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
18#define AWKWARD_LAYOUTBUILDER_DEFAULT_OPTIONS awkward::BuilderOptions(1024, 1)
19
20namespace awkward {
21
22 namespace LayoutBuilder {
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
369
374 class Empty {
375 public:
378 size_t id = 0;
379 set_id(id);
380 }
381
382 void
383 set_id(size_t& /* id */) noexcept {}
384
385 void
386 clear() noexcept {}
387
389 size_t
390 length() const noexcept {
391 return 0;
392 }
393
395 bool
396 is_valid(std::string& /* error */) const noexcept {
397 return true;
398 }
399
400 void
401 buffer_nbytes(std::map<std::string, size_t>& /* names_nbytes */) const
402 noexcept {}
403
404 void
405 to_buffers(std::map<std::string, void*>& /* buffers */) const noexcept {}
406
411 void
412 to_char_buffers(std::map<std::string, uint8_t*>& /* buffers */) const noexcept {}
413
416 std::string
417 form() const noexcept {
418 return "{ \"class\": \"EmptyArray\" }";
419 }
420
421 private:
423 size_t id_;
424 };
425
426
436 template <class MAP = std::map<std::size_t, std::string>,
437 typename... BUILDERS>
438 class Record {
439 public:
440 using RecordContents = typename std::tuple<BUILDERS...>;
441 using UserDefinedMap = MAP;
442
443 template <std::size_t INDEX>
444 using RecordFieldType = std::tuple_element_t<INDEX, RecordContents>;
445
448 size_t id = 0;
449 set_id(id);
450 map_fields(std::index_sequence_for<BUILDERS...>());
451 }
452
459 Record(UserDefinedMap user_defined_field_id_to_name_map)
460 : content_names_(user_defined_field_id_to_name_map) {
461 assert(content_names_.size() == fields_count_);
462 size_t id = 0;
463 set_id(id);
464 }
465
467 const std::vector<std::string>
468 fields() const noexcept {
469 if (content_names_.empty()) {
470 return fields_;
471 } else {
472 std::vector<std::string> result;
473 for (auto it : content_names_) {
474 result.emplace_back(it.second);
475 }
476 return result;
477 }
478 }
479
484 void
485 set_fields(MAP user_defined_field_id_to_name_map) noexcept {
486 content_names_ = user_defined_field_id_to_name_map;
487 }
488
490 template <std::size_t INDEX>
491 typename RecordFieldType<INDEX>::Builder&
492 content() noexcept {
493 return std::get<INDEX>(contents).builder;
494 }
495
497 const std::string&
498 parameters() const noexcept {
499 return parameters_;
500 }
501
503 void
504 set_parameters(std::string parameter) noexcept {
505 parameters_ = parameter;
506 }
507
509 void
510 set_id(size_t& id) noexcept {
511 id_ = id;
512 id++;
513 for (size_t i = 0; i < fields_count_; i++) {
514 visit_at(contents, i, [&id](auto& content) {
515 content.builder.set_id(id);
516 });
517 }
518 }
519
524 void
525 clear() noexcept {
526 for (size_t i = 0; i < fields_count_; i++)
527 visit_at(contents, i, [](auto& content) {
528 content.builder.clear();
529 });
530 }
531
533 size_t
534 length() const noexcept {
535 return (std::get<0>(contents).builder.length());
536 }
537
539 bool
540 is_valid(std::string& error) const noexcept {
541 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
542
543 int64_t length = -1;
544 std::vector<size_t> lengths = field_lengths(index_sequence);
545 for (size_t i = 0; i < lengths.size(); i++) {
546 if (length == -1) {
547 length = lengths[i];
548 }
549 else if (length != (int64_t)lengths[i]) {
550 std::stringstream out;
551 out << "Record node" << id_ << " has field \""
552 << fields().at(i) << "\" length " << lengths[i]
553 << " that differs from the first length " << length << "\n";
554 error.append(out.str());
555
556 return false;
557 }
558 }
559
560 std::vector<bool> valid_fields = field_is_valid(index_sequence, error);
561 return std::none_of(std::cbegin(valid_fields),
562 std::cend(valid_fields),
563 std::logical_not<bool>());
564 }
565
568 void
569 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
570 noexcept {
571 for (size_t i = 0; i < fields_count_; i++)
572 visit_at(contents, i, [&names_nbytes](auto& content) {
573 content.builder.buffer_nbytes(names_nbytes);
574 });
575 }
576
582 void
583 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
584 for (size_t i = 0; i < fields_count_; i++)
585 visit_at(contents, i, [&buffers](auto& content) {
586 content.builder.to_buffers(buffers);
587 });
588 }
589
594 void
595 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
596 for (size_t i = 0; i < fields_count_; i++)
597 visit_at(contents, i, [&buffers](auto& content) {
598 content.builder.to_char_buffers(buffers);
599 });
600 }
601
604 std::string
605 form() const noexcept {
606 std::stringstream form_key;
607 form_key << "node" << id_;
608 std::string params("");
609 if (parameters_ == "") {
610 } else {
611 params = std::string("\"parameters\": { " + parameters_ + " }, ");
612 }
613 std::stringstream out;
614 out << "{ \"class\": \"RecordArray\", \"contents\": { ";
615 for (size_t i = 0; i < fields_count_; i++) {
616 if (i != 0) {
617 out << ", ";
618 }
619 auto contents_form = [&](auto& content) {
620 out << "\""
621 << (!content_names_.empty() ? content_names_.at(content.index)
622 : content.index_as_field())
623 << +"\": ";
624 out << content.builder.form();
625 };
626 visit_at(contents, i, contents_form);
627 }
628 out << " }, ";
629 out << params << "\"form_key\": \"" << form_key.str() << "\" }";
630 return out.str();
631 }
632
635
636 private:
639 template <std::size_t... S>
640 void
641 map_fields(std::index_sequence<S...>) noexcept {
642 fields_ = std::vector<std::string>(
643 {std::string(std::get<S>(contents).index_as_field())...});
644 }
645
648 template <std::size_t... S>
649 std::vector<size_t>
650 field_lengths(std::index_sequence<S...>) const noexcept {
651 return std::vector<size_t>({std::get<S>(contents).builder.length()...});
652 }
653
655 template <std::size_t... S>
656 std::vector<bool>
657 field_is_valid(std::index_sequence<S...>, std::string& error) const
658 noexcept {
659 return std::vector<bool>(
660 {std::get<S>(contents).builder.is_valid(error)...});
661 }
662
664 std::vector<std::string> fields_;
665
667 UserDefinedMap content_names_;
668
670 std::string parameters_;
671
673 size_t id_;
674
676 static constexpr size_t fields_count_ = sizeof...(BUILDERS);
677 };
678
685 template <typename... BUILDERS>
686 class Tuple {
687 using TupleContents = typename std::tuple<BUILDERS...>;
688
689 template <std::size_t INDEX>
690 using TupleContentType = std::tuple_element_t<INDEX, TupleContents>;
691
692 public:
695 size_t id = 0;
696 set_id(id);
697 }
698
700 template <std::size_t INDEX>
701 TupleContentType<INDEX>&
702 content() noexcept {
703 return std::get<INDEX>(contents);
704 }
705
707 const std::string&
708 parameters() const noexcept {
709 return parameters_;
710 }
711
713 void
714 set_parameters(std::string parameter) noexcept {
715 parameters_ = parameter;
716 }
717
719 void
720 set_id(size_t& id) noexcept {
721 id_ = id;
722 id++;
723 for (size_t i = 0; i < fields_count_; i++) {
724 visit_at(contents, i, [&id](auto& content) {
725 content.set_id(id);
726 });
727 }
728 }
729
733 void
734 clear() noexcept {
735 for (size_t i = 0; i < fields_count_; i++)
736 visit_at(contents, i, [](auto& content) {
737 content.clear();
738 });
739 }
740
742 size_t
743 length() const noexcept {
744 return (std::get<0>(contents).length());
745 }
746
748 bool
749 is_valid(std::string& error) const noexcept {
750 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
751
752 int64_t length = -1;
753 std::vector<size_t> lengths = content_lengths(index_sequence);
754 for (size_t i = 0; i < lengths.size(); i++) {
755 if (length == -1) {
756 length = (int64_t)lengths[i];
757 }
758 else if (length != (int64_t)lengths[i]) {
759 std::stringstream out;
760 out << "Record node" << id_ << " has index \"" << i << "\" length "
761 << lengths[i] << " that differs from the first length "
762 << length << "\n";
763 error.append(out.str());
764
765 return false;
766 }
767 }
768
769 std::vector<bool> valid_fields =
770 content_is_valid(index_sequence, error);
771 return std::none_of(std::cbegin(valid_fields),
772 std::cend(valid_fields),
773 std::logical_not<bool>());
774 }
775
778 void
779 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
780 noexcept {
781 for (size_t i = 0; i < fields_count_; i++)
782 visit_at(contents, i, [&names_nbytes](auto& content) {
783 content.buffer_nbytes(names_nbytes);
784 });
785 }
786
792 void
793 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
794 for (size_t i = 0; i < fields_count_; i++)
795 visit_at(contents, i, [&buffers](auto& content) {
796 content.to_buffers(buffers);
797 });
798 }
799
804 void
805 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
806 for (size_t i = 0; i < fields_count_; i++)
807 visit_at(contents, i, [&buffers](auto& content) {
808 content.to_char_buffers(buffers);
809 });
810 }
811
814 std::string
815 form() const noexcept {
816 std::stringstream form_key;
817 form_key << "node" << id_;
818 std::string params("");
819 if (parameters_ == "") {
820 } else {
821 params = std::string("\"parameters\": { " + parameters_ + " }, ");
822 }
823 std::stringstream out;
824 out << "{ \"class\": \"RecordArray\", \"contents\": [";
825 for (size_t i = 0; i < fields_count_; i++) {
826 if (i != 0) {
827 out << ", ";
828 }
829 auto contents_form = [&out](auto& content) {
830 out << content.form();
831 };
832 visit_at(contents, i, contents_form);
833 }
834 out << "], ";
835 out << params << "\"form_key\": \"" << form_key.str() << "\" }";
836 return out.str();
837 }
838
840 TupleContents contents;
841
842 private:
845 template <std::size_t... S>
846 std::vector<size_t>
847 content_lengths(std::index_sequence<S...>) const noexcept {
848 return std::vector<size_t>({std::get<S>(contents).length()...});
849 }
850
852 template <std::size_t... S>
853 std::vector<bool>
854 content_is_valid(std::index_sequence<S...>, std::string& error) const
855 noexcept {
856 return std::vector<bool>({std::get<S>(contents).is_valid(error)...});
857 }
858
860 std::vector<int64_t> field_index_;
861
863 std::string parameters_;
864
866 size_t id_;
867
869 static constexpr size_t fields_count_ = sizeof...(BUILDERS);
870 };
871
885 template <unsigned SIZE, typename BUILDER>
886 class Regular {
887 public:
889 Regular() : length_(0) {
890 size_t id = 0;
891 set_id(id);
892 }
893
895 BUILDER&
896 content() noexcept {
897 return content_;
898 }
899
902 BUILDER&
903 begin_list() noexcept {
904 return content_;
905 }
906
908 void
909 end_list() noexcept {
910 length_++;
911 }
912
914 const std::string&
915 parameters() const noexcept {
916 return parameters_;
917 }
918
920 void
921 set_parameters(std::string parameter) noexcept {
922 parameters_ = parameter;
923 }
924
926 void
927 set_id(size_t& id) noexcept {
928 id_ = id;
929 id++;
930 content_.set_id(id);
931 }
932
934 void
935 clear() noexcept {
936 length_ = 0;
937 content_.clear();
938 }
939
941 size_t
942 length() const noexcept {
943 return length_;
944 }
945
947 bool
948 is_valid(std::string& error) const noexcept {
949 if (content_.length() != length_ * size_) {
950 std::stringstream out;
951 out << "Regular node" << id_ << "has content length "
952 << content_.length() << ", but length " << length_ << " and size "
953 << size_ << "\n";
954 error.append(out.str());
955
956 return false;
957 } else {
958 return content_.is_valid(error);
959 }
960 }
961
964 void
965 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
966 noexcept {
967 content_.buffer_nbytes(names_nbytes);
968 }
969
975 void
976 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
977 content_.to_buffers(buffers);
978 }
979
984 void
985 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
986 content_.to_char_buffers(buffers);
987 }
988
991 std::string
992 form() const noexcept {
993 std::stringstream form_key;
994 form_key << "node" << id_;
995 std::string params("");
996 if (parameters_ == "") {
997 } else {
998 params = std::string(", \"parameters\": { " + parameters_ + " }");
999 }
1000 return "{ \"class\": \"RegularArray\", \"content\": " +
1001 content_.form() + ", \"size\": " + std::to_string(size_) +
1002 params + ", \"form_key\": \"" + form_key.str() + "\" }";
1003 }
1004
1005 private:
1007 BUILDER content_;
1008
1010 std::string parameters_;
1011
1013 size_t id_;
1014
1016 size_t length_;
1017
1019 size_t size_ = SIZE;
1020 };
1021
1022
1033 template <typename PRIMITIVE, typename BUILDER>
1035 public:
1039 : index_(
1041 last_valid_(-1) {
1042 size_t id = 0;
1043 set_id(id);
1044 }
1045
1052 : index_(awkward::GrowableBuffer<PRIMITIVE>(options)),
1053 last_valid_(-1) {
1054 size_t id = 0;
1055 set_id(id);
1056 }
1057
1059 BUILDER&
1060 content() noexcept {
1061 return content_;
1062 }
1063
1066 BUILDER&
1067 append_valid() noexcept {
1068 last_valid_ = content_.length();
1069 index_.append(last_valid_);
1070 return content_;
1071 }
1072
1077 BUILDER&
1078 extend_valid(size_t size) noexcept {
1079 size_t start = content_.length();
1080 size_t stop = start + size;
1081 last_valid_ = stop - 1;
1082 for (size_t i = start; i < stop; i++) {
1083 index_.append(i);
1084 }
1085 return content_;
1086 }
1087
1089 void
1090 append_invalid() noexcept {
1091 index_.append(-1);
1092 }
1093
1097 void
1098 extend_invalid(size_t size) noexcept {
1099 for (size_t i = 0; i < size; i++) {
1100 index_.append(-1);
1101 }
1102 }
1103
1105 const std::string&
1106 parameters() const noexcept {
1107 return parameters_;
1108 }
1109
1111 void
1112 set_parameters(std::string parameter) noexcept {
1113 parameters_ = parameter;
1114 }
1115
1117 void
1118 set_id(size_t& id) noexcept {
1119 id_ = id;
1120 id++;
1121 content_.set_id(id);
1122 }
1123
1126 void
1127 clear() noexcept {
1128 last_valid_ = -1;
1129 index_.clear();
1130 content_.clear();
1131 }
1132
1134 size_t
1135 length() const noexcept {
1136 return index_.length();
1137 }
1138
1140 bool
1141 is_valid(std::string& error) const noexcept {
1142 if (content_.length() != last_valid_ + 1) {
1143 std::stringstream out;
1144 out << "IndexedOption node" << id_ << " has content length "
1145 << content_.length() << " but last valid index is " << last_valid_
1146 << "\n";
1147 error.append(out.str());
1148
1149 return false;
1150 } else {
1151 return content_.is_valid(error);
1152 }
1153 }
1154
1157 void
1158 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1159 noexcept {
1160 names_nbytes["node" + std::to_string(id_) + "-index"] = index_.nbytes();
1161 content_.buffer_nbytes(names_nbytes);
1162 }
1163
1169 void
1170 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1171 index_.concatenate(reinterpret_cast<PRIMITIVE*>(
1172 buffers["node" + std::to_string(id_) + "-index"]));
1173 content_.to_buffers(buffers);
1174 }
1175
1180 void
1181 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1182 index_.concatenate(reinterpret_cast<PRIMITIVE*>(
1183 buffers["node" + std::to_string(id_) + "-index"]));
1184 content_.to_char_buffers(buffers);
1185 }
1186
1189 std::string
1190 form() const noexcept {
1191 std::stringstream form_key;
1192 form_key << "node" << id_;
1193 std::string params("");
1194 if (parameters_ == "") {
1195 } else {
1196 params = std::string(", \"parameters\": { " + parameters_ + " }");
1197 }
1198 return "{ \"class\": \"IndexedOptionArray\", \"index\": \"" +
1199 type_to_numpy_like<PRIMITIVE>() +
1200 "\", \"content\": " + content_.form() + params +
1201 ", \"form_key\": \"" + form_key.str() + "\" }";
1202 }
1203
1204 private:
1209
1211 BUILDER content_;
1212
1214 std::string parameters_;
1215
1217 size_t id_;
1218
1220 size_t last_valid_;
1221 };
1222
1234 template <typename BUILDER>
1235 class Unmasked {
1236 public:
1239 size_t id = 0;
1240 set_id(id);
1241 }
1242
1244 BUILDER&
1245 content() noexcept {
1246 return content_;
1247 }
1248
1250 const std::string&
1251 parameters() const noexcept {
1252 return parameters_;
1253 }
1254
1256 void
1257 set_parameters(std::string parameter) noexcept {
1258 parameters_ = parameter;
1259 }
1260
1262 void
1263 set_id(size_t& id) noexcept {
1264 id_ = id;
1265 id++;
1266 content_.set_id(id);
1267 }
1268
1270 void
1271 clear() noexcept {
1272 content_.clear();
1273 }
1274
1276 size_t
1277 length() const noexcept {
1278 return content_.length();
1279 }
1280
1282 bool
1283 is_valid(std::string& error) const noexcept {
1284 return content_.is_valid(error);
1285 }
1286
1289 void
1290 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1291 noexcept {
1292 content_.buffer_nbytes(names_nbytes);
1293 }
1294
1300 void
1301 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1302 content_.to_buffers(buffers);
1303 }
1304
1309 void
1310 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1311 content_.to_char_buffers(buffers);
1312 }
1313
1316 std::string
1317 form() const noexcept {
1318 std::stringstream form_key;
1319 form_key << "node" << id_;
1320 std::string params("");
1321 if (parameters_ == "") {
1322 } else {
1323 params = std::string(", \"parameters\": { " + parameters_ + " }");
1324 }
1325 return "{ \"class\": \"UnmaskedArray\", \"content\": " +
1326 content_.form() + params + ", \"form_key\": \"" +
1327 form_key.str() + "\" }";
1328 }
1329
1330 private:
1332 BUILDER content_;
1333
1335 std::string parameters_;
1336
1338 size_t id_;
1339 };
1340
1357 template <bool VALID_WHEN, typename BUILDER>
1359 public:
1364 size_t id = 0;
1365 set_id(id);
1366 }
1367
1374 : mask_(awkward::GrowableBuffer<int8_t>(options)) {
1375 size_t id = 0;
1376 set_id(id);
1377 }
1378
1380 BUILDER&
1381 content() noexcept {
1382 return content_;
1383 }
1384
1386 bool
1387 valid_when() const noexcept {
1388 return valid_when_;
1389 }
1390
1394 BUILDER&
1395 append_valid() noexcept {
1396 mask_.append(valid_when_);
1397 return content_;
1398 }
1399
1405 BUILDER&
1406 extend_valid(size_t size) noexcept {
1407 for (size_t i = 0; i < size; i++) {
1408 mask_.append(valid_when_);
1409 }
1410 return content_;
1411 }
1412
1416 BUILDER&
1417 append_invalid() noexcept {
1418 mask_.append(!valid_when_);
1419 return content_;
1420 }
1421
1427 BUILDER&
1428 extend_invalid(size_t size) noexcept {
1429 for (size_t i = 0; i < size; i++) {
1430 mask_.append(!valid_when_);
1431 }
1432 return content_;
1433 }
1434
1436 const std::string&
1437 parameters() const noexcept {
1438 return parameters_;
1439 }
1440
1442 void
1443 set_parameters(std::string parameter) noexcept {
1444 parameters_ = parameter;
1445 }
1446
1448 void
1449 set_id(size_t& id) noexcept {
1450 id_ = id;
1451 id++;
1452 content_.set_id(id);
1453 }
1454
1457 void
1458 clear() noexcept {
1459 mask_.clear();
1460 content_.clear();
1461 }
1462
1464 size_t
1465 length() const noexcept {
1466 return mask_.length();
1467 }
1468
1470 bool
1471 is_valid(std::string& error) const noexcept {
1472 if (content_.length() != mask_.length()) {
1473 std::stringstream out;
1474 out << "ByteMasked node" << id_ << "has content length "
1475 << content_.length() << "but mask length " << mask_.length()
1476 << "\n";
1477 error.append(out.str());
1478
1479 return false;
1480 } else {
1481 return content_.is_valid(error);
1482 }
1483 }
1484
1487 void
1488 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1489 noexcept {
1490 names_nbytes["node" + std::to_string(id_) + "-mask"] = mask_.nbytes();
1491 content_.buffer_nbytes(names_nbytes);
1492 }
1493
1499 void
1500 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1501 mask_.concatenate(reinterpret_cast<int8_t*>(
1502 buffers["node" + std::to_string(id_) + "-mask"]));
1503 content_.to_buffers(buffers);
1504 }
1505
1510 void
1511 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1512 mask_.concatenate(reinterpret_cast<int8_t*>(
1513 buffers["node" + std::to_string(id_) + "-mask"]));
1514 content_.to_char_buffers(buffers);
1515 }
1516
1519 std::string
1520 form() const noexcept {
1521 std::stringstream form_key, form_valid_when;
1522 form_key << "node" << id_;
1523 form_valid_when << std::boolalpha << valid_when_;
1524 std::string params("");
1525 if (parameters_ == "") {
1526 } else {
1527 params = std::string(", \"parameters\": { " + parameters_ + " }");
1528 }
1529 return "{ \"class\": \"ByteMaskedArray\", \"mask\": \"i8\", "
1530 "\"content\": " +
1531 content_.form() + ", \"valid_when\": " + form_valid_when.str() +
1532 params + ", \"form_key\": \"" + form_key.str() + "\" }";
1533 }
1534
1535 private:
1540
1542 BUILDER content_;
1543
1545 std::string parameters_;
1546
1548 size_t id_;
1549
1551 bool valid_when_ = VALID_WHEN;
1552 };
1553
1570 template <bool VALID_WHEN, bool LSB_ORDER, typename BUILDER>
1572 public:
1577 current_byte_(uint8_t(0)),
1578 current_byte_ref_(mask_.append_and_get_ref(current_byte_)),
1579 current_index_(0) {
1580 size_t id = 0;
1581 set_id(id);
1582 if (lsb_order_) {
1583 for (size_t i = 0; i < 8; i++) {
1584 cast_[i] = 1 << i;
1585 }
1586 } else {
1587 for (size_t i = 0; i < 8; i++) {
1588 cast_[i] = 128 >> i;
1589 }
1590 }
1591 }
1592
1599 : mask_(awkward::GrowableBuffer<uint8_t>(options)),
1600 current_byte_(uint8_t(0)),
1601 current_byte_ref_(mask_.append_and_get_ref(current_byte_)),
1602 current_index_(0) {
1603 size_t id = 0;
1604 set_id(id);
1605 if (lsb_order_) {
1606 for (size_t i = 0; i < 8; i++) {
1607 cast_[i] = 1 << i;
1608 }
1609 } else {
1610 for (size_t i = 0; i < 8; i++) {
1611 cast_[i] = 128 >> i;
1612 }
1613 }
1614 }
1615
1617 BUILDER&
1618 content() noexcept {
1619 return content_;
1620 }
1621
1623 bool
1624 valid_when() const noexcept {
1625 return valid_when_;
1626 }
1627
1630 bool
1631 lsb_order() const noexcept {
1632 return lsb_order_;
1633 }
1634
1639 BUILDER&
1640 append_valid() noexcept {
1641 append_begin();
1642 current_byte_ |= cast_[current_index_];
1643 append_end();
1644 return content_;
1645 }
1646
1653 BUILDER&
1654 extend_valid(size_t size) noexcept {
1655 for (size_t i = 0; i < size; i++) {
1656 append_valid();
1657 }
1658 return content_;
1659 }
1660
1664 BUILDER&
1665 append_invalid() noexcept {
1666 append_begin();
1667 append_end();
1668 return content_;
1669 }
1670
1676 BUILDER&
1677 extend_invalid(size_t size) noexcept {
1678 for (size_t i = 0; i < size; i++) {
1680 }
1681 return content_;
1682 }
1683
1685 const std::string&
1686 parameters() const noexcept {
1687 return parameters_;
1688 }
1689
1691 void
1692 set_parameters(std::string parameter) noexcept {
1693 parameters_ = parameter;
1694 }
1695
1697 void
1698 set_id(size_t& id) noexcept {
1699 id_ = id;
1700 id++;
1701 content_.set_id(id);
1702 }
1703
1706 void
1707 clear() noexcept {
1708 mask_.clear();
1709 content_.clear();
1710 current_byte_ = 0;
1711 current_byte_ref_ = mask_.append_and_get_ref(current_byte_);
1712 current_index_ = 0;
1713 }
1714
1716 size_t
1717 length() const noexcept {
1718 return mask_.length() > 0 ?
1719 (mask_.length() - 1) * 8 + current_index_ : current_index_;
1720 }
1721
1723 bool
1724 is_valid(std::string& error) const noexcept {
1725 if (content_.length() != length()) {
1726 std::stringstream out;
1727 out << "BitMasked node" << id_ << "has content length "
1728 << content_.length() << "but bit mask length " << mask_.length()
1729 << "\n";
1730 error.append(out.str());
1731
1732 return false;
1733 } else {
1734 return content_.is_valid(error);
1735 }
1736 }
1737
1740 void
1741 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1742 noexcept {
1743 names_nbytes["node" + std::to_string(id_) + "-mask"] = mask_.nbytes();
1744 content_.buffer_nbytes(names_nbytes);
1745 }
1746
1752 void
1753 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1754 mask_.concatenate_from(reinterpret_cast<uint8_t*>(
1755 buffers["node" + std::to_string(id_) + "-mask"]), 0, 1);
1756 mask_.append(reinterpret_cast<uint8_t*>(
1757 buffers["node" + std::to_string(id_) + "-mask"]), mask_.length() - 1, 0, 1);
1758 content_.to_buffers(buffers);
1759 }
1760
1765 void
1766 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1767 mask_.concatenate_from(reinterpret_cast<uint8_t*>(
1768 buffers["node" + std::to_string(id_) + "-mask"]), 0, 1);
1769 mask_.append(reinterpret_cast<uint8_t*>(
1770 buffers["node" + std::to_string(id_) + "-mask"]), mask_.length() - 1, 0, 1);
1771 content_.to_char_buffers(buffers);
1772 }
1773
1776 std::string
1777 form() const noexcept {
1778 std::stringstream form_key, form_valid_when, form_lsb_order;
1779 form_key << "node" << id_;
1780 form_valid_when << std::boolalpha << valid_when_;
1781 form_lsb_order << std::boolalpha << lsb_order_;
1782 std::string params("");
1783 if (parameters_ == "") {
1784 } else {
1785 params = std::string(", \"parameters\": { " + parameters_ + " }");
1786 }
1787 return "{ \"class\": \"BitMaskedArray\", \"mask\": \"u8\", "
1788 "\"content\": " +
1789 content_.form() + ", \"valid_when\": " + form_valid_when.str() +
1790 ", \"lsb_order\": " + form_lsb_order.str() + params +
1791 ", \"form_key\": \"" + form_key.str() + "\" }";
1792 }
1793
1794 private:
1798 void
1799 append_begin() {
1800 if (current_index_ == 8) {
1801 current_byte_ref_ = mask_.append_and_get_ref(current_byte_);
1802 current_byte_ = uint8_t(0);
1803 current_index_ = 0;
1804 }
1805 }
1806
1812 void
1813 append_end() {
1814 current_index_ += 1;
1815 if (valid_when_) {
1816 current_byte_ref_ = current_byte_;
1817 } else {
1818 current_byte_ref_ = ~current_byte_;
1819 }
1820 }
1821
1825 GrowableBuffer<uint8_t> mask_;
1826
1828 BUILDER content_;
1829
1831 std::string parameters_;
1832
1834 size_t id_;
1835
1837 uint8_t current_byte_;
1838
1840 uint8_t& current_byte_ref_;
1841
1843 size_t current_index_;
1844
1846 uint8_t cast_[8];
1847
1849 bool valid_when_ = VALID_WHEN;
1850
1853 bool lsb_order_ = LSB_ORDER;
1854 };
1855
1871 template <typename TAGS, typename INDEX, typename... BUILDERS>
1872 class Union {
1873 public:
1874 using Contents = typename std::tuple<BUILDERS...>;
1875
1876 template <std::size_t I>
1877 using ContentType = std::tuple_element_t<I, Contents>;
1878
1884 size_t id = 0;
1885 set_id(id);
1886 for (size_t i = 0; i < contents_count_; i++)
1887 last_valid_index_[i] = -1;
1888 }
1889
1896 : tags_(awkward::GrowableBuffer<TAGS>(options)),
1897 index_(awkward::GrowableBuffer<INDEX>(options)) {
1898 size_t id = 0;
1899 set_id(id);
1900 for (size_t i = 0; i < contents_count_; i++)
1901 last_valid_index_[i] = -1;
1902 }
1903
1904 template <std::size_t I>
1905 ContentType<I>&
1906 content() noexcept {
1907 return std::get<I>(contents_);
1908 }
1909
1912 template <std::size_t TAG>
1913 ContentType<TAG>&
1914 append_content() noexcept {
1915 auto& which_content = std::get<TAG>(contents_);
1916 INDEX next_index = which_content.length();
1917
1918 TAGS tag = (TAGS)TAG;
1919 last_valid_index_[tag] = next_index;
1920 tags_.append(tag);
1921 index_.append(next_index);
1922
1923 return which_content;
1924 }
1925
1927 const std::string&
1928 parameters() const noexcept {
1929 return parameters_;
1930 }
1931
1933 void
1934 set_parameters(std::string parameter) noexcept {
1935 parameters_ = parameter;
1936 }
1937
1939 void
1940 set_id(size_t& id) noexcept {
1941 id_ = id;
1942 id++;
1943 auto contents_id = [&id](auto& content) {
1944 content.set_id(id);
1945 };
1946 for (size_t i = 0; i < contents_count_; i++)
1947 visit_at(contents_, i, contents_id);
1948 }
1949
1954 void
1955 clear() noexcept {
1956 for (size_t i = 0; i < contents_count_; i++)
1957 last_valid_index_[i] = -1;
1958 tags_.clear();
1959 index_.clear();
1960 auto clear_contents = [](auto& content) {
1961 content.clear();
1962 };
1963 for (size_t i = 0; i < contents_count_; i++)
1964 visit_at(contents_, i, clear_contents);
1965 }
1966
1968 size_t
1969 length() const noexcept {
1970 return tags_.length();
1971 }
1972
1974 bool
1975 is_valid(std::string& error) const noexcept {
1976 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
1977
1978 std::vector<size_t> lengths = content_lengths(index_sequence);
1979 for (size_t tag = 0; tag < contents_count_; tag++) {
1980 if (lengths[tag] != last_valid_index_[tag] + 1) {
1981 std::stringstream out;
1982 out << "Union node" << id_ << " has content length " << lengths[tag]
1983 << " but index length " << last_valid_index_[tag] << "\n";
1984 error.append(out.str());
1985
1986 return false;
1987 }
1988 }
1989
1990 std::vector<bool> valid_contents =
1991 content_is_valid(index_sequence, error);
1992 return std::none_of(std::cbegin(valid_contents),
1993 std::cend(valid_contents),
1994 std::logical_not<bool>());
1995 }
1996
1999 void
2000 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
2001 noexcept {
2002 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
2003
2004 names_nbytes["node" + std::to_string(id_) + "-tags"] = tags_.nbytes();
2005 names_nbytes["node" + std::to_string(id_) + "-index"] = index_.nbytes();
2006
2007 for (size_t i = 0; i < contents_count_; i++)
2008 visit_at(contents_, i, [&names_nbytes](auto& content) {
2009 content.buffer_nbytes(names_nbytes);
2010 });
2011 }
2012
2018 void
2019 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
2020 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
2021
2022 tags_.concatenate(reinterpret_cast<TAGS*>(
2023 buffers["node" + std::to_string(id_) + "-tags"]));
2024 index_.concatenate(reinterpret_cast<INDEX*>(
2025 buffers["node" + std::to_string(id_) + "-index"]));
2026
2027 for (size_t i = 0; i < contents_count_; i++)
2028 visit_at(contents_, i, [&buffers](auto& content) {
2029 content.to_buffers(buffers);
2030 });
2031 }
2032
2037 void
2038 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
2039 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
2040
2041 tags_.concatenate(reinterpret_cast<TAGS*>(
2042 buffers["node" + std::to_string(id_) + "-tags"]));
2043 index_.concatenate(reinterpret_cast<INDEX*>(
2044 buffers["node" + std::to_string(id_) + "-index"]));
2045
2046 for (size_t i = 0; i < contents_count_; i++)
2047 visit_at(contents_, i, [&buffers](auto& content) {
2048 content.to_char_buffers(buffers);
2049 });
2050 }
2051
2054 std::string
2055 form() const noexcept {
2056 std::stringstream form_key;
2057 form_key << "node" << id_;
2058 std::string params("");
2059 if (parameters_ == "") {
2060 } else {
2061 params = std::string(", \"parameters\": { " + parameters_ + " }");
2062 }
2063 std::stringstream out;
2064 out << "{ \"class\": \"UnionArray\", \"tags\": \"" +
2065 type_to_numpy_like<TAGS>() + "\", \"index\": \"" +
2066 type_to_numpy_like<INDEX>() + "\", \"contents\": [";
2067 for (size_t i = 0; i < contents_count_; i++) {
2068 if (i != 0) {
2069 out << ", ";
2070 }
2071 auto contents_form = [&](auto& content) {
2072 out << content.form();
2073 };
2074 visit_at(contents_, i, contents_form);
2075 }
2076 out << "], ";
2077 out << params << "\"form_key\": \"" << form_key.str() << "\" }";
2078 return out.str();
2079 }
2080
2081 private:
2084 template <std::size_t... S>
2085 std::vector<size_t>
2086 content_lengths(std::index_sequence<S...>) const {
2087 return std::vector<size_t>({std::get<S>(contents_).length()...});
2088 }
2089
2091 template <std::size_t... S>
2092 std::vector<bool>
2093 content_is_valid(std::index_sequence<S...>, std::string& error) const {
2094 return std::vector<bool>({std::get<S>(contents_).is_valid(error)...});
2095 }
2096
2100 GrowableBuffer<TAGS> tags_;
2101
2105 GrowableBuffer<INDEX> index_;
2106
2108 Contents contents_;
2109
2111 std::string parameters_;
2112
2114 size_t id_;
2115
2117 size_t last_valid_index_[sizeof...(BUILDERS)];
2118
2120 static constexpr size_t contents_count_ = sizeof...(BUILDERS);
2121 };
2122
2123 } // namespace LayoutBuilder
2124} // namespace awkward
2125
2126#endif // AWKWARD_LAYOUTBUILDER_H_
#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:1571
bool valid_when() const noexcept
Determines when the builder content are valid.
Definition LayoutBuilder.h:1624
void clear() noexcept
Discards the accumulated mask and clears the content of the builder.
Definition LayoutBuilder.h:1707
bool lsb_order() const noexcept
Determines whether the position of each bit is in Least-Significant Bit order (LSB) or not.
Definition LayoutBuilder.h:1631
BUILDER & append_invalid() noexcept
Sets current_byte_ and cast_ default to null, no change in current_byte_.
Definition LayoutBuilder.h:1665
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:1654
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:1777
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1686
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1692
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1618
size_t length() const noexcept
Current length of the mask buffer.
Definition LayoutBuilder.h:1717
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:1766
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1698
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1724
BitMasked(const awkward::BuilderOptions &options)
Creates a new BitMasked layout builder by allocating a new mask buffer, taking options from BuilderOp...
Definition LayoutBuilder.h:1598
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:1640
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:1741
BUILDER & extend_invalid(size_t size) noexcept
Sets current_byte_ and cast_ default to null, no change in current_byte_.
Definition LayoutBuilder.h:1677
BitMasked()
Creates a new BitMasked layout builder by allocating a new mask buffer, using AWKWARD_LAYOUTBUILDER_D...
Definition LayoutBuilder.h:1575
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:1753
Builds a ByteMaskedArray using a mask which is an array of booleans that determines whether the corre...
Definition LayoutBuilder.h:1358
bool valid_when() const noexcept
Determines when the builder content are valid.
Definition LayoutBuilder.h:1387
void clear() noexcept
Discards the accumulated mask and clears the content of the builder.
Definition LayoutBuilder.h:1458
BUILDER & append_invalid() noexcept
Inserts !valid_when in the mask.
Definition LayoutBuilder.h:1417
BUILDER & extend_valid(size_t size) noexcept
Inserts size number of valid_when in the mask.
Definition LayoutBuilder.h:1406
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:1520
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1437
ByteMasked()
Creates a new ByteMasked layout builder by allocating a new mask buffer, using AWKWARD_LAYOUTBUILDER_...
Definition LayoutBuilder.h:1362
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1443
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1381
ByteMasked(const awkward::BuilderOptions &options)
Creates a new ByteMasked layout builder by allocating a new mask buffer, taking options from BuilderO...
Definition LayoutBuilder.h:1373
size_t length() const noexcept
Current length of the mask buffer.
Definition LayoutBuilder.h:1465
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:1511
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1449
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1471
BUILDER & append_valid() noexcept
Inserts valid_when in the mask.
Definition LayoutBuilder.h:1395
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:1488
BUILDER & extend_invalid(size_t size) noexcept
Inserts size number of !valid_when in the mask.
Definition LayoutBuilder.h:1428
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:1500
Builds an EmptyArray which has no content in it. It is used whenever an array's type is not known bec...
Definition LayoutBuilder.h:374
void clear() noexcept
Definition LayoutBuilder.h:386
bool is_valid(std::string &) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:396
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:417
void to_buffers(std::map< std::string, void * > &) const noexcept
Definition LayoutBuilder.h:405
Empty()
Creates a new Empty layout builder.
Definition LayoutBuilder.h:377
void set_id(size_t &) noexcept
Definition LayoutBuilder.h:383
size_t length() const noexcept
Current length of the content.
Definition LayoutBuilder.h:390
void buffer_nbytes(std::map< std::string, size_t > &) const noexcept
Definition LayoutBuilder.h:401
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:412
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:1034
void clear() noexcept
Discards the accumulated index and clears the content of the builder. Also, last valid returns to -1.
Definition LayoutBuilder.h:1127
void extend_invalid(size_t size) noexcept
Inserts -1 in the index buffer size number of times.
Definition LayoutBuilder.h:1098
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:1078
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:1190
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1106
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1112
IndexedOption(const awkward::BuilderOptions &options)
Creates a new IndexedOption layout builder by allocating a new index buffer, taking options from Buil...
Definition LayoutBuilder.h:1051
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1060
size_t length() const noexcept
Current length of the index buffer.
Definition LayoutBuilder.h:1135
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:1181
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1118
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1141
IndexedOption()
Creates a new IndexedOption layout builder by allocating a new index buffer, using AWKWARD_LAYOUTBUIL...
Definition LayoutBuilder.h:1038
BUILDER & append_valid() noexcept
Inserts the last valid index in the index buffer and returns the reference to the builder content.
Definition LayoutBuilder.h:1067
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:1158
void append_invalid() noexcept
Inserts -1 in the index buffer.
Definition LayoutBuilder.h:1090
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:1170
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 AWKWARD_LAYOUTBUILDE...
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 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 AWKWARD_LAYOUTBUILDER_DEFAULT_OP...
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:438
void clear() noexcept
Clears the builder contents.
Definition LayoutBuilder.h:525
Record()
Creates a new Record layout builder.
Definition LayoutBuilder.h:447
MAP UserDefinedMap
Definition LayoutBuilder.h:441
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:605
RecordFieldType< INDEX >::Builder & content() noexcept
Returns the reference to the builder contents at INDEX.
Definition LayoutBuilder.h:492
std::tuple_element_t< INDEX, RecordContents > RecordFieldType
Definition LayoutBuilder.h:444
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:459
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:498
typename std::tuple< BUILDERS... > RecordContents
Definition LayoutBuilder.h:440
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:504
size_t length() const noexcept
Current number of records in first field.
Definition LayoutBuilder.h:534
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:595
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:510
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:540
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:569
void set_fields(MAP user_defined_field_id_to_name_map) noexcept
Sets the field names.
Definition LayoutBuilder.h:485
const std::vector< std::string > fields() const noexcept
Returns a vector of strings sontaining all the field names.
Definition LayoutBuilder.h:468
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:583
RecordContents contents
The contents of the RecordArray.
Definition LayoutBuilder.h:634
Builds a RegularArray that describes lists that have the same length, a single integer size....
Definition LayoutBuilder.h:886
void clear() noexcept
Clears the builder content.
Definition LayoutBuilder.h:935
BUILDER & begin_list() noexcept
Begins a list and returns the reference to the content of the builder.
Definition LayoutBuilder.h:903
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:992
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:915
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:921
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:896
size_t length() const noexcept
Current number of lists of length SIZE.
Definition LayoutBuilder.h:942
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:985
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:927
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:948
void end_list() noexcept
Ends a list and increments the number of lists.
Definition LayoutBuilder.h:909
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:965
Regular()
Creates a new Regular layout builder.
Definition LayoutBuilder.h:889
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:976
Builds a RecordArray which represents an array of tuples which can be of same or different types with...
Definition LayoutBuilder.h:686
void clear() noexcept
Clears the builder contents.
Definition LayoutBuilder.h:734
TupleContents contents
The contents of the RecordArray without fields.
Definition LayoutBuilder.h:840
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:815
Tuple()
Creates a new Tuple layout builder.
Definition LayoutBuilder.h:694
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:708
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:714
size_t length() const noexcept
Current number of records in the first index of the tuple.
Definition LayoutBuilder.h:743
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:805
TupleContentType< INDEX > & content() noexcept
Returns the reference to the builder contents at INDEX.
Definition LayoutBuilder.h:702
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:720
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:749
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:779
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:793
Builds a UnionArray which represents data drawn from an ordered list of contents, which can have diff...
Definition LayoutBuilder.h:1872
void clear() noexcept
Discards the accumulated tags and index, and clears the builder contents.
Definition LayoutBuilder.h:1955
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:1895
typename std::tuple< BUILDERS... > Contents
Definition LayoutBuilder.h:1874
std::tuple_element_t< I, Contents > ContentType
Definition LayoutBuilder.h:1877
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:1914
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:2055
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1928
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1934
size_t length() const noexcept
Current length of the tags buffer.
Definition LayoutBuilder.h:1969
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:2038
Union()
Creates a new Union layout builder by allocating new tags and index buffers, using AWKWARD_LAYOUTBUIL...
Definition LayoutBuilder.h:1881
ContentType< I > & content() noexcept
Definition LayoutBuilder.h:1906
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1940
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1975
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:2000
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:2019
Builds an UnmaskedArray which the values are never, in fact, missing. It exists to satisfy systems th...
Definition LayoutBuilder.h:1235
void clear() noexcept
Clears the builder content.
Definition LayoutBuilder.h:1271
Unmasked()
Creates a new Unmasked layout builder.
Definition LayoutBuilder.h:1238
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:1317
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1251
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1257
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1245
size_t length() const noexcept
Current length of the content.
Definition LayoutBuilder.h:1277
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:1310
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1263
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1283
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:1290
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:1301
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