MagneticField
Interpolation
src
binary_ofstream.cc
Go to the documentation of this file.
1
#include "
binary_ofstream.h
"
2
3
#include <cstdio>
4
#include <iostream>
5
6
struct
binary_ofstream_error
{};
7
8
binary_ofstream::binary_ofstream
(
const
char
*
name
) : file_(nullptr) {
init
(
name
); }
9
10
binary_ofstream::binary_ofstream
(
const
std::string
&
name
) : file_(nullptr) {
init
(
name
.c_str()); }
11
12
void
binary_ofstream::init
(
const
char
*
name
) {
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
}
19
20
binary_ofstream::~binary_ofstream
() {
close
(); }
21
void
binary_ofstream::close
() {
22
if
(
file_
!=
nullptr
)
23
fclose(
file_
);
24
file_
=
nullptr
;
25
}
26
27
binary_ofstream
&
binary_ofstream::operator<<
(
char
n
) {
28
fputc(
n
,
file_
);
29
return
*
this
;
30
}
31
binary_ofstream
&
binary_ofstream::operator<<
(
unsigned
char
n
) {
32
fputc(
n
,
file_
);
33
return
*
this
;
34
}
35
36
binary_ofstream
&
binary_ofstream::operator<<
(
short
n
) {
37
fwrite(&
n
,
sizeof
(
n
), 1,
file_
);
38
return
*
this
;
39
}
40
binary_ofstream
&
binary_ofstream::operator<<
(
unsigned
short
n
) {
41
fwrite(&
n
,
sizeof
(
n
), 1,
file_
);
42
return
*
this
;
43
}
44
binary_ofstream
&
binary_ofstream::operator<<
(
int
n
) {
45
fwrite(&
n
,
sizeof
(
n
), 1,
file_
);
46
return
*
this
;
47
}
48
binary_ofstream
&
binary_ofstream::operator<<
(
unsigned
int
n
) {
49
fwrite(&
n
,
sizeof
(
n
), 1,
file_
);
50
return
*
this
;
51
}
52
binary_ofstream
&
binary_ofstream::operator<<
(
long
n
) {
53
fwrite(&
n
,
sizeof
(
n
), 1,
file_
);
54
return
*
this
;
55
}
56
binary_ofstream
&
binary_ofstream::operator<<
(
unsigned
long
n
) {
57
fwrite(&
n
,
sizeof
(
n
), 1,
file_
);
58
return
*
this
;
59
}
60
binary_ofstream
&
binary_ofstream::operator<<
(
float
n
) {
61
fwrite(&
n
,
sizeof
(
n
), 1,
file_
);
62
return
*
this
;
63
}
64
binary_ofstream
&
binary_ofstream::operator<<
(
double
n
) {
65
fwrite(&
n
,
sizeof
(
n
), 1,
file_
);
66
return
*
this
;
67
}
68
69
binary_ofstream
&
binary_ofstream::operator<<
(
bool
n
) {
return
operator<<(static_cast<char>(
n
)); }
70
71
binary_ofstream
&
binary_ofstream::operator<<
(
const
std::string
&
s
) {
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
}
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
binary_ofstream::binary_ofstream
binary_ofstream(const char *name)
Definition:
binary_ofstream.cc:8
binary_ofstream::~binary_ofstream
~binary_ofstream()
Definition:
binary_ofstream.cc:20
alignCSCRings.s
s
Definition:
alignCSCRings.py:92
binary_ofstream.h
binary_ofstream::close
void close()
Definition:
binary_ofstream.cc:21
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition:
AlCaHLTBitMon_QueryRunRegistry.py:256
binary_ofstream
Definition:
binary_ofstream.h:8
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
binary_ofstream::operator<<
binary_ofstream & operator<<(char n)
Definition:
binary_ofstream.cc:27
Generated for CMSSW Reference Manual by
1.8.16