Loading...
Searching...
No Matches
LayoutBuilder.h
Go to the documentation of this file.
1// BSD 3-Clause License; see https://github.com/scikit-hep/awkward/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
149 void
150 to_buffer(void* buffer, const char* name) const noexcept {
151 if (std::string(name) == std::string("node" + std::to_string(id_) + "-data")) {
152 data_.concatenate(reinterpret_cast<PRIMITIVE*>(buffer));
153 }
154 }
155
160 void
161 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
162 data_.concatenate(reinterpret_cast<PRIMITIVE*>(
163 buffers["node" + std::to_string(id_) + "-data"]));
164 }
165
168 std::string
169 form() const {
170 std::stringstream form_key;
171 form_key << "node" << id_;
172
173 std::string params("");
174 if (parameters_ == "") {
175 } else {
176 params = std::string(", \"parameters\": { " + parameters_ + " }");
177 }
178
179 if (std::is_arithmetic<PRIMITIVE>::value) {
180 return "{ \"class\": \"NumpyArray\", \"primitive\": \"" +
181 type_to_name<PRIMITIVE>() + "\"" + params +
182 ", \"form_key\": \"" + form_key.str() + "\" }";
184 return "{ \"class\": \"NumpyArray\", \"primitive\": \"" +
185 type_to_name<PRIMITIVE>() + "\"" + params +
186 ", \"form_key\": \"" + form_key.str() + "\" }";
187 } else {
188 throw std::runtime_error("type " +
189 std::string(typeid(PRIMITIVE).name()) +
190 "is not supported");
191 }
192 }
193
194 private:
197
199 std::string parameters_;
200
202 size_t id_;
203 };
204
219 template <typename PRIMITIVE, typename BUILDER>
221 public:
225 : offsets_(
227 offsets_.append(0);
228 size_t id = 0;
229 set_id(id);
230 }
231
238 : offsets_(awkward::GrowableBuffer<PRIMITIVE>(options)) {
239 offsets_.append(0);
240 size_t id = 0;
241 set_id(id);
242 }
243
245 BUILDER&
246 content() noexcept {
247 return content_;
248 }
249
251 BUILDER&
252 begin_list() noexcept {
253 return content_;
254 }
255
258 void
259 end_list() noexcept {
260 offsets_.append(content_.length());
261 }
262
264 const std::string&
265 parameters() const noexcept {
266 return parameters_;
267 }
268
270 void
271 set_parameters(std::string parameter) noexcept {
272 parameters_ = parameter;
273 }
274
276 void
277 set_id(size_t& id) noexcept {
278 id_ = id;
279 id++;
280 content_.set_id(id);
281 }
282
284 void
285 clear() noexcept {
286 offsets_.clear();
287 offsets_.append(0);
288 content_.clear();
289 }
290
292 size_t
293 length() const noexcept {
294 return offsets_.length() - 1;
295 }
296
298 bool
299 is_valid(std::string& error) const noexcept {
300 if ((int64_t)content_.length() != (int64_t)offsets_.last()) {
301 std::stringstream out;
302 out << "ListOffset node" << id_ << "has content length "
303 << content_.length() << "but last offset " << offsets_.last()
304 << "\n";
305 error.append(out.str());
306
307 return false;
308 } else {
309 return content_.is_valid(error);
310 }
311 }
312
315 void
316 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
317 noexcept {
318 names_nbytes["node" + std::to_string(id_) + "-offsets"] =
319 offsets_.nbytes();
320 content_.buffer_nbytes(names_nbytes);
321 }
322
328 void
329 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
330 offsets_.concatenate(reinterpret_cast<PRIMITIVE*>(
331 buffers["node" + std::to_string(id_) + "-offsets"]));
332 content_.to_buffers(buffers);
333 }
334
339 void
340 to_buffer(void* buffer, const char* name) const noexcept {
341 if (std::string(name) == std::string("node" + std::to_string(id_) + "-offsets")) {
342 offsets_.concatenate(reinterpret_cast<PRIMITIVE*>(buffer));
343 }
344 content_.to_buffer(buffer, name);
345 }
346
351 void
352 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
353 offsets_.concatenate(reinterpret_cast<PRIMITIVE*>(
354 buffers["node" + std::to_string(id_) + "-offsets"]));
355 content_.to_char_buffers(buffers);
356 }
357
360 std::string
361 form() const noexcept {
362 std::stringstream form_key;
363 form_key << "node" << id_;
364 std::string params("");
365 if (parameters_ == "") {
366 } else {
367 params = std::string(", \"parameters\": { " + parameters_ + " }");
368 }
369 return "{ \"class\": \"ListOffsetArray\", \"offsets\": \"" +
370 type_to_numpy_like<PRIMITIVE>() +
371 "\", \"content\": " + content_.form() + params +
372 ", \"form_key\": \"" + form_key.str() + "\" }";
373 }
374
375 private:
380
382 BUILDER content_;
383
385 std::string parameters_;
386
388 size_t id_;
389 };
390
395 template<class PRIMITIVE>
396 class String : public ListOffset<PRIMITIVE, Numpy<uint8_t>> {
397 public:
398 String() : ListOffset<PRIMITIVE, Numpy<uint8_t>>() {
399 this->set_parameters(R"""("__array__": "string")""");
400 this->content().set_parameters(R"""("__array__": "char")""");
401 }
402
403 void append(const std::string& value) {
404 this->begin_list();
405 for (const auto& c: value) {
406 this->content().append(c);
407 }
408 this->end_list();
409 }
410 };
411
416 class Empty {
417 public:
420 size_t id = 0;
421 set_id(id);
422 }
423
424 void
425 set_id(size_t& /* id */) noexcept {}
426
427 void
428 clear() noexcept {}
429
431 size_t
432 length() const noexcept {
433 return 0;
434 }
435
437 bool
438 is_valid(std::string& /* error */) const noexcept {
439 return true;
440 }
441
442 void
443 buffer_nbytes(std::map<std::string, size_t>& /* names_nbytes */) const
444 noexcept {}
445
446 void
447 to_buffers(std::map<std::string, void*>& /* buffers */) const noexcept {}
448
449 void
450 to_buffer(void* /* buffer */, const char* /* name */) const noexcept {}
451
456 void
457 to_char_buffers(std::map<std::string, uint8_t*>& /* buffers */) const noexcept {}
458
461 std::string
462 form() const noexcept {
463 return "{ \"class\": \"EmptyArray\" }";
464 }
465
466 private:
468 size_t id_;
469 };
470
471
481 template <class MAP = std::map<std::size_t, std::string>,
482 typename... BUILDERS>
483 class Record {
484 public:
485 using RecordContents = typename std::tuple<BUILDERS...>;
486 using UserDefinedMap = MAP;
487
488 template <std::size_t INDEX>
489 using RecordFieldType = std::tuple_element_t<INDEX, RecordContents>;
490
493 size_t id = 0;
494 set_id(id);
495 map_fields(std::index_sequence_for<BUILDERS...>());
496 }
497
504 Record(UserDefinedMap user_defined_field_id_to_name_map)
505 : content_names_(user_defined_field_id_to_name_map) {
506 assert(content_names_.size() == fields_count_);
507 size_t id = 0;
508 set_id(id);
509 }
510
512 const std::vector<std::string>
513 fields() const noexcept {
514 if (content_names_.empty()) {
515 return fields_;
516 } else {
517 std::vector<std::string> result;
518 for (auto it : content_names_) {
519 result.emplace_back(it.second);
520 }
521 return result;
522 }
523 }
524
529 void
530 set_fields(MAP user_defined_field_id_to_name_map) noexcept {
531 content_names_ = user_defined_field_id_to_name_map;
532 }
533
535 template <std::size_t INDEX>
536 typename RecordFieldType<INDEX>::Builder&
537 content() noexcept {
538 return std::get<INDEX>(contents).builder;
539 }
540
542 const std::string&
543 parameters() const noexcept {
544 return parameters_;
545 }
546
548 void
549 set_parameters(std::string parameter) noexcept {
550 parameters_ = parameter;
551 }
552
554 void
555 set_id(size_t& id) noexcept {
556 id_ = id;
557 id++;
558 for (size_t i = 0; i < fields_count_; i++) {
559 visit_at(contents, i, [&id](auto& content) {
560 content.builder.set_id(id);
561 });
562 }
563 }
564
569 void
570 clear() noexcept {
571 for (size_t i = 0; i < fields_count_; i++) {
572 visit_at(contents, i, [](auto& content) {
573 content.builder.clear();
574 });
575 }
576 }
577
579 size_t
580 length() const noexcept {
581 return (std::get<0>(contents).builder.length());
582 }
583
585 bool
586 is_valid(std::string& error) const noexcept {
587 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
588
589 int64_t length = -1;
590 std::vector<size_t> lengths = field_lengths(index_sequence);
591 for (size_t i = 0; i < lengths.size(); i++) {
592 if (length == -1) {
593 length = lengths[i];
594 }
595 else if (length != (int64_t)lengths[i]) {
596 std::stringstream out;
597 out << "Record node" << id_ << " has field \""
598 << fields().at(i) << "\" length " << lengths[i]
599 << " that differs from the first length " << length << "\n";
600 error.append(out.str());
601
602 return false;
603 }
604 }
605
606 std::vector<bool> valid_fields = field_is_valid(index_sequence, error);
607 return std::none_of(std::cbegin(valid_fields),
608 std::cend(valid_fields),
609 std::logical_not<bool>());
610 }
611
614 void
615 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
616 noexcept {
617 for (size_t i = 0; i < fields_count_; i++) {
618 visit_at(contents, i, [&names_nbytes](auto& content) {
619 content.builder.buffer_nbytes(names_nbytes);
620 });
621 }
622 }
623
629 void
630 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
631 for (size_t i = 0; i < fields_count_; i++) {
632 visit_at(contents, i, [&buffers](auto& content) {
633 content.builder.to_buffers(buffers);
634 });
635 }
636 }
637
641 void
642 to_buffer(void* buffer, const char* name) const noexcept {
643 for (size_t i = 0; i < fields_count_; i++) {
644 visit_at(contents, i, [&buffer, &name](auto& content) {
645 content.builder.to_buffer(buffer, name);
646 });
647 }
648 }
649
654 void
655 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
656 for (size_t i = 0; i < fields_count_; i++) {
657 visit_at(contents, i, [&buffers](auto& content) {
658 content.builder.to_char_buffers(buffers);
659 });
660 }
661 }
662
665 std::string
666 form() const noexcept {
667 std::stringstream form_key;
668 form_key << "node" << id_;
669 std::string params("");
670 if (parameters_ == "") {
671 } else {
672 params = std::string("\"parameters\": { " + parameters_ + " }, ");
673 }
674 std::stringstream out;
675 out << "{ \"class\": \"RecordArray\", \"contents\": { ";
676 for (size_t i = 0; i < fields_count_; i++) {
677 if (i != 0) {
678 out << ", ";
679 }
680 auto contents_form = [&](auto& content) {
681 out << "\""
682 << (!content_names_.empty() ? content_names_.at(content.index)
683 : content.index_as_field())
684 << +"\": ";
685 out << content.builder.form();
686 };
687 visit_at(contents, i, contents_form);
688 }
689 out << " }, ";
690 out << params << "\"form_key\": \"" << form_key.str() << "\" }";
691 return out.str();
692 }
693
696
697 private:
700 template <std::size_t... S>
701 void
702 map_fields(std::index_sequence<S...>) noexcept {
703 fields_ = std::vector<std::string>(
704 {std::string(std::get<S>(contents).index_as_field())...});
705 }
706
709 template <std::size_t... S>
710 std::vector<size_t>
711 field_lengths(std::index_sequence<S...>) const noexcept {
712 return std::vector<size_t>({std::get<S>(contents).builder.length()...});
713 }
714
716 template <std::size_t... S>
717 std::vector<bool>
718 field_is_valid(std::index_sequence<S...>, std::string& error) const
719 noexcept {
720 return std::vector<bool>(
721 {std::get<S>(contents).builder.is_valid(error)...});
722 }
723
725 std::vector<std::string> fields_;
726
728 UserDefinedMap content_names_;
729
731 std::string parameters_;
732
734 size_t id_;
735
737 static constexpr size_t fields_count_ = sizeof...(BUILDERS);
738 };
739
746 template <typename... BUILDERS>
747 class Tuple {
748 using TupleContents = typename std::tuple<BUILDERS...>;
749
750 template <std::size_t INDEX>
751 using TupleContentType = std::tuple_element_t<INDEX, TupleContents>;
752
753 public:
756 size_t id = 0;
757 set_id(id);
758 }
759
761 template <std::size_t INDEX>
762 TupleContentType<INDEX>&
763 content() noexcept {
764 return std::get<INDEX>(contents);
765 }
766
768 const std::string&
769 parameters() const noexcept {
770 return parameters_;
771 }
772
774 void
775 set_parameters(std::string parameter) noexcept {
776 parameters_ = parameter;
777 }
778
780 void
781 set_id(size_t& id) noexcept {
782 id_ = id;
783 id++;
784 for (size_t i = 0; i < fields_count_; i++) {
785 visit_at(contents, i, [&id](auto& content) {
786 content.set_id(id);
787 });
788 }
789 }
790
794 void
795 clear() noexcept {
796 for (size_t i = 0; i < fields_count_; i++) {
797 visit_at(contents, i, [](auto& content) {
798 content.clear();
799 });
800 }
801 }
802
804 size_t
805 length() const noexcept {
806 return (std::get<0>(contents).length());
807 }
808
810 bool
811 is_valid(std::string& error) const noexcept {
812 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
813
814 int64_t length = -1;
815 std::vector<size_t> lengths = content_lengths(index_sequence);
816 for (size_t i = 0; i < lengths.size(); i++) {
817 if (length == -1) {
818 length = (int64_t)lengths[i];
819 }
820 else if (length != (int64_t)lengths[i]) {
821 std::stringstream out;
822 out << "Record node" << id_ << " has index \"" << i << "\" length "
823 << lengths[i] << " that differs from the first length "
824 << length << "\n";
825 error.append(out.str());
826
827 return false;
828 }
829 }
830
831 std::vector<bool> valid_fields =
832 content_is_valid(index_sequence, error);
833 return std::none_of(std::cbegin(valid_fields),
834 std::cend(valid_fields),
835 std::logical_not<bool>());
836 }
837
840 void
841 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
842 noexcept {
843 for (size_t i = 0; i < fields_count_; i++) {
844 visit_at(contents, i, [&names_nbytes](auto& content) {
845 content.buffer_nbytes(names_nbytes);
846 });
847 }
848 }
849
855 void
856 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
857 for (size_t i = 0; i < fields_count_; i++) {
858 visit_at(contents, i, [&buffers](auto& content) {
859 content.to_buffers(buffers);
860 });
861 }
862 }
863
867 void
868 to_buffer(void* buffer, const char* name) const noexcept {
869 for (size_t i = 0; i < fields_count_; i++) {
870 visit_at(contents, i, [&buffer, &name](auto& content) {
871 content.to_buffer(buffer, name);
872 });
873 }
874 }
875
880 void
881 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
882 for (size_t i = 0; i < fields_count_; i++) {
883 visit_at(contents, i, [&buffers](auto& content) {
884 content.to_char_buffers(buffers);
885 });
886 }
887 }
888
891 std::string
892 form() const noexcept {
893 std::stringstream form_key;
894 form_key << "node" << id_;
895 std::string params("");
896 if (parameters_ == "") {
897 } else {
898 params = std::string("\"parameters\": { " + parameters_ + " }, ");
899 }
900 std::stringstream out;
901 out << "{ \"class\": \"RecordArray\", \"contents\": [";
902 for (size_t i = 0; i < fields_count_; i++) {
903 if (i != 0) {
904 out << ", ";
905 }
906 auto contents_form = [&out](auto& content) {
907 out << content.form();
908 };
909 visit_at(contents, i, contents_form);
910 }
911 out << "], ";
912 out << params << "\"form_key\": \"" << form_key.str() << "\" }";
913 return out.str();
914 }
915
917 TupleContents contents;
918
919 private:
922 template <std::size_t... S>
923 std::vector<size_t>
924 content_lengths(std::index_sequence<S...>) const noexcept {
925 return std::vector<size_t>({std::get<S>(contents).length()...});
926 }
927
929 template <std::size_t... S>
930 std::vector<bool>
931 content_is_valid(std::index_sequence<S...>, std::string& error) const
932 noexcept {
933 return std::vector<bool>({std::get<S>(contents).is_valid(error)...});
934 }
935
937 std::vector<int64_t> field_index_;
938
940 std::string parameters_;
941
943 size_t id_;
944
946 static constexpr size_t fields_count_ = sizeof...(BUILDERS);
947 };
948
962 template <unsigned SIZE, typename BUILDER>
963 class Regular {
964 public:
966 Regular() : length_(0) {
967 size_t id = 0;
968 set_id(id);
969 }
970
972 BUILDER&
973 content() noexcept {
974 return content_;
975 }
976
979 BUILDER&
980 begin_list() noexcept {
981 return content_;
982 }
983
985 void
986 end_list() noexcept {
987 length_++;
988 }
989
991 const std::string&
992 parameters() const noexcept {
993 return parameters_;
994 }
995
997 void
998 set_parameters(std::string parameter) noexcept {
999 parameters_ = parameter;
1000 }
1001
1003 void
1004 set_id(size_t& id) noexcept {
1005 id_ = id;
1006 id++;
1007 content_.set_id(id);
1008 }
1009
1011 void
1012 clear() noexcept {
1013 length_ = 0;
1014 content_.clear();
1015 }
1016
1018 size_t
1019 length() const noexcept {
1020 return length_;
1021 }
1022
1024 bool
1025 is_valid(std::string& error) const noexcept {
1026 if (content_.length() != length_ * size_) {
1027 std::stringstream out;
1028 out << "Regular node" << id_ << "has content length "
1029 << content_.length() << ", but length " << length_ << " and size "
1030 << size_ << "\n";
1031 error.append(out.str());
1032
1033 return false;
1034 } else {
1035 return content_.is_valid(error);
1036 }
1037 }
1038
1041 void
1042 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1043 noexcept {
1044 content_.buffer_nbytes(names_nbytes);
1045 }
1046
1052 void
1053 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1054 content_.to_buffers(buffers);
1055 }
1056
1060 void
1061 to_buffer(void* buffer, const char* name) const noexcept {
1062 content_.to_buffer(buffer, name);
1063 }
1064
1069 void
1070 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1071 content_.to_char_buffers(buffers);
1072 }
1073
1076 std::string
1077 form() const noexcept {
1078 std::stringstream form_key;
1079 form_key << "node" << id_;
1080 std::string params("");
1081 if (parameters_ == "") {
1082 } else {
1083 params = std::string(", \"parameters\": { " + parameters_ + " }");
1084 }
1085 return "{ \"class\": \"RegularArray\", \"content\": " +
1086 content_.form() + ", \"size\": " + std::to_string(size_) +
1087 params + ", \"form_key\": \"" + form_key.str() + "\" }";
1088 }
1089
1090 private:
1092 BUILDER content_;
1093
1095 std::string parameters_;
1096
1098 size_t id_;
1099
1101 size_t length_;
1102
1104 size_t size_ = SIZE;
1105 };
1106
1107
1117 template <typename PRIMITIVE, typename BUILDER>
1118 class Indexed {
1119 public:
1123 : index_(
1125 max_index_(0) {
1126 size_t id = 0;
1127 set_id(id);
1128 }
1129
1136 : index_(awkward::GrowableBuffer<PRIMITIVE>(options)),
1137 max_index_(0) {
1138 size_t id = 0;
1139 set_id(id);
1140 }
1141
1143 BUILDER&
1144 content() noexcept {
1145 return content_;
1146 }
1147
1150 BUILDER&
1151 append_index() noexcept {
1152 return append_index(content_.length());
1153 }
1154
1157 BUILDER&
1158 append_index(size_t i) noexcept {
1159 index_.append(i);
1160 if (i > max_index_) {
1161 max_index_ = i;
1162 } else if (i < 0) {
1163 max_index_ = UINTMAX_MAX;
1164 }
1165 return content_;
1166 }
1167
1172 BUILDER&
1173 extend_index(size_t size) noexcept {
1174 size_t start = content_.length();
1175 size_t stop = start + size;
1176 if (stop - 1 > max_index_) {
1177 max_index_ = stop - 1;
1178 }
1179 for (size_t i = start; i < stop; i++) {
1180 index_.append(i);
1181 }
1182 return content_;
1183 }
1184
1186 const std::string&
1187 parameters() const noexcept {
1188 return parameters_;
1189 }
1190
1192 void
1193 set_parameters(std::string parameter) noexcept {
1194 parameters_ = parameter;
1195 }
1196
1198 void
1199 set_id(size_t& id) noexcept {
1200 id_ = id;
1201 id++;
1202 content_.set_id(id);
1203 }
1204
1207 void
1208 clear() noexcept {
1209 max_index_ = 0;
1210 index_.clear();
1211 content_.clear();
1212 }
1213
1215 size_t
1216 length() const noexcept {
1217 return index_.length();
1218 }
1219
1222 void
1223 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1224 noexcept {
1225 names_nbytes["node" + std::to_string(id_) + "-index"] = index_.nbytes();
1226 content_.buffer_nbytes(names_nbytes);
1227 }
1228
1230 bool
1231 is_valid(std::string& error) const noexcept {
1232
1233 if (max_index_ == UINTMAX_MAX) {
1234 std::stringstream out;
1235 out << "Indexed node" << id_ << " has a negative index\n";
1236 error.append(out.str());
1237 return false;
1238 } else if ((content_.length() == 0) && (max_index_ == 0)) { // catches empty object
1239 } else if (max_index_ >= content_.length()) {
1240 std::stringstream out;
1241 out << "Indexed node" << id_ << " has index " << max_index_
1242 << " but content has length "
1243 << content_.length() << "\n";
1244 error.append(out.str());
1245 return false;
1246 }
1247 return content_.is_valid(error);
1248 }
1249
1255 void
1256 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1257 index_.concatenate(reinterpret_cast<PRIMITIVE*>(
1258 buffers["node" + std::to_string(id_) + "-index"]));
1259 content_.to_buffers(buffers);
1260 }
1261
1266 void
1267 to_buffer(void* buffer, const char* name) const noexcept {
1268 if (std::string(name) == std::string("node" + std::to_string(id_) + "-index")) {
1269 index_.concatenate(reinterpret_cast<PRIMITIVE*>(buffer));
1270 }
1271 content_.to_buffer(buffer, name);
1272 }
1273
1278 void
1279 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1280 index_.concatenate(reinterpret_cast<PRIMITIVE*>(
1281 buffers["node" + std::to_string(id_) + "-index"]));
1282 content_.to_char_buffers(buffers);
1283 }
1284
1287 std::string
1288 form() const noexcept {
1289 std::stringstream form_key;
1290 form_key << "node" << id_;
1291 std::string params("");
1292 if (parameters_ == "") {
1293 } else {
1294 params = std::string(", \"parameters\": { " + parameters_ + " }");
1295 }
1296 return "{ \"class\": \"IndexedArray\", \"index\": \"" +
1297 type_to_numpy_like<PRIMITIVE>() +
1298 "\", \"content\": " + content_.form() + params +
1299 ", \"form_key\": \"" + form_key.str() + "\" }";
1300 }
1301
1302 private:
1307
1309 BUILDER content_;
1310
1312 std::string parameters_;
1313
1315 size_t id_;
1316
1318 size_t max_index_;
1319 };
1320
1331 template <typename PRIMITIVE, typename BUILDER>
1333 public:
1337 : index_(
1339 last_valid_(-1),
1340 max_index_(0) {
1341 size_t id = 0;
1342 set_id(id);
1343 }
1344
1351 : index_(awkward::GrowableBuffer<PRIMITIVE>(options)),
1352 last_valid_(-1),
1353 max_index_(0) {
1354 size_t id = 0;
1355 set_id(id);
1356 }
1357
1359 BUILDER&
1360 content() noexcept {
1361 return content_;
1362 }
1363
1366 BUILDER&
1367 append_valid() noexcept {
1368 last_valid_ = content_.length();
1369 return append_valid(last_valid_);
1370 }
1371
1374 BUILDER&
1375 append_valid(size_t i) noexcept {
1376 last_valid_ = content_.length();
1377 index_.append(i);
1378 if (i > max_index_) {
1379 max_index_ = i;
1380 }
1381 return content_;
1382 }
1383
1388 BUILDER&
1389 extend_valid(size_t size) noexcept {
1390 size_t start = content_.length();
1391 size_t stop = start + size;
1392 last_valid_ = stop - 1;
1393 if (last_valid_ > max_index_) {
1394 max_index_ = last_valid_;
1395 }
1396 for (size_t i = start; i < stop; i++) {
1397 index_.append(i);
1398 }
1399 return content_;
1400 }
1401
1403 void
1404 append_invalid() noexcept {
1405 index_.append(-1);
1406 }
1407
1411 void
1412 extend_invalid(size_t size) noexcept {
1413 for (size_t i = 0; i < size; i++) {
1414 index_.append(-1);
1415 }
1416 }
1417
1419 const std::string&
1420 parameters() const noexcept {
1421 return parameters_;
1422 }
1423
1425 void
1426 set_parameters(std::string parameter) noexcept {
1427 parameters_ = parameter;
1428 }
1429
1431 void
1432 set_id(size_t& id) noexcept {
1433 id_ = id;
1434 id++;
1435 content_.set_id(id);
1436 }
1437
1440 void
1441 clear() noexcept {
1442 last_valid_ = -1;
1443 index_.clear();
1444 content_.clear();
1445 }
1446
1448 size_t
1449 length() const noexcept {
1450 return index_.length();
1451 }
1452
1454 bool
1455 is_valid(std::string& error) const noexcept {
1456 if ((content_.length() == 0) && (max_index_ == 0)) { // catches empty object
1457 } else if (max_index_ >= content_.length()) {
1458 std::stringstream out;
1459 out << "IndexedOption node" << id_ << " has index " << max_index_
1460 << " but content has length "
1461 << content_.length() << "\n";
1462 error.append(out.str());
1463
1464 return false;
1465 }
1466 return content_.is_valid(error);
1467 }
1468
1471 void
1472 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1473 noexcept {
1474 names_nbytes["node" + std::to_string(id_) + "-index"] = index_.nbytes();
1475 content_.buffer_nbytes(names_nbytes);
1476 }
1477
1483 void
1484 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1485 index_.concatenate(reinterpret_cast<PRIMITIVE*>(
1486 buffers["node" + std::to_string(id_) + "-index"]));
1487 content_.to_buffers(buffers);
1488 }
1489
1494 void
1495 to_buffer(void* buffer, const char* name) const noexcept {
1496 if (std::string(name) == std::string("node" + std::to_string(id_) + "-index")) {
1497 index_.concatenate(reinterpret_cast<PRIMITIVE*>(buffer));
1498 }
1499 content_.to_buffer(buffer, name);
1500 }
1501
1506 void
1507 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1508 index_.concatenate(reinterpret_cast<PRIMITIVE*>(
1509 buffers["node" + std::to_string(id_) + "-index"]));
1510 content_.to_char_buffers(buffers);
1511 }
1512
1515 std::string
1516 form() const noexcept {
1517 std::stringstream form_key;
1518 form_key << "node" << id_;
1519 std::string params("");
1520 if (parameters_ == "") {
1521 } else {
1522 params = std::string(", \"parameters\": { " + parameters_ + " }");
1523 }
1524 return "{ \"class\": \"IndexedOptionArray\", \"index\": \"" +
1525 type_to_numpy_like<PRIMITIVE>() +
1526 "\", \"content\": " + content_.form() + params +
1527 ", \"form_key\": \"" + form_key.str() + "\" }";
1528 }
1529
1530 private:
1535
1537 BUILDER content_;
1538
1540 std::string parameters_;
1541
1543 size_t id_;
1544
1546 size_t last_valid_;
1547
1549 size_t max_index_;
1550 };
1551
1563 template <typename BUILDER>
1564 class Unmasked {
1565 public:
1568 size_t id = 0;
1569 set_id(id);
1570 }
1571
1573 BUILDER&
1574 content() noexcept {
1575 return content_;
1576 }
1577
1579 const std::string&
1580 parameters() const noexcept {
1581 return parameters_;
1582 }
1583
1585 void
1586 set_parameters(std::string parameter) noexcept {
1587 parameters_ = parameter;
1588 }
1589
1591 void
1592 set_id(size_t& id) noexcept {
1593 id_ = id;
1594 id++;
1595 content_.set_id(id);
1596 }
1597
1599 void
1600 clear() noexcept {
1601 content_.clear();
1602 }
1603
1605 size_t
1606 length() const noexcept {
1607 return content_.length();
1608 }
1609
1611 bool
1612 is_valid(std::string& error) const noexcept {
1613 return content_.is_valid(error);
1614 }
1615
1618 void
1619 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1620 noexcept {
1621 content_.buffer_nbytes(names_nbytes);
1622 }
1623
1629 void
1630 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1631 content_.to_buffers(buffers);
1632 }
1633
1637 void
1638 to_buffer(void* buffer, const char* name) const noexcept {
1639 content_.to_buffer(buffer, name);
1640 }
1641
1646 void
1647 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1648 content_.to_char_buffers(buffers);
1649 }
1650
1653 std::string
1654 form() const noexcept {
1655 std::stringstream form_key;
1656 form_key << "node" << id_;
1657 std::string params("");
1658 if (parameters_ == "") {
1659 } else {
1660 params = std::string(", \"parameters\": { " + parameters_ + " }");
1661 }
1662 return "{ \"class\": \"UnmaskedArray\", \"content\": " +
1663 content_.form() + params + ", \"form_key\": \"" +
1664 form_key.str() + "\" }";
1665 }
1666
1667 private:
1669 BUILDER content_;
1670
1672 std::string parameters_;
1673
1675 size_t id_;
1676 };
1677
1694 template <bool VALID_WHEN, typename BUILDER>
1696 public:
1701 size_t id = 0;
1702 set_id(id);
1703 }
1704
1711 : mask_(awkward::GrowableBuffer<int8_t>(options)) {
1712 size_t id = 0;
1713 set_id(id);
1714 }
1715
1717 BUILDER&
1718 content() noexcept {
1719 return content_;
1720 }
1721
1723 bool
1724 valid_when() const noexcept {
1725 return valid_when_;
1726 }
1727
1731 BUILDER&
1732 append_valid() noexcept {
1733 mask_.append(valid_when_);
1734 return content_;
1735 }
1736
1742 BUILDER&
1743 extend_valid(size_t size) noexcept {
1744 for (size_t i = 0; i < size; i++) {
1745 mask_.append(valid_when_);
1746 }
1747 return content_;
1748 }
1749
1753 BUILDER&
1754 append_invalid() noexcept {
1755 mask_.append(!valid_when_);
1756 return content_;
1757 }
1758
1764 BUILDER&
1765 extend_invalid(size_t size) noexcept {
1766 for (size_t i = 0; i < size; i++) {
1767 mask_.append(!valid_when_);
1768 }
1769 return content_;
1770 }
1771
1773 const std::string&
1774 parameters() const noexcept {
1775 return parameters_;
1776 }
1777
1779 void
1780 set_parameters(std::string parameter) noexcept {
1781 parameters_ = parameter;
1782 }
1783
1785 void
1786 set_id(size_t& id) noexcept {
1787 id_ = id;
1788 id++;
1789 content_.set_id(id);
1790 }
1791
1794 void
1795 clear() noexcept {
1796 mask_.clear();
1797 content_.clear();
1798 }
1799
1801 size_t
1802 length() const noexcept {
1803 return mask_.length();
1804 }
1805
1807 bool
1808 is_valid(std::string& error) const noexcept {
1809 if (content_.length() != mask_.length()) {
1810 std::stringstream out;
1811 out << "ByteMasked node" << id_ << "has content length "
1812 << content_.length() << "but mask length " << mask_.length()
1813 << "\n";
1814 error.append(out.str());
1815
1816 return false;
1817 } else {
1818 return content_.is_valid(error);
1819 }
1820 }
1821
1824 void
1825 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
1826 noexcept {
1827 names_nbytes["node" + std::to_string(id_) + "-mask"] = mask_.nbytes();
1828 content_.buffer_nbytes(names_nbytes);
1829 }
1830
1836 void
1837 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
1838 mask_.concatenate(reinterpret_cast<int8_t*>(
1839 buffers["node" + std::to_string(id_) + "-mask"]));
1840 content_.to_buffers(buffers);
1841 }
1842
1847 void
1848 to_buffer(void* buffer, const char* name) const noexcept {
1849 if (std::string(name) == std::string("node" + std::to_string(id_) + "-mask")) {
1850 mask_.concatenate(reinterpret_cast<int8_t*>(buffer));
1851 }
1852 content_.to_buffer(buffer, name);
1853 }
1854
1859 void
1860 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
1861 mask_.concatenate(reinterpret_cast<int8_t*>(
1862 buffers["node" + std::to_string(id_) + "-mask"]));
1863 content_.to_char_buffers(buffers);
1864 }
1865
1868 std::string
1869 form() const noexcept {
1870 std::stringstream form_key, form_valid_when;
1871 form_key << "node" << id_;
1872 form_valid_when << std::boolalpha << valid_when_;
1873 std::string params("");
1874 if (parameters_ == "") {
1875 } else {
1876 params = std::string(", \"parameters\": { " + parameters_ + " }");
1877 }
1878 return "{ \"class\": \"ByteMaskedArray\", \"mask\": \"i8\", "
1879 "\"content\": " +
1880 content_.form() + ", \"valid_when\": " + form_valid_when.str() +
1881 params + ", \"form_key\": \"" + form_key.str() + "\" }";
1882 }
1883
1884 private:
1889
1891 BUILDER content_;
1892
1894 std::string parameters_;
1895
1897 size_t id_;
1898
1900 bool valid_when_ = VALID_WHEN;
1901 };
1902
1919 template <bool VALID_WHEN, bool LSB_ORDER, typename BUILDER>
1921 public:
1926 current_byte_(uint8_t(0)),
1927 current_byte_ref_(mask_.append_and_get_ref(current_byte_)),
1928 current_index_(0) {
1929 size_t id = 0;
1930 set_id(id);
1931 if (lsb_order_) {
1932 for (size_t i = 0; i < 8; i++) {
1933 cast_[i] = 1 << i;
1934 }
1935 } else {
1936 for (size_t i = 0; i < 8; i++) {
1937 cast_[i] = 128 >> i;
1938 }
1939 }
1940 }
1941
1948 : mask_(awkward::GrowableBuffer<uint8_t>(options)),
1949 current_byte_(uint8_t(0)),
1950 current_byte_ref_(mask_.append_and_get_ref(current_byte_)),
1951 current_index_(0) {
1952 size_t id = 0;
1953 set_id(id);
1954 if (lsb_order_) {
1955 for (size_t i = 0; i < 8; i++) {
1956 cast_[i] = 1 << i;
1957 }
1958 } else {
1959 for (size_t i = 0; i < 8; i++) {
1960 cast_[i] = 128 >> i;
1961 }
1962 }
1963 }
1964
1966 BUILDER&
1967 content() noexcept {
1968 return content_;
1969 }
1970
1972 bool
1973 valid_when() const noexcept {
1974 return valid_when_;
1975 }
1976
1979 bool
1980 lsb_order() const noexcept {
1981 return lsb_order_;
1982 }
1983
1988 BUILDER&
1989 append_valid() noexcept {
1990 append_begin();
1991 current_byte_ |= cast_[current_index_];
1992 append_end();
1993 return content_;
1994 }
1995
2002 BUILDER&
2003 extend_valid(size_t size) noexcept {
2004 for (size_t i = 0; i < size; i++) {
2005 append_valid();
2006 }
2007 return content_;
2008 }
2009
2013 BUILDER&
2014 append_invalid() noexcept {
2015 append_begin();
2016 append_end();
2017 return content_;
2018 }
2019
2025 BUILDER&
2026 extend_invalid(size_t size) noexcept {
2027 for (size_t i = 0; i < size; i++) {
2029 }
2030 return content_;
2031 }
2032
2034 const std::string&
2035 parameters() const noexcept {
2036 return parameters_;
2037 }
2038
2040 void
2041 set_parameters(std::string parameter) noexcept {
2042 parameters_ = parameter;
2043 }
2044
2046 void
2047 set_id(size_t& id) noexcept {
2048 id_ = id;
2049 id++;
2050 content_.set_id(id);
2051 }
2052
2055 void
2056 clear() noexcept {
2057 mask_.clear();
2058 content_.clear();
2059 current_byte_ = 0;
2060 current_byte_ref_ = mask_.append_and_get_ref(current_byte_);
2061 current_index_ = 0;
2062 }
2063
2065 size_t
2066 length() const noexcept {
2067 return mask_.length() > 0 ?
2068 (mask_.length() - 1) * 8 + current_index_ : current_index_;
2069 }
2070
2072 bool
2073 is_valid(std::string& error) const noexcept {
2074 if (content_.length() != length()) {
2075 std::stringstream out;
2076 out << "BitMasked node" << id_ << "has content length "
2077 << content_.length() << "but bit mask length " << mask_.length()
2078 << "\n";
2079 error.append(out.str());
2080
2081 return false;
2082 } else {
2083 return content_.is_valid(error);
2084 }
2085 }
2086
2089 void
2090 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
2091 noexcept {
2092 names_nbytes["node" + std::to_string(id_) + "-mask"] = mask_.nbytes();
2093 content_.buffer_nbytes(names_nbytes);
2094 }
2095
2101 void
2102 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
2103 mask_.concatenate_from(reinterpret_cast<uint8_t*>(
2104 buffers["node" + std::to_string(id_) + "-mask"]), 0, 1);
2105 mask_.append(reinterpret_cast<uint8_t*>(
2106 buffers["node" + std::to_string(id_) + "-mask"]), mask_.length() - 1, 0, 1);
2107 content_.to_buffers(buffers);
2108 }
2109
2114 void
2115 to_buffer(void* buffer, const char* name) const noexcept {
2116 if (std::string(name) == std::string("node" + std::to_string(id_) + "-mask")) {
2117 mask_.concatenate_from(reinterpret_cast<uint8_t*>(buffer), 0, 1);
2118 mask_.append(reinterpret_cast<uint8_t*>(buffer), mask_.length() - 1, 0, 1);
2119 }
2120 content_.to_buffer(buffer, name);
2121 }
2122
2127 void
2128 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
2129 mask_.concatenate_from(reinterpret_cast<uint8_t*>(
2130 buffers["node" + std::to_string(id_) + "-mask"]), 0, 1);
2131 mask_.append(reinterpret_cast<uint8_t*>(
2132 buffers["node" + std::to_string(id_) + "-mask"]), mask_.length() - 1, 0, 1);
2133 content_.to_char_buffers(buffers);
2134 }
2135
2138 std::string
2139 form() const noexcept {
2140 std::stringstream form_key, form_valid_when, form_lsb_order;
2141 form_key << "node" << id_;
2142 form_valid_when << std::boolalpha << valid_when_;
2143 form_lsb_order << std::boolalpha << lsb_order_;
2144 std::string params("");
2145 if (parameters_ == "") {
2146 } else {
2147 params = std::string(", \"parameters\": { " + parameters_ + " }");
2148 }
2149 return "{ \"class\": \"BitMaskedArray\", \"mask\": \"u8\", "
2150 "\"content\": " +
2151 content_.form() + ", \"valid_when\": " + form_valid_when.str() +
2152 ", \"lsb_order\": " + form_lsb_order.str() + params +
2153 ", \"form_key\": \"" + form_key.str() + "\" }";
2154 }
2155
2156 private:
2160 void
2161 append_begin() {
2162 if (current_index_ == 8) {
2163 current_byte_ref_ = mask_.append_and_get_ref(current_byte_);
2164 current_byte_ = uint8_t(0);
2165 current_index_ = 0;
2166 }
2167 }
2168
2174 void
2175 append_end() {
2176 current_index_ += 1;
2177 if (valid_when_) {
2178 current_byte_ref_ = current_byte_;
2179 } else {
2180 current_byte_ref_ = ~current_byte_;
2181 }
2182 }
2183
2187 GrowableBuffer<uint8_t> mask_;
2188
2190 BUILDER content_;
2191
2193 std::string parameters_;
2194
2196 size_t id_;
2197
2199 uint8_t current_byte_;
2200
2202 uint8_t& current_byte_ref_;
2203
2205 size_t current_index_;
2206
2208 uint8_t cast_[8];
2209
2211 bool valid_when_ = VALID_WHEN;
2212
2215 bool lsb_order_ = LSB_ORDER;
2216 };
2217
2233 template <typename TAGS, typename INDEX, typename... BUILDERS>
2234 class Union {
2235 public:
2236 using Contents = typename std::tuple<BUILDERS...>;
2237
2238 template <std::size_t I>
2239 using ContentType = std::tuple_element_t<I, Contents>;
2240
2246 size_t id = 0;
2247 set_id(id);
2248 for (size_t i = 0; i < contents_count_; i++) {
2249 last_valid_index_[i] = -1;
2250 }
2251 }
2252
2259 : tags_(awkward::GrowableBuffer<TAGS>(options)),
2260 index_(awkward::GrowableBuffer<INDEX>(options)) {
2261 size_t id = 0;
2262 set_id(id);
2263 for (size_t i = 0; i < contents_count_; i++) {
2264 last_valid_index_[i] = -1;
2265 }
2266 }
2267
2268 template <std::size_t I>
2269 ContentType<I>&
2270 content() noexcept {
2271 return std::get<I>(contents_);
2272 }
2273
2276 template <std::size_t TAG>
2277 ContentType<TAG>&
2278 append_content() noexcept {
2279 auto& which_content = std::get<TAG>(contents_);
2280 INDEX next_index = which_content.length();
2281
2282 TAGS tag = (TAGS)TAG;
2283 last_valid_index_[tag] = next_index;
2284 tags_.append(tag);
2285 index_.append(next_index);
2286
2287 return which_content;
2288 }
2289
2291 const std::string&
2292 parameters() const noexcept {
2293 return parameters_;
2294 }
2295
2297 void
2298 set_parameters(std::string parameter) noexcept {
2299 parameters_ = parameter;
2300 }
2301
2303 void
2304 set_id(size_t& id) noexcept {
2305 id_ = id;
2306 id++;
2307 auto contents_id = [&id](auto& content) {
2308 content.set_id(id);
2309 };
2310 for (size_t i = 0; i < contents_count_; i++) {
2311 visit_at(contents_, i, contents_id);
2312 }
2313 }
2314
2319 void
2320 clear() noexcept {
2321 for (size_t i = 0; i < contents_count_; i++) {
2322 last_valid_index_[i] = -1;
2323 }
2324 tags_.clear();
2325 index_.clear();
2326 auto clear_contents = [](auto& content) {
2327 content.clear();
2328 };
2329 for (size_t i = 0; i < contents_count_; i++) {
2330 visit_at(contents_, i, clear_contents);
2331 }
2332 }
2333
2335 size_t
2336 length() const noexcept {
2337 return tags_.length();
2338 }
2339
2341 bool
2342 is_valid(std::string& error) const noexcept {
2343 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
2344
2345 std::vector<size_t> lengths = content_lengths(index_sequence);
2346 std::unique_ptr<INDEX[]> index_ptr(new INDEX[index_.length()]);
2347 index_.concatenate(index_ptr.get());
2348 std::unique_ptr<TAGS[]> tags_ptr(new TAGS[tags_.length()]);
2349 tags_.concatenate(tags_ptr.get());
2350 for (size_t i = 0; i < index_.length(); i++) {
2351 if (index_ptr.get()[i] < 0 || index_ptr.get()[i] >= lengths[tags_ptr.get()[i]]) {
2352 std::stringstream out;
2353 out << "Union node" << id_ << " has index " << index_ptr.get()[i]
2354 << " at position " << i << " but content has length "
2355 << lengths[tags_ptr.get()[i]] << "\n";
2356 error.append(out.str());
2357
2358 return false;
2359 }
2360 }
2361
2362 std::vector<bool> valid_contents =
2363 content_is_valid(index_sequence, error);
2364 return std::none_of(std::cbegin(valid_contents),
2365 std::cend(valid_contents),
2366 std::logical_not<bool>());
2367 }
2368
2371 void
2372 buffer_nbytes(std::map<std::string, size_t>& names_nbytes) const
2373 noexcept {
2374 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
2375
2376 names_nbytes["node" + std::to_string(id_) + "-tags"] = tags_.nbytes();
2377 names_nbytes["node" + std::to_string(id_) + "-index"] = index_.nbytes();
2378
2379 for (size_t i = 0; i < contents_count_; i++) {
2380 visit_at(contents_, i, [&names_nbytes](auto& content) {
2381 content.buffer_nbytes(names_nbytes);
2382 });
2383 }
2384 }
2385
2391 void
2392 to_buffers(std::map<std::string, void*>& buffers) const noexcept {
2393 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
2394
2395 tags_.concatenate(reinterpret_cast<TAGS*>(
2396 buffers["node" + std::to_string(id_) + "-tags"]));
2397 index_.concatenate(reinterpret_cast<INDEX*>(
2398 buffers["node" + std::to_string(id_) + "-index"]));
2399
2400 for (size_t i = 0; i < contents_count_; i++) {
2401 visit_at(contents_, i, [&buffers](auto& content) {
2402 content.to_buffers(buffers);
2403 });
2404 }
2405 }
2406
2411 void
2412 to_buffer(void* buffer, const char* name) const noexcept {
2413 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
2414
2415 if (std::string(name) == std::string("node" + std::to_string(id_) + "-tags")) {
2416 tags_.concatenate(reinterpret_cast<TAGS*>(buffer));
2417 }
2418 else if (std::string(name) == std::string("node" + std::to_string(id_) + "-index")) {
2419 index_.concatenate(reinterpret_cast<INDEX*>(buffer));
2420 }
2421
2422 for (size_t i = 0; i < contents_count_; i++) {
2423 visit_at(contents_, i, [&buffer, &name](auto& content) {
2424 content.to_buffer(buffer, name);
2425 });
2426 }
2427 }
2428
2433 void
2434 to_char_buffers(std::map<std::string, uint8_t*>& buffers) const noexcept {
2435 auto index_sequence((std::index_sequence_for<BUILDERS...>()));
2436
2437 tags_.concatenate(reinterpret_cast<TAGS*>(
2438 buffers["node" + std::to_string(id_) + "-tags"]));
2439 index_.concatenate(reinterpret_cast<INDEX*>(
2440 buffers["node" + std::to_string(id_) + "-index"]));
2441
2442 for (size_t i = 0; i < contents_count_; i++) {
2443 visit_at(contents_, i, [&buffers](auto& content) {
2444 content.to_char_buffers(buffers);
2445 });
2446 }
2447 }
2448
2451 std::string
2452 form() const noexcept {
2453 std::stringstream form_key;
2454 form_key << "node" << id_;
2455 std::string params("");
2456 if (parameters_ == "") {
2457 } else {
2458 params = std::string(", \"parameters\": { " + parameters_ + " }");
2459 }
2460 std::stringstream out;
2461 out << "{ \"class\": \"UnionArray\", \"tags\": \"" +
2462 type_to_numpy_like<TAGS>() + "\", \"index\": \"" +
2463 type_to_numpy_like<INDEX>() + "\", \"contents\": [";
2464 for (size_t i = 0; i < contents_count_; i++) {
2465 if (i != 0) {
2466 out << ", ";
2467 }
2468 auto contents_form = [&](auto& content) {
2469 out << content.form();
2470 };
2471 visit_at(contents_, i, contents_form);
2472 }
2473 out << "], ";
2474 out << params << "\"form_key\": \"" << form_key.str() << "\" }";
2475 return out.str();
2476 }
2477
2478 private:
2481 template <std::size_t... S>
2482 std::vector<size_t>
2483 content_lengths(std::index_sequence<S...>) const {
2484 return std::vector<size_t>({std::get<S>(contents_).length()...});
2485 }
2486
2488 template <std::size_t... S>
2489 std::vector<bool>
2490 content_is_valid(std::index_sequence<S...>, std::string& error) const {
2491 return std::vector<bool>({std::get<S>(contents_).is_valid(error)...});
2492 }
2493
2497 GrowableBuffer<TAGS> tags_;
2498
2502 GrowableBuffer<INDEX> index_;
2503
2505 Contents contents_;
2506
2508 std::string parameters_;
2509
2511 size_t id_;
2512
2514 size_t last_valid_index_[sizeof...(BUILDERS)];
2515
2517 static constexpr size_t contents_count_ = sizeof...(BUILDERS);
2518 };
2519
2520 } // namespace LayoutBuilder
2521} // namespace awkward
2522
2523#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:1920
bool valid_when() const noexcept
Determines when the builder content are valid.
Definition LayoutBuilder.h:1973
void clear() noexcept
Discards the accumulated mask and clears the content of the builder.
Definition LayoutBuilder.h:2056
bool lsb_order() const noexcept
Determines whether the position of each bit is in Least-Significant Bit order (LSB) or not.
Definition LayoutBuilder.h:1980
BUILDER & append_invalid() noexcept
Sets current_byte_ and cast_ default to null, no change in current_byte_.
Definition LayoutBuilder.h:2014
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:2003
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:2139
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:2035
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:2041
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1967
size_t length() const noexcept
Current length of the mask buffer.
Definition LayoutBuilder.h:2066
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:2128
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:2047
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:2073
BitMasked(const awkward::BuilderOptions &options)
Creates a new BitMasked layout builder by allocating a new mask buffer, taking options from BuilderOp...
Definition LayoutBuilder.h:1947
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:1989
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:2090
BUILDER & extend_invalid(size_t size) noexcept
Sets current_byte_ and cast_ default to null, no change in current_byte_.
Definition LayoutBuilder.h:2026
void to_buffer(void *buffer, const char *name) const noexcept
Copies and concatenates the accumulated data in the builder buffer to a user-defined pointer if the g...
Definition LayoutBuilder.h:2115
BitMasked()
Creates a new BitMasked layout builder by allocating a new mask buffer, using AWKWARD_LAYOUTBUILDER_D...
Definition LayoutBuilder.h:1924
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:2102
Builds a ByteMaskedArray using a mask which is an array of booleans that determines whether the corre...
Definition LayoutBuilder.h:1695
bool valid_when() const noexcept
Determines when the builder content are valid.
Definition LayoutBuilder.h:1724
void clear() noexcept
Discards the accumulated mask and clears the content of the builder.
Definition LayoutBuilder.h:1795
BUILDER & append_invalid() noexcept
Inserts !valid_when in the mask.
Definition LayoutBuilder.h:1754
BUILDER & extend_valid(size_t size) noexcept
Inserts size number of valid_when in the mask.
Definition LayoutBuilder.h:1743
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:1869
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1774
ByteMasked()
Creates a new ByteMasked layout builder by allocating a new mask buffer, using AWKWARD_LAYOUTBUILDER_...
Definition LayoutBuilder.h:1699
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1780
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1718
ByteMasked(const awkward::BuilderOptions &options)
Creates a new ByteMasked layout builder by allocating a new mask buffer, taking options from BuilderO...
Definition LayoutBuilder.h:1710
size_t length() const noexcept
Current length of the mask buffer.
Definition LayoutBuilder.h:1802
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:1860
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1786
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1808
BUILDER & append_valid() noexcept
Inserts valid_when in the mask.
Definition LayoutBuilder.h:1732
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:1825
BUILDER & extend_invalid(size_t size) noexcept
Inserts size number of !valid_when in the mask.
Definition LayoutBuilder.h:1765
void to_buffer(void *buffer, const char *name) const noexcept
Copies and concatenates the accumulated data in the builder buffer to a user-defined pointer if the g...
Definition LayoutBuilder.h:1848
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:1837
Builds an EmptyArray which has no content in it. It is used whenever an array's type is not known bec...
Definition LayoutBuilder.h:416
void clear() noexcept
Definition LayoutBuilder.h:428
bool is_valid(std::string &) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:438
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:462
void to_buffers(std::map< std::string, void * > &) const noexcept
Definition LayoutBuilder.h:447
void to_buffer(void *, const char *) const noexcept
Definition LayoutBuilder.h:450
Empty()
Creates a new Empty layout builder.
Definition LayoutBuilder.h:419
void set_id(size_t &) noexcept
Definition LayoutBuilder.h:425
size_t length() const noexcept
Current length of the content.
Definition LayoutBuilder.h:432
void buffer_nbytes(std::map< std::string, size_t > &) const noexcept
Definition LayoutBuilder.h:443
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:457
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:1332
void clear() noexcept
Discards the accumulated index and clears the content of the builder. Also, last valid returns to -1.
Definition LayoutBuilder.h:1441
void extend_invalid(size_t size) noexcept
Inserts -1 in the index buffer size number of times.
Definition LayoutBuilder.h:1412
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:1389
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:1516
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1420
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1426
IndexedOption(const awkward::BuilderOptions &options)
Creates a new IndexedOption layout builder by allocating a new index buffer, taking options from Buil...
Definition LayoutBuilder.h:1350
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1360
BUILDER & append_valid(size_t i) noexcept
Inserts an explicit value in the index buffer and returns the reference to the builder content.
Definition LayoutBuilder.h:1375
size_t length() const noexcept
Current length of the index buffer.
Definition LayoutBuilder.h:1449
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:1507
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1432
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1455
IndexedOption()
Creates a new IndexedOption layout builder by allocating a new index buffer, using AWKWARD_LAYOUTBUIL...
Definition LayoutBuilder.h:1336
BUILDER & append_valid() noexcept
Inserts the last valid index in the index buffer and returns the reference to the builder content.
Definition LayoutBuilder.h:1367
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:1472
void append_invalid() noexcept
Inserts -1 in the index buffer.
Definition LayoutBuilder.h:1404
void to_buffer(void *buffer, const char *name) const noexcept
Copies and concatenates the accumulated data in the builder buffer to a user-defined pointer if the g...
Definition LayoutBuilder.h:1495
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:1484
Builds an IndexedArray which consists of an index buffer.
Definition LayoutBuilder.h:1118
void clear() noexcept
Discards the accumulated index and clears the content of the builder.
Definition LayoutBuilder.h:1208
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:1288
Indexed(const awkward::BuilderOptions &options)
Creates a new Indexed layout builder by allocating a new index buffer, taking options from BuilderOpt...
Definition LayoutBuilder.h:1135
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1187
Indexed()
Creates a new Indexed layout builder by allocating a new index buffer, using AWKWARD_LAYOUTBUILDER_DE...
Definition LayoutBuilder.h:1122
BUILDER & append_index() noexcept
Inserts the last valid index in the index buffer and returns the reference to the builder content.
Definition LayoutBuilder.h:1151
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1193
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1144
BUILDER & extend_index(size_t size) noexcept
Inserts size number indices in the index buffer and returns the reference to the builder content.
Definition LayoutBuilder.h:1173
size_t length() const noexcept
Current length of the index buffer.
Definition LayoutBuilder.h:1216
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:1279
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1199
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1231
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:1223
void to_buffer(void *buffer, const char *name) const noexcept
Copies and concatenates the accumulated data in the builder buffer to a user-defined pointer if the g...
Definition LayoutBuilder.h:1267
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:1256
BUILDER & append_index(size_t i) noexcept
Inserts an explicit value in the index buffer and returns the reference to the builder content.
Definition LayoutBuilder.h:1158
Builds a ListOffsetArray which describes unequal-length lists (often called a "jagged" or "ragged" ar...
Definition LayoutBuilder.h:220
void clear() noexcept
Discards the accumulated offsets and clears the builder content.
Definition LayoutBuilder.h:285
BUILDER & begin_list() noexcept
Begins a list and returns the reference to the builder content.
Definition LayoutBuilder.h:252
ListOffset()
Creates a new ListOffset layout builder by allocating a new offset buffer, using AWKWARD_LAYOUTBUILDE...
Definition LayoutBuilder.h:224
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:361
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:265
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:271
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:246
size_t length() const noexcept
Current length of the content.
Definition LayoutBuilder.h:293
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:352
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:277
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:299
void end_list() noexcept
Ends a list and appends the current length of the list contents in the offsets buffer.
Definition LayoutBuilder.h:259
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:316
void to_buffer(void *buffer, const char *name) const noexcept
Copies and concatenates the accumulated data in the builder buffer to a user-defined pointer if the g...
Definition LayoutBuilder.h:340
ListOffset(const awkward::BuilderOptions &options)
Creates a new ListOffset layout builder by allocating a new offset buffer, taking options from Builde...
Definition LayoutBuilder.h:237
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:329
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:161
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_buffer(void *buffer, const char *name) const noexcept
Copies and concatenates the accumulated data in the builder buffer to a user-defined pointer if the g...
Definition LayoutBuilder.h:150
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:169
Builds a RecordArray which represents an array of records, which can be of same or different types....
Definition LayoutBuilder.h:483
void clear() noexcept
Clears the builder contents.
Definition LayoutBuilder.h:570
Record()
Creates a new Record layout builder.
Definition LayoutBuilder.h:492
MAP UserDefinedMap
Definition LayoutBuilder.h:486
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:666
RecordFieldType< INDEX >::Builder & content() noexcept
Returns the reference to the builder contents at INDEX.
Definition LayoutBuilder.h:537
std::tuple_element_t< INDEX, RecordContents > RecordFieldType
Definition LayoutBuilder.h:489
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:504
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:543
typename std::tuple< BUILDERS... > RecordContents
Definition LayoutBuilder.h:485
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:549
size_t length() const noexcept
Current number of records in first field.
Definition LayoutBuilder.h:580
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:655
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:555
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:586
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:615
void set_fields(MAP user_defined_field_id_to_name_map) noexcept
Sets the field names.
Definition LayoutBuilder.h:530
void to_buffer(void *buffer, const char *name) const noexcept
Copies and concatenates the accumulated data in the buffers of the builder contents to user-defined p...
Definition LayoutBuilder.h:642
const std::vector< std::string > fields() const noexcept
Returns a vector of strings sontaining all the field names.
Definition LayoutBuilder.h:513
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:630
RecordContents contents
The contents of the RecordArray.
Definition LayoutBuilder.h:695
Builds a RegularArray that describes lists that have the same length, a single integer size....
Definition LayoutBuilder.h:963
void clear() noexcept
Clears the builder content.
Definition LayoutBuilder.h:1012
BUILDER & begin_list() noexcept
Begins a list and returns the reference to the content of the builder.
Definition LayoutBuilder.h:980
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:1077
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:992
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:998
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:973
size_t length() const noexcept
Current number of lists of length SIZE.
Definition LayoutBuilder.h:1019
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:1070
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1004
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1025
void end_list() noexcept
Ends a list and increments the number of lists.
Definition LayoutBuilder.h:986
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:1042
void to_buffer(void *buffer, const char *name) const noexcept
Copies and concatenates the accumulated data in the buffers of the builder content to user-defined po...
Definition LayoutBuilder.h:1061
Regular()
Creates a new Regular layout builder.
Definition LayoutBuilder.h:966
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:1053
Helper for building an array of strings with a similar API as a Numpy builder.
Definition LayoutBuilder.h:396
void append(const std::string &value)
Definition LayoutBuilder.h:403
String()
Definition LayoutBuilder.h:398
Builds a RecordArray which represents an array of tuples which can be of same or different types with...
Definition LayoutBuilder.h:747
void clear() noexcept
Clears the builder contents.
Definition LayoutBuilder.h:795
TupleContents contents
The contents of the RecordArray without fields.
Definition LayoutBuilder.h:917
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:892
Tuple()
Creates a new Tuple layout builder.
Definition LayoutBuilder.h:755
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:769
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:775
size_t length() const noexcept
Current number of records in the first index of the tuple.
Definition LayoutBuilder.h:805
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:881
TupleContentType< INDEX > & content() noexcept
Returns the reference to the builder contents at INDEX.
Definition LayoutBuilder.h:763
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:781
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:811
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:841
void to_buffer(void *buffer, const char *name) const noexcept
Copies and concatenates the accumulated data in the buffers of the builder contents to user-defined p...
Definition LayoutBuilder.h:868
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:856
Builds a UnionArray which represents data drawn from an ordered list of contents, which can have diff...
Definition LayoutBuilder.h:2234
void clear() noexcept
Discards the accumulated tags and index, and clears the builder contents.
Definition LayoutBuilder.h:2320
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:2258
typename std::tuple< BUILDERS... > Contents
Definition LayoutBuilder.h:2236
std::tuple_element_t< I, Contents > ContentType
Definition LayoutBuilder.h:2239
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:2278
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:2452
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:2292
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:2298
size_t length() const noexcept
Current length of the tags buffer.
Definition LayoutBuilder.h:2336
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:2434
Union()
Creates a new Union layout builder by allocating new tags and index buffers, using AWKWARD_LAYOUTBUIL...
Definition LayoutBuilder.h:2243
ContentType< I > & content() noexcept
Definition LayoutBuilder.h:2270
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:2304
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:2342
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:2372
void to_buffer(void *buffer, const char *name) const noexcept
Copies and concatenates the accumulated data in the builder buffers to user-defined pointers if the g...
Definition LayoutBuilder.h:2412
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:2392
Builds an UnmaskedArray which the values are never, in fact, missing. It exists to satisfy systems th...
Definition LayoutBuilder.h:1564
void clear() noexcept
Clears the builder content.
Definition LayoutBuilder.h:1600
Unmasked()
Creates a new Unmasked layout builder.
Definition LayoutBuilder.h:1567
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:1654
const std::string & parameters() const noexcept
Parameters for the builder form.
Definition LayoutBuilder.h:1580
void set_parameters(std::string parameter) noexcept
Sets the form parameters.
Definition LayoutBuilder.h:1586
BUILDER & content() noexcept
Returns the reference to the builder content.
Definition LayoutBuilder.h:1574
size_t length() const noexcept
Current length of the content.
Definition LayoutBuilder.h:1606
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:1647
void set_id(size_t &id) noexcept
Assigns a unique ID to each node.
Definition LayoutBuilder.h:1592
bool is_valid(std::string &error) const noexcept
Checks for validity and consistency.
Definition LayoutBuilder.h:1612
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:1619
void to_buffer(void *buffer, const char *name) const noexcept
Copies and concatenates the accumulated data in the buffers of the builder content to user-defined po...
Definition LayoutBuilder.h:1638
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:1630
Definition ArrayBuilder.h:14
void visit_at(std::tuple< CONTENTs... > const &contents, size_t index, FUNCTION fun)
Visits the tuple contents at index.
Definition utils.h:263
Container for all configuration options needed by ArrayBuilder, GrowableBuffer, LayoutBuilder and the...
Definition BuilderOptions.h:20
Definition utils.h:168
std::map< std::size_t, std::string > UserDefinedMap
Definition test_1494-layout-builder.cpp:39