ATLAS Offline Software
Loading...
Searching...
No Matches
Athena::ThinningCacheTool Class Reference

Create ThinningCache for a given stream. More...

#include <ThinningCacheTool.h>

Inheritance diagram for Athena::ThinningCacheTool:
Collaboration diagram for Athena::ThinningCacheTool:

Public Member Functions

virtual StatusCode initialize () override
 Gaudi initialize method.
virtual StatusCode postInitialize () override
 Called at the end of initialize.
virtual StatusCode preExecute () override
 Called at the beginning of execute.
virtual StatusCode preStream () override
 Called before actually streaming objects.
virtual StatusCode postExecute () override
 Called at the end of execute.
virtual StatusCode preFinalize () override
 Called at the beginning of finalize.

Private Member Functions

std::string wantedKey (const std::string &key) const
 Test if a thinning decision object is for our stream.

Private Attributes

StringProperty m_streamName { this, "StreamName", "", "Name of the stream being written." }
 Name of the stream for this tool.
ServiceHandle< ITrigNavigationThinningSvcm_trigNavigationThinningSvc { this, "TrigNavigationThinningSvc", "", "Service to use for TrigNavigation thinning (optional)." }
 Optional TrigNavigation thinning service to use.
SG::ThinningCache m_cache
 Thinning cache instance for this stream.

Detailed Description

Create ThinningCache for a given stream.

Hooks in this class are called before and after output is written for a given stream. The preExecute hook will query the event store for any thinning to be done for the stream, build a ThinningCache object for all of these, and install it in the current EventContext. The postExecute hook will then clear the cache from the EventContext.

Definition at line 36 of file ThinningCacheTool.h.

Member Function Documentation

◆ initialize()

StatusCode Athena::ThinningCacheTool::initialize ( )
overridevirtual

Gaudi initialize method.

Definition at line 27 of file ThinningCacheTool.cxx.

28{
29 if (!m_trigNavigationThinningSvc.empty()) {
31 }
32 return StatusCode::SUCCESS;
33}
#define ATH_CHECK
Evaluate an expression and check for errors.
ServiceHandle< ITrigNavigationThinningSvc > m_trigNavigationThinningSvc
Optional TrigNavigation thinning service to use.

◆ postExecute()

StatusCode Athena::ThinningCacheTool::postExecute ( )
overridevirtual

Called at the end of execute.

Remove ThinningCache from the EventContext and clear the cache instance.

Definition at line 140 of file ThinningCacheTool.cxx.

141{
142 if (!m_cache.empty() || m_cache.trigNavigationThinningSvc()) {
143 EventContext ctx = Gaudi::Hive::currentContext();
145 Gaudi::Hive::setCurrentContext (ctx);
146 }
147
148 m_cache.clear();
149 return StatusCode::SUCCESS;
150}
SG::ThinningCache m_cache
Thinning cache instance for this stream.
void setThinningCache(const SG::ThinningCache *cache)
Thread-local thinning cache.
const ExtendedEventContext & getExtendedEventContext(const EventContext &ctx)
Retrieve an extended context from a context object.

◆ postInitialize()

StatusCode Athena::ThinningCacheTool::postInitialize ( )
overridevirtual

Called at the end of initialize.

A no-op here.

Definition at line 39 of file ThinningCacheTool.cxx.

40{
41 return StatusCode::SUCCESS;
42}

◆ preExecute()

StatusCode Athena::ThinningCacheTool::preExecute ( )
overridevirtual

Called at the beginning of execute.

A no-op for now.

Definition at line 48 of file ThinningCacheTool.cxx.

49{
50 return StatusCode::SUCCESS;
51}

◆ preFinalize()

StatusCode Athena::ThinningCacheTool::preFinalize ( )
overridevirtual

Called at the beginning of finalize.

A no-op here.

Definition at line 156 of file ThinningCacheTool.cxx.

157{
158 return StatusCode::SUCCESS;
159}

◆ preStream()

StatusCode Athena::ThinningCacheTool::preStream ( )
overridevirtual

Called before actually streaming objects.

Find all thinning requests for this stream, build the ThinningCache, and install it in the current EventContext.

Definition at line 59 of file ThinningCacheTool.cxx.

