Skip to content

Commit

Permalink
Update utility for timestamp extraction to optimize it + switches for…
Browse files Browse the repository at this point in the history
… IDC task what to plot
  • Loading branch information
Laura Serksnyte authored and wiechula committed Sep 26, 2024
1 parent 779dda4 commit fa48f59
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 57 deletions.
2 changes: 2 additions & 0 deletions Modules/TPC/include/TPC/IDCs.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class IDCs : public quality_control::postprocessing::PostProcessingInterface
o2::ccdb::CcdbApi mCdbApi;
std::string mHost;
bool mDoIDCDelta = false;
bool mDoIDC1 = false;
bool mDoFourier = false;
std::unique_ptr<TCanvas> mIDCZeroScale;
std::unique_ptr<TCanvas> mIDCZerOverview;
std::unique_ptr<TCanvas> mIDCZeroSides;
Expand Down
6 changes: 6 additions & 0 deletions Modules/TPC/include/TPC/Utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@

namespace o2::quality_control_modules::tpc
{
/// \brief Get boolean configurable from json file
/// This function checks if a configurable is available in the json file and makes sure that different versions of it are accepted (true, TRUE, 1, etc)
/// \param config ConfigurationInterface with prefix set to ""
/// \param id Task id
/// \param property Property name to be looked for in json
bool getPropertyBool(const boost::property_tree::ptree& config, const std::string& id, const std::string property);

/// \brief Prepare canvases to publish DalPad data
/// This function creates canvases for CalPad data and registers them to be published on the QCG.
Expand Down
141 changes: 87 additions & 54 deletions Modules/TPC/src/IDCs.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,9 @@ void IDCs::configure(const boost::property_tree::ptree& config)

mHost = config.get<std::string>("qc.postprocessing." + id + ".dataSourceURL");

boost::optional<const boost::property_tree::ptree&> doDeltaExists = config.get_child_optional("qc.postprocessing." + id + ".doIDCDelta");
if (doDeltaExists) {
auto doDelta = config.get<std::string>("qc.postprocessing." + id + ".doIDCDelta");
if (doDelta == "1" || doDelta == "true" || doDelta == "True" || doDelta == "TRUE" || doDelta == "yes") {
mDoIDCDelta = true;
} else if (doDelta == "0" || doDelta == "false" || doDelta == "False" || doDelta == "FALSE" || doDelta == "no") {
mDoIDCDelta = false;
} else {
mDoIDCDelta = false;
ILOG(Warning, Support) << "No valid input for 'doIDCDelta'. Using default value 'false'." << ENDM;
}
} else {
mDoIDCDelta = false;
ILOG(Warning, Support) << "Option 'doIDCDelta' is missing. Using default value 'false'." << ENDM;
}
mDoIDCDelta = getPropertyBool(config, id, "doIDCDelta");
mDoIDC1 = getPropertyBool(config, id, "doIDC1");
mDoFourier = getPropertyBool(config, id, "doFourier");
}

void IDCs::initialize(Trigger, framework::ServiceRegistryRef)
Expand All @@ -137,20 +125,18 @@ void IDCs::initialize(Trigger, framework::ServiceRegistryRef)
mIDCZeroRadialProf.reset();
mIDCZeroStacksA.reset();
mIDCZeroStacksC.reset();
mIDCOneSides1D.reset();
mFourierCoeffsA.reset();
mFourierCoeffsC.reset();

mIDCZeroScale = std::make_unique<TCanvas>("c_sides_IDC0_scale");
mIDCZerOverview = std::make_unique<TCanvas>("c_sides_IDC0_overview");
mIDCZeroRadialProf = std::make_unique<TCanvas>("c_sides_IDC0_radialProfile");
mIDCZeroStacksA = std::make_unique<TCanvas>("c_GEMStacks_IDC0_1D_ASide");
mIDCZeroStacksC = std::make_unique<TCanvas>("c_GEMStacks_IDC0_1D_CSide");

mIDCOneSides1D = std::make_unique<TCanvas>("c_sides_IDC1_1D");

