Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-24 02:52:17

0001 #ifndef L1COMPARATOR_H
0002 #define L1COMPARATOR_H
0003 
0004 /*\class L1Comparator
0005  *\description L1 trigger data|emulation comparison and validation
0006  *\author Nuno Leonardo (CERN)
0007  *\date 07.02
0008  */
0009 
0010 // common/system includes
0011 #include <memory>
0012 #include <string>
0013 #include <iostream>
0014 #include <fstream>
0015 #include <iomanip>
0016 #include <vector>
0017 #include <algorithm>
0018 #include <atomic>
0019 #include "FWCore/ServiceRegistry/interface/Service.h"
0020 #include "FWCore/Framework/interface/Frameworkfwd.h"
0021 #include "FWCore/Framework/interface/global/EDProducer.h"
0022 #include "FWCore/Framework/interface/Event.h"
0023 #include "FWCore/Framework/interface/MakerMacros.h"
0024 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0025 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0026 #include "FWCore/Utilities/interface/EDGetToken.h"
0027 #include "FWCore/Utilities/interface/ESGetToken.h"
0028 
0029 // l1 dataformats, d|e record includes
0030 #include "L1Trigger/HardwareValidation/interface/DEtrait.h"
0031 
0032 // comparator template
0033 #include "L1Trigger/HardwareValidation/interface/DEcompare.h"
0034 
0035 // db trigger/subsystem key access
0036 #include "CondFormats/L1TObjects/interface/L1TriggerKey.h"
0037 //#include "CondFormats/L1TObjects/interface/L1TriggerKeyList.h"
0038 #include "CondFormats/DataRecord/interface/L1TriggerKeyRcd.h"
0039 //#include "CondFormats/DataRecord/interface/L1TriggerKeyListRcd.h"
0040 
0041 template <class T>
0042 class DEcompare;
0043 
0044 class L1Comparator : public edm::global::EDProducer<edm::RunCache<std::array<bool, dedefs::DEnsys>>> {
0045 public:
0046   explicit L1Comparator(const edm::ParameterSet&);
0047 
0048 private:
0049   using RunCache = std::array<bool, dedefs::DEnsys>;
0050   std::shared_ptr<RunCache> globalBeginRun(edm::Run const&, const edm::EventSetup&) const final;
0051   void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0052   void globalEndRun(edm::Run const&, edm::EventSetup const&) const final {}
0053   void endJob() override;
0054 
0055   struct EventInfo {
0056     L1DEDigiCollection m_dedigis;
0057     std::array<bool, dedefs::DEnsys> DEmatchEvt = {{true}};
0058     std::array<std::array<int, 2>, dedefs::DEnsys> DEncand = {{{{0, 0}}}};
0059     std::ostringstream dumpToFile_;
0060     int nevt_;
0061     int evtNum_;
0062     int runNum_;
0063     //flag whether event id has already been written to dumpFile
0064     bool dumpEvent_ = true;
0065   };
0066 
0067   template <class T>
0068   void process(T const*, T const*, const int, const int, EventInfo& eventInfo) const;
0069   template <class T>
0070   void process(
0071       const edm::Handle<T> data, const edm::Handle<T> emul, const int sys, const int cid, EventInfo& eventInfo) const {
0072     if (data.isValid() && emul.isValid())
0073       process(data.product(), emul.product(), sys, cid, eventInfo);
0074   }
0075 
0076   template <class T>
0077   bool CompareCollections(edm::Handle<T> data, edm::Handle<T> emul, std::ostream&) const;
0078   template <class T>
0079   bool dumpCandidate(const T& dt, const T& em, std::ostream& s) const;
0080 
0081   int verbose() const { return verbose_; }
0082   const bool m_stage1_layer2_;
0083 
0084 private:
0085   mutable std::atomic<int> nevt_;
0086   const int verbose_;
0087 
0088   edm::EDGetTokenT<L1CaloEmCollection> tokenCaloEm_[2];
0089   edm::EDGetTokenT<L1CaloRegionCollection> tokenCaloRegion_[2];
0090   edm::EDGetTokenT<L1GctEmCandCollection> tokenGctEmCand_isoEm_[2];
0091   edm::EDGetTokenT<L1GctEmCandCollection> tokenGctEmCand_nonIsoEm_[2];
0092   edm::EDGetTokenT<L1GctJetCandCollection> tokenGctJetCand_cenJets_[2];
0093   edm::EDGetTokenT<L1GctJetCandCollection> tokenGctJetCand_forJets_[2];
0094   edm::EDGetTokenT<L1GctJetCandCollection> tokenGctJetCand_tauJets_[2];
0095   edm::EDGetTokenT<L1GctJetCandCollection> tokenGctJetCand_isoTauJets_[2];
0096   edm::EDGetTokenT<L1GctEtTotalCollection> tokenGctEtTotal_[2];
0097   edm::EDGetTokenT<L1GctEtHadCollection> tokenGctEtHad_[2];
0098   edm::EDGetTokenT<L1GctEtMissCollection> tokenGctEtMiss_[2];
0099   edm::EDGetTokenT<L1GctHFRingEtSumsCollection> tokenGctHFRingEtSums_[2];
0100   edm::EDGetTokenT<L1GctHFBitCountsCollection> tokenGctHFBitCounts_[2];
0101   edm::EDGetTokenT<L1GctHtMissCollection> tokenGctHtMiss_[2];
0102   edm::EDGetTokenT<L1GctJetCountsCollection> tokenGctJetCounts_[2];
0103   edm::EDGetTokenT<L1MuDTChambPhContainer> tokenMuDTChambPh_[2];
0104   edm::EDGetTokenT<L1MuDTChambThContainer> tokenMuDTChambTh_[2];
0105   edm::EDGetTokenT<LTCDigiCollection> tokenLTCDigi_[2];
0106   edm::EDGetTokenT<L1MuDTTrackContainer> tokenMuDTTrack_[2];
0107   edm::EDGetTokenT<L1MuRegionalCandCollection> tokenMuRegionalCandRPCb_[2];
0108   edm::EDGetTokenT<L1MuRegionalCandCollection> tokenMuRegionalCandRPCf_[2];
0109   edm::EDGetTokenT<L1MuGMTCandCollection> tokenMuGMTCand_[2];
0110   edm::EDGetTokenT<L1MuGMTReadoutCollection> tokenMuReadoutCand_[2];
0111 
0112   const edm::ESGetToken<L1TriggerKey, L1TriggerKeyRcd> tokenTriggerKey_;
0113 
0114   const std::array<bool, dedefs::DEnsys> m_doSys;
0115   const std::string m_dumpFileName;
0116   CMS_THREAD_GUARD(m_fileGuard) mutable std::ofstream m_dumpFile;
0117   const int m_dumpMode;
0118   mutable std::mutex m_fileGuard;
0119   mutable std::atomic<bool> m_match;
0120 };
0121 
0122 #endif