Skip to content

Commit 13dd120

Browse files
committed
[QC-854] Add templating to the discard log file (#1449)
* [QC-854] Add templating to the discard log file * format * fix * remove redundant comment * remove include * remove include * fix * fpormat * Update runnerUtils.h * fix
1 parent 7df2097 commit 13dd120

8 files changed

Lines changed: 42 additions & 5 deletions

File tree

Framework/basic.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"infologger": { "": "Configuration of the Infologger (optional).",
2929
"filterDiscardDebug": "true", "": "Set to true to discard debug and trace messages (default: false)",
3030
"filterDiscardLevel": "11", "": "Message at this level or above are discarded (default: 21 - Trace)",
31-
"filterDiscardFile": "/tmp/test.txt", "": "If set, the discarded messages will go to this file (default: <none>)"
31+
"filterDiscardFile": "/tmp/_ID_-test.txt", "": "If set, the discarded messages will go to this file (default: <none>)",
32+
"" : "The keyword _ID_ is replaced by the device id."
3233
}
3334
},
3435
"tasks": {

Framework/include/QualityControl/TaskRunnerConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct TaskRunnerConfig {
4747
int resetAfterCycles = 0;
4848
bool infologgerFilterDiscardDebug = false;
4949
int infologgerDiscardLevel = 21;
50-
std::string infologgerDiscardFile = "";
50+
std::string infologgerDiscardFile{};
5151
Activity fallbackActivity;
5252
};
5353

Framework/include/QualityControl/runnerUtils.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121
#include <Configuration/ConfigurationFactory.h>
2222
#include <Common/Exceptions.h>
2323
#include <Framework/RawDeviceService.h>
24+
#include <Framework/DeviceSpec.h>
2425
#include <fairmq/Device.h>
2526
#include <Framework/ConfigParamRegistry.h>
2627
#include <QualityControl/QcInfoLogger.h>
2728
#include <boost/property_tree/json_parser.hpp>
2829
#include <CommonUtils/StringUtils.h>
2930
#include "QualityControl/Activity.h"
31+
#include <regex>
3032

3133
namespace o2::quality_control::core
3234
{
@@ -184,6 +186,23 @@ inline void overrideValues(boost::property_tree::ptree& tree, std::vector<std::p
184186
}
185187
}
186188

189+
/**
190+
* template the param infologgerDiscardFile (_ID_->[device-id])
191+
* @param originalFile
192+
* @param iCtx
193+
* @return
194+
*/
195+
inline std::string templateILDiscardFile(std::string& originalFile, framework::InitContext& iCtx)
196+
{
197+
try {
198+
auto& deviceSpec = iCtx.services().get<o2::framework::DeviceSpec const>();
199+
return std::regex_replace(originalFile, std::regex("_ID_"), deviceSpec.id);
200+
} catch (...) {
201+
ILOG(Error, Devel) << "exception caught and swallowed in templateILDiscardFile : " << boost::current_exception_diagnostic_information() << ENDM;
202+
}
203+
return originalFile;
204+
}
205+
187206
} // namespace o2::quality_control::core
188207

189208
#endif // QUALITYCONTROL_RUNNERUTILS_H

Framework/src/AggregatorRunner.cxx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ void AggregatorRunner::initAggregators()
299299

300300
void AggregatorRunner::initInfoLogger(InitContext& iCtx)
301301
{
302+
// TODO : the method should be merged with the other, similar, methods in *Runners
303+
302304
InfoLoggerContext* ilContext = nullptr;
303305
AliceO2::InfoLogger::InfoLogger* il = nullptr;
304306
try {
@@ -307,7 +309,14 @@ void AggregatorRunner::initInfoLogger(InitContext& iCtx)
307309
} catch (const RuntimeErrorRef& err) {
308310
ILOG(Error) << "Could not find the DPL InfoLogger." << ENDM;
309311
}
310-
QcInfoLogger::init("aggregator", mRunnerConfig.infologgerFilterDiscardDebug, mRunnerConfig.infologgerDiscardLevel, mRunnerConfig.infologgerDiscardFile, il, ilContext);
312+
313+
mRunnerConfig.infologgerDiscardFile = templateILDiscardFile(mRunnerConfig.infologgerDiscardFile, iCtx);
314+
QcInfoLogger::init("aggregator",
315+
mRunnerConfig.infologgerFilterDiscardDebug,
316+
mRunnerConfig.infologgerDiscardLevel,
317+
mRunnerConfig.infologgerDiscardFile,
318+
il,
319+
ilContext);
311320
}
312321

