Skip to content

Commit 3e26f6c

Browse files
authored
CPV,PHS: modernize cell, digit and cluster readers (#12060)
* CPV,PHS: modernize cell, digit and cluster readers * GlobalTrackingWorkflow: add modernized CPV and PHS readers to InputHelper.cxx
1 parent a784234 commit 3e26f6c

File tree

18 files changed

+840
-22
lines changed

18 files changed

+840
-22
lines changed

Detectors/CPV/workflow/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
o2_add_library(CPVWorkflow
1313
SOURCES src/RecoWorkflow.cxx
1414
src/ReaderSpec.cxx
15+
src/DigitReaderSpec.cxx
16+
src/ClusterReaderSpec.cxx
1517
src/WriterSpec.cxx
1618
src/ClusterizerSpec.cxx
1719
src/DigitsPrinterSpec.cxx
@@ -41,3 +43,13 @@ o2_add_executable(cluster-writer-workflow
4143
COMPONENT_NAME cpv
4244
SOURCES src/cluster-writer-workflow.cxx
4345
PUBLIC_LINK_LIBRARIES O2::CPVWorkflow)
46+
47+
o2_add_executable(digit-reader-workflow
48+
COMPONENT_NAME cpv
49+
SOURCES src/digit-reader-workflow.cxx
50+
PUBLIC_LINK_LIBRARIES O2::CPVWorkflow)
51+
52+
o2_add_executable(cluster-reader-workflow
53+
COMPONENT_NAME cpv
54+
SOURCES src/cluster-reader-workflow.cxx
55+
PUBLIC_LINK_LIBRARIES O2::CPVWorkflow)
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
14+
#ifndef O2_CPV_CLUSTERREADER
15+
#define O2_CPV_CLUSTERREADER
16+
17+
#include "TFile.h"
18+
#include "TTree.h"
19+
20+
#include "Framework/DataProcessorSpec.h"
21+
#include "Framework/Task.h"
22+
#include "Headers/DataHeader.h"
23+
#include "DataFormatsCPV/Cluster.h"
24+
#include "DataFormatsCPV/TriggerRecord.h"
25+
#include "SimulationDataFormat/MCCompLabel.h"
26+
#include "SimulationDataFormat/MCTruthContainer.h"
27+
28+
namespace o2
29+
{
30+
namespace cpv
31+
{
32+
33+
class ClusterReader : public o2::framework::Task
34+
{
35+
public:
36+
ClusterReader(bool useMC = true);
37+
~ClusterReader() override = default;
38+
void init(o2::framework::InitContext& ic) final;
39+
void run(o2::framework::ProcessingContext& pc) final;
40+
41+
protected:
42+
void connectTree(const std::string& filename);
43+
44+
std::vector<o2::cpv::Cluster> mClusters, *mClustersInp = &mClusters;
45+
std::vector<o2::cpv::TriggerRecord> mTRs, *mTRsInp = &mTRs;
46+
o2::dataformats::MCTruthContainer<o2::MCCompLabel> mMCTruth, *mMCTruthInp = &mMCTruth;
47+
48+
o2::header::DataOrigin mOrigin = o2::header::gDataOriginCPV;
49+
50+
bool mUseMC = true; // use MC truth
51+
52+
std::unique_ptr<TFile> mFile;
53+
std::unique_ptr<TTree> mTree;
54+
std::string mInputFileName = "";
55+
std::string mClusterTreeName = "o2sim";
56+
std::string mClusterBranchName = "CPVCluster";
57+
std::string mTRBranchName = "CPVClusterTrigRec";
58+
std::string mClusterMCTruthBranchName = "CPVClusterTrueMC";
59+
};
60+
61+
/// create a processor spec
62+
/// read CPV Cluster data from a root file
63+
framework::DataProcessorSpec getCPVClusterReaderSpec(bool useMC = true);
64+
65+
} // namespace cpv
66+
} // namespace o2
67+
68+
#endif /* O2_CPV_CLUSTERREADER */
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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 DigitReaderSpec.h
13+
14+
#ifndef O2_CPV_DIGITREADER
15+
#define O2_CPV_DIGITREADER
16+
17+
#include "TFile.h"
18+
#include "TTree.h"
19+
20+
#include "Framework/DataProcessorSpec.h"
21+
#include "Framework/Task.h"
22+
#include "Headers/DataHeader.h"
23+
#include "DataFormatsCPV/Digit.h"
24+
#include "DataFormatsCPV/TriggerRecord.h"
25+
#include "SimulationDataFormat/MCCompLabel.h"
26+
#include "SimulationDataFormat/MCTruthContainer.h"
27+
28+
namespace o2
29+
{
30+
namespace cpv
31+
{
32+
33+
class DigitReader : public o2::framework::Task
34+
{
35+
public:
36+
DigitReader(bool useMC = true);
37+
~DigitReader() override = default;
38+
void init(o2::framework::InitContext& ic) final;
39+
void run(o2::framework::ProcessingContext& pc) final;
40+
41+
protected:
42+
void connectTree(const std::string& filename);
43+
44+
std::vector<o2::cpv::Digit> mDigits, *mDigitsInp = &mDigits;
45+
std::vector<o2::cpv::TriggerRecord> mTRs, *mTRsInp = &mTRs;
46+
// std::vector<o2::MCCompLabel> mMCTruth, *mMCTruthInp = &mMCTruth;
47+
o2::dataformats::MCTruthContainer<o2::MCCompLabel> mMCTruth, *mMCTruthInp = &mMCTruth;
48+
49+
o2::header::DataOrigin mOrigin = o2::header::gDataOriginCPV;
50+
51+
bool mUseMC = true; // use MC truth
52+
53+
std::unique_ptr<TFile> mFile;
54+
std::unique_ptr<TTree> mTree;
55+
std::string mInputFileName = "";
56+
std::string mDigitTreeName = "o2sim";
57+
std::string mDigitBranchName = "CPVDigit";
58+
std::string mTRBranchName = "CPVDigitTrigRecords";
59+
std::string mDigitMCTruthBranchName = "CPVDigitMCTruth";
60+
};
61+
62+
/// create a processor spec
63+
/// read CPV Digit data from a root file
64+
framework::DataProcessorSpec getCPVDigitReaderSpec(bool useMC = true);
65+
66+
} // namespace cpv
67+
} // namespace o2
68+
69+
#endif /* O2_CPV_DIGITREADER */
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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+
14+
#include <vector>
15+
#include <cassert>
16+
#include "Framework/ControlService.h"
17+
#include "Framework/ConfigParamRegistry.h"
18+
#include "CPVWorkflow/ClusterReaderSpec.h"
19+
#include "CommonUtils/NameConf.h"
20+
21+
using namespace o2::framework;
22+
using namespace o2::cpv;
23+
24+
namespace o2
25+
{
26+
namespace cpv
27+
{
28+
29+
ClusterReader::ClusterReader(bool useMC)
30+
{
31+
mUseMC = useMC;
32+
}
33+
34+
void ClusterReader::init(InitContext& ic)
35+
{
36+
mInputFileName = o2::utils::Str::concat_string(o2::utils::Str::rectifyDirectory(ic.options().get<std::string>("input-dir")),
37+
ic.options().get<std::string>("cpv-clusters-infile"));
38+
connectTree(mInputFileName);
39+
}
40+
41+
void ClusterReader::run(ProcessingContext& pc)
42+
{
43+
auto ent = mTree->GetReadEntry() + 1;
44+
assert(ent < mTree->GetEntries()); // this should not happen
45+
mTree->GetEntry(ent);
46+
LOG(info) << "Pushing " << mClusters.size() << " Clusters in " << mTRs.size() << " TriggerRecords at entry " << ent;
47+
pc.outputs().snapshot(Output{mOrigin, "CLUSTERS", 0, Lifetime::Timeframe}, mClusters);
48+
pc.outputs().snapshot(Output{mOrigin, "CLUSTERTRIGRECS", 0, Lifetime::Timeframe}, mTRs);
49+
if (mUseMC) {
50+
pc.outputs().snapshot(Output{mOrigin, "CLUSTERTRUEMC", 0, Lifetime::Timeframe}, mMCTruth);
51+
}
52+
53+
if (mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
54+
pc.services().get<ControlService>().endOfStream();
55+
pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
56+
}
57+
}
58+
59+
void ClusterReader::connectTree(const std::string& filename)
60+
{
61+
mTree.reset(nullptr); // in case it was already loaded
62+
mFile.reset(TFile::Open(filename.c_str()));
63+
assert(mFile && !mFile->IsZombie());
64+
mTree.reset((TTree*)mFile->Get(mClusterTreeName.c_str()));
65+
assert(mTree);
66+
assert(mTree->GetBranch(mTRBranchName.c_str()));
67+
68+
mTree->SetBranchAddress(mTRBranchName.c_str(), &mTRsInp);
69+
mTree->SetBranchAddress(mClusterBranchName.c_str(), &mClustersInp);
70+
if (mUseMC) {
71+
if (mTree->GetBranch(mClusterMCTruthBranchName.c_str())) {
72+
mTree->SetBranchAddress(mClusterMCTruthBranchName.c_str(), &mMCTruthInp);
73+
} else {
74+
LOG(warning) << "MC-truth is missing, message will be empty";
75+
}
76+
}
77+
LOG(info) << "Loaded tree from " << filename << " with " << mTree->GetEntries() << " entries";
78+
}
79+
80+
DataProcessorSpec getCPVClusterReaderSpec(bool useMC)
81+
{
82+
std::vector<OutputSpec> outputSpec;
83+
outputSpec.emplace_back("CPV", "CLUSTERS", 0, Lifetime::Timeframe);
84+
outputSpec.emplace_back("CPV", "CLUSTERTRIGRECS", 0, Lifetime::Timeframe);
85+
if (useMC) {
86+
outputSpec.emplace_back("CPV", "CLUSTERTRUEMC", 0, Lifetime::Timeframe);
87+
}
88+
89+
return DataProcessorSpec{
90+
"cpv-cluster-reader",
91+
Inputs{},
92+
outputSpec,
93+
AlgorithmSpec{adaptFromTask<ClusterReader>(useMC)},
94+
Options{
95+
{"cpv-clusters-infile", VariantType::String, "cpvclusters.root", {"Name of the input Cluster file"}},
96+
{"input-dir", VariantType::String, "none", {"Input directory"}}}};
97+
}
98+
99+
} // namespace cpv
100+
} // namespace o2
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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 DigitReaderSpec.cxx
13+
14+
#include <vector>
15+
#include <cassert>
16+
#include "Framework/ControlService.h"
17+
#include "Framework/ConfigParamRegistry.h"
18+
#include "CPVWorkflow/DigitReaderSpec.h"
19+
#include "CommonUtils/NameConf.h"
20+
21+
using namespace o2::framework;
22+
using namespace o2::cpv;
23+
24+
namespace o2
25+
{
26+
namespace cpv
27+
{
28+
29+
DigitReader::DigitReader(bool useMC)
30+
{
31+
mUseMC = useMC;
32+
}
33+
34+
void DigitReader::init(InitContext& ic)
35+
{
36+
mInputFileName = o2::utils::Str::concat_string(o2::utils::Str::rectifyDirectory(ic.options().get<std::string>("input-dir")),
37+
ic.options().get<std::string>("cpv-digits-infile"));
38+
connectTree(mInputFileName);
39+
}
40+
41+
void DigitReader::run(ProcessingContext& pc)
42+
{
43+
auto ent = mTree->GetReadEntry() + 1;
44+
assert(ent < mTree->GetEntries()); // this should not happen
45+
mTree->GetEntry(ent);
46+
LOG(info) << "Pushing " << mDigits.size() << " Digits in " << mTRs.size() << " TriggerRecords at entry " << ent;
47+
pc.outputs().snapshot(Output{mOrigin, "DIGITS", 0, Lifetime::Timeframe}, mDigits);
48+
pc.outputs().snapshot(Output{mOrigin, "DIGITTRIGREC", 0, Lifetime::Timeframe}, mTRs);
49+
if (mUseMC) {
50+
pc.outputs().snapshot(Output{mOrigin, "DIGITSMCTR", 0, Lifetime::Timeframe}, mMCTruth);
51+
}
52+
53+
if (mTree->GetReadEntry() + 1 >= mTree->GetEntries()) {
54+
pc.services().get<ControlService>().endOfStream();
55+
pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
56+
}
57+
}
58+
59+
void DigitReader::connectTree(const std::string& filename)
60+
{
61+
mTree.reset(nullptr); // in case it was already loaded
62+
mFile.reset(TFile::Open(filename.c_str()));
63+
assert(mFile && !mFile->IsZombie());
64+
mTree.reset((TTree*)mFile->Get(mDigitTreeName.c_str()));
65+
assert(mTree);
66+
assert(mTree->GetBranch(mTRBranchName.c_str()));
67+
68+
mTree->SetBranchAddress(mTRBranchName.c_str(), &mTRsInp);
69+
mTree->SetBranchAddress(mDigitBranchName.c_str(), &mDigitsInp);
70+
if (mUseMC) {
71+
if (mTree->GetBranch(mDigitMCTruthBranchName.c_str())) {
72+
mTree->SetBranchAddress(mDigitMCTruthBranchName.c_str(), &mMCTruthInp);
73+
} else {
74+
LOG(warning) << "MC-truth is missing, message will be empty";
75+
}
76+
}
77+
LOG(info) << "Loaded tree from " << filename << " with " << mTree->GetEntries() << " entries";
78+
}
79+
80+
DataProcessorSpec getCPVDigitReaderSpec(bool useMC)
81+
{
82+
std::vector<OutputSpec> outputSpec;
83+
outputSpec.emplace_back("CPV", "DIGITS", 0, Lifetime::Timeframe);
84+
outputSpec.emplace_back("CPV", "DIGITTRIGREC", 0, Lifetime::Timeframe);
85+
if (useMC) {
86+
outputSpec.emplace_back("CPV", "DIGITSMCTR", 0, Lifetime::Timeframe);
87+
}
88+
89+
return DataProcessorSpec{
90+
"cpv-digit-reader",
91+
Inputs{},
92+
outputSpec,
93+
AlgorithmSpec{adaptFromTask<DigitReader>(useMC)},
94+
Options{
95+
{"cpv-digits-infile", VariantType::String, "cpvdigits.root", {"Name of the input Digit file"}},
96+
{"input-dir", VariantType::String, "none", {"Input directory"}}}};
97+
}
98+
99+
} // namespace cpv
100+
} // namespace o2

Detectors/CPV/workflow/src/RecoWorkflow.cxx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "SimulationDataFormat/MCCompLabel.h"
2525
#include "DataFormatsCPV/TriggerRecord.h"
2626
#include "CPVWorkflow/RecoWorkflow.h"
27+
#include "CPVWorkflow/DigitReaderSpec.h"
2728
#include "CPVWorkflow/ClusterizerSpec.h"
2829
#include "CPVWorkflow/ReaderSpec.h"
2930
#include "CPVWorkflow/WriterSpec.h"
@@ -107,7 +108,8 @@ o2::framework::WorkflowSpec getWorkflow(bool disableRootInp,
107108
// Digits to ....
108109
if (inputType == InputType::Digits) {
109110
if (!disableRootInp) {
110-
specs.emplace_back(o2::cpv::getDigitsReaderSpec(propagateMC));
111+
specs.emplace_back(o2::cpv::getCPVDigitReaderSpec(propagateMC));
112+
// specs.emplace_back(o2::cpv::getDigitsReaderSpec(propagateMC));
111113
}
112114

113115
if (isEnabled(OutputType::Clusters)) {

0 commit comments

Comments
 (0)