Skip to content
Snippets Groups Projects

LArTemperatureCorrectionTool: Coverity warnings and tidy

1 file
+ 46
30
Compare changes
  • Side-by-side
  • Inline
/*
Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
*/
#include <TParameter.h>
#include <ElectronPhotonFourMomentumCorrection/LArTemperatureCorrectionTool.h>
#include <TParameter.h>
#include <exception>
template<typename T>
T get_value_parameter(TFile& f, const std::string& name)
T
get_value_parameter(TFile& f, const std::string& name)
{
TParameter<T>* p = dynamic_cast<TParameter<T>*>(f.Get(name.c_str()));
if (not p) { return 0; }
if (not p) {
return 0;
}
return p->GetVal();
}
LArTemperatureCorrectionTool::LArTemperatureCorrectionTool(const std::string& filename)
: asg::AsgMessaging("LArTemperatureCorrectionTool"), m_file(TFile::Open(filename.c_str()))
: asg::AsgMessaging("LArTemperatureCorrectionTool")
, m_file(TFile::Open(filename.c_str()))
{
if (!m_file or m_file->IsZombie()) { ATH_MSG_ERROR("cannot open file"); }
if (!m_file or m_file->IsZombie()) {
throw std::runtime_error("LArTemperatureCorrectionTool: Cannot open file");
}
m_tree = dynamic_cast<TTree*>(m_file->Get("temperature"));
if (!m_tree) { ATH_MSG_FATAL("cannot find tree"); }
if (!m_tree) {
throw std::runtime_error("LArTemperatureCorrectionTool: Cannot find tree");
}
Int_t t_run = 0;
m_tree->SetBranchAddress("run", &t_run);
@@ -29,10 +37,6 @@ LArTemperatureCorrectionTool::LArTemperatureCorrectionTool(const std::string& fi
m_tree->GetEntry(m_tree->GetEntries() - 1);
m_last_run = t_run;
m_file->Get("base_temperature_barrel");
TParameter<double>* p = static_cast<TParameter<double>*>(m_file->Get("base_temperature_barrel"));
p->GetVal();
base_temperature.barrel = get_value_parameter<double>(*m_file, "base_temperature_barrel");
base_temperature.endcapA = get_value_parameter<double>(*m_file, "base_temperature_endcapA");
base_temperature.endcapC = get_value_parameter<double>(*m_file, "base_temperature_endcapC");
@@ -41,12 +45,17 @@ LArTemperatureCorrectionTool::LArTemperatureCorrectionTool(const std::string& fi
sensitivity_temperature.endcapA = get_value_parameter<double>(*m_file, "sensitivity_temperature_endcapA");
sensitivity_temperature.endcapC = get_value_parameter<double>(*m_file, "sensitivity_temperature_endcapC");
ATH_MSG_INFO("LArTemperatureCorrectionTool initialized for runs " << m_first_run << ".." << m_last_run);
ATH_MSG_INFO("base temperatures (barrel/endcapA/endcapC) = " << base_temperature.barrel << "/" << base_temperature.endcapA << "/" << base_temperature.endcapC);
ATH_MSG_INFO("sensitivity relE/K (barrel/endcapA/endcapC) = " << sensitivity_temperature.barrel << "/" << sensitivity_temperature.endcapA << "/" << sensitivity_temperature.endcapC);
ATH_MSG_INFO("LArTemperatureCorrectionTool initialized for runs " << m_first_run << ".." << m_last_run);
ATH_MSG_INFO("base temperatures (barrel/endcapA/endcapC) = " << base_temperature.barrel << "/"
<< base_temperature.endcapA << "/"
<< base_temperature.endcapC);
ATH_MSG_INFO("sensitivity relE/K (barrel/endcapA/endcapC) = " << sensitivity_temperature.barrel << "/"
<< sensitivity_temperature.endcapA << "/"
<< sensitivity_temperature.endcapC);
}
LArTemperatureCorrectionTool::AllValues LArTemperatureCorrectionTool::search_correction(int run) const
LArTemperatureCorrectionTool::AllValues
LArTemperatureCorrectionTool::search_correction(int run) const
{
AllValues temp = search_temperature(run);
temp.barrel = 1. - (temp.barrel - base_temperature.barrel) * sensitivity_temperature.barrel;
@@ -55,7 +64,8 @@ LArTemperatureCorrectionTool::AllValues LArTemperatureCorrectionTool::search_cor
return temp;
}
LArTemperatureCorrectionTool::AllValues LArTemperatureCorrectionTool::search_temperature(int run) const
LArTemperatureCorrectionTool::AllValues
LArTemperatureCorrectionTool::search_temperature(int run) const
{
Float_t t_barrel = base_temperature.barrel;
Float_t t_endcapA = base_temperature.endcapA;
@@ -72,40 +82,46 @@ LArTemperatureCorrectionTool::AllValues LArTemperatureCorrectionTool::search_tem
int mid = 0;
while (low <= high) {
if (high - low < 50) { // prefer sequential scan
if (high - low < 50) { // prefer sequential scan
for (int i = low; i <= high; ++i) {
m_tree->GetEntry(i);
if (run == t_run) { return AllValues { t_barrel, t_endcapA, t_endcapC }; }
if (run == t_run) {
return AllValues{ t_barrel, t_endcapA, t_endcapC };
}
}
break;
}
mid = low + (high - low) / 2; // scared of overflow?
mid = low + (high - low) / 2; // scared of overflow?
m_tree->GetEntry(mid);
if (run == t_run) { return AllValues { t_barrel, t_endcapA, t_endcapC }; }
else if (run < t_run) { high = mid - 1; }
else { low = mid + 1; }
if (run == t_run) {
return AllValues{ t_barrel, t_endcapA, t_endcapC };
} else if (run < t_run) {
high = mid - 1;
} else {
low = mid + 1;
}
}
ATH_MSG_WARNING("run " << run << " not found - no temperature correction");
return base_temperature;
}
LArTemperatureCorrectionTool::AllValues LArTemperatureCorrectionTool::get_corrections(int run) const
LArTemperatureCorrectionTool::AllValues
LArTemperatureCorrectionTool::get_corrections(int run) const
{
const auto it = m_cache.find(run);
if (it != m_cache.end()) { return it->second; }
else {
if (it != m_cache.end()) {
return it->second;
} else {
AllValues corrections{};
if (run < m_first_run) {
ATH_MSG_WARNING("run " << run << " is before the first run - using the first run");
corrections = search_correction(m_first_run);
}
else if (run > m_last_run) {
} else if (run > m_last_run) {
ATH_MSG_WARNING("run " << run << " is after the last run - using the last run");
corrections = search_correction(m_last_run);
}
else {
} else {
corrections = search_correction(run);
}
m_cache[run] = corrections;
Loading