26CellRecalibratorSpec::CellRecalibratorSpec(uint32_t outputspec,
LEDEventSettings ledsettings,
bool badChannelCalib,
bool timeCalib,
bool gainCalib,
bool isMC, std::shared_ptr<o2::emcal::CalibLoader> calibHandler) : mOutputSubspec(outputspec), mIsMC(isMC), mLEDsettings(ledsettings), mCalibrationHandler(calibHandler)
39 std::string ledsettingstitle;
40 switch (mLEDsettings) {
42 ledsettingstitle =
"keep";
45 ledsettingstitle =
"drop";
48 ledsettingstitle =
"redirect to EMC/CELLS/10";
51 LOG(info) <<
"Handling of LED events: " << ledsettingstitle;
53 LOG(info) <<
"MC mode - removing labels for masked cells from MC label container";
59 auto inputcells = ctx.
inputs().
get<gsl::span<o2::emcal::Cell>>(
"cells");
60 auto intputtriggers = ctx.
inputs().
get<gsl::span<o2::emcal::TriggerRecord>>(
"triggerrecords");
61 LOG(info) <<
"Received " << inputcells.size() <<
" cells from " << intputtriggers.size() <<
" triggers";
62 std::unique_ptr<const o2::dataformats::MCTruthContainer<o2::emcal::MCLabel>> inputMCLabels =
nullptr;
63 std::optional<o2::dataformats::MCTruthContainer<o2::emcal::MCLabel>> outputMCLabels;
67 LOG(info) <<
"Received " << inputMCLabels->
getIndexedSize() <<
" MC Label entries";
70 mCalibrationHandler->checkUpdates(ctx);
73 std::vector<o2::emcal::Cell> outputcells;
74 std::vector<o2::emcal::TriggerRecord> outputtriggers;
77 std::vector<o2::emcal::Cell> ledcells;
78 std::vector<o2::emcal::TriggerRecord> ledtriggers;
80 uint32_t currentfirst = outputcells.size(),
81 currentledfirst = ledcells.size();
82 for (
const auto& trg : intputtriggers) {
84 switch (mLEDsettings) {
87 writeTrigger(inputcells.subspan(trg.getFirstEntry(), trg.getNumberOfObjects()), trg, outputcells, outputtriggers);
94 writeTrigger(inputcells.subspan(trg.getFirstEntry(), trg.getNumberOfObjects()), trg, ledcells, ledtriggers);
99 if (!trg.getNumberOfObjects()) {
100 outputtriggers.emplace_back(trg.getBCData(), outputcells.size(), trg.getNumberOfObjects()).setTriggerBits(trg.getTriggerBits());
103 auto [calibratedCells, cellIndices] = mCellRecalibrator.
getCalibratedCells(gsl::span<const o2::emcal::Cell>(inputcells.data() + trg.getFirstEntry(), trg.getNumberOfObjects()));
104 writeTrigger(calibratedCells, trg, outputcells, outputtriggers);
106 writeMCLabels(*inputMCLabels, outputMCLabels.value(), cellIndices, trg.getFirstEntry());
110 LOG(info) <<
"Timeframe: " << inputcells.size() <<
" cells read, " << outputcells.size() <<
" cells kept";
112 LOG(info) <<
"Redirecting " << ledcells.size() <<
" LED cells from " << ledtriggers.size() <<
" LED triggers";
118 if (outputMCLabels.has_value()) {
119 LOG(info) <<
"Timeframe: " << inputMCLabels->getIndexedSize() <<
" label entries read, " << outputMCLabels->getIndexedSize() <<
" label entries kept";
128void CellRecalibratorSpec::writeTrigger(
const gsl::span<const o2::emcal::Cell> selectedCells,
const o2::emcal::TriggerRecord& currenttrigger, std::vector<o2::emcal::Cell>& outputcontainer, std::vector<o2::emcal::TriggerRecord>& outputtriggers)
130 std::size_t currentfirst = outputcontainer.size();
131 if (selectedCells.size()) {
132 std::copy(selectedCells.begin(), selectedCells.end(), std::back_inserter(outputcontainer));
134 outputtriggers.emplace_back(currenttrigger.
getBCData(), currentfirst, selectedCells.size()).setTriggerBits(currenttrigger.
getTriggerBits());
139 for (
auto keptindex : keptIndices) {
140 int globalInputIndex = firstindex + keptindex;
141 auto labelsToKeep = inputlabels.
getLabels(globalInputIndex);
148 LOG(info) <<
"Handling new Calibration objects";
149 if (mCalibrationHandler->finalizeCCDB(matcher, obj)) {
154void CellRecalibratorSpec::updateCalibObjects()
157 if (mCalibrationHandler->hasUpdateBadChannelMap()) {
158 LOG(info) <<
"updateCalibObjects: Bad channel map changed";
159 mCellRecalibrator.
setBadChannelMap(mCalibrationHandler->getBadChannelMap());
163 if (mCalibrationHandler->hasUpdateTimeCalib()) {
164 LOG(info) <<
"updateCalibObjects: Time calib params changed";
169 if (mCalibrationHandler->hasUpdateGainCalib()) {
170 LOG(info) <<
"updateCalibObjects: Time calib params changed";
178 auto calibhandler = std::make_shared<o2::emcal::CalibLoader>();
179 calibhandler->enableBadChannelMap(badChannelCalib);
180 calibhandler->enableTimeCalib(timeCalib);
181 calibhandler->enableGainCalib(gainCalib);
182 std::vector<o2::framework::InputSpec>
186 switch (ledsettings) {
197 LOG(fatal) <<
"Undefined handling of LED events";
199 std::vector<o2::framework::OutputSpec> outputs = {{
o2::header::gDataOriginEMC,
"CELLS", outputSubspec, o2::framework::Lifetime::Timeframe},
206 inputs.push_back({
"cellmclabels",
o2::header::gDataOriginEMC,
"CELLSMCTR", inputSubspec, o2::framework::Lifetime::Timeframe});
209 calibhandler->defineInputSpecs(inputs);
214 o2::framework::adaptFromTask<o2::emcal::CellRecalibratorSpec>(outputSubspec, taskledsettings, badChannelCalib, timeCalib, gainCalib, isMC, calibhandler)};
Definition of the 32 Central Trigger System (CTS) Trigger Types defined in https://twiki....
LEDEventSettings
Dedicated handling for LED events.
@ REDIRECT
Redirect LED events to dedicated output.
@ KEEP
Keep LED events in timeframe (uncalibrated)
void setRunGainCalibration(bool doRun)
Switch for the gain calibration.
void setRunTimeCalibration(bool doRun)
Switch for time calibration.
void finaliseCCDB(framework::ConcreteDataMatcher &matcher, void *obj) final
Fetching cell objects and assigning them to the internal handlers.
void setRunBadChannelCalibration(bool doRun)
Switch for bad channel calibration.
CellRecalibratorSpec(uint32_t outputspec, LEDEventSettings ledsettings, bool badChannelCalib, bool timeCalib, bool gainCalib, bool isMC, std::shared_ptr< CalibLoader >(calibHandler))
Constructor.
bool isRunBadChannlCalibration() const
Check if the bad channel calibration is enabled.
void run(framework::ProcessingContext &ctx) final
Run recalibration of cells for a new timeframe.
bool isRunTimeCalibration() const
Check if the time calibration is enabled.
bool isRunGainCalibration() const
Check if the gain calibration is enabled.
void init(framework::InitContext &ctx) final
Initialize recalibrator.
std::tuple< std::vector< T >, std::vector< int > > getCalibratedCells(const gsl::span< const T > inputcells)
Get list of calibrated cells based on a cell input collection.
void setGainCalibration(const GainCalibrationFactors *gcf)
Set the gain calibration params.
void setTimeCalibration(const TimeCalibrationParams *tcp)
Set the time calibration params.
void setBadChannelMap(const BadChannelMap *bcm)
Set the bad channel map.
Header for data corresponding to the same hardware trigger.
uint32_t getTriggerBits() const
const BCData & getBCData() const
void snapshot(const Output &spec, T const &object)
DataAllocator & outputs()
The data allocator is used to allocate memory for the output data.
InputRecord & inputs()
The inputs associated with this processing context.
constexpr o2::header::DataOrigin gDataOriginEMC
framework::DataProcessorSpec getCellRecalibratorSpec(uint32_t inputSubspec, uint32_t outputSubspec, uint32_t ledsettings, bool badChannelCalib, bool timeCalib, bool gainCalib, bool isMC)
Create CellRecalibrator processor spec.
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"