ATLAS Offline Software
Loading...
Searching...
No Matches
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.
Interface inherited from @c IAthenaOutputTool
StatusCode postInitialize () override
 Called at the end of initialize.
StatusCode preExecute () override
 Called at the beginning of execute.
StatusCode postExecute () override
 Called at the end of execute.
StatusCode preFinalize () override
 Called at the beginning of finalize.
StatusCode preStream () override
 Called at the.

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

Private Attributes

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

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

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
63 SG::ReadHandle< DataHeader > dataHeader(m_dataHeaderKey);
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 }
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
uint32_t CLID
The Class ID type.
std::mutex m_efMutex
Mutex for the m_ef variable.
Gaudi::Property< std::vector< std::string > > m_typeNames
Type names for which a metadata entry should be added.
ServiceHandle< IAthMetaDataSvc > m_metadataStore
Use the metadata tool interface to store the EventFormat object.
std::set< CLID > m_warnedCLIDs
CLIDs about which warnings have already been printed.
Gaudi::Property< std::vector< std::string > > m_ignoreKeys
StoreGate keys that should be ignored during the metadata collection.
ServiceHandle< IClassIDSvc > m_clidSvc
Connection to the CLID service.
std::mutex m_warnedCLIDsMutex
Mutex for the m_warnedCLIDs variable.
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
void add(const EventFormatElement &element, bool updatePersistent=true)
Add the description of a new branch.
bool exists(const std::string &key) const
Check if a description exists about a given branch.
const EventFormatElement * get(const std::string &key, bool quiet=false) const
Get the description of a given branch.
EventFormat_v1 EventFormat
Definition of the current event format version.
Definition EventFormat.h:16

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

70 { this, "ClassIDSvc", "ClassIDSvc",
71 "The ClassID service instance to use" };

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

86 {this, "DataHeaderKey", "",
87 "Key of DataHeader produced by output stream" };

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

82 { this,
83 "IgnoreKeys", { "HLTAutoKey_.*" },
84 "SG keys that should be ignored during the metadata collection" };

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

73 { this, "Key", "EventInfo",
74 "Key for EventFormat object in metadata store" };

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

66 { this, "MetaDataSvc",
67 "MetaDataSvc", "The metadata service use to record the xAOD::EventFormat" };

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

77 { this,
78 "TypeNames", { ".*xAOD::.*", "DataVector<SG::AuxElement>" },
79 "Type names for which metadata entries are added" };

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