apps/argos/EntryPoint.hpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // <EntryPoint.hpp> -*- C++ -*- | ||
| 2 | |||
| 3 | #pragma once | ||
| 4 | |||
| 5 | #include "simdb/Assert.hpp" | ||
| 6 | #include "simdb/apps/argos/EnumInspector.hpp" | ||
| 7 | #include "simdb/apps/argos/PipelineDataTypes.hpp" | ||
| 8 | #include "simdb/apps/argos/PipelineStagerInterface.hpp" | ||
| 9 | #include "simdb/utils/Demangle.hpp" | ||
| 10 | #include "simdb/utils/TinyStrings.hpp" | ||
| 11 | #include "simdb/utils/TypeTraits.hpp" | ||
| 12 | |||
| 13 | namespace simdb::argos { | ||
| 14 | |||
| 15 | //! \class EntryPoint | ||
| 16 | //! \brief Main entry point into Argos collection. | ||
| 17 | //! | ||
| 18 | //! TODO cnyce: These need to be template classes when the collection | ||
| 19 | //! code from Sparta is moved into SimDB. | ||
| 20 | class EntryPoint | ||
| 21 | { | ||
| 22 | public: | ||
| 23 | 91 | EntryPoint(PipelineStagerInterface* stager_interface, TinyStrings<>* tiny_strings) : | |
| 24 | 91 | stager_interface_(stager_interface), | |
| 25 | 91 | tiny_strings_(tiny_strings) | |
| 26 | { | ||
| 27 | 91 | } | |
| 28 | |||
| 29 | /// Get the unique ID for this collection point. | ||
| 30 | 222147 | uint16_t getID() const { return cid_; } | |
| 31 | |||
| 32 | /// Suppress heartbeat re-emission of previously seen bytes. | ||
| 33 | 4595 | void closeRecord() | |
| 34 | { | ||
| 35 | 4595 | if (!closed_) | |
| 36 | { | ||
| 37 | 4412 | closed_ = true; | |
| 38 | 4412 | stager_interface_->closeRecord(getID()); | |
| 39 | } | ||
| 40 | 4595 | } | |
| 41 | |||
| 42 | /// For testing purposes only. DO NOT CALL IN PRODUCTION. | ||
| 43 | 5 | static void resetCIDs() { nextCID_() = 0; } | |
| 44 | |||
| 45 | TinyStrings<>* getTinyStrings() const { return tiny_strings_; } | ||
| 46 | |||
| 47 | //! NOTE: We only have setScalarValueBytes(), setContigContainerBinBytes() | ||
| 48 | //! and setSparseContainerBinBytes() all together in one class temporarily | ||
| 49 | //! until Sparta/SimDB collection is merged. When the entry point class | ||
| 50 | //! becomes a template, these will collapse to one method (<T> decides | ||
| 51 | //! the input data structure). | ||
| 52 | 13008 | void setScalarValueBytes(std::vector<char>&& scalar_bytes) | |
| 53 | { | ||
| 54 | 13008 | if (scalar_bytes.empty()) | |
| 55 | { | ||
| 56 | ✗ | closeRecord(); | |
| 57 | ✗ | return; | |
| 58 | } | ||
| 59 | 13008 | closed_ = false; | |
| 60 | 13008 | stager_interface_->stage(getID(), std::move(scalar_bytes)); | |
| 61 | } | ||
| 62 | |||
| 63 | //! \see setScalarValueBytes | ||
| 64 | 12810 | void setContigContainerBinBytes(std::vector<std::vector<char>>&& contig_bin_bytes) | |
| 65 | { | ||
| 66 | 12810 | if (contig_bin_bytes.empty()) | |
| 67 | { | ||
| 68 | 795 | closeRecord(); | |
| 69 | 795 | return; | |
| 70 | } | ||
| 71 | 12015 | closed_ = false; | |
| 72 | 12015 | stager_interface_->stage(getID(), std::move(contig_bin_bytes)); | |
| 73 | } | ||
| 74 | |||
| 75 | //! \see setScalarValueBytes | ||
| 76 | 13230 | void setSparseContainerBinBytes(std::map<uint16_t, std::vector<char>>&& sparse_bin_bytes) | |
| 77 | { | ||
| 78 | 13230 | if (sparse_bin_bytes.empty()) | |
| 79 | { | ||
| 80 | 792 | closeRecord(); | |
| 81 | 792 | return; | |
| 82 | } | ||
| 83 | 12438 | closed_ = false; | |
| 84 | 12438 | stager_interface_->stage(getID(), std::move(sparse_bin_bytes)); | |
| 85 | } | ||
| 86 | |||
| 87 | private: | ||
| 88 | /// Unique ID generator. | ||
| 89 | 96 | static uint16_t& nextCID_() | |
| 90 | { | ||
| 91 | static uint16_t counter = 0; | ||
| 92 | 96 | simdb_assert(counter != UINT16_MAX, "Max number of collectables exceeded (" << UINT16_MAX << ")"); | |
| 93 | 96 | ++counter; | |
| 94 | 96 | return counter; | |
| 95 | } | ||
| 96 | |||
| 97 | /// Unique collectable ID | ||
| 98 | const uint16_t cid_{nextCID_()}; | ||
| 99 | |||
| 100 | /// Suppress heartbeat re-emission while true | ||
| 101 | bool closed_ = true; | ||
| 102 | |||
| 103 | /// Most of what EntryPoint does is forward to the stager (ledger) | ||
| 104 | PipelineStagerInterface* const stager_interface_; | ||
| 105 | |||
| 106 | /// DB-backed string-to-int mapping | ||
| 107 | TinyStrings<>* const tiny_strings_; | ||
| 108 | }; | ||
| 109 | |||
| 110 | } // namespace simdb::argos | ||
| 111 |