Warning, file /include/root/ROOT/RRawPtrWriteEntry.hxx was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef ROOT_RRawPtrWriteEntry
0017 #define ROOT_RRawPtrWriteEntry
0018
0019 #include <ROOT/RFieldBase.hxx>
0020 #include <ROOT/RFieldToken.hxx>
0021 #include <ROOT/RError.hxx>
0022
0023 #include <cstdint>
0024 #include <unordered_map>
0025 #include <vector>
0026
0027 namespace ROOT {
0028
0029 class RNTupleModel;
0030
0031 class RNTupleFillContext;
0032
0033 namespace Experimental {
0034 namespace Detail {
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046 class RRawPtrWriteEntry {
0047 friend class ROOT::RNTupleModel;
0048 friend class ROOT::RNTupleFillContext;
0049
0050 private:
0051
0052 std::uint64_t fModelId = 0;
0053
0054 std::uint64_t fSchemaId = 0;
0055
0056 std::vector<ROOT::RFieldBase *> fFields;
0057
0058 std::vector<const void *> fRawPtrs;
0059
0060 std::unordered_map<std::string, std::size_t> fFieldName2Token;
0061
0062 explicit RRawPtrWriteEntry(std::uint64_t modelId, std::uint64_t schemaId) : fModelId(modelId), fSchemaId(schemaId) {}
0063
0064 void AddField(ROOT::RFieldBase &field)
0065 {
0066 fFieldName2Token[field.GetQualifiedFieldName()] = fFields.size();
0067 fFields.emplace_back(&field);
0068 fRawPtrs.emplace_back(nullptr);
0069 }
0070
0071 std::size_t Append()
0072 {
0073 std::size_t bytesWritten = 0;
0074 for (std::size_t i = 0; i < fFields.size(); i++) {
0075 bytesWritten += fFields[i]->Append(fRawPtrs[i]);
0076 }
0077 return bytesWritten;
0078 }
0079
0080 void EnsureMatchingModel(RFieldToken token) const
0081 {
0082 if (fSchemaId != token.fSchemaId) {
0083 throw RException(R__FAIL("invalid token for this entry, "
0084 "make sure to use a token from a model with the same schema as this entry."));
0085 }
0086 }
0087
0088 public:
0089 RRawPtrWriteEntry(const RRawPtrWriteEntry &other) = delete;
0090 RRawPtrWriteEntry &operator=(const RRawPtrWriteEntry &other) = delete;
0091 RRawPtrWriteEntry(RRawPtrWriteEntry &&other) = default;
0092 RRawPtrWriteEntry &operator=(RRawPtrWriteEntry &&other) = default;
0093 ~RRawPtrWriteEntry() = default;
0094
0095
0096 RFieldToken GetToken(std::string_view fieldName) const
0097 {
0098 auto it = fFieldName2Token.find(std::string(fieldName));
0099 if (it == fFieldName2Token.end()) {
0100 throw RException(R__FAIL("invalid field name: " + std::string(fieldName)));
0101 }
0102 return RFieldToken(it->second, fSchemaId);
0103 }
0104
0105 template <typename T>
0106 void BindRawPtr(RFieldToken token, const T *rawPtr)
0107 {
0108 EnsureMatchingModel(token);
0109 fRawPtrs[token.fIndex] = rawPtr;
0110 }
0111
0112 template <typename T>
0113 void BindRawPtr(std::string_view fieldName, const T *rawPtr)
0114 {
0115 BindRawPtr(GetToken(fieldName), rawPtr);
0116 }
0117
0118 std::uint64_t GetModelId() const { return fModelId; }
0119 std::uint64_t GetSchemaId() const { return fSchemaId; }
0120 };
0121
0122 }
0123 }
0124 }
0125
0126 #endif