60using ModelTokensPair = std::pair<std::unique_ptr<RNTupleModel>, std::vector<REntry::RFieldToken>>;
72 std::unique_ptr<TFile> fFile;
78 fFile.reset(
TFile::Open(std::string(
url).c_str(), std::string(options).c_str()));
82 TFile &GetFile() {
return *fFile; }
83 std::mutex &GetMutex() {
return fMutex; }
91 virtual void InitSlot(
unsigned slot) = 0;
92 virtual void Fill(
unsigned slot,
const std::vector<DataProduct> &
products) = 0;
99 std::vector<REntry::RFieldToken>
fTokens;
103 std::unique_ptr<REntry>
entry;
105 std::vector<SlotData>
fSlots;
109 const RNTupleWriteOptions &options)
118 void InitSlot(
unsigned slot)
final
129 void Fill(
unsigned slot,
const std::vector<DataProduct> &
products)
final
141 RNTupleFillStatus status;
143 if (status.ShouldFlushCluster()) {
164 std::unique_ptr<RNTupleWriter> fWriter;
166 std::vector<REntry::RFieldToken>
fTokens;
169 std::unique_ptr<REntry>
entry;
171 std::vector<SlotData>
fSlots;
175 const RNTupleWriteOptions &options)
184 void InitSlot(
unsigned slot)
final
191 fSlots[
slot].entry = fWriter->GetModel().CreateBareEntry();
194 void Fill(
unsigned slot,
const std::vector<DataProduct> &
products)
final
208 RNTupleFillStatus status;
209 fWriter->FillNoFlush(
entry, status);
210 if (status.ShouldFlushCluster()) {
214 fWriter->FlushColumns();
219 fWriter->FlushCluster();
245 std::vector<ChargedTrack>
muons;
252 auto model = RNTupleModel::CreateBare();
254 std::vector<REntry::RFieldToken>
tokens;
257 tokens.push_back(model->GetToken(
"eventId"));
259 model->MakeField<
decltype(Event::runId)>(
"runId");
260 tokens.push_back(model->GetToken(
"runId"));
262 model->MakeField<
decltype(Event::electrons)>(
"electrons");
263 tokens.push_back(model->GetToken(
"electrons"));
265 model->MakeField<
decltype(Event::photons)>(
"photons");
266 tokens.push_back(model->GetToken(
"photons"));
268 model->MakeField<
decltype(Event::muons)>(
"muons");
269 tokens.push_back(model->GetToken(
"muons"));
271 return {std::move(model), std::move(
tokens)};
280 products.emplace_back(1, &event.runId);
281 products.emplace_back(2, &event.electrons);
282 products.emplace_back(3, &event.photons);
283 products.emplace_back(4, &event.muons);
290 std::uint32_t nEvents;
297 auto model = RNTupleModel::CreateBare();
299 std::vector<REntry::RFieldToken>
tokens;
301 model->MakeField<
decltype(Run::runId)>(
"runId");
302 tokens.push_back(model->GetToken(
"runId"));
304 model->MakeField<
decltype(Run::nEvents)>(
"nEvents");
305 tokens.push_back(model->GetToken(
"nEvents"));
307 return {std::move(model), std::move(
tokens)};
315 products.emplace_back(0, &run.runId);
316 products.emplace_back(1, &run.nEvents);
330 std::uniform_real_distribution<float>
floatDist;
334 std::uint32_t nEvents = 0;
336 nEvents =
static_cast<std::uint32_t
>(
nEventsD);
343 for (std::uint32_t eventId = 0; eventId < nEvents; eventId++) {
344 event.eventId = eventId;
353 electron.charge = (gen() % 2 ? 1 : -1);
365 muon.mass = 105.658 ;
368 muon.charge = (gen() % 2 ? 1 : -1);
377 run.nEvents = nEvents;
390 RNTupleWriteOptions options;
392 options.SetUseBufferedWrite(
true);
394 options.SetApproxZippedClusterSize(2 * 1024 * 1024);
398 options.SetUseBufferedWrite(
true);
400 options.SetApproxZippedClusterSize(1024);
404 for (
unsigned i = 0; i <
kNThreads; i++) {
409 std::vector<std::thread>
threads;
410 for (
unsigned i = 0; i <
kNThreads; i++) {
413 for (
unsigned i = 0; i <
kNThreads; i++) {
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
The REntry is a collection of values in an ntuple corresponding to a complete row in the data set.
A context for filling entries (data) into clusters of an RNTuple.
A status object after filling an entry.
The RNTupleModel encapulates the schema of an ntuple.
A writer to fill an RNTuple from multiple contexts.
An RNTuple that gets filled with entries (data) and writes them to storage.
Common user-tunable settings for storing ntuples.
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
double product(double const *factors, std::size_t nFactors)