Main Page
Namespaces
Classes
Package Documentation
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Pages
HiggsAnalysis
CombinedLimit
src
CloseCoutSentry.cc
Go to the documentation of this file.
1
#include "../interface/CloseCoutSentry.h"
2
3
#include <cstdio>
4
#include <unistd.h>
5
6
bool
CloseCoutSentry::open_
=
true
;
7
int
CloseCoutSentry::fdOut_
= 0;
8
int
CloseCoutSentry::fdErr_
= 0;
9
FILE *
CloseCoutSentry::trueStdOut_
= 0;
10
11
CloseCoutSentry::CloseCoutSentry
(
bool
silent) :
12
silent_(silent), stdOutIsMine_(
false
)
13
{
14
if
(
silent_
) {
15
if
(
open_
) {
16
open_
=
false
;
17
if
(
fdOut_
== 0 &&
fdErr_
== 0) {
18
fdOut_
= dup(1);
19
fdErr_
= dup(2);
20
}
21
freopen(
"/dev/null"
,
"w"
, stdout);
22
freopen(
"/dev/null"
,
"w"
, stderr);
23
}
else
{
24
silent_
=
false
;
25
}
26
}
27
}
28
29
CloseCoutSentry::~CloseCoutSentry
()
30
{
31
clear
();
32
}
33
34
void
CloseCoutSentry::clear
()
35
{
36
if
(
stdOutIsMine_
) { fclose(
trueStdOut_
);
trueStdOut_
= 0; }
37
if
(
silent_
) {
38
reallyClear
();
39
silent_
=
false
;
40
}
41
}
42
43
void
CloseCoutSentry::reallyClear
()
44
{
45
if
(
fdOut_
!=
fdErr_
) {
46
char
buf[50];
47
sprintf(buf,
"/dev/fd/%d"
,
fdOut_
); freopen(buf,
"w"
, stdout);
48
sprintf(buf,
"/dev/fd/%d"
,
fdErr_
); freopen(buf,
"w"
, stderr);
49
open_
=
true
;
50
fdOut_
=
fdErr_
= 0;
51
}
52
}
53
54
void
CloseCoutSentry::breakFree
()
55
{
56
reallyClear
();
57
}
58
59
FILE *
CloseCoutSentry::trueStdOut
()
60
{
61
if
(
open_
)
return
stdout;
62
if
(
trueStdOut_
)
return
trueStdOut_
;
63
stdOutIsMine_
=
true
;
64
char
buf[50];
65
sprintf(buf,
"/dev/fd/%d"
,
fdOut_
);
trueStdOut_
= fopen(buf,
"w"
);
66
return
trueStdOut_
;
67
}
CloseCoutSentry::trueStdOut_
static FILE * trueStdOut_
Definition:
CloseCoutSentry.h:22
funct::false
false
Definition:
Factorize.h:34
CloseCoutSentry::fdErr_
static int fdErr_
Definition:
CloseCoutSentry.h:18
CloseCoutSentry::silent_
bool silent_
Definition:
CloseCoutSentry.h:17
CloseCoutSentry::breakFree
static void breakFree()
Definition:
CloseCoutSentry.cc:54
CloseCoutSentry::trueStdOut
FILE * trueStdOut()
Definition:
CloseCoutSentry.cc:59
CloseCoutSentry::reallyClear
static void reallyClear()
Definition:
CloseCoutSentry.cc:43
CloseCoutSentry::CloseCoutSentry
CloseCoutSentry(bool silent=true)
Definition:
CloseCoutSentry.cc:11
CloseCoutSentry::clear
void clear()
Definition:
CloseCoutSentry.cc:34
CloseCoutSentry::stdOutIsMine_
bool stdOutIsMine_
Definition:
CloseCoutSentry.h:23
CloseCoutSentry::open_
static bool open_
Definition:
CloseCoutSentry.h:19
CloseCoutSentry::~CloseCoutSentry
~CloseCoutSentry()
Definition:
CloseCoutSentry.cc:29
CloseCoutSentry::fdOut_
static int fdOut_
Definition:
CloseCoutSentry.h:18
Generated for CMSSW Reference Manual by
1.8.5