Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-17 23:36:01

0001 // -*- C++ -*-
0002 //
0003 // Package:    L1CondDBPayloadWriter
0004 // Class:      L1CondDBPayloadWriter
0005 //
0006 /**\class L1CondDBPayloadWriter L1CondDBPayloadWriter.cc CondTools/L1CondDBPayloadWriter/src/L1CondDBPayloadWriter.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:  Sun Mar  2 07:05:15 CET 2008
0016 // $Id: L1CondDBPayloadWriter.cc,v 1.17 2010/02/09 21:52:35 wsun Exp $
0017 //
0018 //
0019 
0020 // system include files
0021 
0022 // user include files
0023 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0024 
0025 #include "CondTools/L1Trigger/plugins/L1CondDBPayloadWriter.h"
0026 
0027 #include "CondFormats/L1TObjects/interface/L1TriggerKey.h"
0028 #include "CondFormats/DataRecord/interface/L1TriggerKeyRcd.h"
0029 #include "CondFormats/L1TObjects/interface/L1TriggerKeyList.h"
0030 #include "CondFormats/DataRecord/interface/L1TriggerKeyListRcd.h"
0031 
0032 //
0033 // class declaration
0034 //
0035 
0036 //
0037 // constants, enums and typedefs
0038 //
0039 
0040 //
0041 // constructors and destructor
0042 //
0043 L1CondDBPayloadWriter::L1CondDBPayloadWriter(const edm::ParameterSet& iConfig)
0044     : m_writeL1TriggerKey(iConfig.getParameter<bool>("writeL1TriggerKey")),
0045       m_writeConfigData(iConfig.getParameter<bool>("writeConfigData")),
0046       m_overwriteKeys(iConfig.getParameter<bool>("overwriteKeys")),
0047       m_logTransactions(iConfig.getParameter<bool>("logTransactions")),
0048       m_newL1TriggerKeyList(iConfig.getParameter<bool>("newL1TriggerKeyList")),
0049       l1TriggerKeyToken_(esConsumes()) {}
0050 
0051 L1CondDBPayloadWriter::~L1CondDBPayloadWriter() {
0052   // do anything here that needs to be done at desctruction time
0053   // (e.g. close files, deallocate resources etc.)
0054 }
0055 
0056 //
0057 // member functions
0058 //
0059 
0060 // ------------ method called to for each event  ------------
0061 void L1CondDBPayloadWriter::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0062   using namespace edm;
0063 
0064   // Get L1TriggerKeyList and make a copy
0065   L1TriggerKeyList oldKeyList;
0066 
0067   if (!m_newL1TriggerKeyList) {
0068     if (!m_writer.fillLastTriggerKeyList(oldKeyList)) {
0069       edm::LogError("L1-O2O") << "Problem getting last L1TriggerKeyList";
0070     }
0071   }
0072 
0073   L1TriggerKeyList* keyList = nullptr;
0074 
0075   // Write L1TriggerKey to ORCON with no IOV
0076   std::string token;
0077   ESHandle<L1TriggerKey> key;
0078 
0079   // Before calling writePayload(), check if TSC key is already in
0080   // L1TriggerKeyList.  writePayload() will not catch this situation in
0081   // the case of dummy configurations.
0082   bool triggerKeyOK = true;
0083   try {
0084     // Get L1TriggerKey
0085     key = iSetup.getHandle(l1TriggerKeyToken_);
0086 
0087     if (!m_overwriteKeys) {
0088       triggerKeyOK = oldKeyList.token(key->tscKey()).empty();
0089     }
0090   } catch (l1t::DataAlreadyPresentException& ex) {
0091     triggerKeyOK = false;
0092     edm::LogVerbatim("L1-O2O") << ex.what();
0093   }
0094 
0095   if (triggerKeyOK && m_writeL1TriggerKey) {
0096     edm::LogVerbatim("L1-O2O") << "Object key for L1TriggerKeyRcd@L1TriggerKey: " << key->tscKey();
0097     token = m_writer.writePayload(iSetup, "L1TriggerKeyRcd@L1TriggerKey");
0098   }
0099 
0100   // If L1TriggerKey is invalid, then all configuration data is already in DB
0101   bool throwException = false;
0102 
0103   if (!token.empty() || !m_writeL1TriggerKey) {
0104     // Record token in L1TriggerKeyList
0105     if (m_writeL1TriggerKey) {
0106       keyList = new L1TriggerKeyList(oldKeyList);
0107       if (!(keyList->addKey(key->tscKey(), token, m_overwriteKeys))) {
0108         throw cond::Exception("L1CondDBPayloadWriter: TSC key " + key->tscKey() + " already in L1TriggerKeyList");
0109       }
0110     }
0111 
0112     if (m_writeConfigData) {
0113       // Loop over record@type in L1TriggerKey
0114       L1TriggerKey::RecordToKey::const_iterator it = key->recordToKeyMap().begin();
0115       L1TriggerKey::RecordToKey::const_iterator end = key->recordToKeyMap().end();
0116 
0117       for (; it != end; ++it) {
0118         // Do nothing if object key is null.
0119         if (it->second == L1TriggerKey::kNullKey) {
0120           edm::LogVerbatim("L1-O2O") << "L1CondDBPayloadWriter: null object key for " << it->first
0121                                      << "; skipping this record.";
0122         } else {
0123           // Check key is new before writing
0124           if (oldKeyList.token(it->first, it->second).empty() || m_overwriteKeys) {
0125             // Write data to ORCON with no IOV
0126             if (!oldKeyList.token(it->first, it->second).empty()) {
0127               edm::LogVerbatim("L1-O2O") << "*** Overwriting payload: object key for " << it->first << ": "
0128                                          << it->second;
0129             } else {
0130               edm::LogVerbatim("L1-O2O") << "object key for " << it->first << ": " << it->second;
0131             }
0132 
0133             try {
0134               token = m_writer.writePayload(iSetup, it->first);
0135             } catch (l1t::DataInvalidException& ex) {
0136               edm::LogVerbatim("L1-O2O") << ex.what() << " Skipping to next record.";
0137 
0138               throwException = true;
0139 
0140               continue;
0141             }
0142 
0143             if (!token.empty()) {
0144               // Record token in L1TriggerKeyList
0145               if (!keyList) {
0146                 keyList = new L1TriggerKeyList(oldKeyList);
0147               }
0148 
0149               if (!(keyList->addKey(it->first, it->second, token, m_overwriteKeys))) {
0150                 // This should never happen because of the check
0151                 // above, but just in case....
0152                 throw cond::Exception("L1CondDBPayloadWriter: subsystem key " + it->second + " for " + it->first +
0153                                       " already in L1TriggerKeyList");
0154               }
0155             }
0156           } else {
0157             edm::LogVerbatim("L1-O2O") << "L1CondDBPayloadWriter: object key " << it->second << " for " << it->first
0158                                        << " already in L1TriggerKeyList";
0159           }
0160         }
0161       }
0162     }
0163   }
0164 
0165   if (keyList) {
0166     // Write L1TriggerKeyList to ORCON
0167     m_writer.writeKeyList(keyList, 0, m_logTransactions);
0168   }
0169 
0170   if (throwException) {
0171     throw l1t::DataInvalidException("Payload problem found.");
0172   }
0173 }
0174 
0175 // ------------ method called once each job just before starting event loop  ------------
0176 void L1CondDBPayloadWriter::beginJob() {}
0177 
0178 // ------------ method called once each job just after ending the event loop  ------------
0179 void L1CondDBPayloadWriter::endJob() {}
0180 
0181 //define this as a plug-in
0182 //DEFINE_FWK_MODULE(L1CondDBPayloadWriter);