ATLAS Offline Software
Loading...
Searching...
No Matches
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):
7
8// standard library includes
9#include <memory>
10#include <utility>
11
12// EDM include(s):
15
16
17namespace xAODMaker {
18
19FileMetaDataTool::FileMetaDataTool(const std::string& name)
20 : base_class( name ) { }
21
22StatusCode
24#ifndef XAOD_STANDALONE
25 ASG_CHECK(m_metaDataSvc.retrieve());
26#endif // XAOD_STANDALONE
27
28 // Return gracefully:
29 return StatusCode::SUCCESS;
30 }
31
32StatusCode
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(
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
69StatusCode
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(
124 std::move(output), key));
125
126 ASG_CHECK(
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
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
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
#define ASG_CHECK(...)
Helper macro for checking the status code returned by a function call.
Definition Check.h:43
void copyValues(const xAOD::FileMetaData *src, xAOD::FileMetaData *dst, const std::string &var)
Gaudi::Property< std::vector< std::string > > m_keys
StatusCode beginInputFile() override
Collecting file metadata from input and write to output.
ServiceHandle< IAthMetaDataSvc > m_metaDataSvc
Get a handle on the metadata store for the job.
StatusCode copy(const std::string &)
FileMetaDataTool(const std::string &name="FileMetaDataTool")
Regular AsgTool constructor.
StatusCode initialize() override
Function initialising the tool.
bool setValue(MetaDataType type, const std::string &val)
Set a pre-defined string value on the object.
bool value(MetaDataType type, std::string &val) const
Get a pre-defined string value out of the object.
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
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.
FileMetaDataAuxInfo_v1 FileMetaDataAuxInfo
Declare the latest version of the class.
FileMetaData_v1 FileMetaData
Declare the latest version of the class.