forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaskMakerSpec.cxx
More file actions
147 lines (124 loc) · 5.66 KB
/
MaskMakerSpec.cxx
File metadata and controls
147 lines (124 loc) · 5.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/// \file MID/Workflow/src/MaskMakerSpec.cxx
/// \brief Processor to compute the masks
/// \author Diego Stocco <Diego.Stocco at cern.ch>
/// \date 12 may 2021
#include "MIDWorkflow/MaskMakerSpec.h"
#include <array>
#include <vector>
#include <chrono>
#include <gsl/gsl>
#include "Framework/ConfigParamRegistry.h"
#include "Framework/ControlService.h"
#include "Framework/DataRefUtils.h"
#include "Framework/InputRecordWalker.h"
#include "Framework/InputSpec.h"
#include "Framework/Logger.h"
#include "Framework/Task.h"
#include "DataFormatsMID/ColumnData.h"
#include "DataFormatsMID/ROFRecord.h"
#include "MIDFiltering/ChannelMasksHandler.h"
#include "MIDFiltering/ChannelScalers.h"
#include "MIDFiltering/FetToDead.h"
#include "MIDFiltering/MaskMaker.h"
namespace of = o2::framework;
namespace o2
{
namespace mid
{
class MaskMakerDeviceDPL
{
public:
MaskMakerDeviceDPL(const FEEIdConfig& feeIdConfig, const CrateMasks& crateMasks)
{
mRefMasks = makeDefaultMasksFromCrateConfig(feeIdConfig, crateMasks);
mFetToDead.setMasks(mRefMasks);
}
void init(of::InitContext& ic)
{
mThreshold = ic.options().get<double>("mid-mask-threshold");
mNReset = ic.options().get<int>("mid-mask-reset");
auto stop = [this]() {
double scaleFactor = (mCounter == 0) ? 0 : 1.e6 / mCounter;
LOG(info) << "Processing time / " << mCounter << " events: full: " << mTimer.count() * scaleFactor << " us mask maker: " << mTimerMaskMaker.count() * scaleFactor << " us";
};
ic.services().get<of::CallbackService>().set<of::CallbackService::Id::Stop>(stop);
}
void run(of::ProcessingContext& pc)
{
auto tStart = std::chrono::high_resolution_clock::now();
gsl::span<const ColumnData> calibData, fetData;
gsl::span<const ROFRecord> calibDataRof, fetDataRof;
calibData = pc.inputs().get<gsl::span<o2::mid::ColumnData>>("mid_data_1");
calibDataRof = pc.inputs().get<gsl::span<o2::mid::ROFRecord>>("mid_data_rof_1");
fetData = pc.inputs().get<gsl::span<o2::mid::ColumnData>>("mid_data_2");
fetDataRof = pc.inputs().get<gsl::span<o2::mid::ROFRecord>>("mid_data_rof_2");
unsigned long nEvents = calibDataRof.size();
if (nEvents == 0) {
return;
}
auto tAlgoStart = std::chrono::high_resolution_clock::now();
for (auto& col : calibData) {
mScalers[0].count(col);
}
for (auto& rof : fetDataRof) {
auto subSet = fetData.subspan(rof.firstEntry, rof.nEntries);
auto deadChannels = mFetToDead.process(subSet);
for (auto& col : deadChannels) {
mScalers[1].count(col);
}
}
mCounter += nEvents;
mCounterSinceReset += nEvents;
if (mCounterSinceReset >= mNReset) {
for (size_t itype = 0; itype < 2; ++itype) {
auto masks = o2::mid::makeMasks(mScalers[itype], mCounterSinceReset, mThreshold, mRefMasks);
pc.outputs().snapshot(of::Output{header::gDataOriginMID, "MASKS", static_cast<header::DataHeader::SubSpecificationType>(itype + 1)}, masks);
}
mCounterSinceReset = 0;
for (auto& scaler : mScalers) {
scaler.reset();
}
}
mTimerMaskMaker += std::chrono::high_resolution_clock::now() - tAlgoStart;
mTimer += std::chrono::high_resolution_clock::now() - tStart;
}
private:
FetToDead mFetToDead{}; ///< FET to dead channels converter
std::vector<ColumnData> mRefMasks{}; ///< Reference masks
std::array<ChannelScalers, 2> mScalers{}; ///< Array fo channel scalers
std::chrono::duration<double> mTimer{0}; ///< full timer
std::chrono::duration<double> mTimerMaskMaker{0}; ///< mask maker timer
unsigned long mCounter{0}; ///< Total number of processed events
unsigned long mCounterSinceReset{0}; ///< Total number of processed events since last reset
double mThreshold{0.9}; ///< Occupancy threshold for producing a mask
int mNReset{1}; ///< Number of calibration events to be tested before checking the scalers
};
framework::DataProcessorSpec getMaskMakerSpec(const FEEIdConfig& feeIdConfig, const CrateMasks& crateMasks)
{
std::vector<of::InputSpec> inputSpecs;
for (o2::header::DataHeader::SubSpecificationType subSpec = 1; subSpec < NEvTypes; ++subSpec) {
inputSpecs.emplace_back(fmt::format("mid_data_{}", subSpec), o2::header::gDataOriginMID, "DATA", subSpec, of::Lifetime::Timeframe);
inputSpecs.emplace_back(fmt::format("mid_data_rof_{}", subSpec), o2::header::gDataOriginMID, "DATAROF", subSpec, of::Lifetime::Timeframe);
}
std::vector<of::OutputSpec> outputSpecs{
of::OutputSpec{header::gDataOriginMID, "MASKS", 1},
of::OutputSpec{header::gDataOriginMID, "MASKS", 2}};
return of::DataProcessorSpec{
"MIDMaskMaker",
{inputSpecs},
{outputSpecs},
of::AlgorithmSpec{of::adaptFromTask<o2::mid::MaskMakerDeviceDPL>(feeIdConfig, crateMasks)},
of::Options{{"mid-mask-threshold", of::VariantType::Double, 0.9, {"Tolerated occupancy before producing a map"}}, {"mid-mask-reset", of::VariantType::Int, 100, {"Number of calibration events to be checked before resetting the scalers"}}}};
}
} // namespace mid
} // namespace o2