CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/HLTrigger/HLTcore/src/TriggerExpressionData.cc

Go to the documentation of this file.
00001 #include <boost/shared_ptr.hpp>
00002 
00003 #include "FWCore/Framework/interface/Event.h"
00004 #include "FWCore/Framework/interface/EventSetup.h"
00005 #include "FWCore/Framework/interface/ESHandle.h"
00006 #include "FWCore/Common/interface/TriggerNames.h"
00007 #include "FWCore/Utilities/interface/Exception.h"
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009 #include "DataFormats/Common/interface/Handle.h"
00010 #include "DataFormats/Common/interface/TriggerResults.h"
00011 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
00012 #include "CondFormats/DataRecord/interface/L1GtTriggerMenuRcd.h"
00013 #include "CondFormats/DataRecord/interface/L1GtTriggerMaskAlgoTrigRcd.h"
00014 #include "CondFormats/DataRecord/interface/L1GtTriggerMaskTechTrigRcd.h"
00015 #include "CondFormats/L1TObjects/interface/L1GtTriggerMask.h"
00016 #include "CondFormats/L1TObjects/interface/L1GtTriggerMenu.h"
00017 #include "HLTrigger/HLTcore/interface/TriggerExpressionData.h"
00018 
00019 namespace triggerExpression {
00020 
00021 template <typename T>
00022 static 
00023 const T * get(const edm::Event & event, const edm::InputTag & tag) {
00024   edm::Handle<T> handle;
00025   event.getByLabel(tag, handle);
00026   if (not handle.isValid()) {
00027     boost::shared_ptr<cms::Exception> const & error = handle.whyFailed();
00028     edm::LogWarning(error->category()) << error->what();
00029     return 0;
00030   } else {
00031     return handle.product();
00032   }
00033 }
00034 
00035 template <typename R, typename T>
00036 static
00037 const T * get(const edm::EventSetup & setup) {
00038   edm::ESHandle<T> handle;
00039   setup.get<R>().get(handle);
00040   return handle.product();
00041 }
00042 
00043 bool Data::setEvent(const edm::Event & event, const edm::EventSetup & setup) {
00044 
00045   // cache the event number
00046   m_eventNumber = event.id().event();
00047 
00048   // access L1 objects only if L1 is used
00049   if (not m_l1tResultsTag.label().empty()) {
00050     // cache the L1 GT results objects
00051     m_l1tResults = get<L1GlobalTriggerReadoutRecord>(event, m_l1tResultsTag);
00052     if (not m_l1tResults)
00053       return false;
00054 
00055     // cache the L1 trigger masks
00056     m_l1tAlgoMask = get<L1GtTriggerMaskAlgoTrigRcd, L1GtTriggerMask>(setup);
00057     m_l1tTechMask = get<L1GtTriggerMaskTechTrigRcd, L1GtTriggerMask>(setup);
00058 
00059     // cache the L1 trigger menu
00060     unsigned long long l1tCacheID = setup.get<L1GtTriggerMenuRcd>().cacheIdentifier();
00061     if (m_l1tCacheID == l1tCacheID) {
00062       m_l1tUpdated = false;
00063     } else {
00064       m_l1tMenu = get<L1GtTriggerMenuRcd, L1GtTriggerMenu>(setup);
00065       (const_cast<L1GtTriggerMenu *>(m_l1tMenu))->buildGtConditionMap();
00066       m_l1tCacheID = l1tCacheID;
00067       m_l1tUpdated = true;
00068     }
00069   }
00070 
00071   // access HLT objects only if HLT is used
00072   if (not m_hltResultsTag.label().empty()) {
00073     // cache the HLT TriggerResults
00074     m_hltResults = get<edm::TriggerResults>(event, m_hltResultsTag);
00075     if (not m_hltResults)
00076       return false;
00077 
00078     // access the TriggerNames, and check if it has changed
00079     m_hltMenu = & event.triggerNames(* m_hltResults);
00080     if (m_hltMenu->parameterSetID() == m_hltCacheID) {
00081       m_hltUpdated = false;
00082     } else {
00083       m_hltCacheID = m_hltMenu->parameterSetID();
00084       m_hltUpdated = true;
00085     }
00086   }
00087 
00088   return true;
00089 }
00090 
00091 } // namespace triggerExpression