Logo ROOT  
Reference Guide
RNTupleModel.cxx
Go to the documentation of this file.
1/// \file RNTupleModel.cxx
2/// \ingroup NTuple ROOT7
3/// \author Jakob Blomer <jblomer@cern.ch>
4/// \date 2018-10-15
5/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6/// is welcome!
7
8/*************************************************************************
9 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
10 * All rights reserved. *
11 * *
12 * For the licensing terms see $ROOTSYS/LICENSE. *
13 * For the list of contributors see $ROOTSYS/README/CREDITS. *
14 *************************************************************************/
15
16#include <ROOT/RField.hxx>
17#include <ROOT/RNTupleModel.hxx>
18#include <ROOT/RNTuple.hxx>
19
20#include <TError.h>
21
22#include <cstdlib>
23#include <memory>
24#include <utility>
25
26
28 : fRootField(std::make_unique<RFieldRoot>())
29 , fDefaultEntry(std::make_unique<REntry>())
30{}
31
33{
34 auto cloneModel = new RNTupleModel();
35 auto cloneRootField = static_cast<RFieldRoot*>(fRootField->Clone(""));
36 cloneModel->fRootField = std::unique_ptr<RFieldRoot>(cloneRootField);
37 cloneModel->fDefaultEntry = std::unique_ptr<REntry>(cloneRootField->GenerateEntry());
38 return cloneModel;
39}
40
41
42void ROOT::Experimental::RNTupleModel::AddField(std::unique_ptr<Detail::RFieldBase> field)
43{
44 fDefaultEntry->AddValue(field->GenerateValue());
45 fRootField->Attach(std::move(field));
46}
47
48
49std::shared_ptr<ROOT::Experimental::RCollectionNTuple> ROOT::Experimental::RNTupleModel::MakeCollection(
50 std::string_view fieldName, std::unique_ptr<RNTupleModel> collectionModel)
51{
52 auto collectionNTuple = std::make_shared<RCollectionNTuple>(std::move(collectionModel->fDefaultEntry));
53 auto field = std::make_unique<RFieldCollection>(fieldName, collectionNTuple, std::move(collectionModel));
54 fDefaultEntry->CaptureValue(field->CaptureValue(collectionNTuple->GetOffsetPtr()));
55 fRootField->Attach(std::move(field));
56 return collectionNTuple;
57}
58
59std::unique_ptr<ROOT::Experimental::REntry> ROOT::Experimental::RNTupleModel::CreateEntry()
60{
61 auto entry = std::make_unique<REntry>();
62 for (auto& f : *fRootField) {
63 if (f.GetParent() != GetRootField())
64 continue;
65 entry->AddValue(f.GenerateValue());
66 }
67 return entry;
68}
#define f(i)
Definition: RSha256.hxx:104
The REntry is a collection of values in an ntuple corresponding to a complete row in the data set.
Definition: REntry.hxx:42
The container field for an ntuple model, which itself has no physical representation.
Definition: RField.hxx:290
The RNTupleModel encapulates the schema of an ntuple.
std::shared_ptr< RCollectionNTuple > MakeCollection(std::string_view fieldName, std::unique_ptr< RNTupleModel > collectionModel)
Ingests a model for a sub collection and attaches it to the current model.
std::unique_ptr< REntry > CreateEntry()
void AddField(std::unique_ptr< Detail::RFieldBase > field)
Adds a field whose type is not known at compile time. Thus there is no shared pointer returned.
basic_string_view< char > string_view