Skip to content

Commit

Permalink
Check if the data passed to the frame model is not a nullptr (#578)
Browse files Browse the repository at this point in the history
* Check if the data passed to the frame model is not a nullptr

* Update constructor docs and error message

---------

Co-authored-by: jmcarcell <[email protected]>
  • Loading branch information
jmcarcell and jmcarcell authored Apr 11, 2024
1 parent 5964958 commit eb24243
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions include/podio/Frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ class Frame {
///
/// @tparam FrameDataT Arbitrary data container that provides access to the
/// collection buffers as well as the metadata, when
/// requested by the Frame.
/// requested by the Frame. The unique_ptr has to be checked
/// for validity before calling this construtor.
///
/// @throws std::invalid_argument if the passed pointer is a nullptr.
template <typename FrameDataT>
Frame(std::unique_ptr<FrameDataT>);

Expand Down Expand Up @@ -391,11 +394,15 @@ const CollT& Frame::put(CollT&& coll, const std::string& name) {

template <typename FrameDataT>
Frame::FrameModel<FrameDataT>::FrameModel(std::unique_ptr<FrameDataT> data) :
m_mapMtx(std::make_unique<std::mutex>()),
m_data(std::move(data)),
m_dataMtx(std::make_unique<std::mutex>()),
m_idTable(std::move(m_data->getIDTable())),
m_parameters(std::move(m_data->getParameters())) {
m_mapMtx(std::make_unique<std::mutex>()), m_dataMtx(std::make_unique<std::mutex>()) {
if (!data) {
throw std::invalid_argument(
"FrameData is a nullptr. If you are reading from a file it may be corrupted or you may reading beyond the end "
"of the file, please check the validity of the data before creating a Frame.");
}
m_data = std::move(data);
m_idTable = std::move(m_data->getIDTable());
m_parameters = std::move(m_data->getParameters());
}

template <typename FrameDataT>
Expand Down

0 comments on commit eb24243

Please sign in to comment.