Project
Loading...
Searching...
No Matches
TrackReaderSpec.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
18#include "Framework/Lifetime.h"
19#include "Framework/Logger.h"
20#include "Framework/Task.h"
27#include <iostream>
28#include <vector>
29
30using namespace o2::framework;
31
32namespace o2::mid
33{
34
35template <typename T>
36void printBranch(char* data, const char* what)
37{
38 auto tdata = reinterpret_cast<std::vector<T>*>(data);
39 LOGP(info, "MID {:d} {:s}", tdata->size(), what);
40}
41
43 [](std::string_view name, ProcessingContext&, Output const&, char* data) -> bool {
44 if (name == "MIDTrackROF") {
45 printBranch<ROFRecord>(data, "TRACKROFS");
46 }
47 if (name == "MIDTrackClusterROF") {
48 printBranch<ROFRecord>(data, "TRCLUSROFS");
49 }
50 if (name == "MIDTrack") {
51 printBranch<Track>(data, "TRACKS");
52 }
53 if (name == "MIDTrackCluster") {
54 printBranch<Cluster>(data, "TRACKCLUSTERS");
55 }
56 if (name == "MIDTrackLabels") {
57 printBranch<MCCompLabel>(data, "TRACKLABELS");
58 }
59 if (name == "MIDTrackClusterLabels") {
60 auto tdata = reinterpret_cast<o2::dataformats::MCTruthContainer<MCClusterLabel>*>(data);
61 LOGP(info, "MID {:d} {:s}", tdata->getNElements(), "TRCLUSLABELS");
62 }
63 return false;
64 }};
65
67 std::unique_ptr<RootTreeReader> mTreeReader;
68 bool mUseMC = false;
69 TrackReader(bool useMC = false) : mUseMC(useMC) {}
70 void init(InitContext& ic)
71 {
72 if (!mUseMC) {
73 LOGP(warning, "Not reading MID Track Labels");
74 }
75 auto treeName = "midreco";
76 auto fileName = o2::utils::Str::concat_string(o2::utils::Str::rectifyDirectory(ic.options().get<std::string>("input-dir")), ic.options().get<std::string>("infile"));
77 auto nofEntries{-1};
78 if (mUseMC) {
79 mTreeReader = std::make_unique<RootTreeReader>(
80 treeName,
81 fileName.c_str(),
82 nofEntries,
84 RootTreeReader::BranchDefinition<std::vector<Track>>{Output{"MID", "TRACKS", 0}, "MIDTrack"},
85 RootTreeReader::BranchDefinition<std::vector<ROFRecord>>{Output{"MID", "TRACKROFS", 0}, "MIDTrackROF"},
86 RootTreeReader::BranchDefinition<std::vector<Cluster>>{Output{"MID", "TRACKCLUSTERS", 0}, "MIDTrackCluster"},
87 RootTreeReader::BranchDefinition<std::vector<ROFRecord>>{Output{"MID", "TRCLUSROFS", 0}, "MIDTrackClusterROF"},
88 RootTreeReader::BranchDefinition<std::vector<MCCompLabel>>{Output{"MID", "TRACKLABELS", 0}, "MIDTrackLabels"},
89 RootTreeReader::BranchDefinition<o2::dataformats::MCTruthContainer<MCClusterLabel>>{Output{"MID", "TRCLUSLABELS", 0}, "MIDTrackClusterLabels"},
90 &logging);
91 } else {
92 mTreeReader = std::make_unique<RootTreeReader>(
93 treeName,
94 fileName.c_str(),
95 nofEntries,
97 RootTreeReader::BranchDefinition<std::vector<Track>>{Output{"MID", "TRACKS", 0}, "MIDTrack"},
98 RootTreeReader::BranchDefinition<std::vector<ROFRecord>>{Output{"MID", "TRACKROFS", 0}, "MIDTrackROF"},
99 RootTreeReader::BranchDefinition<std::vector<Cluster>>{Output{"MID", "TRACKCLUSTERS", 0}, "MIDTrackCluster"},
100 RootTreeReader::BranchDefinition<std::vector<ROFRecord>>{Output{"MID", "TRCLUSROFS", 0}, "MIDTrackClusterROF"},
101 &logging);
102 }
103 }
104
106 {
107 if (mTreeReader->next()) {
108 (*mTreeReader)(pc);
109 } else {
110 pc.services().get<ControlService>().endOfStream();
111 }
112 }
113};
114
115DataProcessorSpec getTrackReaderSpec(bool useMC, const char* specName)
116{
117 std::vector<OutputSpec> outputSpecs;
118 outputSpecs.emplace_back(OutputSpec{{"tracks"}, "MID", "TRACKS", 0, Lifetime::Timeframe});
119 outputSpecs.emplace_back(OutputSpec{{"tracksrof"}, "MID", "TRACKROFS", 0, Lifetime::Timeframe});
120 outputSpecs.emplace_back(OutputSpec{{"trackclusters"}, "MID", "TRACKCLUSTERS", 0, Lifetime::Timeframe});
121 outputSpecs.emplace_back(OutputSpec{{"trclusrof"}, "MID", "TRCLUSROFS", 0, Lifetime::Timeframe});
122 if (useMC) {
123 outputSpecs.emplace_back(OutputSpec{{"tracklabels"}, "MID", "TRACKLABELS", 0, Lifetime::Timeframe});
124 outputSpecs.emplace_back(OutputSpec{{"trcluslabels"}, "MID", "TRCLUSLABELS", 0, Lifetime::Timeframe});
125 }
126
127 auto options = Options{
128 {"infile", VariantType::String, "mid-reco.root", {"name of the input track file"}},
129 {"input-dir", VariantType::String, "none", {"Input directory"}}};
130
131 return DataProcessorSpec{
132 specName,
133 Inputs{},
134 outputSpecs,
135 adaptFromTask<TrackReader>(useMC),
136 options};
137}
138} // namespace o2::mid
Reconstructed MID cluster.
Reconstructed MID track.
Label for MID clusters.
Definition of a container to keep Monte Carlo truth external to simulation objects.
Definition of the MID event record.
A generic reader for ROOT TTrees.
const char * specName
A container to hold and manage MC truth information/labels.
ConfigParamRegistry const & options()
Definition InitContext.h:33
ServiceRegistryRef services()
The services registry associated with this processing context.
GLuint const GLchar * name
Definition glcorearb.h:781
GLboolean * data
Definition glcorearb.h:298
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
RootTreeReader::SpecialPublishHook logging
void printBranch(char *data, const char *what)
void run(ProcessingContext &pc)
TrackReader(bool useMC=false)
std::unique_ptr< RootTreeReader > mTreeReader
void init(InitContext &ic)
static std::string rectifyDirectory(const std::string_view p)
static std::string concat_string(Ts const &... ts)