55using ModelTokensPair = std::pair<std::unique_ptr<ROOT::RNTupleModel>, std::vector<ROOT::RFieldToken>>;
67 std::unique_ptr<TFile> fFile;
73 fFile.reset(
TFile::Open(std::string(
url).c_str(), std::string(options).c_str()));
77 TFile &GetFile() {
return *fFile; }
78 std::mutex &GetMutex() {
return fMutex; }
86 virtual void InitSlot(
unsigned slot) = 0;
87 virtual void Fill(
unsigned slot,
const std::vector<DataProduct> &
products) = 0;
94 std::vector<ROOT::RFieldToken>
fTokens;
97 std::shared_ptr<ROOT::RNTupleFillContext>
fillContext;
98 std::unique_ptr<RRawPtrWriteEntry>
entry;
100 std::vector<SlotData> fSlots;
114 void InitSlot(
unsigned slot)
final
116 if (
slot >= fSlots.size()) {
117 fSlots.resize(
slot + 1);
121 fSlots[
slot].entry = fSlots[
slot].fillContext->GetModel().CreateRawPtrWriteEntry();
159 std::unique_ptr<ROOT::RNTupleWriter> fWriter;
161 std::vector<ROOT::RFieldToken>
fTokens;
164 std::unique_ptr<RRawPtrWriteEntry>
entry;
166 std::vector<SlotData> fSlots;
179 void InitSlot(
unsigned slot)
final
181 if (
slot >= fSlots.size()) {
182 fSlots.resize(
slot + 1);
185 fSlots[
slot].entry = fWriter->GetModel().CreateRawPtrWriteEntry();
203 fWriter->FillNoFlush(
entry, status);
208 fWriter->FlushColumns();
213 fWriter->FlushCluster();
239 std::vector<ChargedTrack>
muons;
248 std::vector<ROOT::RFieldToken>
tokens;
251 tokens.push_back(model->GetToken(
"eventId"));
253 model->MakeField<
decltype(Event::runId)>(
"runId");
254 tokens.push_back(model->GetToken(
"runId"));
256 model->MakeField<
decltype(Event::electrons)>(
"electrons");
257 tokens.push_back(model->GetToken(
"electrons"));
259 model->MakeField<
decltype(Event::photons)>(
"photons");
260 tokens.push_back(model->GetToken(
"photons"));
262 model->MakeField<
decltype(Event::muons)>(
"muons");
263 tokens.push_back(model->GetToken(
"muons"));
265 return {std::move(model), std::move(
tokens)};
274 products.emplace_back(1, &event.runId);
275 products.emplace_back(2, &event.electrons);
276 products.emplace_back(3, &event.photons);
277 products.emplace_back(4, &event.muons);
284 std::uint32_t nEvents;
293 std::vector<ROOT::RFieldToken>
tokens;
295 model->MakeField<
decltype(Run::runId)>(
"runId");
296 tokens.push_back(model->GetToken(
"runId"));
298 model->MakeField<
decltype(Run::nEvents)>(
"nEvents");
299 tokens.push_back(model->GetToken(
"nEvents"));
301 return {std::move(model), std::move(
tokens)};
309 products.emplace_back(0, &run.runId);
310 products.emplace_back(1, &run.nEvents);
324 std::uniform_real_distribution<float>
floatDist;
328 std::uint32_t nEvents = 0;
330 nEvents =
static_cast<std::uint32_t
>(
nEventsD);
337 for (std::uint32_t eventId = 0; eventId < nEvents; eventId++) {
338 event.eventId = eventId;
359 muon.mass = 105.658 ;
362 muon.charge = (
gen() % 2 ? 1 : -1);
371 run.nEvents = nEvents;
398 for (
unsigned i = 0; i <
kNThreads; i++) {
403 std::vector<std::thread>
threads;
404 for (
unsigned i = 0; i <
kNThreads; i++) {
407 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
Int_t Fill(Double_t x) override
A container of const raw pointers, corresponding to a row in the data set.
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(double const *factors, std::size_t nFactors)