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