diff --git a/src/ROOTNTupleWriter.cc b/src/ROOTNTupleWriter.cc index dfa75badf..9cf3b9d8d 100644 --- a/src/ROOTNTupleWriter.cc +++ b/src/ROOTNTupleWriter.cc @@ -71,7 +71,7 @@ void ROOTNTupleWriter::writeFrame(const podio::Frame& frame, const std::string& const bool new_category = (catInfo.writer == nullptr); if (new_category) { // This is the minimal information that we need for now - catInfo.name = collsToWrite; + catInfo.name = root_utils::sortAlphabeticaly(collsToWrite); } std::vector collections; diff --git a/src/rootUtils.h b/src/rootUtils.h index 648a6f166..acc552f24 100644 --- a/src/rootUtils.h +++ b/src/rootUtils.h @@ -287,9 +287,16 @@ inline bool checkConsistentColls(const std::vector& existingColls, // Since we are guaranteed to have unique names here, we can just look for // collisions brute force, which seems to be quickest approach for vector - // sizes we typically have here (few hundred) + // sizes we typically have (few hundred). We can take advantage of the fact + // that the existingColls are ordered (alphabetically and case-insensitive), + // so we can do a binary_search for (const auto& id : candidateColls) { - if (std::find(existingColls.begin(), existingColls.end(), id) == existingColls.end()) { + if (!std::binary_search(existingColls.begin(), existingColls.end(), id, [](const auto& lhs, const auto& rhs) { + return lhs.size() == rhs.size() && + std::lexicographical_compare( + lhs.begin(), lhs.end(), rhs.begin(), rhs.end(), + [](const auto cl, const auto cr) { return std::tolower(cl) < std::tolower(cr); }); + })) { return false; } }