CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/CommonTools/TriggerUtils/src/GenericTriggerEventFlag.cc

Go to the documentation of this file.
00001 //
00002 // $Id: GenericTriggerEventFlag.cc,v 1.6 2011/04/30 19:13:48 vadler Exp $
00003 //
00004 
00005 
00006 #include "CommonTools/TriggerUtils/interface/GenericTriggerEventFlag.h"
00007 
00008 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
00009 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerEvmReadoutRecord.h"
00010 #include "CondFormats/HLTObjects/interface/AlCaRecoTriggerBits.h"
00011 #include "DataFormats/L1GlobalTrigger/interface/L1GtLogicParser.h"
00012 #include "FWCore/Framework/interface/ESHandle.h"
00013 
00014 #include <vector>
00015 
00016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00017 
00018 
00020 GenericTriggerEventFlag::GenericTriggerEventFlag( const edm::ParameterSet & config )
00021   : watchDB_( 0 )
00022   , hltConfigInit_( false )
00023   , andOr_( false )
00024   , dbLabel_( "" )
00025   , verbose_( 0 )
00026   , andOrDcs_( false )
00027   , errorReplyDcs_( false )
00028   , andOrGt_( false )
00029   , gtInputTag_( "" )
00030   , gtEvmInputTag_( "" )
00031   , gtDBKey_( "" )
00032   , errorReplyGt_( false )
00033   , andOrL1_( false )
00034   , l1BeforeMask_( true )
00035   , l1DBKey_( "" )
00036   , errorReplyL1_( false )
00037   , andOrHlt_( false )
00038   , hltDBKey_( "" )
00039   , errorReplyHlt_( false )
00040   , on_( true )
00041   , onDcs_( true )
00042   , onGt_( true )
00043   , onL1_( true )
00044   , onHlt_( true )
00045   , configError_( "CONFIG_ERROR" )
00046 {
00047 
00048   // General switch(es)
00049   if ( config.exists( "andOr" ) ) {
00050     andOr_ = config.getParameter< bool >( "andOr" );
00051     if ( config.exists( "verbosityLevel" ) ) verbose_ = config.getParameter< unsigned >( "verbosityLevel" );
00052   } else {
00053     on_    = false;
00054     onDcs_ = false;
00055     onGt_  = false;
00056     onL1_  = false;
00057     onHlt_ = false;
00058   }
00059 
00060   if ( on_ ) {
00061     if ( config.exists( "andOrDcs" ) ) {
00062       andOrDcs_      = config.getParameter< bool >( "andOrDcs" );
00063       dcsInputTag_   = config.getParameter< edm::InputTag >( "dcsInputTag" );
00064       dcsPartitions_ = config.getParameter< std::vector< int > >( "dcsPartitions" );
00065       errorReplyDcs_ = config.getParameter< bool >( "errorReplyDcs" );
00066     } else {
00067       onDcs_ = false;
00068     }
00069     if ( config.exists( "andOrGt" ) ) {
00070       andOrGt_              = config.getParameter< bool >( "andOrGt" );
00071       gtInputTag_           = config.getParameter< edm::InputTag >( "gtInputTag" );
00072       gtLogicalExpressions_ = config.getParameter< std::vector< std::string > >( "gtStatusBits" );
00073       errorReplyGt_         = config.getParameter< bool >( "errorReplyGt" );
00074       if ( config.exists( "gtEvmInputTag" ) ) gtEvmInputTag_ = config.getParameter< edm::InputTag >( "gtEvmInputTag" );
00075       if ( config.exists( "gtDBKey" ) )       gtDBKey_       = config.getParameter< std::string >( "gtDBKey" );
00076     } else {
00077       onGt_ = false;
00078     }
00079     if ( config.exists( "andOrL1" ) ) {
00080       andOrL1_              = config.getParameter< bool >( "andOrL1" );
00081       l1LogicalExpressions_ = config.getParameter< std::vector< std::string > >( "l1Algorithms" );
00082       errorReplyL1_         = config.getParameter< bool >( "errorReplyL1" );
00083       if ( config.exists( "l1DBKey" ) )      l1DBKey_      = config.getParameter< std::string >( "l1DBKey" );
00084       if ( config.exists( "l1BeforeMask" ) ) l1BeforeMask_ = config.getParameter< bool >( "l1BeforeMask" );
00085     } else {
00086       onL1_ = false;
00087     }
00088     if ( config.exists( "andOrHlt" ) ) {
00089       andOrHlt_              = config.getParameter< bool >( "andOrHlt" );
00090       hltInputTag_           = config.getParameter< edm::InputTag >( "hltInputTag" );
00091       hltLogicalExpressions_ = config.getParameter< std::vector< std::string > >( "hltPaths" );
00092       errorReplyHlt_         = config.getParameter< bool >( "errorReplyHlt" );
00093       if ( config.exists( "hltDBKey" ) ) hltDBKey_ = config.getParameter< std::string >( "hltDBKey" );
00094     } else {
00095       onHlt_ = false;
00096     }
00097     if ( ! onDcs_ && ! onGt_ && ! onL1_ && ! onHlt_ ) on_ = false;
00098     else {
00099       if ( config.exists( "dbLabel" ) ) dbLabel_ = config.getParameter< std::string >( "dbLabel" );
00100       watchDB_ = new edm::ESWatcher< AlCaRecoTriggerBitsRcd >;
00101     }
00102   }
00103 
00104 }
00105 
00106 
00108 GenericTriggerEventFlag::~GenericTriggerEventFlag()
00109 {
00110 
00111   if ( on_ ) delete watchDB_;
00112 
00113 }
00114 
00115 
00117 void GenericTriggerEventFlag::initRun( const edm::Run & run, const edm::EventSetup & setup )
00118 {
00119 
00120   if ( watchDB_->check( setup ) ) {
00121     if ( onGt_ && gtDBKey_.size() > 0 ) {
00122       const std::vector< std::string > exprs( expressionsFromDB( gtDBKey_, setup ) );
00123       if ( exprs.empty() || exprs.at( 0 ) != configError_ ) gtLogicalExpressions_ = exprs;
00124     }
00125     if ( onL1_ && l1DBKey_.size() > 0 ) {
00126       const std::vector< std::string > exprs( expressionsFromDB( l1DBKey_, setup ) );
00127       if ( exprs.empty() || exprs.at( 0 ) != configError_ ) l1LogicalExpressions_ = exprs;
00128     }
00129     if ( onHlt_ && hltDBKey_.size() > 0 ) {
00130       const std::vector< std::string > exprs( expressionsFromDB( hltDBKey_, setup ) );
00131       if ( exprs.empty() || exprs.at( 0 ) != configError_ ) hltLogicalExpressions_ = exprs;
00132     }
00133   }
00134 
00135   hltConfigInit_ = false;
00136   if ( onHlt_ ) {
00137     if ( hltInputTag_.process().size() == 0 ) {
00138       if ( verbose_ > 0 ) edm::LogError( "GenericTriggerEventFlag" ) << "HLT TriggerResults InputTag \"" << hltInputTag_.encode() << "\" specifies no process";
00139     } else {
00140       bool hltChanged( false );
00141       if ( ! hltConfig_.init( run, setup, hltInputTag_.process(), hltChanged ) ) {
00142         if ( verbose_ > 0 ) edm::LogError( "GenericTriggerEventFlag" ) << "HLT config initialization error with process name \"" << hltInputTag_.process() << "\"";
00143       } else if ( hltConfig_.size() <= 0 ) {
00144         if ( verbose_ > 0 ) edm::LogError( "GenericTriggerEventFlag" ) << "HLT config size error";
00145       } else hltConfigInit_ = true;
00146     }
00147   }
00148 
00149 }
00150 
00151 
00153 bool GenericTriggerEventFlag::accept( const edm::Event & event, const edm::EventSetup & setup )
00154 {
00155 
00156   if ( ! on_ ) return true;
00157 
00158   // Determine decision
00159   if ( andOr_ ) return ( acceptDcs( event ) || acceptGt( event ) || acceptL1( event, setup ) || acceptHlt( event ) );
00160   return ( acceptDcs( event ) && acceptGt( event ) && acceptL1( event, setup ) && acceptHlt( event ) );
00161 
00162 }
00163 
00164 
00165 bool GenericTriggerEventFlag::acceptDcs( const edm::Event & event )
00166 {
00167 
00168   // An empty DCS partitions list acts as switch.
00169   if ( ! onDcs_ || dcsPartitions_.empty() ) return ( ! andOr_ ); // logically neutral, depending on base logical connective
00170 
00171   // Accessing the DcsStatusCollection
00172   edm::Handle< DcsStatusCollection > dcsStatus;
00173   event.getByLabel( dcsInputTag_, dcsStatus );
00174   if ( ! dcsStatus.isValid() ) {
00175     if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "DcsStatusCollection product with InputTag \"" << dcsInputTag_.encode() << "\" not in event ==> decision: " << errorReplyDcs_;
00176     return errorReplyDcs_;
00177   }
00178   if ( ( *dcsStatus ).size() == 0 ) {
00179     if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "DcsStatusCollection product with InputTag \"" << dcsInputTag_.encode() << "\" empty ==> decision: " << errorReplyDcs_;
00180     return errorReplyDcs_;
00181   }
00182 
00183   // Determine decision of DCS partition combination and return
00184   if ( andOrDcs_ ) { // OR combination
00185     for ( std::vector< int >::const_iterator partitionNumber = dcsPartitions_.begin(); partitionNumber != dcsPartitions_.end(); ++partitionNumber ) {
00186       if ( acceptDcsPartition( dcsStatus, *partitionNumber ) ) return true;
00187     }
00188     return false;
00189   }
00190   for ( std::vector< int >::const_iterator partitionNumber = dcsPartitions_.begin(); partitionNumber != dcsPartitions_.end(); ++partitionNumber ) {
00191     if ( ! acceptDcsPartition( dcsStatus, *partitionNumber ) ) return false;
00192   }
00193   return true;
00194 
00195 }
00196 
00197 
00198 bool GenericTriggerEventFlag::acceptDcsPartition( const edm::Handle< DcsStatusCollection > & dcsStatus, int dcsPartition ) const
00199 {
00200 
00201   // Error checks
00202   switch( dcsPartition ) {
00203     case DcsStatus::EBp   :
00204     case DcsStatus::EBm   :
00205     case DcsStatus::EEp   :
00206     case DcsStatus::EEm   :
00207     case DcsStatus::HBHEa :
00208     case DcsStatus::HBHEb :
00209     case DcsStatus::HBHEc :
00210     case DcsStatus::HF    :
00211     case DcsStatus::HO    :
00212     case DcsStatus::RPC   :
00213     case DcsStatus::DT0   :
00214     case DcsStatus::DTp   :
00215     case DcsStatus::DTm   :
00216     case DcsStatus::CSCp  :
00217     case DcsStatus::CSCm  :
00218     case DcsStatus::CASTOR:
00219     case DcsStatus::TIBTID:
00220     case DcsStatus::TOB   :
00221     case DcsStatus::TECp  :
00222     case DcsStatus::TECm  :
00223     case DcsStatus::BPIX  :
00224     case DcsStatus::FPIX  :
00225     case DcsStatus::ESp   :
00226     case DcsStatus::ESm   :
00227       break;
00228     default:
00229       if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "DCS partition number \"" << dcsPartition << "\" does not exist ==> decision: " << errorReplyDcs_;
00230       return errorReplyDcs_;
00231   }
00232 
00233   // Determine decision
00234   return dcsStatus->at( 0 ).ready( dcsPartition );
00235 
00236 }
00237 
00238 
00240 bool GenericTriggerEventFlag::acceptGt( const edm::Event & event )
00241 {
00242 
00243   // An empty GT status bits logical expressions list acts as switch.
00244   if ( ! onGt_ || gtLogicalExpressions_.empty() ) return ( ! andOr_ ); // logically neutral, depending on base logical connective
00245 
00246   // Determine decision of GT status bits logical expression combination and return
00247   if ( andOrGt_ ) { // OR combination
00248     for ( std::vector< std::string >::const_iterator gtLogicalExpression = gtLogicalExpressions_.begin(); gtLogicalExpression != gtLogicalExpressions_.end(); ++gtLogicalExpression ) {
00249       if ( acceptGtLogicalExpression( event, *gtLogicalExpression ) ) return true;
00250     }
00251     return false;
00252   }
00253   for ( std::vector< std::string >::const_iterator gtLogicalExpression = gtLogicalExpressions_.begin(); gtLogicalExpression != gtLogicalExpressions_.end(); ++gtLogicalExpression ) {
00254     if ( ! acceptGtLogicalExpression( event, *gtLogicalExpression ) ) return false;
00255   }
00256   return true;
00257 
00258 }
00259 
00260 
00262 bool GenericTriggerEventFlag::acceptGtLogicalExpression( const edm::Event & event, std::string gtLogicalExpression )
00263 {
00264 
00265   // Check empty std::strings
00266   if ( gtLogicalExpression.empty() ) {
00267     if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "Empty logical expression ==> decision: " << errorReplyGt_;
00268     return errorReplyGt_;
00269   }
00270 
00271   // Negated paths
00272   bool negExpr( negate( gtLogicalExpression ) );
00273   if ( negExpr && gtLogicalExpression.empty() ) {
00274     if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "Empty (negated) logical expression ==> decision: " << errorReplyGt_;
00275     return errorReplyGt_;
00276   }
00277 
00278   // Parse logical expression and determine GT status bit decision
00279   L1GtLogicParser gtAlgoLogicParser( gtLogicalExpression );
00280   // Loop over status bits
00281   for ( size_t iStatusBit = 0; iStatusBit < gtAlgoLogicParser.operandTokenVector().size(); ++iStatusBit ) {
00282     const std::string gtStatusBit( gtAlgoLogicParser.operandTokenVector().at( iStatusBit ).tokenName );
00283     // Manipulate status bit decision as stored in the parser
00284     bool decision( errorReplyDcs_ );
00285     // Hard-coded status bits!!!
00286     if ( gtStatusBit == "PhysDecl" || gtStatusBit == "PhysicsDeclared" ) {
00287       edm::Handle< L1GlobalTriggerReadoutRecord > gtReadoutRecord;
00288       event.getByLabel( gtInputTag_, gtReadoutRecord );
00289       if ( ! gtReadoutRecord.isValid() ) {
00290         if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "L1GlobalTriggerReadoutRecord product with InputTag \"" << gtInputTag_.encode() << "\" not in event";
00291         event.getByType( gtReadoutRecord );
00292         if ( ! gtReadoutRecord.isValid() ) {
00293           if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "L1GlobalTriggerReadoutRecord product not in event at all ==> decision: " << errorReplyGt_;
00294           gtAlgoLogicParser.operandTokenVector().at( iStatusBit ).tokenResult = errorReplyDcs_;
00295           continue;
00296         }
00297       }
00298       decision = ( gtReadoutRecord->gtFdlWord().physicsDeclared() == 1 );
00299     } else if ( gtStatusBit == "Stable" || gtStatusBit == "StableBeam" || gtStatusBit == "Adjust" || gtStatusBit == "Sqeeze" || gtStatusBit == "Flat" || gtStatusBit == "FlatTop" ||
00300                 gtStatusBit == "7TeV" || gtStatusBit == "900GeV" ) {
00301       edm::Handle< L1GlobalTriggerEvmReadoutRecord > gtEvmReadoutRecord;
00302       event.getByLabel( gtEvmInputTag_, gtEvmReadoutRecord );
00303       if ( ! gtEvmReadoutRecord.isValid() ) {
00304         if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "L1GlobalTriggerEvmReadoutRecord product with InputTag \"" << gtEvmInputTag_.encode() << "\" not in event";
00305         event.getByType( gtEvmReadoutRecord );
00306         if ( ! gtEvmReadoutRecord.isValid() ) {
00307           if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "L1GlobalTriggerEvmReadoutRecord product not in event at all ==> decision: " << errorReplyGt_;
00308           gtAlgoLogicParser.operandTokenVector().at( iStatusBit ).tokenResult = errorReplyDcs_;
00309           continue;
00310         }
00311       }
00312       if ( gtStatusBit == "Stable" || gtStatusBit == "StableBeam" ) {
00313         decision = ( gtEvmReadoutRecord->gtfeWord().beamMode() == 11 );
00314       } else if ( gtStatusBit == "Adjust" ) {
00315         decision = ( 10 <= gtEvmReadoutRecord->gtfeWord().beamMode() && gtEvmReadoutRecord->gtfeWord().beamMode() <= 11 );
00316       } else if ( gtStatusBit == "Sqeeze" ) {
00317         decision = ( 9 <= gtEvmReadoutRecord->gtfeWord().beamMode() && gtEvmReadoutRecord->gtfeWord().beamMode() <= 11 );
00318       } else if ( gtStatusBit == "Flat" || gtStatusBit == "FlatTop" ) {
00319         decision = ( 8 <= gtEvmReadoutRecord->gtfeWord().beamMode() && gtEvmReadoutRecord->gtfeWord().beamMode() <= 11 );
00320       } else if ( gtStatusBit == "7TeV" ) {
00321         decision = ( gtEvmReadoutRecord->gtfeWord().beamMomentum() == 3500 );
00322       } else if ( gtStatusBit == "900GeV" ) {
00323         decision = ( gtEvmReadoutRecord->gtfeWord().beamMomentum() == 450 );
00324       }
00325     } else {
00326       if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "GT status bit \"" << gtStatusBit << "\" is not defined ==> decision: " << errorReplyGt_;
00327     }
00328     gtAlgoLogicParser.operandTokenVector().at( iStatusBit ).tokenResult = decision;
00329   }
00330 
00331   // Determine decision
00332   const bool gtDecision( gtAlgoLogicParser.expressionResult() );
00333   return negExpr ? ( ! gtDecision ) : gtDecision;
00334 
00335 }
00336 
00337 
00339 bool GenericTriggerEventFlag::acceptL1( const edm::Event & event, const edm::EventSetup & setup )
00340 {
00341 
00342   // An empty L1 logical expressions list acts as switch.
00343   if ( ! onL1_ || l1LogicalExpressions_.empty() ) return ( ! andOr_ ); // logically neutral, depending on base logical connective
00344 
00345   // Getting the L1 event setup
00346   l1Gt_.retrieveL1EventSetup( setup ); // FIXME This can possibly go to initRun()
00347 
00348   // Determine decision of L1 logical expression combination and return
00349   if ( andOrL1_ ) { // OR combination
00350     for ( std::vector< std::string >::const_iterator l1LogicalExpression = l1LogicalExpressions_.begin(); l1LogicalExpression != l1LogicalExpressions_.end(); ++l1LogicalExpression ) {
00351       if ( acceptL1LogicalExpression( event, *l1LogicalExpression ) ) return true;
00352     }
00353     return false;
00354   }
00355   for ( std::vector< std::string >::const_iterator l1LogicalExpression = l1LogicalExpressions_.begin(); l1LogicalExpression != l1LogicalExpressions_.end(); ++l1LogicalExpression ) {
00356     if ( ! acceptL1LogicalExpression( event, *l1LogicalExpression ) ) return false;
00357   }
00358   return true;
00359 
00360 }
00361 
00362 
00364 bool GenericTriggerEventFlag::acceptL1LogicalExpression( const edm::Event & event, std::string l1LogicalExpression )
00365 {
00366 
00367   // Check empty std::strings
00368   if ( l1LogicalExpression.empty() ) {
00369     if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "Empty logical expression ==> decision: " << errorReplyL1_;
00370     return errorReplyL1_;
00371   }
00372 
00373   // Negated logical expression
00374   bool negExpr( negate( l1LogicalExpression ) );
00375   if ( negExpr && l1LogicalExpression.empty() ) {
00376     if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "Empty (negated) logical expression ==> decision: " << errorReplyL1_;
00377     return errorReplyL1_;
00378   }
00379 
00380   // Parse logical expression and determine L1 decision
00381   L1GtLogicParser l1AlgoLogicParser( l1LogicalExpression );
00382   // Loop over algorithms
00383   for ( size_t iAlgorithm = 0; iAlgorithm < l1AlgoLogicParser.operandTokenVector().size(); ++iAlgorithm ) {
00384     const std::string l1AlgoName( l1AlgoLogicParser.operandTokenVector().at( iAlgorithm ).tokenName );
00385     int error( -1 );
00386     const bool decision( l1BeforeMask_ ? l1Gt_.decisionBeforeMask( event, l1AlgoName, error ) : l1Gt_.decisionAfterMask( event, l1AlgoName, error ) );
00387     // Error checks
00388     if ( error != 0 ) {
00389       if ( verbose_ > 1 ) {
00390         if ( error == 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "L1 algorithm \"" << l1AlgoName << "\" does not exist in the L1 menu ==> decision: "                                          << errorReplyL1_;
00391         else              edm::LogWarning( "GenericTriggerEventFlag" ) << "L1 algorithm \"" << l1AlgoName << "\" received error code " << error << " from L1GtUtils::decisionBeforeMask ==> decision: " << errorReplyL1_;
00392       }
00393       l1AlgoLogicParser.operandTokenVector().at( iAlgorithm ).tokenResult = errorReplyL1_;
00394       continue;
00395     }
00396     // Manipulate algo decision as stored in the parser
00397     l1AlgoLogicParser.operandTokenVector().at( iAlgorithm ).tokenResult = decision;
00398   }
00399 
00400   // Return decision
00401   const bool l1Decision( l1AlgoLogicParser.expressionResult() );
00402   return negExpr ? ( ! l1Decision ) : l1Decision;
00403 
00404 }
00405 
00406 
00408 bool GenericTriggerEventFlag::acceptHlt( const edm::Event & event )
00409 {
00410 
00411   // An empty HLT logical expressions list acts as switch.
00412   if ( ! onHlt_ || hltLogicalExpressions_.empty() ) return ( ! andOr_ ); // logically neutral, depending on base logical connective
00413 
00414   // Checking the HLT configuration,
00415   if ( ! hltConfigInit_ ) {
00416     if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "HLT config error ==> decision: " << errorReplyHlt_;
00417     return errorReplyHlt_;
00418   }
00419 
00420   // Accessing the TriggerResults
00421   edm::Handle< edm::TriggerResults > hltTriggerResults;
00422   event.getByLabel( hltInputTag_, hltTriggerResults );
00423   if ( ! hltTriggerResults.isValid() ) {
00424     if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "TriggerResults product with InputTag \"" << hltInputTag_.encode() << "\" not in event ==> decision: " << errorReplyHlt_;
00425     return errorReplyHlt_;
00426   }
00427   if ( ( *hltTriggerResults ).size() == 0 ) {
00428     if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "TriggerResults product with InputTag \"" << hltInputTag_.encode() << "\" empty ==> decision: " << errorReplyHlt_;
00429     return errorReplyDcs_;
00430   }
00431 
00432   // Determine decision of HLT logical expression combination and return
00433   if ( andOrHlt_ ) { // OR combination
00434     for ( std::vector< std::string >::const_iterator hltLogicalExpression = hltLogicalExpressions_.begin(); hltLogicalExpression != hltLogicalExpressions_.end(); ++hltLogicalExpression ) {
00435       if ( acceptHltLogicalExpression( hltTriggerResults, *hltLogicalExpression ) ) return true;
00436     }
00437     return false;
00438   }
00439   for ( std::vector< std::string >::const_iterator hltLogicalExpression = hltLogicalExpressions_.begin(); hltLogicalExpression != hltLogicalExpressions_.end(); ++hltLogicalExpression ) {
00440     if ( ! acceptHltLogicalExpression( hltTriggerResults, *hltLogicalExpression ) ) return false;
00441   }
00442   return true;
00443 
00444 }
00445 
00446 
00448 bool GenericTriggerEventFlag::acceptHltLogicalExpression( const edm::Handle< edm::TriggerResults > & hltTriggerResults, std::string hltLogicalExpression ) const
00449 {
00450 
00451   // Check empty std::strings
00452   if ( hltLogicalExpression.empty() ) {
00453     if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "Empty logical expression ==> decision: " << errorReplyHlt_;
00454     return errorReplyHlt_;
00455   }
00456 
00457   // Negated paths
00458   bool negExpr( negate( hltLogicalExpression ) );
00459   if ( negExpr && hltLogicalExpression.empty() ) {
00460     if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "Empty (negated) logical expression ==> decision: " << errorReplyHlt_;
00461     return errorReplyHlt_;
00462   }
00463 
00464   // Parse logical expression and determine HLT decision
00465   L1GtLogicParser hltAlgoLogicParser( hltLogicalExpression );
00466   // Loop over paths
00467   for ( size_t iPath = 0; iPath < hltAlgoLogicParser.operandTokenVector().size(); ++iPath ) {
00468     const std::string hltPathName( hltAlgoLogicParser.operandTokenVector().at( iPath ).tokenName );
00469     const unsigned indexPath( hltConfig_.triggerIndex( hltPathName ) );
00470     // Further error checks
00471     if ( indexPath == hltConfig_.size() ) {
00472       if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "HLT path \"" << hltPathName << "\" is not found in process " << hltInputTag_.process() << " ==> decision: " << errorReplyHlt_;
00473       hltAlgoLogicParser.operandTokenVector().at( iPath ).tokenResult = errorReplyHlt_;
00474       continue;
00475     }
00476     if ( hltTriggerResults->error( indexPath ) ) {
00477       if ( verbose_ > 1 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "HLT path \"" << hltPathName << "\" in error ==> decision: " << errorReplyHlt_;
00478       hltAlgoLogicParser.operandTokenVector().at( iPath ).tokenResult = errorReplyHlt_;
00479       continue;
00480     }
00481     // Manipulate algo decision as stored in the parser
00482     const bool decision( hltTriggerResults->accept( indexPath ) );
00483     hltAlgoLogicParser.operandTokenVector().at( iPath ).tokenResult = decision;
00484   }
00485 
00486   // Determine decision
00487   const bool hltDecision( hltAlgoLogicParser.expressionResult() );
00488   return negExpr ? ( ! hltDecision ) : hltDecision;
00489 
00490 }
00491 
00492 
00493 
00495 std::vector< std::string > GenericTriggerEventFlag::expressionsFromDB( const std::string & key, const edm::EventSetup & setup )
00496 {
00497 
00498   edm::ESHandle< AlCaRecoTriggerBits > logicalExpressions;
00499   setup.get< AlCaRecoTriggerBitsRcd >().get( dbLabel_, logicalExpressions );
00500   const std::map< std::string, std::string > & expressionMap = logicalExpressions->m_alcarecoToTrig;
00501   std::map< std::string, std::string >::const_iterator listIter = expressionMap.find( key );
00502   if ( listIter == expressionMap.end() ) {
00503     if ( verbose_ > 0 ) edm::LogWarning( "GenericTriggerEventFlag" ) << "No logical expressions found under key " << key << " in 'AlCaRecoTriggerBitsRcd'";
00504     return std::vector< std::string >( 1, configError_ );
00505   }
00506   return logicalExpressions->decompose( listIter->second );
00507 
00508 }
00509 
00510 
00511 
00513 bool GenericTriggerEventFlag::negate( std::string & word ) const
00514 {
00515 
00516   bool negate( false );
00517   if ( word.at( 0 ) == '~' ) {
00518     negate = true;
00519     word.erase( 0, 1 );
00520   }
00521   return negate;
00522 
00523 }