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 "boost/regex.hpp"
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{
141 lock_t lock (m_mutex);
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>
157{
158 lock_t lock (m_mutex);
160 return std::vector<std::string> (m_chainNames.begin(),
162}
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
193 lock_t lock (m_mutex);
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 boost::regex compiled( chainName );
202 boost::cmatch what;
203 std::string chains;
204
205 std::map< std::string, std::string >::const_iterator iter =
206 m_l1l2Map.begin();
207 std::map< std::string, std::string >::const_iterator end =
208 m_l1l2Map.end();
209 for( ; iter != end; ++iter ) {
210 // check if the l1 chain matches the regex supplied by chainName
211 if( boost::regex_match( iter->first.c_str(), what, compiled ) ) {
212 if( chains.empty() ) {
213 chains += iter->second;
214 } else {
215 chains += "|" + iter->second;
216 }
217 }
218 }
219
220 // add it to the cache
221 m_l1l2Map[ chainName ] = chains;
222 }
223
224 // if it wasn't in the cache before, it will be now, so pull it out
225 std::string output = m_l1l2Map[ chainName ];
226 if( output.find( "|" ) != std::string::npos ) {
227 output = "(" + output + ")";
228 }
229
230 return output;
231}
232
233
234int TrigMatchToolCore::TypeMap::key (const std::type_info* tid)
235{
236 lock_t lock (m_mutex);
237 typeMap_t::const_iterator it = m_typeMap.find (tid);
238 if (it != m_typeMap.end()) {
239 return it->second;
240 }
241
242 int type_key = m_typeMap.size();
243 m_typeMap[tid] = type_key;
244 return type_key;
245}
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