Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-28 23:48:18

0001 #include <memory>
0002 #include <sstream>
0003 
0004 #include "FWCore/Framework/interface/Frameworkfwd.h"
0005 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0006 
0007 #include "FWCore/Framework/interface/Event.h"
0008 #include "FWCore/Framework/interface/MakerMacros.h"
0009 #include "FWCore/Framework/interface/EventSetup.h"
0010 #include "FWCore/Framework/interface/ESHandle.h"
0011 
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 
0014 #include "CondFormats/L1TObjects/interface/L1TriggerKey.h"
0015 #include "CondFormats/L1TObjects/interface/L1TriggerKeyExt.h"
0016 #include "CondFormats/L1TObjects/interface/L1TriggerKeyListExt.h"
0017 #include "CondFormats/DataRecord/interface/L1TriggerKeyRcd.h"
0018 #include "CondFormats/DataRecord/interface/L1TriggerKeyExtRcd.h"
0019 #include "CondFormats/DataRecord/interface/L1TriggerKeyListExtRcd.h"
0020 
0021 #include "CondTools/L1Trigger/interface/Exception.h"
0022 #include "CondTools/L1TriggerExt/interface/DataWriterExt.h"
0023 
0024 //
0025 // class decleration
0026 //
0027 
0028 class L1O2OTestAnalyzerExt : public edm::one::EDAnalyzer<> {
0029 public:
0030   explicit L1O2OTestAnalyzerExt(const edm::ParameterSet&);
0031   ~L1O2OTestAnalyzerExt() override;
0032 
0033 private:
0034   void beginJob() override;
0035   void analyze(const edm::Event&, const edm::EventSetup&) override;
0036   void endJob() override;
0037 
0038   // ----------member data ---------------------------
0039   bool m_printL1TriggerKeyExt;
0040   bool m_printL1TriggerKeyListExt;
0041   bool m_printESRecords;
0042   bool m_printPayloadTokens;
0043   std::vector<std::string> m_recordsToPrint;
0044   edm::ESGetToken<L1TriggerKeyExt, L1TriggerKeyExtRcd> l1TriggerKeyExtToken_;
0045 };
0046 
0047 L1O2OTestAnalyzerExt::L1O2OTestAnalyzerExt(const edm::ParameterSet& iConfig)
0048     : m_printL1TriggerKeyExt(iConfig.getParameter<bool>("printL1TriggerKeyExt")),
0049       m_printL1TriggerKeyListExt(iConfig.getParameter<bool>("printL1TriggerKeyListExt")),
0050       m_printESRecords(iConfig.getParameter<bool>("printESRecords")),
0051       m_printPayloadTokens(iConfig.getParameter<bool>("printPayloadTokens")),
0052       m_recordsToPrint(iConfig.getParameter<std::vector<std::string> >("recordsToPrint")) {
0053   //now do what ever initialization is needed
0054   l1TriggerKeyExtToken_ = esConsumes();
0055 }
0056 
0057 L1O2OTestAnalyzerExt::~L1O2OTestAnalyzerExt() {
0058   // do anything here that needs to be done at desctruction time
0059   // (e.g. close files, deallocate resources etc.)
0060 }
0061 
0062 // ------------ method called to for each event  ------------
0063 void L1O2OTestAnalyzerExt::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0064   using namespace edm;
0065 
0066   if (m_printL1TriggerKeyListExt) {
0067     //        ESHandle< L1TriggerKeyListExt > pList ;
0068     //        iSetup.get< L1TriggerKeyListExtRcd >().get( pList ) ;
0069     L1TriggerKeyListExt pList;
0070     l1t::DataWriterExt dataWriter;
0071     if (!dataWriter.fillLastTriggerKeyList(pList)) {
0072       edm::LogError("L1-O2O") << "Problem getting last L1TriggerKeyListExt";
0073     }
0074 
0075     edm::LogInfo("L1-O2O") << "Found " << pList.tscKeyToTokenMap().size() << " TSC keys:";
0076 
0077     L1TriggerKeyListExt::KeyToToken::const_iterator iTSCKey = pList.tscKeyToTokenMap().begin();
0078     L1TriggerKeyListExt::KeyToToken::const_iterator eTSCKey = pList.tscKeyToTokenMap().end();
0079     for (; iTSCKey != eTSCKey; ++iTSCKey) {
0080       edm::LogInfo("L1-O2O") << iTSCKey->first;
0081       if (m_printPayloadTokens) {
0082         edm::LogInfo("L1-O2O") << " " << iTSCKey->second;
0083       }
0084     }
0085 
0086     L1TriggerKeyListExt::RecordToKeyToToken::const_iterator iRec = pList.recordTypeToKeyToTokenMap().begin();
0087     L1TriggerKeyListExt::RecordToKeyToToken::const_iterator eRec = pList.recordTypeToKeyToTokenMap().end();
0088     for (; iRec != eRec; ++iRec) {
0089       const L1TriggerKeyListExt::KeyToToken& keyTokenMap = iRec->second;
0090       edm::LogInfo("L1-O2O") << "For record@type " << iRec->first << ", found " << keyTokenMap.size() << " keys:";
0091 
0092       L1TriggerKeyListExt::KeyToToken::const_iterator iKey = keyTokenMap.begin();
0093       L1TriggerKeyListExt::KeyToToken::const_iterator eKey = keyTokenMap.end();
0094       for (; iKey != eKey; ++iKey) {
0095         edm::LogInfo("L1-O2O") << iKey->first;
0096         if (m_printPayloadTokens) {
0097           edm::LogInfo("L1-O2O") << " " << iKey->second;
0098         }
0099       }
0100     }
0101   }
0102 
0103   if (m_printL1TriggerKeyExt) {
0104     try {
0105       ESHandle<L1TriggerKeyExt> pKey = iSetup.getHandle(l1TriggerKeyExtToken_);
0106 
0107       edm::LogInfo("L1-O2O") << "Current TSC key = " << pKey->tscKey();
0108 
0109       edm::LogInfo("L1-O2O") << "Current subsystem keys:";
0110       edm::LogInfo("L1-O2O") << "TSP0 " << pKey->subsystemKey(L1TriggerKeyExt::kuGT);
0111 
0112       edm::LogInfo("L1-O2O") << "Object keys:";
0113       const L1TriggerKeyExt::RecordToKey& recKeyMap = pKey->recordToKeyMap();
0114       L1TriggerKeyExt::RecordToKey::const_iterator iRec = recKeyMap.begin();
0115       L1TriggerKeyExt::RecordToKey::const_iterator eRec = recKeyMap.end();
0116       for (; iRec != eRec; ++iRec) {
0117         edm::LogInfo("L1-O2O") << iRec->first << " " << iRec->second;
0118       }
0119     } catch (cms::Exception& ex) {
0120       edm::LogInfo("L1-O2O") << "No L1TriggerKeyExt found.";
0121     }
0122   }
0123 
0124   if (m_printESRecords) {
0125     L1TriggerKeyListExt pList;
0126     l1t::DataWriterExt dataWriter;
0127     if (!dataWriter.fillLastTriggerKeyList(pList)) {
0128       edm::LogError("L1-O2O") << "Problem getting last L1TriggerKeyListExt";
0129     }
0130 
0131     // Start log string, convert run number into string
0132     unsigned long long run = iEvent.id().run();
0133     std::stringstream ss;
0134     ss << run;
0135     std::string log = "runNumber=" + ss.str();
0136 
0137     l1t::DataWriterExt writer;
0138 
0139     edm::LogInfo("L1-O2O") << "Run Settings keys:";
0140 
0141     std::vector<std::string>::const_iterator iRec = m_recordsToPrint.begin();
0142     std::vector<std::string>::const_iterator iEnd = m_recordsToPrint.end();
0143     for (; iRec != iEnd; ++iRec) {
0144       std::string payloadToken = writer.payloadToken(*iRec, iEvent.id().run());
0145       std::string key;
0146 
0147       if (*iRec == "L1TriggerKeyExtRcd") {
0148         key = pList.tscKey(payloadToken);
0149       } else {
0150         key = pList.objectKey(*iRec, payloadToken);
0151       }
0152 
0153       edm::LogInfo("L1-O2O") << *iRec << " " << key;
0154       if (m_printPayloadTokens) {
0155         edm::LogInfo("L1-O2O") << " " << payloadToken;
0156       }
0157 
0158       // Replace spaces in key with ?s.  Do reverse substitution when
0159       // making L1TriggerKeyExt.
0160       replace(key.begin(), key.end(), ' ', '?');
0161       log += " " + *iRec + "Key=" + key;
0162     }
0163 
0164     edm::LogInfo("L1-O2O") << log;
0165   }
0166 }
0167 
0168 // ------------ method called once each job just before starting event loop  ------------
0169 void L1O2OTestAnalyzerExt::beginJob() {}
0170 
0171 // ------------ method called once each job just after ending the event loop  ------------
0172 void L1O2OTestAnalyzerExt::endJob() {}
0173 
0174 //define this as a plug-in
0175 DEFINE_FWK_MODULE(L1O2OTestAnalyzerExt);