ATLAS Offline Software
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),
15  m_trigDecisionToolCore(0)
16 {
17 }
18 
20 {
21 }
22 
23 std::string
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 
47 TrigMatchToolCore::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 
61 size_t
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),
85  TrigDefs::alsoDeactivateTEs);
86  slotCache.m_featureContainers[chainIndex].swap (fc);
87 #else
88  slotCache.m_featureContainers[chainIndex] =
89  this->getFeatureContainer (m_chainNameIndex.chainName(chainIndex),
90  TrigDefs::alsoDeactivateTEs);
91 #endif
92  slotCache.m_featureContainersValid[chainIndex] = true;
93  }
94 
95  return slotCache.m_featureContainers[chainIndex];
96 }
97 
98 
99 //***************************************************************************
100 
101 
103  : m_core (core)
104 {
105 }
106 
107 
108 void
110 {
111  if (m_chainNames.empty()) {
112  m_chainNames = m_core->getConfiguredChainNames();
113  m_nConfiguredChainNames = m_chainNames.size();
114  m_chainIndexMap.clear();
115  for (size_t i = 0; i < m_chainNames.size(); i++) {
116  const std::string& chainName = m_chainNames[i];
117  m_chainIndexMap[chainName] = 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 
138 size_t
140 {
141  lock_t lock (m_mutex);
142  assertConfiguredChainNames();
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 
155 std::vector<std::string>
157 {
158  lock_t lock (m_mutex);
159  assertConfiguredChainNames();
160  return std::vector<std::string> (m_chainNames.begin(),
161  m_chainNames.begin() + m_nConfiguredChainNames);
162 }
163 
164 
165 std::string
167 {
168  lock_t lock (m_mutex);
169  assertConfiguredChainNames();
170  return m_chainNames.at (index);
171 }
172 
173 
174 void
176 {
177  lock_t lock (m_mutex);
178  m_chainNames.clear();
179  m_chainIndexMap.clear();
180  m_nConfiguredChainNames = 0;
181  m_l1l2Map.clear();
182  assertConfiguredChainNames();
183 }
184 
185 
186 std::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 
234 int 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 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
TrigMatchToolCore::SlotCache::m_featureContainers
std::vector< Trig::FeatureContainer > m_featureContainers
Definition: TrigMatchToolCore.h:685
TrigMatchToolCore::getCache1
TrigFeatureCacheBase *& getCache1(const std::type_info *tid, int type_key, SlotCache &slotCache, const SlotCache::lock_t &lock) const
Definition: TrigMatchToolCore.cxx:47
TrigMatchToolCore::TypeMap::lock_t
std::lock_guard< mutex_t > lock_t
Definition: TrigMatchToolCore.h:626
TrigMatchToolCore::TrigFeatureCacheBase
Definition: TrigMatchToolCore.h:550
TrigMatchToolCore::TypeMap::key
int key(const std::type_info *tid)
Definition: TrigMatchToolCore.cxx:234
TrigMatchToolCore::ChainNameIndex::propagateChainNames
std::string propagateChainNames(const std::string &chainName)
Definition: TrigMatchToolCore.cxx:187
index
Definition: index.py:1
TrigMatchToolCore::SlotCache
Definition: TrigMatchToolCore.h:636
skel.it
it
Definition: skel.GENtoEVGEN.py:423
TrigMatchToolCore::ChainNameIndex::chainNameToIndex
size_t chainNameToIndex(const std::string &chainName)
Definition: TrigMatchToolCore.cxx:139
TrigMatchToolCore::TrigMatchToolCore
TrigMatchToolCore()
Definition: TrigMatchToolCore.cxx:13
TrigMatchToolCore::getFeatureContainer
virtual Trig::FeatureContainer getFeatureContainer(const std::string &chainName, const int condition) const =0
TrigMatchToolCore::ChainNameIndex::assertConfiguredChainNames
void assertConfiguredChainNames()
Definition: TrigMatchToolCore.cxx:109
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
PrepareReferenceFile.regex
regex
Definition: PrepareReferenceFile.py:43
Trig::FeatureContainer
Definition: FeatureContainer.h:54
TrigMatchToolCore::ChainNameIndex::configuredChainNames
std::vector< std::string > configuredChainNames()
Definition: TrigMatchToolCore.cxx:156
TrigMatchToolCore::chainNameToIndex
size_t chainNameToIndex(const std::string &chainName) const
Definition: TrigMatchToolCore.cxx:62
lumiFormat.i
int i
Definition: lumiFormat.py:92
TrigMatchToolCore::SlotCache::lock_t
std::lock_guard< mutex_t > lock_t
Definition: TrigMatchToolCore.h:690
TrigMatchToolCore::SlotCache::m_featureContainersValid
std::vector< bool > m_featureContainersValid
Definition: TrigMatchToolCore.h:686
TrigMatchToolCore::endEvent
virtual void endEvent()
Definition: TrigMatchToolCore.cxx:30
TrigMatchToolCore
The TrigMatchToolCore defines the core functionality of the TrigMatchTool and is used for matching tr...
Definition: TrigMatchToolCore.h:40
merge.output
output
Definition: merge.py:17
python.ExitCodes.what
def what(code)
Definition: ExitCodes.py:73
TrigMatchToolCore::SlotCache::m_caches
cacheVec_t * m_caches
Definition: TrigMatchToolCore.h:680
python.copyTCTOutput.chains
chains
Definition: copyTCTOutput.py:81
TrigMatchToolCore::SlotCache::m_nFeatureContainers
size_t m_nFeatureContainers
Definition: TrigMatchToolCore.h:687
TrigMatchToolCore::propagateChainNames
std::string propagateChainNames(const std::string &chainName, const trait *) const
Definition: TrigMatchToolCore.h:467
TrigMatchToolCore::clearChainIndex
void clearChainIndex()
Definition: TrigMatchToolCore.cxx:40
TrigMatchToolCore::ChainNameIndex::lock_t
std::lock_guard< mutex_t > lock_t
Definition: TrigMatchToolCore.h:418
python.TriggerAPI.TriggerAPISession.chainName
chainName
Definition: TriggerAPISession.py:353
TrigMatchToolCore::ChainNameIndex::chainName
std::string chainName(size_t index)
Definition: TrigMatchToolCore.cxx:166
skel.l1
l1
Definition: skel.GENtoEVGEN.py:425
TrigMatchToolCore::getCachedFeatureContainer
const Trig::FeatureContainer & getCachedFeatureContainer(size_t chainIndex, SlotCache &cache, const SlotCache::lock_t &lock) const
Definition: TrigMatchToolCore.cxx:69
TrigMatchToolCore.h
TrigMatchToolCore::ChainNameIndex::clear
void clear()
Definition: TrigMatchToolCore.cxx:175
TrigMatchToolCore::~TrigMatchToolCore
virtual ~TrigMatchToolCore()
Definition: TrigMatchToolCore.cxx:19
TrigMatchToolCore::ChainNameIndex::ChainNameIndex
ChainNameIndex(TrigMatchToolCore *core)
Definition: TrigMatchToolCore.cxx:102