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::vector< std::regex > m_ignoreKeyRegexes
 m_ignoreKeys, compiled once in initialize()
std::vector< std::regex > m_typeNameRegexes
 m_typeNames, compiled once in initialize()
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 30 of file EventFormatStreamHelperTool.h.

Member Typedef Documentation

◆ sgkey_t

Member Function Documentation

◆ collectFormatMetadata()

StatusCode xAODMaker::EventFormatStreamHelperTool::collectFormatMetadata ( )
private

Definition at line 57 of file EventFormatStreamHelperTool.cxx.

57 {
58 // Get the EventFormat object
59 xAOD::EventFormat * event_format =
60 m_metadataStore->tryRetrieve< xAOD::EventFormat >(m_key.value());
61
62 if (!event_format) {
63 auto p_event_format = std::make_unique< xAOD::EventFormat >();
64 event_format = p_event_format.get();
65 ATH_CHECK(m_metadataStore->record(std::move(p_event_format), m_key));
66 ATH_MSG_VERBOSE("Created new xAOD::EventFormat: " << m_key.value());
67 } else {
68 ATH_MSG_VERBOSE("Use existing xAOD::EventFormat: " << m_key.value());
69 }
70
71 // Grab output stream data header
72 SG::ReadHandle< DataHeader > dataHeader(m_dataHeaderKey);
73 if (!dataHeader.isValid()) {
74 // DataHeader won't exist if this event was rejected.
75 return StatusCode::SUCCESS;
76 }
77
78 // Loop over objects in output stream
79 for (const DataHeaderElement& elem : *dataHeader) {
80 // Caveat: assume branch name that Athena I/O is going to give to
81 // this object is the key name
82 const std::string& key = elem.getKey();
83 const CLID classID = elem.getPrimaryClassID();
84
85 // Skip objects that were set up to be ignored.
86 {
87 bool ignoreObject = false;
88 for (const std::regex& ignorePattern : m_ignoreKeyRegexes) {
89 if (std::regex_match(key, ignorePattern)) {
90 ignoreObject = true;
91 break;
92 }
93 }
94 if (ignoreObject) continue;
95 }
96
97 // Get the type name of this object.
98 std::string typeName;
99 if (m_clidSvc->getTypeInfoNameOfID(classID, typeName).isFailure()) {
100 // Make sure that nobody else is using @c m_warnedCLIDs right now.
101 std::lock_guard< std::mutex > lock(m_warnedCLIDsMutex);
102
103 // Print a warning if this CLID didn't produce a warning yet:
104 if (m_warnedCLIDs.insert(classID).second)
105 ATH_MSG_WARNING("Couldn't get type name for CLID = " << classID );
106
107 continue;
108 }
109
110 // Now that we have the type name, check whether metadata for this type
111 // should be stored.
112 {
113 bool ignoreObject = true;
114 for (const std::regex& typePattern : m_typeNameRegexes) {
115 if (std::regex_match(typeName, typePattern)) {
116 ignoreObject = false;
117 break;
118 }
119 }
120 if (ignoreObject) continue;
121 }
122
123 // Update the metadata object
124 try {
125 const sgkey_t hash =
126 lookUpHash(classID, elem.getClassIDs(), elem.getHashes());
127
128 // Make sure that nobody else is modifying @c m_ef or @c m_spool
129 // right now.
130 std::lock_guard< std::mutex > lock(m_efMutex);
131 // If we already know about this object, then don't bother.
132 if (event_format->exists(key)) continue;
133 static const std::string emptyStr{};
134 // Add the info.
135 event_format->add(xAOD::EventFormatElement(key, typeName, emptyStr, hash));
136
137 // Tell the user what happened.
138 ATH_MSG_VERBOSE("Adding info: key = \"" << key
139 << ", typeName = \"" << typeName << "\""
140 << ", hash = 0x" << std::hex << std::setw(8)
141 << std::setfill('0') << hash);
142 } catch (const std::exception& e) {
143 ATH_MSG_WARNING(e.what());
144 }
145 }
146
147 // Return gracefully.
148 return StatusCode::SUCCESS;
149 }
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_VERBOSE(x,...)
uint32_t CLID
The Class ID type.
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
std::mutex m_efMutex
Mutex for the m_ef variable.
std::vector< std::regex > m_ignoreKeyRegexes
m_ignoreKeys, compiled once in initialize()
std::vector< std::regex > m_typeNameRegexes
m_typeNames, compiled once in initialize()
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.
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 // Compile the configured patterns once, so that the event loop doesn't
26 // have to do it for every object of every event.
27 m_ignoreKeyRegexes.reserve(m_ignoreKeys.size());
28 for (const std::string& pattern : m_ignoreKeys.value())
29 m_ignoreKeyRegexes.emplace_back(pattern, std::regex::optimize);
30 m_typeNameRegexes.reserve(m_typeNames.size());
31 for (const std::string& pattern : m_typeNames.value())
32 m_typeNameRegexes.emplace_back(pattern, std::regex::optimize);
33
34 if (m_dataHeaderKey.empty()) {
35 // find out name of stream we are working for
36 const Gaudi::Algorithm *parentAlg =
37 dynamic_cast< const Gaudi::Algorithm* >(parent());
38 if (parentAlg) m_dataHeaderKey = parentAlg->name();
39 }
40
41 // Return gracefully
42 return StatusCode::SUCCESS;
43 }
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.

