Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:44:53

0001 #ifndef GENERS_MULTIFILEARCHIVE_HH_
0002 #define GENERS_MULTIFILEARCHIVE_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 MultiFileArchive : public BinaryArchiveBase {
0011   public:
0012     // See the note inside the "BinaryArchiveBase.hh" header
0013     // for the meaning of the "mode" argument
0014     MultiFileArchive(const char *basename,
0015                      const char *mode,
0016                      const char *annotation = nullptr,
0017                      unsigned typicalFileSizeInMB = 1000U,
0018                      unsigned dataFileBufferSize = 1048576U,
0019                      unsigned catalogFileBufferSize = 131072U);
0020     ~MultiFileArchive() override;
0021 
0022     void flush() override;
0023 
0024   private:
0025     void writeCatalog();
0026     void openWriteStream();
0027     void setupWriteStream();
0028     void updateReadStream(const std::string &uri);
0029     void releaseBuffers();
0030 
0031     template <class Catalog>
0032     void readCatalog() {
0033       assert(!catalog());
0034       unsigned compressionMode;
0035       setCatalog(
0036           readBinaryCatalog<Catalog>(catStream_, &compressionMode, &catalogMergeLevel_, &catalogAnnotations_, true));
0037       assert(catalog());
0038       setCompressionMode(compressionMode);
0039     }
0040 
0041     // The following methods have to be overriden from the base
0042     std::ostream &plainOutputStream() override;
0043     std::istream &plainInputStream(unsigned long long id,
0044                                    unsigned *compressionCode,
0045                                    unsigned long long *length) override;
0046 
0047     unsigned long long addToCatalog(const AbsRecord &record,
0048                                     unsigned compressionCode,
0049                                     unsigned long long itemLength) override;
0050 
0051     char *filebuf_;
0052     char *readbuf_;
0053     char *catabuf_;
0054     std::string annotation_;
0055     std::string catalogFileName_;
0056     std::string writeFileName_;
0057     std::string writeFileURI_;
0058     std::string readFileName_;
0059     std::string readFileURI_;
0060     std::fstream writeStream_;
0061     std::fstream catStream_;
0062     std::fstream separateReadStream_;
0063     std::streampos lastpos_;
0064     std::streampos jumppos_;
0065     std::streampos maxpos_;
0066     std::vector<std::string> catalogAnnotations_;
0067     unsigned long writeFileNumber_;
0068     unsigned catalogMergeLevel_;
0069     bool annotationsMerged_;
0070     bool streamFlushed_;
0071   };
0072 }  // namespace gs
0073 
0074 #endif  // GENERS_MULTIFILEARCHIVE_HH_