Go to the documentation of this file.00001
00002
00003
00004
00005 #include "DataFormats/PatCandidates/interface/TriggerObjectStandAlone.h"
00006
00007 #include <boost/algorithm/string.hpp>
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009
00010
00011 using namespace pat;
00012
00013
00014
00015
00016
00017 const char TriggerObjectStandAlone::wildcard_;
00018
00019
00020
00021
00022
00023
00024 bool TriggerObjectStandAlone::hasAnyName( const std::string & name, const std::vector< std::string > & nameVec ) const
00025 {
00026
00027
00028 if ( nameVec.empty() ) return false;
00029
00030 if ( name.find_first_not_of( wildcard_ ) == std::string::npos ) return true;
00031
00032 std::vector< std::string > namePartsVec;
00033 boost::split( namePartsVec, name, boost::is_any_of( std::string( 1, wildcard_ ) ), boost::token_compress_on );
00034
00035 for ( std::vector< std::string >::const_iterator iVec = nameVec.begin(); iVec != nameVec.end(); ++iVec ) {
00036
00037 bool failed( false );
00038
00039 size_type index( 0 );
00040
00041 for ( std::vector< std::string >::const_iterator iName = namePartsVec.begin(); iName != namePartsVec.end(); ++iName ) {
00042
00043
00044
00045 if ( iName->length() == 0 ) continue;
00046
00047
00048 index = iVec->find( *iName, index );
00049
00050
00051
00052 if ( index == std::string::npos || ( iName == namePartsVec.begin() && index > 0 ) ) {
00053 failed = true;
00054 break;
00055 }
00056
00057 index += iName->length();
00058 }
00059
00060 if ( index < iVec->length() && namePartsVec.back().length() != 0 ) failed = true;
00061
00062 if ( ! failed ) return true;
00063 }
00064
00065 return false;
00066 }
00067
00068
00069
00070 void TriggerObjectStandAlone::addPathOrAlgorithm( const std::string & name, bool firing )
00071 {
00072
00073 if ( ! hasPathOrAlgorithm( name, false ) ) {
00074
00075 pathNames_.push_back( name );
00076
00077 pathLastFilterAccepted_.push_back( firing );
00078 }
00079 }
00080
00081
00082
00083 std::vector< std::string > TriggerObjectStandAlone::pathsOrAlgorithms( bool firing ) const
00084 {
00085
00086 if ( ! firing || ! hasFiring() ) return pathNames_;
00087
00088 std::vector< std::string > paths;
00089
00090 for ( unsigned iPath = 0; iPath < pathNames_.size(); ++iPath ) {
00091 if ( pathLastFilterAccepted_.at( iPath ) ) paths.push_back( pathNames_.at( iPath ) );
00092 }
00093
00094 return paths;
00095 }
00096
00097
00098
00099 bool TriggerObjectStandAlone::hasFilterOrCondition( const std::string & name ) const
00100 {
00101
00102 if ( name.find( wildcard_ ) != std::string::npos ) return hasAnyName( name, filterLabels_ );
00103
00104 return ( std::find( filterLabels_.begin(), filterLabels_.end(), name ) != filterLabels_.end() );
00105 }
00106
00107
00108
00109 bool TriggerObjectStandAlone::hasPathOrAlgorithm( const std::string & name, bool firing ) const
00110 {
00111
00112 if ( name.find( wildcard_ ) != std::string::npos ) return hasAnyName( name, pathsOrAlgorithms( firing ) );
00113
00114 if ( ! hasFiring() ) firing = false;
00115
00116 std::vector< std::string >::const_iterator match( std::find( pathNames_.begin(), pathNames_.end(), name ) );
00117
00118 if ( match == pathNames_.end() ) return false;
00119
00120 return ( firing ? pathLastFilterAccepted_.at( match - pathNames_.begin() ) : true );
00121 }
00122
00123
00124
00125
00126
00127
00128 TriggerObject TriggerObjectStandAlone::triggerObject()
00129 {
00130
00131 TriggerObject theObj( p4(), pdgId() );
00132
00133 theObj.setCollection( collection() );
00134 for ( size_t i = 0; i < triggerObjectTypes().size(); ++i ) theObj.addTriggerObjectType( triggerObjectTypes().at( i ) );
00135
00136 return theObj;
00137 }
00138
00139
00140
00141 bool TriggerObjectStandAlone::hasCollection( const std::string & collName ) const
00142 {
00143
00144 if ( collName.find( wildcard_ ) != std::string::npos ) {
00145
00146 if ( hasAnyName( collName, std::vector< std::string >( 1, collection() ) ) ) return true;
00147
00148 const edm::InputTag collectionTag( collection() );
00149 const edm::InputTag collTag( collName );
00150
00151 if ( collTag.process().empty() ) {
00152
00153 if ( ( collTag.instance().empty() && collectionTag.instance().empty() ) || hasAnyName( collTag.instance(), std::vector< std::string >( 1, collectionTag.instance() ) ) ) {
00154
00155 return hasAnyName( collTag.label(), std::vector< std::string >( 1, collectionTag.label() ) );
00156 }
00157 }
00158 return false;
00159 }
00160
00161 return TriggerObject::hasCollection( collName );
00162 }