◆ 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 152 of file EventFormatStreamHelperTool.cxx.

155 {
156 // two collections of different size would cause undefined behaviour
157 if (classIDs.size() != hashes.size())
158 throw(std::runtime_error("CLID and hash sets not equal in size"));
159
160 auto it = classIDs.find(primaryClassID);
161
162 // bail if we don't find the primary class ID
163 if (it == classIDs.end())
164 throw(std::range_error("Primary class ID not in list of class IDs"));
165
166 return hashes[std::distance(classIDs.begin(), it)];
167 }

◆ postExecute()

StatusCode xAODMaker::EventFormatStreamHelperTool::postExecute ( )
override

Called at the end of execute.

Definition at line 46 of file EventFormatStreamHelperTool.cxx.

46 {
47 // Notify the event format service that it should collect the metadata
48 // that it needs.
50 ATH_MSG_VERBOSE("Triggered metadata collection on: " << m_key.value());
51
52 // Return gracefully.
53 return StatusCode::SUCCESS;
54 }

◆ postInitialize()

StatusCode xAODMaker::EventFormatStreamHelperTool::postInitialize ( )
inlineoverride

Called at the end of initialize.

Definition at line 49 of file EventFormatStreamHelperTool.h.

49{return StatusCode::SUCCESS;}

◆ preExecute()

StatusCode xAODMaker::EventFormatStreamHelperTool::preExecute ( )
inlineoverride

Called at the beginning of execute.

Definition at line 52 of file EventFormatStreamHelperTool.h.

52{return StatusCode::SUCCESS;}

◆ preFinalize()

StatusCode xAODMaker::EventFormatStreamHelperTool::preFinalize ( )
inlineoverride

Called at the beginning of finalize.

Definition at line 58 of file EventFormatStreamHelperTool.h.

58{return StatusCode::SUCCESS;}

◆ preStream()

StatusCode xAODMaker::EventFormatStreamHelperTool::preStream ( )
inlineoverride

Called at the.

Definition at line 61 of file EventFormatStreamHelperTool.h.

61{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 71 of file EventFormatStreamHelperTool.h.

71 { this, "ClassIDSvc", "ClassIDSvc",
72 "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 87 of file EventFormatStreamHelperTool.h.

87 {this, "DataHeaderKey", "",
88 "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 130 of file EventFormatStreamHelperTool.h.

◆ m_ignoreKeyRegexes

std::vector< std::regex > xAODMaker::EventFormatStreamHelperTool::m_ignoreKeyRegexes
private

m_ignoreKeys, compiled once in initialize()

Definition at line 93 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 83 of file EventFormatStreamHelperTool.h.

83 { this,
84 "IgnoreKeys", { "HLTAutoKey_.*" },
85 "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 74 of file EventFormatStreamHelperTool.h.

74 { this, "Key", "EventInfo",
75 "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 67 of file EventFormatStreamHelperTool.h.

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

◆ m_typeNameRegexes

std::vector< std::regex > xAODMaker::EventFormatStreamHelperTool::m_typeNameRegexes
private

m_typeNames, compiled once in initialize()

Definition at line 95 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 78 of file EventFormatStreamHelperTool.h.

78 { this,
79 "TypeNames", { ".*xAOD::.*", "DataVector<SG::AuxElement>" },
80 "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 125 of file EventFormatStreamHelperTool.h.

◆ m_warnedCLIDsMutex

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

Mutex for the m_warnedCLIDs variable.

Definition at line 127 of file EventFormatStreamHelperTool.h.


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