Project
Loading...
Searching...
No Matches
MCTruthSourceSpec.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
16#include "Framework/Lifetime.h"
19#include "Framework/Task.h"
20#include "Framework/Logger.h"
21
22using namespace o2::framework;
23
24namespace o2
25{
26
28{
29 public:
30 MCTruthSourceTask(bool newmctruth) : mNew{newmctruth} {}
31
32 void init(framework::InitContext& ic) override
33 {
34 LOG(info) << "Initializing MCTruth source";
35 mSize = ic.options().get<int>("size");
36 }
37
39 {
40 if (mFinished) {
41 return;
42 }
43 LOG(info) << "Creating MCTruth container";
44
45 using TruthElement = o2::MCCompLabel;
47 Container container;
48 // create a very large container and stream it to TTree
49 for (int i = 0; i < mSize; ++i) {
50 container.addElement(i, TruthElement(i, i, i));
51 container.addElement(i, TruthElement(i + 1, i, i));
52 }
53
54 if (mNew) {
55 LOG(info) << "New serialization";
56 // we need to flatten it and write to managed shared memory container
57 auto& sharedlabels = pc.outputs().make<o2::dataformats::ConstMCTruthContainer<o2::MCCompLabel>>(Output{"TST", "LABELS", 0});
58 container.flatten_to(sharedlabels);
59 sleep(1);
60 } else {
61 LOG(info) << "Old serialization";
62 pc.outputs().snapshot({"TST", "LABELS", 0}, container);
63 sleep(1);
64 }
65
66 // we should be only called once; tell DPL that this process is ready to exit
67 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
68 mFinished = true;
69 }
70
71 private:
72 bool mFinished = false;
73 int mSize = 0;
74 bool mNew = false;
75};
76
78{
79 // create the full data processor spec using
80 // a name identifier
81 // input description
82 // algorithmic description (here a lambda getting called once to setup the actual processing function)
83 // options that can be used for this processor (here: input file names where to take the hits)
84 std::vector<OutputSpec> outputs;
85 outputs.emplace_back("TST", "LABELS", 0, Lifetime::Timeframe);
86
87 return DataProcessorSpec{
88 "MCTruthSource",
89 Inputs{},
90 outputs,
91 AlgorithmSpec{adaptFromTask<MCTruthSourceTask>(newmctruth)},
92 Options{
93 {"size", VariantType::Int, 100000, {"Sample size"}}}};
94}
95
96} // end namespace o2
A const (ready only) version of MCTruthContainer.
int32_t i
MCTruthSourceTask(bool newmctruth)
void init(framework::InitContext &ic) override
void run(framework::ProcessingContext &pc) override
A read-only version of MCTruthContainer allowing for storage optimisation.
A container to hold and manage MC truth information/labels.
void addElement(uint32_t dataindex, TruthElement const &element, bool noElement=false)
void snapshot(const Output &spec, T const &object)
decltype(auto) make(const Output &spec, Args... args)
ConfigParamRegistry const & options()
Definition InitContext.h:33
DataAllocator & outputs()
The data allocator is used to allocate memory for the output data.
ServiceRegistryRef services()
The services registry associated with this processing context.
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
o2::framework::DataProcessorSpec getMCTruthSourceSpec(bool newmctruth)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"