Project
Loading...
Searching...
No Matches
MCTruthReaderSpec.h
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
12#ifndef STEER_DIGITIZERWORKFLOW_SRC_MCTRUTHREADERSPEC_H_
13#define STEER_DIGITIZERWORKFLOW_SRC_MCTRUTHREADERSPEC_H_
14
19#include "Framework/Lifetime.h"
23#include "Framework/Task.h"
24#include "Framework/Logger.h"
25#include "TTree.h"
26#include "TFile.h"
27#include "TString.h"
28#include <sstream>
29
30using namespace o2::framework;
31
32namespace o2
33{
34
36{
37 public:
38 MCTruthReaderTask(bool newmctruth) : mNew{newmctruth} {}
39
40 void init(framework::InitContext& ic) override
41 {
42 LOG(info) << "Initializing MCTruth reader ";
43 }
44
46 {
47 if (mFinished) {
48 return;
49 }
50 LOG(info) << "Running MCTruth reader ";
51 auto labelfilename = pc.inputs().get<TString*>("trigger");
52 LOG(info) << "Opening file " << labelfilename->Data();
53 TFile f(labelfilename->Data(), "OPEN");
54 auto tree = (TTree*)f.Get("o2sim");
55 auto br = tree->GetBranch("Labels");
56
57 if (mNew) {
58 //
59 dataformats::IOMCTruthContainerView* iocontainer = nullptr;
60 br->SetAddress(&iocontainer);
61 br->GetEntry(0);
62
63 // publish the labels in a const shared memory container
64 auto& sharedlabels = pc.outputs().make<o2::dataformats::ConstMCTruthContainer<o2::MCCompLabel>>(Output{"TST", "LABELS2", 0});
65 iocontainer->copyandflatten(sharedlabels);
66
67 } else {
68 // the original way with the MCTruthContainer
69 dataformats::MCTruthContainer<MCCompLabel>* mccontainer = nullptr;
70 br->SetAddress(&mccontainer);
71 br->GetEntry(0);
72
73 LOG(info) << "MCCONTAINER CHECK" << mccontainer;
74 LOG(info) << "MCCONTAINER CHECK" << mccontainer->getNElements();
75
76 // publish the original labels
77 pc.outputs().snapshot(Output{"TST", "LABELS2", 0}, *mccontainer);
78 }
79 // we should be only called once; tell DPL that this process is ready to exit
80 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
81 mFinished = true;
82 }
83
84 private:
85 bool mFinished = false;
86 bool mNew = false;
87};
88
90{
91 std::vector<InputSpec> inputs;
92 // input to notify that labels can be read
93 inputs.emplace_back("trigger", "TST", "TRIGGERREAD", 0, Lifetime::Timeframe);
94 return DataProcessorSpec{
95 "MCTruthReader",
96 inputs,
97 Outputs{{"TST", "LABELS2", 0, Lifetime::Timeframe}},
98 AlgorithmSpec{adaptFromTask<MCTruthReaderTask>(newmctruth)},
99 Options{}};
100}
101
102} // end namespace o2
103
104#endif
A const (ready only) version of MCTruthContainer.
A special IO container - splitting a given vector to enable ROOT IO.
void run(framework::ProcessingContext &pc) override
MCTruthReaderTask(bool newmctruth)
void init(framework::InitContext &ic) override
A read-only version of MCTruthContainer allowing for storage optimisation.
void copyandflatten(std::vector< char, Alloc > &output) const
A container to hold and manage MC truth information/labels.
void snapshot(const Output &spec, T const &object)
decltype(auto) make(const Output &spec, Args... args)
decltype(auto) get(R binding, int part=0) const
DataAllocator & outputs()
The data allocator is used to allocate memory for the output data.
InputRecord & inputs()
The inputs associated with this processing context.
ServiceRegistryRef services()
The services registry associated with this processing context.
GLdouble f
Definition glcorearb.h:310
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
std::vector< OutputSpec > Outputs
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
o2::framework::DataProcessorSpec getMCTruthReaderSpec(bool newmctruth)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))