The Gaudi Framework
v36r16 (ea80daf8)
JSONSink.cpp
Go to the documentation of this file.
1
/***********************************************************************************\
2
* (c) Copyright 2022 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
#include <
Gaudi/BaseSink.h
>
13
#include <
Gaudi/MonitoringHub.h
>
14
15
#include <fstream>
16
17
#include <string>
18
19
namespace
Gaudi::Monitoring
{
20
21
class
JSONSink
:
public
BaseSink
{
22
23
public
:
24
using
BaseSink::BaseSink;
25
26
StatusCode
stop
()
override
{
27
if
(
m_fileName
.empty() ) {
return
StatusCode::SUCCESS
; }
28
nlohmann::json
output
;
29
applytoAllEntities
( [&
output
](
auto
& ent ) {
30
output
.emplace_back(
nlohmann::json
{
31
{
"name"
, ent.name },
32
{
"component"
, ent.component },
33
{
"entity"
, ent.toJSON() },
34
} );
35
} );
36
info() <<
"Writing JSON file "
<<
m_fileName
.
value
() <<
endmsg
;
37
std::ofstream
os(
m_fileName
,
std::ios::out
);
38
os <<
output
.dump( 4 );
39
os.
close
();
40
// call parent's stop
41
return
BaseSink::stop
();
42
}
43
44
private
:
45
Gaudi::Property<std::string>
m_fileName
{
this
,
"FileName"
,
"json_output.json"
,
46
"Name of output json file. Empty fileName means no output"
};
47
};
48
49
DECLARE_COMPONENT
( JSONSink )
50
51
}
// namespace Gaudi::Monitoring
Gaudi::Monitoring::BaseSink
Base class for all Sinks registering to the Monitoring Hub.
Definition:
BaseSink.h:27
Gaudi::Monitoring::JSONSink
Definition:
JSONSink.cpp:21
MonitoringHub.h
jsonFromLHCbLog.json
json
Definition:
jsonFromLHCbLog.py:87
Gaudi::Monitoring
Definition:
JSONSink.cpp:19
gaudirun.output
output
Definition:
gaudirun.py:523
StatusCode
Definition:
StatusCode.h:65
std::ofstream
STL class.
Gaudi::Property::value
const ValueType & value() const
Definition:
Property.h:239
std::ofstream::close
T close(T... args)
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition:
MsgStream.h:203
Gaudi::Monitoring::JSONSink::stop
StatusCode stop() override
Definition:
JSONSink.cpp:26
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition:
StatusCode.h:100
Service::stop
StatusCode stop() override
Definition:
Service.cpp:181
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition:
PluginServiceV1.h:46
BaseSink.h
Gaudi::Monitoring::JSONSink::m_fileName
Gaudi::Property< std::string > m_fileName
Definition:
JSONSink.cpp:45
Gaudi::Monitoring::BaseSink::applytoAllEntities
void applytoAllEntities(Callable func)
applies a callable to all monitoring entities
Definition:
BaseSink.h:58
Gaudi::Property< std::string >
PrepareBase.out
out
Definition:
PrepareBase.py:20
GaudiCoreSvc
src
MessageSvc
JSONSink.cpp
Generated on Fri Jul 28 2023 16:22:53 for The Gaudi Framework by
1.8.18