Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:18:41

0001 // -*- C++ -*-
0002 //
0003 // Package:    HLTL1NumberFilter
0004 // Class:      HLTL1NumberFilter
0005 //
0006 /**\class HLTL1NumberFilter HLTL1NumberFilter.cc filter/HLTL1NumberFilter/src/HLTL1NumberFilter.cc
0007 
0008 Description:
0009 
0010 Implementation:
0011 <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Martin Grunewald
0015 //         Created:  Tue Jan 22 13:55:00 CET 2008
0016 //
0017 //
0018 
0019 // system include files
0020 #include <string>
0021 #include <iostream>
0022 #include <memory>
0023 
0024 // user include files
0025 #include "HLTL1NumberFilter.h"
0026 #include "DataFormats/Common/interface/Handle.h"
0027 #include "DataFormats/FEDRawData/interface/FEDHeader.h"
0028 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0029 #include "DataFormats/TCDS/interface/TCDSRecord.h"
0030 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0031 
0032 //
0033 // constructors and destructor
0034 //
0035 HLTL1NumberFilter::HLTL1NumberFilter(const edm::ParameterSet& config)
0036     :  //now do what ever initialization is needed
0037       inputToken_(consumes<FEDRawDataCollection>(config.getParameter<edm::InputTag>("rawInput"))),
0038       period_(config.getParameter<unsigned int>("period")),
0039       fedId_(config.getParameter<int>("fedId")),
0040       invert_(config.getParameter<bool>("invert")),
0041       // only try and use TCDS event number if the FED ID 1024 is selected
0042       useTCDS_(config.getParameter<bool>("useTCDSEventNumber") and fedId_ == 1024) {}
0043 
0044 HLTL1NumberFilter::~HLTL1NumberFilter() {
0045   // do anything here that needs to be done at desctruction time
0046   // (e.g. close files, deallocate resources etc.)
0047 }
0048 
0049 void HLTL1NumberFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0050   edm::ParameterSetDescription desc;
0051   desc.add<edm::InputTag>("rawInput", edm::InputTag("source"));
0052   desc.add<unsigned int>("period", 4096);
0053   desc.add<bool>("invert", true);
0054   desc.add<int>("fedId", 812);
0055   desc.add<bool>("useTCDSEventNumber", false);
0056   descriptions.add("hltL1NumberFilter", desc);
0057 }
0058 //
0059 // member functions
0060 //
0061 
0062 // ------------ method called on each new Event  ------------
0063 bool HLTL1NumberFilter::filter(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0064   using namespace edm;
0065 
0066   if (iEvent.isRealData()) {
0067     bool accept(false);
0068     edm::Handle<FEDRawDataCollection> theRaw;
0069     iEvent.getByToken(inputToken_, theRaw);
0070     const FEDRawData& data = theRaw->FEDData(fedId_);
0071     if (data.data() and data.size() > 0) {
0072       unsigned long counter;
0073       if (useTCDS_) {
0074         TCDSRecord record(data.data());
0075         counter = record.getTriggerCount();
0076       } else {
0077         FEDHeader header(data.data());
0078         counter = header.lvl1ID();
0079       }
0080       if (period_ != 0)
0081         accept = (counter % period_ == 0);
0082       if (invert_)
0083         accept = not accept;
0084       return accept;
0085     } else {
0086       LogWarning("HLTL1NumberFilter") << "No valid data for FED " << fedId_ << " used by HLTL1NumberFilter";
0087       return false;
0088     }
0089   } else {
0090     return true;
0091   }
0092 }
0093 
0094 // declare this class as a framework plugin
0095 #include "FWCore/Framework/interface/MakerMacros.h"
0096 DEFINE_FWK_MODULE(HLTL1NumberFilter);