Skip to content
Merged
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
30 changes: 13 additions & 17 deletions include/podio/RNTupleReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class RNTupleReader {
///
/// @throws std::invalid_argument in case collsToRead contains collection
/// names that are not available
std::unique_ptr<podio::ROOTFrameData> readNextEntry(const std::string& name,
std::unique_ptr<podio::ROOTFrameData> readNextEntry(std::string_view name,
const std::vector<std::string>& collsToRead = {});

/// Read the desired data entry for a given category.
Expand All @@ -88,7 +88,7 @@ class RNTupleReader {
///
/// @throws std::invalid_argument in case collsToRead contains collection
/// names that are not available
std::unique_ptr<podio::ROOTFrameData> readEntry(const std::string& name, const unsigned entry,
std::unique_ptr<podio::ROOTFrameData> readEntry(std::string_view name, const unsigned entry,
const std::vector<std::string>& collsToRead = {});

/// Get the names of all the available Frame categories in the current file(s).
Expand All @@ -101,7 +101,7 @@ class RNTupleReader {
/// @param name The name of the category
///
/// @returns The number of entries that are available for the category
unsigned getEntries(const std::string& name) const;
unsigned getEntries(std::string_view name) const;

/// Get the build version of podio that has been used to write the current
/// file
Expand All @@ -118,7 +118,7 @@ class RNTupleReader {
///
/// @returns The (build) version of the datamodel if available or an empty
/// optional
std::optional<podio::version::Version> currentFileVersion(const std::string& name) const {
std::optional<podio::version::Version> currentFileVersion(std::string_view name) const {
return m_datamodelHolder.getDatamodelVersion(name);
}

Expand All @@ -127,7 +127,7 @@ class RNTupleReader {
/// @param name The name of the datamodel
///
/// @returns The high level definition of the datamodel in JSON format
const std::string_view getDatamodelDefinition(const std::string& name) const {
const std::string_view getDatamodelDefinition(std::string_view name) const {
return m_datamodelHolder.getDatamodelDefinition(name);
}

Expand All @@ -143,40 +143,36 @@ class RNTupleReader {
* Initialize the given category by filling the maps with metadata information
* that will be used later
*/
bool initCategory(const std::string& category);
bool initCategory(std::string_view category);

/**
* Read and reconstruct the generic parameters of the Frame
*/
GenericParameters readEventMetaData(const std::string& name, const unsigned localEntry, const unsigned readerIndex);

template <typename T>
void readParams(const std::string& name, const unsigned entNum, const unsigned readerIndex,
GenericParameters& params);
GenericParameters readEventMetaData(root_compat::RNTupleReader* reader, const unsigned localEntry);

std::unique_ptr<root_compat::RNTupleReader> m_metadata{};

podio::version::Version m_fileVersion{};
DatamodelDefinitionHolder m_datamodelHolder{};

std::unordered_map<std::string, std::vector<std::unique_ptr<root_compat::RNTupleReader>>> m_readers{};
std::unordered_map<std::string_view, std::vector<std::unique_ptr<root_compat::RNTupleReader>>> m_readers{};
std::unordered_map<std::string, std::unique_ptr<root_compat::RNTupleReader>> m_metadata_readers{};
std::vector<std::string> m_filenames{};

std::unordered_map<std::string, unsigned> m_entries{};
std::unordered_map<std::string_view, unsigned> m_entries{};
// Map category to a vector that contains at how many entries each reader starts
// For example, if we have 3 readers and the first one has 10 entries, the second one 20 and the third one 30
// then the vector will be {0, 10, 30}
// 60 is not needed because anything after 30 will be in the last reader
std::unordered_map<std::string, std::vector<unsigned>> m_readerEntries{};
std::unordered_map<std::string, unsigned> m_totalEntries{};
std::unordered_map<std::string_view, std::vector<unsigned>> m_readerEntries{};
std::unordered_map<std::string_view, unsigned> m_totalEntries{};

/// Map each category to the collections that have been written and are available
std::unordered_map<std::string, std::vector<podio::root_utils::CollectionWriteInfo>> m_collectionInfo{};
std::unordered_map<std::string_view, std::vector<podio::root_utils::CollectionWriteInfo>> m_collectionInfo{};

std::vector<std::string> m_availableCategories{};

std::unordered_map<std::string, std::shared_ptr<podio::CollectionIDTable>> m_idTables{};
std::unordered_map<std::string_view, std::shared_ptr<podio::CollectionIDTable>> m_idTables{};
};

} // namespace podio
Expand Down
12 changes: 6 additions & 6 deletions include/podio/RNTupleWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "podio/Frame.h"
#include "podio/utilities/DatamodelRegistryIOHelpers.h"
#include "podio/utilities/RootHelpers.h"
#include "podio/utilities/StringKeyMap.h"

#include "TFile.h"
#include <ROOT/RNTuple.hxx>
Expand All @@ -12,7 +13,6 @@
#include <ROOT/RVersion.hxx>

#include <string>
#include <unordered_map>
#include <vector>

namespace podio {
Expand Down Expand Up @@ -66,7 +66,7 @@ class RNTupleWriter {
///
/// @param frame The Frame to store
/// @param category The category name under which this Frame should be stored
void writeFrame(const podio::Frame& frame, const std::string& category);
void writeFrame(const podio::Frame& frame, std::string_view category);

/// Store the given Frame with the given category.
///
Expand All @@ -79,7 +79,7 @@ class RNTupleWriter {
/// @param category The category name under which this Frame should be
/// stored
/// @param collsToWrite The collection names that should be written
void writeFrame(const podio::Frame& frame, const std::string& category, const std::vector<std::string>& collsToWrite);
void writeFrame(const podio::Frame& frame, std::string_view category, const std::vector<std::string>& collsToWrite);

/// Write the current file, including all the necessary metadata to read it
/// again.
Expand Down Expand Up @@ -107,7 +107,7 @@ class RNTupleWriter {
/// collsToWrite only. If both vectors are empty the category and the passed
/// collsToWrite are consistent.
std::tuple<std::vector<std::string>, std::vector<std::string>>
checkConsistency(const std::vector<std::string>& collsToWrite, const std::string& category) const;
checkConsistency(const std::vector<std::string>& collsToWrite, std::string_view category) const;

private:
std::unique_ptr<root_compat::RNTupleModel> createModels(const std::vector<root_utils::StoreCollection>& collections);
Expand All @@ -127,7 +127,7 @@ class RNTupleWriter {
root_utils::ParamStorage<double> doubleParams{};
root_utils::ParamStorage<std::string> stringParams{};
};
CategoryInfo& getCategoryInfo(const std::string& category);
CategoryInfo& getCategoryInfo(std::string_view category);

template <typename T>
void fillParams(const GenericParameters& params, CategoryInfo& catInfo, root_compat::REntry* entry);
Expand All @@ -139,7 +139,7 @@ class RNTupleWriter {

DatamodelDefinitionCollector m_datamodelCollector{};

std::unordered_map<std::string, CategoryInfo> m_categories{};
podio::StringKeyMap<CategoryInfo> m_categories{};
};

} // namespace podio
Expand Down
6 changes: 3 additions & 3 deletions include/podio/ROOTLegacyReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class ROOTLegacyReader {
///
/// @returns FrameData from which a podio::Frame can be constructed if there
/// are still entries left to read. Otherwise a nullptr
std::unique_ptr<podio::ROOTFrameData> readNextEntry(const std::string&, const std::vector<std::string>& = {});
std::unique_ptr<podio::ROOTFrameData> readNextEntry(std::string_view, const std::vector<std::string>& = {});

/// Read the desired data entry from which a Frame can be constructed.
///
Expand All @@ -90,15 +90,15 @@ class ROOTLegacyReader {
///
/// @returns FrameData from which a podio::Frame can be constructed if the
/// desired entry exists. Otherwise a nullptr
std::unique_ptr<podio::ROOTFrameData> readEntry(const std::string&, const unsigned entry,
std::unique_ptr<podio::ROOTFrameData> readEntry(std::string_view, const unsigned entry,
const std::vector<std::string>& = {});

/// Get the number of entries for the given name
///
/// @param name The name of the category
///
/// @returns The number of entries that are available for the category
unsigned getEntries(const std::string& name) const;
unsigned getEntries(std::string_view name) const;

/// Get the build version of podio that has been used to write the current
/// file
Expand Down
20 changes: 10 additions & 10 deletions include/podio/ROOTReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class ROOTReader {
///
/// @throws std::invalid_argument in case collsToRead contains collection
/// names that are not available
std::unique_ptr<podio::ROOTFrameData> readNextEntry(const std::string& name,
std::unique_ptr<podio::ROOTFrameData> readNextEntry(std::string_view name,
const std::vector<std::string>& collsToRead = {});

/// Read the desired data entry for a given category.
Expand All @@ -102,15 +102,15 @@ class ROOTReader {
///
/// @throws std::invalid_argument in case collsToRead contains collection
/// names that are not available
std::unique_ptr<podio::ROOTFrameData> readEntry(const std::string& name, const unsigned entry,
std::unique_ptr<podio::ROOTFrameData> readEntry(std::string_view name, const unsigned entry,
const std::vector<std::string>& collsToRead = {});

/// Get the number of entries for the given name
///
/// @param name The name of the category
///
/// @returns The number of entries that are available for the category
unsigned getEntries(const std::string& name) const;
unsigned getEntries(std::string_view name) const;

/// Get the build version of podio that has been used to write the current
/// file
Expand All @@ -127,7 +127,7 @@ class ROOTReader {
///
/// @returns The (build) version of the datamodel if available or an empty
/// optional
std::optional<podio::version::Version> currentFileVersion(const std::string& name) const {
std::optional<podio::version::Version> currentFileVersion(std::string_view name) const {
return m_datamodelHolder.getDatamodelVersion(name);
}

Expand All @@ -141,7 +141,7 @@ class ROOTReader {
/// @param name The name of the datamodel
///
/// @returns The high level definition of the datamodel in JSON format
const std::string_view getDatamodelDefinition(const std::string& name) const {
const std::string_view getDatamodelDefinition(std::string_view name) const {
return m_datamodelHolder.getDatamodelDefinition(name);
}

Expand Down Expand Up @@ -174,12 +174,12 @@ class ROOTReader {
/// Initialize the passed CategoryInfo by setting up the necessary branches,
/// collection infos and all necessary meta data to be able to read entries
/// with this name
void initCategory(CategoryInfo& catInfo, const std::string& name);
void initCategory(CategoryInfo& catInfo, std::string_view name);

/// Get the category information for the given name. In case there is no TTree
/// with contents for the given name this will return a CategoryInfo with an
/// uninitialized chain (nullptr) member
CategoryInfo& getCategoryInfo(const std::string& name);
CategoryInfo& getCategoryInfo(std::string_view name);

/// Read the parameters for the entry specified in the passed CategoryInfo
GenericParameters readEntryParameters(CategoryInfo& catInfo, bool reloadBranches, unsigned int localEntry);
Expand All @@ -198,9 +198,9 @@ class ROOTReader {
std::optional<podio::CollectionReadBuffers> getCollectionBuffers(CategoryInfo& catInfo, size_t iColl,
bool reloadBranches, unsigned int localEntry);

std::unique_ptr<TChain> m_metaChain{nullptr}; ///< The metadata tree
std::unordered_map<std::string, CategoryInfo> m_categories{}; ///< All categories
std::vector<std::string> m_availCategories{}; ///< All available categories from this file
std::unique_ptr<TChain> m_metaChain{nullptr}; ///< The metadata tree
std::unordered_map<std::string_view, CategoryInfo> m_categories{}; ///< All categories
std::vector<std::string> m_availCategories{}; ///< All available categories from this file

podio::version::Version m_fileVersion{0, 0, 0};
DatamodelDefinitionHolder m_datamodelHolder{};
Expand Down
15 changes: 8 additions & 7 deletions include/podio/ROOTWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

#include "TFile.h"

#include "podio/utilities/StringKeyMap.h"

#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>

// forward declarations
Expand Down Expand Up @@ -54,7 +55,7 @@ class ROOTWriter {
///
/// @param frame The Frame to store
/// @param category The category name under which this Frame should be stored
void writeFrame(const podio::Frame& frame, const std::string& category);
void writeFrame(const podio::Frame& frame, std::string_view category);

/// Store the given Frame with the given category.
///
Expand All @@ -67,7 +68,7 @@ class ROOTWriter {
/// @param category The category name under which this Frame should be
/// stored
/// @param collsToWrite The collection names that should be written
void writeFrame(const podio::Frame& frame, const std::string& category, const std::vector<std::string>& collsToWrite);
void writeFrame(const podio::Frame& frame, std::string_view category, const std::vector<std::string>& collsToWrite);

/// Write the current file, including all the necessary metadata to read it
/// again.
Expand Down Expand Up @@ -95,7 +96,7 @@ class ROOTWriter {
/// collsToWrite only. If both vectors are empty the category and the passed
/// collsToWrite are consistent.
std::tuple<std::vector<std::string>, std::vector<std::string>>
checkConsistency(const std::vector<std::string>& collsToWrite, const std::string& category) const;
checkConsistency(const std::vector<std::string>& collsToWrite, std::string_view category) const;

private:
/// Helper struct to group together all necessary state to write / process a
Expand All @@ -119,15 +120,15 @@ class ROOTWriter {
const podio::GenericParameters& parameters);

/// Get the (potentially uninitialized category information for this category)
CategoryInfo& getCategoryInfo(const std::string& category);
CategoryInfo& getCategoryInfo(std::string_view category);

static void resetBranches(CategoryInfo& categoryInfo, const std::vector<root_utils::StoreCollection>& collections);

/// Fill the parameter keys and values into the CategoryInfo storage
static void fillParams(CategoryInfo& catInfo, const GenericParameters& params);

TFile m_file; ///< The storage file
std::unordered_map<std::string, CategoryInfo> m_categories{}; ///< All categories
TFile m_file; ///< The storage file
podio::StringKeyMap<CategoryInfo> m_categories{}; ///< All categories

DatamodelDefinitionCollector m_datamodelCollector{};
};
Expand Down
Loading
Loading