Project
Loading...
Searching...
No Matches
PressureTemperatureHelper.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
15
19#include "DataFormatsTPC/DCS.h"
23
24using namespace o2::tpc;
25using namespace o2::framework;
26
28{
29 pc.inputs().get<dcs::Pressure*>("pressure");
30 pc.inputs().get<dcs::Temperature*>("temperature");
31}
32
34{
35 if (matcher == ConcreteDataMatcher(o2::header::gDataOriginTPC, "PRESSURECCDB", 0)) {
36 LOGP(info, "Updating pressure");
37 const auto& pressure = ((dcs::Pressure*)obj);
38 mPressure.second = pressure->robustPressure.time;
39 mPressure.first = pressure->robustPressure.robustPressure;
40 return true;
41 }
42
43 if (matcher == ConcreteDataMatcher(o2::header::gDataOriginTPC, "TEMPERATURECCDB", 0)) {
44 LOGP(info, "Updating temperature");
45 auto temp = *(dcs::Temperature*)obj;
46 temp.fitTemperature(o2::tpc::Side::A, mFitIntervalMS, false);
47 temp.fitTemperature(o2::tpc::Side::C, mFitIntervalMS, false);
48
49 mTemperatureA.first.clear();
50 mTemperatureC.first.clear();
51 mTemperatureA.second.clear();
52 mTemperatureC.second.clear();
53
54 for (const auto& dp : temp.statsA.data) {
55 mTemperatureA.first.emplace_back(dp.value.mean);
56 mTemperatureA.second.emplace_back(dp.time);
57 }
58
59 for (const auto& dp : temp.statsC.data) {
60 mTemperatureC.first.emplace_back(dp.value.mean);
61 mTemperatureC.second.emplace_back(dp.time);
62 }
63 return true;
64 }
65 return false;
66}
67
68void PressureTemperatureHelper::requestCCDBInputs(std::vector<InputSpec>& inputs)
69{
70 addInput(inputs, {"pressure", o2::header::gDataOriginTPC, "PRESSURECCDB", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalPressure), {}, 1)});
71 addInput(inputs, {"temperature", o2::header::gDataOriginTPC, "TEMPERATURECCDB", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalTemperature), {}, 1)});
72}
73
74void PressureTemperatureHelper::addInput(std::vector<InputSpec>& inputs, InputSpec&& isp)
75{
76 if (std::find(inputs.begin(), inputs.end(), isp) == inputs.end()) {
77 inputs.emplace_back(isp);
78 }
79}
80
86
87void PressureTemperatureHelper::addOutput(std::vector<OutputSpec>& outputs, OutputSpec&& osp)
88{
89 if (std::find(outputs.begin(), outputs.end(), osp) == outputs.end()) {
90 outputs.emplace_back(osp);
91 }
92}
93
94float PressureTemperatureHelper::interpolate(const std::vector<uint64_t>& timestamps, const std::vector<float>& values, uint64_t timestamp) const
95{
96 if (auto idxClosest = o2::math_utils::findClosestIndices(timestamps, timestamp)) {
97 auto [idxLeft, idxRight] = *idxClosest;
98 if (idxRight > idxLeft) {
99 const uint64_t x0 = timestamps[idxLeft];
100 const uint64_t x1 = timestamps[idxRight];
101 const float y0 = values[idxLeft];
102 const float y1 = values[idxRight];
103 const float y = (y0 * (x1 - timestamp) + y1 * (timestamp - x0)) / (x1 - x0);
104 return y;
105 } else {
106 return values[idxLeft];
107 }
108 }
109 return 0; // this should never happen
110}
111
113{
114 const float pressure = getPressure(timestamp);
115 const auto temp = getTemperature(timestamp);
116 LOGP(info, "Sending pressure {}, temperature A {} and temperature C {} for timestamp {}", pressure, temp.first, temp.second, timestamp);
119}
Simple interface to the CDB manager.
DCS data point data formats.
Helper class to extract pressure and temperature.
void snapshot(const Output &spec, T const &object)
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.
dataformats::Pair< float, float > getTemperature(const uint64_t timestamp) const
get temperature for given time stamp in ms
static void requestCCDBInputs(std::vector< o2::framework::InputSpec > &inputs)
float interpolate(const std::vector< uint64_t > &timestamps, const std::vector< float > &values, uint64_t timestamp) const
interpolate input values for given timestamp
void extractCCDBInputs(o2::framework::ProcessingContext &pc) const
trigger checking for CCDB objects
static constexpr o2::header::DataDescription getDataDescriptionTemperature()
std::pair< std::vector< float >, std::vector< uint64_t > > mTemperatureC
temperature values C-side
static void addOutput(std::vector< o2::framework::OutputSpec > &outputs, o2::framework::OutputSpec &&osp)
int mFitIntervalMS
fit interval for the temperature
std::pair< std::vector< float >, std::vector< uint64_t > > mTemperatureA
temperature values A-side
void sendPTForTS(o2::framework::ProcessingContext &pc, const uint64_t timestamp) const
send temperature and pressure for given time stamp
std::pair< std::vector< float >, std::vector< uint64_t > > mPressure
pressure values for both measurements
float getPressure(const uint64_t timestamp) const
get pressure for given time stamp in ms
static constexpr o2::header::DataDescription getDataDescriptionPressure()
static void addInput(std::vector< o2::framework::InputSpec > &inputs, o2::framework::InputSpec &&isp)
bool accountCCDBInputs(const o2::framework::ConcreteDataMatcher &matcher, void *obj)
check for new CCDB objects
static void setOutputs(std::vector< o2::framework::OutputSpec > &outputs)
define outputs in case pressure and temperature will be send
GLuint GLfloat GLfloat GLfloat GLfloat y1
Definition glcorearb.h:5034
GLuint GLfloat GLfloat GLfloat x1
Definition glcorearb.h:5034
GLint y
Definition glcorearb.h:270
GLenum GLsizei GLsizei GLint * values
Definition glcorearb.h:1576
GLuint GLfloat x0
Definition glcorearb.h:5034
GLuint GLfloat GLfloat y0
Definition glcorearb.h:5034
constexpr o2::header::DataOrigin gDataOriginTPC
Definition DataHeader.h:576
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > ccdbParamSpec(std::string const &path, int runDependent, std::vector< CCDBMetadata > metadata={}, int qrate=0)
std::optional< std::pair< size_t, size_t > > findClosestIndices(const std::vector< DataTimeType > &timestamps, DataTime timestamp)
Definition fit.h:796
Global TPC definitions and constants.
Definition SimTraits.h:167
const std::unordered_map< CDBType, const std::string > CDBTypeMap
Storage name in CCDB for each calibration and parameter type.
Definition CDBTypes.h:96
@ A
Definition Defs.h:35
@ C
Definition Defs.h:36
@ CalPressure
DCS pressure measurements.
@ CalTemperature
DCS temperature measurements.