ATLAS Offline Software
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 
17 namespace xAODMaker {
18 
20  : base_class( name ) { }
21 
24 #ifndef XAOD_STANDALONE
25  ASG_CHECK(m_metaDataSvc.retrieve());
26 #endif // XAOD_STANDALONE
27 
28  // Return gracefully:
29  return StatusCode::SUCCESS;
30  }
31 
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 
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
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
beamspotnt.var
var
Definition: bin/beamspotnt.py:1393
ASG_CHECK
#define ASG_CHECK(...)
Helper macro for checking the status code returned by a function call.
Definition: Check.h:43
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
xAOD::FileMetaDataAuxInfo_v1
Auxiliary store for xAOD::FileMetaData_v1.
Definition: FileMetaDataAuxInfo_v1.h:31
xAODMaker::FileMetaDataTool::m_toolMutex
std::mutex m_toolMutex
Definition: FileMetaDataTool.h:88
WriteCellNoiseToCool.src
src
Definition: WriteCellNoiseToCool.py:513
skel.it
it
Definition: skel.GENtoEVGEN.py:407
xAODMaker::FileMetaDataTool::copy
StatusCode copy(const std::string &)
Definition: FileMetaDataTool.cxx:70
FileMetaDataAuxInfo.h
python.RatesEmulationExample.lock
lock
Definition: RatesEmulationExample.py:148
xAODMaker
Definition: StoreGateSvc.h:70
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
DiTauMassTools::ignore
void ignore(T &&)
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:58
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
xAOD::FileMetaData_v1
Class holding file-level metadata about an xAOD file.
Definition: FileMetaData_v1.h:34
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
xAODMaker::FileMetaDataTool::copyValues
void copyValues(const xAOD::FileMetaData *src, xAOD::FileMetaData *dst, const std::string &var)
Definition: FileMetaDataTool.cxx:138
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
xAODMaker::FileMetaDataTool::m_metaDataSvc
ServiceHandle< IAthMetaDataSvc > m_metaDataSvc
Get a handle on the metadata store for the job.
Definition: FileMetaDataTool.h:84
FileMetaDataTool.h
createLinkingScheme.dst_vec
dst_vec
Definition: createLinkingScheme.py:81
xAODMaker::FileMetaDataTool::beginInputFile
StatusCode beginInputFile() override
Collecting file metadata from input and write to output.
Definition: FileMetaDataTool.cxx:33
xAODMaker::FileMetaDataTool::m_keys
Gaudi::Property< std::vector< std::string > > m_keys
Definition: FileMetaDataTool.h:76
FileMetaData.h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:801
xAODMaker::FileMetaDataTool::initialize
StatusCode initialize() override
Function initialising the tool.
Definition: FileMetaDataTool.cxx:23
xAODMaker::FileMetaDataTool::FileMetaDataTool
FileMetaDataTool(const std::string &name="FileMetaDataTool")
Regular AsgTool constructor.
Definition: FileMetaDataTool.cxx:19
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37