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<< (bool n)
 
binary_ofstreamoperator<< (char n)
 
binary_ofstreamoperator<< (const std::string &n)
 
binary_ofstreamoperator<< (double n)
 
binary_ofstreamoperator<< (float n)
 
binary_ofstreamoperator<< (int n)
 
binary_ofstreamoperator<< (long n)
 
binary_ofstreamoperator<< (short n)
 
binary_ofstreamoperator<< (unsigned char n)
 
binary_ofstreamoperator<< (unsigned int n)
 
binary_ofstreamoperator<< (unsigned long n)
 
binary_ofstreamoperator<< (unsigned short 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 8 of file binary_ofstream.cc.

8 : file_(nullptr) { init(name); }

References init(), and Skims_PA_cff::name.

◆ binary_ofstream() [2/2]

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

Definition at line 10 of file binary_ofstream.cc.

10 : file_(nullptr) { init(name.c_str()); }

References init(), and Skims_PA_cff::name.

◆ ~binary_ofstream()

binary_ofstream::~binary_ofstream ( )

Definition at line 20 of file binary_ofstream.cc.

20 { close(); }

References close().

Member Function Documentation

◆ close()

void binary_ofstream::close ( void  )

Definition at line 21 of file binary_ofstream.cc.

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

References file_.

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

◆ init()

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

Definition at line 12 of file binary_ofstream.cc.

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

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

Referenced by binary_ofstream().

◆ operator<<() [1/12]

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

Definition at line 69 of file binary_ofstream.cc.

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

References dqmiodumpmetadata::n.

◆ operator<<() [2/12]

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

Definition at line 27 of file binary_ofstream.cc.

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

References file_, and dqmiodumpmetadata::n.

◆ operator<<() [3/12]

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

Definition at line 71 of file binary_ofstream.cc.

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

References file_, and alignCSCRings::s.

◆ operator<<() [4/12]

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

Definition at line 64 of file binary_ofstream.cc.

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

References file_, and dqmiodumpmetadata::n.

◆ operator<<() [5/12]

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

Definition at line 60 of file binary_ofstream.cc.

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

References file_, and dqmiodumpmetadata::n.

◆ operator<<() [6/12]

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

Definition at line 44 of file binary_ofstream.cc.

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

References file_, and dqmiodumpmetadata::n.

◆ operator<<() [7/12]

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

Definition at line 52 of file binary_ofstream.cc.

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

References file_, and dqmiodumpmetadata::n.

◆ operator<<() [8/12]

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

Definition at line 36 of file binary_ofstream.cc.

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

References file_, and dqmiodumpmetadata::n.

◆ operator<<() [9/12]

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

Definition at line 31 of file binary_ofstream.cc.

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

References file_, and dqmiodumpmetadata::n.

◆ operator<<() [10/12]

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

Definition at line 48 of file binary_ofstream.cc.

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

References file_, and dqmiodumpmetadata::n.

◆ operator<<() [11/12]

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

Definition at line 56 of file binary_ofstream.cc.

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

References file_, and dqmiodumpmetadata::n.

◆ operator<<() [12/12]

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

Definition at line 40 of file binary_ofstream.cc.

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

References file_, and dqmiodumpmetadata::n.

Member Data Documentation

◆ file_

FILE* binary_ofstream::file_
private

Definition at line 36 of file binary_ofstream.h.

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

dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
gather_cfg.cout
cout
Definition: gather_cfg.py:144
binary_ofstream::file_
FILE * file_
Definition: binary_ofstream.h:36
alignCSCRings.s
s
Definition: alignCSCRings.py:92
binary_ofstream::close
void close()
Definition: binary_ofstream.cc:21
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
binary_ofstream::init
void init(const char *name)
Definition: binary_ofstream.cc:12
binary_ofstream_error
Definition: binary_ofstream.cc:6