Skip to content

Commit fa48f59

Browse files
Laura Serksnytewiechula
authored andcommitted
Update utility for timestamp extraction to optimize it + switches for IDC task what to plot
1 parent 779dda4 commit fa48f59

4 files changed

Lines changed: 126 additions & 57 deletions

File tree

Modules/TPC/include/TPC/IDCs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ class IDCs : public quality_control::postprocessing::PostProcessingInterface
7373
o2::ccdb::CcdbApi mCdbApi;
7474
std::string mHost;
7575
bool mDoIDCDelta = false;
76+
bool mDoIDC1 = false;
77+
bool mDoFourier = false;
7678
std::unique_ptr<TCanvas> mIDCZeroScale;
7779
std::unique_ptr<TCanvas> mIDCZerOverview;
7880
std::unique_ptr<TCanvas> mIDCZeroSides;

Modules/TPC/include/TPC/Utility.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030

3131
namespace o2::quality_control_modules::tpc
3232
{
33+
/// \brief Get boolean configurable from json file
34+
/// 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)
35+
/// \param config ConfigurationInterface with prefix set to ""
36+
/// \param id Task id
37+
/// \param property Property name to be looked for in json
38+
bool getPropertyBool(const boost::property_tree::ptree& config, const std::string& id, const std::string property);
3339

3440
/// \brief Prepare canvases to publish DalPad data
3541
/// This function creates canvases for CalPad data and registers them to be published on the QCG.

Modules/TPC/src/IDCs.cxx

Lines changed: 87 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -111,21 +111,9 @@ void IDCs::configure(const boost::property_tree::ptree& config)
111111

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

114-
boost::optional<const boost::property_tree::ptree&> doDeltaExists = config.get_child_optional("qc.postprocessing." + id + ".doIDCDelta");
115-
if (doDeltaExists) {
116-
auto doDelta = config.get<std::string>("qc.postprocessing." + id + ".doIDCDelta");
117-
if (doDelta == "1" || doDelta == "true" || doDelta == "True" || doDelta == "TRUE" || doDelta == "yes") {
118-
mDoIDCDelta = true;
119-
} else if (doDelta == "0" || doDelta == "false" || doDelta == "False" || doDelta == "FALSE" || doDelta == "no") {
120-
mDoIDCDelta = false;
121-
} else {
122-
mDoIDCDelta = false;
123-
ILOG(Warning, Support) << "No valid input for 'doIDCDelta'. Using default value 'false'." << ENDM;
124-
}
125-
} else {
126-
mDoIDCDelta = false;
127-
ILOG(Warning, Support) << "Option 'doIDCDelta' is missing. Using default value 'false'." << ENDM;
128-
}
114+
mDoIDCDelta = getPropertyBool(config, id, "doIDCDelta");
115+
mDoIDC1 = getPropertyBool(config, id, "doIDC1");
116+
mDoFourier = getPropertyBool(config, id, "doFourier");
129117
}
130118

131119
void IDCs::initialize(Trigger, framework::ServiceRegistryRef)
@@ -137,20 +125,18 @@ void IDCs::initialize(Trigger, framework::ServiceRegistryRef)
137125
mIDCZeroRadialProf.reset();
138126
mIDCZeroStacksA.reset();
139127
mIDCZeroStacksC.reset();
140-
mIDCOneSides1D.reset();
141-
mFourierCoeffsA.reset();
142-
mFourierCoeffsC.reset();
143128

144129
mIDCZeroScale = std::make_unique<TCanvas>("c_sides_IDC0_scale");
145130
mIDCZerOverview = std::make_unique<TCanvas>("c_sides_IDC0_overview");
146131
mIDCZeroRadialProf = std::make_unique<TCanvas>("c_sides_IDC0_radialProfile");
147132
mIDCZeroStacksA = std::make_unique<TCanvas>("c_GEMStacks_IDC0_1D_ASide");
148133
mIDCZeroStacksC = std::make_unique<TCanvas>("c_GEMStacks_IDC0_1D_CSide");
149134

