ATLAS Offline Software
EventFormatMetaDataTool.cxx
Go to the documentation of this file.
1 // Dear emacs, this is -*- c++ -*-
2 /* Copyright (C) 2002-2021 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):
13 
14 // Local include(s):
16 
17 namespace xAODMaker {
18 
19 
21  const std::string& name,
22  const IInterface* parent):
24  declareInterface< ::IMetaDataTool >(this);
25  }
26 
29  // Greet the user:
30  ATH_MSG_VERBOSE("Initialising");
33  if (!m_keys.empty()) {
34  ATH_MSG_VERBOSE("Asked to copy EventFormat with keys:");
35  for (const std::string& key : m_keys) {
36  ATH_MSG_VERBOSE(" - " << key);
37  }
38  }
39 
40  // Connect to the metadata stores:
41  ATH_CHECK(m_inputMetaStore.retrieve());
42  ATH_CHECK(m_outputMetaStore.retrieve());
43 
44  // Return gracefully:
45  return StatusCode::SUCCESS;
46  }
47 
50  // lock the tool, so metaDataStop will wait for write to finish
51  std::lock_guard< std::mutex > guard(m_outputMutex);
52 
53  // Create object to hold information from the new file
54  auto format = std::make_unique< xAOD::EventFormat >();
55 
57  if (sc.isFailure()) {
58  REPORT_ERROR(sc) << "Failed to collect metadata from the input file";
59  throw std::runtime_error("Failed to collect event format "
60  "metadata from the input");
61  }
62 
63  return StatusCode::SUCCESS;
64  }
65 
68  // wait for threads currently writing to finish
69  std::lock_guard< std::mutex > guard(m_outputMutex);
70 
71  return StatusCode::SUCCESS;
72  }
73 
76 
77  std::vector< std::string > keys = m_keys;
78  if (keys.empty()) {
80  } else {
81  // remove keys not in the InputMetaDataStore
82  keys.erase(
83  std::remove_if(
84  keys.begin(), keys.end(),
85  [this](std::string& key) {
86  return !m_inputMetaStore->contains<xAOD::EventFormat>(key);
87  }),
88  keys.end());
89  }
90 
91  // If the input file doesn't have any event format metadata,
92  // then finish right away:
93  if (keys.empty()) return StatusCode::SUCCESS;
94 
95  // Retrieve the input container:
96  for (const std::string& key : keys) {
97  std::list<SG::ObjectWithVersion<xAOD::EventFormat> > allVersions;
98  if (!m_inputMetaStore->retrieveAllVersions(allVersions, key)
99  .isSuccess()) {
100  ATH_MSG_DEBUG("Failed to retrieve \""
101  << key << "\" from InputMetaDataStore");
102  continue; // try next key
103  }
104 
105  // get output object
106  auto output = m_outputMetaStore->tryRetrieve<xAOD::EventFormat>(key);
107  if (!output) {
108  auto ef = std::make_unique<xAOD::EventFormat>();
109  output = ef.get();
110  if (!m_outputMetaStore->record(std::move(ef), key).isSuccess()) {
111  ATH_MSG_DEBUG("Failed to create output object \""
112  << key << "\" in MetaDataSvc");
113  continue;
114  }
115  }
116 
117  ATH_MSG_VERBOSE("Merging all versions of " << key);
119  const xAOD::EventFormat* input = version.dataObject.cptr();
120  // Merge the new object into the output one:
121  for (auto itr = input->begin(); itr != input->end(); ++itr) {
122  if (!output->exists(itr->second.hash())) {
123  output->add(itr->second);
124  }
125  }
126  }
127  }
128 
129  // Return gracefully:
130  return StatusCode::SUCCESS;
131  }
132 
133 } // namespace xAODMaker
xAODMaker::EventFormatMetaDataTool::metaDataStop
virtual StatusCode metaDataStop()
Wait for metadata write operations to finish, then return SUCCESS.
Definition: EventFormatMetaDataTool.cxx:67
REPORT_ERROR
#define REPORT_ERROR(SC)
Report an error.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:355
xAODMaker::EventFormatMetaDataTool::EventFormatMetaDataTool
EventFormatMetaDataTool(const std::string &type, const std::string &name, const IInterface *parent)
Regular AlgTool constructor.
Definition: EventFormatMetaDataTool.cxx:20
vtune_athena.format
format
Definition: vtune_athena.py:14
EventFormatMetaDataTool.h
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:81
xAODMaker::EventFormatMetaDataTool::m_outputMutex
std::mutex m_outputMutex
MetaDataStop need to wait for ongoing writes.
Definition: EventFormatMetaDataTool.h:85
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
xAODMaker
Definition: StoreGateSvc.h:72
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
xAODMaker::EventFormatMetaDataTool::initialize
virtual StatusCode initialize()
Function initialising the tool.
Definition: EventFormatMetaDataTool.cxx:28
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
xAODMaker::EventFormatMetaDataTool::m_outputMetaStore
ServiceHandle< IAthMetaDataSvc > m_outputMetaStore
Connection to the output metadata store.
Definition: EventFormatMetaDataTool.h:77
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
test_pyathena.parent
parent
Definition: test_pyathena.py:15
xAODMaker::EventFormatMetaDataTool::m_inputMetaStore
ServiceHandle< ::StoreGateSvc > m_inputMetaStore
Connection to the input metadata store.
Definition: EventFormatMetaDataTool.h:73
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
merge.output
output
Definition: merge.py:17
xAOD::EventFormat_v1
Event format metadata for xAOD files.
Definition: EventFormat_v1.h:38
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
errorcheck.h
Helpers for checking error return status codes and reporting errors.
xAODMaker::EventFormatMetaDataTool::collectMetaData
StatusCode collectMetaData()
Function collecting the event format metadata from the input file.
Definition: EventFormatMetaDataTool.cxx:75
xAODMaker::EventFormatMetaDataTool::beginInputFile
virtual StatusCode beginInputFile()
Function called when a new input file is opened.
Definition: EventFormatMetaDataTool.cxx:49
get_generator_info.version
version
Definition: get_generator_info.py:33
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:790
AthAlgTool
Definition: AthAlgTool.h:26
SG::ObjectWithVersion
associate a data object with its VersionedKey The object is held by a ReadHandle to delay its retriev...
Definition: SGVersionedKey.h:17
LheEventFiller_Common.ef
ef
Definition: SFGen_i/share/common/LheEventFiller_Common.py:7
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37