Project
Loading...
Searching...
No Matches
ClusterReaderSpec.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
14#include <iostream>
15#include <vector>
18#include "Framework/Lifetime.h"
19#include "Framework/Logger.h"
20#include "Framework/Task.h"
28
29using namespace o2::framework;
30
31namespace o2::mch
32{
33
35 std::unique_ptr<RootTreeReader> mTreeReader;
36 bool mUseMC = false;
37 bool mGlobal = false;
38 bool mDigits = false;
39
40 ClusterReader(bool useMC, bool global, bool digits) : mUseMC(useMC), mGlobal(global), mDigits(digits) {}
41
42 void init(InitContext& ic)
43 {
44 auto treeName = "o2sim";
45 auto fileName = o2::utils::Str::concat_string(o2::utils::Str::rectifyDirectory(ic.options().get<std::string>("input-dir")), ic.options().get<std::string>("infile"));
46 auto nofEntries{-1};
47 auto clusterDescription = mGlobal ? header::DataDescription{"GLOBALCLUSTERS"} : header::DataDescription{"CLUSTERS"};
48 if (mUseMC) {
49 // not clear where the MClabels come from
50 LOG(warn) << "Disabling clusters MC labels reading";
51 mUseMC = false;
52 }
53 if (mUseMC) {
54 if (mDigits) {
55 mTreeReader = std::make_unique<RootTreeReader>(
56 treeName,
57 fileName.c_str(),
58 nofEntries,
60 RootTreeReader::BranchDefinition<std::vector<Cluster>>{Output{"MCH", clusterDescription, 0}, "clusters"},
61 RootTreeReader::BranchDefinition<std::vector<ROFRecord>>{Output{"MCH", "CLUSTERROFS", 0}, "clusterrofs"},
62 RootTreeReader::BranchDefinition<std::vector<Digit>>{Output{"MCH", "CLUSTERDIGITS", 0}, "clusterdigits"},
64 } else {
65 mTreeReader = std::make_unique<RootTreeReader>(
66 treeName,
67 fileName.c_str(),
68 nofEntries,
70 RootTreeReader::BranchDefinition<std::vector<Cluster>>{Output{"MCH", clusterDescription, 0}, "clusters"},
71 RootTreeReader::BranchDefinition<std::vector<ROFRecord>>{Output{"MCH", "CLUSTERROFS", 0}, "clusterrofs"},
73 }
74 } else {
75 if (mDigits) {
76 mTreeReader = std::make_unique<RootTreeReader>(
77 treeName,
78 fileName.c_str(),
79 nofEntries,
81 RootTreeReader::BranchDefinition<std::vector<Cluster>>{Output{"MCH", clusterDescription, 0}, "clusters"},
82 RootTreeReader::BranchDefinition<std::vector<ROFRecord>>{Output{"MCH", "CLUSTERROFS", 0}, "clusterrofs"},
83 RootTreeReader::BranchDefinition<std::vector<Digit>>{Output{"MCH", "CLUSTERDIGITS", 0}, "clusterdigits"});
84 } else {
85 mTreeReader = std::make_unique<RootTreeReader>(
86 treeName,
87 fileName.c_str(),
88 nofEntries,
90 RootTreeReader::BranchDefinition<std::vector<Cluster>>{Output{"MCH", clusterDescription, 0}, "clusters"},
91 RootTreeReader::BranchDefinition<std::vector<ROFRecord>>{Output{"MCH", "CLUSTERROFS", 0}, "clusterrofs"});
92 }
93 }
94 }
95
97 {
98 if (mTreeReader->next()) {
99 (*mTreeReader)(pc);
100 } else {
101 pc.services().get<ControlService>().endOfStream();
102 }
103 }
104};
105
106DataProcessorSpec getClusterReaderSpec(bool useMC, const char* specName, bool global, bool digits)
107{
108 auto clusterDescription = global ? header::DataDescription{"GLOBALCLUSTERS"} : header::DataDescription{"CLUSTERS"};
109 std::vector<OutputSpec> outputSpecs;
110 outputSpecs.emplace_back(OutputSpec{{"clusters"}, "MCH", clusterDescription, 0, Lifetime::Timeframe});
111 outputSpecs.emplace_back(OutputSpec{{"clusterrofs"}, "MCH", "CLUSTERROFS", 0, Lifetime::Timeframe});
112 if (digits) {
113 outputSpecs.emplace_back(OutputSpec{{"clusterdigits"}, "MCH", "CLUSTERDIGITS", 0, Lifetime::Timeframe});
114 }
115 if (useMC) {
116 outputSpecs.emplace_back(OutputSpec{{"clusterlabels"}, "MCH", "CLUSTERLABELS", 0, Lifetime::Timeframe});
117 }
118
119 auto options = Options{
120 {"infile", VariantType::String, "mchclusters.root", {"name of the input cluster file"}},
121 {"input-dir", VariantType::String, "none", {"Input directory"}}};
122
123 return DataProcessorSpec{
124 specName,
125 Inputs{},
126 outputSpecs,
127 adaptFromTask<ClusterReader>(useMC, global, digits),
128 options};
129}
130} // namespace o2::mch
Definition of the MCH cluster minimal structure.
Definition of a container to keep Monte Carlo truth external to simulation objects.
Definition of the MCH ROFrame record.
A generic reader for ROOT TTrees.
const char * specName
ConfigParamRegistry const & options()
Definition InitContext.h:33
ServiceRegistryRef services()
The services registry associated with this processing context.
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
void init(InitContext &ic)
ClusterReader(bool useMC, bool global, bool digits)
void run(ProcessingContext &pc)
std::unique_ptr< RootTreeReader > mTreeReader
static std::string rectifyDirectory(const std::string_view p)
static std::string concat_string(Ts const &... ts)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::vector< Digit > digits