49using ModelTokensPair = std::pair<std::unique_ptr<ROOT::RNTupleModel>, std::vector<ROOT::RFieldToken>>;
61 std::unique_ptr<TFile> fFile;
67 fFile.reset(
TFile::Open(std::string(
url).c_str(), std::string(options).c_str()));
71 TFile &GetFile() {
return *fFile; }
72 std::mutex &GetMutex() {
return fMutex; }
80 virtual void InitSlot(
unsigned slot) = 0;
81 virtual void Fill(
unsigned slot,
const std::vector<DataProduct> &
products) = 0;
88 std::vector<ROOT::RFieldToken>
fTokens;
91 std::shared_ptr<ROOT::RNTupleFillContext>
fillContext;
92 std::unique_ptr<ROOT::Detail::RRawPtrWriteEntry>
entry;
94 std::vector<SlotData> fSlots;
108 void InitSlot(
unsigned slot)
final
110 if (
slot >= fSlots.size()) {
111 fSlots.resize(
slot + 1);
115 fSlots[
slot].entry = fSlots[
slot].fillContext->GetModel().CreateRawPtrWriteEntry();
118 void Fill(
unsigned slot,
const std::vector<DataProduct> &
products)
final
153 std::unique_ptr<ROOT::RNTupleWriter> fWriter;
155 std::vector<ROOT::RFieldToken>
fTokens;
158 std::unique_ptr<ROOT::Detail::RRawPtrWriteEntry>
entry;
160 std::vector<SlotData> fSlots;
173 void InitSlot(
unsigned slot)
final
175 if (
slot >= fSlots.size()) {
176 fSlots.resize(
slot + 1);
179 fSlots[
slot].entry = fWriter->GetModel().CreateRawPtrWriteEntry();
182 void Fill(
unsigned slot,
const std::vector<DataProduct> &
products)
final
197 fWriter->FillNoFlush(
entry, status);
202 fWriter->FlushColumns();
207 fWriter->FlushCluster();
233 std::vector<ChargedTrack>
muons;
242 std::vector<ROOT::RFieldToken>
tokens;
245 tokens.push_back(model->GetToken(
"eventId"));
247 model->MakeField<
decltype(Event::runId)>(
"runId");
248 tokens.push_back(model->GetToken(
"runId"));
250 model->MakeField<
decltype(Event::electrons)>(
"electrons");
251 tokens.push_back(model->GetToken(
"electrons"));
253 model->MakeField<
decltype(Event::photons)>(
"photons");
254 tokens.push_back(model->GetToken(
"photons"));
256 model->MakeField<
decltype(Event::muons)>(
"muons");
257 tokens.push_back(model->GetToken(
"muons"));
259 return {std::move(model), std::move(
tokens)};
268 products.emplace_back(1, &event.runId);
269 products.emplace_back(2, &event.electrons);
270 products.emplace_back(3, &event.photons);
271 products.emplace_back(4, &event.muons);
278 std::uint32_t nEvents;
287 std::vector<ROOT::RFieldToken>
tokens;
289 model->MakeField<
decltype(Run::runId)>(
"runId");
290 tokens.push_back(model->GetToken(
"runId"));
292 model->MakeField<
decltype(Run::nEvents)>(
"nEvents");
293 tokens.push_back(model->GetToken(
"nEvents"));
295 return {std::move(model), std::move(
tokens)};
303 products.emplace_back(0, &run.runId);
304 products.emplace_back(1, &run.nEvents);
318 std::uniform_real_distribution<float>
floatDist;
322 std::uint32_t nEvents = 0;
324 nEvents =
static_cast<std::uint32_t
>(
nEventsD);
331 for (std::uint32_t eventId = 0; eventId < nEvents; eventId++) {
332 event.eventId = eventId;
353 muon.mass = 105.658 ;
356 muon.charge = (
gen() % 2 ? 1 : -1);
365 run.nEvents = nEvents;
392 for (
unsigned i = 0; i <
kNThreads; i++) {
397 std::vector<std::thread>
threads;
398 for (
unsigned i = 0; i <
kNThreads; i++) {
401 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
A status object after filling an entry.
bool ShouldFlushCluster() const
Return true if the caller should call FlushCluster.
static std::unique_ptr< RNTupleModel > CreateBare()
Creates a "bare model", i.e. an RNTupleModel with no default entry.
static std::unique_ptr< RNTupleParallelWriter > Append(std::unique_ptr< ROOT::RNTupleModel > model, std::string_view ntupleName, TDirectory &fileOrDirectory, const ROOT::RNTupleWriteOptions &options=ROOT::RNTupleWriteOptions())
Append an RNTuple to the existing file.
Common user-tunable settings for storing RNTuples.
void SetUseBufferedWrite(bool val)
void SetApproxZippedClusterSize(std::size_t val)
static std::unique_ptr< RNTupleWriter > Append(std::unique_ptr< ROOT::RNTupleModel > model, std::string_view ntupleName, TDirectory &fileOrDirectory, const ROOT::RNTupleWriteOptions &options=ROOT::RNTupleWriteOptions())
Creates an RNTupleWriter that writes into an existing TFile or TDirectory, without overwriting its co...
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(DoubleArray factors, std::size_t nFactors)