ATLAS Offline Software
Loading...
Searching...
No Matches
ThinningCacheTool.cxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration.
3 */
10
11
12#include "ThinningCacheTool.h"
14#include "SGTools/DataProxy.h"
17#include "GaudiKernel/ThreadLocalContext.h"
18#include "SelectionVetoes.h"
19#include "CompressionInfo.h"
20
21namespace Athena {
22
23
28{
29 if (!m_trigNavigationThinningSvc.empty()) {
31 }
32 return StatusCode::SUCCESS;
33}
34
35
40{
41 return StatusCode::SUCCESS;
42}
43
44
49{
50 return StatusCode::SUCCESS;
51}
52
53
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.
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}
134
135
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}
151
152
157{
158 return StatusCode::SUCCESS;
159}
160
161
169std::string ThinningCacheTool::wantedKey (const std::string& key) const
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}
181
182
183} // namespace Athena
184
#define ATH_CHECK
Evaluate an expression and check for errors.
uint32_t CLID
The Class ID type.
Create ThinningCache for a given stream.
Hold thinning decisions for one container.
StringProperty m_streamName
Name of the stream for this tool.
ServiceHandle< ITrigNavigationThinningSvc > m_trigNavigationThinningSvc
Optional TrigNavigation thinning service to use.
SG::ThinningCache m_cache
Thinning cache instance for this stream.
virtual StatusCode initialize() override
Gaudi initialize method.
virtual StatusCode preStream() override
Called before actually streaming objects.
virtual StatusCode preExecute() override
Called at the beginning of execute.
virtual StatusCode preFinalize() override
Called at the beginning of finalize.
std::string wantedKey(const std::string &key) const
Test if a thinning decision object is for our stream.
virtual StatusCode postExecute() override
Called at the end of execute.
virtual StatusCode postInitialize() override
Called at the end of initialize.
void setThinningCache(const SG::ThinningCache *cache)
Thread-local thinning cache.
virtual sgkey_t stringToKey(const std::string &str, CLID clid) override
a const_iterator facade to DataHandle.
Definition SGIterator.h:164
Hold thinning decisions for one container.
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
Some weak symbol referencing magic... These are declared in AthenaKernel/getMessageSvc....
const ExtendedEventContext & getExtendedEventContext(const EventContext &ctx)
Retrieve an extended context from a context object.
bool hasExtendedEventContext(const EventContext &ctx)
Test whether a context object has an extended context installed.
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.