Skip to content

Commit

Permalink
Moving doc strings to header file
Browse files Browse the repository at this point in the history
  • Loading branch information
kjvbrt committed Jul 8, 2024
1 parent 9dcfd4c commit 776769c
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 74 deletions.
89 changes: 83 additions & 6 deletions include/podio/ROOTDataSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,87 @@ namespace podio {

class ROOTDataSource : public ROOT::RDF::RDataSource {
public:
///
/// @brief Construct the podio::ROOTDataSource from the provided file.
///
explicit ROOTDataSource(const std::string& filePath, int nEvents = -1);

///
/// @brief Construct the podio::ROOTDataSource from the provided file
/// list.
///
explicit ROOTDataSource(const std::vector<std::string>& filePathList,
int nEvents = -1);

///
/// @brief Inform the podio::ROOTDataSource of the desired level of
/// parallelism.
///
void SetNSlots(unsigned int nSlots) override;

///
/// @brief Retrieve from podio::ROOTDataSource per-thread readers for the
/// desired columns.
///
template<typename T>
std::vector<T**> GetColumnReaders(std::string_view columnName);

///
/// @brief Inform podio::ROOTDataSource that an event-loop is about to
/// start.
///
void Initialize() override;

///
/// @brief Retrieve from podio::ROOTDataSource a set of ranges of entries
/// that can be processed concurrently.
///
std::vector<std::pair<ULong64_t, ULong64_t>> GetEntryRanges() override;

///
/// @brief Inform podio::ROOTDataSource that a certain thread is about to
/// start working on a certain range of entries.
///
void InitSlot(unsigned int slot, ULong64_t firstEntry) override;

///
/// @brief Inform podio::ROOTDataSource that a certain thread is about to
/// start working on a certain entry.
///
bool SetEntry(unsigned int slot, ULong64_t entry) override;

///
/// @brief Inform podio::ROOTDataSource that a certain thread finished
/// working on a certain range of entries.
///
void FinalizeSlot(unsigned int slot) override;

///
/// @brief Inform podio::ROOTDataSource that an event-loop finished.
///
void Finalize() override;

///
/// @brief Returns a reference to the collection of the dataset's column
/// names
///
const std::vector<std::string>& GetColumnNames() const override;

///
/// @brief Checks if the dataset has a certain column.
///
bool HasColumn(std::string_view columnName) const override;

///
/// @brief Type of a column as a string. Required for JITting.
///
std::string GetTypeName(std::string_view columnName) const override;

protected:
///
/// @brief Type-erased vector of pointers to pointers to column
/// values --- one per slot.
///
Record_t GetColumnReadersImpl (
std::string_view name,
const std::type_info& typeInfo) override;
Expand All @@ -56,35 +109,46 @@ namespace podio {
private:
/// Number of slots/threads
unsigned int m_nSlots = 1;

/// Input filename
std::vector<std::string> m_filePathList = {};

/// Total number of events
unsigned int m_nEvents = 0;

/// Ranges of events available to be processed
std::vector<std::pair<ULong64_t, ULong64_t>> m_rangesAvailable = {};

/// Ranges of events available ever created
std::vector<std::pair<ULong64_t, ULong64_t>> m_rangesAll = {};

/// Column names
std::vector<std::string> m_columnNames {};

/// Column types
std::vector<std::string> m_columnTypes = {};

/// Collections, m_Collections[columnIndex][slotIndex]
std::vector<std::vector<const podio::CollectionBase*>> m_Collections = {};

/// Active collections
std::vector<unsigned int> m_activeCollections = {};

/// Root podio readers
std::vector<std::unique_ptr<podio::ROOTReader>> m_podioReaders = {};

/// Podio frames
std::vector<std::unique_ptr<podio::Frame>> m_frames = {};
/// Setup input

///
/// @brief Setup input for the podio::ROOTDataSource.
///
/// @param[in] Number of events.
/// @return void.
///
void SetupInput(int nEvents);
};


/**
* \brief Retrieve from podio::ROOTDataSource per-thread readers for the
* desired columns.
*/
template<typename T>
std::vector<T**>
ROOTDataSource::GetColumnReaders(std::string_view columnName) {
Expand All @@ -96,8 +160,21 @@ namespace podio {
return readers;
}

///
/// @brief Create RDataFrame from multiple Podio files.
///
/// @param[in] filePathList List of file paths from which the RDataFrame
/// will be created.
/// @return RDataFrame created from input file list.
///
ROOT::RDataFrame CreateDataFrame(const std::vector<std::string>& filePathList);

///
/// @brief Create RDataFrame from a Podio file.
///
/// @param[in] filePath File path from which the RDataFrame will be created.
/// @return RDataFrame created from input file list.
///
ROOT::RDataFrame CreateDataFrame(const std::string& filePath);
}

Expand Down
76 changes: 8 additions & 68 deletions src/ROOTDataSource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,24 @@
#include <podio/Frame.h>
#include <podio/ROOTReader.h>

bool loadROOTDataSource() {
return true;
}

namespace podio {
///
/// @brief Construct the podio::ROOTDataSource from the provided file.
///
ROOTDataSource::ROOTDataSource(const std::string& filePath,
int nEvents) : m_nSlots{1} {
m_filePathList.emplace_back(filePath);
SetupInput(nEvents);
}

///
/// @brief Construct the podio::ROOTDataSource from the provided file list.
///

ROOTDataSource::ROOTDataSource(
const std::vector<std::string>& filePathList,
int nEvents) : m_nSlots{1},
m_filePathList{filePathList} {
SetupInput(nEvents);
}

///
/// @brief Setup input for the podio::ROOTDataSource.
///

/// @TODO Check for the existence of the file, which might be coming from web
/// or EOS.
void ROOTDataSource::SetupInput(int nEvents) {
// std::cout << "podio::ROOTDataSource: Constructing the source ..." << std::endl;

Expand All @@ -51,7 +42,6 @@ namespace podio {

for (const auto& filePath : m_filePathList) {
// Check if file exists
// TODO: file can be coming from web or eos
// if (!std::filesystem::exists(filePath)) {
// throw std::runtime_error("podio::ROOTDataSource: Provided file \""
// + filePath + "\" does not exist!");
Expand Down Expand Up @@ -116,9 +106,6 @@ namespace podio {
}


///
/// @brief Inform the podio::ROOTDataSource of the desired level of parallelism.
///
void
ROOTDataSource::SetNSlots(unsigned int nSlots) {
// std::cout << "podio::ROOTDataSource: Setting num. of slots to: " << nSlots
Expand Down Expand Up @@ -158,19 +145,12 @@ namespace podio {
}


///
/// @brief Inform podio::ROOTDataSource that an event-loop is about to start.
///
void
ROOTDataSource::Initialize() {
// std::cout << "podio::ROOTDataSource: Initializing the source ..." << std::endl;
}


///
/// @brief Retrieve from podio::ROOTDataSource a set of ranges of entries that can be
/// processed concurrently.
///
std::vector<std::pair<ULong64_t, ULong64_t>>
ROOTDataSource::GetEntryRanges() {
// std::cout << "podio::ROOTDataSource: Getting entry ranges ..." << std::endl;
Expand Down Expand Up @@ -217,10 +197,6 @@ namespace podio {
}


///
/// @brief Inform podio::ROOTDataSource that a certain thread is about to start working
/// on a certain range of entries.
///
void
ROOTDataSource::InitSlot([[maybe_unused]] unsigned int slot,
[[maybe_unused]] ULong64_t firstEntry) {
Expand All @@ -229,10 +205,6 @@ namespace podio {
}


///
/// @brief Inform podio::ROOTDataSource that a certain thread is about to start working
/// on a certain entry.
///
bool
ROOTDataSource::SetEntry(unsigned int slot, ULong64_t entry) {
// std::cout << "podio::ROOTDataSource: In slot: " << slot << ", setting entry: "
Expand All @@ -258,10 +230,6 @@ namespace podio {
}


///
/// @brief Inform podio::ROOTDataSource that a certain thread finished working on a
/// certain range of entries.
///
void
ROOTDataSource::FinalizeSlot([[maybe_unused]] unsigned int slot) {
/*
Expand All @@ -280,19 +248,12 @@ namespace podio {
}


///
/// @brief Inform podio::ROOTDataSource that an event-loop finished.
///
void
ROOTDataSource::Finalize() {
// std::cout << "podio::ROOTDataSource: Finalizing ..." << std::endl;
}


///
/// @brief Type-erased vector of pointers to pointers to column values --- one
/// per slot
///
Record_t
ROOTDataSource::GetColumnReadersImpl(
std::string_view columnName,
Expand Down Expand Up @@ -338,19 +299,14 @@ namespace podio {
}


///
/// @brief Returns a reference to the collection of the dataset's column names
///
const std::vector<std::string>&
ROOTDataSource::GetColumnNames() const {
// std::cout << "podio::ROOTDataSource: Looking for column names" << std::endl;

return m_columnNames;
}

///
/// @brief Checks if the dataset has a certain column.
///

bool
ROOTDataSource::HasColumn(std::string_view columnName) const {
// std::cout << "podio::ROOTDataSource: Looking for column: " << columnName
Expand All @@ -366,9 +322,6 @@ namespace podio {
}


///
/// @brief Type of a column as a string. Required for JITting.
///
std::string
ROOTDataSource::GetTypeName(std::string_view columnName) const {
// std::cout << "podio::ROOTDataSource: Looking for type name of column: "
Expand All @@ -387,31 +340,18 @@ namespace podio {
return "float";
}

///
/// @brief Create RDataFrame from multiple Podio files.
///
/// @param[in] filePathList List of file paths from which the RDataFrame
/// will be created.
/// @return RDataFrame created from input file list.
///

ROOT::RDataFrame
CreateDataFrame(const std::vector<std::string>& filePathList) {
ROOT::RDataFrame rdf(std::make_unique<ROOTDataSource>(filePathList));

return rdf;
}

///
/// @brief Create RDataFrame from a Podio file.
///
/// @param[in] filePath File path from which the RDataFrame will be created.
/// @return RDataFrame created from input file list.
///

ROOT::RDataFrame
CreateDataFrame(const std::string& filePath) {
std::vector<std::string> filePathList;
filePathList.emplace_back(filePath);
ROOT::RDataFrame rdf(std::make_unique<ROOTDataSource>(filePathList));
ROOT::RDataFrame rdf(std::make_unique<ROOTDataSource>(filePath));

return rdf;
}
Expand Down

0 comments on commit 776769c

Please sign in to comment.