ATLAS Offline Software
Loading...
Searching...
No Matches
xAODMaker::FileMetaDataTool Class Reference

Tool propagating xAOD::FileMetaData from input to output. More...

#include <FileMetaDataTool.h>

Inheritance diagram for xAODMaker::FileMetaDataTool:
Collaboration diagram for xAODMaker::FileMetaDataTool:

Public Member Functions

 FileMetaDataTool (const std::string &name="FileMetaDataTool")
 Regular AsgTool constructor.
StatusCode initialize () override
 Function initialising the tool.
Functions called by the IMetaDataTool base class
StatusCode beginInputFile () override
 Collecting file metadata from input and write to output.
StatusCode endInputFile () override
 Does nothing.
StatusCode beginInputFile (const SG::SourceID &) override
 Collecting file metadata from input and write to output.
StatusCode endInputFile (const SG::SourceID &) override
 Does nothing.
StatusCode metaDataStop () override
 Does nothing.

Private Member Functions

StatusCode copy (const std::string &)
void copyValues (const xAOD::FileMetaData *src, xAOD::FileMetaData *dst, const std::string &var)

Private Attributes

Gaudi::Property< std::vector< std::string > > m_keys
ServiceHandle< IAthMetaDataSvcm_metaDataSvc {"MetaDataSvc", name()}
 Get a handle on the metadata store for the job.
std::mutex m_toolMutex

Detailed Description

Tool propagating xAOD::FileMetaData from input to output.

This tool propagates the xAOD::FileMetaData object from the input files to the MetaDataStore in Athena. It requires the input to contain the information in an xAOD format. The tool will emit a warning if the file metadata between inputs does not match.

Author
Attila Krasznahorkay Attil.nosp@m.a.Kr.nosp@m.aszna.nosp@m.hork.nosp@m.ay@ce.nosp@m.rn.c.nosp@m.h
Frank Berghaus fberg.nosp@m.haus.nosp@m.@anl..nosp@m.gov

Definition at line 37 of file FileMetaDataTool.h.

Constructor & Destructor Documentation

◆ FileMetaDataTool()

xAODMaker::FileMetaDataTool::FileMetaDataTool ( const std::string & name = "FileMetaDataTool")
explicit

Regular AsgTool constructor.

Definition at line 19 of file FileMetaDataTool.cxx.

20 : base_class( name ) { }

Member Function Documentation

◆ beginInputFile() [1/2]

StatusCode xAODMaker::FileMetaDataTool::beginInputFile ( )
override

Collecting file metadata from input and write to output.

Definition at line 33 of file FileMetaDataTool.cxx.

33 {
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 }
#define ASG_CHECK(...)
Helper macro for checking the status code returned by a function call.
Definition Check.h:43
Gaudi::Property< std::vector< std::string > > m_keys
ServiceHandle< IAthMetaDataSvc > m_metaDataSvc
Get a handle on the metadata store for the job.
StatusCode copy(const std::string &)
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.
FileMetaData_v1 FileMetaData
Declare the latest version of the class.

◆ beginInputFile() [2/2]

StatusCode xAODMaker::FileMetaDataTool::beginInputFile ( const SG::SourceID & )
inlineoverride

Collecting file metadata from input and write to output.

Definition at line 64 of file FileMetaDataTool.h.

64{return beginInputFile();};
StatusCode beginInputFile() override
Collecting file metadata from input and write to output.

◆ copy()

StatusCode xAODMaker::FileMetaDataTool::copy ( const std::string & key)
private

Definition at line 70 of file FileMetaDataTool.cxx.

70 {
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 }
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
void copyValues(const xAOD::FileMetaData *src, xAOD::FileMetaData *dst, const std::string &var)
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
output
Definition merge.py:16
retrieve(aClass, aKey=None)
Definition PyKernel.py:110
FileMetaDataAuxInfo_v1 FileMetaDataAuxInfo
Declare the latest version of the class.

◆ copyValues()

void xAODMaker::FileMetaDataTool::copyValues ( const xAOD::FileMetaData * src,
xAOD::FileMetaData * dst,
const std::string & var )
private

Definition at line 138 of file FileMetaDataTool.cxx.

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}
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.

◆ endInputFile() [1/2]

StatusCode xAODMaker::FileMetaDataTool::endInputFile ( )
inlineoverride

Does nothing.

Definition at line 60 of file FileMetaDataTool.h.

60{return StatusCode::SUCCESS;};

◆ endInputFile() [2/2]

StatusCode xAODMaker::FileMetaDataTool::endInputFile ( const SG::SourceID & )
inlineoverride

Does nothing.

Definition at line 67 of file FileMetaDataTool.h.

67{return StatusCode::SUCCESS;};

◆ initialize()

StatusCode xAODMaker::FileMetaDataTool::initialize ( )
override

Function initialising the tool.

Definition at line 23 of file FileMetaDataTool.cxx.

23 {
24#ifndef XAOD_STANDALONE
25 ASG_CHECK(m_metaDataSvc.retrieve());
26#endif // XAOD_STANDALONE
27
28 // Return gracefully:
29 return StatusCode::SUCCESS;
30 }

◆ metaDataStop()

StatusCode xAODMaker::FileMetaDataTool::metaDataStop ( )
inlineoverride

Does nothing.

Definition at line 71 of file FileMetaDataTool.h.

71{return StatusCode::SUCCESS;};

Member Data Documentation

◆ m_keys

Gaudi::Property<std::vector<std::string> > xAODMaker::FileMetaDataTool::m_keys
private
Initial value:
{
this,
"Keys",
{},
"(optional) List of keys to copy. Copy all keys if empty"}

Definition at line 76 of file FileMetaDataTool.h.

76 {
77 this,
78 "Keys",
79 {},
80 "(optional) List of keys to copy. Copy all keys if empty"};

◆ m_metaDataSvc

ServiceHandle< IAthMetaDataSvc > xAODMaker::FileMetaDataTool::m_metaDataSvc {"MetaDataSvc", name()}
private

Get a handle on the metadata store for the job.

Definition at line 84 of file FileMetaDataTool.h.

84{"MetaDataSvc", name()};

◆ m_toolMutex

std::mutex xAODMaker::FileMetaDataTool::m_toolMutex
private

Definition at line 88 of file FileMetaDataTool.h.


The documentation for this class was generated from the following files: