Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Detectors/Upgrades/ALICE3/IOTOF/workflow/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ o2_add_library(IOTOFWorkflow
src/DigitWriterSpec.cxx
src/ClustererSpec.cxx
src/ClusterWriterSpec.cxx
src/ClusterReaderSpec.cxx
src/RecoWorkflow.cxx
PUBLIC_LINK_LIBRARIES O2::Framework
O2::DataFormatsIOTOF
O2::DataFormatsITSMFT
O2::IOTOFReconstruction
O2::DPLUtils
O2::SimulationDataFormat
)

o2_add_executable(reco-workflow
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

/// \file ClusterReaderSpec.h
/// \brief The TF3 clusters of o2-alice3-iotof-reco-workflow's cluster file
/// (ClusterWriterSpec.h), one timeframe per entry.

#ifndef O2_IOTOF_CLUSTERREADERSPEC_H
#define O2_IOTOF_CLUSTERREADERSPEC_H

#include "DataFormatsIOTOF/Cluster.h"
#include "DataFormatsITSMFT/ROFRecord.h"
#include "Framework/DataProcessorSpec.h"
#include "Framework/Task.h"
#include "SimulationDataFormat/MCCompLabel.h"
#include "SimulationDataFormat/MCTruthContainer.h"

#include <TFile.h>
#include <TTree.h>

#include <memory>
#include <string>
#include <vector>

namespace o2::iotof
{

/// Publishes TF3/CLUSTERS, TF3/PATTERNS, TF3/CLUSTERSROF and, with MC,
/// TF3/CLUSTERSMCTR (subspec 0) from the tree `o2sim` of `--tf3-cluster-infile`,
/// as the clusterer publishes them; an empty timeframe past the tree's last
/// entry.
class ClusterReader : public o2::framework::Task
{
public:
explicit ClusterReader(bool useMC) : mUseMC(useMC) {}
void init(o2::framework::InitContext& ic) final;
void run(o2::framework::ProcessingContext& pc) final;

private:
void connectTree(const std::string& filename);

std::unique_ptr<TFile> mFile;
std::unique_ptr<TTree> mTree;
std::vector<o2::iotof::Cluster>* mClusters = nullptr;
std::vector<unsigned char>* mPatterns = nullptr;
std::vector<o2::itsmft::ROFRecord>* mROFs = nullptr;
o2::dataformats::MCTruthContainer<o2::MCCompLabel>* mLabels = nullptr;
bool mUseMC = false;
};

/// The reader's device, `tf3-cluster-reader`; its file `--tf3-cluster-infile`
/// (tf3clusters.root by default).
o2::framework::DataProcessorSpec getIOTOFClusterReaderSpec(bool useMC);

} // namespace o2::iotof

#endif // O2_IOTOF_CLUSTERREADERSPEC_H
109 changes: 109 additions & 0 deletions Detectors/Upgrades/ALICE3/IOTOF/workflow/src/ClusterReaderSpec.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

/// \file ClusterReaderSpec.cxx
/// \brief The TF3 cluster reader (ClusterReaderSpec.h).

#include "IOTOFWorkflow/ClusterReaderSpec.h"

#include "Framework/ConfigParamRegistry.h"
#include "Framework/ControlService.h"
#include "Framework/Logger.h"
#include "Headers/DataHeader.h"

#include <format>
#include <stdexcept>

using namespace o2::framework;

namespace o2::iotof
{

void ClusterReader::init(InitContext& ic)
{
connectTree(ic.options().get<std::string>("tf3-cluster-infile"));
}

void ClusterReader::run(ProcessingContext& pc)
{
const auto entry = mTree->GetReadEntry() + 1;
// A timeframe without a collision has no entry: publish empty streams, so
// that the consumers still see the timeframe (as TRK's reader does).
const bool noEntry = entry >= mTree->GetEntries();
if (noEntry) {
LOG(info) << "TF3ClusterReader: no entry to read, publishing empty output";
} else {
mTree->GetEntry(entry);
}
static const std::vector<o2::iotof::Cluster> noClusters;
static const std::vector<unsigned char> noPatterns;
static const std::vector<o2::itsmft::ROFRecord> noROFs;
static const o2::dataformats::MCTruthContainer<o2::MCCompLabel> noLabels;
const auto& clusters = noEntry ? noClusters : *mClusters;
LOG(info) << "TF3ClusterReader pushes " << clusters.size() << " clusters at entry " << entry;
pc.outputs().snapshot(Output{o2::header::gDataOriginTF3, "CLUSTERS", 0}, clusters);
pc.outputs().snapshot(Output{o2::header::gDataOriginTF3, "PATTERNS", 0}, noEntry ? noPatterns : *mPatterns);
pc.outputs().snapshot(Output{o2::header::gDataOriginTF3, "CLUSTERSROF", 0}, noEntry ? noROFs : *mROFs);
if (mUseMC) {
pc.outputs().snapshot(Output{o2::header::gDataOriginTF3, "CLUSTERSMCTR", 0}, noEntry ? noLabels : *mLabels);
}
if (noEntry || mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
pc.services().get<ControlService>().endOfStream();
pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
}
}

void ClusterReader::connectTree(const std::string& filename)
{
mTree.reset();
mFile.reset(TFile::Open(filename.c_str()));
if (!mFile || mFile->IsZombie()) {
throw std::runtime_error("TF3ClusterReader: cannot open " + filename);
}
mTree.reset(mFile->Get<TTree>("o2sim"));
if (!mTree) {
throw std::runtime_error("TF3ClusterReader: no tree o2sim in " + filename);
}
const auto connect = [this](const char* name, auto*& address) {
if (!mTree->GetBranch(name)) {
throw std::runtime_error(std::format("TF3ClusterReader: no branch {}", name));
}
if (const Int_t status = mTree->SetBranchAddress(name, &address); status < 0) {
throw std::runtime_error(std::format("TF3ClusterReader: cannot set the address of {} ({})", name, status));
}
};
connect("TF3Cluster", mClusters);
connect("TF3ClusterPatt", mPatterns);
connect("TF3ClusterROF", mROFs);
if (mUseMC) {
connect("TF3ClusterMCTruth", mLabels);
}
LOG(info) << "TF3ClusterReader: " << filename << " with " << mTree->GetEntries() << " entries";
}

DataProcessorSpec getIOTOFClusterReaderSpec(bool useMC)
{
std::vector<OutputSpec> outputs{{o2::header::gDataOriginTF3, "CLUSTERS", 0, Lifetime::Timeframe},
{o2::header::gDataOriginTF3, "PATTERNS", 0, Lifetime::Timeframe},
{o2::header::gDataOriginTF3, "CLUSTERSROF", 0, Lifetime::Timeframe}};
if (useMC) {
outputs.emplace_back(o2::header::gDataOriginTF3, "CLUSTERSMCTR", 0, Lifetime::Timeframe);
}
return DataProcessorSpec{
.name = "tf3-cluster-reader",
.inputs = Inputs{},
.outputs = outputs,
.algorithm = AlgorithmSpec{adaptFromTask<ClusterReader>(useMC)},
.options = Options{{"tf3-cluster-infile", VariantType::String, "tf3clusters.root", {"Name of the input cluster file"}}},
};
}

} // namespace o2::iotof
Loading