1717#include " Framework/CallbackService.h"
1818#include " FairMQLogger.h"
1919#include " Framework/SerializationMethods.h"
20- #include " DataFormatsMID/Cluster2D.h "
20+ #include < boost/serialization/access.hpp >
2121
2222using namespace o2 ::framework;
2323using DataHeader = o2::header::DataHeader;
2424
25+ // / Dummy boost-serializable struct to perform some tests
26+ class Foo
27+ {
28+ public:
29+ int fBar1 ;
30+ double fBar2 [2 ];
31+ std::vector<float > fBar3 ;
32+ std::string fBar4 ;
33+
34+ Foo ()
35+ {
36+ fBar1 = 1 ;
37+ fBar2 [0 ] = 2.1 ;
38+ fBar2 [1 ] = 2.2 ;
39+ fBar3 = { 3.1 , 3.2 , 3.3 };
40+ fBar4 = " This is FooBar!" ;
41+ };
42+ Foo (int bar1, double bar21, double bar22, std::vector<float >& bar3, std::string& bar4) : fBar1 (bar1),
43+ fBar4 (bar4),
44+ fBar3(bar3)
45+ {
46+ fBar2 [0 ] = bar21;
47+ fBar2 [1 ] = bar22;
48+ };
49+
50+ friend class boost ::serialization::access;
51+
52+ // / Serializes the struct
53+ template <class Archive >
54+ void serialize (Archive& ar, const unsigned int version)
55+ {
56+ ar& fBar1 ;
57+ ar& fBar2 ;
58+ ar& fBar3 ;
59+ ar& fBar4 ;
60+ }
61+ };
62+
2563// / Example of how to send around strings using DPL.
2664WorkflowSpec defineDataProcessing (ConfigContext const &)
2765{
@@ -34,13 +72,15 @@ WorkflowSpec defineDataProcessing(ConfigContext const&)
3472 OutputSpec{ { " make" }, " TES" , " BOOST" }, //
3573 },
3674 AlgorithmSpec{ [](ProcessingContext& ctx) {
37- auto & out1 = ctx.outputs ().make <BoostSerialized<std::vector<o2::mid::Cluster2D >>>({ " TES" , " BOOST" });
75+ auto & out1 = ctx.outputs ().make <BoostSerialized<std::vector<Foo >>>({ " TES" , " BOOST" });
3876 // auto& out1 = ctx.outputs().make_boost<std::array<int,6>>({ "TES", "BOOST" });
3977 // auto& out1 = ctx.outputs().make<BoostSerialized<std::array<int,6>>>({ "TES", "BOOST" });
4078 // auto& out1 = ctx.outputs().make<std::array<int,6>>({ "TES", "BOOST" });
4179 for (size_t i = 0 ; i < 17 ; i++) {
4280 float iFloat = (float )i;
43- out1.emplace_back (o2::mid::Cluster2D{ (uint8_t )i, 0 .3f * iFloat, 0 .5f * iFloat, 0 .7f / iFloat, 0 .9f / iFloat });
81+ std::vector<float > floatVect = { iFloat * 3 .f , iFloat * 3 .1f , iFloat * 3 .2f };
82+ std::string string = " This is Foo!" ;
83+ out1.emplace_back (Foo{ (int )i, 2 . * iFloat, 2.1 * iFloat, floatVect, string });
4484 }
4585 } } //
4686 }, //
@@ -54,20 +94,26 @@ WorkflowSpec defineDataProcessing(ConfigContext const&)
5494 [](ProcessingContext& ctx) {
5595 LOG (INFO) << " Buffer ready to receive" ;
5696
57- auto in = ctx.inputs ().get <BoostSerialized<std::vector<o2::mid::Cluster2D >>>(" make" );
58- std::vector<o2::mid::Cluster2D > check;
97+ auto in = ctx.inputs ().get <BoostSerialized<std::vector<Foo >>>(" make" );
98+ std::vector<Foo > check;
5999 for (size_t i = 0 ; i < 17 ; i++) {
60100 float iFloat = (float )i;
61- check.emplace_back (o2::mid::Cluster2D{ (uint8_t )i, 0 .3f * iFloat, 0 .5f * iFloat, 0 .7f / iFloat, 0 .9f / iFloat });
101+ std::vector<float > floatVect = { iFloat * 3 .f , iFloat * 3 .1f , iFloat * 3 .2f };
102+ std::string string = " This is Foo!" ;
103+ check.emplace_back (Foo{ (int )i, 2 . * iFloat, 2.1 * iFloat, floatVect, string });
62104 }
63105
64106 size_t i = 0 ;
65107 for (auto const & test : in) {
66- assert ((test.deId == check[i].deId )); // deId Wrong
67- assert ((test.xCoor == check[i].xCoor )); // xCoor Wrong
68- assert ((test.yCoor == check[i].yCoor )); // yCoor Wrong
69- assert ((test.sigmaX2 == check[i].sigmaX2 )); // sigmaX2 Wrong
70- assert ((test.sigmaY2 == check[i].sigmaY2 )); // sigmaY2 Wrong
108+ assert ((test.fBar1 == check[i].fBar1 )); // fBar1 wrong
109+ assert ((test.fBar2 [0 ] == check[i].fBar2 [0 ])); // fBar2[0] wrong
110+ assert ((test.fBar2 [1 ] == check[i].fBar2 [1 ])); // fBar2[1] wrong
111+ size_t j = 0 ;
112+ for (auto const & fBar3It : test.fBar3 ) {
113+ assert ((fBar3It == check[i].fBar3 [j])); // fBar3[j] wrong
114+ j++;
115+ }
116+ assert ((test.fBar4 == check[i].fBar4 )); // fBar4 wrong
71117 i++;
72118 }
73119 ctx.services ().get <ControlService>().readyToQuit (true );
0 commit comments