@@ -112,22 +112,6 @@ std::vector<ROOT::RFieldBase::RValue> SplitVector(std::shared_ptr<void> valuePtr
112
112
return result;
113
113
}
114
114
115
- std::vector<ROOT::RFieldBase::RValue>
116
- SplitBoolVector (std::shared_ptr<std::vector<bool >> boolVec, ROOT::RFieldBase &itemField)
117
- {
118
- auto count = boolVec->size ();
119
- std::vector<ROOT::RFieldBase::RValue> result;
120
- result.reserve (count);
121
- for (unsigned i = 0 ; i < count; ++i) {
122
- if ((*boolVec)[i]) {
123
- result.emplace_back (itemField.BindValue (std::shared_ptr<bool >(new bool (true ))));
124
- } else {
125
- result.emplace_back (itemField.BindValue (std::shared_ptr<bool >(new bool (false ))));
126
- }
127
- }
128
- return result;
129
- }
130
-
131
115
} // anonymous namespace
132
116
133
117
ROOT::RArrayField::RArrayField (std::string_view fieldName, std::unique_ptr<RFieldBase> itemField,
@@ -785,15 +769,47 @@ void ROOT::RField<std::vector<bool>>::ReadGlobalImpl(ROOT::NTupleSize_t globalIn
785
769
{
786
770
auto typedValue = static_cast <std::vector<bool > *>(to);
787
771
788
- ROOT::NTupleSize_t nItems;
789
- RNTupleLocalIndex collectionStart;
790
- fPrincipalColumn ->GetCollectionInfo (globalIndex, &collectionStart, &nItems);
772
+ if (fOnDiskNRepetitions == 0 ) {
773
+ ROOT::NTupleSize_t nItems;
774
+ RNTupleLocalIndex collectionStart;
775
+ fPrincipalColumn ->GetCollectionInfo (globalIndex, &collectionStart, &nItems);
776
+ typedValue->resize (nItems);
777
+ for (std::size_t i = 0 ; i < nItems; ++i) {
778
+ bool bval;
779
+ CallReadOn (*fSubfields [0 ], collectionStart + i, &bval);
780
+ (*typedValue)[i] = bval;
781
+ }
782
+ } else {
783
+ typedValue->resize (fOnDiskNRepetitions );
784
+ for (std::size_t i = 0 ; i < fOnDiskNRepetitions ; ++i) {
785
+ bool bval;
786
+ CallReadOn (*fSubfields [0 ], globalIndex * fOnDiskNRepetitions + i, &bval);
787
+ (*typedValue)[i] = bval;
788
+ }
789
+ }
790
+ }
791
791
792
- typedValue->resize (nItems);
793
- for (unsigned i = 0 ; i < nItems; ++i) {
794
- bool bval;
795
- CallReadOn (*fSubfields [0 ], collectionStart + i, &bval);
796
- (*typedValue)[i] = bval;
792
+ void ROOT::RField<std::vector<bool >>::ReadInClusterImpl(ROOT::RNTupleLocalIndex localIndex, void *to)
793
+ {
794
+ auto typedValue = static_cast <std::vector<bool > *>(to);
795
+
796
+ if (fOnDiskNRepetitions == 0 ) {
797
+ ROOT::NTupleSize_t nItems;
798
+ RNTupleLocalIndex collectionStart;
799
+ fPrincipalColumn ->GetCollectionInfo (localIndex, &collectionStart, &nItems);
800
+ typedValue->resize (nItems);
801
+ for (std::size_t i = 0 ; i < nItems; ++i) {
802
+ bool bval;
803
+ CallReadOn (*fSubfields [0 ], collectionStart + i, &bval);
804
+ (*typedValue)[i] = bval;
805
+ }
806
+ } else {
807
+ typedValue->resize (fOnDiskNRepetitions );
808
+ for (std::size_t i = 0 ; i < fOnDiskNRepetitions ; ++i) {
809
+ bool bval;
810
+ CallReadOn (*fSubfields [0 ], localIndex * fOnDiskNRepetitions + i, &bval);
811
+ (*typedValue)[i] = bval;
812
+ }
797
813
}
798
814
}
799
815
@@ -803,7 +819,7 @@ const ROOT::RFieldBase::RColumnRepresentations &ROOT::RField<std::vector<bool>>:
803
819
{ENTupleColumnType::kIndex64 },
804
820
{ENTupleColumnType::kSplitIndex32 },
805
821
{ENTupleColumnType::kIndex32 }},
806
- {});
822
+ {{} });
807
823
return representations;
808
824
}
809
825
@@ -814,36 +830,39 @@ void ROOT::RField<std::vector<bool>>::GenerateColumns()
814
830
815
831
void ROOT::RField<std::vector<bool >>::GenerateColumns(const ROOT::RNTupleDescriptor &desc)
816
832
{
817
- GenerateColumnsImpl<ROOT::Internal::RColumnIndex>(desc);
833
+ if (fOnDiskNRepetitions == 0 )
834
+ GenerateColumnsImpl<ROOT::Internal::RColumnIndex>(desc);
818
835
}
819
836
820
- std::unique_ptr<ROOT::RFieldBase>
821
- ROOT::RField<std::vector<bool >>::BeforeConnectPageSource(Internal::RPageSource &pageSource)
837
+ void ROOT::RField<std::vector<bool >>::ReconcileOnDiskField(const RNTupleDescriptor &desc)
822
838
{
823
- if (GetOnDiskId () == kInvalidDescriptorId )
824
- return nullptr ;
825
-
826
- const auto descGuard = pageSource.GetSharedDescriptorGuard ();
827
- const auto &fieldDesc = descGuard->GetFieldDescriptor (GetOnDiskId ());
839
+ const auto &fieldDesc = desc.GetFieldDescriptor (GetOnDiskId ());
828
840
if (fieldDesc.GetTypeName ().rfind (" std::array<" , 0 ) == 0 ) {
829
- auto itemClone = fSubfields [0 ]->Clone (fSubfields [0 ]->GetFieldName ()).release ();
830
- auto substitute = std::make_unique<RArrayAsBoolVectorField>(
831
- GetFieldName (), std::unique_ptr<RField<bool >>(static_cast <RField<bool > *>(itemClone)),
832
- fieldDesc.GetNRepetitions ());
833
- substitute->SetOnDiskId (GetOnDiskId ());
834
- return substitute;
841
+ EnsureMatchingOnDiskField (fieldDesc, kDiffTypeName | kDiffStructure | kDiffNRepetitions ).ThrowOnError ();
842
+ if (fieldDesc.GetNRepetitions () == 0 )
843
+ throw RException (R__FAIL (" fixed-size array --> std::vector<bool>: expected repetition count > 0" ));
844
+ if (fieldDesc.GetStructure () != ENTupleStructure::kPlain )
845
+ throw RException (R__FAIL (" fixed-size array --> std::vector<bool>: expected plain on-disk field" ));
846
+ fOnDiskNRepetitions = fieldDesc.GetNRepetitions ();
847
+ } else {
848
+ EnsureMatchingOnDiskField (fieldDesc, kDiffTypeName ).ThrowOnError ();
835
849
}
836
- return nullptr ;
837
- }
838
-
839
- void ROOT::RField<std::vector<bool >>::ReconcileOnDiskField(const RNTupleDescriptor &desc)
840
- {
841
- EnsureMatchingOnDiskField (desc.GetFieldDescriptor (GetOnDiskId ()), kDiffTypeName ).ThrowOnError ();
842
850
}
843
851
844
852
std::vector<ROOT::RFieldBase::RValue> ROOT::RField<std::vector<bool >>::SplitValue(const RValue &value) const
845
853
{
846
- return SplitBoolVector (value.GetPtr <std::vector<bool >>(), *fSubfields [0 ]);
854
+ const auto typedValue = value.GetPtr <std::vector<bool >>();
855
+ auto count = typedValue->size ();
856
+ std::vector<ROOT::RFieldBase::RValue> result;
857
+ result.reserve (count);
858
+ for (unsigned i = 0 ; i < count; ++i) {
859
+ if ((*typedValue)[i]) {
860
+ result.emplace_back (fSubfields [0 ]->BindValue (std::shared_ptr<bool >(new bool (true ))));
861
+ } else {
862
+ result.emplace_back (fSubfields [0 ]->BindValue (std::shared_ptr<bool >(new bool (false ))));
863
+ }
864
+ }
865
+ return result;
847
866
}
848
867
849
868
void ROOT::RField<std::vector<bool >>::AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const
@@ -1036,71 +1055,3 @@ void ROOT::RArrayAsVectorField::AcceptVisitor(ROOT::Detail::RFieldVisitor &visit
1036
1055
{
1037
1056
visitor.VisitArrayAsVectorField (*this );
1038
1057
}
1039
-
1040
- // ------------------------------------------------------------------------------
1041
-
1042
- ROOT::RArrayAsBoolVectorField::RArrayAsBoolVectorField (std::string_view fieldName,
1043
- std::unique_ptr<ROOT::RField<bool >> itemField,
1044
- std::size_t arrayLength)
1045
- : ROOT::RFieldBase(fieldName, " std::vector<bool>" , ROOT::ENTupleStructure::kCollection , false /* isSimple */ ),
1046
- fArrayLength(arrayLength)
1047
- {
1048
- Attach (std::move (itemField));
1049
- }
1050
-
1051
- std::unique_ptr<ROOT::RFieldBase> ROOT::RArrayAsBoolVectorField::CloneImpl (std::string_view newName) const
1052
- {
1053
- auto clone = fSubfields [0 ]->Clone (fSubfields [0 ]->GetFieldName ()).release ();
1054
- auto newItemField = std::unique_ptr<RField<bool >>(static_cast <RField<bool > *>(clone));
1055
- return std::make_unique<RArrayAsBoolVectorField>(newName, std::move (newItemField), fArrayLength );
1056
- }
1057
-
1058
- void ROOT::RArrayAsBoolVectorField::GenerateColumns ()
1059
- {
1060
- throw RException (R__FAIL (" RArrayAsBoolVectorField fields must only be used for reading" ));
1061
- }
1062
-
1063
- void ROOT::RArrayAsBoolVectorField::ReadGlobalImpl (ROOT::NTupleSize_t globalIndex, void *to)
1064
- {
1065
- auto typedValue = static_cast <std::vector<bool > *>(to);
1066
-
1067
- typedValue->resize (fArrayLength );
1068
- for (std::size_t i = 0 ; i < fArrayLength ; ++i) {
1069
- bool val;
1070
- CallReadOn (*fSubfields [0 ], globalIndex * fArrayLength + i, &val);
1071
- (*typedValue)[i] = val;
1072
- }
1073
- }
1074
-
1075
- void ROOT::RArrayAsBoolVectorField::ReadInClusterImpl (ROOT::RNTupleLocalIndex localIndex, void *to)
1076
- {
1077
- auto typedValue = static_cast <std::vector<char > *>(to);
1078
-
1079
- typedValue->resize (fArrayLength );
1080
- for (std::size_t i = 0 ; i < fArrayLength ; ++i) {
1081
- bool val;
1082
- CallReadOn (*fSubfields [0 ], localIndex * fArrayLength + i, &val);
1083
- (*typedValue)[i] = val;
1084
- }
1085
- }
1086
-
1087
- void ROOT::RArrayAsBoolVectorField::ReconcileOnDiskField (const RNTupleDescriptor &desc)
1088
- {
1089
- const auto &fieldDesc = desc.GetFieldDescriptor (GetOnDiskId ());
1090
- EnsureMatchingOnDiskField (fieldDesc, kDiffTypeName | kDiffTypeVersion | kDiffStructure | kDiffNRepetitions );
1091
- if (fieldDesc.GetTypeName ().rfind (" std::array<" , 0 ) != 0 ) {
1092
- throw RException (
1093
- R__FAIL (" RArrayAsBoolVectorField " + GetQualifiedFieldName () + " expects an on-disk array field" ));
1094
- }
1095
- }
1096
-
1097
- std::vector<ROOT::RFieldBase::RValue>
1098
- ROOT::RArrayAsBoolVectorField::SplitValue (const ROOT::RFieldBase::RValue &value) const
1099
- {
1100
- return SplitBoolVector (value.GetPtr <std::vector<bool >>(), *fSubfields [0 ]);
1101
- }
1102
-
1103
- void ROOT::RArrayAsBoolVectorField::AcceptVisitor (ROOT::Detail::RFieldVisitor &visitor) const
1104
- {
1105
- visitor.VisitArrayAsBoolVectorField (*this );
1106
- }
0 commit comments