CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
edm::streamer::OutputFile Class Reference

#include <StreamerFileIO.h>

Public Member Functions

uint32 adler32 () const
 
void close ()
 
uint64 current_offset () const
 
std::string fileName () const
 
 OutputFile (const std::string &name, uint32 padding=0)
 
void set_current_offset (uint64 v)
 
void set_do_adler (bool v)
 
bool write (const char *ptr, size_t n, bool doPadding=false)
 
bool writePadding ()
 
 ~OutputFile ()
 

Private Attributes

uint32 adlera_
 
uint32 adlerb_
 
uint64 current_offset_
 
bool do_adler_
 
std::string filename_
 
edm::propagate_const< std::shared_ptr< std::ofstream > > ost_
 
uint32 padding_
 
std::unique_ptr< char[]> paddingBuf_
 

Detailed Description

Class representing Output (Streamer) file.

Definition at line 17 of file StreamerFileIO.h.

Constructor & Destructor Documentation

◆ OutputFile()

edm::streamer::OutputFile::OutputFile ( const std::string &  name,
uint32  padding = 0 
)
explicit

Definition at line 10 of file StreamerFileIO.cc.

References Exception, Skims_PA_cff::name, ost_, edm::streamer::Header::PADDING, padding_, and paddingBuf_.

11  : current_offset_(1),
12  do_adler_(false),
13  adlera_(1),
14  adlerb_(0),
15  padding_(padding),
16  ost_(new std::ofstream(name.c_str(), std::ios_base::binary | std::ios_base::out)),
17  filename_(name) {
18  if (!ost_->is_open()) {
19  throw cms::Exception("OutputFile", "OutputFile") << "Error Opening Output File: " << name << "\n";
20  }
21  ost_->rdbuf()->pubsetbuf(nullptr, 0);
22  if (padding_) {
23  paddingBuf_ = std::make_unique<char[]>(padding_);
24  memset(paddingBuf_.get(), Header::PADDING, padding_);
25  }
26  }
edm::propagate_const< std::shared_ptr< std::ofstream > > ost_
std::unique_ptr< char[]> paddingBuf_

◆ ~OutputFile()

edm::streamer::OutputFile::~OutputFile ( )

CTOR, takes file path name as argument

Definition at line 28 of file StreamerFileIO.cc.

References ost_.

28 { ost_->close(); }
edm::propagate_const< std::shared_ptr< std::ofstream > > ost_

Member Function Documentation

◆ adler32()

uint32 edm::streamer::OutputFile::adler32 ( ) const
inline

Definition at line 34 of file StreamerFileIO.h.

References adlera_, and adlerb_.

34 { return (adlerb_ << 16) | adlera_; }

◆ close()

void edm::streamer::OutputFile::close ( void  )

Definition at line 54 of file StreamerFileIO.cc.

References Exception, filename_, ost_, padding_, and writePadding().

Referenced by esMonitoring.AsyncLineReaderMixin::handle_close(), and esMonitoring.FDJsonServer::handle_close().

54  {
55  if (padding_)
56  if (writePadding())
57  throw cms::Exception("OutputFile", "OutputFile")
58  << "Error writing padding to the output file: " << filename_ << ": " << std::strerror(errno);
59  ost_->close();
60  }
edm::propagate_const< std::shared_ptr< std::ofstream > > ost_

◆ current_offset()

uint64 edm::streamer::OutputFile::current_offset ( ) const
inline

Definition at line 33 of file StreamerFileIO.h.

References current_offset_.

33 { return current_offset_; }

◆ fileName()

std::string edm::streamer::OutputFile::fileName ( ) const
inline

Definition at line 32 of file StreamerFileIO.h.

References filename_.

32 { return filename_; }

◆ set_current_offset()

void edm::streamer::OutputFile::set_current_offset ( uint64  v)
inline

◆ set_do_adler()

void edm::streamer::OutputFile::set_do_adler ( bool  v)
inline

Definition at line 36 of file StreamerFileIO.h.

References do_adler_, and findQualityFiles::v.

◆ write()

bool edm::streamer::OutputFile::write ( const char *  ptr,
size_t  n,
bool  doPadding = false 
)

Definition at line 30 of file StreamerFileIO.cc.

References cms::Adler32(), adlera_, adlerb_, current_offset_, do_adler_, dqmiodumpmetadata::n, ost_, padding_, and writePadding().

Referenced by writePadding().

30  {
31  ost_->write(ptr, n);
32  if (!ost_->fail()) {
33  current_offset_ += (uint64)(n);
34  if (do_adler_)
35  cms::Adler32(ptr, n, adlera_, adlerb_);
36  if (doPadding && padding_) {
37  return writePadding();
38  }
39  return false;
40  }
41  return true;
42  }
edm::propagate_const< std::shared_ptr< std::ofstream > > ost_
void Adler32(char const *data, size_t len, uint32_t &a, uint32_t &b)
unsigned long long uint64
Definition: MsgTools.h:15

◆ writePadding()

bool edm::streamer::OutputFile::writePadding ( )

Definition at line 44 of file StreamerFileIO.cc.

References mod(), ost_, padding_, paddingBuf_, runTheMatrix::ret, and write().

Referenced by close(), and write().

44  {
45  uint64 mod = ost_->tellp() % padding_;
46  if (mod) {
47  uint32 rem = padding_ - (uint32)(mod % padding_);
48  bool ret = write(paddingBuf_.get(), rem, false);
49  return ret;
50  }
51  return false;
52  }
ret
prodAgent to be discontinued
edm::propagate_const< std::shared_ptr< std::ofstream > > ost_
bool write(const char *ptr, size_t n, bool doPadding=false)
unsigned long long uint64
Definition: MsgTools.h:15
std::unique_ptr< char[]> paddingBuf_
unsigned int uint32
Definition: MsgTools.h:14
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4

Member Data Documentation

◆ adlera_

uint32 edm::streamer::OutputFile::adlera_
private

Definition at line 44 of file StreamerFileIO.h.

Referenced by adler32(), and write().

◆ adlerb_

uint32 edm::streamer::OutputFile::adlerb_
private

Definition at line 45 of file StreamerFileIO.h.

Referenced by adler32(), and write().

◆ current_offset_

uint64 edm::streamer::OutputFile::current_offset_
private

Definition at line 41 of file StreamerFileIO.h.

Referenced by current_offset(), set_current_offset(), and write().

◆ do_adler_

bool edm::streamer::OutputFile::do_adler_
private

Location of current ioptr

Definition at line 43 of file StreamerFileIO.h.

Referenced by set_do_adler(), and write().

◆ filename_

std::string edm::streamer::OutputFile::filename_
private

Definition at line 49 of file StreamerFileIO.h.

Referenced by close(), and fileName().

◆ ost_

edm::propagate_const<std::shared_ptr<std::ofstream> > edm::streamer::OutputFile::ost_
private

Definition at line 48 of file StreamerFileIO.h.

Referenced by close(), OutputFile(), write(), writePadding(), and ~OutputFile().

◆ padding_

uint32 edm::streamer::OutputFile::padding_
private

Definition at line 46 of file StreamerFileIO.h.

Referenced by close(), OutputFile(), write(), and writePadding().

◆ paddingBuf_

std::unique_ptr<char[]> edm::streamer::OutputFile::paddingBuf_
private

Definition at line 50 of file StreamerFileIO.h.

Referenced by OutputFile(), and writePadding().