CMS 3D CMS Logo

pat::PATTriggerProducer Class Reference

Produces the pat::TriggerPathCollection, pat::TriggerFilterCollection and pat::TriggerObjectCollection in PAT layer 0. More...

#include <PhysicsTools/PatAlgos/plugins/PATTriggerProducer.h>

Inheritance diagram for pat::PATTriggerProducer:

edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

 PATTriggerProducer (const edm::ParameterSet &iConfig)
 ~PATTriggerProducer ()

Private Member Functions

virtual void beginRun (edm::Run &iRun, const edm::EventSetup &iSetup)
virtual void produce (edm::Event &iEvent, const edm::EventSetup &iSetup)

Private Attributes

bool addPathModuleLabels_
HLTConfigProvider hltConfig_
std::string nameProcess_
bool onlyStandAlone_
edm::InputTag tagTriggerEvent_
edm::InputTag tagTriggerResults_


Detailed Description

Produces the pat::TriggerPathCollection, pat::TriggerFilterCollection and pat::TriggerObjectCollection in PAT layer 0.

[...]

Author:
Volker Adler
Version:
Id
PATTriggerProducer.h,v 1.1.2.4 2009/04/01 15:45:33 vadler Exp

Definition at line 47 of file PATTriggerProducer.h.


Constructor & Destructor Documentation

PATTriggerProducer::PATTriggerProducer ( const edm::ParameterSet iConfig  )  [explicit]

Definition at line 13 of file PATTriggerProducer.cc.

References edm::InputTag::instance(), edm::InputTag::label(), nameProcess_, onlyStandAlone_, edm::InputTag::process(), tagTriggerEvent_, and tagTriggerResults_.

00013                                                                         :
00014   nameProcess_( iConfig.getParameter< std::string >( "processName" ) ),
00015   tagTriggerResults_( iConfig.getParameter< edm::InputTag >( "triggerResults" ) ),
00016   tagTriggerEvent_( iConfig.getParameter< edm::InputTag >( "triggerEvent" ) ),
00017   onlyStandAlone_( iConfig.getParameter< bool >( "onlyStandAlone" ) ),
00018   addPathModuleLabels_( iConfig.getParameter< bool >( "addPathModuleLabels" ) )
00019 {
00020   if ( tagTriggerResults_.process().empty() ) {
00021     tagTriggerResults_ = edm::InputTag( tagTriggerResults_.label(), tagTriggerResults_.instance(), nameProcess_ );
00022   }
00023   if ( tagTriggerEvent_.process().empty() ) {
00024     tagTriggerEvent_ = edm::InputTag( tagTriggerEvent_.label(), tagTriggerEvent_.instance(), nameProcess_ );
00025   }
00026 
00027   if ( ! onlyStandAlone_ ) {
00028     produces< TriggerPathCollection >();
00029     produces< TriggerFilterCollection >();
00030     produces< TriggerObjectCollection >();
00031   }
00032   produces< TriggerObjectStandAloneCollection >();
00033 }

PATTriggerProducer::~PATTriggerProducer (  ) 

Definition at line 35 of file PATTriggerProducer.cc.

00036 {
00037 }


Member Function Documentation

void PATTriggerProducer::beginRun ( edm::Run iRun,
const edm::EventSetup iSetup 
) [private, virtual]

Reimplemented from edm::EDProducer.

Definition at line 39 of file PATTriggerProducer.cc.

References hltConfig_, HLTConfigProvider::init(), and nameProcess_.

00040 {
00041   if ( ! hltConfig_.init( nameProcess_ ) ) {
00042     edm::LogError( "errorHltConfigExtraction" ) << "HLT config extraction error with process name " << nameProcess_;
00043     return;
00044   }                          
00045 }

void PATTriggerProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
) [private, virtual]

Implements edm::EDProducer.

Definition at line 47 of file PATTriggerProducer.cc.

