CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GenericTriggerEventFlag.cc
Go to the documentation of this file.
1 //
2 // $Id: GenericTriggerEventFlag.cc,v 1.13 2012/04/22 15:09:29 vadler Exp $
3 //
4 
5 
7 
15 
16 #include <vector>
17 
19 
20 
21 // Constants' definitions
22 static const bool useL1EventSetup( true );
23 static const bool useL1GtTriggerMenuLite( false );
24 
25 
28  : watchDB_( 0 )
29  , hltConfigInit_( false )
30  , andOr_( false )
31  , dbLabel_( "" )
32  , verbose_( 0 )
33  , andOrDcs_( false )
34  , errorReplyDcs_( false )
35  , andOrGt_( false )
36  , gtInputTag_( "" )
37  , gtEvmInputTag_( "" )
38  , gtDBKey_( "" )
39  , errorReplyGt_( false )
40  , andOrL1_( false )
41  , l1BeforeMask_( true )
42  , l1DBKey_( "" )
43  , errorReplyL1_( false )
44  , andOrHlt_( false )
45  , hltDBKey_( "" )
46  , errorReplyHlt_( false )
47  , on_( true )
48  , onDcs_( true )
49  , onGt_( true )
50  , onL1_( true )
51  , onHlt_( true )
52  , configError_( "CONFIG_ERROR" )
53  , emptyKeyError_( "EMPTY_KEY_ERROR" )
54 {
55 
56  // General switch(es)
57  if ( config.exists( "andOr" ) ) {
58  andOr_ = config.getParameter< bool >( "andOr" );
59  if ( config.exists( "verbosityLevel" ) ) verbose_ = config.getParameter< unsigned >( "verbosityLevel" );
60  } else {
61  on_ = false;
62  onDcs_ = false;
63  onGt_ = false;
64  onL1_ = false;
65  onHlt_ = false;
66  }
67 
68  if ( on_ ) {
69  if ( config.exists( "andOrDcs" ) ) {
70  andOrDcs_ = config.getParameter< bool >( "andOrDcs" );
71  dcsInputTag_ = config.getParameter< edm::InputTag >( "dcsInputTag" );
72  dcsPartitions_ = config.getParameter< std::vector< int > >( "dcsPartitions" );
73  errorReplyDcs_ = config.getParameter< bool >( "errorReplyDcs" );
74  } else {
75  onDcs_ = false;
76  }
77  if ( config.exists( "andOrGt" ) ) {
78  andOrGt_ = config.getParameter< bool >( "andOrGt" );
79  gtInputTag_ = config.getParameter< edm::InputTag >( "gtInputTag" );
80  gtLogicalExpressions_ = config.getParameter< std::vector< std::string > >( "gtStatusBits" );
81  errorReplyGt_ = config.getParameter< bool >( "errorReplyGt" );
82  if ( config.exists( "gtEvmInputTag" ) ) gtEvmInputTag_ = config.getParameter< edm::InputTag >( "gtEvmInputTag" );
83  if ( config.exists( "gtDBKey" ) ) gtDBKey_ = config.getParameter< std::string >( "gtDBKey" );
84  } else {
85  onGt_ = false;
86  }
87  if ( config.exists( "andOrL1" ) ) {
88  andOrL1_ = config.getParameter< bool >( "andOrL1" );
89  l1LogicalExpressionsCache_ = config.getParameter< std::vector< std::string > >( "l1Algorithms" );
90  errorReplyL1_ = config.getParameter< bool >( "errorReplyL1" );
91  if ( config.exists( "l1DBKey" ) ) l1DBKey_ = config.getParameter< std::string >( "l1DBKey" );
92  if ( config.exists( "l1BeforeMask" ) ) l1BeforeMask_ = config.getParameter< bool >( "l1BeforeMask" );
93  } else {
94  onL1_ = false;
95  }
96  if ( config.exists( "andOrHlt" ) ) {
97  andOrHlt_ = config.getParameter< bool >( "andOrHlt" );
98  hltInputTag_ = config.getParameter< edm::InputTag >( "hltInputTag" );
99  hltLogicalExpressionsCache_ = config.getParameter< std::vector< std::string > >( "hltPaths" );
100  errorReplyHlt_ = config.getParameter< bool >( "errorReplyHlt" );
101  if ( config.exists( "hltDBKey" ) ) hltDBKey_ = config.getParameter< std::string >( "hltDBKey" );
102  } else {
103  onHlt_ = false;
104  }
105  if ( ! onDcs_ && ! onGt_ && ! onL1_ && ! onHlt_ ) on_ = false;
106  else {
107  if ( config.exists( "dbLabel" ) ) dbLabel_ = config.getParameter< std::string >( "dbLabel" );
109  }
110  }
111 
112 }
113 
114 
117 {
118 
119  if ( on_ ) delete watchDB_;
120 
121 }
122 
123 
126 {
127 
128  if ( watchDB_->check( setup ) ) {
129  if ( onGt_ && gtDBKey_.size() > 0 ) {
130  const std::vector< std::string > exprs( expressionsFromDB( gtDBKey_, setup ) );
131  if ( exprs.empty() || exprs.at( 0 ) != configError_ ) gtLogicalExpressions_ = exprs;
132  }
133  if ( onL1_ && l1DBKey_.size() > 0 ) {
134  const std::vector< std::string > exprs( expressionsFromDB( l1DBKey_, setup ) );
135  if ( exprs.empty() || exprs.at( 0 ) != configError_ ) l1LogicalExpressionsCache_ = exprs;
136  }
137  if ( onHlt_ && hltDBKey_.size() > 0 ) {
138  const std::vector< std::string > exprs( expressionsFromDB( hltDBKey_, setup ) );
139  if ( exprs.empty() || exprs.at( 0 ) != configError_ ) hltLogicalExpressionsCache_ = exprs;
140  }
141  }
142 
143  // Re-initialise starting valuse before wild-card expansion
146 
147  hltConfigInit_ = false;
148  if ( onHlt_ ) {
149  if ( hltInputTag_.process().size() == 0 ) {
150  if ( verbose_ > 0 ) edm::LogError( "GenericTriggerEventFlag" ) << "HLT TriggerResults InputTag \"" << hltInputTag_.encode() << "\" specifies no process";
151  } else {
152  bool hltChanged( false );
153  if ( ! hltConfig_.init( run, setup, hltInputTag_.process(), hltChanged ) ) {
154  if ( verbose_ > 0 ) edm::LogError( "GenericTriggerEventFlag" ) << "HLT config initialization error with process name \"" << hltInputTag_.process() << "\"";
155  } else if ( hltConfig_.size() <= 0 ) {
156  if ( verbose_ > 0 ) edm::LogError( "GenericTriggerEventFlag" ) << "HLT config size error";
157  } else hltConfigInit_ = true;
158  }
159  }
160 
161  // Expand version wild-cards in HLT logical expressions
162  // L1
163  if ( onL1_ ) {
164  // build vector of algo names
165  l1Gt_.getL1GtRunCache( run, setup, true, false );
166  edm::ESHandle< L1GtTriggerMenu > handleL1GtTriggerMenu;
167  setup.get< L1GtTriggerMenuRcd >().get( handleL1GtTriggerMenu );
168 // L1GtTriggerMenu l1GtTriggerMenu( *handleL1GtTriggerMenu );
169  std::vector< std::string > algoNames;
170 // const AlgorithmMap l1GtPhys( l1GtTriggerMenu.gtAlgorithmMap() );
171  const AlgorithmMap l1GtPhys( handleL1GtTriggerMenu->gtAlgorithmMap() );
172  for ( CItAlgo iAlgo = l1GtPhys.begin(); iAlgo != l1GtPhys.end(); ++iAlgo ) {
173  algoNames.push_back( iAlgo->second.algoName() );
174  }
175 // const AlgorithmMap l1GtTech( l1GtTriggerMenu.gtTechnicalTriggerMap() );
176  const AlgorithmMap l1GtTech( handleL1GtTriggerMenu->gtTechnicalTriggerMap() );
177  for ( CItAlgo iAlgo = l1GtTech.begin(); iAlgo != l1GtTech.end(); ++iAlgo ) {
178  algoNames.push_back( iAlgo->second.algoName() );
179  }
180  for ( unsigned iExpr = 0; iExpr < l1LogicalExpressions_.size(); ++iExpr ) {
181  std::string l1LogicalExpression( l1LogicalExpressions_.at( iExpr ) );
182  L1GtLogicParser l1AlgoLogicParser( l1LogicalExpression );
183  // Loop over algorithms
184  for ( size_t iAlgo = 0; iAlgo < l1AlgoLogicParser.operandTokenVector().size(); ++iAlgo ) {
185  const std::string l1AlgoName( l1AlgoLogicParser.operandTokenVector().at( iAlgo ).tokenName );
186  if ( l1AlgoName.find( '*' ) != std::string::npos ) {
187  l1LogicalExpression.replace( l1LogicalExpression.find( l1AlgoName ), l1AlgoName.size(), expandLogicalExpression( algoNames, l1AlgoName ) );
188  }
189  }
190  l1LogicalExpressions_[ iExpr ] = l1LogicalExpression;
191  }
192  }
193  // HLT
194  if ( hltConfigInit_ ) {
195  for ( unsigned iExpr = 0; iExpr < hltLogicalExpressions_.size(); ++iExpr ) {
196  std::string hltLogicalExpression( hltLogicalExpressions_.at( iExpr ) );
197  L1GtLogicParser hltAlgoLogicParser( hltLogicalExpression );
198  // Loop over paths
199  for ( size_t iPath = 0; iPath < hltAlgoLogicParser.operandTokenVector().size(); ++iPath ) {
200  const std::string hltPathName( hltAlgoLogicParser.operandTokenVector().at( iPath ).tokenName );
201  if ( hltPathName.find( '*' ) != std::string::npos ) {
202  hltLogicalExpression.replace( hltLogicalExpression.find( hltPathName ), hltPathName.size(), expandLogicalExpression( hltConfig_.triggerNames(), hltPathName ) );
203  }
204  }
205  hltLogicalExpressions_[ iExpr ] = hltLogicalExpression;
206  }
207  }
208 
209 }
210 
211 
214 {
215 
216  if ( ! on_ ) return true;
217 
218  // Determine decision
219  if ( andOr_ ) return ( acceptDcs( event ) || acceptGt( event ) || acceptL1( event, setup ) || acceptHlt( event ) );
220  return ( acceptDcs( event ) && acceptGt( event ) && acceptL1( event, setup ) && acceptHlt( event ) );
221 
222 }
223 
224 
226 {
227 
228  // An empty DCS partitions list acts as switch.
229  if ( ! onDcs_ || dcsPartitions_.empty() ) return ( ! andOr_ ); // logically neutral, depending on base logical connective
230 
231  // Accessing the DcsStatusCollection
233  event.getByLabel( dcsInputTag_, dcsStatus );
234  if ( ! dcsStatus.isValid() ) {
235  if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "DcsStatusCollection product with InputTag \"" << dcsInputTag_.encode() << "\" not in event ==> decision: " << errorReplyDcs_;
236  return errorReplyDcs_;
237  }
238  if ( ( *dcsStatus ).size() == 0 ) {
239  if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "DcsStatusCollection product with InputTag \"" << dcsInputTag_.encode() << "\" empty ==> decision: " << errorReplyDcs_;
240  return errorReplyDcs_;
241  }
242 
243  // Determine decision of DCS partition combination and return
244  if ( andOrDcs_ ) { // OR combination
245  for ( std::vector< int >::const_iterator partitionNumber = dcsPartitions_.begin(); partitionNumber != dcsPartitions_.end(); ++partitionNumber ) {
246  if ( acceptDcsPartition( dcsStatus, *partitionNumber ) ) return true;
247  }
248  return false;
249  }
250  for ( std::vector< int >::const_iterator partitionNumber = dcsPartitions_.begin(); partitionNumber != dcsPartitions_.end(); ++partitionNumber ) {
251  if ( ! acceptDcsPartition( dcsStatus, *partitionNumber ) ) return false;
252  }
253  return true;
254 
255 }
256 
257 
259 {
260 
261  // Error checks
262  switch( dcsPartition ) {
263  case DcsStatus::EBp :
264  case DcsStatus::EBm :
265  case DcsStatus::EEp :
266  case DcsStatus::EEm :
267  case DcsStatus::HBHEa :
268  case DcsStatus::HBHEb :
269  case DcsStatus::HBHEc :
270  case DcsStatus::HF :
271  case DcsStatus::HO :
272  case DcsStatus::RPC :
273  case DcsStatus::DT0 :
274  case DcsStatus::DTp :
275  case DcsStatus::DTm :
276  case DcsStatus::CSCp :
277  case DcsStatus::CSCm :
278  case DcsStatus::CASTOR:
279  case DcsStatus::TIBTID:
280  case DcsStatus::TOB :
281  case DcsStatus::TECp :
282  case DcsStatus::TECm :
283  case DcsStatus::BPIX :
284  case DcsStatus::FPIX :
285  case DcsStatus::ESp :
286  case DcsStatus::ESm :
287  break;
288  default:
289  if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "DCS partition number \"" << dcsPartition << "\" does not exist ==> decision: " << errorReplyDcs_;
290  return errorReplyDcs_;
291  }
292 
293  // Determine decision
294  return dcsStatus->at( 0 ).ready( dcsPartition );
295 
296 }
297 
298 
301 {
302 
303  // An empty GT status bits logical expressions list acts as switch.
304  if ( ! onGt_ || gtLogicalExpressions_.empty() ) return ( ! andOr_ ); // logically neutral, depending on base logical connective
305 
306  // Determine decision of GT status bits logical expression combination and return
307  if ( andOrGt_ ) { // OR combination
308  for ( std::vector< std::string >::const_iterator gtLogicalExpression = gtLogicalExpressions_.begin(); gtLogicalExpression != gtLogicalExpressions_.end(); ++gtLogicalExpression ) {
309  if ( acceptGtLogicalExpression( event, *gtLogicalExpression ) ) return true;
310  }
311  return false;
312  }
313  for ( std::vector< std::string >::const_iterator gtLogicalExpression = gtLogicalExpressions_.begin(); gtLogicalExpression != gtLogicalExpressions_.end(); ++gtLogicalExpression ) {
314  if ( ! acceptGtLogicalExpression( event, *gtLogicalExpression ) ) return false;
315  }
316  return true;
317 
318 }
319 
320 
322 bool GenericTriggerEventFlag::acceptGtLogicalExpression( const edm::Event & event, std::string gtLogicalExpression )
323 {
324 
325  // Check empty std::strings
326  if ( gtLogicalExpression.empty() ) {
327  if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "Empty logical expression ==> decision: " << errorReplyGt_;
328  return errorReplyGt_;
329  }
330 
331  // Negated paths
332  bool negExpr( negate( gtLogicalExpression ) );
333  if ( negExpr && gtLogicalExpression.empty() ) {
334  if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "Empty (negated) logical expression ==> decision: " << errorReplyGt_;
335  return errorReplyGt_;
336  }
337 
338  // Parse logical expression and determine GT status bit decision
339  L1GtLogicParser gtAlgoLogicParser( gtLogicalExpression );
340  // Loop over status bits
341  for ( size_t iStatusBit = 0; iStatusBit < gtAlgoLogicParser.operandTokenVector().size(); ++iStatusBit ) {
342  const std::string gtStatusBit( gtAlgoLogicParser.operandTokenVector().at( iStatusBit ).tokenName );
343  // Manipulate status bit decision as stored in the parser
344  bool decision( errorReplyDcs_ );
345  // Hard-coded status bits!!!
346  if ( gtStatusBit == "PhysDecl" || gtStatusBit == "PhysicsDeclared" ) {
348  event.getByLabel( gtInputTag_, gtReadoutRecord );
349  if ( ! gtReadoutRecord.isValid() ) {
350  if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "L1GlobalTriggerReadoutRecord product with InputTag \"" << gtInputTag_.encode() << "\" not in event";
351  event.getByType( gtReadoutRecord );
352  if ( ! gtReadoutRecord.isValid() ) {
353  if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "L1GlobalTriggerReadoutRecord product not in event at all ==> decision: " << errorReplyGt_;
354  gtAlgoLogicParser.operandTokenVector().at( iStatusBit ).tokenResult = errorReplyDcs_;
355  continue;
356  }
357  }
358  decision = ( gtReadoutRecord->gtFdlWord().physicsDeclared() == 1 );
359  } else if ( gtStatusBit == "Stable" || gtStatusBit == "StableBeam" || gtStatusBit == "Adjust" || gtStatusBit == "Sqeeze" || gtStatusBit == "Flat" || gtStatusBit == "FlatTop" ||
360  gtStatusBit == "7TeV" || gtStatusBit == "900GeV" ) {
362  event.getByLabel( gtEvmInputTag_, gtEvmReadoutRecord );
363  if ( ! gtEvmReadoutRecord.isValid() ) {
364  if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "L1GlobalTriggerEvmReadoutRecord product with InputTag \"" << gtEvmInputTag_.encode() << "\" not in event";
365  event.getByType( gtEvmReadoutRecord );
366  if ( ! gtEvmReadoutRecord.isValid() ) {
367  if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "L1GlobalTriggerEvmReadoutRecord product not in event at all ==> decision: " << errorReplyGt_;
368  gtAlgoLogicParser.operandTokenVector().at( iStatusBit ).tokenResult = errorReplyDcs_;
369  continue;
370  }
371  }
372  if ( gtStatusBit == "Stable" || gtStatusBit == "StableBeam" ) {
373  decision = ( gtEvmReadoutRecord->gtfeWord().beamMode() == 11 );
374  } else if ( gtStatusBit == "Adjust" ) {
375  decision = ( 10 <= gtEvmReadoutRecord->gtfeWord().beamMode() && gtEvmReadoutRecord->gtfeWord().beamMode() <= 11 );
376  } else if ( gtStatusBit == "Sqeeze" ) {
377  decision = ( 9 <= gtEvmReadoutRecord->gtfeWord().beamMode() && gtEvmReadoutRecord->gtfeWord().beamMode() <= 11 );
378  } else if ( gtStatusBit == "Flat" || gtStatusBit == "FlatTop" ) {
379  decision = ( 8 <= gtEvmReadoutRecord->gtfeWord().beamMode() && gtEvmReadoutRecord->gtfeWord().beamMode() <= 11 );
380  } else if ( gtStatusBit == "7TeV" ) {
381  decision = ( gtEvmReadoutRecord->gtfeWord().beamMomentum() == 3500 );
382  } else if ( gtStatusBit == "900GeV" ) {
383  decision = ( gtEvmReadoutRecord->gtfeWord().beamMomentum() == 450 );
384  }
385  } else {
386  if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "GT status bit \"" << gtStatusBit << "\" is not defined ==> decision: " << errorReplyGt_;
387  }
388  gtAlgoLogicParser.operandTokenVector().at( iStatusBit ).tokenResult = decision;
389  }
390 
391  // Determine decision
392  const bool gtDecision( gtAlgoLogicParser.expressionResult() );
393  return negExpr ? ( ! gtDecision ) : gtDecision;
394 
395 }
396 
397 
400 {
401 
402  // An empty L1 logical expressions list acts as switch.
403  if ( ! onL1_ || l1LogicalExpressions_.empty() ) return ( ! andOr_ ); // logically neutral, depending on base logical connective
404 
405  // Getting the L1 event setup
406  l1Gt_.getL1GtRunCache( event, setup, useL1EventSetup, useL1GtTriggerMenuLite ); // FIXME This can possibly go to initRun()
407 
408  // Determine decision of L1 logical expression combination and return
409  if ( andOrL1_ ) { // OR combination
410  for ( std::vector< std::string >::const_iterator l1LogicalExpression = l1LogicalExpressions_.begin(); l1LogicalExpression != l1LogicalExpressions_.end(); ++l1LogicalExpression ) {
411  if ( acceptL1LogicalExpression( event, *l1LogicalExpression ) ) return true;
412  }
413  return false;
414  }
415  for ( std::vector< std::string >::const_iterator l1LogicalExpression = l1LogicalExpressions_.begin(); l1LogicalExpression != l1LogicalExpressions_.end(); ++l1LogicalExpression ) {
416  if ( ! acceptL1LogicalExpression( event, *l1LogicalExpression ) ) return false;
417  }
418  return true;
419 
420 }
421 
422 
424 bool GenericTriggerEventFlag::acceptL1LogicalExpression( const edm::Event & event, std::string l1LogicalExpression )
425 {
426 
427  // Check empty std::strings
428  if ( l1LogicalExpression.empty() ) {
429  if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "Empty logical expression ==> decision: " << errorReplyL1_;
430  return errorReplyL1_;
431  }
432 
433  // Negated logical expression
434  bool negExpr( negate( l1LogicalExpression ) );
435  if ( negExpr && l1LogicalExpression.empty() ) {
436  if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "Empty (negated) logical expression ==> decision: " << errorReplyL1_;
437  return errorReplyL1_;
438  }
439 
440  // Parse logical expression and determine L1 decision
441  L1GtLogicParser l1AlgoLogicParser( l1LogicalExpression );
442  // Loop over algorithms
443  for ( size_t iAlgorithm = 0; iAlgorithm < l1AlgoLogicParser.operandTokenVector().size(); ++iAlgorithm ) {
444  const std::string l1AlgoName( l1AlgoLogicParser.operandTokenVector().at( iAlgorithm ).tokenName );
445  int error( -1 );
446  const bool decision( l1BeforeMask_ ? l1Gt_.decisionBeforeMask( event, l1AlgoName, error ) : l1Gt_.decisionAfterMask( event, l1AlgoName, error ) );
447  // Error checks
448  if ( error != 0 ) {
449  if ( verbose_ > 1 ) {
450  if ( error == 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "L1 algorithm \"" << l1AlgoName << "\" does not exist in the L1 menu ==> decision: " << errorReplyL1_;
451  else edm::LogWarning( "GenericTriggerEventFlag" ) << "L1 algorithm \"" << l1AlgoName << "\" received error code " << error << " from L1GtUtils::decisionBeforeMask ==> decision: " << errorReplyL1_;
452  }
453  l1AlgoLogicParser.operandTokenVector().at( iAlgorithm ).tokenResult = errorReplyL1_;
454  continue;
455  }
456  // Manipulate algo decision as stored in the parser
457  l1AlgoLogicParser.operandTokenVector().at( iAlgorithm ).tokenResult = decision;
458  }
459 
460  // Return decision
461  const bool l1Decision( l1AlgoLogicParser.expressionResult() );
462  return negExpr ? ( ! l1Decision ) : l1Decision;
463 
464 }
465 
466 
469 {
470 
471  // An empty HLT logical expressions list acts as switch.
472  if ( ! onHlt_ || hltLogicalExpressions_.empty() ) return ( ! andOr_ ); // logically neutral, depending on base logical connective
473 
474  // Checking the HLT configuration,
475  if ( ! hltConfigInit_ ) {
476  if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "HLT config error ==> decision: " << errorReplyHlt_;
477  return errorReplyHlt_;
478  }
479 
480  // Accessing the TriggerResults
481  edm::Handle< edm::TriggerResults > hltTriggerResults;
482  event.getByLabel( hltInputTag_, hltTriggerResults );
483  if ( ! hltTriggerResults.isValid() ) {
484  if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "TriggerResults product with InputTag \"" << hltInputTag_.encode() << "\" not in event ==> decision: " << errorReplyHlt_;
485  return errorReplyHlt_;
486  }
487  if ( ( *hltTriggerResults ).size() == 0 ) {
488  if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "TriggerResults product with InputTag \"" << hltInputTag_.encode() << "\" empty ==> decision: " << errorReplyHlt_;
489  return errorReplyDcs_;
490  }
491 
492  // Determine decision of HLT logical expression combination and return
493  if ( andOrHlt_ ) { // OR combination
494  for ( std::vector< std::string >::const_iterator hltLogicalExpression = hltLogicalExpressions_.begin(); hltLogicalExpression != hltLogicalExpressions_.end(); ++hltLogicalExpression ) {
495  if ( acceptHltLogicalExpression( hltTriggerResults, *hltLogicalExpression ) ) return true;
496  }
497  return false;
498  }
499  for ( std::vector< std::string >::const_iterator hltLogicalExpression = hltLogicalExpressions_.begin(); hltLogicalExpression != hltLogicalExpressions_.end(); ++hltLogicalExpression ) {
500  if ( ! acceptHltLogicalExpression( hltTriggerResults, *hltLogicalExpression ) ) return false;
501  }
502  return true;
503 
504 }
505 
506 
508 bool GenericTriggerEventFlag::acceptHltLogicalExpression( const edm::Handle< edm::TriggerResults > & hltTriggerResults, std::string hltLogicalExpression ) const
509 {
510 
511  // Check empty std::strings
512  if ( hltLogicalExpression.empty() ) {
513  if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "Empty logical expression ==> decision: " << errorReplyHlt_;
514  return errorReplyHlt_;
515  }
516 
517  // Negated paths
518  bool negExpr( negate( hltLogicalExpression ) );
519  if ( negExpr && hltLogicalExpression.empty() ) {
520  if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "Empty (negated) logical expression ==> decision: " << errorReplyHlt_;
521  return errorReplyHlt_;
522  }
523 
524  // Parse logical expression and determine HLT decision
525  L1GtLogicParser hltAlgoLogicParser( hltLogicalExpression );
526  // Loop over paths
527  for ( size_t iPath = 0; iPath < hltAlgoLogicParser.operandTokenVector().size(); ++iPath ) {
528  const std::string hltPathName( hltAlgoLogicParser.operandTokenVector().at( iPath ).tokenName );
529  const unsigned indexPath( hltConfig_.triggerIndex( hltPathName ) );
530  // Further error checks
531  if ( indexPath == hltConfig_.size() ) {
532  if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "HLT path \"" << hltPathName << "\" is not found in process " << hltInputTag_.process() << " ==> decision: " << errorReplyHlt_;
533  hltAlgoLogicParser.operandTokenVector().at( iPath ).tokenResult = errorReplyHlt_;
534  continue;
535  }
536  if ( hltTriggerResults->error( indexPath ) ) {
537  if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "HLT path \"" << hltPathName << "\" in error ==> decision: " << errorReplyHlt_;
538  hltAlgoLogicParser.operandTokenVector().at( iPath ).tokenResult = errorReplyHlt_;
539  continue;
540  }
541  // Manipulate algo decision as stored in the parser
542  const bool decision( hltTriggerResults->accept( indexPath ) );
543  hltAlgoLogicParser.operandTokenVector().at( iPath ).tokenResult = decision;
544  }
545 
546  // Determine decision
547  const bool hltDecision( hltAlgoLogicParser.expressionResult() );
548  return negExpr ? ( ! hltDecision ) : hltDecision;
549 
550 }
551 
552 
553 
555 std::string GenericTriggerEventFlag::expandLogicalExpression( const std::vector< std::string > & targets, const std::string & expr, bool useAnd ) const
556 {
557 
558  // Find matching entries in the menu
559  std::vector< std::string > matched;
560  const std::string versionWildcard( "_v*" );
561  if ( expr.substr( expr.size() - versionWildcard.size() ) == versionWildcard ) {
562  const std::string exprBase( expr.substr( 0, expr.size() - versionWildcard.size() ) );
563  matched = hltConfig_.restoreVersion( targets, exprBase );
564  } else {
565  matched = hltConfig_.matched( targets, expr );
566  }
567 
568  // Return input, if no match is found
569  if ( matched.empty() ) {
570  if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "Logical expression: \"" << expr << "\" could not be resolved";
571  return expr;
572  }
573 
574  // Compose logical expression
575  std::string expanded( "(" );
576  for ( unsigned iVers = 0; iVers < matched.size(); ++iVers ) {
577  if ( iVers > 0 ) expanded.append( useAnd ? " AND " : " OR " );
578  expanded.append( matched.at( iVers ) );
579  }
580  expanded.append( ")" );
581  if ( verbose_ > 1 ) edm::LogInfo( "GenericTriggerEventFlag" ) << "Logical expression: \"" << expr << "\"\n"
582  << " --> expanded to \"" << expanded << "\"";
583 
584  return expanded;
585 
586 }
587 
588 
589 
591 bool GenericTriggerEventFlag::negate( std::string & word ) const
592 {
593 
594  bool negate( false );
595  if ( word.at( 0 ) == '~' ) {
596  negate = true;
597  word.erase( 0, 1 );
598  }
599  return negate;
600 
601 }
602 
603 
604 
606 std::vector< std::string > GenericTriggerEventFlag::expressionsFromDB( const std::string & key, const edm::EventSetup & setup )
607 {
608 
609  if ( key.size() == 0 ) return std::vector< std::string >( 1, emptyKeyError_ );
610  edm::ESHandle< AlCaRecoTriggerBits > logicalExpressions;
611  std::vector< edm::eventsetup::DataKey > labels;
612  setup.get< AlCaRecoTriggerBitsRcd >().fillRegisteredDataKeys( labels );
613  std::vector< edm::eventsetup::DataKey >::const_iterator iKey = labels.begin();
614  while ( iKey != labels.end() && iKey->name().value() != dbLabel_ ) ++iKey;
615  if ( iKey == labels.end() ) {
616  if ( verbose_ > 0 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "Label " << dbLabel_ << " not found in DB for 'AlCaRecoTriggerBitsRcd'";
617  return std::vector< std::string >( 1, configError_ );
618  }
619  setup.get< AlCaRecoTriggerBitsRcd >().get( dbLabel_, logicalExpressions );
620  const std::map< std::string, std::string > & expressionMap = logicalExpressions->m_alcarecoToTrig;
621  std::map< std::string, std::string >::const_iterator listIter = expressionMap.find( key );
622  if ( listIter == expressionMap.end() ) {
623  if ( verbose_ > 0 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "No logical expressions found under key " << key << " in 'AlCaRecoTriggerBitsRcd'";
624  return std::vector< std::string >( 1, configError_ );
625  }
626  return logicalExpressions->decompose( listIter->second );
627 
628 }
unsigned int size() const
number of trigger paths in trigger table
bool negate(std::string &word) const
Checks for negated words.
T getParameter(std::string const &) const
const bool decisionAfterMask(const edm::Event &iEvent, const edm::InputTag &l1GtRecordInputTag, const edm::InputTag &l1GtReadoutRecordInputTag, const std::string &nameAlgoTechTrig, int &errorCode) const
return decision after trigger mask for a given algorithm or technical trigger
Definition: L1GtUtils.cc:1413
std::vector< int > dcsPartitions_
static const std::vector< std::string > matched(const std::vector< std::string > &inputs, const std::string &pattern)
regexp processing
static const bool useL1GtTriggerMenuLite(false)
std::map< std::string, L1GtAlgorithm > AlgorithmMap
map containing the algorithms
std::vector< std::string > gtLogicalExpressions_
std::vector< std::string > hltLogicalExpressions_
const std::vector< std::string > & triggerNames() const
names of trigger paths
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::string encode() const
Definition: InputTag.cc:72
const bool decisionBeforeMask(const edm::Event &iEvent, const edm::InputTag &l1GtRecordInputTag, const edm::InputTag &l1GtReadoutRecordInputTag, const std::string &nameAlgoTechTrig, int &errorCode) const
return decision before trigger mask for a given algorithm or technical trigger
Definition: L1GtUtils.cc:1376
std::vector< std::string > l1LogicalExpressionsCache_
bool acceptHlt(const edm::Event &event)
Was this event accepted by the configured HLT logical expression combination?
AlgorithmMap::const_iterator CItAlgo
iterators through map containing the algorithms
bool acceptDcsPartition(const edm::Handle< DcsStatusCollection > &dcsStatus, int dcsPartition) const
unsigned int triggerIndex(const std::string &triggerName) const
slot position of trigger path in trigger table (0 to size-1)
std::vector< std::string > expressionsFromDB(const std::string &key, const edm::EventSetup &setup)
Reads and returns logical expressions from DB.
std::vector< OperandToken > & operandTokenVector()
return the vector of operand tokens
bool accept(const edm::Event &event, const edm::EventSetup &setup)
To be called from analyze/filter() methods.
bool acceptGtLogicalExpression(const edm::Event &event, std::string gtLogicalExpression)
Does this event fulfill this particular GT status bits&#39; logical expression?
bool acceptL1LogicalExpression(const edm::Event &event, std::string l1LogicalExpression)
Was this event accepted by this particular L1 algorithms&#39; logical expression?
GenericTriggerEventFlag(const edm::ParameterSet &config)
To be called from the ED module&#39;s c&#39;tor.
~GenericTriggerEventFlag()
To be called from d&#39;tors by &#39;delete&#39;.
static const bool useL1EventSetup(true)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
bool isValid() const
Definition: HandleBase.h:76
void getL1GtRunCache(const edm::Run &, const edm::EventSetup &, const bool, const bool, const edm::InputTag &)
get all the run-constant quantities for L1 trigger and cache them
Definition: L1GtUtils.cc:313
edm::ESWatcher< AlCaRecoTriggerBitsRcd > * watchDB_
bool acceptDcs(const edm::Event &event)
std::vector< std::string > hltLogicalExpressionsCache_
static const std::vector< std::string > restoreVersion(const std::vector< std::string > &inputs, const std::string &trigger)
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
const T & get() const
Definition: EventSetup.h:55
std::vector< std::string > l1LogicalExpressions_
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:59
std::string const & process() const
Definition: InputTag.h:29
list key
Definition: combine.py:13
void initRun(const edm::Run &run, const edm::EventSetup &setup)
To be called from beginRun() methods.
std::string expandLogicalExpression(const std::vector< std::string > &target, const std::string &expr, bool useAnd=false) const
Expand wild-carded logical expressions, giving version postfixes priority.
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
Definition: Run.h:33
bool acceptHltLogicalExpression(const edm::Handle< edm::TriggerResults > &hltTriggerResults, std::string hltLogicalExpression) const
Was this event accepted by this particular HLT paths&#39; logical expression?
bool acceptL1(const edm::Event &event, const edm::EventSetup &setup)
Was this event accepted by the configured L1 logical expression combination?
virtual const bool expressionResult() const
bool acceptGt(const edm::Event &event)
Does this event fulfill the configured GT status logical expression combination?