Project
Loading...
Searching...
No Matches
MCTruthWriterSpec.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"
20#include "Framework/Task.h"
21#include "Framework/Logger.h"
22#include "TTree.h"
23#include "TFile.h"
24#include "TString.h"
25#include <sstream>
26
27using namespace o2::framework;
28
29namespace o2
30{
31
33{
34 public:
35 MCTruthWriterTask(int id, bool doio, bool newmctruth) : mID{id}, mIO{doio}, mNew{newmctruth} {}
36
37 void init(framework::InitContext& ic) override
38 {
39 LOG(info) << "Initializing MCTruth consumer " << mID;
40 }
41
43 {
44 if (mFinished) {
45 return;
46 }
47 LOG(info) << "Running MCTruth consumer " << mID;
48 TString labelfilename;
49 if (mNew) {
50 auto labels = pc.inputs().get<o2::dataformats::ConstMCTruthContainer<o2::MCCompLabel>>(mID >= 0 ? "labels" : "labels2");
51 LOG(info) << "GOT " << labels.getNElements() << " labels";
52
53 sleep(1);
54
55 if (mIO) {
57 labelfilename = "labels_new.root";
58 TFile f(labelfilename.Data(), "RECREATE");
59 TTree tree("o2sim", "o2sim");
60 auto br = tree.Branch("Labels", &io);
61 tree.Fill();
62 f.Write();
63 f.Close();
64 }
65
66 sleep(1);
67 } else {
68 auto labels = pc.inputs().get<o2::dataformats::MCTruthContainer<o2::MCCompLabel>*>(mID >= 0 ? "labels" : "labels2");
69 LOG(info) << "GOT " << labels->getNElements() << " labels";
70
71 sleep(1);
72
73 if (mIO) {
74 labelfilename = "labels_old.root";
75 TFile f(labelfilename.Data(), "RECREATE");
76 TTree tree("o2sim", "o2sim");
77 auto rawptr = labels.get();
78 auto br = tree.Branch("Labels", &rawptr);
79 tree.Fill();
80 f.Write();
81 f.Close();
82 }
83 sleep(1);
84 }
85 if (mIO) {
86 // this triggers the reader process
87 pc.outputs().snapshot({"TST", "TRIGGERREAD", 0}, labelfilename);
88 }
89
90 // we should be only called once; tell DPL that this process is ready to exit
91 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
92 mFinished = true;
93 }
94
95 private:
96 bool mFinished = false;
97 bool mNew = false;
98 bool mIO = false;
99 int mID = 0;
100};
101
103{
104 std::vector<InputSpec> inputs;
105 if (id == -1) {
106 // we use this id as a secondary consumer of the LABELS2 channel
107 inputs.emplace_back("labels2", "TST", "LABELS2", 0, Lifetime::Timeframe);
108 } else {
109 inputs.emplace_back("labels", "TST", "LABELS", 0, Lifetime::Timeframe);
110 }
111 std::stringstream str;
112 str << "MCTruthWriter" << id;
113
114 std::vector<OutputSpec> outputs;
115 if (doio) {
116 outputs.emplace_back("TST", "TRIGGERREAD", 0, Lifetime::Timeframe);
117 }
118 return DataProcessorSpec{
119 str.str(),
120 inputs,
121 outputs,
122 AlgorithmSpec{adaptFromTask<MCTruthWriterTask>(id, doio, newmctruth)},
123 Options{}};
124}
125
126} // end namespace o2
A const (ready only) version of MCTruthContainer.
A special IO container - splitting a given vector to enable ROOT IO.
MCTruthWriterTask(int id, bool doio, bool newmctruth)
void run(framework::ProcessingContext &pc) override
void init(framework::InitContext &ic) override
A read-only version of MCTruthContainer allowing for storage optimisation.
A container to hold and manage MC truth information/labels.
void snapshot(const Output &spec, T const &object)
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
GLuint id
Definition glcorearb.h:650
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
o2::framework::DataProcessorSpec getMCTruthWriterSpec(int id, bool doio, 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()))
const std::string str