diff --git a/python/templates/Collection.cc.jinja2 b/python/templates/Collection.cc.jinja2 index 2fa4fbc71..b5871a117 100644 --- a/python/templates/Collection.cc.jinja2 +++ b/python/templates/Collection.cc.jinja2 @@ -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 @@ -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 ); diff --git a/src/SchemaEvolution.cc b/src/SchemaEvolution.cc index 78aad343f..6c118a4a6 100644 --- a/src/SchemaEvolution.cc +++ b/src/SchemaEvolution.cc @@ -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); @@ -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,