Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

thinking about the data source, background loading and data transport mess #975

Draft
wants to merge 34 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
4fa3e8f
Is this how we want to put it?
reinago Jan 21, 2022
2134538
frames should (de)serialize themselves
reinago Jan 21, 2022
316aef4
Merge remote-tracking branch 'origin/master' into datasource_concept
reinago Jan 24, 2022
6fd7507
fixes
reinago Jan 24, 2022
8552920
more tinkering and open questions
reinago Jan 25, 2022
7a1f39f
before I forget
reinago Jan 25, 2022
c15b9f9
more plumbing
reinago Jan 25, 2022
2dbd4bb
cleanup
reinago Jan 25, 2022
e6de7d8
cleanup and bug fix (thx Adrian)
reinago Jan 25, 2022
f2e2696
tinkering with LRU from Adrian
reinago Jan 28, 2022
f72bd28
meanwhile, a small fix for mmpldinfo
reinago Jan 31, 2022
efb74c6
tinkering...
reinago Feb 2, 2022
9ef222d
this is no good.
reinago Feb 2, 2022
614345d
still plot holes
reinago Feb 2, 2022
7c51703
Merge branch 'master' into datasource_concept
reinago Feb 3, 2022
af577cd
we really have some weird MMPLD files flying around...
reinago Feb 3, 2022
50a3cf3
frametable hex to facilitate manual fixing
reinago Feb 4, 2022
5a43922
tiny cosmetic fix in graph errors
reinago Feb 10, 2022
a21d296
another error output fix
reinago Feb 10, 2022
d9de523
more tinkering
reinago Feb 10, 2022
ef1c94a
dispatch example
gralkapk Feb 14, 2022
6fa917e
Apply the hammer of Gralka!
reinago Feb 14, 2022
c79044b
even more fun
reinago Feb 14, 2022
e6d6fa1
const for thoroughness
reinago Feb 15, 2022
851db60
still not happy
reinago Feb 16, 2022
58b410a
cleanup
reinago Feb 16, 2022
6c68385
we accidentally designed a channel, not a frame
reinago Feb 17, 2022
4fe2345
surface lic does something, but might be broken
reinago Feb 17, 2022
f5aa7f6
fixed bug in tablecolumnfilter
reinago Feb 17, 2022
7f0e968
typo
reinago Mar 3, 2022
7a0a4ca
Clear before rendering, as FBO is reused and may not be empty
straubar Mar 4, 2022
5a4b860
Use glowl Framebuffer and correct chaining mechanism, both for callin…
straubar Mar 4, 2022
cf8a1bf
Merge remote-tracking branch 'origin/master' into datasource_concept
reinago Mar 14, 2022
7331b09
Merge branch 'master' into datasource_concept
reinago Mar 16, 2022
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
3 changes: 3 additions & 0 deletions core/src/CoreInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3236,6 +3236,9 @@ void megamol::core::CoreInstance::loadPlugin(
} catch (const vislib::Exception& vex) {
megamol::core::utility::log::Log::DefaultLog.WriteMsg(
loadFailedLevel, "Unable to load Plugin: %s (%s, &d)", vex.GetMsgA(), vex.GetFile(), vex.GetLine());
} catch (const std::exception& ex) {
megamol::core::utility::log::Log::DefaultLog.WriteMsg(
loadFailedLevel, "Unable to load Plugin: %s", ex.what());
} catch (...) {
megamol::core::utility::log::Log::DefaultLog.WriteMsg(
loadFailedLevel, "Unable to load Plugin: unknown exception");
Expand Down
4 changes: 2 additions & 2 deletions core/src/MegaMolGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ bool megamol::core::MegaMolGraph::add_call(CallInstantiationRequest_t const& req
if (!slots.empty()) {
slot_names = "";
for (auto x = 0; x < slots.size() - 1; ++x) {
slot_names += slots[x]->Name();
slot_names += slots[x]->Name() + ", ";
}
slot_names += slots[slots.size() - 1]->Name();
}
Expand All @@ -620,7 +620,7 @@ bool megamol::core::MegaMolGraph::add_call(CallInstantiationRequest_t const& req
if (!slots.empty()) {
slot_names = "";
for (auto x = 0; x < slots.size() - 1; ++x) {
slot_names += slots[x]->Name();
slot_names += slots[x]->Name() + ", ";
}
slot_names += slots[slots.size() - 1]->Name();
}
Expand Down
39 changes: 39 additions & 0 deletions plugins/datatools/include/datatools/io/dataformat/CSVDataFormat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma once

#include "DataFormat.h"

namespace megamol {
namespace datatools {
namespace io {
namespace dataformat {

struct CSVColumnInfo {
std::string name;
// TODO
};

struct CSVFrame : AbstractFrame {
using FrameIndexType = uint32_t;
using DataIndexType = uint32_t;

FrameIndexType FrameIndex = 0;
DataIndexType NumColumns = 0;
DataIndexType NumRows = 0;
std::vector<CSVColumnInfo> ColumnInfos;
std::vector<float> Values;

//bool Read(std::ifstream& io) override {
// return true;
//}
//bool Write(std::ofstream& io) override {
// return true;
//}
};

using CSVDataFormat = AbstractDataFormat<CSVFrame>;
using CSVFileCollection = FolderContainer<CSVDataFormat>;

} // namespace dataformat
} // namespace io
} // namespace datatools
} // namespace megamol
170 changes: 170 additions & 0 deletions plugins/datatools/include/datatools/io/dataformat/DataFormat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
#pragma once

#include <filesystem>
#include <fstream>
#include <regex>
#include <vector>

#include "LRUCache.h"

namespace megamol {
namespace datatools {
namespace io {
namespace dataformat {

// every call ideally should implement this, as a generic interface for "brain dumps"
// this has *nothing* to do with proper file formats. readers support these to provide data via the said call
struct AbstractFrame {
virtual ~AbstractFrame() = default;
virtual void Read(std::istream& io) = 0;
virtual void Write(std::ostream& io) const = 0;
[[nodiscard]] virtual std::size_t ByteSize() const = 0;
};

struct AbstractMetadata {
using FrameIndexType = uint32_t;
};

struct AbstractNaming {
virtual ~AbstractNaming() = default;
virtual std::regex Pattern() = 0;
};

template<typename FrameIndexType>
struct BaseNumbering {
virtual ~BaseNumbering() = default;

BaseNumbering(uint8_t digits = 5) : digits(digits) {
reg = std::regex(std::string("(\d{") + std::to_string(digits) + "})");
}

virtual FrameIndexType ExtractNumber(std::string filename) {
std::smatch matches;
if (std::regex_match(filename, matches, reg)) {
return std::stoi(matches[0].str());
}
return static_cast<FrameIndexType>(0);
}

virtual std::string MakeFileName(std::string prefix, FrameIndexType idx) {
std::stringstream str;
str << std::setfill('0') << std::setw(digits) << idx;
return prefix + str.str();
}

private:
std::regex reg;
uint8_t digits;
};

template<class Frame>
class AbstractDataFormat {
public:
virtual ~AbstractDataFormat() = default;
using FrameType = Frame;
using FileType = std::filesystem::directory_entry;

//virtual std::unique_ptr<Frame> ReadFrame(std::ifstream& io, FrameIndexType idx) = 0;
//virtual void WriteFrame(std::ofstream& io, Frame const& frame) = 0;
};

// TODO read-ahead number
template<class Format>
class AbstractDataContainer {
public:
using FormatType = Format;
using FrameType = typename Format::FrameType;
using FrameIndexType = typename FrameType::FrameIndexType;
using FrameCollection = LRUCache<AbstractDataContainer>;

AbstractDataContainer(FrameIndexType readAhead = 3)
: readAhead(readAhead)
, frames(LRUCache<AbstractDataContainer>()) {
}

virtual ~AbstractDataContainer() = default;

// TODO generic EnumerateFrames that only files the frame indices with empty frames for now?
virtual FrameIndexType EnumerateFrames() = 0;

std::shared_ptr<FrameType> ReadFrame(FrameIndexType idx) {
// here we should actually grab the frames from some background thread that reads ahead and stuff?
return frames.findOrCreate(idx, *this);
}

void WriteFrame(FrameIndexType idx, FrameType const& frame) {}

virtual std::ifstream IndexToIStream(FrameIndexType idx) = 0;
virtual std::ofstream IndexToOStream(FrameIndexType idx) = 0;
protected:
FrameIndexType readAhead;
FrameCollection frames;
};

// A directory containing several files, one for each frame
template<class Format>
class FolderContainer : public AbstractDataContainer<Format> {
// this container supports arbitrary insertion and appending
public:
using FileType = typename Format::FileType;
using FileListType = std::vector<FileType>;
using FrameIndexType = typename Format::FrameIndexType;

// TODO fix basenumbering

FolderContainer(std::string location, std::unique_ptr<AbstractNaming> naming,
std::unique_ptr<BaseNumbering<FrameIndexType>> numbering = std::make_unique<BaseNumbering<FrameIndexType>>())
: files(EnumerateFramesInDirectory(FileType(location)))
, naming(std::move(naming))
, numbering(std::move(numbering)) {
}

FrameIndexType EnumerateFrames() override {
return static_cast<FrameIndexType>(files.size());
}

FileListType EnumerateFramesInDirectory(FileType Path) {
auto r = std::regex(naming->Pattern());
FileListType fileList;
for (const auto& entry : std::filesystem::directory_iterator(Path)) {
if (std::regex_match(entry.path().filename().string(), r)) {
fileList.push_back(entry);
}
}
std::sort(fileList.begin(), fileList.end());
return fileList;
}

std::ifstream IndexToIStream(FrameIndexType idx) override {
return std::ifstream(files[idx].path().string().c_str(), std::ifstream::binary);
}
std::ofstream IndexToOStream(FrameIndexType idx) override {
// TODO some code for making paths when idx > what we already had
// TODO what about sparse stuff, i.e. when the numbers were not consecutive?
// TODO the clang dangling pointer
auto filename = files[idx].path().string().c_str();
return std::ofstream(filename, std::ifstream::binary);
}

private:
FileListType files;
std::unique_ptr<AbstractNaming> naming;
std::unique_ptr<BaseNumbering<FrameIndexType>> numbering;
};

// One big blob of data, each frame sitting at some offset
template<class Format>
class BlobContainer : public AbstractDataContainer<Format> {
// TODO this container does not support frame insertion. it should support frame appending.
// totally TODO actually
bool Open(std::string location) {
return true;
}
};

// some other containers...?

} // namespace dataformat
} // namespace io
} // namespace datatools
} // namespace megamol
Loading