60{
61 m_cache.clear();
62
63 // Nothing to do if we don't have an extended event context.
64 EventContext ctx = Gaudi::Hive::currentContext();
66 return StatusCode::SUCCESS;
67 }
68
69 // Examine all ThinningDecision objects in the store.
70 SG::ConstIterator<SG::ThinningDecision> beg;
71 SG::ConstIterator<SG::ThinningDecision> end;
72 // Will return FAILURE if no matches, so ignore.
73 evtStore()->retrieve<SG::ThinningDecision>(beg, end).ignore();
74 for (; beg != end; ++beg)
75 {
76 // See if this is for this stream.
77 std::string key = wantedKey (beg.key());
78 if (!key.empty()) {
79
80 // Get the set of hashed SG keys for this object.
81 std::vector<SG::sgkey_t> sgkeys;
82 SG::DataProxy* proxy = beg->link().proxy (true);
83 if (proxy) {
84 sgkeys.push_back (proxy->sgkey());
85 CLID pCLID = proxy->clID();
86 IProxyDict* store = proxy->store();
87 for (CLID clid : proxy->transientID()) {
88 if (clid != pCLID) {
89 sgkeys.push_back (store->stringToKey (key, clid));
90 }
91 }
92 }
93
94 // Add it to the cache.
95 m_cache.addThinning (key, sgkeys, &*beg);
96 }
97 }
98
99 // Look for any selection vetoes.
100 const std::string selVetoesKey = "SelectionVetoes_" + m_streamName;
101 const SG::SelectionVetoes* vetoes = nullptr;
102 if (evtStore()->contains<SG::SelectionVetoes> (selVetoesKey)) {
103 ATH_CHECK( evtStore()->retrieve (vetoes, selVetoesKey) );
104 for (const auto& p : *vetoes) {
105 m_cache.setVetoed (p.first, p.second);
106 }
107 }
108
109 // Look for any compression info
110 const std::string compInfoKey = "CompressionInfo_" + m_streamName;
111 const SG::CompressionInfo* compInfo = nullptr;
112 if (evtStore()->contains<SG::CompressionInfo> (compInfoKey)) {
113 ATH_CHECK( evtStore()->retrieve (compInfo, compInfoKey) );
114 for (const auto& p : *compInfo) {
115 m_cache.setCompression (p.first, p.second);
116 }
117 }
118
119 // Set the TrigNavigation thinning tool if needed.
120 if (!m_trigNavigationThinningSvc.empty()) {
121 m_cache.setTrigNavigationThinningSvc (m_trigNavigationThinningSvc.get());
122 }
123
124 // If there was any thinning for this stream, then install the cache
125 // in the EventContext.
126 if (!m_cache.empty() || m_cache.trigNavigationThinningSvc()) {
127 m_cache.lockOwned();
129 Gaudi::Hive::setCurrentContext (ctx);
130 }
131
132 return StatusCode::SUCCESS;
133}
uint32_t CLID
The Class ID type.
StringProperty m_streamName
Name of the stream for this tool.
std::string wantedKey(const std::string &key) const
Test if a thinning decision object is for our stream.
virtual sgkey_t stringToKey(const std::string &str, CLID clid) override
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
bool hasExtendedEventContext(const EventContext &ctx)
Test whether a context object has an extended context installed.
TestStore store
Definition TestStore.cxx:23
std::unordered_map< std::string, SG::auxid_set_t > SelectionVetoes
Map of vetoed variables.
std::unordered_map< std::string, SG::ThinningInfo::compression_map_t > CompressionInfo
Map of compressed variables and their compression levels.

◆ wantedKey()

std::string Athena::ThinningCacheTool::wantedKey ( const std::string & key) const
private

Test if a thinning decision object is for our stream.

Parameters
keyThe SG key of the ThinningDecision object.

If this thinning decision is for our stream, then return the SG key of the object being thinned. Otherwise, return an empty string.

Definition at line 169 of file ThinningCacheTool.cxx.

170{
171 std::string suffix = "_THINNED_" + m_streamName;
172 std::string::size_type spos = key.find (suffix);
173 if (spos != std::string::npos &&
174 (spos + suffix.size() == key.size() ||
175 key[spos + suffix.size()] == '.'))
176 {
177 return key.substr (0, spos);
178 }
179 return "";
180}

Member Data Documentation

◆ m_cache

SG::ThinningCache Athena::ThinningCacheTool::m_cache
private

Thinning cache instance for this stream.

Definition at line 103 of file ThinningCacheTool.h.

◆ m_streamName

StringProperty Athena::ThinningCacheTool::m_streamName { this, "StreamName", "", "Name of the stream being written." }
private

Name of the stream for this tool.

Definition at line 93 of file ThinningCacheTool.h.

94{ this, "StreamName", "", "Name of the stream being written." };

◆ m_trigNavigationThinningSvc

ServiceHandle<ITrigNavigationThinningSvc> Athena::ThinningCacheTool::m_trigNavigationThinningSvc { this, "TrigNavigationThinningSvc", "", "Service to use for TrigNavigation thinning (optional)." }
private

Optional TrigNavigation thinning service to use.

Definition at line 98 of file ThinningCacheTool.h.

99{ this, "TrigNavigationThinningSvc", "", "Service to use for TrigNavigation thinning (optional)." };

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