Project
Loading...
Searching...
No Matches
EventFinderSpec.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
16
17#include "EventFinderSpec.h"
18
19#include <chrono>
20#include <string>
21#include <vector>
22
23#include <fmt/format.h>
24
25#include <gsl/span>
26
29#include "Framework/Task.h"
31#include "Framework/Logger.h"
39
40namespace o2
41{
42namespace mch
43{
44
45using namespace o2::framework;
46using namespace o2::dataformats;
47
49{
50 public:
51 EventFinderTask(bool useMC) : mUseMC{useMC} {}
52
53 //_________________________________________________________________________________________________
55 void init(InitContext& ic)
56 {
57 LOG(info) << "initializing event finding";
58
59 auto config = ic.options().get<std::string>("mch-config");
60 if (!config.empty()) {
61 conf::ConfigurableParam::updateFromFile(config, "MCHTriggering", true);
62 }
63
64 auto stop = [this]() {
65 LOG(info) << "event finder duration = " << mElapsedTime.count() << " s";
66 };
67 ic.services().get<CallbackService>().set<CallbackService::Id::Stop>(stop);
68 }
69
70 //_________________________________________________________________________________________________
73 {
74 auto mchROFs = pc.inputs().get<gsl::span<mch::ROFRecord>>("mchrofs");
75 auto mchDigits = pc.inputs().get<gsl::span<mch::Digit>>("mchdigits");
76 auto mchLabels = mUseMC ? pc.inputs().get<MCTruthContainer<MCCompLabel>*>("mchlabels") : nullptr;
77 auto midROFs = pc.inputs().get<gsl::span<mid::ROFRecord>>("midrofs");
78
79 auto tStart = std::chrono::high_resolution_clock::now();
80 mEventFinder.run(mchROFs, mchDigits, mchLabels.get(), midROFs);
81 auto tEnd = std::chrono::high_resolution_clock::now();
82 mElapsedTime += tEnd - tStart;
83
84 pc.outputs().snapshot(OutputRef{"rofs"}, mEventFinder.getOutputROFs());
85 pc.outputs().snapshot(OutputRef{"digits"}, mEventFinder.getOutputDigits());
86 if (mUseMC) {
87 pc.outputs().snapshot(OutputRef{"labels"}, mEventFinder.getOutputLabels());
88 }
89
90 LOGP(info, "produced {} ROFs with {} digits {}",
91 mEventFinder.getOutputROFs().size(),
92 mEventFinder.getOutputDigits().size(),
93 mUseMC ? fmt::format("and {} labels", mEventFinder.getOutputLabels().getNElements()) : "");
94 }
95
96 private:
97 bool mUseMC = false;
98 EventFinder mEventFinder{};
99 std::chrono::duration<double> mElapsedTime{};
100};
101
102//_________________________________________________________________________________________________
104 std::string_view specName,
105 std::string_view inputDigitDataDescription,
106 std::string_view outputDigitDataDescription,
107 std::string_view inputDigitRofDataDescription,
108 std::string_view outputDigitRofDataDescription,
109 std::string_view inputDigitLabelDataDescription,
110 std::string_view outputDigitLabelDataDescription)
111{
112 std::string input =
113 fmt::format("mchdigits:MCH/{}/0;mchrofs:MCH/{}/0", inputDigitDataDescription, inputDigitRofDataDescription);
114 if (useMC) {
115 input += fmt::format(";mchlabels:MCH/{}/0", inputDigitLabelDataDescription);
116 }
117 input += ";midrofs:MID/TRACKROFS/0";
118
119 std::string output =
120 fmt::format("digits:MCH/{}/0;rofs:MCH/{}/0", outputDigitDataDescription, outputDigitRofDataDescription);
121 if (useMC) {
122 output += fmt::format(";labels:MCH/{}/0", outputDigitLabelDataDescription);
123 }
124
125 std::vector<OutputSpec> outputs;
126 auto matchers = select(output.c_str());
127 for (auto& matcher : matchers) {
128 outputs.emplace_back(DataSpecUtils::asOutputSpec(matcher));
129 }
130
131 return DataProcessorSpec{
132 specName.data(),
133 Inputs{select(input.c_str())},
134 outputs,
135 AlgorithmSpec{adaptFromTask<EventFinderTask>(useMC)},
136 Options{{"mch-config", VariantType::String, "", {"JSON or INI file with event finder parameters"}}}};
137}
138
139} // namespace mch
140} // namespace o2
Definition of a data processor to group MCH digits based on MID information.
Definition of a class to group MCH digits based on MID information.
void output(const std::map< std::string, ChannelStat > &channels)
Definition rawdump.cxx:197
Definition of a container to keep Monte Carlo truth external to simulation objects.
Definition of the MCH ROFrame record.
Definition of the MID event record.
const char * specName
static void updateFromFile(std::string const &, std::string const &paramsList="", bool unchangedOnly=false)
A container to hold and manage MC truth information/labels.
void snapshot(const Output &spec, T const &object)
ServiceRegistryRef services()
Definition InitContext.h:34
ConfigParamRegistry const & options()
Definition InitContext.h:33
decltype(auto) get(R binding, int part=0) const
DataAllocator & outputs()
The data allocator is used to allocate memory for the output data.
InputRecord & inputs()
The inputs associated with this processing context.
void run(ProcessingContext &pc)
run the track matching
void init(InitContext &ic)
prepare the event finding
Class to group MCH digits based on MID information.
Definition EventFinder.h:39
const std::vector< mch::ROFRecord > & getOutputROFs() const
get the output MCH ROFs
Definition EventFinder.h:53
const std::vector< mch::Digit > & getOutputDigits() const
get the output MCH digits
Definition EventFinder.h:55
const dataformats::MCLabelContainer & getOutputLabels() const
get the output MCH labels
Definition EventFinder.h:57
void run(const gsl::span< const mch::ROFRecord > &mchROFs, const gsl::span< const mch::Digit > &digits, const dataformats::MCLabelContainer *labels, const gsl::span< const mid::ROFRecord > &midROFs)
run the event finder algorithm
Definition of a container to keep/associate and arbitrary number of labels associated to an index wit...
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > select(char const *matcher="")
std::vector< InputSpec > Inputs
DataProcessorSpec getEventFinderSpec(bool useMC, std::string_view specName, std::string_view inputDigitDataDescription, std::string_view outputDigitDataDescription, std::string_view inputDigitRofDataDescription, std::string_view outputDigitRofDataDescription, std::string_view inputDigitLabelDataDescription, std::string_view outputDigitLabelDataDescription)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
static OutputSpec asOutputSpec(InputSpec const &spec)
std::vector< o2::mid::ROFRecord > midROFs
o2::dataformats::MCLabelContainer mchLabels
std::vector< o2::mch::Digit > mchDigits
std::vector< o2::mch::ROFRecord > mchROFs
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"