Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Store the collection information in a struct instead of a tuple #711

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/podio/ROOTLegacyReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class ROOTLegacyReader {
private:
std::pair<TTree*, unsigned> getLocalTreeAndEntry(const std::string& treename);

void createCollectionBranches(const std::vector<root_utils::CollectionWriteInfoT>& collInfo);
void createCollectionBranches(const std::vector<root_utils::CollectionWriteInfo>& collInfo);

podio::GenericParameters readEventMetaData();

Expand Down
2 changes: 1 addition & 1 deletion include/podio/ROOTWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class ROOTWriter {
struct CategoryInfo {
TTree* tree{nullptr}; ///< The TTree to which this category is written
std::vector<root_utils::CollectionBranches> branches{}; ///< The branches for this category
std::vector<root_utils::CollectionWriteInfoT> collInfo{}; ///< Collection info for this category
std::vector<root_utils::CollectionWriteInfo> collInfo{}; ///< Collection info for this category
podio::CollectionIDTable idTable{}; ///< The collection id table for this category
std::vector<std::string> collsToWrite{}; ///< The collections to write for this category

Expand Down
8 changes: 8 additions & 0 deletions include/podio/utilities/RootHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>(-1)};
std::string dataType{};
bool isSubset{false};
unsigned int schemaVersion{0};
};
// The format used until version 1.2
using CollectionWriteInfoT = std::tuple<uint32_t, std::string, bool, unsigned int>;

// for backwards compatibility
using CollectionInfoWithoutSchemaT = std::tuple<int, std::string, bool>;

Expand Down
9 changes: 7 additions & 2 deletions src/ROOTLegacyReader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,12 @@ void ROOTLegacyReader::openFiles(const std::vector<std::string>& filenames) {
collInfoBranch->SetAddress(&collectionInfo);
collInfoBranch->GetEntry(0);
}
createCollectionBranches(*collectionInfo);
std::vector<root_utils::CollectionWriteInfo> 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: \'"
Expand All @@ -168,7 +173,7 @@ unsigned ROOTLegacyReader::getEntries(const std::string& name) const {
return m_chain->GetEntries();
}

void ROOTLegacyReader::createCollectionBranches(const std::vector<root_utils::CollectionWriteInfoT>& collInfo) {
void ROOTLegacyReader::createCollectionBranches(const std::vector<root_utils::CollectionWriteInfo>& collInfo) {
size_t collectionIndex{0};

for (const auto& [collID, collType, isSubsetColl, collSchemaVersion] : collInfo) {
Expand Down
45 changes: 29 additions & 16 deletions src/ROOTReader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ namespace podio {

std::tuple<std::vector<root_utils::CollectionBranches>, std::vector<std::pair<std::string, detail::CollectionInfo>>>
createCollectionBranches(TChain* chain, const podio::CollectionIDTable& idTable,
const std::vector<root_utils::CollectionWriteInfoT>& collInfo);
const std::vector<root_utils::CollectionWriteInfo>& collInfo);

std::tuple<std::vector<root_utils::CollectionBranches>, std::vector<std::pair<std::string, detail::CollectionInfo>>>
createCollectionBranchesIndexBased(TChain* chain, const podio::CollectionIDTable& idTable,
const std::vector<root_utils::CollectionWriteInfoT>& collInfo);
const std::vector<root_utils::CollectionWriteInfo>& collInfo);

template <typename T>
void ROOTReader::readParams(ROOTReader::CategoryInfo& catInfo, podio::GenericParameters& params, bool reloadBranches,
Expand Down Expand Up @@ -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<root_utils::CollectionWriteInfoT>();
if (m_fileVersion < podio::version::Version{0, 16, 4}) {
auto oldCollInfo = new std::vector<root_utils::CollectionInfoWithoutSchemaT>();
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<root_utils::CollectionWriteInfo>();

if (m_fileVersion >= podio::version::Version{1, 1, 0}) {
collInfoBranch->SetAddress(&collInfo);
collInfoBranch->GetEntry(0);
} else {
auto collInfoOld = new std::vector<root_utils::CollectionWriteInfoT>();
if (m_fileVersion < podio::version::Version{0, 16, 4}) {
auto collInfoReallyOld = new std::vector<root_utils::CollectionInfoWithoutSchemaT>();
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
Expand Down Expand Up @@ -309,7 +322,7 @@ std::vector<std::string_view> ROOTReader::getAvailableCategories() const {

std::tuple<std::vector<root_utils::CollectionBranches>, std::vector<std::pair<std::string, detail::CollectionInfo>>>
createCollectionBranchesIndexBased(TChain* chain, const podio::CollectionIDTable& idTable,
const std::vector<root_utils::CollectionWriteInfoT>& collInfo) {
const std::vector<root_utils::CollectionWriteInfo>& collInfo) {

size_t collectionIndex{0};
std::vector<root_utils::CollectionBranches> collBranches;
Expand Down Expand Up @@ -361,7 +374,7 @@ createCollectionBranchesIndexBased(TChain* chain, const podio::CollectionIDTable

std::tuple<std::vector<root_utils::CollectionBranches>, std::vector<std::pair<std::string, detail::CollectionInfo>>>
createCollectionBranches(TChain* chain, const podio::CollectionIDTable& idTable,
const std::vector<root_utils::CollectionWriteInfoT>& collInfo) {
const std::vector<root_utils::CollectionWriteInfo>& collInfo) {

size_t collectionIndex{0};
std::vector<root_utils::CollectionBranches> collBranches;
Expand Down
2 changes: 1 addition & 1 deletion src/rootUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<CollectionWriteInfoT> collInfo;
std::vector<CollectionWriteInfo> collInfo;

for (size_t iColl = 0; iColl < idTable.names().size(); ++iColl) {
const auto collID = idTable.ids()[iColl];
Expand Down
3 changes: 3 additions & 0 deletions src/root_selection.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
<class name="podio::ROOTWriter"/>
<class name="podio::RNTupleReader"/>
<class name="podio::RNTupleWriter"/>

<class name="podio::root_utils::CollectionWriteInfo"/>
<class name="std::vector<podio::root_utils::CollectionWriteInfo>"/>
</selection>
</lcgdict>
Loading