ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Event
xAOD
xAODEventFormatCnv
src
EventFormatMetaDataTool.cxx
Go to the documentation of this file.
1
// Dear emacs, this is -*- c++ -*-
2
/* Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration */
3
4
5
// System include(s):
6
#include <algorithm>
7
#include <stdexcept>
8
#include <utility>
9
#include <vector>
10
11
// Gaudi/Athena include(s):
12
#include "
AthenaKernel/errorcheck.h
"
13
14
// Local include(s):
15
#include "
EventFormatMetaDataTool.h
"
16
17
namespace
xAODMaker
{
18
19
20
EventFormatMetaDataTool::EventFormatMetaDataTool
(
const
std::string&
type
,
21
const
std::string& name,
22
const
IInterface* parent):
23
base_class(
type
, name, parent) { }
24
25
StatusCode
26
EventFormatMetaDataTool::initialize
() {
27
// Greet the user:
28
ATH_MSG_VERBOSE
(
"Initialising"
);
29
ATH_MSG_VERBOSE
(
" "
<<
m_inputMetaStore
);
30
ATH_MSG_VERBOSE
(
" "
<<
m_outputMetaStore
);
31
if
(!
m_keys
.empty()) {
32
ATH_MSG_VERBOSE
(
"Asked to copy EventFormat with keys:"
);
33
for
(
const
std::string& key :
m_keys
) {
34
ATH_MSG_VERBOSE
(
" - "
<< key);
35
}
36
}
37
38
// Connect to the metadata stores:
39
ATH_CHECK
(
m_inputMetaStore
.retrieve());
40
ATH_CHECK
(
m_outputMetaStore
.retrieve());
41
42
// Return gracefully:
43
return
StatusCode::SUCCESS;
44
}
45
46
StatusCode
47
EventFormatMetaDataTool::beginInputFile
() {
48
// lock the tool, so metaDataStop will wait for write to finish
49
std::lock_guard< std::mutex > guard(
m_outputMutex
);
50
51
// Create object to hold information from the new file
52
auto
format = std::make_unique< xAOD::EventFormat >();
53
54
ATH_CHECK
(
collectMetaData
());
55
56
return
StatusCode::SUCCESS;
57
}
58
59
StatusCode
60
EventFormatMetaDataTool::metaDataStop
() {
61
// wait for threads currently writing to finish
62
std::lock_guard< std::mutex > guard(
m_outputMutex
);
63
64
return
StatusCode::SUCCESS;
65
}
66
67
StatusCode
68
EventFormatMetaDataTool::collectMetaData
() {
69
70
std::vector< std::string > keys =
m_keys
;
71
if
(keys.empty()) {
72
m_inputMetaStore
->keys<
xAOD::EventFormat
>(keys);
73
}
else
{
74
// remove keys not in the InputMetaDataStore
75
keys.erase(
76
std::remove_if
(
77
keys.begin(), keys.end(),
78
[
this
](std::string& key) {
79
return !m_inputMetaStore->contains<xAOD::EventFormat>(key);
80
}),
81
keys.end());
82
}
83
84
// If the input file doesn't have any event format metadata,
85
// then finish right away:
86
if
(keys.empty())
return
StatusCode::SUCCESS;
87
88
// Retrieve the input container:
89
for
(
const
std::string& key : keys) {
90
std::list<SG::ObjectWithVersion<xAOD::EventFormat> > allVersions;
91
if
(!
m_inputMetaStore
->retrieveAllVersions(allVersions, key)
92
.isSuccess()) {
93
ATH_MSG_DEBUG
(
"Failed to retrieve \""
94
<< key <<
"\" from InputMetaDataStore"
);
95
continue
;
// try next key
96
}
97
98
// get output object
99
auto
output =
m_outputMetaStore
->tryRetrieve<
xAOD::EventFormat
>(key);
100
if
(!output) {
101
auto
ef = std::make_unique<xAOD::EventFormat>();
102
output = ef.get();
103
if
(!
m_outputMetaStore
->record(std::move(ef), key).isSuccess()) {
104
ATH_MSG_DEBUG
(
"Failed to create output object \""
105
<< key <<
"\" in MetaDataSvc"
);
106
continue
;
107
}
108
}
109
110
ATH_MSG_VERBOSE
(
"Merging all versions of "
<< key);
111
for
(
auto
& version : allVersions) {
112
const
auto
* input = version.dataObject.cptr();
113
// Merge the new object into the output one:
114
for
(
const
auto
&
pair
: *input) {
115
if
(!output->exists(
pair
.second.hash())) {
116
output->add(
pair
.second);
117
}
118
}
119
}
120
}
121
122
// Return gracefully:
123
return
StatusCode::SUCCESS;
124
}
125
126
}
// namespace xAODMaker
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition
AthMsgStreamMacros.h:28
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
errorcheck.h
Helpers for checking error return status codes and reporting errors.
EventFormatMetaDataTool.h
pair
STL class.
xAODMaker::EventFormatMetaDataTool::m_outputMetaStore
ServiceHandle< IAthMetaDataSvc > m_outputMetaStore
Connection to the output metadata store.
Definition
EventFormatMetaDataTool.h:73
xAODMaker::EventFormatMetaDataTool::m_inputMetaStore
ServiceHandle< ::StoreGateSvc > m_inputMetaStore
Connection to the input metadata store.
Definition
EventFormatMetaDataTool.h:69
xAODMaker::EventFormatMetaDataTool::m_outputMutex
std::mutex m_outputMutex
MetaDataStop need to wait for ongoing writes.
Definition
EventFormatMetaDataTool.h:81
xAODMaker::EventFormatMetaDataTool::initialize
virtual StatusCode initialize() override
Function initialising the tool.
Definition
EventFormatMetaDataTool.cxx:26
xAODMaker::EventFormatMetaDataTool::metaDataStop
virtual StatusCode metaDataStop() override
Wait for metadata write operations to finish, then return SUCCESS.
Definition
EventFormatMetaDataTool.cxx:60
xAODMaker::EventFormatMetaDataTool::collectMetaData
StatusCode collectMetaData()
Function collecting the event format metadata from the input file.
Definition
EventFormatMetaDataTool.cxx:68
xAODMaker::EventFormatMetaDataTool::EventFormatMetaDataTool
EventFormatMetaDataTool(const std::string &type, const std::string &name, const IInterface *parent)
Regular AlgTool constructor.
Definition
EventFormatMetaDataTool.cxx:20
xAODMaker::EventFormatMetaDataTool::beginInputFile
virtual StatusCode beginInputFile()
Function called when a new input file is opened.
Definition
EventFormatMetaDataTool.cxx:47
xAODMaker::EventFormatMetaDataTool::m_keys
Gaudi::Property< std::vector< std::string > > m_keys
(optional) list of keys to copy, all if empty, default: empty
Definition
EventFormatMetaDataTool.h:77
std::remove_if
DataModel_detail::iterator< DVL > remove_if(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end, Predicate pred)
Specialization of remove_if for DataVector/List.
Definition
DVL_algorithms.h:70
xAODMaker
Definition
StoreGateSvc.h:70
xAOD::EventFormat
EventFormat_v1 EventFormat
Definition of the current event format version.
Definition
EventFormat.h:16
type
Generated on
for ATLAS Offline Software by
1.17.0