ATLAS Offline Software
Public Types | Private Member Functions | Private Attributes | List of all members
xAODMaker::EventFormatStreamHelperTool Class Reference

Tool creating and maintaining xAOD::EventFormat at the end-of-events. More...

#include <EventFormatStreamHelperTool.h>

Inheritance diagram for xAODMaker::EventFormatStreamHelperTool:
Collaboration diagram for xAODMaker::EventFormatStreamHelperTool:

Public Types

using sgkey_t = SG::sgkey_t
 

Public Member Functions

Interface inherited from @c AthAlgTool
StatusCode initialize () override
 Initialise the tool. More...
 
Interface inherited from @c IAthenaOutputTool
StatusCode postInitialize () override
 Called at the end of initialize. More...
 
StatusCode preExecute () override
 Called at the beginning of execute. More...
 
StatusCode postExecute () override
 Called at the end of execute. More...
 
StatusCode preFinalize () override
 Called at the beginning of finalize. More...
 
StatusCode preStream () override
 Called at the. More...
 

Private Member Functions

StatusCode collectFormatMetadata ()
 
sgkey_t lookUpHash (CLID primaryClassID, const std::set< CLID > &classIDs, const std::vector< sgkey_t > &hashes) const
 look up hash corresponding to primary class ID More...
 

Private Attributes

ServiceHandle< IAthMetaDataSvcm_metadataStore
 Use the metadata tool interface to store the EventFormat object. More...
 
ServiceHandle< IClassIDSvc > m_clidSvc
 Connection to the CLID service. More...
 
Gaudi::Property< std::string > m_key
 
Gaudi::Property< std::vector< std::string > > m_typeNames
 Type names for which a metadata entry should be added. More...
 
Gaudi::Property< std::vector< std::string > > m_ignoreKeys
 StoreGate keys that should be ignored during the metadata collection. More...
 
Gaudi::Property< std::string > m_dataHeaderKey
 
std::set< CLIDm_warnedCLIDs
 CLIDs about which warnings have already been printed. More...
 
std::mutex m_warnedCLIDsMutex
 Mutex for the m_warnedCLIDs variable. More...
 
std::mutex m_efMutex
 Mutex for the m_ef variable. More...
 

Detailed Description

Tool creating and maintaining xAOD::EventFormat at the end-of-events.

This tool is meant to be added to every xAOD output stream, so that it would maintain xAOD::EventFormat object every time a new event is written out.

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 29 of file EventFormatStreamHelperTool.h.

Member Typedef Documentation

◆ sgkey_t

Definition at line 31 of file EventFormatStreamHelperTool.h.

Member Function Documentation

◆ collectFormatMetadata()

StatusCode xAODMaker::EventFormatStreamHelperTool::collectFormatMetadata ( )
private

Definition at line 48 of file EventFormatStreamHelperTool.cxx.

