Project
Loading...
Searching...
No Matches
DigitsToClustersSpec.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
14
18
19#include <array>
20#include <fstream>
21#include <functional>
22#include <iostream>
23#include <random>
24#include <stdexcept>
25#include <vector>
26
32#include "Framework/Lifetime.h"
33#include "Framework/Logger.h"
34#include "Framework/Output.h"
35
39
40#include "CommonUtils/NameConf.h" // o2::utils::Str
41
42namespace o2
43{
44namespace hmpid
45{
46
47using namespace o2;
48using namespace o2::header;
49using namespace o2::framework;
51
52// Splits a string in float array for string delimiter, TODO: Move this in a
53// HMPID common library
54void DigitsToClustersTask::strToFloatsSplit(std::string s,
55 std::string delimiter, float* res,
56 int maxElem)
57{
58 int index = 0;
59 size_t pos_start = 0;
60 size_t pos_end;
61 size_t delim_len = delimiter.length();
62 std::string token;
63 while ((pos_end = s.find(delimiter, pos_start)) != std::string::npos) {
64 token = s.substr(pos_start, pos_end - pos_start);
65 pos_start = pos_end + delim_len;
66 res[index++] = std::stof(token);
67 if (index == maxElem) {
68 return;
69 }
70 }
71 res[index++] = (std::stof(s.substr(pos_start)));
72 return;
73}
74
75//=======================
76//
78{
79 mSigmaCutPar = ic.options().get<std::string>("sigma-cut");
80
81 if (mSigmaCutPar != "") {
82 strToFloatsSplit(mSigmaCutPar, ",", mSigmaCut, 7);
83 }
84
85 mDigitsReceived = 0, mClustersReceived = 0;
86
87 mRec.reset(new o2::hmpid::Clusterer()); // ef: changed to smart-pointer
88
89 mExTimer.start();
90}
91
93{
94 // outputs
95 std::vector<o2::hmpid::Cluster> clusters;
96 std::vector<o2::hmpid::Trigger> clusterTriggers;
97 LOG(info) << "[HMPID DClusterization - run() ] Enter ...";
98 clusters.clear();
99 clusterTriggers.clear();
100
101 auto triggers = pc.inputs().get<gsl::span<o2::hmpid::Trigger>>("intrecord");
102 auto digits = pc.inputs().get<gsl::span<o2::hmpid::Digit>>("digits");
103
104 for (const auto& trig : triggers) {
105 if (trig.getNumberOfObjects()) {
106 gsl::span<const o2::hmpid::Digit> trigDigits{
107 digits.data() + trig.getFirstEntry(),
108 size_t(trig.getNumberOfObjects())};
109 size_t clStart = clusters.size();
110 mRec->Dig2Clu(trigDigits, clusters, mSigmaCut, true);
111 clusterTriggers.emplace_back(trig.getIr(), clStart, clusters.size() - clStart);
112 }
113 }
114 LOGP(info, "Received {} triggers with {} digits -> {} triggers with {} clusters",
115 triggers.size(), digits.size(), clusterTriggers.size(), clusters.size());
116 mDigitsReceived += digits.size();
117 mClustersReceived += clusters.size();
118
119 pc.outputs().snapshot(o2::framework::Output{"HMP", "CLUSTERS", 0}, clusters);
120 pc.outputs().snapshot(o2::framework::Output{"HMP", "INTRECORDS1", 0}, clusterTriggers);
121
122 mExTimer.elapseMes("Clusterization of Digits received = " + std::to_string(mDigitsReceived));
123 mExTimer.elapseMes("Clusterization of Clusters received = " + std::to_string(mClustersReceived));
124}
125
127{
128
129 mExTimer.stop();
130 mExTimer.logMes("End Clusterization ! digits = " +
131 std::to_string(mDigitsReceived));
132}
133
134//_______________________________________________________________________________________________
137
138{
139
140 std::vector<o2::framework::InputSpec> inputs;
141
142 inputs.emplace_back("digits", o2::header::gDataOriginHMP, "DIGITS", 0,
143 o2::framework::Lifetime::Timeframe);
144 inputs.emplace_back("intrecord", o2::header::gDataOriginHMP, "INTRECORDS", 0,
145 o2::framework::Lifetime::Timeframe);
146
147 // define outputs
148 std::vector<o2::framework::OutputSpec> outputs;
149
150 outputs.emplace_back("HMP", "CLUSTERS", 0,
151 o2::framework::Lifetime::Timeframe);
152 outputs.emplace_back("HMP", "INTRECORDS1", 0,
153 o2::framework::Lifetime::Timeframe);
154
155 return DataProcessorSpec{
156 "HMP-Clusterization", inputs, outputs,
157 AlgorithmSpec{adaptFromTask<DigitsToClustersTask>()},
158 Options{{"sigma-cut",
159 VariantType::String,
160 "",
161 {"sigmas as comma separated list"}}}};
162}
163
164} // namespace hmpid
165} // end namespace o2
Implementation of writing HMPID clusters to file.
A raw page parser for DPL input.
Implementation of clusterization for HMPID; read upstream/from file write upstream/to file.
A helper class to iteratate over all parts of all input routes.
Definition of the Names Generator class.
Definition of the RAW Data Header.
uint32_t res
Definition RawData.h:0
void snapshot(const Output &spec, T const &object)
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 init(framework::InitContext &ic) final
void endOfStream(framework::EndOfStreamContext &ec) override
This is invoked whenever we have an EndOfStream event.
void run(framework::ProcessingContext &pc) final
void stop()
stop : stops the timer
Definition Common.h:73
void elapseMes(std::string const message)
Definition Common.h:91
void start()
start : starts the timer
Definition Common.h:64
void logMes(std::string const message)
Definition Common.h:81
GLuint index
Definition glcorearb.h:781
constexpr o2::header::DataOrigin gDataOriginHMP
Definition DataHeader.h:569
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
O2 data header classes and API, v0.1.
Definition DetID.h:49
o2::framework::DataProcessorSpec getDigitsToClustersSpec()
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::vector< Cluster > clusters
std::vector< Digit > digits