Jpp 21.0.0-rc.1-88-g0130508c4
the software that should make you happy
Loading...
Searching...
No Matches
test_head.cc File Reference
#include "km3net-dataformat/offline/Head.hh"
#include "km3net-dataformat/offline/io_ascii.hh"
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

Go to the source code of this file.

Functions

int main ()
 

Function Documentation

◆ main()

int main ( )

Definition at line 43 of file test_head.cc.

44{
45 Head h;
46
47 h.set_line("seed", "42");
48 h.set_line("detector", "aaa bbb");
49 h.set_line("detector", "ccc ddd");
50 h.set_line("detector", "ccc ddd eee");
51
52 const std::vector<std::string> expected_keys = {
53 "detector",
54 "detector_1",
55 "detector_2"
56 };
57 const std::vector<std::string> expected_lines = {
58 "aaa bbb",
59 "ccc ddd",
60 "ccc ddd eee"
61 };
62
63 const auto keys = h.matching_keys("detector");
64 const auto lines = h.get_lines("detector");
65 std::ostringstream output;
66
67 expect_equal(keys, expected_keys, "matching_keys");
68 expect_equal(lines, expected_lines, "get_lines");
69
70 expect_true(write(h, output), "write(Head, ostream) returned false");
71
72 const std::string rendered = output.str();
73 expect_true(rendered.find("seed: 42") != std::string::npos,
74 "Rendered header does not contain the seed line");
75 expect_true(rendered.find("detector_2: ccc ddd eee") != std::string::npos,
76 "Rendered header does not contain the final detector line");
77
78 std::cout << "OK" << std::endl;
79 return 0;
80}
bool write(const Vec &v, std::ostream &os)
Write a Vec(tor) to a stream.
Definition io_ascii.hh:155
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition Head.hh:65
std::vector< std::string > matching_keys(const std::string &tag) const
In case of duplicate keys, they are internally stored in the map with a suffix "_n".
Definition Head.hh:115
std::string set_line(std::string tag, std::string line, bool ensure_unique=true)
Set data with the given tag.
Definition Head.hh:176
std::vector< std::string > get_lines(const std::string &tag) const
Get all data compatible with the given key.
Definition Head.hh:154