ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Event
xAOD
xAODMetaDataCnv
Root
FileMetaDataTool.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
// Local include(s):
6
#include "
xAODMetaDataCnv/FileMetaDataTool.h
"
7
8
// standard library includes
9
#include <memory>
10
#include <utility>
11
12
// EDM include(s):
13
#include "
xAODMetaData/FileMetaData.h
"
14
#include "
xAODMetaData/FileMetaDataAuxInfo.h
"
15
16
17
namespace
xAODMaker
{
18
19
FileMetaDataTool::FileMetaDataTool
(
const
std::string& name)
20
: base_class( name ) { }
21
22
StatusCode
23
FileMetaDataTool::initialize
() {
24
#ifndef XAOD_STANDALONE
25
ASG_CHECK
(
m_metaDataSvc
.retrieve());
26
#endif
// XAOD_STANDALONE
27
28
// Return gracefully:
29
return
StatusCode::SUCCESS;
30
}
31
32
StatusCode
33
FileMetaDataTool::beginInputFile
() {
34
// Previous input file has been processed
35
std::lock_guard
lock
(
m_toolMutex
);
36
37
// get the keys for all metadata in input
38
std::vector<std::string> keys =
m_keys
;
39
if
(keys.empty()) {
40
inputMetaStore()->keys<
xAOD::FileMetaData
>(keys);
41
}
else
{
42
// remove keys not in the InputMetaDataStore
43
keys.erase(
44
std::remove_if
(
45
keys.begin(), keys.end(),
46
[
this
](std::string& key) {
47
return !inputMetaStore()->contains<xAOD::FileMetaData>(key);
48
}),
49
keys.end());
50
}
51
52
// If the input file doesn't have any event format metadata,
53
// then finish right away:
54
if
(keys.empty())
return
StatusCode::SUCCESS;
55
56
// Now copy all object to MetaDataStore
57
for
(
const
std::string& key : keys) {
58
#ifdef XAOD_STANDALONE
59
ASG_CHECK
(
copy
(key));
60
#else
61
for
(
const
std::string& stream_key :
m_metaDataSvc
->getPerStreamKeysFor(key) ) {
62
ASG_CHECK
(
copy
(stream_key) );
63
}
64
#endif
// XAOD_STANDALONE
65
}
66
return
StatusCode::SUCCESS;
67
}
68
69
StatusCode
70
FileMetaDataTool::copy
(
const
std::string& key) {
71
ATH_MSG_DEBUG
(
"Copying \""
<< key <<
"\" from InputMetaDataStore"
);
72
// Quit gracefully if there is nothing to do
73
if
(!inputMetaStore()->
contains< xAOD::FileMetaData >
(key)) {
74
ATH_MSG_INFO
(
"No \""
<< key <<
"\" in the input file"
);
75
return
StatusCode::SUCCESS;
76
}
77
78
// Get the FileMetaData object from the input file
79
const
xAOD::FileMetaData
* input =
nullptr
;
80
ASG_CHECK
(inputMetaStore()->retrieve(input, key));
81
82
// Emit a warning if the FileMetaData from previous files does not
83
// match that of the new input file
84
#ifdef XAOD_STANDALONE
85
if
(outputMetaStore()->
contains< xAOD::FileMetaData >
(key)) {
86
xAOD::FileMetaData
* output =
nullptr
;
87
ASG_CHECK
(outputMetaStore()->retrieve(output, key));
88
#else
89
if
(
m_metaDataSvc
->contains<
xAOD::FileMetaData
>(key)) {
90
auto
*output =
m_metaDataSvc
->tryRetrieve<
xAOD::FileMetaData
>(key);
91
if
(!output)
return
StatusCode::FAILURE;
92
#endif
// XAOD_STANDALONE
93
94
copyValues
(input, output,
"runNumbers"
);
95
copyValues
(input, output,
"lumiBlocks"
);
96
97
const
std::set<std::string> ignore {
"runNumbers"
,
"lumiBlocks"
};
98
if
( !input->compareWith(*output, ignore) )
99
ATH_MSG_WARNING
(
"Inconsistent input file MetaData"
);
100
101
return
StatusCode::SUCCESS;
102
}
103
104
ATH_MSG_DEBUG
(
"Creating output objects"
);
105
auto
output = std::make_unique< xAOD::FileMetaData >();
106
auto
outputAux = std::make_unique< xAOD::FileMetaDataAuxInfo >();
107
output->setStore(outputAux.get());
108
109
// Copy input object
110
*output = *input;
111
112
113
#ifdef XAOD_STANDALONE
114
ASG_CHECK
(
115
outputMetaStore()->record< xAOD::FileMetaData >(
116
std::move(output), key));
117
118
ASG_CHECK
(
119
outputMetaStore()->record< xAOD::FileMetaDataAuxInfo >(
120
std::move(outputAux), key +
"Aux."
));
121
#else
122
ASG_CHECK
(
123
m_metaDataSvc
->record<
xAOD::FileMetaData
>(
124
std::move(output), key));
125
126
ASG_CHECK
(
127
m_metaDataSvc
->record<
xAOD::FileMetaDataAuxInfo
>(
128
std::move(outputAux), key +
"Aux."
));
129
#endif
// XAOD_STANDALONE
130
131
ATH_MSG_INFO
(
"Copied \""
<< key <<
"\" to MetaDataStore"
);
132
133
// Return gracefully:
134
return
StatusCode::SUCCESS;
135
}
136
137
138
void
FileMetaDataTool::copyValues
(
const
xAOD::FileMetaData
*src,
xAOD::FileMetaData
*dst,
139
const
std::string& var)
140
{
141
std::vector<uint32_t> src_vec, dst_vec;
142
src->value(var, src_vec);
143
dst->
value
(var, dst_vec);
144
bool
updated =
false
;
145
146
for
(
auto
val : src_vec ) {
147
// we want a sorted list of unique values (without using std::set)
148
auto
it = std::lower_bound( dst_vec.begin(), dst_vec.end(), val );
149
if
( it == dst_vec.end() || (*it) != val ) {
150
dst_vec.insert(it, val);
151
updated =
true
;
152
ATH_MSG_DEBUG
(
"added "
<< val <<
" to list of "
<< var);
153
}
154
}
155
if
( updated ) {
156
if
( !dst->
setValue
(var, dst_vec) ) {
157
ATH_MSG_WARNING
(
"error updating values for "
+ var);
158
}
159
}
160
}
161
162
}
// namespace xAODMaker
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
ASG_CHECK
#define ASG_CHECK(...)
Helper macro for checking the status code returned by a function call.
Definition
Check.h:43
FileMetaData.h
FileMetaDataAuxInfo.h
FileMetaDataTool.h
lock
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
xAODMaker::FileMetaDataTool::copyValues
void copyValues(const xAOD::FileMetaData *src, xAOD::FileMetaData *dst, const std::string &var)
Definition
FileMetaDataTool.cxx:138
xAODMaker::FileMetaDataTool::m_keys
Gaudi::Property< std::vector< std::string > > m_keys
Definition
FileMetaDataTool.h:76
xAODMaker::FileMetaDataTool::beginInputFile
StatusCode beginInputFile() override
Collecting file metadata from input and write to output.
Definition
FileMetaDataTool.cxx:33
xAODMaker::FileMetaDataTool::m_toolMutex
std::mutex m_toolMutex
Definition
FileMetaDataTool.h:88
xAODMaker::FileMetaDataTool::m_metaDataSvc
ServiceHandle< IAthMetaDataSvc > m_metaDataSvc
Get a handle on the metadata store for the job.
Definition
FileMetaDataTool.h:84
xAODMaker::FileMetaDataTool::copy
StatusCode copy(const std::string &)
Definition
FileMetaDataTool.cxx:70
xAODMaker::FileMetaDataTool::FileMetaDataTool
FileMetaDataTool(const std::string &name="FileMetaDataTool")
Regular AsgTool constructor.
Definition
FileMetaDataTool.cxx:19
xAODMaker::FileMetaDataTool::initialize
StatusCode initialize() override
Function initialising the tool.
Definition
FileMetaDataTool.cxx:23
xAOD::FileMetaData_v1::setValue
bool setValue(MetaDataType type, const std::string &val)
Set a pre-defined string value on the object.
Definition
FileMetaData_v1.cxx:233
xAOD::FileMetaData_v1::value
bool value(MetaDataType type, std::string &val) const
Get a pre-defined string value out of the object.
Definition
FileMetaData_v1.cxx:195
contains
bool contains(const std::string &s, const std::string ®x)
does a string contain the substring
Definition
hcg.cxx:116
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::FileMetaDataAuxInfo
FileMetaDataAuxInfo_v1 FileMetaDataAuxInfo
Declare the latest version of the class.
Definition
FileMetaDataAuxInfo.h:16
xAOD::FileMetaData
FileMetaData_v1 FileMetaData
Declare the latest version of the class.
Definition
Event/xAOD/xAODMetaData/xAODMetaData/FileMetaData.h:16
Generated on
for ATLAS Offline Software by
1.17.0