ATLAS Offline Software
Loading...
Searching...
No Matches
SG::ThinningCache Class Reference

Cache thinning decisions for converters. More...

#include <ThinningCache.h>

Collaboration diagram for SG::ThinningCache:

Public Member Functions

bool empty () const
 Test to see if there's any thinning defined.
const ThinningDecisionBasethinning (const std::string &key) const
 Return thinning for key.
const ThinningDecisionBasethinning (const sgkey_t sgkey) const
 Return thinning for sgkey.
void addThinning (const std::string &key, const std::vector< sgkey_t > &sgkeys, const ThinningDecisionBase *thinning, bool unique=false)
 Add thinning information for one object.
const ITrigNavigationThinningSvctrigNavigationThinningSvc () const
 Return the TrigNavigation helper for this stream, or nullptr.
void setTrigNavigationThinningSvc (const ITrigNavigationThinningSvc *thinning)
 Set the TrigNavigation helper for this stream.
void lockOwned ()
 Lock all the ThinningDecisionBase objects that we own.
void setVetoed (const std::string &key, const CxxUtils::ConcurrentBitset &vetoed)
 Set vetoed variable information one object.
void setCompression (const std::string &key, const ThinningInfo::compression_map_t &compression)
 Set lossy float compression information for the object.
const ThinningInfothinningInfo (const std::string &key) const
 Return thinning information for key.
void clear ()
 Clear the cache.

Private Types

typedef std::unordered_map< std::string, ThinningInfomap_t
 Mapping by string SG key.
typedef SGKeyMap< ThinningInfosgmap_t
 Mapping by hashed SG key.

Private Member Functions

void merge (ThinningInfo &info, const std::vector< sgkey_t > &sgkeys, const ThinningDecisionBase &thinning)
 Merge a new thinning request into an existing one via AND.

Private Attributes

map_t m_map
sgmap_t m_sgmap
std::vector< std::unique_ptr< ThinningDecisionBase > > m_owned
 List of decision objects we've copied in order to handle merges.
const ITrigNavigationThinningSvcm_trigNavigationThinningSvc = nullptr
 Optional TrigNavigation thinning helper for this stream.

Detailed Description

Cache thinning decisions for converters.

This class caches thinning decisions for a single stream for the use of converters. ThinningDecision objects may be looked up by SG key, either as a string or as a hashed value.

While writing is in progress, a pointer to the current cache is saved in the EventContext. Converters can find it there.

Definition at line 47 of file ThinningCache.h.

Member Typedef Documentation

◆ map_t

typedef std::unordered_map<std::string, ThinningInfo> SG::ThinningCache::map_t
private

Mapping by string SG key.

Definition at line 152 of file ThinningCache.h.

◆ sgmap_t

Mapping by hashed SG key.

Definition at line 156 of file ThinningCache.h.

Member Function Documentation

◆ addThinning()

void SG::ThinningCache::addThinning ( const std::string & key,
const std::vector< sgkey_t > & sgkeys,
const ThinningDecisionBase * thinning,
bool unique = false )

Add thinning information for one object.

Parameters
keySG string key of the object being added.
sgkeysSG hashed keys of the object being added.
thinningThinning information for the object.
uniqueIf true, the object must not already be listed in the cache.

If there is already thinning information in the cache for the object identified by key:

  • If unique is false, the new thinning request will be merged with the existing one via AND.
  • If unique is true, an exception will be thrown.

Definition at line 77 of file ThinningCache.cxx.

81{
82 if (!thinning) return;
83
84 {
85 ThinningInfo& info = m_map[key];
86 if (info.m_decision) {
87 if (!unique) {
88 merge (info, sgkeys, *thinning);
89 return;
90 }
91 throw std::runtime_error ("Duplicated thinning definition");
92 }
93 else {
94 info.m_decision = thinning;
95 }
96 }
97
98 for (sgkey_t sgkey : sgkeys) {
99 ThinningInfo& info = m_sgmap[sgkey];
100 if (info.m_decision) {
101 throw std::runtime_error ("Duplicated thinning definition");
102 }
103 info.m_decision = thinning;
104 }
105}
const ThinningDecisionBase * thinning(const std::string &key) const
Return thinning for key.
void merge(ThinningInfo &info, const std::vector< sgkey_t > &sgkeys, const ThinningDecisionBase &thinning)
Merge a new thinning request into an existing one via AND.
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
Definition sgkey_t.h:32
sgkey(tool)
Definition common.py:1027

◆ clear()

void SG::ThinningCache::clear ( )

Clear the cache.

Definition at line 186 of file ThinningCache.cxx.

187{
188 m_map.clear();
189 m_sgmap.clear();
190 m_owned.clear();
192}
std::vector< std::unique_ptr< ThinningDecisionBase > > m_owned
List of decision objects we've copied in order to handle merges.
const ITrigNavigationThinningSvc * m_trigNavigationThinningSvc
Optional TrigNavigation thinning helper for this stream.

◆ empty()

bool SG::ThinningCache::empty ( ) const

Test to see if there's any thinning defined.

Definition at line 22 of file ThinningCache.cxx.

23{
24 return m_map.empty();
25}

◆ lockOwned()

void SG::ThinningCache::lockOwned ( )

Lock all the ThinningDecisionBase objects that we own.

This should be called after all thinning objects have been added, but before the cache is installed in the EventContext.

Definition at line 134 of file ThinningCache.cxx.

135{
136 for (const std::unique_ptr<ThinningDecisionBase>& dec : m_owned) {
137 dec->buildIndexMap();
138 }
139}

