CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/HLTrigger/HLTfilters/src/HLTLevel1Activity.cc

Go to the documentation of this file.
00001 
00018 #include <vector>
00019 
00020 #include "FWCore/Framework/interface/ESWatcher.h"
00021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00022 #include "FWCore/Utilities/interface/InputTag.h"
00023 #include "CondFormats/DataRecord/interface/L1GtTriggerMaskTechTrigRcd.h"
00024 #include "CondFormats/DataRecord/interface/L1GtTriggerMaskAlgoTrigRcd.h"
00025 #include "HLTrigger/HLTcore/interface/HLTFilter.h"
00026 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
00027 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
00028 
00029 // FIXME: these should come form the L1 configuration at runtime
00030 #define PHYSICS_BITS_SIZE    128
00031 #define TECHNICAL_BITS_SIZE   64
00032 
00033 //
00034 // class declaration
00035 //
00036 
00037 class HLTLevel1Activity : public HLTFilter {
00038 public:
00039   explicit HLTLevel1Activity(const edm::ParameterSet&);
00040   ~HLTLevel1Activity();
00041   static void fillDescriptions(edm::ConfigurationDescriptions & descriptions);
00042   virtual bool filter(edm::Event&, const edm::EventSetup&);
00043 
00044 private:
00045   edm::InputTag     m_gtReadoutRecord;
00046   std::vector<int>  m_bunchCrossings;
00047   std::vector<bool> m_selectPhysics;
00048   std::vector<bool> m_selectTechnical;
00049   std::vector<bool> m_maskedPhysics;
00050   std::vector<bool> m_maskedTechnical;
00051   unsigned int      m_daqPartitions;
00052   bool              m_ignoreL1Mask;
00053   bool              m_invert;
00054 
00055   edm::ESWatcher<L1GtTriggerMaskAlgoTrigRcd> m_watchPhysicsMask;
00056   edm::ESWatcher<L1GtTriggerMaskTechTrigRcd> m_watchTechnicalMask;
00057 };
00058 
00059 #include <boost/foreach.hpp>
00060 
00061 #include "FWCore/Framework/interface/EventSetup.h"
00062 #include "FWCore/Framework/interface/ESHandle.h"
00063 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00064 #include "CondFormats/L1TObjects/interface/L1GtTriggerMask.h"
00065 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
00066 
00067 //
00068 // constructors and destructor
00069 //
00070 HLTLevel1Activity::HLTLevel1Activity(const edm::ParameterSet & config) :
00071   m_gtReadoutRecord( config.getParameter<edm::InputTag>     ("L1GtReadoutRecordTag") ),
00072   m_bunchCrossings(  config.getParameter<std::vector<int> > ("bunchCrossings") ),
00073   m_selectPhysics(   PHYSICS_BITS_SIZE ),
00074   m_selectTechnical( TECHNICAL_BITS_SIZE ),
00075   m_maskedPhysics(   PHYSICS_BITS_SIZE ),
00076   m_maskedTechnical( TECHNICAL_BITS_SIZE ),
00077   m_daqPartitions(   config.getParameter<unsigned int>      ("daqPartitions") ),
00078   m_ignoreL1Mask(    config.getParameter<bool>              ("ignoreL1Mask") ),
00079   m_invert(          config.getParameter<bool>              ("invert") )
00080 {
00081   unsigned long long low  = config.getParameter<unsigned long long>("physicsLoBits");
00082   unsigned long long high = config.getParameter<unsigned long long>("physicsHiBits");
00083   unsigned long long tech = config.getParameter<unsigned long long>("technicalBits");
00084   for (unsigned int i = 0; i < 64; i++) {
00085     m_selectPhysics[i]    = low  & (0x01ULL << (unsigned long long) i);
00086     m_maskedPhysics[i]    = low  & (0x01ULL << (unsigned long long) i);
00087   }
00088   for (unsigned int i = 0; i < 64; i++) {
00089     m_selectPhysics[i+64] = high & (0x01ULL << (unsigned long long) i);
00090     m_maskedPhysics[i+64] = high & (0x01ULL << (unsigned long long) i);
00091   }
00092   for (unsigned int i = 0; i < 64; i++) {
00093     m_selectTechnical[i]  = tech & (0x01ULL << (unsigned long long) i);
00094     m_maskedTechnical[i]  = tech & (0x01ULL << (unsigned long long) i);
00095   }
00096 }
00097 
00098 HLTLevel1Activity::~HLTLevel1Activity()
00099 {
00100 }
00101 
00102 void
00103 HLTLevel1Activity::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
00104   edm::ParameterSetDescription desc;
00105   desc.add<edm::InputTag>("L1GtReadoutRecordTag",edm::InputTag("hltGtDigis"));
00106   {
00107     std::vector<int> temp1;
00108     temp1.reserve(3);
00109     temp1.push_back(0);
00110     temp1.push_back(-1);
00111     temp1.push_back(1);
00112     desc.add<std::vector<int> >("bunchCrossings",temp1);
00113   }
00114   desc.add<unsigned int>("daqPartitions",1);
00115   desc.add<bool>("ignoreL1Mask",false);
00116   desc.add<bool>("invert",false);
00117   desc.add<unsigned long long int>("physicsLoBits",1);
00118   desc.add<unsigned long long int>("physicsHiBits",262144);
00119   desc.add<unsigned long long int>("technicalBits",1);
00120   descriptions.add("hltLevel1Activity",desc);
00121 }
00122 
00123 //
00124 // member functions
00125 //
00126 
00127 // ------------ method called to produce the data  ------------
00128 bool
00129 HLTLevel1Activity::filter(edm::Event& event, const edm::EventSetup& setup)
00130 {
00131   // apply L1 mask to the physics bits
00132   //  - mask & partition == part. --> fully masked
00133   //  - mask & partition == 0x00  --> fully unmasked
00134   //  - mask & partition != part. --> unmasked in some partitions, consider as unmasked
00135   if (not m_ignoreL1Mask and m_watchPhysicsMask.check(setup)) {
00136     edm::ESHandle<L1GtTriggerMask> h_mask;
00137     setup.get<L1GtTriggerMaskAlgoTrigRcd>().get(h_mask);
00138     const std::vector<unsigned int> & mask = h_mask->gtTriggerMask();
00139     for (unsigned int i = 0; i < PHYSICS_BITS_SIZE; ++i)
00140       m_maskedPhysics[i] = m_selectPhysics[i] and ((mask[i] & m_daqPartitions) != m_daqPartitions);
00141   }
00142   
00143   // apply L1 mask to the technical bits
00144   //  - mask & partition == part. --> fully masked
00145   //  - mask & partition == 0x00  --> fully unmasked
00146   //  - mask & partition != part. --> unmasked in some partitions, consider as unmasked
00147   if (not m_ignoreL1Mask and m_watchTechnicalMask.check(setup)) {
00148     edm::ESHandle<L1GtTriggerMask> h_mask;
00149     setup.get<L1GtTriggerMaskTechTrigRcd>().get(h_mask);
00150     const std::vector<unsigned int> & mask = h_mask->gtTriggerMask();
00151     for (unsigned int i = 0; i < TECHNICAL_BITS_SIZE; ++i)
00152       m_maskedTechnical[i] = m_selectTechnical[i] and ((mask[i] & m_daqPartitions) != m_daqPartitions);
00153   }
00154 
00155   // access the L1 decisions
00156   edm::Handle<L1GlobalTriggerReadoutRecord> h_gtReadoutRecord;
00157   event.getByLabel(m_gtReadoutRecord, h_gtReadoutRecord);
00158 
00159   // compare the results with the requested bits, and return true as soon as the first match is found
00160   BOOST_FOREACH(int bx, m_bunchCrossings) {
00161     const std::vector<bool> & physics = h_gtReadoutRecord->decisionWord(bx);
00162     if (physics.size() != PHYSICS_BITS_SIZE)
00163       // error in L1 results
00164       return m_invert;
00165     for (unsigned int i = 0; i < PHYSICS_BITS_SIZE; ++i)
00166       if (m_maskedPhysics[i] and physics[i])
00167         return not m_invert;
00168     const std::vector<bool> & technical = h_gtReadoutRecord->technicalTriggerWord(bx);
00169     if (technical.size() != TECHNICAL_BITS_SIZE)
00170       // error in L1 results
00171       return m_invert;
00172     for (unsigned int i = 0; i < TECHNICAL_BITS_SIZE; ++i)
00173       if (m_maskedTechnical[i] and technical[i])
00174         return not m_invert;
00175   }
00176  
00177   return m_invert; 
00178 }
00179 
00180 // define as a framework plugin
00181 #include "FWCore/Framework/interface/MakerMacros.h"
00182 DEFINE_FWK_MODULE(HLTLevel1Activity);