313322
void AggregatorRunner::initLibraries()

Framework/src/CheckRunner.cxx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,8 @@ void CheckRunner::initServiceDiscovery()
477477

478478
void CheckRunner::initInfologger(framework::InitContext& iCtx)
479479
{
480+
// TODO : the method should be merged with the other, similar, methods in *Runners
481+
480482
InfoLoggerContext* ilContext = nullptr;
481483
AliceO2::InfoLogger::InfoLogger* il = nullptr;
482484
try {
@@ -485,6 +487,8 @@ void CheckRunner::initInfologger(framework::InitContext& iCtx)
485487
} catch (const RuntimeErrorRef& err) {
486488
ILOG(Error) << "Could not find the DPL InfoLogger." << ENDM;
487489
}
490+
491+
mConfig.infologgerDiscardFile = templateILDiscardFile(mConfig.infologgerDiscardFile, iCtx);
488492
QcInfoLogger::init(createCheckRunnerFacility(mDeviceName),
489493
mConfig.infologgerFilterDiscardDebug,
490494
mConfig.infologgerDiscardLevel,

Framework/src/InfrastructureSpecReader.cxx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
#include <DataSampling/DataSampling.h>
2424
#include <Framework/DataDescriptorQueryBuilder.h>
25-
#include <boost/property_tree/ptree.hpp>
2625

2726
using namespace o2::utilities;
2827
using namespace o2::framework;

Framework/src/TaskRunner.cxx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ void TaskRunner::refreshConfig(InitContext& iCtx)
105105

106106
void TaskRunner::initInfologger(InitContext& iCtx)
107107
{
108+
// TODO : the method should be merged with the other, similar, methods in *Runners
109+
108110
AliceO2::InfoLogger::InfoLoggerContext* ilContext = nullptr;
109111
AliceO2::InfoLogger::InfoLogger* il = nullptr;
110112
try {
@@ -113,6 +115,8 @@ void TaskRunner::initInfologger(InitContext& iCtx)
113115
} catch (const RuntimeErrorRef& err) {
114116
ILOG(Error, Devel) << "Could not find the DPL InfoLogger" << ENDM;
115117
}
118+
119+
mTaskConfig.infologgerDiscardFile = templateILDiscardFile(mTaskConfig.infologgerDiscardFile, iCtx);
116120
QcInfoLogger::init("task/" + mTaskConfig.taskName,
117121
mTaskConfig.infologgerFilterDiscardDebug,
118122
mTaskConfig.infologgerDiscardLevel,

doc/Advanced.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,8 @@ should not be present in real configuration files.
900900
"infologger": { "": "Configuration of the Infologger (optional).",
901901
"filterDiscardDebug": "false", "": "Set to 1 to discard debug and trace messages (default: false)",
902902
"filterDiscardLevel": "2", "": "Message at this level or above are discarded (default: 21 - Trace)",
903-
"filterDiscardFile": "", "": "If set, the discarded messages will go to this file (default: <none>)"
903+
"filterDiscardFile": "", "": ["If set, the discarded messages will go to this file (default: <none>)",
904+
"The keyword _ID_, if used, is replaced by the device ID."]
904905
},
905906
"postprocessing": { "": "Configuration parameters for post-processing",
906907
"periodSeconds": 10.0, "": "Sets the interval of checking all the triggers. One can put a very small value",

0 commit comments

Comments
 (0)