Project
Loading...
Searching...
No Matches
PreClusterReaderSpec.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"
27#include "MCHBase/PreCluster.h"
28
29using namespace o2::framework;
30
31namespace o2::mch
32{
33
35 std::unique_ptr<RootTreeReader> mTreeReader;
36 bool mUseMC = false;
37
38 PreClusterReader(bool useMC) : mUseMC(useMC) {}
39
40 void init(InitContext& ic)
41 {
42 auto treeName = "o2sim";
43 auto fileName = o2::utils::Str::concat_string(o2::utils::Str::rectifyDirectory(ic.options().get<std::string>("input-dir")), ic.options().get<std::string>("infile"));
44 auto nofEntries{-1};
45 if (mUseMC) {
46 // not available (yet?)
47 LOG(warn) << "Disabling preclusters MC labels reading";
48 mUseMC = false;
49 }
50 if (mUseMC) {
51 mTreeReader = std::make_unique<RootTreeReader>(
52 treeName,
53 fileName.c_str(),
54 nofEntries,
56 RootTreeReader::BranchDefinition<std::vector<ROFRecord>>{Output{"MCH", "PRECLUSTERROFS", 0}, "preclusterrofs"},
57 RootTreeReader::BranchDefinition<std::vector<PreCluster>>{Output{"MCH", "PRECLUSTERS", 0}, "preclusters"},
58 RootTreeReader::BranchDefinition<std::vector<Digit>>{Output{"MCH", "PRECLUSTERDIGITS", 0}, "preclusterdigits"},
59 RootTreeReader::BranchDefinition<dataformats::MCTruthContainer<MCCompLabel>>{Output{"MCH", "PRECLUSTERLABELS", 0}, "preclusterlabels"});
60 } else {
61 mTreeReader = std::make_unique<RootTreeReader>(
62 treeName,
63 fileName.c_str(),
64 nofEntries,
66 RootTreeReader::BranchDefinition<std::vector<ROFRecord>>{Output{"MCH", "PRECLUSTERROFS", 0}, "preclusterrofs"},
67 RootTreeReader::BranchDefinition<std::vector<PreCluster>>{Output{"MCH", "PRECLUSTERS", 0}, "preclusters"},
68 RootTreeReader::BranchDefinition<std::vector<Digit>>{Output{"MCH", "PRECLUSTERDIGITS", 0}, "preclusterdigits"});
69 }
70 }
71
73 {
74 if (mTreeReader->next()) {
75 (*mTreeReader)(pc);
76 } else {
77 pc.services().get<ControlService>().endOfStream();
78 }
79 }
80};
81
83{
84 std::vector<OutputSpec> outputSpecs;
85 outputSpecs.emplace_back(OutputSpec{{"preclusterrofs"}, "MCH", "PRECLUSTERROFS", 0, Lifetime::Timeframe});
86 outputSpecs.emplace_back(OutputSpec{{"preclusters"}, "MCH", "PRECLUSTERS", 0, Lifetime::Timeframe});
87 outputSpecs.emplace_back(OutputSpec{{"preclusterdigits"}, "MCH", "PRECLUSTERDIGITS", 0, Lifetime::Timeframe});
88
89 auto options = Options{
90 {"infile", VariantType::String, "mchpreclusters.root", {"name of the input precluster file"}},
91 {"input-dir", VariantType::String, "none", {"Input directory"}}};
92
93 return DataProcessorSpec{
95 Inputs{},
96 outputSpecs,
97 adaptFromTask<PreClusterReader>(useMC),
98 options};
99}
100} // namespace o2::mch
Definition of the MCH precluster 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
o2::framework::DataProcessorSpec getPreClusterReaderSpec(bool useMC, const char *specName="mch-precluster-reader")
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"