150-
mIDCOneSides1D = std::make_unique<TCanvas>("c_sides_IDC1_1D");
151-
152-
mFourierCoeffsA = std::make_unique<TCanvas>("c_FourierCoefficients_1D_ASide");
153-
mFourierCoeffsC = std::make_unique<TCanvas>("c_FourierCoefficients_1D_CSide");
135+
getObjectsManager()->startPublishing(mIDCZeroScale.get());
136+
getObjectsManager()->startPublishing(mIDCZerOverview.get());
137+
getObjectsManager()->startPublishing(mIDCZeroRadialProf.get());
138+
getObjectsManager()->startPublishing(mIDCZeroStacksA.get());
139+
getObjectsManager()->startPublishing(mIDCZeroStacksC.get());
154140

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

164-
getObjectsManager()->startPublishing(mIDCZeroScale.get());
165-
getObjectsManager()->startPublishing(mIDCZerOverview.get());
166-
getObjectsManager()->startPublishing(mIDCZeroRadialProf.get());
167-
getObjectsManager()->startPublishing(mIDCZeroStacksA.get());
168-
getObjectsManager()->startPublishing(mIDCZeroStacksC.get());
169-
170-
getObjectsManager()->startPublishing(mIDCOneSides1D.get());
150+
if (mDoIDC1) {
151+
mIDCOneSides1D.reset();
152+
mIDCOneSides1D = std::make_unique<TCanvas>("c_sides_IDC1_1D");
153+
getObjectsManager()->startPublishing(mIDCOneSides1D.get());
154+
}
171155

172-
getObjectsManager()->startPublishing(mFourierCoeffsA.get());
173-
getObjectsManager()->startPublishing(mFourierCoeffsC.get());
156+
if (mDoFourier) {
157+
mFourierCoeffsA.reset();
158+
mFourierCoeffsC.reset();
159+
mFourierCoeffsA = std::make_unique<TCanvas>("c_FourierCoefficients_1D_ASide");
160+
mFourierCoeffsC = std::make_unique<TCanvas>("c_FourierCoefficients_1D_CSide");
161+
getObjectsManager()->startPublishing(mFourierCoeffsA.get());
162+
getObjectsManager()->startPublishing(mFourierCoeffsC.get());
163+
}
174164
}
175165