mFourierCoeffsA = std::make_unique<TCanvas>("c_FourierCoefficients_1D_ASide");
mFourierCoeffsC = std::make_unique<TCanvas>("c_FourierCoefficients_1D_CSide");
getObjectsManager()->startPublishing(mIDCZeroScale.get());
getObjectsManager()->startPublishing(mIDCZerOverview.get());
getObjectsManager()->startPublishing(mIDCZeroRadialProf.get());
getObjectsManager()->startPublishing(mIDCZeroStacksA.get());
getObjectsManager()->startPublishing(mIDCZeroStacksC.get());

if (mDoIDCDelta) {
mIDCDeltaStacksA.reset();
Expand All @@ -161,47 +147,82 @@ void IDCs::initialize(Trigger, framework::ServiceRegistryRef)
getObjectsManager()->startPublishing(mIDCDeltaStacksC.get());
}

getObjectsManager()->startPublishing(mIDCZeroScale.get());
getObjectsManager()->startPublishing(mIDCZerOverview.get());
getObjectsManager()->startPublishing(mIDCZeroRadialProf.get());
getObjectsManager()->startPublishing(mIDCZeroStacksA.get());
getObjectsManager()->startPublishing(mIDCZeroStacksC.get());

getObjectsManager()->startPublishing(mIDCOneSides1D.get());
if (mDoIDC1) {
mIDCOneSides1D.reset();
mIDCOneSides1D = std::make_unique<TCanvas>("c_sides_IDC1_1D");
getObjectsManager()->startPublishing(mIDCOneSides1D.get());
}

getObjectsManager()->startPublishing(mFourierCoeffsA.get());
getObjectsManager()->startPublishing(mFourierCoeffsC.get());
if (mDoFourier) {
mFourierCoeffsA.reset();
mFourierCoeffsC.reset();
mFourierCoeffsA = std::make_unique<TCanvas>("c_FourierCoefficients_1D_ASide");
mFourierCoeffsC = std::make_unique<TCanvas>("c_FourierCoefficients_1D_CSide");
getObjectsManager()->startPublishing(mFourierCoeffsA.get());
getObjectsManager()->startPublishing(mFourierCoeffsC.get());
}
}

