Project
Loading...
Searching...
No Matches
SecondaryVertexReaderSpec.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
13
14#include <vector>
15
18#include "Framework/Logger.h"
25#include "TFile.h"
26#include "TTree.h"
27
28using namespace o2::framework;
29
30namespace o2
31{
32namespace vertexing
33{
34// read secondary vertices produces by the o2-secondary-vertexing-workflow
36{
39 using V0 = o2::dataformats::V0;
44
45 public:
47 ~SecondaryVertexReader() override = default;
48 void init(o2::framework::InitContext& ic) final;
50
51 protected:
52 void connectTree();
53
54 bool mVerbose = false;
55
56 std::vector<V0Index> mV0sIdx, *mV0sIdxPtr = &mV0sIdx;
57 std::vector<V0> mV0s, *mV0sPtr = &mV0s;
58 std::vector<RRef> mPV2V0Ref, *mPV2V0RefPtr = &mPV2V0Ref;
59 std::vector<CascadeIndex> mCascsIdx, *mCascsIdxPtr = &mCascsIdx;
60 std::vector<Cascade> mCascs, *mCascsPtr = &mCascs;
61 std::vector<RRef> mPV2CascRef, *mPV2CascRefPtr = &mPV2CascRef;
62 std::vector<Decay3BodyIndex> m3BodysIdx, *m3BodysIdxPtr = &m3BodysIdx;
63 std::vector<Decay3Body> m3Bodys, *m3BodysPtr = &m3Bodys;
65
66 std::unique_ptr<TFile> mFile;
67 std::unique_ptr<TTree> mTree;
68 std::string mFileName = "";
69 std::string mFileNameMatches = "";
70 std::string mSVertexTreeName = "o2sim";
71 std::string mV0IdxBranchName = "V0sID";
72 std::string mV0BranchName = "V0s";
73 std::string mPVertex2V0RefBranchName = "PV2V0Refs";
74 std::string mCascIdxBranchName = "CascadesID";
75 std::string mCascBranchName = "Cascades";
76 std::string mPVertex2CascRefBranchName = "PV2CascRefs";
77 std::string m3BodyIdxBranchName = "Decays3BodyID";
78 std::string m3BodyBranchName = "Decays3Body";
79 std::string mPVertex23BodyRefBranchName = "PV23BodyRefs";
80};
81
83{
85 ic.options().get<std::string>("secondary-vertex-infile"));
87}
88
90{
91 auto ent = mTree->GetReadEntry() + 1;
92 // A timeframe holds no collision at all whenever the interaction rate is low enough, and
93 // the tree then has no entry to read. Publish empty containers instead of reading past the
94 // end and pushing branch addresses that GetEntry has not filled, so that the consumers
95 // downstream still see the timeframe. (This used to be an assert, which is compiled out of
96 // every production build since ENABLE_CASSERT defaults to OFF.)
97 const bool noEntry = ent >= mTree->GetEntries();
98 if (noEntry) {
99 LOG(info) << "no entry to read, publishing empty output";
100 } else {
101 mTree->GetEntry(ent);
102 }
103 LOGP(info, "Pushing {} V0s ({} indices), {} cascades ({} indices) and {} 3-body ({} indices ) at entry {}",
104 mV0s.size(), mV0sIdx.size(), mCascs.size(), mCascsIdx.size(), m3Bodys.size(), m3BodysIdx.size(), ent);
105
106 pc.outputs().snapshot(Output{"GLO", "V0S_IDX", 0}, mV0sIdx);
107 pc.outputs().snapshot(Output{"GLO", "V0S", 0}, mV0s);
108 pc.outputs().snapshot(Output{"GLO", "PVTX_V0REFS", 0}, mPV2V0Ref);
109 pc.outputs().snapshot(Output{"GLO", "CASCS_IDX", 0}, mCascsIdx);
110 pc.outputs().snapshot(Output{"GLO", "CASCS", 0}, mCascs);
111 pc.outputs().snapshot(Output{"GLO", "PVTX_CASCREFS", 0}, mPV2CascRef);
112 pc.outputs().snapshot(Output{"GLO", "DECAYS3BODY_IDX", 0}, m3BodysIdx);
113 pc.outputs().snapshot(Output{"GLO", "DECAYS3BODY", 0}, m3Bodys);
114 pc.outputs().snapshot(Output{"GLO", "PVTX_3BODYREFS", 0}, mPV23BodyRef);
115
116 if (noEntry || mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
118 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
119 }
120}
121
123{
124 mTree.reset(nullptr); // in case it was already loaded
125 mFile.reset(TFile::Open(mFileName.c_str()));
126 assert(mFile && !mFile->IsZombie());
127 mTree.reset((TTree*)mFile->Get(mSVertexTreeName.c_str()));
128 assert(mTree);
129 assert(mTree->GetBranch(mV0IdxBranchName.c_str()));
130 assert(mTree->GetBranch(mV0BranchName.c_str()));
131 assert(mTree->GetBranch(mPVertex2V0RefBranchName.c_str()));
132 assert(mTree->GetBranch(mCascBranchName.c_str()));
133 assert(mTree->GetBranch(mCascIdxBranchName.c_str()));
134 assert(mTree->GetBranch(mPVertex2CascRefBranchName.c_str()));
135 assert(mTree->GetBranch(m3BodyIdxBranchName.c_str()));
136 assert(mTree->GetBranch(m3BodyBranchName.c_str()));
137 assert(mTree->GetBranch(mPVertex23BodyRefBranchName.c_str()));
138
139 mTree->SetBranchAddress(mV0IdxBranchName.c_str(), &mV0sIdxPtr);
140 mTree->SetBranchAddress(mV0BranchName.c_str(), &mV0sPtr);
141 mTree->SetBranchAddress(mPVertex2V0RefBranchName.c_str(), &mPV2V0RefPtr);
142 mTree->SetBranchAddress(mCascIdxBranchName.c_str(), &mCascsIdxPtr);
143 mTree->SetBranchAddress(mCascBranchName.c_str(), &mCascsPtr);
144 mTree->SetBranchAddress(mPVertex2CascRefBranchName.c_str(), &mPV2CascRefPtr);
145 mTree->SetBranchAddress(m3BodyIdxBranchName.c_str(), &m3BodysIdxPtr);
146 mTree->SetBranchAddress(m3BodyBranchName.c_str(), &m3BodysPtr);
147 mTree->SetBranchAddress(mPVertex23BodyRefBranchName.c_str(), &mPV23BodyRefPtr);
148
149 LOG(info) << "Loaded " << mSVertexTreeName << " tree from " << mFileName << " with " << mTree->GetEntries() << " entries";
150}
151
153{
154 std::vector<OutputSpec> outputs;
155 outputs.emplace_back("GLO", "V0S_IDX", 0, Lifetime::Timeframe); // found V0s indices
156 outputs.emplace_back("GLO", "V0S", 0, Lifetime::Timeframe); // found V0s
157 outputs.emplace_back("GLO", "PVTX_V0REFS", 0, Lifetime::Timeframe); // prim.vertex -> V0s refs
158 outputs.emplace_back("GLO", "CASCS_IDX", 0, Lifetime::Timeframe); // found Cascades indices
159 outputs.emplace_back("GLO", "CASCS", 0, Lifetime::Timeframe); // found Cascades
160 outputs.emplace_back("GLO", "PVTX_CASCREFS", 0, Lifetime::Timeframe); // prim.vertex -> Cascades refs
161 outputs.emplace_back("GLO", "DECAYS3BODY_IDX", 0, Lifetime::Timeframe); // found 3 body vertices indices
162 outputs.emplace_back("GLO", "DECAYS3BODY", 0, Lifetime::Timeframe); // found 3 body Decays
163 outputs.emplace_back("GLO", "PVTX_3BODYREFS", 0, Lifetime::Timeframe); // prim.vertex -> 3 body Decays refs
164
165 return DataProcessorSpec{
166 "secondary-vertex-reader",
167 Inputs{},
168 outputs,
169 AlgorithmSpec{adaptFromTask<SecondaryVertexReader>()},
170 Options{
171 {"secondary-vertex-infile", VariantType::String, "o2_secondary_vertex.root", {"Name of the input secondary vertex file"}},
172 {"input-dir", VariantType::String, "none", {"Input directory"}}}};
173}
174
175} // namespace vertexing
176} // namespace o2
Definition of the Names Generator class.
Class to refer to the 1st entry and N elements of some group in the continuous container.
TO BE DONE: extend to generic N body vertex.
Definition Decay3Body.h:26
void snapshot(const Output &spec, T const &object)
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.
virtual void endOfStream(EndOfStreamContext &context)
This is invoked whenever we have an EndOfStream event.
Definition Task.h:43
~SecondaryVertexReader() override=default
void init(o2::framework::InitContext &ic) final
void run(o2::framework::ProcessingContext &pc) final
std::vector< Decay3BodyIndex > * m3BodysIdxPtr
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
o2::framework::DataProcessorSpec getSecondaryVertexReaderSpec()
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
static std::string rectifyDirectory(const std::string_view p)
static std::string concat_string(Ts const &... ts)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"