48  {
49  // Get the EventFormat object
50  xAOD::EventFormat * event_format =
51  m_metadataStore->tryRetrieve< xAOD::EventFormat >(m_key.value());
52 
53  if (!event_format) {
54  auto p_event_format = std::make_unique< xAOD::EventFormat >();
55  event_format = p_event_format.get();
56  ATH_CHECK(m_metadataStore->record(std::move(p_event_format), m_key));
57  ATH_MSG_VERBOSE("Created new xAOD::EventFormat: " << m_key.value());
58  } else {
59  ATH_MSG_VERBOSE("Use existing xAOD::EventFormat: " << m_key.value());
60  }
61 
62  // Grab output stream data header
64  if (!dataHeader.isValid()) {
65  // DataHeader won't exist if this event was rejected.
66  return StatusCode::SUCCESS;
67  }
68 
69  // Loop over objects in output stream
70  for (const DataHeaderElement& elem : *dataHeader) {
71  // Caveat: assume branch name that Athena I/O is going to give to
72  // this object is the key name
73  const std::string& key = elem.getKey();
74  const CLID classID = elem.getPrimaryClassID();
75 
76  // Skip objects that were set up to be ignored.
77  {
78  bool ignoreObject = false;
79  for (const std::string& ignorePattern : m_ignoreKeys.value()) {
80  if (std::regex_match(key, std::regex(ignorePattern))) {
81  ignoreObject = true;
82  break;
83  }
84  }
85  if (ignoreObject) continue;
86  }
87 
88  // Get the type name of this object.
89  std::string typeName;
90  if (m_clidSvc->getTypeInfoNameOfID(classID, typeName).isFailure()) {
91  // Make sure that nobody else is using @c m_warnedCLIDs right now.
92  std::lock_guard< std::mutex > lock(m_warnedCLIDsMutex);
93 
94  // Print a warning if this CLID didn't produce a warning yet:
95  if (m_warnedCLIDs.insert(classID).second)
96  ATH_MSG_WARNING("Couldn't get type name for CLID = " << classID );
97 
98  continue;
99  }
100 
101  // Now that we have the type name, check whether metadata for this type
102  // should be stored.
103  {
104  bool ignoreObject = true;
105  for (const std::string& typePattern : m_typeNames.value()) {
106  if (std::regex_match(typeName, std::regex(typePattern))) {
107  ignoreObject = false;
108  break;
109  }
110  }
111  if (ignoreObject) continue;
112  }
113 
114  // Update the metadata object
115  try {
116  const sgkey_t hash =
117  lookUpHash(classID, elem.getClassIDs(), elem.getHashes());
118 
119  // Make sure that nobody else is modifying @c m_ef or @c m_spool
120  // right now.
121  std::lock_guard< std::mutex > lock(m_efMutex);
122  // If we already know about this object, then don't bother.
123  if (event_format->exists(key)) continue;
124 
125  // Add the info.
126  event_format->add(xAOD::EventFormatElement(key, typeName, "", hash));
127 
128  // Tell the user what happened.
129  ATH_MSG_VERBOSE("Adding info: key = \"" << key
130  << ", typeName = \"" << typeName << "\""
131  << ", hash = 0x" << std::hex << std::setw(8)
132  << std::setfill('0') << hash);
133  } catch (const std::exception& e) {
134  ATH_MSG_WARNING(e.what());
135  }
136  }
137 
138  // Return gracefully.
139  return StatusCode::SUCCESS;
140  }

◆ initialize()

StatusCode xAODMaker::EventFormatStreamHelperTool::initialize ( )
override

Initialise the tool.

Definition at line 21 of file EventFormatStreamHelperTool.cxx.

21  {
22  // Retrieve all needed components.
23  ATH_CHECK(m_metadataStore.retrieve());
24 
25  if (m_dataHeaderKey.empty()) {
26  // find out name of stream we are working for
27  const Gaudi::Algorithm *parentAlg =
28  dynamic_cast< const Gaudi::Algorithm* >(parent());
29  if (parentAlg) m_dataHeaderKey = parentAlg->name();
30  }
31 
32  // Return gracefully
33  return StatusCode::SUCCESS;
34  }

◆ lookUpHash()

EventFormatStreamHelperTool::sgkey_t xAODMaker::EventFormatStreamHelperTool::lookUpHash ( CLID  primaryClassID,
const std::set< CLID > &  classIDs,
const std::vector< sgkey_t > &  hashes 
) const
private

look up hash corresponding to primary class ID

We can retrieve the list of all class IDs and hashes corresponding to an element in the output stream. The two collections should be of the same size. Element one of the classIDs corresponds to element one of the hashes and so on. This function steps through the two collections and returns the hash corresponding to the classID matching the primaryClassID.

Parameters
[in]primaryClassIDthe primary class ID
[in]classIDsthe set of classIDs associated with a DataHeaderElement
[in]hashesthe vector of hashes associated with a DataHeaderElement
Warning
classIDs and hashes must have the same number of entries
Exceptions
std::runtime_errorclassIDs and hashes not the same size
std::range_errorprimaryClassID not found in classIDs
Returns
the hash corresponding to the primaryClassID

Definition at line 143 of file EventFormatStreamHelperTool.cxx.

146  {
147  // two collections of different size would cause undefined behaviour
148  if (classIDs.size() != hashes.size())
149  throw(std::runtime_error("CLID and hash sets not equal in size"));
150 
151  auto it = classIDs.find(primaryClassID);
152 
153  // bail if we don't find the primary class ID
154  if (it == classIDs.end())
155  throw(std::range_error("Primary class ID not in list of class IDs"));
156 
157  return hashes[std::distance(classIDs.begin(), it)];
158  }

◆ postExecute()