References pat::TriggerObjectStandAlone::addFilterLabel(), pat::TriggerFilter::addObjectId(), pat::TriggerFilter::addObjectKey(), addPathModuleLabels_, pat::TriggerObjectStandAlone::addPathName(), edm::InputTag::encode(), edm::Event::getByLabel(), hltConfig_, edm::Handle< T >::isValid(), bookConverter::keys, HLTConfigProvider::moduleIndex(), HLTConfigProvider::moduleLabel(), HLTConfigProvider::moduleType(), nameProcess_, onlyStandAlone_, edm::Event::put(), pat::TriggerFilter::setStatus(), pat::TriggerFilter::setType(), HLTConfigProvider::size(), tagTriggerEvent_, tagTriggerResults_, HLTConfigProvider::triggerIndex(), and HLTConfigProvider::triggerName().

00048 {
00049   if ( hltConfig_.size() <= 0 ) {
00050     edm::LogError( "errorHltConfigSize" ) << "HLT config size error" << "\n"
00051                                           << "Check for occurence of an \"errorHltConfigExtraction\" from beginRun()";
00052     return;
00053   }
00054   edm::Handle< edm::TriggerResults > handleTriggerResults;
00055   iEvent.getByLabel( tagTriggerResults_, handleTriggerResults );
00056   if ( ! handleTriggerResults.isValid() ) {
00057     edm::LogError( "errorTriggerResultsValid" ) << "edm::TriggerResults product with InputTag " << tagTriggerResults_.encode() << " not in event";
00058     return;
00059   }
00060   edm::Handle< trigger::TriggerEvent > handleTriggerEvent;
00061   iEvent.getByLabel( tagTriggerEvent_, handleTriggerEvent );
00062   if ( ! handleTriggerEvent.isValid() ) {
00063     edm::LogError( "errorTriggerEventValid" ) << "trigger::TriggerEvent product with InputTag " << tagTriggerEvent_.encode() << " not in event";
00064     return;
00065   }
00066 
00067   // produce trigger paths and determine status of modules
00068   
00069   const unsigned sizePaths( hltConfig_.size() );
00070   const unsigned sizeFilters( handleTriggerEvent->sizeFilters() );
00071   const unsigned sizeObjects( handleTriggerEvent->sizeObjects() );
00072     
00073   std::auto_ptr< TriggerPathCollection > triggerPaths( new TriggerPathCollection() );
00074   triggerPaths->reserve( onlyStandAlone_ ? 0 : sizePaths );
00075   std::map< std::string, int > moduleStates;
00076   std::multimap< std::string, std::string > filterPaths;
00077   
00078   for ( unsigned iP = 0; iP < sizePaths; ++iP ) {
00079     const std::string namePath( hltConfig_.triggerName( iP ) );
00080     const unsigned indexPath( hltConfig_.triggerIndex( namePath ) );
00081     const unsigned sizeModules( hltConfig_.size( namePath ) );
00082     for ( unsigned iM = 0; iM < sizeModules; ++iM ) {
00083       const std::string nameModule( hltConfig_.moduleLabel( indexPath, iM ) );
00084       const unsigned indexFilter( handleTriggerEvent->filterIndex( edm::InputTag( nameModule, "", nameProcess_ ) ) );
00085       if ( indexFilter < sizeFilters ) {
00086         filterPaths.insert( std::pair< std::string, std::string >( nameModule, namePath ) );
00087       }
00088     }
00089     if ( ! onlyStandAlone_ ) {
00090       const unsigned indexLastFilter( handleTriggerResults->index( indexPath ) );
00091       TriggerPath triggerPath( namePath, indexPath, 0, handleTriggerResults->wasrun( indexPath ), handleTriggerResults->accept( indexPath ), handleTriggerResults->error( indexPath ), indexLastFilter );
00092       // add module names to path and states' map
00093       assert( indexLastFilter < sizeModules );
00094       std::map< unsigned, std::string > indicesModules;
00095       for ( unsigned iM = 0; iM < sizeModules; ++iM ) {
00096         const std::string nameModule( hltConfig_.moduleLabel( indexPath, iM ) );
00097         if ( addPathModuleLabels_ ) {
00098           triggerPath.addModule( nameModule );
00099         }
00100         const unsigned indexFilter( handleTriggerEvent->filterIndex( edm::InputTag( nameModule, "", nameProcess_ ) ) );
00101         if ( indexFilter < sizeFilters ) {
00102           triggerPath.addFilterIndex( indexFilter );
00103         }
00104         const unsigned slotModule( hltConfig_.moduleIndex( indexPath, nameModule ) ); 
00105         indicesModules.insert( std::pair< unsigned, std::string >( slotModule, nameModule ) );
00106       }
00107       // store path
00108       triggerPaths->push_back( triggerPath );
00109       // store module states to be used for the filters
00110       for ( std::map< unsigned, std::string >::const_iterator iM = indicesModules.begin(); iM != indicesModules.end(); ++iM ) {
00111         if ( iM->first < indexLastFilter ) {
00112           moduleStates[ iM->second ] = 1;
00113         } else if ( iM->first == indexLastFilter ) {
00114           moduleStates[ iM->second ] = handleTriggerResults->accept( indexPath );
00115         } else if ( moduleStates.find( iM->second ) == moduleStates.end() ) {
00116           moduleStates[ iM->second ] = -1;
00117         }
00118       }
00119     }
00120   }
00121   
00122   if ( ! onlyStandAlone_ ) {
00123     iEvent.put( triggerPaths );
00124   }
00125   
00126   // produce trigger filters and store used trigger object types
00127   // (only last active filter(s) available from trigger::TriggerEvent)
00128   
00129   std::auto_ptr< TriggerFilterCollection > triggerFilters( new TriggerFilterCollection() );
00130   triggerFilters->reserve( onlyStandAlone_ ? 0 : sizeFilters );
00131   std::multimap< trigger::size_type, int >         filterIds;
00132   std::multimap< trigger::size_type, std::string > filterLabels;
00133   
00134   for ( unsigned iF = 0; iF < sizeFilters; ++iF ) {
00135     const std::string nameFilter( handleTriggerEvent->filterTag( iF ).label() );
00136     const trigger::Keys & keys = handleTriggerEvent->filterKeys( iF );
00137     const trigger::Vids & ids  = handleTriggerEvent->filterIds( iF );   
00138     assert( ids.size() == keys.size() );
00139     for ( unsigned iK = 0; iK < keys.size(); ++iK ) {
00140       filterLabels.insert( std::pair< trigger::size_type, std::string >( keys[ iK ], nameFilter ) ); // only for objects used in last active filter
00141       filterIds.insert( std::pair< trigger::size_type, int >( keys[ iK ], ids[ iK ] ) );             // only for objects used in last active filter
00142     }
00143     if ( ! onlyStandAlone_ ) {
00144       TriggerFilter triggerFilter( nameFilter );
00145       // set filter type
00146       const std::string typeFilter( hltConfig_.moduleType( nameFilter ) );
00147       triggerFilter.setType( typeFilter );
00148       // set filter IDs of used objects
00149       for ( unsigned iK = 0; iK < keys.size(); ++iK ) {
00150         triggerFilter.addObjectKey( keys[ iK ] );
00151       }
00152       for ( unsigned iI = 0; iI < ids.size(); ++iI ) {
00153         triggerFilter.addObjectId( ids[ iI ] );
00154       }
00155     // set status from path info
00156       std::map< std::string, int >::iterator iS( moduleStates.find( nameFilter ) );
00157       if ( iS != moduleStates.end() ) {
00158         if ( ! triggerFilter.setStatus( iS->second ) ) {
00159           triggerFilter.setStatus( -1 ); // different code for "unvalid status determined" needed?
00160         }
00161       } else {
00162         triggerFilter.setStatus( -1 ); // different code for "unknown" needed?
00163       }
00164       // store filter
00165       triggerFilters->push_back( triggerFilter );
00166     }
00167     // store used trigger object types to be used with the objects
00168   }
00169 
00170   if ( ! onlyStandAlone_ ) {
00171     iEvent.put( triggerFilters );
00172   }
00173   
00174   // produce trigger objects
00175   
00176   std::auto_ptr< TriggerObjectCollection > triggerObjects( new TriggerObjectCollection() );
00177   triggerObjects->reserve( onlyStandAlone_ ? 0 : sizeObjects );
00178   std::auto_ptr< TriggerObjectStandAloneCollection > triggerObjectsStandAlone( new TriggerObjectStandAloneCollection() );
00179   triggerObjectsStandAlone->reserve( sizeObjects );
00180   
00181   const trigger::Keys & collectionKeys( handleTriggerEvent->collectionKeys() );
00182   for ( unsigned iO = 0, iC = 0; iO < sizeObjects && iC < handleTriggerEvent->sizeCollections(); ++iO ) {
00183     TriggerObject triggerObject( handleTriggerEvent->getObjects().at( iO ) );
00184     // set collection
00185     while ( iO >= collectionKeys[ iC ] ) {
00186       ++iC;
00187     } // relies on well ordering of trigger objects with respect to the collections
00188     triggerObject.setCollection( handleTriggerEvent->collectionTag( iC ).encode() );
00189     // set filter ID
00190     for ( std::multimap< trigger::size_type, int >::iterator iM = filterIds.begin(); iM != filterIds.end(); ++iM ) {
00191       if ( iM->first == iO && ! triggerObject.hasFilterId( iM->second ) ) {
00192         triggerObject.addFilterId( iM->second );
00193       }
00194     }
00195     if ( ! onlyStandAlone_ ) {
00196       triggerObjects->push_back( triggerObject );
00197     }
00198     // stand-alone trigger object
00199     TriggerObjectStandAlone triggerObjectStandAlone( triggerObject );
00200     for ( std::multimap< trigger::size_type, std::string >::iterator iM = filterLabels.begin(); iM != filterLabels.end(); ++iM ) {
00201       if ( iM->first == iO ) {
00202         for ( std::multimap< std::string, std::string >::iterator iP = filterPaths.begin(); iP != filterPaths.end(); ++iP ) {
00203           if ( iP->first == iM->second ) {
00204             triggerObjectStandAlone.addPathName( iP->second );
00205             break;
00206           }
00207         }
00208         triggerObjectStandAlone.addFilterLabel( iM->second );
00209         break;
00210       }
00211     }
00212     
00213     triggerObjectsStandAlone->push_back( triggerObjectStandAlone );
00214   }
00215   
00216   if ( ! onlyStandAlone_ ) {
00217     iEvent.put( triggerObjects );
00218   }
00219   iEvent.put( triggerObjectsStandAlone );
00220 }


Member Data Documentation

bool pat::PATTriggerProducer::addPathModuleLabels_ [private]

Definition at line 66 of file PATTriggerProducer.h.

Referenced by produce().

HLTConfigProvider pat::PATTriggerProducer::hltConfig_ [private]

Definition at line 59 of file PATTriggerProducer.h.

Referenced by beginRun(), and produce().

std::string pat::PATTriggerProducer::nameProcess_ [private]

Definition at line 60 of file PATTriggerProducer.h.

Referenced by beginRun(), PATTriggerProducer(), and produce().

bool pat::PATTriggerProducer::onlyStandAlone_ [private]

Definition at line 63 of file PATTriggerProducer.h.

Referenced by PATTriggerProducer(), and produce().

edm::InputTag pat::PATTriggerProducer::tagTriggerEvent_ [private]

Definition at line 62 of file PATTriggerProducer.h.

Referenced by PATTriggerProducer(), and produce().

edm::InputTag pat::PATTriggerProducer::tagTriggerResults_ [private]

Definition at line 61 of file PATTriggerProducer.h.

Referenced by PATTriggerProducer(), and produce().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:49:44 2009 for CMSSW by  doxygen 1.5.4