Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:12

0001 // -*- C++ -*-
0002 //
0003 // Package:    L1O2OTestAnalyzer
0004 // Class:      L1O2OTestAnalyzer
0005 //
0006 /**\class L1O2OTestAnalyzer L1O2OTestAnalyzer.cc CondTools/L1O2OTestAnalyzer/src/L1O2OTestAnalyzer.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Werner Man-Li Sun
0015 //         Created:  Thu Nov  6 23:00:43 CET 2008
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 #include <sstream>
0022 
0023 // user include files
0024 #include "FWCore/Framework/interface/Frameworkfwd.h"
0025 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0026 
0027 #include "FWCore/Framework/interface/Event.h"
0028 #include "FWCore/Framework/interface/MakerMacros.h"
0029 #include "FWCore/Framework/interface/EventSetup.h"
0030 #include "FWCore/Framework/interface/ESHandle.h"
0031 
0032 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0033 
0034 #include "CondFormats/L1TObjects/interface/L1TriggerKey.h"
0035 #include "CondFormats/L1TObjects/interface/L1TriggerKeyList.h"
0036 #include "CondFormats/DataRecord/interface/L1TriggerKeyRcd.h"
0037 #include "CondFormats/DataRecord/interface/L1TriggerKeyListRcd.h"
0038 
0039 #include "CondTools/L1Trigger/interface/Exception.h"
0040 #include "CondTools/L1Trigger/interface/DataWriter.h"
0041 
0042 //
0043 // class decleration
0044 //
0045 
0046 class L1O2OTestAnalyzer : public edm::one::EDAnalyzer<> {
0047 public:
0048   explicit L1O2OTestAnalyzer(const edm::ParameterSet&);
0049   ~L1O2OTestAnalyzer() override;
0050 
0051 private:
0052   void beginJob() override;
0053   void analyze(const edm::Event&, const edm::EventSetup&) override;
0054   void endJob() override;
0055 
0056   // ----------member data ---------------------------
0057   bool m_printL1TriggerKey;
0058   bool m_printL1TriggerKeyList;
0059   bool m_printESRecords;
0060   bool m_printPayloadTokens;
0061   std::vector<std::string> m_recordsToPrint;
0062   edm::ESGetToken<L1TriggerKey, L1TriggerKeyRcd> l1TriggerKeyToken_;
0063 };
0064 
0065 //
0066 // constants, enums and typedefs
0067 //
0068 
0069 //
0070 // static data member definitions
0071 //
0072 
0073 //
0074 // constructors and destructor
0075 //
0076 L1O2OTestAnalyzer::L1O2OTestAnalyzer(const edm::ParameterSet& iConfig)
0077     : m_printL1TriggerKey(iConfig.getParameter<bool>("printL1TriggerKey")),
0078       m_printL1TriggerKeyList(iConfig.getParameter<bool>("printL1TriggerKeyList")),
0079       m_printESRecords(iConfig.getParameter<bool>("printESRecords")),
0080       m_printPayloadTokens(iConfig.getParameter<bool>("printPayloadTokens")),
0081       m_recordsToPrint(iConfig.getParameter<std::vector<std::string> >("recordsToPrint")) {
0082   //now do what ever initialization is needed
0083   l1TriggerKeyToken_ = esConsumes();
0084 }
0085 
0086 L1O2OTestAnalyzer::~L1O2OTestAnalyzer() {
0087   // do anything here that needs to be done at desctruction time
0088   // (e.g. close files, deallocate resources etc.)
0089 }
0090 
0091 //
0092 // member functions
0093 //
0094 
0095 // ------------ method called to for each event  ------------
0096 void L1O2OTestAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0097   using namespace edm;
0098 
0099   if (m_printL1TriggerKeyList) {
0100     //        ESHandle< L1TriggerKeyList > pList ;
0101     //        iSetup.get< L1TriggerKeyListRcd >().get( pList ) ;
0102     L1TriggerKeyList pList;
0103     l1t::DataWriter dataWriter;
0104     if (!dataWriter.fillLastTriggerKeyList(pList)) {
0105       edm::LogError("L1-O2O") << "Problem getting last L1TriggerKeyList";
0106     }
0107 
0108     edm::LogInfo("L1-O2O") << "Found " << pList.tscKeyToTokenMap().size() << " TSC keys:" << std::endl;
0109 
0110     L1TriggerKeyList::KeyToToken::const_iterator iTSCKey = pList.tscKeyToTokenMap().begin();
0111     L1TriggerKeyList::KeyToToken::const_iterator eTSCKey = pList.tscKeyToTokenMap().end();
0112     for (; iTSCKey != eTSCKey; ++iTSCKey) {
0113       edm::LogInfo("L1-O2O") << iTSCKey->first;
0114       if (m_printPayloadTokens) {
0115         edm::LogInfo("L1-O2O") << " " << iTSCKey->second;
0116       }
0117       edm::LogInfo("L1-O2O") << std::endl;
0118     }
0119     edm::LogInfo("L1-O2O") << std::endl;
0120 
0121     L1TriggerKeyList::RecordToKeyToToken::const_iterator iRec = pList.recordTypeToKeyToTokenMap().begin();
0122     L1TriggerKeyList::RecordToKeyToToken::const_iterator eRec = pList.recordTypeToKeyToTokenMap().end();
0123     for (; iRec != eRec; ++iRec) {
0124       const L1TriggerKeyList::KeyToToken& keyTokenMap = iRec->second;
0125       edm::LogInfo("L1-O2O") << "For record@type " << iRec->first << ", found " << keyTokenMap.size()
0126                              << " keys:" << std::endl;
0127 
0128       L1TriggerKeyList::KeyToToken::const_iterator iKey = keyTokenMap.begin();
0129       L1TriggerKeyList::KeyToToken::const_iterator eKey = keyTokenMap.end();
0130       for (; iKey != eKey; ++iKey) {
0131         edm::LogInfo("L1-O2O") << iKey->first;
0132         if (m_printPayloadTokens) {
0133           edm::LogInfo("L1-O2O") << " " << iKey->second;
0134         }
0135         edm::LogInfo("L1-O2O") << std::endl;
0136       }
0137       edm::LogInfo("L1-O2O") << std::endl;
0138     }
0139   }
0140 
0141   if (m_printL1TriggerKey) {
0142     try {
0143       auto pKey = iSetup.getHandle(l1TriggerKeyToken_);
0144 
0145       edm::LogInfo("L1-O2O") << std::endl;
0146       edm::LogInfo("L1-O2O") << "Current TSC key = " << pKey->tscKey() << std::endl << std::endl;
0147 
0148       edm::LogInfo("L1-O2O") << "Current subsystem keys:" << std::endl;
0149       edm::LogInfo("L1-O2O") << "CSCTF " << pKey->subsystemKey(L1TriggerKey::kCSCTF) << std::endl;
0150       edm::LogInfo("L1-O2O") << "DTTF " << pKey->subsystemKey(L1TriggerKey::kDTTF) << std::endl;
0151       edm::LogInfo("L1-O2O") << "RPC " << pKey->subsystemKey(L1TriggerKey::kRPC) << std::endl;
0152       edm::LogInfo("L1-O2O") << "GMT " << pKey->subsystemKey(L1TriggerKey::kGMT) << std::endl;
0153       edm::LogInfo("L1-O2O") << "RCT " << pKey->subsystemKey(L1TriggerKey::kRCT) << std::endl;
0154       edm::LogInfo("L1-O2O") << "GCT " << pKey->subsystemKey(L1TriggerKey::kGCT) << std::endl;
0155       edm::LogInfo("L1-O2O") << "GT " << pKey->subsystemKey(L1TriggerKey::kGT) << std::endl;
0156       edm::LogInfo("L1-O2O") << "TSP0 " << pKey->subsystemKey(L1TriggerKey::kTSP0) << std::endl << std::endl;
0157 
0158       edm::LogInfo("L1-O2O") << "Object keys:" << std::endl;
0159       const L1TriggerKey::RecordToKey& recKeyMap = pKey->recordToKeyMap();
0160       L1TriggerKey::RecordToKey::const_iterator iRec = recKeyMap.begin();
0161       L1TriggerKey::RecordToKey::const_iterator eRec = recKeyMap.end();
0162       for (; iRec != eRec; ++iRec) {
0163         edm::LogInfo("L1-O2O") << iRec->first << " " << iRec->second << std::endl;
0164       }
0165     } catch (cms::Exception& ex) {
0166       edm::LogError("L1-O2O") << "No L1TriggerKey found." << std::endl;
0167     }
0168   }
0169 
0170   if (m_printESRecords) {
0171     //        ESHandle< L1TriggerKeyList > pList ;
0172     //        iSetup.get< L1TriggerKeyListRcd >().get( pList ) ;
0173 
0174     L1TriggerKeyList pList;
0175     l1t::DataWriter dataWriter;
0176     if (!dataWriter.fillLastTriggerKeyList(pList)) {
0177       edm::LogError("L1-O2O") << "Problem getting last L1TriggerKeyList";
0178     }
0179 
0180     // Start log string, convert run number into string
0181     unsigned long long run = iEvent.id().run();
0182     std::stringstream ss;
0183     ss << run;
0184     std::string log = "runNumber=" + ss.str();
0185 
0186     l1t::DataWriter writer;
0187 
0188     edm::LogInfo("L1-O2O") << std::endl << "Run Settings keys:" << std::endl;
0189 
0190     std::vector<std::string>::const_iterator iRec = m_recordsToPrint.begin();
0191     std::vector<std::string>::const_iterator iEnd = m_recordsToPrint.end();
0192     for (; iRec != iEnd; ++iRec) {
0193       std::string payloadToken = writer.payloadToken(*iRec, iEvent.id().run());
0194       std::string key;
0195 
0196       if (*iRec == "L1TriggerKeyRcd") {
0197         key = pList.tscKey(payloadToken);
0198       } else {
0199         key = pList.objectKey(*iRec, payloadToken);
0200       }
0201 
0202       edm::LogInfo("L1-O2O") << *iRec << " " << key;
0203       if (m_printPayloadTokens) {
0204         edm::LogInfo("L1-O2O") << " " << payloadToken;
0205       }
0206       edm::LogInfo("L1-O2O") << std::endl;
0207 
0208       // Replace spaces in key with ?s.  Do reverse substitution when
0209       // making L1TriggerKey.
0210       replace(key.begin(), key.end(), ' ', '?');
0211       log += " " + *iRec + "Key=" + key;
0212     }
0213 
0214     edm::LogInfo("L1-O2O") << std::endl << log << std::endl;
0215   }
0216 }
0217 
0218 // ------------ method called once each job just before starting event loop  ------------
0219 void L1O2OTestAnalyzer::beginJob() {}
0220 
0221 // ------------ method called once each job just after ending the event loop  ------------
0222 void L1O2OTestAnalyzer::endJob() {}
0223 
0224 //define this as a plug-in
0225 DEFINE_FWK_MODULE(L1O2OTestAnalyzer);