StatusCode xAODMaker::EventFormatStreamHelperTool::postExecute ( )
override

Called at the end of execute.

Definition at line 37 of file EventFormatStreamHelperTool.cxx.

37  {
38  // Notify the event format service that it should collect the metadata
39  // that it needs.
41  ATH_MSG_VERBOSE("Triggered metadata collection on: " << m_key.value());
42 
43  // Return gracefully.
44  return StatusCode::SUCCESS;
45  }

◆ postInitialize()

StatusCode xAODMaker::EventFormatStreamHelperTool::postInitialize ( )
inlineoverride

Called at the end of initialize.

Definition at line 48 of file EventFormatStreamHelperTool.h.

48 {return StatusCode::SUCCESS;}

◆ preExecute()

StatusCode xAODMaker::EventFormatStreamHelperTool::preExecute ( )
inlineoverride

Called at the beginning of execute.

Definition at line 51 of file EventFormatStreamHelperTool.h.

51 {return StatusCode::SUCCESS;}

◆ preFinalize()

StatusCode xAODMaker::EventFormatStreamHelperTool::preFinalize ( )
inlineoverride

Called at the beginning of finalize.

Definition at line 57 of file EventFormatStreamHelperTool.h.

57 {return StatusCode::SUCCESS;}

◆ preStream()

StatusCode xAODMaker::EventFormatStreamHelperTool::preStream ( )
inlineoverride

Called at the.

Definition at line 60 of file EventFormatStreamHelperTool.h.

60 {return StatusCode::SUCCESS;}

Member Data Documentation

◆ m_clidSvc

ServiceHandle< IClassIDSvc > xAODMaker::EventFormatStreamHelperTool::m_clidSvc
private
Initial value:
{ this, "ClassIDSvc", "ClassIDSvc",
"The ClassID service instance to use" }

Connection to the CLID service.

Definition at line 70 of file EventFormatStreamHelperTool.h.

◆ m_dataHeaderKey

Gaudi::Property< std::string > xAODMaker::EventFormatStreamHelperTool::m_dataHeaderKey
private
Initial value:
{this, "DataHeaderKey", "",
"Key of DataHeader produced by output stream" }

Definition at line 86 of file EventFormatStreamHelperTool.h.

◆ m_efMutex

std::mutex xAODMaker::EventFormatStreamHelperTool::m_efMutex
mutableprivate

Mutex for the m_ef variable.

Definition at line 124 of file EventFormatStreamHelperTool.h.

◆ m_ignoreKeys

Gaudi::Property< std::vector< std::string > > xAODMaker::EventFormatStreamHelperTool::m_ignoreKeys
private
Initial value:
{ this,
"IgnoreKeys", { "HLTAutoKey_.*" },
"SG keys that should be ignored during the metadata collection" }

StoreGate keys that should be ignored during the metadata collection.

Definition at line 82 of file EventFormatStreamHelperTool.h.

◆ m_key

Gaudi::Property< std::string > xAODMaker::EventFormatStreamHelperTool::m_key
private
Initial value:
{ this, "Key", "EventInfo",
"Key for EventFormat object in metadata store" }

Definition at line 73 of file EventFormatStreamHelperTool.h.

◆ m_metadataStore

ServiceHandle< IAthMetaDataSvc > xAODMaker::EventFormatStreamHelperTool::m_metadataStore
private
Initial value:
{ this, "MetaDataSvc",
"MetaDataSvc", "The metadata service use to record the xAOD::EventFormat" }

Use the metadata tool interface to store the EventFormat object.

Definition at line 66 of file EventFormatStreamHelperTool.h.

◆ m_typeNames

Gaudi::Property< std::vector< std::string > > xAODMaker::EventFormatStreamHelperTool::m_typeNames
private
Initial value:
{ this,
"TypeNames", { ".*xAOD::.*", "DataVector<SG::AuxElement>" },
"Type names for which metadata entries are added" }

Type names for which a metadata entry should be added.

Definition at line 77 of file EventFormatStreamHelperTool.h.

◆ m_warnedCLIDs

std::set< CLID > xAODMaker::EventFormatStreamHelperTool::m_warnedCLIDs
private

CLIDs about which warnings have already been printed.

Definition at line 119 of file EventFormatStreamHelperTool.h.

