Skip to content

Commit

Permalink
fix registry of evolution functions; add no-op evolutions where neces…
Browse files Browse the repository at this point in the history
…sary
  • Loading branch information
hegner committed Jul 11, 2023
1 parent d95cd80 commit 6ceba04
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
21 changes: 12 additions & 9 deletions python/templates/Collection.cc.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,17 @@ bool registerCollection() {
factory.registerCreationFunc("{{ class.full_type }}Collection", {{ package_name }}::meta::schemaVersion, createBuffers);

// Make the SchemaEvolution aware of the current version by
// registering a no-op function with it
podio::SchemaEvolution::mutInstance().registerEvolutionFunc(
"{{ class.full_type }}Collection",
{{ package_name }}::meta::schemaVersion,
{{ package_name }}::meta::schemaVersion,
podio::SchemaEvolution::noOpSchemaEvolution,
podio::SchemaEvolution::Priority::AutoGenerated
);
// registering a no-op function for this and all preceeding versions
// will be overriden whenever an explicit action is required
for (unsigned int schemaVersion=1; schemaVersion< {{ package_name }}::meta::schemaVersion+1; ++schemaVersion) {
podio::SchemaEvolution::mutInstance().registerEvolutionFunc(
"{{ class.full_type }}Collection",
schemaVersion,
{{ package_name }}::meta::schemaVersion,
podio::SchemaEvolution::noOpSchemaEvolution,
podio::SchemaEvolution::Priority::AutoGenerated
);
}

{% if old_schema_version is defined %}
// register a buffer creation function for the schema evolution buffer
Expand All @@ -206,7 +209,7 @@ bool registerCollection() {
{{ old_schema_version }},
{{ package_name }}::meta::schemaVersion,
podio::SchemaEvolution::noOpSchemaEvolution,
podio::SchemaEvolution::Priority::UserDefined // TODO: fix bug in registration
podio::SchemaEvolution::Priority::AutoGenerated
);


Expand Down
23 changes: 12 additions & 11 deletions src/SchemaEvolution.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ podio::CollectionReadBuffers SchemaEvolution::evolveBuffers(const podio::Collect
}

const auto& typeEvolFuncs = m_evolutionFuncs[mapIndex];
if (fromVersion < typeEvolFuncs.size() - 1) {
if (fromVersion < typeEvolFuncs.size() ) {
// Do we need this check? In principle we could ensure at registration
// time that this is always guaranteed
return typeEvolFuncs[fromVersion - 1](oldBuffers, fromVersion);
Expand Down Expand Up @@ -53,21 +53,22 @@ void SchemaEvolution::registerEvolutionFunc(const std::string& collType, SchemaV
m_evolutionFuncs.emplace_back(EvolFuncVersionMapT{});
}

// From here on out we don't need the mutabale any longer
// From here on out we don't need the mutable any longer
const auto& [_, mapIndex] = typeIt->second;

auto& versionMap = m_evolutionFuncs[mapIndex];
const auto prevSize = versionMap.size();
if (prevSize < fromVersion) {
versionMap.resize(fromVersion);
versionMap[fromVersion - 1] = evolutionFunc;
} else {
if (priority == Priority::UserDefined) {
versionMap[fromVersion - 1] = evolutionFunc;
} else {
std::cerr << "Not updating evolution function because priority is not UserDefined" << std::endl;
}
if (prevSize < currentVersion) {
versionMap.resize(currentVersion);
}
versionMap[fromVersion - 1] = evolutionFunc;
// TODO: temporarily switching off UserDefined logic
//if (priority == Priority::UserDefined) {
// versionMap[fromVersion - 1] = evolutionFunc;
//} else {
// std::cerr << "Not updating evolution function because priority is not UserDefined" << std::endl;
// }
//}
}

podio::CollectionReadBuffers SchemaEvolution::noOpSchemaEvolution(podio::CollectionReadBuffers&& buffers,
Expand Down

0 comments on commit 6ceba04

Please sign in to comment.