Skip to content

Commit 6ca352f

Browse files
mpuccioclaude
andauthored
IOTOF: Add a TF3 cluster reader (#16161)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 05c13ec commit 6ca352f

3 files changed

Lines changed: 176 additions & 0 deletions

File tree

‎Detectors/Upgrades/ALICE3/IOTOF/workflow/CMakeLists.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ o2_add_library(IOTOFWorkflow
1515
src/DigitWriterSpec.cxx
1616
src/ClustererSpec.cxx
1717
src/ClusterWriterSpec.cxx
18+
src/ClusterReaderSpec.cxx
1819
src/RecoWorkflow.cxx
1920
PUBLIC_LINK_LIBRARIES O2::Framework
2021
O2::DataFormatsIOTOF
2122
O2::DataFormatsITSMFT
2223
O2::IOTOFReconstruction
2324
O2::DPLUtils
25+
O2::SimulationDataFormat
2426
)
2527

2628
o2_add_executable(reco-workflow
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
/// \file ClusterReaderSpec.h
13+
/// \brief The TF3 clusters of o2-alice3-iotof-reco-workflow's cluster file
14+
/// (ClusterWriterSpec.h), one timeframe per entry.
15+
16+
#ifndef O2_IOTOF_CLUSTERREADERSPEC_H
17+
#define O2_IOTOF_CLUSTERREADERSPEC_H
18+
19+
#include "DataFormatsIOTOF/Cluster.h"
20+
#include "DataFormatsITSMFT/ROFRecord.h"
21+
#include "Framework/DataProcessorSpec.h"
22+
#include "Framework/Task.h"
23+
#include "SimulationDataFormat/MCCompLabel.h"
24+
#include "SimulationDataFormat/MCTruthContainer.h"
25+
26+
#include <TFile.h>
27+
#include <TTree.h>
28+
29+
#include <memory>
30+
#include <string>
31+
#include <vector>
32+
33+
namespace o2::iotof
34+
{
35+
36+
/// Publishes TF3/CLUSTERS, TF3/PATTERNS, TF3/CLUSTERSROF and, with MC,
37+
/// TF3/CLUSTERSMCTR (subspec 0) from the tree `o2sim` of `--tf3-cluster-infile`,
38+
/// as the clusterer publishes them; an empty timeframe past the tree's last
39+
/// entry.
40+
class ClusterReader : public o2::framework::Task
41+
{
42+
public:
43+
explicit ClusterReader(bool useMC) : mUseMC(useMC) {}
44+
void init(o2::framework::InitContext& ic) final;
45+
void run(o2::framework::ProcessingContext& pc) final;
46+
47+
private:
48+
void connectTree(const std::string& filename);
49+
50+
std::unique_ptr<TFile> mFile;
51+
std::unique_ptr<TTree> mTree;
52+
std::vector<o2::iotof::Cluster>* mClusters = nullptr;
53+
std::vector<unsigned char>* mPatterns = nullptr;
54+
std::vector<o2::itsmft::ROFRecord>* mROFs = nullptr;
55+
o2::dataformats::MCTruthContainer<o2::MCCompLabel>* mLabels = nullptr;
56+
bool mUseMC = false;
57+
};
58+
59+
/// The reader's device, `tf3-cluster-reader`; its file `--tf3-cluster-infile`
60+
/// (tf3clusters.root by default).
61+
o2::framework::DataProcessorSpec getIOTOFClusterReaderSpec(bool useMC);
62+
63+
} // namespace o2::iotof
64+
65+
#endif // O2_IOTOF_CLUSTERREADERSPEC_H
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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+
/// \file ClusterReaderSpec.cxx
13+
/// \brief The TF3 cluster reader (ClusterReaderSpec.h).
14+
15+
#include "IOTOFWorkflow/ClusterReaderSpec.h"
16+
17+
#include "Framework/ConfigParamRegistry.h"
18+
#include "Framework/ControlService.h"
19+
#include "Framework/Logger.h"
20+
#include "Headers/DataHeader.h"
21+
22+
#include <format>
23+
#include <stdexcept>
24+
25+
using namespace o2::framework;
26+
27+
namespace o2::iotof
28+
{
29+
30+
void ClusterReader::init(InitContext& ic)
31+
{
32+
connectTree(ic.options().get<std::string>("tf3-cluster-infile"));
33+
}
34+
35+
void ClusterReader::run(ProcessingContext& pc)
36+
{
37+
const auto entry = mTree->GetReadEntry() + 1;
38+
// A timeframe without a collision has no entry: publish empty streams, so
39+
// that the consumers still see the timeframe (as TRK's reader does).
40+
const bool noEntry = entry >= mTree->GetEntries();
41+
if (noEntry) {
42+
LOG(info) << "TF3ClusterReader: no entry to read, publishing empty output";
43+
} else {
44+
mTree->GetEntry(entry);
45+
}
46+
static const std::vector<o2::iotof::Cluster> noClusters;
47+
static const std::vector<unsigned char> noPatterns;
48+
static const std::vector<o2::itsmft::ROFRecord> noROFs;
49+
static const o2::dataformats::MCTruthContainer<o2::MCCompLabel> noLabels;
50+
const auto& clusters = noEntry ? noClusters : *mClusters;
51+
LOG(info) << "TF3ClusterReader pushes " << clusters.size() << " clusters at entry " << entry;
52+
pc.outputs().snapshot(Output{o2::header::gDataOriginTF3, "CLUSTERS", 0}, clusters);
53+
pc.outputs().snapshot(Output{o2::header::gDataOriginTF3, "PATTERNS", 0}, noEntry ? noPatterns : *mPatterns);
54+
pc.outputs().snapshot(Output{o2::header::gDataOriginTF3, "CLUSTERSROF", 0}, noEntry ? noROFs : *mROFs);
55+
if (mUseMC) {
56+
pc.outputs().snapshot(Output{o2::header::gDataOriginTF3, "CLUSTERSMCTR", 0}, noEntry ? noLabels : *mLabels);
57+
}
58+
if (noEntry || mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
59+
pc.services().get<ControlService>().endOfStream();
60+
pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
61+
}
62+
}
63+
64+
void ClusterReader::connectTree(const std::string& filename)
65+
{
66+
mTree.reset();
67+
mFile.reset(TFile::Open(filename.c_str()));
68+
if (!mFile || mFile->IsZombie()) {
69+
throw std::runtime_error("TF3ClusterReader: cannot open " + filename);
70+
}
71+
mTree.reset(mFile->Get<TTree>("o2sim"));
72+
if (!mTree) {
73+
throw std::runtime_error("TF3ClusterReader: no tree o2sim in " + filename);
74+
}
75+
const auto connect = [this](const char* name, auto*& address) {
76+
if (!mTree->GetBranch(name)) {
77+
throw std::runtime_error(std::format("TF3ClusterReader: no branch {}", name));
78+
}
79+
if (const Int_t status = mTree->SetBranchAddress(name, &address); status < 0) {
80+
throw std::runtime_error(std::format("TF3ClusterReader: cannot set the address of {} ({})", name, status));
81+
}
82+
};
83+
connect("TF3Cluster", mClusters);
84+
connect("TF3ClusterPatt", mPatterns);
85+
connect("TF3ClusterROF", mROFs);
86+
if (mUseMC) {
87+
connect("TF3ClusterMCTruth", mLabels);
88+
}
89+
LOG(info) << "TF3ClusterReader: " << filename << " with " << mTree->GetEntries() << " entries";
90+
}
91+
92+
DataProcessorSpec getIOTOFClusterReaderSpec(bool useMC)
93+
{
94+
std::vector<OutputSpec> outputs{{o2::header::gDataOriginTF3, "CLUSTERS", 0, Lifetime::Timeframe},
95+
{o2::header::gDataOriginTF3, "PATTERNS", 0, Lifetime::Timeframe},
96+
{o2::header::gDataOriginTF3, "CLUSTERSROF", 0, Lifetime::Timeframe}};
97+
if (useMC) {
98+
outputs.emplace_back(o2::header::gDataOriginTF3, "CLUSTERSMCTR", 0, Lifetime::Timeframe);
99+
}
100+
return DataProcessorSpec{
101+
.name = "tf3-cluster-reader",
102+
.inputs = Inputs{},
103+
.outputs = outputs,
104+
.algorithm = AlgorithmSpec{adaptFromTask<ClusterReader>(useMC)},
105+
.options = Options{{"tf3-cluster-infile", VariantType::String, "tf3clusters.root", {"Name of the input cluster file"}}},
106+
};
107+
}
108+
109+
} // namespace o2::iotof

0 commit comments

Comments
 (0)