void IDCs::update(Trigger, framework::ServiceRegistryRef)
{
std::vector<long> availableTimestampsIDCZeroA = getDataTimestamps(mCdbApi, CDBTypeMap.at(CDBType::CalIDC0A), 1, mTimestamps["IDCZero"]);
std::vector<long> availableTimestampsIDCZeroC = getDataTimestamps(mCdbApi, CDBTypeMap.at(CDBType::CalIDC0C), 1, mTimestamps["IDCZero"]);
std::vector<long> availableTimestampsIDCOneA = getDataTimestamps(mCdbApi, CDBTypeMap.at(CDBType::CalIDC1A), 1, mTimestamps["IDCOne"]);
std::vector<long> availableTimestampsIDCOneC = getDataTimestamps(mCdbApi, CDBTypeMap.at(CDBType::CalIDC1C), 1, mTimestamps["IDCOne"]);
std::vector<long> availableTimestampsFFTA = getDataTimestamps(mCdbApi, CDBTypeMap.at(CDBType::CalIDCFourierA), 1, mTimestamps["FourierCoeffs"]);
std::vector<long> availableTimestampsFFTC = getDataTimestamps(mCdbApi, CDBTypeMap.at(CDBType::CalIDCFourierC), 1, mTimestamps["FourierCoeffs"]);
std::vector<long> availableTimestampsIDCDeltaA{ 0 };
std::vector<long> availableTimestampsIDCDeltaC{ 0 };
std::vector<long> availableTimestampsIDCOneA{ 0 };
std::vector<long> availableTimestampsIDCOneC{ 0 };
std::vector<long> availableTimestampsFFTA{ 0 };
std::vector<long> availableTimestampsFFTC{ 0 };
bool timestampFoundForIDCZero = false;
if (availableTimestampsIDCZeroA.size() == 0 || availableTimestampsIDCZeroC.size() == 0) {
ILOG(Warning, Support) << fmt::format("No timstemp found for '{}' produced in the last day.", "IDCZero") << ENDM;
} else {
timestampFoundForIDCZero = true;
}

bool timestampFoundForIDCDelta = false;
if (mDoIDCDelta) {
availableTimestampsIDCDeltaA = getDataTimestamps(mCdbApi, CDBTypeMap.at(CDBType::CalIDCDeltaA), 1, mTimestamps["IDCDelta"]);
availableTimestampsIDCDeltaC = getDataTimestamps(mCdbApi, CDBTypeMap.at(CDBType::CalIDCDeltaC), 1, mTimestamps["IDCDelta"]);
if (availableTimestampsIDCDeltaA.size() == 0 || availableTimestampsIDCDeltaC.size() == 0) {
ILOG(Warning, Support) << fmt::format("No timstemp found for '{}' produced in the last day.", "IDCDelta") << ENDM;
} else {
timestampFoundForIDCDelta = true;
}
mIDCDeltaStacksA.get()->Clear();
mIDCDeltaStacksC.get()->Clear();
}

bool timestampFoundForIDCOne = false;
if (mDoIDC1) {
availableTimestampsIDCOneA = getDataTimestamps(mCdbApi, CDBTypeMap.at(CDBType::CalIDC1A), 1, mTimestamps["IDCOne"]);
availableTimestampsIDCOneC = getDataTimestamps(mCdbApi, CDBTypeMap.at(CDBType::CalIDC1C), 1, mTimestamps["IDCOne"]);
if (availableTimestampsIDCOneA.size() == 0 || availableTimestampsIDCOneC.size() == 0) {
ILOG(Warning, Support) << fmt::format("No timstemp found for '{}' produced in the last day.", "IDCOne") << ENDM;
} else {
timestampFoundForIDCOne = true;
}
mIDCOneSides1D.get()->Clear();
}

bool timestampFoundForFourier = false;
if (mDoFourier) {
availableTimestampsFFTA = getDataTimestamps(mCdbApi, CDBTypeMap.at(CDBType::CalIDCFourierA), 1, mTimestamps["FourierCoeffs"]);
availableTimestampsFFTC = getDataTimestamps(mCdbApi, CDBTypeMap.at(CDBType::CalIDCFourierC), 1, mTimestamps["FourierCoeffs"]);
if (availableTimestampsFFTA.size() == 0 || availableTimestampsFFTC.size() == 0) {
ILOG(Warning, Support) << fmt::format("No timstemp found for '{}' produced in the last day.", "FourierCoeffs") << ENDM;
} else {
timestampFoundForFourier = true;
}
mFourierCoeffsA.get()->Clear();
mFourierCoeffsC.get()->Clear();
}

mIDCZeroScale.get()->Clear();
mIDCZerOverview.get()->Clear();
mIDCZeroRadialProf.get()->Clear();
mIDCZeroStacksA.get()->Clear();
mIDCZeroStacksC.get()->Clear();
mIDCOneSides1D.get()->Clear();
mFourierCoeffsA.get()->Clear();
mFourierCoeffsC.get()->Clear();

if (mDoIDCDelta) {
mIDCDeltaStacksA.get()->Clear();
mIDCDeltaStacksC.get()->Clear();
}

o2::tpc::IDCZero* idcZeroA = nullptr;
o2::tpc::IDCZero* idcZeroC = nullptr;
Expand All @@ -212,16 +233,24 @@ void IDCs::update(Trigger, framework::ServiceRegistryRef)
o2::tpc::FourierCoeff* idcFFTA = nullptr;
o2::tpc::FourierCoeff* idcFFTC = nullptr;

idcZeroA = mCdbApi.retrieveFromTFileAny<IDCZero>(CDBTypeMap.at(CDBType::CalIDC0A), std::map<std::string, std::string>{}, availableTimestampsIDCZeroA[0]);
idcZeroC = mCdbApi.retrieveFromTFileAny<IDCZero>(CDBTypeMap.at(CDBType::CalIDC0C), std::map<std::string, std::string>{}, availableTimestampsIDCZeroC[0]);
if (mDoIDCDelta) {
if (timestampFoundForIDCZero) {
idcZeroA = mCdbApi.retrieveFromTFileAny<IDCZero>(CDBTypeMap.at(CDBType::CalIDC0A), std::map<std::string, std::string>{}, availableTimestampsIDCZeroA[0]);
idcZeroC = mCdbApi.retrieveFromTFileAny<IDCZero>(CDBTypeMap.at(CDBType::CalIDC0C), std::map<std::string, std::string>{}, availableTimestampsIDCZeroC[0]);
}

if (mDoIDCDelta && timestampFoundForIDCDelta) {
idcDeltaA = mCdbApi.retrieveFromTFileAny<IDCDelta<unsigned char>>(CDBTypeMap.at(CDBType::CalIDCDeltaA), std::map<std::string, std::string>{}, availableTimestampsIDCDeltaA[0]);
idcDeltaC = mCdbApi.retrieveFromTFileAny<IDCDelta<unsigned char>>(CDBTypeMap.at(CDBType::CalIDCDeltaC), std::map<std::string, std::string>{}, availableTimestampsIDCDeltaC[0]);
}
idcOneA = mCdbApi.retrieveFromTFileAny<IDCOne>(CDBTypeMap.at(CDBType::CalIDC1A), std::map<std::string, std::string>{}, availableTimestampsIDCOneA[0]);
idcOneC = mCdbApi.retrieveFromTFileAny<IDCOne>(CDBTypeMap.at(CDBType::CalIDC1C), std::map<std::string, std::string>{}, availableTimestampsIDCOneC[0]);
idcFFTA = mCdbApi.retrieveFromTFileAny<FourierCoeff>(CDBTypeMap.at(CDBType::CalIDCFourierA), std::map<std::string, std::string>{}, availableTimestampsFFTA[0]);
idcFFTC = mCdbApi.retrieveFromTFileAny<FourierCoeff>(CDBTypeMap.at(CDBType::CalIDCFourierC), std::map<std::string, std::string>{}, availableTimestampsFFTC[0]);
if (mDoIDC1 && timestampFoundForIDCOne) {
idcOneA = mCdbApi.retrieveFromTFileAny<IDCOne>(CDBTypeMap.at(CDBType::CalIDC1A), std::map<std::string, std::string>{}, availableTimestampsIDCOneA[0]);
idcOneC = mCdbApi.retrieveFromTFileAny<IDCOne>(CDBTypeMap.at(CDBType::CalIDC1C), std::map<std::string, std::string>{}, availableTimestampsIDCOneC[0]);
}

if (mDoFourier && timestampFoundForFourier) {
idcFFTA = mCdbApi.retrieveFromTFileAny<FourierCoeff>(CDBTypeMap.at(CDBType::CalIDCFourierA), std::map<std::string, std::string>{}, availableTimestampsFFTA[0]);
idcFFTC = mCdbApi.retrieveFromTFileAny<FourierCoeff>(CDBTypeMap.at(CDBType::CalIDCFourierC), std::map<std::string, std::string>{}, availableTimestampsFFTC[0]);
}

if (idcZeroA && idcZeroC) {
mCCDBHelper.setIDCZero(idcZeroA, Side::A);
Expand Down Expand Up @@ -290,15 +319,19 @@ void IDCs::finalize(Trigger, framework::ServiceRegistryRef)
getObjectsManager()->stopPublishing(mIDCZeroStacksA.get());
getObjectsManager()->stopPublishing(mIDCZeroStacksC.get());

getObjectsManager()->stopPublishing(mIDCOneSides1D.get());
if (mDoIDC1) {
getObjectsManager()->stopPublishing(mIDCOneSides1D.get());
}

getObjectsManager()->stopPublishing(mFourierCoeffsA.get());
getObjectsManager()->stopPublishing(mFourierCoeffsC.get());
if (mDoFourier) {
getObjectsManager()->stopPublishing(mFourierCoeffsA.get());
getObjectsManager()->stopPublishing(mFourierCoeffsC.get());
}

if (mDoIDCDelta) {
getObjectsManager()->stopPublishing(mIDCDeltaStacksA.get());
getObjectsManager()->stopPublishing(mIDCDeltaStacksC.get());
}
}

} // namespace o2::quality_control_modules::tpc
} // namespace o2::quality_control_modules::tpc
34 changes: 31 additions & 3 deletions Modules/TPC/src/Utility.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,30 @@
#include <Framework/Logger.h>
#include <bitset>
#include <algorithm>
#include <boost/property_tree/ptree.hpp>

