57using ModelTokensPair = std::pair<std::unique_ptr<ROOT::RNTupleModel>, std::vector<ROOT::RFieldToken>>;
69 std::unique_ptr<TFile> fFile;
75 fFile.reset(
TFile::Open(std::string(
url).c_str(), std::string(options).c_str()));
79 TFile &GetFile() {
return *fFile; }
80 std::mutex &GetMutex() {
return fMutex; }
88 virtual void InitSlot(
unsigned slot) = 0;
89 virtual void Fill(
unsigned slot,
const std::vector<DataProduct> &
products) = 0;
96 std::vector<ROOT::RFieldToken>
fTokens;
100 std::unique_ptr<RRawPtrWriteEntry>
entry;
102 std::vector<SlotData> fSlots;
115 void InitSlot(
unsigned slot)
final
117 if (
slot >= fSlots.size()) {
118 fSlots.resize(
slot + 1);
122 fSlots[
slot].entry = fSlots[
slot].fillContext->GetModel().CreateRawPtrWriteEntry();
125 void Fill(
unsigned slot,
const std::vector<DataProduct> &
products)
final
160 std::unique_ptr<ROOT::RNTupleWriter> fWriter;
162 std::vector<ROOT::RFieldToken>
fTokens;
165 std::unique_ptr<RRawPtrWriteEntry>
entry;
167 std::vector<SlotData> fSlots;
180 void InitSlot(
unsigned slot)
final
182 if (
slot >= fSlots.size()) {
183 fSlots.resize(
slot + 1);
186 fSlots[
slot].entry = fWriter->GetModel().CreateRawPtrWriteEntry();
189 void Fill(
unsigned slot,
const std::vector<DataProduct> &
products)
final
204 fWriter->FillNoFlush(
entry, status);
209 fWriter->FlushColumns();
214 fWriter->FlushCluster();
240 std::vector<ChargedTrack>
muons;
249 std::vector<ROOT::RFieldToken>
tokens;
252 tokens.push_back(model->GetToken(
"eventId"));
254 model->MakeField<
decltype(Event::runId)>(
"runId");
255 tokens.push_back(model->GetToken(
"runId"));
257 model->MakeField<
decltype(Event::electrons)>(
"electrons");
258 tokens.push_back(model->GetToken(
"electrons"));
260 model->MakeField<
decltype(Event::photons)>(
"photons");
261 tokens.push_back(model->GetToken(
"photons"));
263 model->MakeField<
decltype(Event::muons)>(
"muons");
264 tokens.push_back(model->GetToken(
"muons"));
266 return {std::move(model), std::move(
tokens)};
275 products.emplace_back(1, &event.runId);
276 products.emplace_back(2, &event.electrons);
277 products.emplace_back(3, &event.photons);
278 products.emplace_back(4, &event.muons);
285 std::uint32_t nEvents;
294 std::vector<ROOT::RFieldToken>
tokens;
296 model->MakeField<
decltype(Run::runId)>(
"runId");
297 tokens.push_back(model->GetToken(
"runId"));
299 model->MakeField<
decltype(Run::nEvents)>(
"nEvents");
300 tokens.push_back(model->GetToken(
"nEvents"));
302 return {std::move(model), std::move(
tokens)};
310 products.emplace_back(0, &run.runId);
311 products.emplace_back(1, &run.nEvents);
325 std::uniform_real_distribution<float>
floatDist;
329 std::uint32_t nEvents = 0;
331 nEvents =
static_cast<std::uint32_t
>(
nEventsD);
338 for (std::uint32_t eventId = 0; eventId < nEvents; eventId++) {
339 event.eventId = eventId;
360 muon.mass = 105.658 ;
363 muon.charge = (
gen() % 2 ? 1 : -1);
372 run.nEvents = nEvents;
399 for (
unsigned i = 0; i <
kNThreads; i++) {
404 std::vector<std::thread>
threads;
405 for (
unsigned i = 0; i <
kNThreads; i++) {
408 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 container of const raw pointers, corresponding to a row in the data set.
A context for filling entries (data) into clusters of an RNTuple.
A writer to fill an RNTuple from multiple contexts.
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.
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())
Throws an exception if the model is null.
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)