ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
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. More...
 
virtual StatusCode postInitialize () override
 Called at the end of initialize. More...
 
virtual StatusCode preExecute () override
 Called at the beginning of execute. More...
 
virtual StatusCode preStream () override
 Called before actually streaming objects. More...
 
virtual StatusCode postExecute () override
 Called at the end of execute. More...
 
virtual StatusCode preFinalize () override
 Called at the beginning of finalize. More...
 

Private Member Functions

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

Private Attributes

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

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 }

◆ 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 {
143  EventContext ctx = Gaudi::Hive::currentContext();
145  Gaudi::Hive::setCurrentContext (ctx);
146  }
147 
148  m_cache.clear();
149  return StatusCode::SUCCESS;
150 }

◆ 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();
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 }

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

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


The documentation for this class was generated from the following files:
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:71
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
hotSpotInTAG.suffix
string suffix
Definition: hotSpotInTAG.py:186
StateLessPT_NewConfig.proxy
proxy
Definition: StateLessPT_NewConfig.py:392
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
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
IProxyDict
A proxy dictionary.
Definition: AthenaKernel/AthenaKernel/IProxyDict.h:47
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
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:58
SG::ThinningCache::clear
void clear()
Clear the cache.
Definition: ThinningCache.cxx:186
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
Athena::ThinningCacheTool::m_cache
SG::ThinningCache m_cache
Thinning cache instance for this stream.
Definition: ThinningCacheTool.h:103
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:389
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::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
SG::DataProxy
Definition: DataProxy.h:44
SG::ConstIterator
Definition: SGIterator.h:163
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37