ATLAS Offline Software
Loading...
Searching...
No Matches
TrigMatchToolCore.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3*/
4
5// $Id$
6
7// Boost include(s):
8#include <regex>
9
10// Local include(s):
12
14 : m_chainNameIndex (this),
16{
17}
18
22
23std::string
24TrigMatchToolCore::propagateChainNames( const std::string &chainName ) const
25{
26 return m_chainNameIndex.propagateChainNames (chainName);
27}
28
29
31{
32 m_slotCache->clear();
33
34 return;
35}
36
37
38// Clear saved chain name -> index mapping and rebuild from current
39// configuration.
41{
42 m_chainNameIndex.clear();
43}
44
45
47TrigMatchToolCore::getCache1 (const std::type_info* tid, int type_key,
48 SlotCache& slotCache,
49 const SlotCache::lock_t& /*lock*/) const
50{
51 if (type_key < 0) {
52 m_typeMap.key (tid);
53 }
54
55 if (static_cast<int> (slotCache.m_caches->size()) <= type_key)
56 slotCache.m_caches->resize (type_key + 1);
57 return (*slotCache.m_caches)[type_key];
58}
59
60
61size_t
62TrigMatchToolCore::chainNameToIndex (const std::string& chainName) const
63{
64 return m_chainNameIndex.chainNameToIndex (chainName);
65}
66
67
70 SlotCache& slotCache,
71 const SlotCache::lock_t& /*lock*/) const
72{
73 if (chainIndex >= slotCache.m_featureContainers.size()) {
74 if (chainIndex >= slotCache.m_nFeatureContainers)
75 slotCache.m_nFeatureContainers = chainIndex + 1;
76 slotCache.m_featureContainers.resize (slotCache.m_nFeatureContainers);
77 slotCache.m_featureContainersValid.resize (slotCache.m_nFeatureContainers);
78 }
79
80 if (!slotCache.m_featureContainersValid[chainIndex]) {
81#if 0
82 // Use this once FeatureContainer::swap is available to avoid copies.
84 this->getFeatureContainer (m_chainNameIndex.chainName(chainIndex),
86 slotCache.m_featureContainers[chainIndex].swap (fc);
87#else
88 slotCache.m_featureContainers[chainIndex] =
89 this->getFeatureContainer (m_chainNameIndex.chainName(chainIndex),
91#endif
92 slotCache.m_featureContainersValid[chainIndex] = true;
93 }
94
95 return slotCache.m_featureContainers[chainIndex];
96}
97
98
99//***************************************************************************
100
101
106
107
108void
110{
111 if (m_chainNames.empty()) {
112 m_chainNames = m_core->getConfiguredChainNames();
114 m_chainIndexMap.clear();
115 for (size_t i = 0; i < m_chainNames.size(); i++) {
116 const std::string& chainName = m_chainNames[i];
118
119 // Build the L1L2 map. Note that we ignore regex support
120 // at this stage - we'll implement regex support by matching
121 // to the keys in the cache later on. Also note that the
122 // cached version does not have parentheses around it (so
123 // they can easily be combined)
124 if (chainName.find("L2_") != std::string::npos) {
125 const std::string l1 = m_core->lowerChainName( chainName );
126
127 if( m_l1l2Map.find( l1 ) == m_l1l2Map.end() ) {
128 m_l1l2Map[ l1 ] = chainName;
129 } else {
130 m_l1l2Map[ l1 ] = m_l1l2Map[ l1 ] + "|" + chainName;
131 }
132 }
133 }
134 }
135}
136
137
138size_t
140{
143 chainIndexMap_t::iterator it = m_chainIndexMap.find (chainName);
144 if (it == m_chainIndexMap.end()) {
145 size_t chainIndex = m_chainNames.size();
146 m_chainIndexMap[chainName] = chainIndex;
147 m_chainNames.push_back (chainName);
148 return chainIndex;
149 }
150 else
151 return it->second;
152}
153
154
155std::vector<std::string>
163
164
165std::string
172
173
174void
184
185
186std::string
188{
189 // only applicable for L1 chains
190 if( chainName.find( "L1_" ) == std::string::npos )
191 return chainName;
192
194
195 // add it to the cache if necessary
196 if( m_l1l2Map.find( chainName ) == m_l1l2Map.end() ) {
197
198 // if its not in the cache, we need to check
199 // if we can build it from the cache.
200 // regex support
201 std::regex compiled( chainName );
202 std::string chains;
203
204 std::map< std::string, std::string >::const_iterator iter =
205 m_l1l2Map.begin();
206 std::map< std::string, std::string >::const_iterator end =
207 m_l1l2Map.end();
208 for( ; iter != end; ++iter ) {
209 // check if the l1 chain matches the regex supplied by chainName
210 if( std::regex_match( iter->first.c_str(), compiled ) ) {
211 if( chains.empty() ) {
212 chains += iter->second;
213 } else {
214 chains += "|" + iter->second;
215 }
216 }
217 }
218
219 // add it to the cache
220 m_l1l2Map[ chainName ] = chains;
221 }
222
223 // if it wasn't in the cache before, it will be now, so pull it out
224 std::string output = m_l1l2Map[ chainName ];
225 if( output.find( "|" ) != std::string::npos ) {
226 output = "(" + output + ")";
227 }
228
229 return output;
230}
231
232
233int TrigMatchToolCore::TypeMap::key (const std::type_info* tid)
234{
236 typeMap_t::const_iterator it = m_typeMap.find (tid);
237 if (it != m_typeMap.end()) {
238 return it->second;
239 }
240
241 int type_key = m_typeMap.size();
242 m_typeMap[tid] = type_key;
243 return type_key;
244}
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
std::string chainName(size_t index)
std::vector< std::string > m_chainNames
size_t chainNameToIndex(const std::string &chainName)
std::vector< std::string > configuredChainNames()
std::lock_guard< mutex_t > lock_t
std::map< std::string, std::string > m_l1l2Map
std::string propagateChainNames(const std::string &chainName)
ChainNameIndex(TrigMatchToolCore *core)
int key(const std::type_info *tid)
std::lock_guard< mutex_t > lock_t
std::string propagateChainNames(const std::string &chainName, const trait *) const
Trig::TrigDecisionToolCore * m_trigDecisionToolCore
size_t chainNameToIndex(const std::string &chainName) const
TrigFeatureCacheBase *& getCache1(const std::type_info *tid, int type_key, SlotCache &slotCache, const SlotCache::lock_t &lock) const
const Trig::FeatureContainer & getCachedFeatureContainer(size_t chainIndex, SlotCache &cache, const SlotCache::lock_t &lock) const
virtual Trig::FeatureContainer getFeatureContainer(const std::string &chainName, const int condition) const =0
virtual void endEvent()
Definition index.py:1
std::vector< bool > m_featureContainersValid
std::vector< Trig::FeatureContainer > m_featureContainers
std::lock_guard< mutex_t > lock_t