Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
27 ROOT::Experimental::RNTupleModel::RNTupleModel()
28  : fRootField(std::make_unique<RFieldRoot>())
29  , fDefaultEntry(std::make_unique<REntry>())
30 {}
31 
32 ROOT::Experimental::RNTupleModel* ROOT::Experimental::RNTupleModel::Clone()
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 
42 void 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 
49 std::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 
59 std::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 }