◆ m_warnedCLIDsMutex

std::mutex xAODMaker::EventFormatStreamHelperTool::m_warnedCLIDsMutex
private

Mutex for the m_warnedCLIDs variable.

Definition at line 121 of file EventFormatStreamHelperTool.h.


The documentation for this class was generated from the following files:
python.root_lsr_rank.hashes
hashes
Definition: root_lsr_rank.py:34
xAODMaker::EventFormatStreamHelperTool::sgkey_t
SG::sgkey_t sgkey_t
Definition: EventFormatStreamHelperTool.h:31
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
xAOD::EventFormat_v1::get
const EventFormatElement * get(const std::string &key, bool quiet=false) const
Get the description of a given branch.
Definition: EventFormat_v1.cxx:91
xAODMaker::EventFormatStreamHelperTool::m_ignoreKeys
Gaudi::Property< std::vector< std::string > > m_ignoreKeys
StoreGate keys that should be ignored during the metadata collection.
Definition: EventFormatStreamHelperTool.h:82
xAODMaker::EventFormatStreamHelperTool::lookUpHash
sgkey_t lookUpHash(CLID primaryClassID, const std::set< CLID > &classIDs, const std::vector< sgkey_t > &hashes) const
look up hash corresponding to primary class ID
Definition: EventFormatStreamHelperTool.cxx:143
xAODMaker::EventFormatStreamHelperTool::m_warnedCLIDsMutex
std::mutex m_warnedCLIDsMutex
Mutex for the m_warnedCLIDs variable.
Definition: EventFormatStreamHelperTool.h:121
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
skel.it
it
Definition: skel.GENtoEVGEN.py:396
xAOD::EventFormatElement
Class describing one branch of the ROOT file.
Definition: EventFormatElement.h:39
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
PrepareReferenceFile.regex
regex
Definition: PrepareReferenceFile.py:43
DataHeaderElement
This class provides a persistent form for the TransientAddress.
Definition: DataHeader.h:36
xAODMaker::EventFormatStreamHelperTool::m_efMutex
std::mutex m_efMutex
Mutex for the m_ef variable.
Definition: EventFormatStreamHelperTool.h:124
calibdata.exception
exception
Definition: calibdata.py:496
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAODMaker::EventFormatStreamHelperTool::m_warnedCLIDs
std::set< CLID > m_warnedCLIDs
CLIDs about which warnings have already been printed.
Definition: EventFormatStreamHelperTool.h:119
xAODMaker::EventFormatStreamHelperTool::m_metadataStore
ServiceHandle< IAthMetaDataSvc > m_metadataStore
Use the metadata tool interface to store the EventFormat object.
Definition: EventFormatStreamHelperTool.h:66
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
xAOD::EventFormat_v1
Event format metadata for xAOD files.
Definition: EventFormat_v1.h:38
xAODMaker::EventFormatStreamHelperTool::m_dataHeaderKey
Gaudi::Property< std::string > m_dataHeaderKey
Definition: EventFormatStreamHelperTool.h:86
xAODMaker::EventFormatStreamHelperTool::m_key
Gaudi::Property< std::string > m_key
Definition: EventFormatStreamHelperTool.h:73
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
ReadCalibFromCool.typeName
typeName
Definition: ReadCalibFromCool.py:477
xAOD::EventFormat_v1::add
void add(const EventFormatElement &element, bool updatePersistent=true)
Add the description of a new branch.
Definition: EventFormat_v1.cxx:43
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition: GeoPrimitivesHelpers.h:54
xAODMaker::EventFormatStreamHelperTool::m_clidSvc
ServiceHandle< IClassIDSvc > m_clidSvc
Connection to the CLID service.
Definition: EventFormatStreamHelperTool.h:70
xAODMaker::EventFormatStreamHelperTool::collectFormatMetadata
StatusCode collectFormatMetadata()
Definition: EventFormatStreamHelperTool.cxx:48
xAOD::EventFormat_v1::exists
bool exists(const std::string &key) const
Check if a description exists about a given branch.
Definition: EventFormat_v1.cxx:65
xAODMaker::EventFormatStreamHelperTool::m_typeNames
Gaudi::Property< std::vector< std::string > > m_typeNames
Type names for which a metadata entry should be added.
Definition: EventFormatStreamHelperTool.h:77
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37