diff --git a/include/podio/ROOTLegacyReader.h b/include/podio/ROOTLegacyReader.h index 9383ca51b..9be8634b5 100644 --- a/include/podio/ROOTLegacyReader.h +++ b/include/podio/ROOTLegacyReader.h @@ -113,7 +113,7 @@ class ROOTLegacyReader { private: std::pair getLocalTreeAndEntry(const std::string& treename); - void createCollectionBranches(const std::vector& collInfo); + void createCollectionBranches(const std::vector& collInfo); podio::GenericParameters readEventMetaData(); diff --git a/include/podio/ROOTWriter.h b/include/podio/ROOTWriter.h index 5ee23835f..0df3e6d54 100644 --- a/include/podio/ROOTWriter.h +++ b/include/podio/ROOTWriter.h @@ -105,7 +105,7 @@ class ROOTWriter { struct CategoryInfo { TTree* tree{nullptr}; ///< The TTree to which this category is written std::vector branches{}; ///< The branches for this category - std::vector collInfo{}; ///< Collection info for this category + std::vector collInfo{}; ///< Collection info for this category podio::CollectionIDTable idTable{}; ///< The collection id table for this category std::vector collsToWrite{}; ///< The collections to write for this category diff --git a/include/podio/utilities/RootHelpers.h b/include/podio/utilities/RootHelpers.h index 360ef6674..7516b4df1 100644 --- a/include/podio/utilities/RootHelpers.h +++ b/include/podio/utilities/RootHelpers.h @@ -18,7 +18,15 @@ namespace root_utils { // A collection of additional information that describes the collection: the // collectionID, the collection (data) type, whether it is a subset // collection, and its schema version + struct CollectionWriteInfo { + uint32_t collectionID{static_cast(-1)}; + std::string dataType{}; + bool isSubset{false}; + unsigned int schemaVersion{0}; + }; + // The format used until version 1.2 using CollectionWriteInfoT = std::tuple; + // for backwards compatibility using CollectionInfoWithoutSchemaT = std::tuple; diff --git a/src/ROOTLegacyReader.cc b/src/ROOTLegacyReader.cc index 87f7a4e1b..d67c509fe 100644 --- a/src/ROOTLegacyReader.cc +++ b/src/ROOTLegacyReader.cc @@ -150,7 +150,12 @@ void ROOTLegacyReader::openFiles(const std::vector& filenames) { collInfoBranch->SetAddress(&collectionInfo); collInfoBranch->GetEntry(0); } - createCollectionBranches(*collectionInfo); + std::vector collInfo; + collInfo.reserve(collectionInfo->size()); + for (auto& [id, typeName, isSubsetColl, schemaVersion] : *collectionInfo) { + collInfo.emplace_back(id, std::move(typeName), isSubsetColl, schemaVersion); + } + createCollectionBranches(collInfo); delete collectionInfo; } else { std::cout << "PODIO: Reconstructing CollectionTypeInfo branch from other sources in file: \'" @@ -168,7 +173,7 @@ unsigned ROOTLegacyReader::getEntries(const std::string& name) const { return m_chain->GetEntries(); } -void ROOTLegacyReader::createCollectionBranches(const std::vector& collInfo) { +void ROOTLegacyReader::createCollectionBranches(const std::vector& collInfo) { size_t collectionIndex{0}; for (const auto& [collID, collType, isSubsetColl, collSchemaVersion] : collInfo) { diff --git a/src/ROOTReader.cc b/src/ROOTReader.cc index 7b0373ba4..9f4080988 100644 --- a/src/ROOTReader.cc +++ b/src/ROOTReader.cc @@ -19,11 +19,11 @@ namespace podio { std::tuple, std::vector>> createCollectionBranches(TChain* chain, const podio::CollectionIDTable& idTable, - const std::vector& collInfo); + const std::vector& collInfo); std::tuple, std::vector>> createCollectionBranchesIndexBased(TChain* chain, const podio::CollectionIDTable& idTable, - const std::vector& collInfo); + const std::vector& collInfo); template void ROOTReader::readParams(ROOTReader::CategoryInfo& catInfo, podio::GenericParameters& params, bool reloadBranches, @@ -169,20 +169,33 @@ void ROOTReader::initCategory(CategoryInfo& catInfo, const std::string& category auto* collInfoBranch = root_utils::getBranch(m_metaChain.get(), root_utils::collInfoName(category)); - auto collInfo = new std::vector(); - if (m_fileVersion < podio::version::Version{0, 16, 4}) { - auto oldCollInfo = new std::vector(); - collInfoBranch->SetAddress(&oldCollInfo); - collInfoBranch->GetEntry(0); - collInfo->reserve(oldCollInfo->size()); - for (auto&& [collID, collType, isSubsetColl] : *oldCollInfo) { - // Manually set the schema version to 1 - collInfo->emplace_back(collID, std::move(collType), isSubsetColl, 1u); - } - delete oldCollInfo; - } else { + auto collInfo = new std::vector(); + + if (m_fileVersion >= podio::version::Version{1, 1, 0}) { collInfoBranch->SetAddress(&collInfo); collInfoBranch->GetEntry(0); + } else { + auto collInfoOld = new std::vector(); + if (m_fileVersion < podio::version::Version{0, 16, 4}) { + auto collInfoReallyOld = new std::vector(); + collInfoBranch->SetAddress(&collInfoReallyOld); + collInfoBranch->GetEntry(0); + collInfoOld->reserve(collInfoReallyOld->size()); + for (auto& [collID, collType, isSubsetColl] : *collInfoReallyOld) { + // Manually set the schema version to 1 + collInfo->emplace_back(collID, std::move(collType), isSubsetColl, 1u); + } + delete collInfoReallyOld; + } else { + collInfoBranch->SetAddress(&collInfoOld); + collInfoBranch->GetEntry(0); + } + // "Convert" to new style + collInfo->reserve(collInfoOld->size()); + for (auto& [id, typeName, isSubsetColl, schemaVersion] : *collInfoOld) { + collInfo->emplace_back(id, std::move(typeName), isSubsetColl, schemaVersion); + } + delete collInfoOld; } // For backwards compatibility make it possible to read the index based files @@ -309,7 +322,7 @@ std::vector ROOTReader::getAvailableCategories() const { std::tuple, std::vector>> createCollectionBranchesIndexBased(TChain* chain, const podio::CollectionIDTable& idTable, - const std::vector& collInfo) { + const std::vector& collInfo) { size_t collectionIndex{0}; std::vector collBranches; @@ -361,7 +374,7 @@ createCollectionBranchesIndexBased(TChain* chain, const podio::CollectionIDTable std::tuple, std::vector>> createCollectionBranches(TChain* chain, const podio::CollectionIDTable& idTable, - const std::vector& collInfo) { + const std::vector& collInfo) { size_t collectionIndex{0}; std::vector collBranches; diff --git a/src/rootUtils.h b/src/rootUtils.h index 007e4e202..004abce3c 100644 --- a/src/rootUtils.h +++ b/src/rootUtils.h @@ -257,7 +257,7 @@ inline void readBranchesData(const CollectionBranches& branches, Long64_t entry) * collections */ inline auto reconstructCollectionInfo(TTree* eventTree, podio::CollectionIDTable const& idTable) { - std::vector collInfo; + std::vector collInfo; for (size_t iColl = 0; iColl < idTable.names().size(); ++iColl) { const auto collID = idTable.ids()[iColl]; diff --git a/src/root_selection.xml b/src/root_selection.xml index 38db949c0..dc4dbb9db 100644 --- a/src/root_selection.xml +++ b/src/root_selection.xml @@ -5,5 +5,8 @@ + + +