Skip to content

Commit

Permalink
log an error message for empty files
Browse files Browse the repository at this point in the history
  • Loading branch information
arahlin committed Jan 24, 2024
1 parent 684baa8 commit d7bf616
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions core/include/core/G3Reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class G3Reader : public G3Module {
boost::iostreams::filtering_istream stream_;
int n_frames_to_read_;
int n_frames_read_;
int n_frames_cur_;
float timeout_;
bool track_filename_;

Expand Down
10 changes: 8 additions & 2 deletions core/src/G3Reader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
G3Reader::G3Reader(std::string filename, int n_frames_to_read,
float timeout, bool track_filename) :
prefix_file_(false), n_frames_to_read_(n_frames_to_read),
n_frames_read_(0), timeout_(timeout), track_filename_(track_filename)
n_frames_read_(0), n_frames_cur_(0), timeout_(timeout),
track_filename_(track_filename)
{
boost::filesystem::path fpath(filename);
if (filename.find("://") == std::string::npos &&
Expand All @@ -20,7 +21,8 @@ G3Reader::G3Reader(std::string filename, int n_frames_to_read,
G3Reader::G3Reader(std::vector<std::string> filename, int n_frames_to_read,
float timeout, bool track_filename) :
prefix_file_(false), n_frames_to_read_(n_frames_to_read),
n_frames_read_(0), timeout_(timeout), track_filename_(track_filename)
n_frames_read_(0), n_frames_cur_(0), timeout_(timeout),
track_filename_(track_filename)
{
if (filename.size() == 0)
log_fatal("Empty file list provided to G3Reader");
Expand All @@ -41,6 +43,7 @@ void G3Reader::StartFile(std::string path)
{
log_info("Starting file %s\n", path.c_str());
cur_file_ = path;
n_frames_cur_ = 0;
(void) g3_istream_from_path(stream_, path, timeout_);
}

Expand Down Expand Up @@ -81,6 +84,8 @@ void G3Reader::Process(G3FramePtr frame, std::deque<G3FramePtr> &out)
_save = PyEval_SaveThread();

while (stream_.peek() == EOF) {
if (n_frames_cur_ == 0)
log_error("Empty file %s", cur_file_.c_str());
if (filename_.size() > 0) {
StartFile(filename_.front());
filename_.pop_front();
Expand Down Expand Up @@ -109,6 +114,7 @@ void G3Reader::Process(G3FramePtr frame, std::deque<G3FramePtr> &out)
out.push_back(frame);

n_frames_read_++;
n_frames_cur_++;
}

off_t G3Reader::Seek(off_t offset) {
Expand Down

0 comments on commit d7bf616

Please sign in to comment.