◆ merge()

void SG::ThinningCache::merge ( ThinningInfo & info,
const std::vector< sgkey_t > & sgkeys,
const ThinningDecisionBase & thinning )
private

Merge a new thinning request into an existing one via AND.

Parameters
infoThinningInfo with existing decision.
sgkeysSG hashed keys of the object being added.
thinningNew thinning decision.

The new thinning decision will be combined with the old one via AND.

Definition at line 203 of file ThinningCache.cxx.

206{
207 // The existing thinning object.
208 ThinningDecisionBase* oldThinning = nullptr;
209
210 // Look for the existing object in our list of owned decision objects.
211 // If we don't find it, then we'll need to make a copy of the existing
212 // decision so that we can modify it.
213 // We expect this to be relatively rare and the number of such objects
214 // to be small, so just use a linear search.
215 auto ownedIt = std::find_if (m_owned.begin(), m_owned.end(),
216 [old = info.m_decision]
217 (const std::unique_ptr<SG::ThinningDecisionBase>& p)
218 { return p.get() == old; });
219
220 if (ownedIt != m_owned.end()) {
221 // We already own the existing decision. We can just use it.
222 oldThinning = ownedIt->get();
223 }
224 else {
225 // We need to make a copy of the existing decision and enter it into the maps.
226 m_owned.push_back (std::make_unique<SG::ThinningDecisionBase> (info.m_decision->size()));
227 oldThinning = m_owned.back().get();
228 oldThinning->thin (*info.m_decision);
229 info.m_decision = oldThinning;
230
231 for (sgkey_t sgkey : sgkeys) {
232 m_sgmap[sgkey].m_decision = oldThinning;
233 }
234 }
235
236 // Merge the decisions.
237 oldThinning->thin (thinning, SG::ThinningDecisionBase::Op::And);
238}

◆ setCompression()

void SG::ThinningCache::setCompression ( const std::string & key,
const ThinningInfo::compression_map_t & compression )

Set lossy float compression information for the object.

Parameters
keySG string key of the object being added.
compressionMap of compression levels to variables for this object.

Definition at line 160 of file ThinningCache.cxx.

162{
163 m_map[key].m_compression = compression;
164}

◆ setTrigNavigationThinningSvc()

void SG::ThinningCache::setTrigNavigationThinningSvc ( const ITrigNavigationThinningSvc * thinning)

Set the TrigNavigation helper for this stream.

Parameters
thinningTrigNavigation helper.

Definition at line 122 of file ThinningCache.cxx.

◆ setVetoed()

void SG::ThinningCache::setVetoed ( const std::string & key,
const CxxUtils::ConcurrentBitset & vetoed )

Set vetoed variable information one object.

Set selected variable information one object.

Parameters
keySG string key of the object being added.
vetoedSet of vetoed variables for this object.
keySG string key of the object being added.
sgkeysSG hashed keys of the object being added.
vetoedSet of vetoed variables for this object.

Definition at line 148 of file ThinningCache.cxx.

150{
151 m_map[key].m_vetoed = vetoed;
152}

◆ thinning() [1/2]

const ThinningDecisionBase * SG::ThinningCache::thinning ( const sgkey_t sgkey) const

Return thinning for sgkey.

Parameters
keySG key for which to return thinning.

Return thinning defined for sgkey. Returns nullptr if that object is not thinned.

Definition at line 54 of file ThinningCache.cxx.

55{
56 auto it = m_sgmap.find (sgkey);
57 if (it != m_sgmap.end()) {
58 return it->second.m_decision;
59 }
60 return nullptr;
61}

◆ thinning() [2/2]

const ThinningDecisionBase * SG::ThinningCache::thinning ( const std::string & key) const

Return thinning for key.

Parameters
keySG key for which to return thinning.

Return thinning defined for key. Returns nullptr if that object is not thinned.

Definition at line 36 of file ThinningCache.cxx.

37{
38 auto it = m_map.find (key);
39 if (it != m_map.end()) {
40 return it->second.m_decision;
41 }
42 return nullptr;
43}

◆ thinningInfo()

const ThinningInfo * SG::ThinningCache::thinningInfo ( const std::string & key) const

Return thinning information for key.

Parameters
keySG key for which to return selected variables.

Return thinning information key, or nullptr.

Definition at line 173 of file ThinningCache.cxx.

174{
175 auto it = m_map.find (key);
176 if (it != m_map.end()) {
177 return &it->second;
178 }
179 return nullptr;
180}

◆ trigNavigationThinningSvc()

const ITrigNavigationThinningSvc * SG::ThinningCache::trigNavigationThinningSvc ( ) const

Return the TrigNavigation helper for this stream, or nullptr.

Definition at line 112 of file ThinningCache.cxx.

113{
115}

Member Data Documentation

◆ m_map

map_t SG::ThinningCache::m_map
private

Definition at line 153 of file ThinningCache.h.

◆ m_owned

std::vector<std::unique_ptr<ThinningDecisionBase> > SG::ThinningCache::m_owned
private

List of decision objects we've copied in order to handle merges.

Definition at line 160 of file ThinningCache.h.

◆ m_sgmap

sgmap_t SG::ThinningCache::m_sgmap
private

Definition at line 157 of file ThinningCache.h.

◆ m_trigNavigationThinningSvc

const ITrigNavigationThinningSvc* SG::ThinningCache::m_trigNavigationThinningSvc = nullptr
private

Optional TrigNavigation thinning helper for this stream.

Definition at line 163 of file ThinningCache.h.


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