Project
Loading...
Searching...
No Matches
ClusterReaderSpec.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#include <cassert>
16
17#include <TTree.h>
18
21#include "Framework/Logger.h"
26
27using namespace o2::framework;
28using namespace o2::itsmft;
29
30namespace o2
31{
32namespace itsmft
33{
34
35template <int N>
36ClusterReader<N>::ClusterReader(bool useMC, bool usePatterns, bool triggerOut) : mUseMC(useMC), mUsePatterns(usePatterns), mTriggerOut(triggerOut), mDetName(Origin.as<std::string>()), mDetNameLC(mDetName)
37{
38 std::transform(mDetNameLC.begin(), mDetNameLC.end(), mDetNameLC.begin(), ::tolower);
39
40 mClusROFRec.fill(nullptr);
41 mClusterCompArray.fill(nullptr);
42 mPatternsArray.fill(nullptr);
43 mClusterMCTruth.fill(nullptr);
44 mClusMC2ROFs.fill(nullptr);
45}
47template <int N>
49{
51 ic.options().get<std::string>((mDetNameLC + "-cluster-infile").c_str()));
52 connectTree(mFileName);
54
55template <int N>
57{
58 auto ent = mTree->GetReadEntry() + 1;
59 assert(ent < mTree->GetEntries()); // this should not happen
60 mTree->GetEntry(ent);
61
62 for (uint32_t iLayer = 0; iLayer < NLayers; ++iLayer) {
63 LOG(info) << mDetName << "ClusterReader:" << iLayer << " pushes " << mClusROFRec[iLayer]->size() << " ROFRecords, " << mClusterCompArray[iLayer]->size() << " compact clusters at entry " << ent;
64 pc.outputs().snapshot(Output{Origin, "CLUSTERSROF", iLayer}, *mClusROFRec[iLayer]);
65 pc.outputs().snapshot(Output{Origin, "COMPCLUSTERS", iLayer}, *mClusterCompArray[iLayer]);
66 if (mUsePatterns) {
67 pc.outputs().snapshot(Output{Origin, "PATTERNS", iLayer}, *mPatternsArray[iLayer]);
68 }
69 if (mUseMC) {
70 pc.outputs().snapshot(Output{Origin, "CLUSTERSMCTR", iLayer}, *mClusterMCTruth[iLayer]);
71 pc.outputs().snapshot(Output{Origin, "CLUSTERSMC2ROF", iLayer}, *mClusMC2ROFs[iLayer]);
72 }
73 }
74 if (mTriggerOut) {
75 std::vector<o2::itsmft::PhysTrigger> dummyTrig;
76 pc.outputs().snapshot(Output{Origin, "PHYSTRIG", 0}, dummyTrig);
77 }
78 if (mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
79 pc.services().get<ControlService>().endOfStream();
80 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
81 }
82}
83
84template <int N>
86{
87 mTree.reset(nullptr); // in case it was already loaded
88 mFile.reset(TFile::Open(filename.c_str()));
89 assert(mFile && !mFile->IsZombie());
90 mTree.reset((TTree*)mFile->Get(mClusTreeName.c_str()));
91 assert(mTree);
92
93 for (uint32_t iLayer = 0; iLayer < NLayers; ++iLayer) {
94 setBranchAddress(mClusROFBranchName, mClusROFRec[iLayer], iLayer);
95 setBranchAddress(mClusterCompBranchName, mClusterCompArray[iLayer], iLayer);
96 if (mUsePatterns) {
97 setBranchAddress(mClusterPattBranchName, mPatternsArray[iLayer], iLayer);
98 }
99 if (mUseMC) {
100 if (mTree->GetBranch(getBranchName(mClustMCTruthBranchName, iLayer).c_str()) &&
101 mTree->GetBranch(getBranchName(mClustMC2ROFBranchName, iLayer).c_str())) {
102 setBranchAddress(mClustMCTruthBranchName, mClusterMCTruth[iLayer], iLayer);
103 setBranchAddress(mClustMC2ROFBranchName, mClusMC2ROFs[iLayer], iLayer);
104 } else {
105 LOG(info) << "MC-truth is missing";
106 mUseMC = false;
107 }
108 }
109 }
110 LOG(info) << "Loaded tree from " << filename << " with " << mTree->GetEntries() << " entries";
111}
112
113template <int N>
114std::string ClusterReader<N>::getBranchName(const std::string& base, int index) const
115{
117 return mDetName + base + "_" + std::to_string(index);
118 }
119 return mDetName + base;
120}
121
122template <int N>
123template <typename Ptr>
124void ClusterReader<N>::setBranchAddress(const std::string& base, Ptr& addr, int layer)
125{
126 const auto name = getBranchName(base, layer);
127 if (Int_t ret = mTree->SetBranchAddress(name.c_str(), &addr); ret != 0) {
128 LOGP(fatal, "failed to set branch address for {} ret={}", name, ret);
129 }
130}
131
132namespace
133{
134template <int N>
135std::vector<OutputSpec> makeOutChannels(o2::header::DataOrigin detOrig, bool mctruth, bool usePatterns, bool triggerOut)
136{
137 std::vector<OutputSpec> outputs;
138 for (uint32_t iLayer = 0; iLayer < ((o2::itsmft::DPLAlpideParam<N>::supportsStaggering()) ? o2::itsmft::DPLAlpideParam<N>::getNLayers() : 1); ++iLayer) {
139 outputs.emplace_back(detOrig, "CLUSTERSROF", iLayer, Lifetime::Timeframe);
140 outputs.emplace_back(detOrig, "COMPCLUSTERS", iLayer, Lifetime::Timeframe);
141 if (usePatterns) {
142 outputs.emplace_back(detOrig, "PATTERNS", iLayer, Lifetime::Timeframe);
143 }
144 if (mctruth) {
145 outputs.emplace_back(detOrig, "CLUSTERSMCTR", iLayer, Lifetime::Timeframe);
146 outputs.emplace_back(detOrig, "CLUSTERSMC2ROF", iLayer, Lifetime::Timeframe);
147 }
148 }
149 if (triggerOut) {
150 outputs.emplace_back(detOrig, "PHYSTRIG", 0, Lifetime::Timeframe);
151 }
152 return outputs;
153}
154} // namespace
155
156DataProcessorSpec getITSClusterReaderSpec(bool useMC, bool usePatterns, bool triggerOut)
157{
158 return DataProcessorSpec{
159 .name = "its-cluster-reader",
160 .inputs = Inputs{},
161 .outputs = makeOutChannels<o2::detectors::DetID::ITS>("ITS", useMC, usePatterns, triggerOut),
162 .algorithm = AlgorithmSpec{adaptFromTask<ITSClusterReader>(useMC, usePatterns, triggerOut)},
163 .options = Options{
164 {"its-cluster-infile", VariantType::String, "o2clus_its.root", {"Name of the input cluster file"}},
165 {"input-dir", VariantType::String, "none", {"Input directory"}}}};
166}
167
168DataProcessorSpec getMFTClusterReaderSpec(bool useMC, bool usePatterns, bool triggerOut)
169{
170 return DataProcessorSpec{
171 .name = "mft-cluster-reader",
172 .inputs = Inputs{},
173 .outputs = makeOutChannels<o2::detectors::DetID::MFT>("MFT", useMC, usePatterns, triggerOut),
174 .algorithm = AlgorithmSpec{adaptFromTask<MFTClusterReader>(useMC, usePatterns, triggerOut)},
175 .options = Options{
176 {"mft-cluster-infile", VariantType::String, "mftclusters.root", {"Name of the input cluster file"}},
177 {"input-dir", VariantType::String, "none", {"Input directory"}}}};
178}
179
180} // namespace itsmft
181} // namespace o2
Definition of the Names Generator class.
Definition Physics trigger record extracted from the ITS/MFT stream.
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.
void run(ProcessingContext &pc) final
std::string getBranchName(const std::string &base, int index) const
void connectTree(const std::string &filename)
std::array< std::vector< unsigned char > *, NLayers > mPatternsArray
void init(InitContext &ic) final
void setBranchAddress(const std::string &base, Ptr &addr, int layer)
std::array< std::vector< o2::itsmft::CompClusterExt > *, NLayers > mClusterCompArray
std::array< std::vector< o2::itsmft::MC2ROFRecord > *, NLayers > mClusMC2ROFs
std::array< std::vector< o2::itsmft::ROFRecord > *, NLayers > mClusROFRec
std::array< o2::dataformats::MCTruthContainer< o2::MCCompLabel > *, NLayers > mClusterMCTruth
GLsizei const GLchar *const * string
Definition glcorearb.h:809
GLuint index
Definition glcorearb.h:781
GLuint const GLchar * name
Definition glcorearb.h:781
GLenum GLuint GLint GLint layer
Definition glcorearb.h:1310
Defining PrimaryVertex explicitly as messageable.
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
framework::DataProcessorSpec getMFTClusterReaderSpec(bool useMC=true, bool usePatterns=true, bool useTriggers=true)
framework::DataProcessorSpec getITSClusterReaderSpec(bool useMC=true, bool usePatterns=true, bool useTriggers=true)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Defining DataPointCompositeObject explicitly as copiable.
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
std::string filename()
static constexpr bool supportsStaggering() noexcept
static std::string rectifyDirectory(const std::string_view p)
static std::string concat_string(Ts const &... ts)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"