From 6adf43a68b4effddf5630fbf803609994dbf9d1d Mon Sep 17 00:00:00 2001 From: Thomas Madlener Date: Tue, 6 Feb 2024 11:18:53 +0100 Subject: [PATCH] Remove the `Frame` from the default readers and writers (#549) * Use freed up name for standard root readers / writers * Rename the SIO default reader / writer * Remove internal usage of deprecated reader / writer * Remove mentions of old names from existing docs * Make edm4hep workflows pass * Make clang-tidy pass clang-tidy seems to struggle with the "header-only" implementation otherwise and not be able to parse out necessary include directories from the compile_commands.json --- .github/workflows/edm4hep.yaml | 2 +- .pre-commit-config.yaml | 2 +- doc/advanced_topics.md | 2 +- include/podio/ROOTFrameReader.h | 169 +---------------- include/podio/ROOTFrameWriter.h | 104 +---------- include/podio/ROOTReader.h | 173 ++++++++++++++++++ include/podio/ROOTWriter.h | 108 +++++++++++ include/podio/SIOFrameReader.h | 86 +-------- include/podio/SIOFrameWriter.h | 40 +--- include/podio/SIOReader.h | 90 +++++++++ include/podio/SIOWriter.h | 44 +++++ python/podio/root_io.py | 4 +- python/podio/sio_io.py | 4 +- src/CMakeLists.txt | 16 +- src/{ROOTFrameReader.cc => ROOTReader.cc} | 28 +-- src/{ROOTFrameWriter.cc => ROOTWriter.cc} | 28 +-- src/{SIOFrameReader.cc => SIOReader.cc} | 20 +- src/{SIOFrameWriter.cc => SIOWriter.cc} | 14 +- src/root_selection.xml | 4 +- src/sio_selection.xml | 4 +- tests/root_io/read_and_write_associated.cpp | 8 +- tests/root_io/read_and_write_frame_root.cpp | 8 +- tests/root_io/read_frame_root.cpp | 6 +- tests/root_io/read_frame_root_multiple.cpp | 6 +- tests/root_io/read_python_frame_root.cpp | 4 +- tests/root_io/relation_range.cpp | 8 +- tests/root_io/write_frame_root.cpp | 4 +- .../root_io/read_new_data_root.cpp | 4 +- .../root_io/write_old_data_root.cpp | 4 +- tests/sio_io/read_and_write_frame_sio.cpp | 8 +- tests/sio_io/read_frame_sio.cpp | 6 +- tests/sio_io/read_python_frame_sio.cpp | 4 +- tests/sio_io/write_frame_sio.cpp | 4 +- tests/unittests/unittest.cpp | 20 +- 34 files changed, 538 insertions(+), 498 deletions(-) create mode 100644 include/podio/ROOTReader.h create mode 100644 include/podio/ROOTWriter.h create mode 100644 include/podio/SIOReader.h create mode 100644 include/podio/SIOWriter.h rename src/{ROOTFrameReader.cc => ROOTReader.cc} (91%) rename src/{ROOTFrameWriter.cc => ROOTWriter.cc} (84%) rename src/{SIOFrameReader.cc => SIOReader.cc} (86%) rename src/{SIOFrameWriter.cc => SIOWriter.cc} (86%) diff --git a/.github/workflows/edm4hep.yaml b/.github/workflows/edm4hep.yaml index 9bb4c5475..ded1c3f4d 100644 --- a/.github/workflows/edm4hep.yaml +++ b/.github/workflows/edm4hep.yaml @@ -65,7 +65,7 @@ jobs: cd $STARTDIR/edm4hep mkdir build && cd build cmake -DCMAKE_CXX_STANDARD=17 \ - -DCMAKE_CXX_FLAGS=" -fdiagnostics-color=always -Werror " \ + -DCMAKE_CXX_FLAGS=" -fdiagnostics-color=always " \ -DUSE_EXTERNAL_CATCH2=ON \ -G Ninja .. ninja -k0 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 61954a07f..00ca2cf97 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,7 +11,7 @@ repos: name: clang-tidy entry: clang-tidy -warnings-as-errors='*,-clang-diagnostic-deprecated-declarations' -p compile_commands.json types: [c++] - exclude: (tests/(datamodel|src)/.*(h|cc)|podioVersion.in.h) + exclude: (tests/(datamodel|src)/.*(h|cc)|podioVersion.in.h|SIOFrame.*h) language: system - id: clang-format name: clang-format diff --git a/doc/advanced_topics.md b/doc/advanced_topics.md index e144b1582..800b5a969 100644 --- a/doc/advanced_topics.md +++ b/doc/advanced_topics.md @@ -215,6 +215,6 @@ read and write all the necessary EDM definitions. - The `DatamodelDefinitionHolder` is intended to be used by readers. It provides the `getDatamodelDefinition` and `getAvailableDatamodels` methods. **It is again the readers property to correctly populate it with the data it - has read from file.** Currently the `SIOFrameReader` and the `ROOTFrameReader` + has read from file.** Currently the `SIOReader`, `ROOTReader` and the `ROOTRNTupleReader`, use it and also offer the same functionality as public methods with the help of it. diff --git a/include/podio/ROOTFrameReader.h b/include/podio/ROOTFrameReader.h index f2d0033a3..39d4c904b 100644 --- a/include/podio/ROOTFrameReader.h +++ b/include/podio/ROOTFrameReader.h @@ -1,173 +1,10 @@ #ifndef PODIO_ROOTFRAMEREADER_H #define PODIO_ROOTFRAMEREADER_H -#include "podio/CollectionBranches.h" -#include "podio/ROOTFrameData.h" -#include "podio/podioVersion.h" -#include "podio/utilities/DatamodelRegistryIOHelpers.h" - -#include "TChain.h" - -#include -#include -#include -#include -#include -#include -#include - -// forward declarations -class TClass; -class TFile; -class TTree; +#include "podio/ROOTReader.h" namespace podio { - -namespace detail { - // Information about the collection class type, whether it is a subset, the - // schema version on file and the index in the collection branches cache - // vector - using CollectionInfo = std::tuple; - -} // namespace detail - -class CollectionBase; -class CollectionIDTable; -class GenericParameters; -struct CollectionReadBuffers; - -/** - * This class has the function to read available data from disk - * and to prepare collections and buffers. - **/ -class ROOTFrameReader { - -public: - ROOTFrameReader() = default; - ~ROOTFrameReader() = default; - - // non-copyable - ROOTFrameReader(const ROOTFrameReader&) = delete; - ROOTFrameReader& operator=(const ROOTFrameReader&) = delete; - - /** - * Open a single file for reading. - * - * @param filename The name of the input file - */ - void openFile(const std::string& filename); - - /** - * Open multiple files for reading and then treat them as if they are one file - * - * NOTE: All of the files are assumed to have the same structure. Specifically - * this means: - * - The same categories are available from all files - * - The collections that are contained in the individual categories are the - * same across all files - * - * This usually boils down to "the files have been written with the same - * settings", e.g. they are outputs of a batched process. - * - * @param filenames The filenames of all input files that should be read - */ - void openFiles(const std::vector& filenames); - - /** - * Read the next data entry from which a Frame can be constructed for the - * given name. In case there are no more entries left for this name or in - * case there is no data for this name, this returns a nullptr. - */ - std::unique_ptr readNextEntry(const std::string& name); - - /** - * Read the specified data entry from which a Frame can be constructed for - * the given name. In case the entry does not exist for this name or in case - * there is no data for this name, this returns a nullptr. - */ - std::unique_ptr readEntry(const std::string& name, const unsigned entry); - - /// Returns number of entries for the given name - unsigned getEntries(const std::string& name) const; - - /// Get the build version of podio that has been used to write the current file - podio::version::Version currentFileVersion() const { - return m_fileVersion; - } - - /// Get the names of all the available Frame categories in the current file(s) - std::vector getAvailableCategories() const; - - /// Get the datamodel definition for the given name - const std::string_view getDatamodelDefinition(const std::string& name) const { - return m_datamodelHolder.getDatamodelDefinition(name); - } - - /// Get all names of the datamodels that ara available from this reader - std::vector getAvailableDatamodels() const { - return m_datamodelHolder.getAvailableDatamodels(); - } - -private: - /** - * Helper struct to group together all the necessary state to read / process a - * given category. A "category" in this case describes all frames with the - * same name which are constrained by the ROOT file structure that we use to - * have the same contents. It encapsulates all state that is necessary for - * reading from a TTree / TChain (i.e. collection infos, branches, ...) - */ - struct CategoryInfo { - /// constructor from chain for more convenient map insertion - CategoryInfo(std::unique_ptr&& c) : chain(std::move(c)) { - } - std::unique_ptr chain{nullptr}; ///< The TChain with the data - unsigned entry{0}; ///< The next entry to read - std::vector> storedClasses{}; ///< The stored collections in this - ///< category - std::vector branches{}; ///< The branches for this category - std::shared_ptr table{nullptr}; ///< The collection ID table for this category - }; - - /** - * 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); - - /** - * 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); - - /** - * Read the parameters for the entry specified in the passed CategoryInfo - */ - GenericParameters readEntryParameters(CategoryInfo& catInfo, bool reloadBranches, unsigned int localEntry); - - /** - * Read the data entry specified in the passed CategoryInfo, and increase the - * counter afterwards. In case the requested entry is larger than the - * available number of entries, return a nullptr. - */ - std::unique_ptr readEntry(ROOTFrameReader::CategoryInfo& catInfo); - - /** - * Get / read the buffers at index iColl in the passed category information - */ - podio::CollectionReadBuffers getCollectionBuffers(CategoryInfo& catInfo, size_t iColl, bool reloadBranches, - unsigned int localEntry); - - std::unique_ptr m_metaChain{nullptr}; ///< The metadata tree - std::unordered_map m_categories{}; ///< All categories - std::vector m_availCategories{}; ///< All available categories from this file - - podio::version::Version m_fileVersion{0, 0, 0}; - DatamodelDefinitionHolder m_datamodelHolder{}; -}; - -} // namespace podio +using ROOTFrameReader [[deprecated("Will be removed in v1.0 switch podio::ROOTReader")]] = podio::ROOTReader; +} #endif // PODIO_ROOTFRAMEREADER_H diff --git a/include/podio/ROOTFrameWriter.h b/include/podio/ROOTFrameWriter.h index d6b7ecc8c..a7fb3edda 100644 --- a/include/podio/ROOTFrameWriter.h +++ b/include/podio/ROOTFrameWriter.h @@ -1,108 +1,10 @@ #ifndef PODIO_ROOTFRAMEWRITER_H #define PODIO_ROOTFRAMEWRITER_H -#include "podio/CollectionBranches.h" -#include "podio/CollectionIDTable.h" -#include "podio/utilities/DatamodelRegistryIOHelpers.h" - -#include "TFile.h" - -#include -#include -#include -#include -#include - -// forward declarations -class TTree; +#include "podio/ROOTWriter.h" namespace podio { -class Frame; -class CollectionBase; -class GenericParameters; - -class ROOTFrameWriter { -public: - ROOTFrameWriter(const std::string& filename); - ~ROOTFrameWriter(); - - ROOTFrameWriter(const ROOTFrameWriter&) = delete; - ROOTFrameWriter& operator=(const ROOTFrameWriter&) = delete; - - /** Store the given frame with the given category. Store all available - * collections from the Frame. - * - * NOTE: The contents of the first Frame that is written in this way - * determines the contents that will be written for all subsequent Frames. - */ - void writeFrame(const podio::Frame& frame, const std::string& category); - - /** Store the given Frame with the given category. Store only the - * collections that are passed. - * - * NOTE: The contents of the first Frame that is written in this way - * determines the contents that will be written for all subsequent Frames. - */ - void writeFrame(const podio::Frame& frame, const std::string& category, const std::vector& collsToWrite); - - /** Write the current file, including all the necessary metadata to read it again. - */ - void finish(); - - /** Check whether the collsToWrite are consistent with the state of the passed - * category. - * - * Return two vectors of collection names. The first one contains all the - * names that were missing from the collsToWrite but were present in the - * category. The second one contains the names that are present in the - * collsToWrite only. If both vectors are empty the category and the passed - * collsToWrite are consistent. - * - * NOTE: This will only be a meaningful check if the first Frame of the passed - * category has already been written. Also, this check is rather expensive as - * it has to effectively do two set differences. - */ - std::tuple, std::vector> - checkConsistency(const std::vector& collsToWrite, const std::string& category) const; - -private: - using StoreCollection = std::pair; - - // collectionID, collectionType, subsetCollection - // NOTE: same as in rootUtils.h private header! - using CollectionInfoT = std::tuple; - - /** - * Helper struct to group together all necessary state to write / process a - * given category. Created during the first writing of a category - */ - 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 - podio::CollectionIDTable idTable{}; ///< The collection id table for this category - std::vector collsToWrite{}; ///< The collections to write for this category - }; - - /// Initialize the branches for this category - void initBranches(CategoryInfo& catInfo, const std::vector& collections, - /*const*/ podio::GenericParameters& parameters); - - /// Get the (potentially uninitialized category information for this category) - CategoryInfo& getCategoryInfo(const std::string& category); - - static void resetBranches(std::vector& branches, - const std::vector& collections, - /*const*/ podio::GenericParameters* parameters); - - std::unique_ptr m_file{nullptr}; ///< The storage file - std::unordered_map m_categories{}; ///< All categories - - DatamodelDefinitionCollector m_datamodelCollector{}; - - bool m_finished{false}; ///< Whether writing has been actually done -}; - -} // namespace podio +using ROOTFrameWriter [[deprecated("Will be removed in v1.0 switch podio::ROOTWriter")]] = podio::ROOTWriter; +} #endif // PODIO_ROOTFRAMEWRITER_H diff --git a/include/podio/ROOTReader.h b/include/podio/ROOTReader.h new file mode 100644 index 000000000..e41753a74 --- /dev/null +++ b/include/podio/ROOTReader.h @@ -0,0 +1,173 @@ +#ifndef PODIO_ROOTREADER_H +#define PODIO_ROOTREADER_H + +#include "podio/CollectionBranches.h" +#include "podio/ROOTFrameData.h" +#include "podio/podioVersion.h" +#include "podio/utilities/DatamodelRegistryIOHelpers.h" + +#include "TChain.h" + +#include +#include +#include +#include +#include +#include +#include + +// forward declarations +class TClass; +class TFile; +class TTree; + +namespace podio { + +namespace detail { + // Information about the collection class type, whether it is a subset, the + // schema version on file and the index in the collection branches cache + // vector + using CollectionInfo = std::tuple; + +} // namespace detail + +class CollectionBase; +class CollectionIDTable; +class GenericParameters; +struct CollectionReadBuffers; + +/** + * This class has the function to read available data from disk + * and to prepare collections and buffers. + **/ +class ROOTReader { + +public: + ROOTReader() = default; + ~ROOTReader() = default; + + // non-copyable + ROOTReader(const ROOTReader&) = delete; + ROOTReader& operator=(const ROOTReader&) = delete; + + /** + * Open a single file for reading. + * + * @param filename The name of the input file + */ + void openFile(const std::string& filename); + + /** + * Open multiple files for reading and then treat them as if they are one file + * + * NOTE: All of the files are assumed to have the same structure. Specifically + * this means: + * - The same categories are available from all files + * - The collections that are contained in the individual categories are the + * same across all files + * + * This usually boils down to "the files have been written with the same + * settings", e.g. they are outputs of a batched process. + * + * @param filenames The filenames of all input files that should be read + */ + void openFiles(const std::vector& filenames); + + /** + * Read the next data entry from which a Frame can be constructed for the + * given name. In case there are no more entries left for this name or in + * case there is no data for this name, this returns a nullptr. + */ + std::unique_ptr readNextEntry(const std::string& name); + + /** + * Read the specified data entry from which a Frame can be constructed for + * the given name. In case the entry does not exist for this name or in case + * there is no data for this name, this returns a nullptr. + */ + std::unique_ptr readEntry(const std::string& name, const unsigned entry); + + /// Returns number of entries for the given name + unsigned getEntries(const std::string& name) const; + + /// Get the build version of podio that has been used to write the current file + podio::version::Version currentFileVersion() const { + return m_fileVersion; + } + + /// Get the names of all the available Frame categories in the current file(s) + std::vector getAvailableCategories() const; + + /// Get the datamodel definition for the given name + const std::string_view getDatamodelDefinition(const std::string& name) const { + return m_datamodelHolder.getDatamodelDefinition(name); + } + + /// Get all names of the datamodels that ara available from this reader + std::vector getAvailableDatamodels() const { + return m_datamodelHolder.getAvailableDatamodels(); + } + +private: + /** + * Helper struct to group together all the necessary state to read / process a + * given category. A "category" in this case describes all frames with the + * same name which are constrained by the ROOT file structure that we use to + * have the same contents. It encapsulates all state that is necessary for + * reading from a TTree / TChain (i.e. collection infos, branches, ...) + */ + struct CategoryInfo { + /// constructor from chain for more convenient map insertion + CategoryInfo(std::unique_ptr&& c) : chain(std::move(c)) { + } + std::unique_ptr chain{nullptr}; ///< The TChain with the data + unsigned entry{0}; ///< The next entry to read + std::vector> storedClasses{}; ///< The stored collections in this + ///< category + std::vector branches{}; ///< The branches for this category + std::shared_ptr table{nullptr}; ///< The collection ID table for this category + }; + + /** + * 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); + + /** + * 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); + + /** + * Read the parameters for the entry specified in the passed CategoryInfo + */ + GenericParameters readEntryParameters(CategoryInfo& catInfo, bool reloadBranches, unsigned int localEntry); + + /** + * Read the data entry specified in the passed CategoryInfo, and increase the + * counter afterwards. In case the requested entry is larger than the + * available number of entries, return a nullptr. + */ + std::unique_ptr readEntry(ROOTReader::CategoryInfo& catInfo); + + /** + * Get / read the buffers at index iColl in the passed category information + */ + podio::CollectionReadBuffers getCollectionBuffers(CategoryInfo& catInfo, size_t iColl, bool reloadBranches, + unsigned int localEntry); + + std::unique_ptr m_metaChain{nullptr}; ///< The metadata tree + std::unordered_map m_categories{}; ///< All categories + std::vector m_availCategories{}; ///< All available categories from this file + + podio::version::Version m_fileVersion{0, 0, 0}; + DatamodelDefinitionHolder m_datamodelHolder{}; +}; + +} // namespace podio + +#endif // PODIO_ROOTREADER_H diff --git a/include/podio/ROOTWriter.h b/include/podio/ROOTWriter.h new file mode 100644 index 000000000..7bee952d3 --- /dev/null +++ b/include/podio/ROOTWriter.h @@ -0,0 +1,108 @@ +#ifndef PODIO_ROOTWRITER_H +#define PODIO_ROOTWRITER_H + +#include "podio/CollectionBranches.h" +#include "podio/CollectionIDTable.h" +#include "podio/utilities/DatamodelRegistryIOHelpers.h" + +#include "TFile.h" + +#include +#include +#include +#include +#include + +// forward declarations +class TTree; + +namespace podio { +class Frame; +class CollectionBase; +class GenericParameters; + +class ROOTWriter { +public: + ROOTWriter(const std::string& filename); + ~ROOTWriter(); + + ROOTWriter(const ROOTWriter&) = delete; + ROOTWriter& operator=(const ROOTWriter&) = delete; + + /** Store the given frame with the given category. Store all available + * collections from the Frame. + * + * NOTE: The contents of the first Frame that is written in this way + * determines the contents that will be written for all subsequent Frames. + */ + void writeFrame(const podio::Frame& frame, const std::string& category); + + /** Store the given Frame with the given category. Store only the + * collections that are passed. + * + * NOTE: The contents of the first Frame that is written in this way + * determines the contents that will be written for all subsequent Frames. + */ + void writeFrame(const podio::Frame& frame, const std::string& category, const std::vector& collsToWrite); + + /** Write the current file, including all the necessary metadata to read it again. + */ + void finish(); + + /** Check whether the collsToWrite are consistent with the state of the passed + * category. + * + * Return two vectors of collection names. The first one contains all the + * names that were missing from the collsToWrite but were present in the + * category. The second one contains the names that are present in the + * collsToWrite only. If both vectors are empty the category and the passed + * collsToWrite are consistent. + * + * NOTE: This will only be a meaningful check if the first Frame of the passed + * category has already been written. Also, this check is rather expensive as + * it has to effectively do two set differences. + */ + std::tuple, std::vector> + checkConsistency(const std::vector& collsToWrite, const std::string& category) const; + +private: + using StoreCollection = std::pair; + + // collectionID, collectionType, subsetCollection + // NOTE: same as in rootUtils.h private header! + using CollectionInfoT = std::tuple; + + /** + * Helper struct to group together all necessary state to write / process a + * given category. Created during the first writing of a category + */ + 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 + podio::CollectionIDTable idTable{}; ///< The collection id table for this category + std::vector collsToWrite{}; ///< The collections to write for this category + }; + + /// Initialize the branches for this category + void initBranches(CategoryInfo& catInfo, const std::vector& collections, + /*const*/ podio::GenericParameters& parameters); + + /// Get the (potentially uninitialized category information for this category) + CategoryInfo& getCategoryInfo(const std::string& category); + + static void resetBranches(std::vector& branches, + const std::vector& collections, + /*const*/ podio::GenericParameters* parameters); + + std::unique_ptr m_file{nullptr}; ///< The storage file + std::unordered_map m_categories{}; ///< All categories + + DatamodelDefinitionCollector m_datamodelCollector{}; + + bool m_finished{false}; ///< Whether writing has been actually done +}; + +} // namespace podio + +#endif // PODIO_ROOTWRITER_H diff --git a/include/podio/SIOFrameReader.h b/include/podio/SIOFrameReader.h index 9902373db..eafc383a9 100644 --- a/include/podio/SIOFrameReader.h +++ b/include/podio/SIOFrameReader.h @@ -1,90 +1,10 @@ #ifndef PODIO_SIOFRAMEREADER_H #define PODIO_SIOFRAMEREADER_H -#include "podio/SIOBlock.h" -#include "podio/SIOFrameData.h" -#include "podio/podioVersion.h" -#include "podio/utilities/DatamodelRegistryIOHelpers.h" - -#include - -#include -#include -#include -#include +#include "podio/SIOReader.h" namespace podio { - -class CollectionIDTable; - -class SIOFrameReader { - -public: - SIOFrameReader(); - ~SIOFrameReader() = default; - - // non copyable - SIOFrameReader(const SIOFrameReader&) = delete; - SIOFrameReader& operator=(const SIOFrameReader&) = delete; - - /** - * Read the next data entry from which a Frame can be constructed for the - * given name. In case there are no more entries left for this name or in - * case there is no data for this name, this returns a nullptr. - */ - std::unique_ptr readNextEntry(const std::string& name); - - /** - * Read the specified data entry from which a Frame can be constructed for - * the given name. In case the entry does not exist for this name or in - * case there is no data for this name, this returns a nullptr. - */ - std::unique_ptr readEntry(const std::string& name, const unsigned entry); - - /// Returns number of entries for the given name - unsigned getEntries(const std::string& name) const; - - void openFile(const std::string& filename); - - /// Get the build version of podio that has been used to write the current file - podio::version::Version currentFileVersion() const { - return m_fileVersion; - } - - /// Get the names of all the available Frame categories in the current file(s) - std::vector getAvailableCategories() const; - - /// Get the datamodel definition for the given name - const std::string_view getDatamodelDefinition(const std::string& name) const { - return m_datamodelHolder.getDatamodelDefinition(name); - } - - /// Get all names of the datamodels that ara available from this reader - std::vector getAvailableDatamodels() const { - return m_datamodelHolder.getAvailableDatamodels(); - } - -private: - void readPodioHeader(); - - /// read the TOC record - bool readFileTOCRecord(); - - void readEDMDefinitions(); - - sio::ifstream m_stream{}; ///< The stream from which we read - - /// Count how many times each an entry of this name has been read already - std::unordered_map m_nameCtr{}; - - /// Table of content record where starting points of named entries can be read from - SIOFileTOCRecord m_tocRecord{}; - /// The podio version that has been used to write the file - podio::version::Version m_fileVersion{0}; - - DatamodelDefinitionHolder m_datamodelHolder{}; -}; - -} // namespace podio +using SIOFrameReader [[deprecated("Will be removed in v1.0 switch podio::SIOReader")]] = podio::SIOReader; +} #endif // PODIO_SIOFRAMEREADER_H diff --git a/include/podio/SIOFrameWriter.h b/include/podio/SIOFrameWriter.h index c111261ca..85b4da8d2 100644 --- a/include/podio/SIOFrameWriter.h +++ b/include/podio/SIOFrameWriter.h @@ -1,44 +1,10 @@ #ifndef PODIO_SIOFRAMEWRITER_H #define PODIO_SIOFRAMEWRITER_H -#include "podio/SIOBlock.h" -#include "podio/utilities/DatamodelRegistryIOHelpers.h" - -#include - -#include -#include -#include +#include "podio/SIOWriter.h" namespace podio { - -class Frame; - -class SIOFrameWriter { -public: - SIOFrameWriter(const std::string& filename); - ~SIOFrameWriter(); - - SIOFrameWriter(const SIOFrameWriter&) = delete; - SIOFrameWriter& operator=(const SIOFrameWriter&) = delete; - - /** Write the given Frame with the given category - */ - void writeFrame(const podio::Frame& frame, const std::string& category); - - /** Write the given Frame with the given category only storing the collections - * that are desired via collsToWrite - */ - void writeFrame(const podio::Frame& frame, const std::string& category, const std::vector& collsToWrite); - - void finish(); - -private: - sio::ofstream m_stream{}; ///< The output file stream - SIOFileTOCRecord m_tocRecord{}; ///< The "table of contents" of the written file - DatamodelDefinitionCollector m_datamodelCollector{}; - bool m_finished{false}; ///< Has finish been called already? -}; -} // namespace podio +using SIOFrameWriter [[deprecated("Will be removed in v1.0 switch podio::SIOWriter")]] = podio::SIOWriter; +} #endif // PODIO_SIOFRAMEWRITER_H diff --git a/include/podio/SIOReader.h b/include/podio/SIOReader.h new file mode 100644 index 000000000..5b16fbe79 --- /dev/null +++ b/include/podio/SIOReader.h @@ -0,0 +1,90 @@ +#ifndef PODIO_SIOREADER_H +#define PODIO_SIOREADER_H + +#include "podio/SIOBlock.h" +#include "podio/SIOFrameData.h" +#include "podio/podioVersion.h" +#include "podio/utilities/DatamodelRegistryIOHelpers.h" + +#include + +#include +#include +#include +#include + +namespace podio { + +class CollectionIDTable; + +class SIOReader { + +public: + SIOReader(); + ~SIOReader() = default; + + // non copyable + SIOReader(const SIOReader&) = delete; + SIOReader& operator=(const SIOReader&) = delete; + + /** + * Read the next data entry from which a Frame can be constructed for the + * given name. In case there are no more entries left for this name or in + * case there is no data for this name, this returns a nullptr. + */ + std::unique_ptr readNextEntry(const std::string& name); + + /** + * Read the specified data entry from which a Frame can be constructed for + * the given name. In case the entry does not exist for this name or in + * case there is no data for this name, this returns a nullptr. + */ + std::unique_ptr readEntry(const std::string& name, const unsigned entry); + + /// Returns number of entries for the given name + unsigned getEntries(const std::string& name) const; + + void openFile(const std::string& filename); + + /// Get the build version of podio that has been used to write the current file + podio::version::Version currentFileVersion() const { + return m_fileVersion; + } + + /// Get the names of all the available Frame categories in the current file(s) + std::vector getAvailableCategories() const; + + /// Get the datamodel definition for the given name + const std::string_view getDatamodelDefinition(const std::string& name) const { + return m_datamodelHolder.getDatamodelDefinition(name); + } + + /// Get all names of the datamodels that ara available from this reader + std::vector getAvailableDatamodels() const { + return m_datamodelHolder.getAvailableDatamodels(); + } + +private: + void readPodioHeader(); + + /// read the TOC record + bool readFileTOCRecord(); + + void readEDMDefinitions(); + + sio::ifstream m_stream{}; ///< The stream from which we read + + /// Count how many times each an entry of this name has been read already + std::unordered_map m_nameCtr{}; + + /// Table of content record where starting points of named entries can be read from + SIOFileTOCRecord m_tocRecord{}; + /// The podio version that has been used to write the file + podio::version::Version m_fileVersion{0}; + + DatamodelDefinitionHolder m_datamodelHolder{}; +}; + +} // namespace podio + +#endif // PODIO_SIOREADER_H diff --git a/include/podio/SIOWriter.h b/include/podio/SIOWriter.h new file mode 100644 index 000000000..2cd02118b --- /dev/null +++ b/include/podio/SIOWriter.h @@ -0,0 +1,44 @@ +#ifndef PODIO_SIOWRITER_H +#define PODIO_SIOWRITER_H + +#include "podio/SIOBlock.h" +#include "podio/utilities/DatamodelRegistryIOHelpers.h" + +#include + +#include +#include +#include + +namespace podio { + +class Frame; + +class SIOWriter { +public: + SIOWriter(const std::string& filename); + ~SIOWriter(); + + SIOWriter(const SIOWriter&) = delete; + SIOWriter& operator=(const SIOWriter&) = delete; + + /** Write the given Frame with the given category + */ + void writeFrame(const podio::Frame& frame, const std::string& category); + + /** Write the given Frame with the given category only storing the collections + * that are desired via collsToWrite + */ + void writeFrame(const podio::Frame& frame, const std::string& category, const std::vector& collsToWrite); + + void finish(); + +private: + sio::ofstream m_stream{}; ///< The output file stream + SIOFileTOCRecord m_tocRecord{}; ///< The "table of contents" of the written file + DatamodelDefinitionCollector m_datamodelCollector{}; + bool m_finished{false}; ///< Has finish been called already? +}; +} // namespace podio + +#endif // PODIO_SIOWRITER_H diff --git a/python/podio/root_io.py b/python/podio/root_io.py index 51416427d..830eb62e7 100644 --- a/python/podio/root_io.py +++ b/python/podio/root_io.py @@ -22,7 +22,7 @@ def __init__(self, filenames): if isinstance(filenames, str): filenames = (filenames,) - self._reader = podio.ROOTFrameReader() + self._reader = podio.ROOTReader() self._reader.openFiles(filenames) super().__init__() @@ -78,7 +78,7 @@ def __init__(self, filename): Args: filename (str): The name of the output file """ - self._writer = podio.ROOTFrameWriter(filename) + self._writer = podio.ROOTWriter(filename) super().__init__() diff --git a/python/podio/sio_io.py b/python/podio/sio_io.py index f876b0475..51c303f2a 100644 --- a/python/podio/sio_io.py +++ b/python/podio/sio_io.py @@ -22,7 +22,7 @@ def __init__(self, filename): Args: filename (str): File to open and read data from """ - self._reader = podio.SIOFrameReader() + self._reader = podio.SIOReader() self._reader.openFile(filename) super().__init__() @@ -57,5 +57,5 @@ def __init__(self, filename): Args: filename (str): The name of the output file """ - self._writer = podio.SIOFrameWriter(filename) + self._writer = podio.SIOWriter(filename) super().__init__() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 77388a439..1397f2e35 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -77,8 +77,8 @@ target_compile_options(podio PRIVATE -pthread) # --- Root I/O functionality and corresponding dictionary SET(root_sources rootUtils.h - ROOTFrameWriter.cc - ROOTFrameReader.cc + ROOTWriter.cc + ROOTReader.cc ROOTLegacyReader.cc ) if(ENABLE_RNTUPLE) @@ -89,9 +89,9 @@ if(ENABLE_RNTUPLE) endif() SET(root_headers - ${PROJECT_SOURCE_DIR}/include/podio/ROOTFrameReader.h + ${PROJECT_SOURCE_DIR}/include/podio/ROOTReader.h ${PROJECT_SOURCE_DIR}/include/podio/ROOTLegacyReader.h - ${PROJECT_SOURCE_DIR}/include/podio/ROOTFrameWriter.h + ${PROJECT_SOURCE_DIR}/include/podio/ROOTWriter.h ) if(ENABLE_RNTUPLE) list(APPEND root_headers @@ -115,17 +115,17 @@ if(ENABLE_SIO) SET(sio_sources SIOBlockUserData.cc SIOBlock.cc - SIOFrameWriter.cc - SIOFrameReader.cc + SIOWriter.cc + SIOReader.cc SIOFrameData.cc sioUtils.h SIOLegacyReader.cc ) SET(sio_headers - ${PROJECT_SOURCE_DIR}/include/podio/SIOFrameReader.h + ${PROJECT_SOURCE_DIR}/include/podio/SIOReader.h ${PROJECT_SOURCE_DIR}/include/podio/SIOLegacyReader.h - ${PROJECT_SOURCE_DIR}/include/podio/SIOFrameWriter.h + ${PROJECT_SOURCE_DIR}/include/podio/SIOWriter.h ) PODIO_ADD_LIB_AND_DICT(podioSioIO "${sio_headers}" "${sio_sources}" sio_selection.xml) diff --git a/src/ROOTFrameReader.cc b/src/ROOTReader.cc similarity index 91% rename from src/ROOTFrameReader.cc rename to src/ROOTReader.cc index 2590cc2ef..8efb2ce2b 100644 --- a/src/ROOTFrameReader.cc +++ b/src/ROOTReader.cc @@ -1,4 +1,4 @@ -#include "podio/ROOTFrameReader.h" +#include "podio/ROOTReader.h" #include "podio/CollectionBase.h" #include "podio/CollectionBufferFactory.h" #include "podio/CollectionBuffers.h" @@ -27,8 +27,8 @@ std::tuple, std::vector& collInfo); -GenericParameters ROOTFrameReader::readEntryParameters(ROOTFrameReader::CategoryInfo& catInfo, bool reloadBranches, - unsigned int localEntry) { +GenericParameters ROOTReader::readEntryParameters(ROOTReader::CategoryInfo& catInfo, bool reloadBranches, + unsigned int localEntry) { // Parameter branch is always the last one auto& paramBranches = catInfo.branches.back(); @@ -46,18 +46,18 @@ GenericParameters ROOTFrameReader::readEntryParameters(ROOTFrameReader::Category return params; } -std::unique_ptr ROOTFrameReader::readNextEntry(const std::string& name) { +std::unique_ptr ROOTReader::readNextEntry(const std::string& name) { auto& catInfo = getCategoryInfo(name); return readEntry(catInfo); } -std::unique_ptr ROOTFrameReader::readEntry(const std::string& name, const unsigned entNum) { +std::unique_ptr ROOTReader::readEntry(const std::string& name, const unsigned entNum) { auto& catInfo = getCategoryInfo(name); catInfo.entry = entNum; return readEntry(catInfo); } -std::unique_ptr ROOTFrameReader::readEntry(ROOTFrameReader::CategoryInfo& catInfo) { +std::unique_ptr ROOTReader::readEntry(ROOTReader::CategoryInfo& catInfo) { if (!catInfo.chain) { return nullptr; } @@ -86,8 +86,8 @@ std::unique_ptr ROOTFrameReader::readEntry(ROOTFrameReader::Categ return std::make_unique(std::move(buffers), catInfo.table, std::move(parameters)); } -podio::CollectionReadBuffers ROOTFrameReader::getCollectionBuffers(ROOTFrameReader::CategoryInfo& catInfo, size_t iColl, - bool reloadBranches, unsigned int localEntry) { +podio::CollectionReadBuffers ROOTReader::getCollectionBuffers(ROOTReader::CategoryInfo& catInfo, size_t iColl, + bool reloadBranches, unsigned int localEntry) { const auto& name = catInfo.storedClasses[iColl].first; const auto& [collType, isSubsetColl, schemaVersion, index] = catInfo.storedClasses[iColl].second; auto& branches = catInfo.branches[index]; @@ -111,7 +111,7 @@ podio::CollectionReadBuffers ROOTFrameReader::getCollectionBuffers(ROOTFrameRead return collBuffers; } -ROOTFrameReader::CategoryInfo& ROOTFrameReader::getCategoryInfo(const std::string& category) { +ROOTReader::CategoryInfo& ROOTReader::getCategoryInfo(const std::string& category) { if (auto it = m_categories.find(category); it != m_categories.end()) { // Use the id table as proxy to check whether this category has been // initialized already @@ -128,7 +128,7 @@ ROOTFrameReader::CategoryInfo& ROOTFrameReader::getCategoryInfo(const std::strin return invalidCategory; } -void ROOTFrameReader::initCategory(CategoryInfo& catInfo, const std::string& category) { +void ROOTReader::initCategory(CategoryInfo& catInfo, const std::string& category) { catInfo.table = std::make_shared(); auto* table = catInfo.table.get(); auto* tableBranch = root_utils::getBranch(m_metaChain.get(), root_utils::idTableName(category)); @@ -189,11 +189,11 @@ std::vector getAvailableCategories(TChain* metaChain) { return brNames; } -void ROOTFrameReader::openFile(const std::string& filename) { +void ROOTReader::openFile(const std::string& filename) { openFiles({filename}); } -void ROOTFrameReader::openFiles(const std::vector& filenames) { +void ROOTReader::openFiles(const std::vector& filenames) { m_metaChain = std::make_unique(root_utils::metaTreeName); // NOTE: We simply assume that the meta data doesn't change throughout the // chain! This essentially boils down to the assumption that all files that @@ -233,7 +233,7 @@ void ROOTFrameReader::openFiles(const std::vector& filenames) { } } -unsigned ROOTFrameReader::getEntries(const std::string& name) const { +unsigned ROOTReader::getEntries(const std::string& name) const { if (auto it = m_categories.find(name); it != m_categories.end()) { return it->second.chain->GetEntries(); } @@ -241,7 +241,7 @@ unsigned ROOTFrameReader::getEntries(const std::string& name) const { return 0; } -std::vector ROOTFrameReader::getAvailableCategories() const { +std::vector ROOTReader::getAvailableCategories() const { std::vector cats; cats.reserve(m_categories.size()); for (const auto& [cat, _] : m_categories) { diff --git a/src/ROOTFrameWriter.cc b/src/ROOTWriter.cc similarity index 84% rename from src/ROOTFrameWriter.cc rename to src/ROOTWriter.cc index 20e6bee53..b38bc145b 100644 --- a/src/ROOTFrameWriter.cc +++ b/src/ROOTWriter.cc @@ -1,4 +1,4 @@ -#include "podio/ROOTFrameWriter.h" +#include "podio/ROOTWriter.h" #include "podio/CollectionBase.h" #include "podio/DatamodelRegistry.h" #include "podio/Frame.h" @@ -11,22 +11,22 @@ namespace podio { -ROOTFrameWriter::ROOTFrameWriter(const std::string& filename) { +ROOTWriter::ROOTWriter(const std::string& filename) { m_file = std::make_unique(filename.c_str(), "recreate"); } -ROOTFrameWriter::~ROOTFrameWriter() { +ROOTWriter::~ROOTWriter() { if (!m_finished) { finish(); } } -void ROOTFrameWriter::writeFrame(const podio::Frame& frame, const std::string& category) { +void ROOTWriter::writeFrame(const podio::Frame& frame, const std::string& category) { writeFrame(frame, category, frame.getAvailableCollections()); } -void ROOTFrameWriter::writeFrame(const podio::Frame& frame, const std::string& category, - const std::vector& collsToWrite) { +void ROOTWriter::writeFrame(const podio::Frame& frame, const std::string& category, + const std::vector& collsToWrite) { auto& catInfo = getCategoryInfo(category); // Use the TTree as proxy here to decide whether this category has already // been initialized @@ -67,7 +67,7 @@ void ROOTFrameWriter::writeFrame(const podio::Frame& frame, const std::string& c catInfo.tree->Fill(); } -ROOTFrameWriter::CategoryInfo& ROOTFrameWriter::getCategoryInfo(const std::string& category) { +ROOTWriter::CategoryInfo& ROOTWriter::getCategoryInfo(const std::string& category) { if (auto it = m_categories.find(category); it != m_categories.end()) { return it->second; } @@ -76,8 +76,8 @@ ROOTFrameWriter::CategoryInfo& ROOTFrameWriter::getCategoryInfo(const std::strin return it->second; } -void ROOTFrameWriter::initBranches(CategoryInfo& catInfo, const std::vector& collections, - /*const*/ podio::GenericParameters& parameters) { +void ROOTWriter::initBranches(CategoryInfo& catInfo, const std::vector& collections, + /*const*/ podio::GenericParameters& parameters) { catInfo.branches.reserve(collections.size() + 1); // collections + parameters // First collections @@ -128,9 +128,9 @@ void ROOTFrameWriter::initBranches(CategoryInfo& catInfo, const std::vector& branches, - const std::vector& collections, - /*const*/ podio::GenericParameters* parameters) { +void ROOTWriter::resetBranches(std::vector& branches, + const std::vector& collections, + /*const*/ podio::GenericParameters* parameters) { size_t iColl = 0; for (auto& coll : collections) { const auto& collBranches = branches[iColl]; @@ -141,7 +141,7 @@ void ROOTFrameWriter::resetBranches(std::vector& branches.back().data->SetAddress(¶meters); } -void ROOTFrameWriter::finish() { +void ROOTWriter::finish() { auto* metaTree = new TTree(root_utils::metaTreeName, "metadata tree for podio I/O functionality"); metaTree->SetDirectory(m_file.get()); @@ -167,7 +167,7 @@ void ROOTFrameWriter::finish() { } std::tuple, std::vector> -ROOTFrameWriter::checkConsistency(const std::vector& collsToWrite, const std::string& category) const { +ROOTWriter::checkConsistency(const std::vector& collsToWrite, const std::string& category) const { if (const auto it = m_categories.find(category); it != m_categories.end()) { return root_utils::getInconsistentColls(it->second.collsToWrite, collsToWrite); } diff --git a/src/SIOFrameReader.cc b/src/SIOReader.cc similarity index 86% rename from src/SIOFrameReader.cc rename to src/SIOReader.cc index 60427adf5..de3d1e0e7 100644 --- a/src/SIOFrameReader.cc +++ b/src/SIOReader.cc @@ -1,4 +1,4 @@ -#include "podio/SIOFrameReader.h" +#include "podio/SIOReader.h" #include "podio/SIOBlock.h" #include "sioUtils.h" @@ -11,11 +11,11 @@ namespace podio { -SIOFrameReader::SIOFrameReader() { +SIOReader::SIOReader() { auto& libLoader [[maybe_unused]] = SIOBlockLibraryLoader::instance(); } -void SIOFrameReader::openFile(const std::string& filename) { +void SIOReader::openFile(const std::string& filename) { m_stream.open(filename, std::ios::binary); if (!m_stream.is_open()) { throw std::runtime_error("File " + filename + " couldn't be opened"); @@ -27,7 +27,7 @@ void SIOFrameReader::openFile(const std::string& filename) { readEDMDefinitions(); // Potentially could do this lazily } -std::unique_ptr SIOFrameReader::readNextEntry(const std::string& name) { +std::unique_ptr SIOReader::readNextEntry(const std::string& name) { // Skip to where the next record of this name starts in the file, based on // how many times we have already read this name // @@ -48,14 +48,14 @@ std::unique_ptr SIOFrameReader::readNextEntry(const std::string& n tableInfo._uncompressed_length); } -std::unique_ptr SIOFrameReader::readEntry(const std::string& name, const unsigned entry) { +std::unique_ptr SIOReader::readEntry(const std::string& name, const unsigned entry) { // NOTE: Will create or overwrite the entry counter // All checks are done in the following function m_nameCtr[name] = entry; return readNextEntry(name); } -std::vector SIOFrameReader::getAvailableCategories() const { +std::vector SIOReader::getAvailableCategories() const { // Filter the available records from the TOC to remove records that are // stored, but use reserved record names for podio meta data auto recordNames = m_tocRecord.getRecordNames(); @@ -65,11 +65,11 @@ std::vector SIOFrameReader::getAvailableCategories() const { return recordNames; } -unsigned SIOFrameReader::getEntries(const std::string& name) const { +unsigned SIOReader::getEntries(const std::string& name) const { return m_tocRecord.getNRecords(name); } -bool SIOFrameReader::readFileTOCRecord() { +bool SIOReader::readFileTOCRecord() { // Check if there is a dedicated marker at the end of the file that tells us // where the TOC actually starts m_stream.seekg(-sio_helpers::SIOTocInfoSize, std::ios_base::end); @@ -99,7 +99,7 @@ bool SIOFrameReader::readFileTOCRecord() { return false; } -void SIOFrameReader::readPodioHeader() { +void SIOReader::readPodioHeader() { const auto& [buffer, _] = sio_utils::readRecord(m_stream, false, sizeof(podio::version::Version)); sio::block_list blocks; @@ -109,7 +109,7 @@ void SIOFrameReader::readPodioHeader() { m_fileVersion = static_cast(blocks[0].get())->version; } -void SIOFrameReader::readEDMDefinitions() { +void SIOReader::readEDMDefinitions() { const auto recordPos = m_tocRecord.getPosition(sio_helpers::SIOEDMDefinitionName); if (recordPos == 0) { // No EDM definitions found diff --git a/src/SIOFrameWriter.cc b/src/SIOWriter.cc similarity index 86% rename from src/SIOFrameWriter.cc rename to src/SIOWriter.cc index dcc1e4c22..da5583e14 100644 --- a/src/SIOFrameWriter.cc +++ b/src/SIOWriter.cc @@ -1,4 +1,4 @@ -#include "podio/SIOFrameWriter.h" +#include "podio/SIOWriter.h" #include "podio/CollectionBase.h" #include "podio/CollectionIDTable.h" #include "podio/Frame.h" @@ -12,7 +12,7 @@ namespace podio { -SIOFrameWriter::SIOFrameWriter(const std::string& filename) { +SIOWriter::SIOWriter(const std::string& filename) { m_stream.open(filename, std::ios::binary); if (!m_stream.is_open()) { SIO_THROW(sio::error_code::not_open, "Couldn't open output stream '" + filename + "'"); @@ -26,18 +26,18 @@ SIOFrameWriter::SIOFrameWriter(const std::string& filename) { sio_utils::writeRecord(blocks, "podio_header_info", m_stream, sizeof(podio::version::Version), false); } -SIOFrameWriter::~SIOFrameWriter() { +SIOWriter::~SIOWriter() { if (!m_finished) { finish(); } } -void SIOFrameWriter::writeFrame(const podio::Frame& frame, const std::string& category) { +void SIOWriter::writeFrame(const podio::Frame& frame, const std::string& category) { writeFrame(frame, category, frame.getAvailableCollections()); } -void SIOFrameWriter::writeFrame(const podio::Frame& frame, const std::string& category, - const std::vector& collsToWrite) { +void SIOWriter::writeFrame(const podio::Frame& frame, const std::string& category, + const std::vector& collsToWrite) { std::vector collections; collections.reserve(collsToWrite.size()); for (const auto& name : collsToWrite) { @@ -56,7 +56,7 @@ void SIOFrameWriter::writeFrame(const podio::Frame& frame, const std::string& ca sio_utils::writeRecord(blocks, category, m_stream); } -void SIOFrameWriter::finish() { +void SIOWriter::finish() { auto edmDefMap = std::make_shared>( m_datamodelCollector.getDatamodelDefinitionsToWrite()); diff --git a/src/root_selection.xml b/src/root_selection.xml index 604c58f13..38db949c0 100644 --- a/src/root_selection.xml +++ b/src/root_selection.xml @@ -1,8 +1,8 @@ - + - + diff --git a/src/sio_selection.xml b/src/sio_selection.xml index b0101fd3e..a7b88c789 100644 --- a/src/sio_selection.xml +++ b/src/sio_selection.xml @@ -1,7 +1,7 @@ - + - + diff --git a/tests/root_io/read_and_write_associated.cpp b/tests/root_io/read_and_write_associated.cpp index d0c73c7e1..9cf005c96 100644 --- a/tests/root_io/read_and_write_associated.cpp +++ b/tests/root_io/read_and_write_associated.cpp @@ -1,6 +1,6 @@ #include "podio/Frame.h" -#include "podio/ROOTFrameReader.h" -#include "podio/ROOTFrameWriter.h" +#include "podio/ROOTReader.h" +#include "podio/ROOTWriter.h" #include "datamodel/EventInfoCollection.h" #include "datamodel/ExampleClusterCollection.h" @@ -10,7 +10,7 @@ #include void writeCollection() { - podio::ROOTFrameWriter writer("associations.root"); + podio::ROOTWriter writer("associations.root"); std::cout << "start writing collections...\n"; @@ -70,7 +70,7 @@ void writeCollection() { void readCollection() { // Start reading the input - auto reader = podio::ROOTFrameReader(); + auto reader = podio::ROOTReader(); reader.openFile("associations.root"); const auto nEvents = reader.getEntries(podio::Category::Event); diff --git a/tests/root_io/read_and_write_frame_root.cpp b/tests/root_io/read_and_write_frame_root.cpp index c25840289..7cde787b2 100644 --- a/tests/root_io/read_and_write_frame_root.cpp +++ b/tests/root_io/read_and_write_frame_root.cpp @@ -1,9 +1,9 @@ #include "read_and_write_frame.h" -#include "podio/ROOTFrameReader.h" -#include "podio/ROOTFrameWriter.h" +#include "podio/ROOTReader.h" +#include "podio/ROOTWriter.h" int main() { - return rewrite_frames("example_frame.root", "rewritten_frame.root") + - read_rewritten_frames("rewritten_frame.root"); + return rewrite_frames("example_frame.root", "rewritten_frame.root") + + read_rewritten_frames("rewritten_frame.root"); } diff --git a/tests/root_io/read_frame_root.cpp b/tests/root_io/read_frame_root.cpp index 2e7f466de..40f8cdccf 100644 --- a/tests/root_io/read_frame_root.cpp +++ b/tests/root_io/read_frame_root.cpp @@ -1,7 +1,7 @@ #include "read_frame.h" #include "read_frame_auxiliary.h" -#include "podio/ROOTFrameReader.h" +#include "podio/ROOTReader.h" #include #include @@ -18,6 +18,6 @@ int main(int argc, char* argv[]) { return 1; } - return read_frames(inputFile, assertBuildVersion) + - test_frame_aux_info(inputFile); + return read_frames(inputFile, assertBuildVersion) + + test_frame_aux_info(inputFile); } diff --git a/tests/root_io/read_frame_root_multiple.cpp b/tests/root_io/read_frame_root_multiple.cpp index 85dcd316b..7c76e25ef 100644 --- a/tests/root_io/read_frame_root_multiple.cpp +++ b/tests/root_io/read_frame_root_multiple.cpp @@ -1,8 +1,8 @@ #include "read_frame.h" -#include "podio/ROOTFrameReader.h" +#include "podio/ROOTReader.h" -int read_frames(podio::ROOTFrameReader& reader) { +int read_frames(podio::ROOTReader& reader) { if (reader.currentFileVersion() != podio::version::build_version) { std::cerr << "The podio build version could not be read back correctly. " << "(expected:" << podio::version::build_version << ", actual: " << reader.currentFileVersion() << ")" @@ -83,7 +83,7 @@ int read_frames(podio::ROOTFrameReader& reader) { } int main() { - auto reader = podio::ROOTFrameReader(); + auto reader = podio::ROOTReader(); reader.openFiles({"example_frame.root", "example_frame.root"}); return read_frames(reader); } diff --git a/tests/root_io/read_python_frame_root.cpp b/tests/root_io/read_python_frame_root.cpp index 23d1c0015..a3497831d 100644 --- a/tests/root_io/read_python_frame_root.cpp +++ b/tests/root_io/read_python_frame_root.cpp @@ -1,7 +1,7 @@ #include "read_python_frame.h" -#include "podio/ROOTFrameReader.h" +#include "podio/ROOTReader.h" int main() { - return read_frame("example_frame_with_py.root"); + return read_frame("example_frame_with_py.root"); } diff --git a/tests/root_io/relation_range.cpp b/tests/root_io/relation_range.cpp index 023ca6aca..6159e8cdc 100644 --- a/tests/root_io/relation_range.cpp +++ b/tests/root_io/relation_range.cpp @@ -3,8 +3,8 @@ #include "datamodel/MutableExampleWithVectorMember.h" #include "podio/Frame.h" -#include "podio/ROOTFrameReader.h" -#include "podio/ROOTFrameWriter.h" +#include "podio/ROOTReader.h" +#include "podio/ROOTWriter.h" #include #include @@ -182,7 +182,7 @@ void testExampleReferencingType() { } void testWithIO() { - podio::ROOTFrameWriter writer("relation_range_io_test.root"); + podio::ROOTWriter writer("relation_range_io_test.root"); for (int i = 0; i < 10; ++i) { auto collection = ExampleMCCollection(); @@ -194,7 +194,7 @@ void testWithIO() { } writer.finish(); - podio::ROOTFrameReader reader; + podio::ROOTReader reader; reader.openFile("relation_range_io_test.root"); for (int i = 0; i < 10; ++i) { diff --git a/tests/root_io/write_frame_root.cpp b/tests/root_io/write_frame_root.cpp index fd1d89beb..2ad648e36 100644 --- a/tests/root_io/write_frame_root.cpp +++ b/tests/root_io/write_frame_root.cpp @@ -1,8 +1,8 @@ #include "write_frame.h" -#include "podio/ROOTFrameWriter.h" +#include "podio/ROOTWriter.h" int main(int, char**) { - write_frames("example_frame.root"); + write_frames("example_frame.root"); return 0; } diff --git a/tests/schema_evolution/root_io/read_new_data_root.cpp b/tests/schema_evolution/root_io/read_new_data_root.cpp index 77f5736a4..b69306478 100644 --- a/tests/schema_evolution/root_io/read_new_data_root.cpp +++ b/tests/schema_evolution/root_io/read_new_data_root.cpp @@ -1,7 +1,7 @@ #include "read_new_data.h" -#include "podio/ROOTFrameReader.h" +#include "podio/ROOTReader.h" int main() { - return read_new_data("example_data_old_schema.root"); + return read_new_data("example_data_old_schema.root"); } diff --git a/tests/schema_evolution/root_io/write_old_data_root.cpp b/tests/schema_evolution/root_io/write_old_data_root.cpp index a3456229f..dcd971d08 100644 --- a/tests/schema_evolution/root_io/write_old_data_root.cpp +++ b/tests/schema_evolution/root_io/write_old_data_root.cpp @@ -1,7 +1,7 @@ #include "schema_evolution/write_old_data.h" -#include "podio/ROOTFrameWriter.h" +#include "podio/ROOTWriter.h" int main() { - return writeData("example_data_old_schema.root"); + return writeData("example_data_old_schema.root"); } diff --git a/tests/sio_io/read_and_write_frame_sio.cpp b/tests/sio_io/read_and_write_frame_sio.cpp index 27a2ae76c..003d80ea4 100644 --- a/tests/sio_io/read_and_write_frame_sio.cpp +++ b/tests/sio_io/read_and_write_frame_sio.cpp @@ -1,9 +1,9 @@ #include "read_and_write_frame.h" -#include "podio/SIOFrameReader.h" -#include "podio/SIOFrameWriter.h" +#include "podio/SIOReader.h" +#include "podio/SIOWriter.h" int main() { - return rewrite_frames("example_frame.sio", "rewritten_frame.sio") + - read_rewritten_frames("rewritten_frame.sio"); + return rewrite_frames("example_frame.sio", "rewritten_frame.sio") + + read_rewritten_frames("rewritten_frame.sio"); } diff --git a/tests/sio_io/read_frame_sio.cpp b/tests/sio_io/read_frame_sio.cpp index 625a7748e..8a27743ac 100644 --- a/tests/sio_io/read_frame_sio.cpp +++ b/tests/sio_io/read_frame_sio.cpp @@ -1,7 +1,7 @@ #include "read_frame.h" #include "read_frame_auxiliary.h" -#include "podio/SIOFrameReader.h" +#include "podio/SIOReader.h" int main(int argc, char* argv[]) { std::string inputFile = "example_frame.sio"; @@ -11,6 +11,6 @@ int main(int argc, char* argv[]) { assertBuildVersion = false; } - return read_frames(inputFile, assertBuildVersion) + - test_frame_aux_info(inputFile); + return read_frames(inputFile, assertBuildVersion) + + test_frame_aux_info(inputFile); } diff --git a/tests/sio_io/read_python_frame_sio.cpp b/tests/sio_io/read_python_frame_sio.cpp index 61c3eb481..5307c1038 100644 --- a/tests/sio_io/read_python_frame_sio.cpp +++ b/tests/sio_io/read_python_frame_sio.cpp @@ -1,7 +1,7 @@ #include "read_python_frame.h" -#include "podio/SIOFrameReader.h" +#include "podio/SIOReader.h" int main() { - return read_frame("example_frame_with_py.sio"); + return read_frame("example_frame_with_py.sio"); } diff --git a/tests/sio_io/write_frame_sio.cpp b/tests/sio_io/write_frame_sio.cpp index 31df08171..21cd740ca 100644 --- a/tests/sio_io/write_frame_sio.cpp +++ b/tests/sio_io/write_frame_sio.cpp @@ -1,8 +1,8 @@ #include "write_frame.h" -#include "podio/SIOFrameWriter.h" +#include "podio/SIOWriter.h" int main(int, char**) { - write_frames("example_frame.sio"); + write_frames("example_frame.sio"); return 0; } diff --git a/tests/unittests/unittest.cpp b/tests/unittests/unittest.cpp index 2a32750e5..d3d5f8937 100644 --- a/tests/unittests/unittest.cpp +++ b/tests/unittests/unittest.cpp @@ -14,17 +14,17 @@ // podio specific includes #include "podio/Frame.h" #include "podio/GenericParameters.h" -#include "podio/ROOTFrameReader.h" -#include "podio/ROOTFrameWriter.h" #include "podio/ROOTLegacyReader.h" +#include "podio/ROOTReader.h" +#include "podio/ROOTWriter.h" #include "podio/podioVersion.h" #ifndef PODIO_ENABLE_SIO #define PODIO_ENABLE_SIO 0 #endif #if PODIO_ENABLE_SIO - #include "podio/SIOFrameReader.h" #include "podio/SIOLegacyReader.h" + #include "podio/SIOReader.h" #endif #if PODIO_ENABLE_RNTUPLE @@ -1099,7 +1099,7 @@ TEST_CASE("Missing files (ROOT readers)", "[basics]") { auto root_legacy_reader = podio::ROOTLegacyReader(); REQUIRE_THROWS_AS(root_legacy_reader.openFile("NonExistentFile.root"), std::runtime_error); - auto root_frame_reader = podio::ROOTFrameReader(); + auto root_frame_reader = podio::ROOTReader(); REQUIRE_THROWS_AS(root_frame_reader.openFile("NonExistentFile.root"), std::runtime_error); } @@ -1108,7 +1108,7 @@ TEST_CASE("Missing files (SIO readers)", "[basics]") { auto sio_legacy_reader = podio::SIOLegacyReader(); REQUIRE_THROWS_AS(sio_legacy_reader.openFile("NonExistentFile.sio"), std::runtime_error); - auto sio_frame_reader = podio::SIOFrameReader(); + auto sio_frame_reader = podio::SIOReader(); REQUIRE_THROWS_AS(sio_frame_reader.openFile("NonExistentFile.root"), std::runtime_error); } #endif @@ -1155,7 +1155,7 @@ TEST_CASE("JSON", "[json]") { // Write a template function that can be used with different writers in order to // be able to tag the unittests differently. This is necessary because the -// ROOTFrameWriter fails with ASan, but the ROOTNTuple writer doesn't +// ROOTWriter fails with ASan, but the ROOTNTuple writer doesn't template void runConsistentFrameTest(const std::string& filename) { using Catch::Matchers::ContainsSubstring; @@ -1225,13 +1225,13 @@ void runCheckConsistencyTest(const std::string& filename) { REQUIRE_THAT(superfluous, UnorderedEquals({"non-existant"})); } -TEST_CASE("ROOTFrameWriter consistent frame contents", "[ASAN-FAIL][UBSAN-FAIL][THREAD-FAIL][basics][root]") { +TEST_CASE("ROOTWriter consistent frame contents", "[ASAN-FAIL][UBSAN-FAIL][THREAD-FAIL][basics][root]") { // The UBSAN-FAIL and TSAN-FAIL only happens on clang12 in CI. - runConsistentFrameTest("unittests_frame_consistency.root"); + runConsistentFrameTest("unittests_frame_consistency.root"); } -TEST_CASE("ROOTFrameWriter check consistency", "[ASAN-FAIL][UBSAN-FAIL][basics][root]") { - runCheckConsistencyTest("unittests_frame_check_consistency.root"); +TEST_CASE("ROOTWriter check consistency", "[ASAN-FAIL][UBSAN-FAIL][basics][root]") { + runCheckConsistencyTest("unittests_frame_check_consistency.root"); } #if PODIO_ENABLE_RNTUPLE