Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
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. More...
 
StatusCode initialize () override
 Function initialising the tool. More...
 
Functions called by the IMetaDataTool base class
StatusCode beginInputFile () override
 Collecting file metadata from input and write to output. More...
 
StatusCode endInputFile () override
 Does nothing. More...
 
StatusCode beginInputFile (const SG::SourceID &) override
 Collecting file metadata from input and write to output. More...
 
StatusCode endInputFile (const SG::SourceID &) override
 Does nothing. More...
 
StatusCode metaDataStop () override
 Does nothing. More...
 

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

◆ 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();};

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

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

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

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

◆ 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:
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
beamspotnt.var
var
Definition: bin/beamspotnt.py:1394
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
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
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
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
merge.output
output
Definition: merge.py:17
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
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
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:798
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37