Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:19:47

0001 #include <memory>
0002 #include "L1Trigger/DTTriggerPhase2/interface/MPRedundantFilter.h"
0003 
0004 using namespace edm;
0005 using namespace std;
0006 using namespace cmsdt;
0007 
0008 // ============================================================================
0009 // Constructors and destructor
0010 // ============================================================================
0011 MPRedundantFilter::MPRedundantFilter(const ParameterSet& pset)
0012     : MPFilter(pset), debug_(pset.getUntrackedParameter<bool>("debug")), maxBufferSize_(8) {}
0013 
0014 MPRedundantFilter::~MPRedundantFilter() {}
0015 
0016 // ============================================================================
0017 // Main methods (initialise, run, finish)
0018 // ============================================================================
0019 void MPRedundantFilter::initialise(const edm::EventSetup& iEventSetup) { buffer_.clear(); }
0020 
0021 void MPRedundantFilter::run(edm::Event& iEvent,
0022                             const edm::EventSetup& iEventSetup,
0023                             MuonPathPtrs& inMPaths,
0024                             MuonPathPtrs& outMPaths) {
0025   buffer_.clear();
0026   for (auto muonpath = inMPaths.begin(); muonpath != inMPaths.end(); ++muonpath) {
0027     filter(*muonpath, outMPaths);
0028   }
0029   buffer_.clear();
0030 }
0031 
0032 void MPRedundantFilter::filter(MuonPathPtr& mPath, MuonPathPtrs& outMPaths) {
0033   if (mPath == nullptr)
0034     return;
0035 
0036   if (!isInBuffer(mPath)) {
0037     // Remove the first element (the oldest)
0038     if (buffer_.size() == maxBufferSize_)
0039       buffer_.pop_front();
0040     // Insert last path as new element
0041     buffer_.push_back(mPath);
0042 
0043     // Send a copy
0044     auto mpAux = std::make_shared<MuonPath>(mPath);
0045     outMPaths.push_back(mpAux);
0046   }
0047 }
0048 
0049 bool MPRedundantFilter::isInBuffer(MuonPathPtr& mPath) {
0050   bool ans = false;
0051 
0052   if (!buffer_.empty()) {
0053     for (unsigned int i = 0; i < buffer_.size(); i++)
0054       if (mPath->isEqualTo((MuonPath*)buffer_.at(i).get())) {
0055         ans = true;
0056         break;
0057       }
0058   }
0059   return ans;
0060 }