Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework
v38r0 (2143aa4c)
Main Page
Related Pages
Modules
Namespaces
Namespace List
Namespace Members
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
Typedefs
a
b
c
d
e
f
g
h
i
l
m
o
p
r
s
t
u
v
w
x
Enumerations
Enumerator
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
y
Classes
Class List
Class Index
Class Hierarchy
Class Members
All
:
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Typedefs
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
Enumerations
a
c
d
e
f
i
l
m
n
o
p
q
r
s
t
v
Enumerator
a
b
c
d
e
f
i
j
k
l
m
n
o
p
r
s
t
u
v
w
Properties
Related Functions
:
a
b
c
d
e
g
h
i
m
o
p
r
s
t
v
Files
File List
File Members
All
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
r
s
t
u
v
w
x
z
Functions
_
b
c
e
f
g
h
i
l
m
n
o
p
r
s
t
u
z
Variables
a
b
c
d
e
g
h
i
m
o
p
r
s
t
v
x
Typedefs
_
a
b
c
d
e
f
g
h
i
l
m
n
o
p
r
s
t
u
w
Enumerations
Enumerator
c
e
f
p
u
v
Macros
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
r
s
t
u
v
w
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Modules
Pages
ToStream.h
Go to the documentation of this file.
1
/***********************************************************************************\
2
* (c) Copyright 1998-2023 CERN for the benefit of the LHCb and ATLAS collaborations *
3
* *
4
* This software is distributed under the terms of the Apache version 2 licence, *
5
* copied verbatim in the file "LICENSE". *
6
* *
7
* In applying this licence, CERN does not waive the privileges and immunities *
8
* granted to it by virtue of its status as an Intergovernmental Organization *
9
* or submit itself to any jurisdiction. *
10
\***********************************************************************************/
11
// ============================================================================
12
#ifndef GAUDIPROPERTYPARSERS_PARSERVALUETOSTREAM_H
13
#define GAUDIPROPERTYPARSERS_PARSERVALUETOSTREAM_H 1
14
// ============================================================================
15
// Include files
16
// ============================================================================
17
// STD & STL
18
// ============================================================================
19
#include <array>
20
#include <iomanip>
21
#include <iostream>
22
#include <list>
23
#include <map>
24
#include <set>
25
#include <sstream>
26
#include <string>
27
#include <type_traits>
28
#include <unordered_set>
29
#include <vector>
30
// ============================================================================
31
// GaudiKernel
32
// ============================================================================
33
#include "
GaudiKernel/HashMap.h
"
34
#include "
GaudiKernel/Map.h
"
35
#include "
GaudiKernel/SerializeSTL.h
"
36
#include "
GaudiKernel/VectorMap.h
"
37
// ============================================================================
47
// ============================================================================
48
namespace
Gaudi
{
49
// ==========================================================================
50
namespace
Utils {
51
// ========================================================================
57
template
<
class
TYPE>
58
std::ostream
&
toStream
(
const
TYPE& obj,
std::ostream
&
s
);
59
// ========================================================================
71
template
<
class
ITERATOR>
72
inline
std::ostream
&
toStream
( ITERATOR first,
// begin of the sequence
73
ITERATOR last,
// end of the sequence
74
std::ostream
&
s
,
// the stream
75
const
std::string
& open,
// opening
76
const
std::string
& close,
// closing
77
const
std::string
& delim );
// delimiter
78
// ========================================================================
85
inline
std::ostream
&
toStream
(
const
std::string
& obj,
std::ostream
&
s
) {
return
s
<< std::quoted( obj,
'\''
); }
90
inline
std::ostream
&
toStream
(
const
bool
obj,
std::ostream
&
s
) {
return
s
<< ( obj ?
"True"
:
"False"
); }
95
inline
std::ostream
&
toStream
(
const
float
obj,
std::ostream
&
s
,
const
int
prec = 6 ) {
96
const
int
p =
static_cast<
int
>
(
s
.precision() );
97
return
s
<<
std::setprecision
( prec ) << obj <<
std::setprecision
( p );
98
}
103
inline
std::ostream
&
toStream
(
const
double
obj,
std::ostream
&
s
,
const
int
prec = 8 ) {
104
const
int
p =
static_cast<
int
>
(
s
.precision() );
105
return
s
<<
std::setprecision
( prec ) << obj <<
std::setprecision
( p );
106
}
111
inline
std::ostream
&
toStream
(
const
long
double
obj,
std::ostream
&
s
,
const
int
prec = 10 ) {
112
const
int
p =
static_cast<
int
>
(
s
.precision() );
113
return
s
<<
std::setprecision
( prec ) << obj <<
std::setprecision
( p );
114
}
115
// ========================================================================
123
template
<
class
KTYPE,
class
VTYPE>
124
inline
std::ostream
&
toStream
(
const
std::pair<KTYPE, VTYPE>
& obj,
std::ostream
&
s
) {
125
return
toStream
( obj.second,
toStream
( obj.first,
s
<<
"( "
) <<
" , "
) <<
" )"
;
126
}
127
// ========================================================================
134
template
<
class
TYPE,
class
ALLOCATOR>
135
inline
std::ostream
&
toStream
(
const
std::vector<TYPE, ALLOCATOR>
& obj,
std::ostream
&
s
) {
136
return
toStream
( obj.
begin
(), obj.
end
(),
s
,
"[ "
,
" ]"
,
" , "
);
137
}
138
// ========================================================================
145
template
<
class
TYPE,
class
ALLOCATOR>
146
inline
std::ostream
&
toStream
(
const
std::list<TYPE, ALLOCATOR>
& obj,
std::ostream
&
s
) {
147
return
toStream
( obj.
begin
(), obj.
end
(),
s
,
"[ "
,
" ]"
,
" , "
);
148
}
149
// ========================================================================
156
template
<
class
TYPE,
class
CMP,
class
ALLOCATOR>
157
inline
std::ostream
&
toStream
(
const
std::set<TYPE, CMP, ALLOCATOR>
& obj,
std::ostream
&
s
) {
158
return
toStream
( obj.
begin
(), obj.
end
(),
s
,
"[ "
,
" ]"
,
" , "
);
159
}
160
// ========================================================================
164
template
<
class
TYPE,
class
HASH,
class
CMP,
class
ALLOCATOR>
165
inline
std::ostream
&
toStream
(
const
std::unordered_set<TYPE, HASH, CMP, ALLOCATOR>
& obj,
std::ostream
&
s
) {
166
auto
ordered =
std::set
( obj.
begin
(), obj.
end
() );
// ensure reproducible printout
167
return
obj.
empty
() ?
s
<<
"set()"
:
toStream
( ordered.begin(), ordered.end(),
s
,
"{ "
,
" }"
,
" , "
);
168
}
169
// ========================================================================
177
template
<
class
KTYPE,
class
VTYPE,
class
CMP,
class
ALLOCATOR>
178
inline
std::ostream
&
toStream
(
const
std::map<KTYPE, VTYPE, CMP, ALLOCATOR>
& obj,
std::ostream
&
s
) {
179
using
GaudiUtils::details::ostream_joiner
;
180
return
ostream_joiner
(
s
<<
"{ "
, obj,
" , "
,
181
[](
std::ostream
& os,
const
std::pair<const KTYPE, VTYPE>
& i ) ->
std::ostream
& {
182
return
toStream
( i.second,
toStream
( i.first, os ) <<
" : "
);
183
} )
184
<<
" }"
;
185
}
186
// ========================================================================
195
template
<
class
KTYPE,
class
VTYPE,
class
CMP,
class
ALLOCATOR>
196
inline
std::ostream
&
toStream
(
const
GaudiUtils::VectorMap<KTYPE, VTYPE, CMP, ALLOCATOR>
& obj,
std::ostream
&
s
) {
197
using
GaudiUtils::details::ostream_joiner
;
198
return
ostream_joiner
(
s
<<
"{ "
, obj,
" , "
,
199
[](
std::ostream
& os,
const
std::pair<const KTYPE, VTYPE>
& i ) ->
std::ostream
& {
200
return
toStream
( i.second,
toStream
( i.first, os ) <<
" : "
);
201
} )
202
<<
" }"
;
203
}
204
// ========================================================================
213
template
<
class
KTYPE,
class
VTYPE,
class
MAP>
214
inline
std::ostream
&
toStream
(
const
GaudiUtils::Map<KTYPE, VTYPE, MAP>
& obj,
std::ostream
&
s
) {
215
using
GaudiUtils::details::ostream_joiner
;
216
return
ostream_joiner
(
s
<<
"{ "
, obj,
" , "
,
217
[](
std::ostream
& os,
const
std::pair<const KTYPE, VTYPE>
& i ) ->
std::ostream
& {
218
return
toStream
( i.second,
toStream
( i.first, os ) <<
" : "
);
219
} )
220
<<
" }"
;
221
}
222
// ========================================================================
231
template
<
class
KTYPE,
class
VTYPE,
class
HASH,
class
MAP>
232
inline
std::ostream
&
toStream
(
const
GaudiUtils::HashMap<KTYPE, VTYPE, HASH, MAP>
& obj,
std::ostream
&
s
) {
233
// Copy the hash map into a map to have it ordered by key.
234
return
toStream
(
GaudiUtils::Map<KTYPE, VTYPE>
{ obj.
begin
(), obj.
end
() },
s
);
235
}
236
// ========================================================================
241
template
<
class
TYPE,
unsigned
int
N>
242
std::ostream
&
toStream
(
const
TYPE ( &obj )[
N
],
std::ostream
&
s
) {
243
if
constexpr (
N
== 1 ) {
244
return
toStream
( obj[0],
s
<<
"( "
) <<
" , )"
;
245
}
else
{
246
return
toStream
( obj, obj +
N
,
s
,
"( "
,
" )"
,
" , "
);
247
}
248
}
249
// ========================================================================
254
template
<
class
TYPE, std::
size_t
N>
255
std::ostream
&
toStream
(
const
std::array<TYPE, N>
& obj,
std::ostream
&
s
) {
256
if
constexpr (
N
== 1 ) {
257
return
toStream
( obj[0],
s
<<
"( "
) <<
" , )"
;
258
}
else
{
259
return
toStream
(
begin
( obj ),
end
( obj ),
s
,
"( "
,
" )"
,
" , "
);
260
}
261
}
262
// ========================================================================
267
template
<
unsigned
int
N>
268
std::ostream
&
toStream
(
const
char
( &obj )[
N
],
std::ostream
&
s
) {
269
return
toStream
(
std::string
( obj, obj +
N
),
s
);
270
}
271
// ========================================================================
276
inline
std::ostream
&
toStream
(
const
char
* obj,
std::ostream
&
s
) {
return
toStream
(
std::string
( obj ),
s
); }
277
// ========================================================================
283
template
<
class
TYPE>
284
inline
std::ostream
&
toStream
(
const
TYPE& obj,
std::ostream
&
s
) {
285
return
s
<< obj;
286
}
287
// ========================================================================
299
template
<
class
ITERATOR>
300
inline
std::ostream
&
toStream
( ITERATOR first,
// begin of the sequence
301
ITERATOR last,
// end of the sequence
302
std::ostream
&
s
,
// the stream
303
const
std::string
& open,
// opening
304
const
std::string
& close,
// closing
305
const
std::string
& delim )
// delimiter
306
{
307
using
ref_t =
typename
std::iterator_traits<ITERATOR>::reference
;
308
using
GaudiUtils::details::ostream_joiner
;
309
return
ostream_joiner
(
s
<< open, first, last, delim,
310
[](
std::ostream
& os, ref_t i ) ->
std::ostream
& {
return
toStream
( i, os ); } )
311
<< close;
312
}
313
// ========================================================================
314
// helper function to print a tuple of any size
315
template
<
class
Tuple, std::
size_t
N>
316
struct
TuplePrinter
{
317
static
std::ostream
&
toStream
(
const
Tuple
&
t
,
std::ostream
&
s
) {
318
TuplePrinter<Tuple, N - 1>::toStream
(
t
,
s
) <<
" , "
;
319
return
Gaudi::Utils::toStream
( std::get<N - 1>(
t
),
s
);
320
}
321
};
322
323
template
<
class
Tuple>
324
struct
TuplePrinter
<
Tuple
, 1> {
325
static
std::ostream
&
toStream
(
const
Tuple
&
t
,
std::ostream
&
s
) {
326
return
Gaudi::Utils::toStream
( std::get<0>(
t
),
s
);
327
}
328
};
329
336
template
<
typename
... Args>
337
inline
std::ostream
&
toStream
(
const
std::tuple<Args...>
& tuple,
std::ostream
&
s
) {
338
auto
&
out
=
TuplePrinter
<decltype( tuple ),
sizeof
...( Args )>::
toStream
( tuple,
s
<<
" ( "
);
339
if
constexpr ( std::tuple_size_v<
std::tuple<Args...>
> == 1 ) {
// this is a special case in Python
340
out
<<
" ,"
;
341
}
342
return
out
<<
" ) "
;
343
}
344
345
// ========================================================================
353
template
<
class
TYPE>
354
inline
std::string
toString
(
const
TYPE& obj ) {
355
std::ostringstream
s
;
356
std::ios::fmtflags orig_flags =
s
.flags();
357
s
.setf( std::ios::showpoint );
// to display correctly floats
358
toStream
( obj,
s
);
359
s
.flags( orig_flags );
360
return
s
.str();
361
}
362
// ========================================================================
363
}
// namespace Utils
364
// ==========================================================================
365
}
// end of namespace Gaudi
366
// ============================================================================
367
// The END
368
// ============================================================================
369
#endif
std::setprecision
T setprecision(T... args)
std::string
STL class.
IOTest.N
N
Definition:
IOTest.py:110
std::list
STL class.
std::unordered_set
STL class.
std::pair
Gaudi::Utils::TuplePrinter
Definition:
ToStream.h:316
gaudirun.s
string s
Definition:
gaudirun.py:346
std::vector
STL class.
GaudiUtils::VectorMap
Definition:
VectorMap.h:112
GaudiAlg.Algs.Tuple
Tuple
Definition:
Algs.py:1173
std::tuple
GaudiUtils::Map< K, T, std::unordered_map< K, T, Hash< K > > >::begin
iterator begin()
Definition:
Map.h:139
Gaudi::Utils::TuplePrinter< Tuple, 1 >::toStream
static std::ostream & toStream(const Tuple &t, std::ostream &s)
Definition:
ToStream.h:325
HashMap.h
bug_34121.t
t
Definition:
bug_34121.py:30
VectorMap.h
Gaudi::Utils::begin
AttribStringParser::Iterator begin(const AttribStringParser &parser)
Definition:
AttribStringParser.h:136
std::ostream
STL class.
std::iterator_traits
std::array
STL class.
GaudiUtils::Map
Definition:
Map.h:91
Gaudi::Utils::end
AttribStringParser::Iterator end(const AttribStringParser &)
Definition:
AttribStringParser.h:139
std::map
STL class.
Gaudi
Header file for std:chrono::duration-based Counters.
Definition:
__init__.py:1
GaudiUtils::Map< K, T, std::unordered_map< K, T, Hash< K > > >::end
iterator end()
Definition:
Map.h:140
std::ostringstream
STL class.
Gaudi::Utils::toString
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition:
ToStream.h:354
std::vector::begin
T begin(T... args)
Gaudi::Utils::toStream
std::ostream & toStream(ITERATOR first, ITERATOR last, std::ostream &s, const std::string &open, const std::string &close, const std::string &delim)
the helper function to print the sequence
Definition:
ToStream.h:300
std::unordered_set::empty
T empty(T... args)
SerializeSTL.h
std::vector::end
T end(T... args)
Map.h
GaudiUtils::HashMap
Definition:
HashMap.h:83
Gaudi::Utils::TuplePrinter::toStream
static std::ostream & toStream(const Tuple &t, std::ostream &s)
Definition:
ToStream.h:317
std::set
STL class.
GaudiUtils::details::ostream_joiner
Stream & ostream_joiner(Stream &os, Iterator first, Iterator last, Separator sep, OutputElement output=OutputElement{})
Definition:
SerializeSTL.h:73
PrepareBase.out
out
Definition:
PrepareBase.py:20
GaudiKernel
include
GaudiKernel
ToStream.h
Generated on Thu Jan 25 2024 17:52:22 for The Gaudi Framework by
1.8.18