176166
void IDCs::update(Trigger, framework::ServiceRegistryRef)
177167
{
178168
std::vector<long> availableTimestampsIDCZeroA = getDataTimestamps(mCdbApi, CDBTypeMap.at(CDBType::CalIDC0A), 1, mTimestamps["IDCZero"]);
179169
std::vector<long> availableTimestampsIDCZeroC = getDataTimestamps(mCdbApi, CDBTypeMap.at(CDBType::CalIDC0C), 1, mTimestamps["IDCZero"]);
180-
std::vector<long> availableTimestampsIDCOneA = getDataTimestamps(mCdbApi, CDBTypeMap.at(CDBType::CalIDC1A), 1, mTimestamps["IDCOne"]);
181-
std::vector<long> availableTimestampsIDCOneC = getDataTimestamps(mCdbApi, CDBTypeMap.at(CDBType::CalIDC1C), 1, mTimestamps["IDCOne"]);
182-
std::vector<long> availableTimestampsFFTA = getDataTimestamps(mCdbApi, CDBTypeMap.at(CDBType::CalIDCFourierA), 1, mTimestamps["FourierCoeffs"]);
183-
std::vector<long> availableTimestampsFFTC = getDataTimestamps(mCdbApi, CDBTypeMap.at(CDBType::CalIDCFourierC), 1, mTimestamps["FourierCoeffs"]);
184170
std::vector<long> availableTimestampsIDCDeltaA{ 0 };
185171
std::vector<long> availableTimestampsIDCDeltaC{ 0 };
172+
std::vector<long> availableTimestampsIDCOneA{ 0 };
173+
std::vector<long> availableTimestampsIDCOneC{ 0 };
174+
std::vector<long> availableTimestampsFFTA{ 0 };
175+
std::vector<long> availableTimestampsFFTC{ 0 };
176+
bool timestampFoundForIDCZero = false;
177+
if (availableTimestampsIDCZeroA.size() == 0 || availableTimestampsIDCZeroC.size() == 0) {
178+
ILOG(Warning, Support) << fmt::format("No timstemp found for '{}' produced in the last day.", "IDCZero") << ENDM;
179+
} else {
180+
timestampFoundForIDCZero = true;
181+
}
186182

183+
bool timestampFoundForIDCDelta = false;
187184
if (mDoIDCDelta) {
188185
availableTimestampsIDCDeltaA = getDataTimestamps(mCdbApi, CDBTypeMap.at(CDBType::CalIDCDeltaA), 1, mTimestamps["IDCDelta"]);
189186
availableTimestampsIDCDeltaC = getDataTimestamps(mCdbApi, CDBTypeMap.at(CDBType::CalIDCDeltaC), 1, mTimestamps["IDCDelta"]);
187+
if (availableTimestampsIDCDeltaA.size() == 0 || availableTimestampsIDCDeltaC.size() == 0) {
188+
ILOG(Warning, Support) << fmt::format("No timstemp found for '{}' produced in the last day.", "IDCDelta") << ENDM;
189+
} else {
190+
timestampFoundForIDCDelta = true;
191+
}
192+
mIDCDeltaStacksA.get()->Clear();
193+
mIDCDeltaStacksC.get()->Clear();
194+
}
195+
196+
bool timestampFoundForIDCOne = false;
197+
if (mDoIDC1) {
198+
availableTimestampsIDCOneA = getDataTimestamps(mCdbApi, CDBTypeMap.at(CDBType::CalIDC1A), 1, mTimestamps["IDCOne"]);
199+
availableTimestampsIDCOneC = getDataTimestamps(mCdbApi, CDBTypeMap.at(CDBType::CalIDC1C), 1, mTimestamps["IDCOne"]);
200+
if (availableTimestampsIDCOneA.size() == 0 || availableTimestampsIDCOneC.size() == 0) {
201+
ILOG(Warning, Support) << fmt::format("No timstemp found for '{}' produced in the last day.", "IDCOne") << ENDM;
202+
} else {
203+
timestampFoundForIDCOne = true;
204+
}
205+
mIDCOneSides1D.get()->Clear();
206+
}
207+
208+
bool timestampFoundForFourier = false;
209+
if (mDoFourier) {
210+
availableTimestampsFFTA = getDataTimestamps(mCdbApi, CDBTypeMap.at(CDBType::CalIDCFourierA), 1, mTimestamps["FourierCoeffs"]);
211+
availableTimestampsFFTC = getDataTimestamps(mCdbApi, CDBTypeMap.at(CDBType::CalIDCFourierC), 1, mTimestamps["FourierCoeffs"]);
212+
if (availableTimestampsFFTA.size() == 0 || availableTimestampsFFTC.size() == 0) {
213+
ILOG(Warning, Support) << fmt::format("No timstemp found for '{}' produced in the last day.", "FourierCoeffs") << ENDM;
214+
} else {
215+
timestampFoundForFourier = true;
216+
}
217+
mFourierCoeffsA.get()->Clear();
218+
mFourierCoeffsC.get()->Clear();
190219
}
191220

192221
mIDCZeroScale.get()->Clear();
193222
mIDCZerOverview.get()->Clear();
194223
mIDCZeroRadialProf.get()->Clear();
195224
mIDCZeroStacksA.get()->Clear();
196225
mIDCZeroStacksC.get()->Clear();
197-
mIDCOneSides1D.get()->Clear();
198-
mFourierCoeffsA.get()->Clear();
199-
mFourierCoeffsC.get()->Clear();
200-
201-
if (mDoIDCDelta) {
202-
mIDCDeltaStacksA.get()->Clear();
203-
mIDCDeltaStacksC.get()->Clear();
204-
}
205226

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

215-
idcZeroA = mCdbApi.retrieveFromTFileAny<IDCZero>(CDBTypeMap.at(CDBType::CalIDC0A), std::map<std::string, std::string>{}, availableTimestampsIDCZeroA[0]);
216-
idcZeroC = mCdbApi.retrieveFromTFileAny<IDCZero>(CDBTypeMap.at(CDBType::CalIDC0C), std::map<std::string, std::string>{}, availableTimestampsIDCZeroC[0]);
217-
if (mDoIDCDelta) {
236+
if (timestampFoundForIDCZero) {
237+
idcZeroA = mCdbApi.retrieveFromTFileAny<IDCZero>(CDBTypeMap.at(CDBType::CalIDC0A), std::map<std::string, std::string>{}, availableTimestampsIDCZeroA[0]);
238+
idcZeroC = mCdbApi.retrieveFromTFileAny<IDCZero>(CDBTypeMap.at(CDBType::CalIDC0C), std::map<std::string, std::string>{}, availableTimestampsIDCZeroC[0]);
239+
}
240+
241+
if (mDoIDCDelta && timestampFoundForIDCDelta) {
218242
idcDeltaA = mCdbApi.retrieveFromTFileAny<IDCDelta<unsigned char>>(CDBTypeMap.at(CDBType::CalIDCDeltaA), std::map<std::string, std::string>{}, availableTimestampsIDCDeltaA[0]);
219243
idcDeltaC = mCdbApi.retrieveFromTFileAny<IDCDelta<unsigned char>>(CDBTypeMap.at(CDBType::CalIDCDeltaC), std::map<std::string, std::string>{}, availableTimestampsIDCDeltaC[0]);
220244
}
221-
idcOneA = mCdbApi.retrieveFromTFileAny<IDCOne>(CDBTypeMap.at(CDBType::CalIDC1A), std::map<std::string, std::string>{}, availableTimestampsIDCOneA[0]);
222-
idcOneC = mCdbApi.retrieveFromTFileAny<IDCOne>(CDBTypeMap.at(CDBType::CalIDC1C), std::map<std::string, std::string>{}, availableTimestampsIDCOneC[0]);
223-
idcFFTA = mCdbApi.retrieveFromTFileAny<FourierCoeff>(CDBTypeMap.at(CDBType::CalIDCFourierA), std::map<std::string, std::string>{}, availableTimestampsFFTA[0]);
224-
idcFFTC = mCdbApi.retrieveFromTFileAny<FourierCoeff>(CDBTypeMap.at(CDBType::CalIDCFourierC), std::map<std::string, std::string>{}, availableTimestampsFFTC[0]);
245+
if (mDoIDC1 && timestampFoundForIDCOne) {
246+
idcOneA = mCdbApi.retrieveFromTFileAny<IDCOne>(CDBTypeMap.at(CDBType::CalIDC1A), std::map<std::string, std::string>{}, availableTimestampsIDCOneA[0]);
247+
idcOneC = mCdbApi.retrieveFromTFileAny<IDCOne>(CDBTypeMap.at(CDBType::CalIDC1C), std::map<std::string, std::string>{}, availableTimestampsIDCOneC[0]);
248+
}
249+
250+
if (mDoFourier && timestampFoundForFourier) {
251+
idcFFTA = mCdbApi.retrieveFromTFileAny<FourierCoeff>(CDBTypeMap.at(CDBType::CalIDCFourierA), std::map<std::string, std::string>{}, availableTimestampsFFTA[0]);
252+
idcFFTC = mCdbApi.retrieveFromTFileAny<FourierCoeff>(CDBTypeMap.at(CDBType::CalIDCFourierC), std::map<std::string, std::string>{}, availableTimestampsFFTC[0]);
253+
}
225254

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

293-
getObjectsManager()->stopPublishing(mIDCOneSides1D.get());
322+
if (mDoIDC1) {
323+
getObjectsManager()->stopPublishing(mIDCOneSides1D.get());
324+
}
294325

295-
getObjectsManager()->stopPublishing(mFourierCoeffsA.get());
296-
getObjectsManager()->stopPublishing(mFourierCoeffsC.get());
326+
if (mDoFourier) {
327+
getObjectsManager()->stopPublishing(mFourierCoeffsA.get());
328+
getObjectsManager()->stopPublishing(mFourierCoeffsC.get());
329+
}
297330

298331
if (mDoIDCDelta) {
299332
getObjectsManager()->stopPublishing(mIDCDeltaStacksA.get());
300333
getObjectsManager()->stopPublishing(mIDCDeltaStacksC.get());
301334
}
302335
}
303336

304-
} // namespace o2::quality_control_modules::tpc
337+
} // namespace o2::quality_control_modules::tpc

