Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
#ifndef GENERS_BINARYFILEARCHIVE_HH_
#define GENERS_BINARYFILEARCHIVE_HH_

#include <cassert>

#include "Alignment/Geners/interface/BinaryArchiveBase.hh"
#include "Alignment/Geners/interface/CatalogIO.hh"

namespace gs {
  class BinaryFileArchive : public BinaryArchiveBase {
  public:
    // See the note inside the "BinaryArchiveBase.hh" header
    // for the meaning of the "mode" argument
    BinaryFileArchive(const char *basename,
                      const char *mode,
                      const char *annotation = nullptr,
                      unsigned dataFileBufferSize = 1048576U,
                      unsigned catalogFileBufferSize = 131072U);
    ~BinaryFileArchive() override;

    void flush() override;

  private:
    void writeCatalog();
    void releaseBuffers();

    template <class Catalog>
    void readCatalog() {
      assert(!catalog());
      unsigned compressionMode;
      setCatalog(
          readBinaryCatalog<Catalog>(catStream_, &compressionMode, &catalogMergeLevel_, &catalogAnnotations_, true));
      assert(catalog());
      setCompressionMode(compressionMode);
    }

    // The following methods have to be overriden from the base
    std::ostream &plainOutputStream() override;
    std::istream &plainInputStream(unsigned long long id,
                                   unsigned *compressionCode,
                                   unsigned long long *length) override;

    unsigned long long addToCatalog(const AbsRecord &record,
                                    unsigned compressionCode,
                                    unsigned long long itemLength) override;

    char *filebuf_;
    char *catabuf_;
    std::string annotation_;
    std::string dataFileName_;
    std::string catalogFileName_;
    std::string dataFileURI_;
    std::fstream dataStream_;
    std::fstream catStream_;
    std::streampos lastpos_;
    std::streampos jumppos_;
    std::vector<std::string> catalogAnnotations_;
    unsigned catalogMergeLevel_;
    bool annotationsMerged_;
    bool streamFlushed_;
  };
}  // namespace gs

#endif  // GENERS_BINARYFILEARCHIVE_HH_