ATLAS Offline Software
InnerDetector/InDetMonitoring/InDetGlobalMonitoring/macros/EnhancedPrimaryVertexMonitoring/TrigD3PD/ChainGroup.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // $Id: ChainGroup.cxx 318255 2010-08-27 11:46:34Z krasznaa $
6 
7 // STL include(s):
8 #include <algorithm>
9 #include <cmath>
10 
11 // ROOT include(s):
12 #include <TRegexp.h>
13 #include <TString.h>
14 
15 // Local include(s):
16 #include "ChainGroup.h"
17 #include "IDataAccess.h"
18 #include "TrigConfigSvcD3PD.h"
19 
21 
22 namespace D3PD {
23 
31  ChainGroup::ChainGroup( const std::vector< std::string >& triggerNames,
33  TrigConfigSvcD3PD& svc )
34  : TNamed( "ChainGroup", "A particular chain group" ),
35  m_parent( parent ), m_configSvc( svc ), m_triggerNames( triggerNames ) {
36 
37  }
38 
53 
54  //
55  // Make sure the object is up to date:
56  //
57  if( ! Update() ) {
58  Error( "IsPassed", "Trigger(s) can't be evaluated" );
59  return kFALSE;
60  }
61 
62  //
63  // Loop over the matching triggers:
64  //
65  for( size_t i = 0; i < m_existingTriggers.size(); ++i ) {
66 
67  // If this is a LVL1 item:
68  if( m_existingTriggers[ i ].find( "L1_" ) != std::string::npos ) {
69 
70  // Variables helping in looking up the correct bit in the result:
71  const Int_t word = m_existingIDs[ i ] / 32;
72  const Int_t bit = m_existingIDs[ i ] % 32;
73 
74  switch( type ) {
75 
76  case TrigDefs::Physics:
77  if( m_parent.GetDetailLevel() >= 0 ) {
78  // Return right away if the trigger fired
79  if( ( ( * m_parent.GetL1Result( Trig::IDataAccess::TAV ) )[ word ] >> bit ) & 0x1 ) {
80  return kTRUE;
81  }
82  } else {
83  Warning( "IsPassed",
84  "The requested information is not available in the input" );
85  return kFALSE;
86  }
87  break;
88  case TrigDefs::L1_TBP:
89  if( m_parent.GetDetailLevel() >= 1 ) {
90  // Return right away if the trigger fired
91  if( ( ( * m_parent.GetL1Result( Trig::IDataAccess::TBP ) )[ word ] >> bit ) & 0x1 ) {
92  return kTRUE;
93  }
94  } else {
95  Warning( "IsPassed",
96  "The requested information is not available in the input" );
97  return kFALSE;
98  }
99  break;
100  case TrigDefs::L1_TAP:
101  if( m_parent.GetDetailLevel() >= 1 ) {
102  // Return right away if the trigger fired
103  if( ( ( * m_parent.GetL1Result( Trig::IDataAccess::TAP ) )[ word ] >> bit ) & 0x1 ) {
104  return kTRUE;
105  }
106  } else {
107  Warning( "IsPassed",
108  "The requested information is not available in the input" );
109  return kFALSE;
110  }
111  break;
112  default:
113  Warning( "IsPassed", "Decision type not recognised for LVL1 items!" );
114  break;
115  }
116 
117  }
118  // If this is a LVL2 chain:
119  else if( m_existingTriggers[ i ].find( "L2_" ) != std::string::npos ) {
120 
121  std::vector< short >::const_iterator begin, end;
122  switch( type ) {
123 
124  case TrigDefs::Physics:
125  if( m_parent.GetDetailLevel() >= 0 ) {
128  } else {
129  Warning( "IsPassed",
130  "The requested information is not available in the input" );
131  return kFALSE;
132  }
133  break;
135  if( m_parent.GetDetailLevel() >= 1 ) {
138  } else {
139  Warning( "IsPassed",
140  "The requested information is not available in the input" );
141  return kFALSE;
142  }
143  break;
145  if( m_parent.GetDetailLevel() >= 2 ) {
148  } else {
149  Warning( "IsPassed",
150  "The requested information is not available in the input" );
151  return kFALSE;
152  }
153  break;
155  if( m_parent.GetDetailLevel() >= 2 ) {
158  } else {
159  Warning( "IsPassed",
160  "The requested information is not available in the input" );
161  return kFALSE;
162  }
163  break;
164  default:
165  Warning( "IsPassed", "Decision type not recognised for HLT chains!" );
166  break;
167  }
168 
169  if( std::find( begin, end, m_existingIDs[ i ] ) != end ) {
170  return kTRUE; // Return right away if the trigger fired
171  }
172 
173  }
174  // If this is an EF chain:
175  else if( m_existingTriggers[ i ].find( "EF_" ) != std::string::npos ) {
176 
177  std::vector< short >::const_iterator begin, end;
178  switch( type ) {
179 
180  case TrigDefs::Physics:
181  if( m_parent.GetDetailLevel() >= 0 ) {
184  } else {
185  Warning( "IsPassed",
186  "The requested information is not available in the input" );
187  return kFALSE;
188  }
189  break;
191  if( m_parent.GetDetailLevel() >= 1 ) {
194  } else {
195  Warning( "IsPassed",
196  "The requested information is not available in the input" );
197  return kFALSE;
198  }
199  break;
201  if( m_parent.GetDetailLevel() >= 2 ) {
204  } else {
205  Warning( "IsPassed",
206  "The requested information is not available in the input" );
207  return kFALSE;
208  }
209  break;
211  if( m_parent.GetDetailLevel() >= 2 ) {
214  } else {
215  Warning( "IsPassed",
216  "The requested information is not available in the input" );
217  return kFALSE;
218  }
219  break;
220  default:
221  Warning( "IsPassed", "Decision type not recognised for HLT chains!" );
222  break;
223  }
224 
225  if( std::find( begin, end, m_existingIDs[ i ] ) != end ) {
226  return kTRUE; // Return right away if the trigger fired
227  }
228 
229  } else {
230  Fatal( "IsPassed", "Something seems to be wrong with this function!" );
231  return kFALSE;
232  }
233 
234  }
235 
236  return kFALSE; // If none of the matching triggers fired in the event
237  }
238 
253  Float_t ChainGroup::GetPrescale() {
254 
255  //
256  // Make sure the object is up to date:
257  //
258  if( ! Update() ) {
259  Error( "IsPassed", "Trigger(s) can't be evaluated" );
260  return 0.0;
261  }
262 
263  // We handle the case when there's only one trigger in the chain group
264  // in a distinct way:
265  const Bool_t singleTrigger = ( m_existingTriggers.size() == 1 );
266 
267  //
268  // Loop over all the matching triggers:
269  //
270  std::vector< std::string >::const_iterator name_itr = m_existingTriggers.begin();
271  std::vector< std::string >::const_iterator name_end = m_existingTriggers.end();
272  for( ; name_itr != name_end; ++name_itr ) {
273 
274  //
275  // Calculate the overall prescale of the chain, or just request the
276  // prescale of LVL1 items:
277  //
278  Float_t chainPrescale = 1.0;
279  if( name_itr->find( "EF_" ) != name_itr->npos ) {
280 
281  chainPrescale = m_configSvc.GetPrescale( *name_itr );
282  const std::string& l2name = m_configSvc.GetLowerChainName( *name_itr );
283  chainPrescale *= m_configSvc.GetPrescale( l2name );
284  const std::string& l1name = m_configSvc.GetLowerChainName( l2name );
285  chainPrescale *= m_configSvc.GetPrescale( l1name );
286 
287  } else if( name_itr->find( "L2_" ) != name_itr->npos ) {
288 
289  chainPrescale = m_configSvc.GetPrescale( *name_itr );
290  const std::string& l1name = m_configSvc.GetLowerChainName( *name_itr );
291  chainPrescale *= m_configSvc.GetPrescale( l1name );
292 
293  } else if( name_itr->find( "L1_" ) != name_itr->npos ) {
294 
295  chainPrescale = m_configSvc.GetPrescale( *name_itr );
296 
297  } else {
298  Fatal( "GetPrescale", "Something seems to be wrong with this function!" );
299  return 0.0;
300  }
301 
302  // If we just have this one trigger in the group, just return now:
303  if( singleTrigger ) return chainPrescale;
304 
305  // If we have multiple triggers, but one of them is unprescaled, then the
306  // whole group is labelled as unprescaled as well:
307  const Bool_t unprescaled = ( std::abs( chainPrescale - 1.0 ) < 1e-5 );
308  if( unprescaled ) return 1.0;
309 
310  }
311 
312  // If we have multiple triggers, and all are prescaled:
313  return 0.0;
314  }
315 
323  const std::vector< std::string >& ChainGroup::GetListOfTriggers() {
324 
325  //
326  // Make sure the object is up to date:
327  //
328  if( ! Update() ) {
329  Error( "IsPassed", "Trigger(s) can't be evaluated" );
330  m_existingTriggers.clear();
331  }
332 
333  return m_existingTriggers;
334  }
335 
343  Bool_t ChainGroup::Update() {
344 
345  // Return right away if we're already configured correctly:
346  if( m_smk == m_parent.GetSMK() ) return kTRUE;
347 
348  // Load the configuration, and remember that the object is initialized with this
349  // configuration:
351  m_smk = m_parent.GetSMK();
352 
353  // Clear the cache variables:
354  m_existingTriggers.clear();
355  m_existingIDs.clear();
356 
357  // Loop over the provided trigger names, and expand them in case they contain lists
358  // or wildcards:
359  std::vector< std::string >::const_iterator name_itr = m_triggerNames.begin();
360  std::vector< std::string >::const_iterator name_end = m_triggerNames.end();
361  for( ; name_itr != name_end; ++name_itr ) {
362 
363  // It's also possible to specify triggers like "L1_MU6,L1_EM5". In this case
364  // the code has to split up these strings into separate trigger names.
365  std::vector< std::string > split_names = ToVector( *name_itr );
366  std::vector< std::string >::const_iterator splitname_itr = split_names.begin();
367  std::vector< std::string >::const_iterator splitname_end = split_names.end();
368  for( ; splitname_itr != splitname_end; ++splitname_itr ) {
369 
370  // Use a TRegexp object only if it's needed:
371  TRegexp re( *splitname_itr );
372  Ssiz_t len = 0;
373  const Bool_t isWildcarded = ( ( splitname_itr->find( '^' ) != splitname_itr->npos ) ||
374  ( splitname_itr->find( '$' ) != splitname_itr->npos ) ||
375  ( splitname_itr->find( '.' ) != splitname_itr->npos ) ||
376  ( splitname_itr->find( '[' ) != splitname_itr->npos ) ||
377  ( splitname_itr->find( ']' ) != splitname_itr->npos ) ||
378  ( splitname_itr->find( '*' ) != splitname_itr->npos ) ||
379  ( splitname_itr->find( '+' ) != splitname_itr->npos ) ||
380  ( splitname_itr->find( '?' ) != splitname_itr->npos ) );
381 
382  // Find out which LVL1 items match the selection:
383  std::vector< std::string >::const_iterator trigger_itr =
384  m_configSvc.GetLVL1Items().begin();
385  std::vector< std::string >::const_iterator trigger_end =
386  m_configSvc.GetLVL1Items().end();
387  for( ; trigger_itr != trigger_end; ++trigger_itr ) {
388  if( isWildcarded ) {
389  if( re.Index( *trigger_itr, &len ) != kNPOS ) {
390  m_existingTriggers.push_back( *trigger_itr );
391  m_existingIDs.push_back( m_configSvc.GetCTPId( *trigger_itr ) );
392  }
393  } else {
394  if( *splitname_itr == *trigger_itr ) {
395  m_existingTriggers.push_back( *trigger_itr );
396  m_existingIDs.push_back( m_configSvc.GetCTPId( *trigger_itr ) );
397  }
398  }
399  }
400 
401  // Find out which HLT chains match the selection:
402  trigger_itr = m_configSvc.GetHLTChains().begin();
403  trigger_end = m_configSvc.GetHLTChains().end();
404  for( ; trigger_itr != trigger_end; ++trigger_itr ) {
405  if( isWildcarded ) {
406  if( re.Index( *trigger_itr, &len ) != kNPOS ) {
407  m_existingTriggers.push_back( *trigger_itr );
408  m_existingIDs.push_back( m_configSvc.GetChainId( *trigger_itr ) );
409  }
410  } else {
411  if( *splitname_itr == *trigger_itr ) {
412  m_existingTriggers.push_back( *trigger_itr );
413  m_existingIDs.push_back( m_configSvc.GetChainId( *trigger_itr ) );
414  }
415  }
416  }
417  }
418  }
419 
420  // Do a final sanity check:
421  if( m_existingTriggers.size() != m_existingIDs.size() ) {
422  Fatal( "Update", "There is a serious problem in the code!" );
423  return kFALSE;
424  }
425 
426  return kTRUE; // The update was successful
427  }
428 
436  std::vector< std::string > ChainGroup::ToVector( const std::string& names ) {
437 
438  // First let's erase all whitespaces:
439  std::string local_names( names );
440  std::string::size_type pos;
441  while( ( pos = local_names.find_first_of( ' ' ) ) != local_names.npos ) {
442  local_names.erase( pos, 1 );
443  }
444 
445  // Now let's split it up:
446  std::vector< std::string > result;
447  std::string::size_type old_pos = 0;
448  while( ( pos = local_names.find( ',', old_pos ) ) != local_names.npos ) {
449  result.push_back( local_names.substr( old_pos, pos - old_pos ) );
450  old_pos = pos + 1;
451  }
452  if( old_pos < local_names.size() ) {
453  result.push_back( local_names.substr( old_pos, local_names.size() - old_pos ) );
454  }
455 
456  return result;
457  }
458 
459 } // namespace D3PD
runTriggerAPIExample.unprescaled
unprescaled
Definition: runTriggerAPIExample.py:15
D3PD::TrigDefs::requireDecision
@ requireDecision
The "raw" decision.
Definition: InnerDetector/InDetMonitoring/InDetGlobalMonitoring/macros/EnhancedPrimaryVertexMonitoring/TrigD3PD/Conditions.h:57
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:216
D3PD::TrigDefs::Physics
@ Physics
"The" physics decision
Definition: InnerDetector/InDetMonitoring/InDetGlobalMonitoring/macros/EnhancedPrimaryVertexMonitoring/TrigD3PD/Conditions.h:48
D3PD::Trig::IDataAccess::GetEFResult
virtual const std::vector< short > * GetEFResult(HLTResultType type) const =0
Function for retrieving the encoded EF result.
D3PD::TrigConfigSvcD3PD::GetLVL1Items
const std::vector< std::string > & GetLVL1Items() const
Get all the configured LVL1 item names.
D3PD::TrigConfigSvcD3PD::GetCTPId
Int_t GetCTPId(const std::string &name) const
Get the CTP ID of a LVL1 item.
D3PD::ChainGroup::ToVector
static std::vector< std::string > ToVector(const std::string &names)
Function splitting a comma separated list into a vector.
D3PD::ChainGroup::IsPassed
Bool_t IsPassed(TrigDefs::DecisionTypes type=TrigDefs::Physics)
Find out if the chain group passed the selection in the event.
get_generator_info.result
result
Definition: get_generator_info.py:21
D3PD::ChainGroup::m_triggerNames
const std::vector< std::string > m_triggerNames
The names given by the user.
Definition: InnerDetector/InDetMonitoring/InDetGlobalMonitoring/macros/EnhancedPrimaryVertexMonitoring/TrigD3PD/ChainGroup.h:70
D3PD::TrigDefs::L1_TAP
@ L1_TAP
LVL1 Trigger After Prescale decision.
Definition: InnerDetector/InDetMonitoring/InDetGlobalMonitoring/macros/EnhancedPrimaryVertexMonitoring/TrigD3PD/Conditions.h:93
TrigConfigSvcD3PD.h
D3PD::Trig::IDataAccess::Resurrected
@ Resurrected
Definition: IDataAccess.h:60
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
D3PD::TrigDefs::DecisionTypes
DecisionTypes
Trigger decision types available from the D3PDs.
Definition: InnerDetector/InDetMonitoring/InDetGlobalMonitoring/macros/EnhancedPrimaryVertexMonitoring/TrigD3PD/Conditions.h:39
IDataAccess.h
D3PD::ChainGroup::Update
Bool_t Update()
Update the object using the trigger configuration.
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
D3PD::ChainGroup::GetListOfTriggers
const std::vector< std::string > & GetListOfTriggers()
Get the list of triggers matching the selection.
ClassImp
ClassImp(D3PD::ChainGroup) namespace D3PD
Definition: InnerDetector/InDetMonitoring/InDetGlobalMonitoring/macros/EnhancedPrimaryVertexMonitoring/TrigD3PD/ChainGroup.cxx:20
D3PD::ChainGroup::m_parent
const Trig::IDataAccess & m_parent
Interface for accessing the trigger data.
Definition: InnerDetector/InDetMonitoring/InDetGlobalMonitoring/macros/EnhancedPrimaryVertexMonitoring/TrigD3PD/ChainGroup.h:67
D3PD::ChainGroup::m_existingTriggers
std::vector< std::string > m_existingTriggers
Names of the triggers.
Definition: InnerDetector/InDetMonitoring/InDetGlobalMonitoring/macros/EnhancedPrimaryVertexMonitoring/TrigD3PD/ChainGroup.h:73
D3PD::ChainGroup::m_smk
Int_t m_smk
The last SMK that was used to update the object.
Definition: InnerDetector/InDetMonitoring/InDetGlobalMonitoring/macros/EnhancedPrimaryVertexMonitoring/TrigD3PD/ChainGroup.h:72
ChainGroup.h
D3PD::Trig::IDataAccess::GetHLTPSK
virtual Int_t GetHLTPSK() const =0
Get the HLT prescale key of the current event.
D3PD::Trig::IDataAccess::TAV
@ TAV
Definition: IDataAccess.h:54
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
D3PD::Trig::IDataAccess::GetL1PSK
virtual Int_t GetL1PSK() const =0
Get the LVL1 prescale key of the current event.
D3PD::TrigConfigSvcD3PD::GetLowerChainName
const std::string & GetLowerChainName(const std::string &name) const
Get the lower chain name of an HLT chain.
D3PD
Block filler tool for noisy FEB information.
Definition: InnerDetector/InDetMonitoring/InDetGlobalMonitoring/macros/EnhancedPrimaryVertexMonitoring/TrigD3PD/ChainGroup.h:21
D3PD::Trig::IDataAccess::TAP
@ TAP
Definition: IDataAccess.h:53
D3PD::Trig::IDataAccess::GetL1Result
virtual const std::vector< unsigned int > * GetL1Result(L1ResultType type) const =0
Function for retrieving the encoded LVL1 result.
lumiFormat.i
int i
Definition: lumiFormat.py:92
D3PD::ChainGroup::ChainGroup
ChainGroup(const std::vector< std::string > &triggerNames, const Trig::IDataAccess &parent, TrigConfigSvcD3PD &svc)
Constructor receiving all the needed information.
D3PD::ChainGroup::GetPrescale
Float_t GetPrescale()
Get the overall prescale of the chain group.
python.subdetectors.mmg.names
names
Definition: mmg.py:8
D3PD::ChainGroup::m_existingIDs
std::vector< Int_t > m_existingIDs
IDs of the triggers.
Definition: InnerDetector/InDetMonitoring/InDetGlobalMonitoring/macros/EnhancedPrimaryVertexMonitoring/TrigD3PD/ChainGroup.h:74
D3PD::Trig::IDataAccess::PassedThrough
@ PassedThrough
Definition: IDataAccess.h:61
test_pyathena.parent
parent
Definition: test_pyathena.py:15
D3PD::Trig::IDataAccess::GetDetailLevel
virtual Int_t GetDetailLevel() const =0
Get the detail level that the D3PD was produced with.
D3PD::Trig::IDataAccess::Physics
@ Physics
Definition: IDataAccess.h:58
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
D3PD::TrigDefs::allowResurrected
@ allowResurrected
The decision while allowing the chain to be resurrected.
Definition: InnerDetector/InDetMonitoring/InDetGlobalMonitoring/macros/EnhancedPrimaryVertexMonitoring/TrigD3PD/Conditions.h:67
D3PD::TrigConfigSvcD3PD::GetPrescale
Float_t GetPrescale(const std::string &name) const
Get the prescale of a trigger (LVL1 or HLT)
ROOT::Shadow::D3PD::Trig::IDataAccess
::D3PD::Trig::IDataAccess IDataAccess
Definition: TriggerD3PDHelpers_Dict.cxx:43
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
D3PD::TrigConfigSvcD3PD::GetHLTChains
const std::vector< std::string > & GetHLTChains() const
Get all the configured HLT chain names.
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
D3PD::TrigConfigSvcD3PD::GetChainId
Int_t GetChainId(const std::string &name) const
Get the chain ID of an HLT chain.
re
const boost::regex re(r_e)
D3PD::Trig::IDataAccess::GetSMK
virtual Int_t GetSMK() const =0
Get the Super Master Key of the current event.
D3PD::TrigDefs::passedThrough
@ passedThrough
The passthrough decision for the chain.
Definition: InnerDetector/InDetMonitoring/InDetGlobalMonitoring/macros/EnhancedPrimaryVertexMonitoring/TrigD3PD/Conditions.h:76
D3PD::ChainGroup::m_configSvc
TrigConfigSvcD3PD & m_configSvc
Reference to the configuration service.
Definition: InnerDetector/InDetMonitoring/InDetGlobalMonitoring/macros/EnhancedPrimaryVertexMonitoring/TrigD3PD/ChainGroup.h:68
D3PD::ChainGroup
Class implementing the chain group functionality.
Definition: InnerDetector/InDetMonitoring/InDetGlobalMonitoring/macros/EnhancedPrimaryVertexMonitoring/TrigD3PD/ChainGroup.h:42
D3PD::Trig::IDataAccess::GetL2Result
virtual const std::vector< short > * GetL2Result(HLTResultType type) const =0
Function for retrieving the encoded LVL2 result.
D3PD::Trig::IDataAccess::Raw
@ Raw
Definition: IDataAccess.h:59
D3PD::TrigDefs::L1_TBP
@ L1_TBP
LVL1 Trigger Before Prescale decision.
Definition: InnerDetector/InDetMonitoring/InDetGlobalMonitoring/macros/EnhancedPrimaryVertexMonitoring/TrigD3PD/Conditions.h:84
D3PD::TrigConfigSvcD3PD::Load
Bool_t Load(Int_t SMK, Int_t L1PSK, Int_t HLTPSK)
Load the configuration belonging to a DB entry.
D3PD::Trig::IDataAccess::TBP
@ TBP
Definition: IDataAccess.h:52