ATLAS Offline Software
ThinningCache.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration.
3  */
14 
15 
16 namespace SG {
17 
18 
23 {
24  return m_map.empty();
25 }
26 
27 
36 ThinningCache::thinning (const std::string& key) const
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 }
44 
45 
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 }
62 
63 
77 void ThinningCache::addThinning (const std::string& key,
78  const std::vector<sgkey_t>& sgkeys,
79  const ThinningDecisionBase* thinning,
80  bool unique /*= false*/)
81 {
82  if (!thinning) return;
83 
84  {
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) {
100  if (info.m_decision) {
101  throw std::runtime_error ("Duplicated thinning definition");
102  }
103  info.m_decision = thinning;
104  }
105 }
106 
107 
113 {
115 }
116 
117 
123 {
125 }
126 
127 
135 {
136  for (const std::unique_ptr<ThinningDecisionBase>& dec : m_owned) {
137  dec->buildIndexMap();
138  }
139 }
140 
141 
148 void ThinningCache::setVetoed (const std::string& key,
149  const CxxUtils::ConcurrentBitset& vetoed)
150 {
151  m_map[key].m_vetoed = vetoed;
152 }
153 
160 void ThinningCache::setCompression(const std::string& key,
162 {
163  m_map[key].m_compression = compression;
164 }
165 
172 const ThinningInfo*
173 ThinningCache::thinningInfo (const std::string& key) const
174 {
175  auto it = m_map.find (key);
176  if (it != m_map.end()) {
177  return &it->second;
178  }
179  return nullptr;
180 }
181 
182 
187 {
188  m_map.clear();
189  m_sgmap.clear();
190  m_owned.clear();
191  m_trigNavigationThinningSvc = nullptr;
192 }
193 
194 
204  const std::vector<sgkey_t>& sgkeys,
205  const ThinningDecisionBase& thinning)
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.
238 }
239 
240 
241 } // namespace SG
grepfile.info
info
Definition: grepfile.py:38
common.sgkey
def sgkey(tool)
Definition: common.py:1028
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
SG::ThinningCache::m_trigNavigationThinningSvc
const ITrigNavigationThinningSvc * m_trigNavigationThinningSvc
Optional TrigNavigation thinning helper for this stream.
Definition: ThinningCache.h:163
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
CxxUtils::ConcurrentBitset
Variable-sized bitset allowing (mostly) concurrent access.
Definition: ConcurrentBitset.h:146
SG::ThinningDecisionBase
Hold thinning decisions for one container.
Definition: ThinningDecisionBase.h:39
SG::ThinningCache::m_map
map_t m_map
Definition: ThinningCache.h:153
skel.it
it
Definition: skel.GENtoEVGEN.py:396
SG::ThinningCache::lockOwned
void lockOwned()
Lock all the ThinningDecisionBase objects that we own.
Definition: ThinningCache.cxx:134
SG::ThinningInfo::compression_map_t
std::map< unsigned int, CxxUtils::ConcurrentBitset > compression_map_t
This map holds a set of auxids to be lossy compressed for each compression level (nmantissa).
Definition: ThinningInfo.h:66
SG::ThinningCache::trigNavigationThinningSvc
const ITrigNavigationThinningSvc * trigNavigationThinningSvc() const
Return the TrigNavigation helper for this stream, or nullptr.
Definition: ThinningCache.cxx:112
ThinningDecisionBase.h
Hold thinning decisions for one container.
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
SG::ThinningCache::thinningInfo
const ThinningInfo * thinningInfo(const std::string &key) const
Return thinning information for key.
Definition: ThinningCache.cxx:173
SG::ThinningCache::clear
void clear()
Clear the cache.
Definition: ThinningCache.cxx:186
SG::ThinningInfo
Hold thinning/slimming information for a given object.
Definition: ThinningInfo.h:40
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
SG::ThinningDecisionBase::Op::And
@ And
SG::ThinningCache::m_sgmap
sgmap_t m_sgmap
Definition: ThinningCache.h:157
ITrigNavigationThinningSvc
Define interface for doing TrigNavigation thinning.
Definition: ITrigNavigationThinningSvc.h:31
SG::ThinningCache::setVetoed
void setVetoed(const std::string &key, const CxxUtils::ConcurrentBitset &vetoed)
Set vetoed variable information one object.
Definition: ThinningCache.cxx:148
SG::ThinningCache::m_owned
std::vector< std::unique_ptr< ThinningDecisionBase > > m_owned
List of decision objects we've copied in order to handle merges.
Definition: ThinningCache.h:160
SG::ThinningDecisionBase::thin
void thin(size_t ndx)
Mark that index ndx in the container should be thinned away.
Definition: ThinningDecisionBase.cxx:70
SG::sgkey_t
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
Definition: CxxUtils/CxxUtils/sgkey_t.h:32
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::ThinningCache::thinning
const ThinningDecisionBase * thinning(const std::string &key) const
Return thinning for key.
Definition: ThinningCache.cxx:36
CSV_InDetExporter.old
old
Definition: CSV_InDetExporter.py:145
SG::ThinningCache::merge
void merge(ThinningInfo &info, const std::vector< sgkey_t > &sgkeys, const ThinningDecisionBase &thinning)
Merge a new thinning request into an existing one via AND.
Definition: ThinningCache.cxx:203
python.BeamSpotUpdate.compression
compression
Definition: BeamSpotUpdate.py:188
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
ThinningCache.h