CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/DataFormats/PatCandidates/src/TriggerObjectStandAlone.cc

Go to the documentation of this file.
00001 //
00002 // $Id: TriggerObjectStandAlone.cc,v 1.10 2011/02/22 18:29:50 vadler Exp $
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 // Const data members' definitions
00015 
00016 
00017 const char TriggerObjectStandAlone::wildcard_;
00018 
00019 
00020 // Private methods
00021 
00022 
00023 // Checks a string vector for occurence of a certain string, incl. wild-card mechanism
00024 bool TriggerObjectStandAlone::hasAnyName( const std::string & name, const std::vector< std::string > & nameVec ) const
00025 {
00026   // Special cases first
00027   // Always false for empty vector to check
00028   if ( nameVec.empty() ) return false;
00029   // Always true for general wild-card(s)
00030   if ( name.find_first_not_of( wildcard_ ) == std::string::npos ) return true;
00031   // Split name to evaluate in parts, seperated by wild-cards
00032   std::vector< std::string > namePartsVec;
00033   boost::split( namePartsVec, name, boost::is_any_of( std::string( 1, wildcard_ ) ), boost::token_compress_on );
00034   // Iterate over vector of names to search
00035   for ( std::vector< std::string >::const_iterator iVec = nameVec.begin(); iVec != nameVec.end(); ++iVec ) {
00036     // Not failed yet
00037     bool failed( false );
00038     // Start searching at the first character
00039     size_type index( 0 );
00040     // Iterate over evaluation name parts
00041     for ( std::vector< std::string >::const_iterator iName = namePartsVec.begin(); iName != namePartsVec.end(); ++iName ) {
00042       // Empty parts due to
00043       // - wild-card at beginning/end or
00044       // - multiple wild-cards (should be supressed by 'boost::token_compress_on')
00045       if ( iName->length() == 0 ) continue;
00046       // Search from current index and
00047       // set index to found occurence
00048       index = iVec->find( *iName, index );
00049       // Failed and exit loop, if
00050       // - part not found
00051       // - part at beginning not found there
00052       if ( index == std::string::npos || ( iName == namePartsVec.begin() && index > 0 ) ) {
00053         failed = true;
00054         break;
00055       }
00056       // Increase index by length of found part
00057       index += iName->length();
00058     }
00059     // Failed, if end of name not reached
00060     if ( index < iVec->length() && namePartsVec.back().length() != 0 ) failed = true;
00061     // Match found!
00062     if ( ! failed ) return true;
00063   }
00064   // No match found!
00065   return false;
00066 }
00067 
00068 
00069 // Adds a new HLT path or L1 algorithm name
00070 void TriggerObjectStandAlone::addPathOrAlgorithm( const std::string & name, bool firing )
00071 {
00072   // Check, if path is already assigned
00073   if ( ! hasPathOrAlgorithm( name, false ) ) {
00074     // The path itself
00075     pathNames_.push_back( name );
00076     // The corresponding usage of the trigger objects
00077     pathLastFilterAccepted_.push_back( firing );
00078   }
00079 }
00080 
00081 
00082 // Gets all HLT path or L1 algorithm names
00083 std::vector< std::string > TriggerObjectStandAlone::pathsOrAlgorithms( bool firing ) const
00084 {
00085   // All path names, if usage not restricted (not required or not available)
00086   if ( ! firing || ! hasFiring() ) return pathNames_;
00087   // Temp vector of path names
00088   std::vector< std::string > paths;
00089   // Loop over usage vector and fill corresponding paths into temp vector
00090   for ( unsigned iPath = 0; iPath < pathNames_.size(); ++iPath ) {
00091     if ( pathLastFilterAccepted_.at( iPath ) ) paths.push_back( pathNames_.at( iPath ) );
00092   }
00093   // Return temp vector
00094   return paths;
00095 }
00096 
00097 
00098 // Checks, if a certain HLT filter label or L1 condition name is assigned
00099 bool TriggerObjectStandAlone::hasFilterOrCondition( const std::string & name ) const
00100 {
00101   // Move to wild-card parser, if needed
00102   if ( name.find( wildcard_ ) != std::string::npos ) return hasAnyName( name, filterLabels_ );
00103   // Return, if filter label is assigned
00104   return ( std::find( filterLabels_.begin(), filterLabels_.end(), name ) != filterLabels_.end() );
00105 }
00106 
00107 
00108 // Checks, if a certain path name is assigned
00109 bool TriggerObjectStandAlone::hasPathOrAlgorithm( const std::string & name, bool firing ) const
00110 {
00111   // Move to wild-card parser, if needed
00112   if ( name.find( wildcard_ ) != std::string::npos ) return hasAnyName( name, pathsOrAlgorithms( firing ) );
00113   // Deal with older PAT-tuples, where trigger object usage is not available
00114   if ( ! hasFiring() ) firing = false;
00115   // Check, if path name is assigned at all
00116   std::vector< std::string >::const_iterator match( std::find( pathNames_.begin(), pathNames_.end(), name ) );
00117   // False, if path name not assigned
00118   if ( match == pathNames_.end() ) return false;
00119   // Return for assigned path name, if trigger object usage meets requirement
00120   return ( firing ? pathLastFilterAccepted_.at( match - pathNames_.begin() ) : true );
00121 }
00122 
00123 
00124 // Methods
00125 
00126 
00127 // Gets the pat::TriggerObject (parent class)
00128 TriggerObject TriggerObjectStandAlone::triggerObject()
00129 {
00130   // Create a TriggerObjects
00131   TriggerObject theObj( p4(), pdgId() );
00132   // Set its collection and trigger objects types (no c'tor for that)
00133   theObj.setCollection( collection() );
00134   for ( size_t i = 0; i < triggerObjectTypes().size(); ++i ) theObj.addTriggerObjectType( triggerObjectTypes().at( i ) );
00135   // Return TriggerObject
00136   return theObj;
00137 }
00138 
00139 
00140 // Checks, if a certain label of original collection is assigned (method overrides)
00141 bool TriggerObjectStandAlone::hasCollection( const std::string & collName ) const
00142 {
00143   // Move to wild-card parser, if needed only
00144   if ( collName.find( wildcard_ ) != std::string::npos ) {
00145     // True, if collection name is simply fine
00146     if ( hasAnyName( collName, std::vector< std::string >( 1, collection() ) ) ) return true;
00147     // Check, if collection name possibly fits in an edm::InputTag approach
00148     const edm::InputTag collectionTag( collection() );
00149     const edm::InputTag collTag( collName );
00150     // If evaluated collection tag contains a process name, it must have been found already by identity check
00151     if ( collTag.process().empty() ) {
00152       // Check instance ...
00153       if ( ( collTag.instance().empty() && collectionTag.instance().empty() ) || hasAnyName( collTag.instance(), std::vector< std::string >( 1, collectionTag.instance() ) ) ) {
00154         // ... and label
00155         return hasAnyName( collTag.label(), std::vector< std::string >( 1, collectionTag.label() ) );
00156       }
00157     }
00158     return false;
00159   }
00160   // Use parent class's method otherwise
00161   return TriggerObject::hasCollection( collName );
00162 }