namespace o2::quality_control_modules::tpc
{

bool getPropertyBool(const boost::property_tree::ptree& config, const std::string& id, const std::string property)
{
const auto propertyFullName = fmt::format("qc.postprocessing.{}.{}", id, property);
const boost::optional<const boost::property_tree::ptree&> propertyExists = config.get_child_optional(propertyFullName);
if (propertyExists) {
const auto doProperty = config.get<std::string>(propertyFullName);
if (doProperty == "1" || doProperty == "true" || doProperty == "True" || doProperty == "TRUE" || doProperty == "yes") {
return true;
} else if (doProperty == "0" || doProperty == "false" || doProperty == "False" || doProperty == "FALSE" || doProperty == "no") {
return false;
} else {
ILOG(Warning, Support) << fmt::format("No valid input for '{}'. Using default value 'false'.", property) << ENDM;
}
} else {
ILOG(Warning, Support) << fmt::format("Option '{}' is missing. Using default value 'false'.", property) << ENDM;
}
return false;
}

void addAndPublish(std::shared_ptr<o2::quality_control::core::ObjectsManager> objectsManager, std::vector<std::unique_ptr<TCanvas>>& canVec, std::vector<std::string_view> canvNames, const std::map<std::string, std::string>& metaData)
{
for (const auto& canvName : canvNames) {
Expand Down Expand Up @@ -174,17 +194,25 @@ std::vector<long> getDataTimestamps(const o2::ccdb::CcdbApi& cdbApi, const std::
{
std::vector<long> outVec{};
std::vector<long> tmpVec{};

std::vector<std::string> fileList = o2::utils::Str::tokenize(cdbApi.list(path.data()), '\n');
std::vector<long> tmpVec2{};

if (limit == -1) {

// get the list of files for the latest timestamps up to 1 day ago from the moment the code is running
// added some seconds to upper timestamp limit as the ccdbapi uses creation timestamp, not validity!
const auto to = std::chrono::duration_cast<std::chrono::milliseconds>((std::chrono::system_clock::now() + std::chrono::minutes(1)).time_since_epoch()).count();
const auto from = std::chrono::duration_cast<std::chrono::milliseconds>((std::chrono::system_clock::now() + std::chrono::weeks(-2)).time_since_epoch()).count();
std::vector<std::string> fileList = o2::utils::Str::tokenize(cdbApi.list(path.data(), false, "text/plain", to, from), '\n');
for (const auto& metaData : fileList) {
getTimestamp(metaData, outVec);
if (outVec.size() == nFiles) {
break;
}
}
} else {
// get file list for requested timestamp minus three days
// added some seconds to upper timestamp limit as the ccdbapi uses creation timestamp, not validity!
std::vector<std::string> fileList = o2::utils::Str::tokenize(cdbApi.list(path.data(), false, "text/plain", limit + 600000, limit - 86400000), '\n');
for (const auto& metaData : fileList) {
if (outVec.size() < nFiles) {
getTimestamp(metaData, tmpVec);
Expand Down Expand Up @@ -313,4 +341,4 @@ void retrieveStatistics(std::vector<double>& values, std::vector<double>& errors
}
}

} // namespace o2::quality_control_modules::tpc
} // namespace o2::quality_control_modules::tpc

0 comments on commit fa48f59

Please sign in to comment.