1717#include " DPLUtils/RawParser.h"
1818#include " Headers/DataHeader.h"
1919#include < vector>
20+ #include < sstream>
2021
2122using namespace o2 ::framework;
2223
@@ -32,38 +33,48 @@ void customize(std::vector<ConfigParamSpec>& workflowOptions)
3233
3334WorkflowSpec 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