Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-22 04:08:30

0001 #include "IOPool/Streamer/interface/StreamerFileIO.h"
0002 #include <fstream>
0003 #include <iostream>
0004 #include "FWCore/Utilities/interface/Adler32Calculator.h"
0005 #include "FWCore/Utilities/interface/Exception.h"
0006 
0007 namespace edm::streamer {
0008   OutputFile::OutputFile(const std::string& name)
0009       : current_offset_(1),
0010         do_adler_(false),
0011         adlera_(1),
0012         adlerb_(0),
0013         ost_(new std::ofstream(name.c_str(), std::ios_base::binary | std::ios_base::out)),
0014         filename_(name) {
0015     if (!ost_->is_open()) {
0016       throw cms::Exception("OutputFile", "OutputFile") << "Error Opening Output File: " << name << "\n";
0017     }
0018     ost_->rdbuf()->pubsetbuf(nullptr, 0);
0019   }
0020 
0021   OutputFile::~OutputFile() { ost_->close(); }
0022 
0023   bool OutputFile::write(const char* ptr, size_t n) {
0024     ost_->write(ptr, n);
0025     if (!ost_->fail()) {
0026       current_offset_ += (uint64)(n);
0027       if (do_adler_)
0028         cms::Adler32(ptr, n, adlera_, adlerb_);
0029       return false;
0030     }
0031     return true;
0032   }
0033 
0034   void OutputFile::close() { ost_->close(); }
0035 }  // namespace edm::streamer