ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Database
AthenaRoot
AthenaRootComps
src
RootAsciiDumperAlg.cxx
Go to the documentation of this file.
1
2
3
/*
4
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
5
*/
6
7
// RootAsciiDumperAlg.cxx
8
// Implementation file for class RootAsciiDumperAlg
9
// Author: S.Binet<binet@cern.ch>
11
12
// AthenaRootComps includes
13
#include "
RootAsciiDumperAlg.h
"
14
15
// STL includes
16
#include <sstream>
17
#include <stdio.h>
18
#include <stdexcept>
19
20
#include <inttypes.h>
21
22
// linux i/o includes
23
#include <sys/stat.h>
24
#include <unistd.h>
25
#include <fcntl.h>
26
#include <format>
27
28
// FrameWork includes
29
#include "Gaudi/Property.h"
30
#include "
AthContainers/ConstAccessor.h
"
31
32
// SGTools
33
#include "
SGTools/BuiltinsClids.h
"
// to put ints,... in evtstore
34
#include "
SGTools/StlVectorClids.h
"
// to put std::vectors... in evtstore
35
36
namespace
Athena
{
37
39
// Public methods:
41
42
// Athena Algorithm's Hooks
44
StatusCode
RootAsciiDumperAlg::initialize
()
45
{
46
ATH_MSG_INFO
(
"Initializing "
<< name() <<
"..."
);
47
ATH_CHECK
(
m_eiKey
.initialize() );
48
ATH_CHECK
(
m_el_jetcone_dr
.initialize() );
49
ATH_CHECK
(
m_el_n
.initialize() );
50
ATH_CHECK
(
m_el_eta
.initialize() );
51
ATH_CHECK
(
m_evtnbr
.initialize() );
52
ATH_CHECK
(
m_runnbr
.initialize() );
53
54
ATH_MSG_INFO
(
"dumping data into file ["
55
<<
m_ofname
<<
"]..."
);
56
if
(
m_ofname
.empty()) {
57
ATH_MSG_ERROR
(
"cannot dump data into an empty file name!"
);
58
return
StatusCode::FAILURE;
59
}
60
m_ofd
= open(
m_ofname
.value().c_str(),
61
O_WRONLY | O_CREAT | O_TRUNC,
62
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
63
64
if
(
m_ofd
< 0) {
65
ATH_MSG_ERROR
(
"problem opening file ["
<<
m_ofname
<<
"] with "
66
"write permissions."
);
67
return
StatusCode::FAILURE;
68
}
69
70
return
StatusCode::SUCCESS;
71
}
72
73
StatusCode
RootAsciiDumperAlg::finalize
()
74
{
75
ATH_MSG_INFO
(
"Finalizing "
<< name() <<
"..."
);
76
77
if
(
m_ofd
> 0) {
78
fflush(NULL);
79
if
(close(
m_ofd
) < 0) {
80
ATH_MSG_WARNING
(
"problem while closing ["
<<
m_ofname
<<
"]"
);
81
}
82
}
83
84
return
StatusCode::SUCCESS;
85
}
86
87
StatusCode
RootAsciiDumperAlg::execute
(
const
EventContext& ctx)
88
{
89
ATH_MSG_DEBUG
(
"Executing "
<< name() <<
"..."
);
90
91
92
uint64_t nevts =
m_nentries
;
93
m_nentries
+= 1;
94
95
SG::ReadHandle<uint32_t>
runnbr (
m_runnbr
, ctx);
96
SG::ReadHandle<uint32_t>
evtnbr (
m_evtnbr
, ctx);
97
98
SG::ReadHandle<int32_t>
el_n (
m_el_n
, ctx);
99
100
SG::ReadHandle<xAOD::EventInfo>
ei (
m_eiKey
, ctx);
101
static
const
SG::ConstAccessor<std::string>
tupleName (
"tupleName"
);
102
static
const
SG::ConstAccessor<std::string>
collectionName (
"collectionName"
);
103
std::string collName = collectionName(*ei);
104
std::string::size_type pos = collName.rfind (
"/"
);
105
if
(pos != std::string::npos) {
106
collName.erase (0, pos+1);
107
}
108
109
std::string
buf
= std::format(
110
"{:03}.{} = {}\n"
111
"{:03}.{} = {}\n"
112
"{:03}.{} = {}\n"
113
"{:03}.{} = {}\n"
114
"{:03}.{} = {}\n"
,
115
nevts,
"collectionName"
, collName,
116
nevts,
"tupleName"
, tupleName(*ei),
117
nevts,
"RunNumber"
, *runnbr,
118
nevts,
"EventNumber"
, *evtnbr,
119
nevts,
"el_n"
, *el_n
120
);
121
122
if
(
buf
.empty()) {
123
throw
std::runtime_error(
"Empty buffer in RootAsciiDumperAlg::execute"
);
124
}
125
126
if
(write(
m_ofd
,
buf
.data(),
buf
.size()) == -1) {
127
throw
std::runtime_error(
"Failed to write buffer to file descriptor"
);
128
}
129
130
131
if
(*el_n > 0) {
132
SG::ReadHandle<std::vector<float>
> el_eta (
m_el_eta
, ctx);
133
SG::ReadHandle<std::vector<std::vector<float>
> > el_jetcone_dr (
m_el_jetcone_dr
, ctx);
134
135
std::ostringstream bufv;
136
for
(int32_t ii = 0; ii < *el_n; ++ii) {
137
bufv << (*el_eta)[ii];
138
if
(ii != (*el_n) - 1) {
139
bufv <<
", "
;
140
}
141
}
142
143
buf
= std::format(
144
"{:03}.{} = [{}]\n"
,
145
nevts,
146
"el_eta"
,
147
bufv.str()
148
);
149
150
if
(
buf
.empty()) {
151
throw
std::runtime_error(
"Empty buffer in RootAsciiDumperAlg::execute"
);
152
}
153
154
if
(write(
m_ofd
,
buf
.data(),
buf
.size()) == -1) {
155
throw
std::runtime_error(
"Failed to write buffer to file descriptor"
);
156
}
157
bufv.str(
""
);
//clear
158
for
(int32_t ii = 0; ii < *el_n; ++ii) {
159
bufv <<
"["
;
160
for
(std::size_t jj = 0; jj < (*el_jetcone_dr)[ii].size(); ++jj) {
161
bufv << (*el_jetcone_dr)[ii][jj];
162
if
(jj + 1 < (*el_jetcone_dr)[ii].
size
()) {
163
bufv <<
", "
;
164
}
165
}
166
bufv <<
"]"
;
167
if
(ii + 1 < *el_n) {
168
bufv <<
", "
;
169
}
170
}
171
172
buf
= std::format(
173
"{:03}.{} = [{}]\n"
,
174
nevts,
175
"el_jetcone_dr"
,
176
bufv.str()
177
);
178
179
if
(write(
m_ofd
,
buf
.data(),
buf
.size()) == -1) {
180
throw
std::runtime_error(
"Failed to write buffer to file descriptor"
);
181
}
182
}
183
184
return
StatusCode::SUCCESS;
185
}
186
187
}
//> end namespace Athena
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
BuiltinsClids.h
ConstAccessor.h
Helper class to provide constant type-safe access to aux data.
RootAsciiDumperAlg.h
StlVectorClids.h
size
size_t size() const
Number of registered mappings.
Athena::RootAsciiDumperAlg::m_ofname
StringProperty m_ofname
ASCII output file name.
Definition
RootAsciiDumperAlg.h:67
Athena::RootAsciiDumperAlg::m_evtnbr
SG::ReadHandleKey< uint32_t > m_evtnbr
event number
Definition
RootAsciiDumperAlg.h:83
Athena::RootAsciiDumperAlg::finalize
virtual StatusCode finalize()
Definition
RootAsciiDumperAlg.cxx:73
Athena::RootAsciiDumperAlg::m_ofd
int m_ofd
file handle to the ASCII output file
Definition
RootAsciiDumperAlg.h:72
Athena::RootAsciiDumperAlg::m_el_jetcone_dr
SG::ReadHandleKey< std::vector< std::vector< float > > > m_el_jetcone_dr
jetcone dR
Definition
RootAsciiDumperAlg.h:95
Athena::RootAsciiDumperAlg::m_eiKey
SG::ReadHandleKey< xAOD::EventInfo > m_eiKey
Definition
RootAsciiDumperAlg.h:98
Athena::RootAsciiDumperAlg::m_runnbr
SG::ReadHandleKey< uint32_t > m_runnbr
run number
Definition
RootAsciiDumperAlg.h:79
Athena::RootAsciiDumperAlg::m_nentries
uint64_t m_nentries
number of entries processed so-far
Definition
RootAsciiDumperAlg.h:75
Athena::RootAsciiDumperAlg::m_el_n
SG::ReadHandleKey< int32_t > m_el_n
number of electrons
Definition
RootAsciiDumperAlg.h:87
Athena::RootAsciiDumperAlg::execute
virtual StatusCode execute(const EventContext &ctx)
Execute method.
Definition
RootAsciiDumperAlg.cxx:87
Athena::RootAsciiDumperAlg::m_el_eta
SG::ReadHandleKey< std::vector< float > > m_el_eta
eta of electrons
Definition
RootAsciiDumperAlg.h:91
Athena::RootAsciiDumperAlg::initialize
virtual StatusCode initialize()
Definition
RootAsciiDumperAlg.cxx:44
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition
ConstAccessor.h:55
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
Athena
Some weak symbol referencing magic... These are declared in AthenaKernel/getMessageSvc....
Definition
AthDsoUtils.h:10
Athena::buf
static char buf[SIGNAL_MESSAGE_BUFSIZE]
Dump application state information on a fatal signal.
Definition
SealSignal.cxx:1512
Generated on
for ATLAS Offline Software by
1.17.0