Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:56:18

0001 #ifndef GENERS_BINARYFILEARCHIVE_HH_
0002 #define GENERS_BINARYFILEARCHIVE_HH_
0003 
0004 #include <cassert>
0005 
0006 #include "Alignment/Geners/interface/BinaryArchiveBase.hh"
0007 #include "Alignment/Geners/interface/CatalogIO.hh"
0008 
0009 namespace gs {
0010   class BinaryFileArchive : public BinaryArchiveBase {
0011   public:
0012     // See the note inside the "BinaryArchiveBase.hh" header
0013     // for the meaning of the "mode" argument
0014     BinaryFileArchive(const char *basename,
0015                       const char *mode,
0016                       const char *annotation = nullptr,
0017                       unsigned dataFileBufferSize = 1048576U,
0018                       unsigned catalogFileBufferSize = 131072U);
0019     ~BinaryFileArchive() override;
0020 
0021     void flush() override;
0022 
0023   private:
0024     void writeCatalog();
0025     void releaseBuffers();
0026 
0027     template <class Catalog>
0028     void readCatalog() {
0029       assert(!catalog());
0030       unsigned compressionMode;
0031       setCatalog(
0032           readBinaryCatalog<Catalog>(catStream_, &compressionMode, &catalogMergeLevel_, &catalogAnnotations_, true));
0033       assert(catalog());
0034       setCompressionMode(compressionMode);
0035     }
0036 
0037     // The following methods have to be overriden from the base
0038     std::ostream &plainOutputStream() override;
0039     std::istream &plainInputStream(unsigned long long id,
0040                                    unsigned *compressionCode,
0041                                    unsigned long long *length) override;
0042 
0043     unsigned long long addToCatalog(const AbsRecord &record,
0044                                     unsigned compressionCode,
0045                                     unsigned long long itemLength) override;
0046 
0047     char *filebuf_;
0048     char *catabuf_;
0049     std::string annotation_;
0050     std::string dataFileName_;
0051     std::string catalogFileName_;
0052     std::string dataFileURI_;
0053     std::fstream dataStream_;
0054     std::fstream catStream_;
0055     std::streampos lastpos_;
0056     std::streampos jumppos_;
0057     std::vector<std::string> catalogAnnotations_;
0058     unsigned catalogMergeLevel_;
0059     bool annotationsMerged_;
0060     bool streamFlushed_;
0061   };
0062 }  // namespace gs
0063 
0064 #endif  // GENERS_BINARYFILEARCHIVE_HH_