ATLAS Offline Software
ThinningCacheTool.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration.
3  */
12 #include "ThinningCacheTool.h"
14 #include "SGTools/DataProxy.h"
17 #include "GaudiKernel/ThreadLocalContext.h"
18 #include "SelectionVetoes.h"
19 #include "CompressionInfo.h"
20 
21 namespace 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();
65  if (!Atlas::hasExtendedEventContext (ctx)) {
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()) {
122  }
123 
124  // If there was any thinning for this stream, then install the cache
125  // in the EventContext.
127  m_cache.lockOwned();
129  Gaudi::Hive::setCurrentContext (ctx);
130  }
131 
132  return StatusCode::SUCCESS;
133 }
134 
135 
141 {
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 
169 std::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 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:69
SG::ThinningCache::setCompression
void setCompression(const std::string &key, const ThinningInfo::compression_map_t &compression)
Set lossy float compression information for the object.
Definition: ThinningCache.cxx:160
Athena::ThinningCacheTool::postExecute
virtual StatusCode postExecute() override
Called at the end of execute.
Definition: ThinningCacheTool.cxx:140
hotSpotInTAG.suffix
string suffix
Definition: hotSpotInTAG.py:186
StateLessPT_NewConfig.proxy
proxy
Definition: StateLessPT_NewConfig.py:392
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
Athena::ThinningCacheTool::wantedKey
std::string wantedKey(const std::string &key) const
Test if a thinning decision object is for our stream.
Definition: ThinningCacheTool.cxx:169
ThinningCacheTool.h
Create ThinningCache for a given stream.
ExtendedEventContext.h
SG::SelectionVetoes
std::unordered_map< std::string, SG::auxid_set_t > SelectionVetoes
Map of vetoed variables.
Definition: SelectionVetoes.h:50
Atlas::hasExtendedEventContext
bool hasExtendedEventContext(const EventContext &ctx)
Test whether a context object has an extended context installed.
Definition: ExtendedEventContext.cxx:23
Atlas::ExtendedEventContext::setThinningCache
void setThinningCache(const SG::ThinningCache *cache)
Thread-local thinning cache.
Definition: ExtendedEventContext.h:62
SG::ThinningCache::lockOwned
void lockOwned()
Lock all the ThinningDecisionBase objects that we own.
Definition: ThinningCache.cxx:134
Athena::ThinningCacheTool::m_streamName
StringProperty m_streamName
Name of the stream for this tool.
Definition: ThinningCacheTool.h:94
SG::ThinningCache::trigNavigationThinningSvc
const ITrigNavigationThinningSvc * trigNavigationThinningSvc() const
Return the TrigNavigation helper for this stream, or nullptr.
Definition: ThinningCache.cxx:112
Athena::ThinningCacheTool::postInitialize
virtual StatusCode postInitialize() override
Called at the end of initialize.
Definition: ThinningCacheTool.cxx:39
IProxyDict
A proxy dictionary.
Definition: AthenaKernel/AthenaKernel/IProxyDict.h:51
Athena::ThinningCacheTool::initialize
virtual StatusCode initialize() override
Gaudi initialize method.
Definition: ThinningCacheTool.cxx:27
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
Athena::ThinningCacheTool::preStream
virtual StatusCode preStream() override
Called before actually streaming objects.
Definition: ThinningCacheTool.cxx:59
SG::ThinningCache::addThinning
void addThinning(const std::string &key, const std::vector< sgkey_t > &sgkeys, const ThinningDecisionBase *thinning, bool unique=false)
Add thinning information for one object.
Definition: ThinningCache.cxx:77
Atlas::getExtendedEventContext
const ExtendedEventContext & getExtendedEventContext(const EventContext &ctx)
Retrieve an extended context from a context object.
Definition: ExtendedEventContext.cxx:32
DiTauMassTools::ignore
void ignore(T &&)
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:54
SG::ThinningCache::clear
void clear()
Clear the cache.
Definition: ThinningCache.cxx:186
Athena::ThinningCacheTool::m_cache
SG::ThinningCache m_cache
Thinning cache instance for this stream.
Definition: ThinningCacheTool.h:103
Athena
Some weak symbol referencing magic...
Definition: AthLegacySequence.h:21
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ThinningDecision.h
Hold thinning decisions for one container.
Athena::ThinningCacheTool::preFinalize
virtual StatusCode preFinalize() override
Called at the beginning of finalize.
Definition: ThinningCacheTool.cxx:156
SG::ThinningDecision
Hold thinning decisions for one container.
Definition: ThinningDecision.h:40
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
StoreGateSvc::stringToKey
virtual sgkey_t stringToKey(const std::string &str, CLID clid) override final
Find the key for a string/CLID pair.
Definition: StoreGateSvc.cxx:400
SG::CompressionInfo
std::unordered_map< std::string, SG::ThinningInfo::compression_map_t > CompressionInfo
Map of compressed variables and their compression levels.
Definition: CompressionInfo.h:37
SG::ThinningCache::setVetoed
void setVetoed(const std::string &key, const CxxUtils::ConcurrentBitset &vetoed)
Set vetoed variable information one object.
Definition: ThinningCache.cxx:148
Athena::ThinningCacheTool::preExecute
virtual StatusCode preExecute() override
Called at the beginning of execute.
Definition: ThinningCacheTool.cxx:48
IProxyDict.h
Athena::ThinningCacheTool::m_trigNavigationThinningSvc
ServiceHandle< ITrigNavigationThinningSvc > m_trigNavigationThinningSvc
Optional TrigNavigation thinning service to use.
Definition: ThinningCacheTool.h:99
WriteBchToCool.beg
beg
Definition: WriteBchToCool.py:69
SG::ThinningCache::setTrigNavigationThinningSvc
void setTrigNavigationThinningSvc(const ITrigNavigationThinningSvc *thinning)
Set the TrigNavigation helper for this stream.
Definition: ThinningCache.cxx:122
SG::ThinningCache::empty
bool empty() const
Test to see if there's any thinning defined.
Definition: ThinningCache.cxx:22
SelectionVetoes.h
CompressionInfo.h
SG::DataProxy
Definition: DataProxy.h:44
SG::ConstIterator
Definition: SGIterator.h:163
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
DataProxy.h