1
1
// This example uses a non-public CMS NanoAOD file called: ttjet_13tev_june2019_lzma.
2
- // Please ask contact us if you need it.
2
+ // Please contact us if you need it.
3
3
4
4
#include " ../common/ttjet_13tev_june2019.hpp"
5
5
14
14
#include < llama/DumpMapping.hpp>
15
15
#include < llama/llama.hpp>
16
16
17
+ using SmallEvent = boost::mp11::mp_take_c<Event, 100 >;
18
+
17
19
int main (int argc, const char * argv[])
18
20
{
19
21
if (argc != 2 )
@@ -25,27 +27,90 @@ int main(int argc, const char* argv[])
25
27
using namespace std ::chrono;
26
28
using namespace ROOT ::Experimental;
27
29
30
+ // auto ntuple
31
+ // = RNTupleReader::Open(RNTupleModel::Create(), "NTuple", "/mnt/c/dev/llama/ttjet_13tev_june2019_lzma.root");
28
32
auto ntuple = RNTupleReader::Open (RNTupleModel::Create (), " NTuple" , argv[1 ]);
29
- const auto n = ntuple->GetNEntries ();
33
+ // try
34
+ // {
35
+ // ntuple->PrintInfo(ROOT::Experimental::ENTupleInfo::kStorageDetails);
36
+ // }
37
+ // catch (const std::exception& e)
38
+ // {
39
+ // fmt::print("PrintInfo error: {}", e.what());
40
+ // }
41
+ const auto eventCount = ntuple->GetNEntries ();
42
+ const auto & d = ntuple->GetDescriptor ();
43
+ const auto electronCount
44
+ = d.GetNElements (d.FindColumnId (d.FindFieldId (" nElectron.nElectron.Electron_deltaEtaSC" ), 0 ));
45
+ fmt::print (" File contains {} events with {} electrons\n " , eventCount, electronCount);
30
46
31
47
auto start = steady_clock::now ();
32
- auto view = llama::allocView (llama::mapping::SoA<llama::ArrayDims<1 >, Event, true >{llama::ArrayDims{n}});
48
+ auto mapping = llama::mapping::OffsetTable<llama::ArrayDims<1 >, SmallEvent>{
49
+ llama::ArrayDims{eventCount},
50
+ llama::ArrayDims{electronCount}};
51
+ auto view = llama::allocView (mapping);
33
52
fmt::print (" Alloc LLAMA view: {}ms\n " , duration_cast<milliseconds>(steady_clock::now () - start).count ());
34
53
35
54
std::size_t totalSize = 0 ;
36
55
for (auto i = 0u ; i < view.mapping .blobCount ; i++)
37
56
totalSize += view.mapping .blobSize (i);
38
57
fmt::print (" Total LLAMA view memory: {}MiB in {} blobs\n " , totalSize / 1024 / 1024 , view.mapping .blobCount );
39
58
59
+ // fill offset table
40
60
start = steady_clock::now ();
41
- llama::forEachLeaf<Event>(
61
+ std::size_t offset = 0 ;
62
+ auto electronViewCollection = ntuple->GetViewCollection (" nElectron" );
63
+ for (std::size_t i = 0 ; i < eventCount; i++)
64
+ {
65
+ offset += electronViewCollection (i);
66
+ view (i)(llama::EndOffset<nElectron>{}) = offset;
67
+ assert (offset <= electronCount);
68
+ }
69
+ fmt::print (" Fill offset table: {}ms\n " , duration_cast<milliseconds>(steady_clock::now () - start).count ());
70
+
71
+ using AugmentedSmallEvent = typename decltype (mapping)::RecordDim;
72
+ start = steady_clock::now ();
73
+ llama::forEachLeaf<AugmentedSmallEvent>(
42
74
[&](auto coord)
43
75
{
44
- using Name = llama::GetTag<Event, decltype (coord)>;
45
- using Type = llama::GetType<Event, decltype (coord)>;
46
- auto column = ntuple->GetView <Type>(llama::structName<Name>());
47
- for (std::size_t i = 0 ; i < n; i++)
48
- view (i)(coord) = column (i);
76
+ using Coord = decltype (coord);
77
+ using LeafTag = llama::GetTag<AugmentedSmallEvent, Coord>;
78
+ using Type = llama::GetType<AugmentedSmallEvent, Coord>;
79
+
80
+ fmt::print (" Copying {}\n " , llama::structName<LeafTag>());
81
+ if constexpr (
82
+ !llama::mapping::internal::isEndOffsetField<LeafTag> && !llama::mapping::internal::isSizeField<LeafTag>)
83
+ {
84
+ if constexpr (boost::mp11::mp_contains<typename Coord::List, boost::mp11::mp_size_t <llama::dynamic>>::
85
+ value)
86
+ {
87
+ using Before = llama::mapping::internal::BeforeDynamic<Coord>;
88
+ using BeforeBefore = llama::RecordCoordFromList<boost::mp11::mp_pop_front<typename Before::List>>;
89
+ using After = llama::mapping::internal::AfterDynamic<Coord>;
90
+ using SubCollectionTag = llama::GetTag<AugmentedSmallEvent, Before>;
91
+
92
+ auto collectionColumn = ntuple->GetViewCollection (llama::structName<SubCollectionTag>());
93
+ auto column = collectionColumn.template GetView <Type>(
94
+ llama::structName<SubCollectionTag>() + " ." + llama::structName<LeafTag>());
95
+ for (std::size_t i = 0 ; i < eventCount; i++)
96
+ {
97
+ const auto subCollectionCount = view (i)(BeforeBefore{})(llama::Size <SubCollectionTag>{});
98
+ assert (subCollectionCount == view (i)(llama::Size <nElectron>{}));
99
+ for (std::size_t j = 0 ; j < subCollectionCount; j++)
100
+ {
101
+ const auto value = column (j);
102
+ auto & dst = view (i)(Before{})(j) (After{});
103
+ dst = value;
104
+ }
105
+ }
106
+ }
107
+ else
108
+ {
109
+ auto column = ntuple->GetView <Type>(llama::structName<LeafTag>());
110
+ for (std::size_t i = 0 ; i < eventCount; i++)
111
+ view (i)(coord) = column (i);
112
+ }
113
+ }
49
114
});
50
115
fmt::print (" Copy RNTuple -> LLAMA view: {}ms\n " , duration_cast<milliseconds>(steady_clock::now () - start).count ());
51
116
0 commit comments