Skip to content

Commit 1b63836

Browse files
Polishing rdh printout
1 parent fee8748 commit 1b63836

2 files changed

Lines changed: 38 additions & 27 deletions

File tree

Framework/Utils/include/DPLUtils/RawParser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ class RawParser
439439

440440
friend std::ostream& operator<<(std::ostream& os, self_type const& it)
441441
{
442-
std::visit([&os](auto& parser) { return parser.format(os); }, it.mParser);
442+
std::visit([&os](auto& parser) { return parser.format(os, raw_parser::FormatSpec::Entry, ""); }, it.mParser);
443443
return os;
444444
}
445445

Framework/Utils/src/raw-parser.cxx

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "DPLUtils/RawParser.h"
1818
#include "Headers/DataHeader.h"
1919
#include <vector>
20+
#include <sstream>
2021

2122
using namespace o2::framework;
2223

@@ -32,38 +33,48 @@ void customize(std::vector<ConfigParamSpec>& workflowOptions)
3233

3334
WorkflowSpec defineDataProcessing(ConfigContext const& config)
3435
{
35-
3636
WorkflowSpec workflow;
3737
workflow.emplace_back(DataProcessorSpec{
3838
"raw-parser",
3939
select(config.options().get<std::string>("input-spec").c_str()),
4040
Outputs{},
41-
AlgorithmSpec{[](InitContext& setup) { return adaptStateless([](InputRecord& inputs, DataAllocator& outputs) {
42-
for (auto& input : inputs) {
43-
const auto* dh = DataRefUtils::getHeader<o2::header::DataHeader*>(input);
44-
// InputSpec implements operator<< so we could print (input.spec) but that is the
45-
// matcher instead of the matched data
46-
LOG(INFO) << dh->dataOrigin.as<std::string>() << "/"
47-
<< dh->dataDescription.as<std::string>() << "/"
48-
<< dh->subSpecification << " payload size " << dh->payloadSize;
41+
AlgorithmSpec{[](InitContext& setup) {
42+
auto loglevel = setup.options().get<int>("log-level");
43+
return adaptStateless([loglevel](InputRecord& inputs, DataAllocator& outputs) {
44+
for (auto& input : inputs) {
45+
const auto* dh = DataRefUtils::getHeader<o2::header::DataHeader*>(input);
46+
if (loglevel > 0) {
47+
// InputSpec implements operator<< so we could print (input.spec) but that is the
48+
// matcher instead of the matched data
49+
LOG(INFO) << dh->dataOrigin.as<std::string>() << "/"
50+
<< dh->dataDescription.as<std::string>() << "/"
51+
<< dh->subSpecification << " payload size " << dh->payloadSize;
52+
}
53+
54+
// there is a bug in InpuRecord::get for vectors of simple types, not catched in
55+
// DataAllocator unit test
56+
//auto data = inputs.get<std::vector<char>>(input.spec->binding.c_str());
57+
//LOG(INFO) << "data size " << data.size();
4958

50-
// there is a bug in InpuRecord::get for vectors of simple types, not catched in
51-
// DataAllocator unit test
52-
//auto data = inputs.get<std::vector<char>>(input.spec->binding.c_str());
53-
//LOG(INFO) << "data size " << data.size();
54-
try {
55-
o2::framework::RawParser parser(input.payload, dh->payloadSize);
59+
try {
60+
o2::framework::RawParser parser(input.payload, dh->payloadSize);
5661

57-
LOG(INFO) << parser << std::endl;
58-
for (auto it = parser.begin(), end = parser.end(); it != end; ++it) {
59-
LOG(INFO) << it << ": block length " << it.length() << std::endl;
60-
}
61-
} catch (const std::runtime_error& e) {
62-
LOG(ERROR) << "can not create raw parser form input data";
63-
o2::header::hexDump("payload", input.payload, dh->payloadSize, 64);
64-
LOG(ERROR) << e.what();
65-
}
66-
}
67-
}); }}});
62+
std::stringstream rdhprintout;
63+
rdhprintout << parser;
64+
for (auto it = parser.begin(), end = parser.end(); it != end; ++it) {
65+
rdhprintout << it << ": block length " << it.length() << std::endl;
66+
}
67+
if (loglevel > 1) {
68+
LOG(INFO) << rdhprintout.str();
69+
}
70+
} catch (const std::runtime_error& e) {
71+
LOG(ERROR) << "can not create raw parser form input data";
72+
o2::header::hexDump("payload", input.payload, dh->payloadSize, 64);
73+
LOG(ERROR) << e.what();
74+
}
75+
}
76+
}); }},
77+
Options{
78+
{"log-level", VariantType::Int, 1, {"Logging level [0-2]"}}}});
6879
return workflow;
6980
}

0 commit comments

Comments
 (0)