Belle II Software light-2406-ragdoll
msghandler.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#include <framework/pcore/MsgHandler.h>
9
10#include <TVector3.h>
11#include <TClonesArray.h>
12#include <TNamed.h>
13
14#include <fstream>
15#include <gtest/gtest.h>
16
17using namespace std;
18using namespace Belle2;
19
20namespace {
21 TEST(MsgHandlerTest, conversion)
22 {
23 MsgHandler handler;
24 TVector3 a(1.0, 2.0, 3.0);
25 handler.add(&a, "vector");
26 TVector3 b(42.0, 7.0, -20.0);
27 handler.add(&b, "vectorb");
28 TNamed c("abc", "def");
29 handler.add(&c, "named");
30 EvtMessage* msg = handler.encode_msg(MSG_EVENT);
31
32 {
33 MsgHandler handler2;
34 vector<TObject*> objs;
35 vector<string> names;
36 handler2.decode_msg(msg, objs, names);
37 ASSERT_EQ(3, objs.size());
38 ASSERT_EQ(3, names.size());
39 ASSERT_EQ("vector", names[0]);
40 ASSERT_EQ("vectorb", names[1]);
41 ASSERT_EQ("named", names[2]);
42
43 auto a2 = dynamic_cast<TVector3*>(objs[0]);
44 ASSERT_NE(a2, nullptr);
45 EXPECT_TRUE(*a2 == a);
46
47 auto b2 = dynamic_cast<TVector3*>(objs[1]);
48 ASSERT_NE(b2, nullptr);
49 EXPECT_TRUE(*b2 == b);
50
51 auto c2 = dynamic_cast<TNamed*>(objs[2]);
52 ASSERT_NE(c2, nullptr);
53 EXPECT_TRUE(std::string(c2->GetName()) == c.GetName());
54 EXPECT_TRUE(std::string(c2->GetTitle()) == c.GetTitle());
55 }
56 delete msg;
57 }
58
59 TEST(MsgHandlerTest, compression)
60 {
61 TClonesArray longarray("Belle2::EventMetaData");
62 longarray.ExpandCreate(1000);
63 for (int algo : {0, 1, 2}) {
64 for (int level = 0; level < 10; ++level) {
65 MsgHandler handler(algo * 100 + level);
66 handler.add(&longarray, "mcparticles");
67 EvtMessage* msg = handler.encode_msg(MSG_EVENT);
68 {
69 MsgHandler handler2;
70 vector<TObject*> objs;
71 vector<string> names;
72 handler2.decode_msg(msg, objs, names);
73 ASSERT_EQ(1, objs.size());
74 ASSERT_EQ(1, names.size());
75 ASSERT_EQ(names[0], "mcparticles");
76 for (auto o : objs) delete o;
77 }
78 }
79 }
80 }
81} // namespace
Class to manage streamed object.
Definition: EvtMessage.h:59
A class to encode/decode an EvtMessage.
Definition: MsgHandler.h:103
virtual void decode_msg(EvtMessage *msg, std::vector< TObject * > &objlist, std::vector< std::string > &namelist)
Decode an EvtMessage into a vector list of objects with names.
Definition: MsgHandler.cc:106
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24
STL namespace.