Modules/TPC/src/Utility.cxx

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,30 @@
3131
#include <Framework/Logger.h>
3232
#include <bitset>
3333
#include <algorithm>
34+
#include <boost/property_tree/ptree.hpp>
3435

3536
namespace o2::quality_control_modules::tpc
3637
{
3738

39+
bool getPropertyBool(const boost::property_tree::ptree& config, const std::string& id, const std::string property)
40+
{
41+
const auto propertyFullName = fmt::format("qc.postprocessing.{}.{}", id, property);
42+
const boost::optional<const boost::property_tree::ptree&> propertyExists = config.get_child_optional(propertyFullName);
43+
if (propertyExists) {
44+
const auto doProperty = config.get<std::string>(propertyFullName);
45+
if (doProperty == "1" || doProperty == "true" || doProperty == "True" || doProperty == "TRUE" || doProperty == "yes") {
46+
return true;
47+
} else if (doProperty == "0" || doProperty == "false" || doProperty == "False" || doProperty == "FALSE" || doProperty == "no") {
48+
return false;
49+
} else {
50+
ILOG(Warning, Support) << fmt::format("No valid input for '{}'. Using default value 'false'.", property) << ENDM;
51+
}
52+
} else {
53+
ILOG(Warning, Support) << fmt::format("Option '{}' is missing. Using default value 'false'.", property) << ENDM;
54+
}
55+
return false;
56+
}
57+
3858
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)
3959
{
4060
for (const auto& canvName : canvNames) {
@@ -174,17 +194,25 @@ std::vector<long> getDataTimestamps(const o2::ccdb::CcdbApi& cdbApi, const std::
174194
{
175195
std::vector<long> outVec{};
176196
std::vector<long> tmpVec{};
177-
178-
std::vector<std::string> fileList = o2::utils::Str::tokenize(cdbApi.list(path.data()), '\n');
197+
std::vector<long> tmpVec2{};
179198

180199
if (limit == -1) {
200+
201+
// get the list of files for the latest timestamps up to 1 day ago from the moment the code is running
202+
// added some seconds to upper timestamp limit as the ccdbapi uses creation timestamp, not validity!
203+
const auto to = std::chrono::duration_cast<std::chrono::milliseconds>((std::chrono::system_clock::now() + std::chrono::minutes(1)).time_since_epoch()).count();
204+
const auto from = std::chrono::duration_cast<std::chrono::milliseconds>((std::chrono::system_clock::now() + std::chrono::weeks(-2)).time_since_epoch()).count();
205+
std::vector<std::string> fileList = o2::utils::Str::tokenize(cdbApi.list(path.data(), false, "text/plain", to, from), '\n');
181206
for (const auto& metaData : fileList) {
182207
getTimestamp(metaData, outVec);
183208
if (outVec.size() == nFiles) {
184209
break;
185210
}
186211
}
187212
} else {
213+
// get file list for requested timestamp minus three days
214+
// added some seconds to upper timestamp limit as the ccdbapi uses creation timestamp, not validity!
215+
std::vector<std::string> fileList = o2::utils::Str::tokenize(cdbApi.list(path.data(), false, "text/plain", limit + 600000, limit - 86400000), '\n');
188216
for (const auto& metaData : fileList) {
189217
if (outVec.size() < nFiles) {
190218
getTimestamp(metaData, tmpVec);
@@ -313,4 +341,4 @@ void retrieveStatistics(std::vector<double>& values, std::vector<double>& errors
313341
}
314342
}
315343

316-
} // namespace o2::quality_control_modules::tpc
344+
} // namespace o2::quality_control_modules::tpc

0 commit comments

Comments
 (0)