Draft: Feature/mapattribute
Towards #89
Serialises map types to bytes according to the format:
<nentries>[(key-bytes)key](val-bytes):val[(key-bytes)key](val-bytes):val...
e.g. the following maps:
std::map<int, std::string> mapintstr{
{1, "one"},
{2, "[some_difficult | ::: ][]{}{}><<<:;?\'\">))(( characters....,,,"},
{-999, "my default value"}};
std::map<std::string, int> mapstrint{
{"one",1},
{"[some_difficult | ::: ][]{}{}><<<:;?\'\">))(( characters....,,,",2},
{"my default value",-999}};
are serialized to HepMC Asciiv3 as:
A mapintstr <3>[(4)-999](16):my default value[(1)1](3):one[(1)2](61):[some_difficult | ::: ][]{}{}><<<:;?'">))(( characters....,,,
A mapstrint <3>[(61)[some_difficult | ::: ][]{}{}><<<:;?'">))(( characters....,,,](1):2[(16)my default value](4):-999[(3)one](1):1
Serialization is all handled via other attribute types and they are used like:
//write via evt
// MapStringToIntAttribute is an alias of MapAttribute<StringAttribute, IntAttribute>
evt.add_attribute(
"mapstrint", std::make_shared<HepMC3::MapStringToIntAttribute>(mapstrint));
// MapIntToStringAttribute is an alias of MapAttribute<IntAttribute, StringAttribute>
gri->add_attribute(
"mapintstr", std::make_shared<HepMC3::MapIntToStringAttribute>(mapintstr));
//read into evt2
auto mapstrint_read =
evt2.attribute<HepMC3::MapStringToIntAttribute>("mapstrint")->value();
auto mapintstr_read =
evt2.run_info()
->attribute<HepMC3::MapIntToStringAttribute>("mapintstr")
->value();
Edited by Luke Pickering