31 namespace Experimental {
53 RPageSource *fPageSource;
54 RPageStorage::ColumnHandle_t fHandleSink;
55 RPageStorage::ColumnHandle_t fHandleSource;
59 NTupleSize_t fNElements;
63 ColumnId_t fColumnIdSource;
65 std::unique_ptr<RColumnElementBase> fElement;
67 RColumn(
const RColumnModel &model, std::uint32_t index);
70 template <
typename CppT, EColumnType ColumnT>
71 static RColumn *Create(
const RColumnModel &model, std::uint32_t index) {
72 R__ASSERT(model.GetType() == ColumnT);
73 auto column =
new RColumn(model, index);
74 column->fElement = std::unique_ptr<RColumnElementBase>(
new RColumnElement<CppT, ColumnT>(
nullptr));
78 RColumn(
const RColumn&) =
delete;
79 RColumn &operator =(
const RColumn&) =
delete;
82 void Connect(DescriptorId_t fieldId, RPageStorage *pageStorage);
84 void Append(
const RColumnElementBase &element) {
85 void *dst = fHeadPage.TryGrow(1);
88 dst = fHeadPage.TryGrow(1);
89 R__ASSERT(dst !=
nullptr);
91 element.WriteTo(dst, 1);
95 void AppendV(
const RColumnElementBase &elemArray, std::size_t count) {
96 void *dst = fHeadPage.TryGrow(count);
98 for (
unsigned i = 0; i < count; ++i) {
99 Append(RColumnElementBase(elemArray, i));
103 elemArray.WriteTo(dst, count);
107 void Read(
const NTupleSize_t globalIndex, RColumnElementBase *element) {
108 if (!fCurrentPage.Contains(globalIndex)) {
109 MapPage(globalIndex);
111 void *src =
static_cast<unsigned char *
>(fCurrentPage.GetBuffer()) +
112 (globalIndex - fCurrentPage.GetGlobalRangeFirst()) * element->GetSize();
113 element->ReadFrom(src, 1);
116 void Read(
const RClusterIndex &clusterIndex, RColumnElementBase *element) {
117 if (!fCurrentPage.Contains(clusterIndex)) {
118 MapPage(clusterIndex);
120 void *src =
static_cast<unsigned char *
>(fCurrentPage.GetBuffer()) +
121 (clusterIndex.GetIndex() - fCurrentPage.GetClusterRangeFirst()) * element->GetSize();
122 element->ReadFrom(src, 1);
125 void ReadV(
const NTupleSize_t globalIndex,
const ClusterSize_t::ValueType count, RColumnElementBase *elemArray) {
126 if (!fCurrentPage.Contains(globalIndex)) {
127 MapPage(globalIndex);
129 NTupleSize_t idxInPage = globalIndex - fCurrentPage.GetGlobalRangeFirst();
131 void *src =
static_cast<unsigned char *
>(fCurrentPage.GetBuffer()) + idxInPage * elemArray->GetSize();
132 if (globalIndex + count <= fCurrentPage.GetGlobalRangeLast() + 1) {
133 elemArray->ReadFrom(src, count);
135 ClusterSize_t::ValueType nBatch = fCurrentPage.GetNElements() - idxInPage;
136 elemArray->ReadFrom(src, nBatch);
137 RColumnElementBase elemTail(*elemArray, nBatch);
138 ReadV(globalIndex + nBatch, count - nBatch, &elemTail);
142 void ReadV(
const RClusterIndex &clusterIndex,
const ClusterSize_t::ValueType count, RColumnElementBase *elemArray)
144 if (!fCurrentPage.Contains(clusterIndex)) {
145 MapPage(clusterIndex);
147 NTupleSize_t idxInPage = clusterIndex.GetIndex() - fCurrentPage.GetClusterRangeFirst();
149 void* src =
static_cast<unsigned char *
>(fCurrentPage.GetBuffer()) + idxInPage * elemArray->GetSize();
150 if (clusterIndex.GetIndex() + count <= fCurrentPage.GetClusterRangeLast() + 1) {
151 elemArray->ReadFrom(src, count);
153 ClusterSize_t::ValueType nBatch = fCurrentPage.GetNElements() - idxInPage;
154 elemArray->ReadFrom(src, nBatch);
155 RColumnElementBase elemTail(*elemArray, nBatch);
156 ReadV(RClusterIndex(clusterIndex.GetClusterId(), clusterIndex.GetIndex() + nBatch), count - nBatch, &elemTail);
160 template <
typename CppT, EColumnType ColumnT>
161 CppT *Map(
const NTupleSize_t globalIndex) {
162 if (!fCurrentPage.Contains(globalIndex)) {
163 MapPage(globalIndex);
165 return reinterpret_cast<CppT*
>(
166 static_cast<unsigned char *
>(fCurrentPage.GetBuffer()) +
167 (globalIndex - fCurrentPage.GetGlobalRangeFirst()) * RColumnElement<CppT, ColumnT>::kSize);
170 template <
typename CppT, EColumnType ColumnT>
171 CppT *Map(
const RClusterIndex &clusterIndex) {
172 if (!fCurrentPage.Contains(clusterIndex)) {
173 MapPage(clusterIndex);
175 return reinterpret_cast<CppT*
>(
176 static_cast<unsigned char *
>(fCurrentPage.GetBuffer()) +
177 (clusterIndex.GetIndex() - fCurrentPage.GetClusterRangeFirst()) * RColumnElement<CppT, ColumnT>::kSize);
180 NTupleSize_t GetGlobalIndex(
const RClusterIndex &clusterIndex) {
181 if (!fCurrentPage.Contains(clusterIndex)) {
182 MapPage(clusterIndex);
184 return fCurrentPage.GetClusterInfo().GetIndexOffset() + clusterIndex.GetIndex();
187 RClusterIndex GetClusterIndex(NTupleSize_t globalIndex) {
188 if (!fCurrentPage.Contains(globalIndex)) {
189 MapPage(globalIndex);
191 return RClusterIndex(fCurrentPage.GetClusterInfo().GetId(),
192 globalIndex - fCurrentPage.GetClusterInfo().GetIndexOffset());
196 void GetCollectionInfo(
const NTupleSize_t globalIndex, RClusterIndex *collectionStart, ClusterSize_t *collectionSize)
198 auto idxStart = (globalIndex == 0) ? 0 : *Map<ClusterSize_t, EColumnType::kIndex>(globalIndex - 1);
199 auto idxEnd = *Map<ClusterSize_t, EColumnType::kIndex>(globalIndex);
200 auto selfOffset = fCurrentPage.GetClusterInfo().GetIndexOffset();
201 if (globalIndex == selfOffset) {
205 *collectionSize = idxEnd - idxStart;
206 *collectionStart = RClusterIndex(fCurrentPage.GetClusterInfo().GetId(), idxStart);
209 void GetCollectionInfo(
const RClusterIndex &clusterIndex,
210 RClusterIndex *collectionStart, ClusterSize_t *collectionSize)
212 auto index = clusterIndex.GetIndex();
213 auto idxStart = (index == 0) ? 0 : *Map<ClusterSize_t, EColumnType::kIndex>(clusterIndex - 1);
214 auto idxEnd = *Map<ClusterSize_t, EColumnType::kIndex>(clusterIndex);
215 *collectionSize = idxEnd - idxStart;
216 *collectionStart = RClusterIndex(clusterIndex.GetClusterId(), idxStart);
220 void GetSwitchInfo(NTupleSize_t globalIndex, RClusterIndex *varIndex, std::uint32_t *tag) {
221 auto varSwitch = Map<RColumnSwitch, EColumnType::kSwitch>(globalIndex);
222 *varIndex = RClusterIndex(fCurrentPage.GetClusterInfo().GetId(), varSwitch->GetIndex());
223 *tag = varSwitch->GetTag();
227 void MapPage(
const NTupleSize_t index);
228 void MapPage(
const RClusterIndex &clusterIndex);
229 NTupleSize_t GetNElements()
const {
return fNElements; }
230 RColumnElementBase *GetElement()
const {
return fElement.get(); }
231 const RColumnModel &GetModel()
const {
return fModel; }
232 std::uint32_t GetIndex()
const {
return fIndex; }
233 ColumnId_t GetColumnIdSource()
const {
return fColumnIdSource; }
234 RPageSource *GetPageSource()
const {
return fPageSource; }
235 RPageStorage::ColumnHandle_t GetHandleSource()
const {
return fHandleSource; }
236 RPageStorage::ColumnHandle_t GetHandleSink()
const {
return fHandleSink; }
237 RNTupleVersion GetVersion()
const {
return RNTupleVersion(); }