CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
binary_ofstream Class Reference

#include <binary_ofstream.h>

Public Member Functions

 binary_ofstream (const char *name)
 
 binary_ofstream (const std::string &name)
 
void close ()
 
binary_ofstreamoperator<< (char n)
 
binary_ofstreamoperator<< (unsigned char n)
 
binary_ofstreamoperator<< (short n)
 
binary_ofstreamoperator<< (unsigned short n)
 
binary_ofstreamoperator<< (int n)
 
binary_ofstreamoperator<< (unsigned int n)
 
binary_ofstreamoperator<< (long n)
 
binary_ofstreamoperator<< (unsigned long n)
 
binary_ofstreamoperator<< (float n)
 
binary_ofstreamoperator<< (double n)
 
binary_ofstreamoperator<< (bool n)
 
binary_ofstreamoperator<< (const std::string &n)
 
 ~binary_ofstream ()
 

Private Member Functions

void init (const char *name)
 

Private Attributes

FILE * file_
 

Detailed Description

Definition at line 8 of file binary_ofstream.h.

Constructor & Destructor Documentation

◆ binary_ofstream() [1/2]

binary_ofstream::binary_ofstream ( const char *  name)
explicit

Definition at line 9 of file binary_ofstream.cc.

References init(), and mergeVDriftHistosByStation::name.

◆ binary_ofstream() [2/2]

binary_ofstream::binary_ofstream ( const std::string &  name)
explicit

Definition at line 11 of file binary_ofstream.cc.

References init(), and mergeVDriftHistosByStation::name.

11 : file_(nullptr) { init(name.c_str()); }
void init(const char *name)

◆ ~binary_ofstream()

binary_ofstream::~binary_ofstream ( )

Definition at line 21 of file binary_ofstream.cc.

References close().

21 { close(); }

Member Function Documentation

◆ close()

void binary_ofstream::close ( void  )

Definition at line 22 of file binary_ofstream.cc.

References file_.

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

22  {
23  if (file_ != nullptr)
24  fclose(file_);
25  file_ = nullptr;
26 }

◆ init()

void binary_ofstream::init ( const char *  name)
private

Definition at line 13 of file binary_ofstream.cc.

References gather_cfg::cout, file_, and mergeVDriftHistosByStation::name.

Referenced by binary_ofstream().

13  {
14  file_ = fopen(name, "wb");
15  if (file_ == nullptr) {
16  std::cout << "file " << name << " cannot be opened for writing" << std::endl;
17  throw binary_ofstream_error();
18  }
19 }

◆ operator<<() [1/12]

binary_ofstream & binary_ofstream::operator<< ( char  n)

Definition at line 28 of file binary_ofstream.cc.

References file_, and create_idmaps::n.

28  {
29  fputc(n, file_);
30  return *this;
31 }

◆ operator<<() [2/12]

binary_ofstream & binary_ofstream::operator<< ( unsigned char  n)

Definition at line 32 of file binary_ofstream.cc.

References file_, and create_idmaps::n.

32  {
33  fputc(n, file_);
34  return *this;
35 }

◆ operator<<() [3/12]

binary_ofstream & binary_ofstream::operator<< ( short  n)

Definition at line 37 of file binary_ofstream.cc.

References file_, and create_idmaps::n.

37  {
38  fwrite(&n, sizeof(n), 1, file_);
39  return *this;
40 }

◆ operator<<() [4/12]

binary_ofstream & binary_ofstream::operator<< ( unsigned short  n)

Definition at line 41 of file binary_ofstream.cc.

References file_, and create_idmaps::n.

41  {
42  fwrite(&n, sizeof(n), 1, file_);
43  return *this;
44 }

◆ operator<<() [5/12]

binary_ofstream & binary_ofstream::operator<< ( int  n)

Definition at line 45 of file binary_ofstream.cc.

References file_, and create_idmaps::n.

45  {
46  fwrite(&n, sizeof(n), 1, file_);
47  return *this;
48 }

◆ operator<<() [6/12]

binary_ofstream & binary_ofstream::operator<< ( unsigned int  n)

Definition at line 49 of file binary_ofstream.cc.

References file_, and create_idmaps::n.

49  {
50  fwrite(&n, sizeof(n), 1, file_);
51  return *this;
52 }

◆ operator<<() [7/12]

binary_ofstream & binary_ofstream::operator<< ( long  n)

Definition at line 53 of file binary_ofstream.cc.

References file_, and create_idmaps::n.

53  {
54  fwrite(&n, sizeof(n), 1, file_);
55  return *this;
56 }

◆ operator<<() [8/12]

binary_ofstream & binary_ofstream::operator<< ( unsigned long  n)

Definition at line 57 of file binary_ofstream.cc.

References file_, and create_idmaps::n.

57  {
58  fwrite(&n, sizeof(n), 1, file_);
59  return *this;
60 }

◆ operator<<() [9/12]

binary_ofstream & binary_ofstream::operator<< ( float  n)

Definition at line 61 of file binary_ofstream.cc.

References file_, and create_idmaps::n.

61  {
62  fwrite(&n, sizeof(n), 1, file_);
63  return *this;
64 }

◆ operator<<() [10/12]

binary_ofstream & binary_ofstream::operator<< ( double  n)

Definition at line 65 of file binary_ofstream.cc.

References file_, and create_idmaps::n.

65  {
66  fwrite(&n, sizeof(n), 1, file_);
67  return *this;
68 }

◆ operator<<() [11/12]

binary_ofstream & binary_ofstream::operator<< ( bool  n)

Definition at line 70 of file binary_ofstream.cc.

References create_idmaps::n.

70 { return operator<<(static_cast<char>(n)); }

◆ operator<<() [12/12]

binary_ofstream & binary_ofstream::operator<< ( const std::string &  n)

Definition at line 72 of file binary_ofstream.cc.

References file_, and alignCSCRings::s.

72  {
73  (*this)
74  << (uint32_t)
75  s.size(); // Use uint32 for backward compatibilty of binary files that were generated on 32-bit machines.
76  fwrite(s.data(), 1, s.size(), file_);
77  return *this;
78 }

Member Data Documentation

◆ file_

FILE* binary_ofstream::file_
private

Definition at line 36 of file binary_ofstream.h.

Referenced by close(), init(), and operator<<().