Skip to content

Commit c55375d

Browse files
tklemenzdavidrohr
authored andcommitted
file reader for TPC Tracks and Clusters (+ MC info)
1 parent f952182 commit c55375d

3 files changed

Lines changed: 115 additions & 2 deletions

File tree

Detectors/TPC/workflow/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ o2_add_library(TPCWorkflow
2525
src/ZSSpec.cxx
2626
src/CalibProcessingHelper.cxx
2727
src/ClusterSharingMapSpec.cxx
28+
src/FileReaderWorkflow.cxx
2829
TARGETVARNAME targetName
2930
PUBLIC_LINK_LIBRARIES O2::Framework O2::DataFormatsTPC
3031
O2::DPLUtils O2::TPCReconstruction
@@ -51,6 +52,11 @@ o2_add_executable(track-reader
5152
SOURCES src/TrackReaderWorkflow.cxx
5253
PUBLIC_LINK_LIBRARIES O2::TPCWorkflow)
5354

55+
o2_add_executable(file-reader
56+
COMPONENT_NAME tpc
57+
SOURCES src/FileReaderWorkflow.cxx
58+
PUBLIC_LINK_LIBRARIES O2::TPCWorkflow)
59+
5460
o2_add_test(workflow
5561
COMPONENT_NAME tpc
5662
LABELS tpc workflow
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
/// @file FileReaderWorkflow.cxx
12+
13+
#include "TPCWorkflow/PublisherSpec.h"
14+
#include "TPCWorkflow/TrackReaderSpec.h"
15+
16+
#include "Algorithm/RangeTokenizer.h"
17+
18+
#include "SimulationDataFormat/IOMCTruthContainerView.h"
19+
#include "SimulationDataFormat/ConstMCTruthContainer.h"
20+
#include "SimulationDataFormat/MCCompLabel.h"
21+
22+
// add workflow options, note that customization needs to be declared before
23+
// including Framework/runDataProcessing
24+
void customize(std::vector<o2::framework::ConfigParamSpec>& workflowOptions)
25+
{
26+
using namespace o2::framework;
27+
28+
std::vector<ConfigParamSpec> options{
29+
{"input-type", VariantType::String, "clusters", {"clusters, tracks"}},
30+
{"disable-mc", VariantType::Bool, false, {"disable sending of MC information"}}};
31+
32+
std::swap(workflowOptions, options);
33+
}
34+
35+
#include "Framework/runDataProcessing.h" // the main driver
36+
37+
using namespace o2::framework;
38+
39+
enum struct Input { Clusters,
40+
Tracks
41+
};
42+
43+
const std::unordered_map<std::string, Input> InputMap{
44+
{"clusters", Input::Clusters},
45+
{"tracks", Input::Tracks}};
46+
47+
/// MC info is processed by default, disabled by using command line option `--disable-mc`
48+
///
49+
/// This function hooks up the the workflow specifications into the DPL driver.
50+
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
51+
{
52+
WorkflowSpec specs;
53+
54+
auto inputType = cfgc.options().get<std::string>("input-type");
55+
bool doMC = not cfgc.options().get<bool>("disable-mc");
56+
57+
std::vector<Input> inputTypes;
58+
try {
59+
inputTypes = o2::RangeTokenizer::tokenize<Input>(inputType, [](std::string const& token) { return InputMap.at(token); });
60+
} catch (std::out_of_range&) {
61+
throw std::invalid_argument(std::string("invalid input type: ") + inputType);
62+
}
63+
auto isEnabled = [&inputTypes](Input type) {
64+
return std::find(inputTypes.begin(), inputTypes.end(), type) != inputTypes.end();
65+
};
66+
67+
if (isEnabled(Input::Clusters)) {
68+
69+
// We provide a special publishing method for labels which have been stored in a split format and need
70+
// to be transformed into a contiguous shareable container before publishing. For other branches/types this returns
71+
// false and the generic RootTreeWriter publishing proceeds
72+
static RootTreeReader::SpecialPublishHook hook{[](std::string_view name, ProcessingContext& context, o2::framework::Output const& output, char* data) -> bool {
73+
if (TString(name.data()).Contains("TPCDigitMCTruth") || TString(name.data()).Contains("TPCClusterHwMCTruth") || TString(name.data()).Contains("TPCClusterNativeMCTruth")) {
74+
auto storedlabels = reinterpret_cast<o2::dataformats::IOMCTruthContainerView const*>(data);
75+
o2::dataformats::ConstMCTruthContainer<o2::MCCompLabel> flatlabels;
76+
storedlabels->copyandflatten(flatlabels);
77+
LOG(INFO) << "PUBLISHING CONST LABELS " << flatlabels.getNElements();
78+
context.outputs().snapshot(output, flatlabels);
79+
return true;
80+
}
81+
return false;
82+
}};
83+
84+
std::vector<int> tpcSectors(36);
85+
std::iota(tpcSectors.begin(), tpcSectors.end(), 0);
86+
std::vector<int> laneConfiguration = tpcSectors;
87+
88+
specs.emplace_back(o2::tpc::getPublisherSpec(o2::tpc::PublisherConf{
89+
"tpc-native-cluster-reader",
90+
"tpcrec",
91+
{"clusterbranch", "TPCClusterNative", "Branch with TPC native clusters"},
92+
{"clustermcbranch", "TPCClusterNativeMCTruth", "MC label branch"},
93+
OutputSpec{"TPC", "CLUSTERNATIVE"},
94+
OutputSpec{"TPC", "CLNATIVEMCLBL"},
95+
tpcSectors,
96+
laneConfiguration,
97+
&hook},
98+
doMC));
99+
}
100+
101+
if (isEnabled(Input::Tracks)) {
102+
103+
specs.push_back(o2::tpc::getTPCTrackReaderSpec(doMC));
104+
}
105+
106+
return std::move(specs);
107+
}

Detectors/TPC/workflow/src/TrackReaderSpec.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ TrackReader::TrackReader(bool useMC)
2929

3030
void TrackReader::init(InitContext& ic)
3131
{
32-
mInputFileName = ic.options().get<std::string>("tpc-tracks-infile");
32+
mInputFileName = ic.options().get<std::string>("infile");
3333
connectTree(mInputFileName);
3434
}
3535

@@ -131,7 +131,7 @@ DataProcessorSpec getTPCTrackReaderSpec(bool useMC)
131131
outputSpec,
132132
AlgorithmSpec{adaptFromTask<TrackReader>(useMC)},
133133
Options{
134-
{"tpc-tracks-infile", VariantType::String, "tpctracks.root", {"Name of the input track file"}}}};
134+
{"infile", VariantType::String, "tpctracks.root", {"Name of the input track file"}}}};
135135
}
136136

137137
} // namespace tpc

0 commit comments

Comments
 (0)