Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Package:    L1CondDBIOVWriter
0004 // Class:      L1CondDBIOVWriter
0005 //
0006 /**\class L1CondDBIOVWriter L1CondDBIOVWriter.cc CondTools/L1CondDBIOVWriter/src/L1CondDBIOVWriter.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 20:09:46 CET 2008
0016 // $Id: L1CondDBIOVWriter.cc,v 1.19 2010/02/16 21:59:24 wsun Exp $
0017 //
0018 //
0019 
0020 // system include files
0021 #include <sstream>
0022 
0023 // user include files
0024 #include "CondTools/L1Trigger/plugins/L1CondDBIOVWriter.h"
0025 #include "CondTools/L1Trigger/interface/DataWriter.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 #include "CondCore/CondDB/interface/Serialization.h"
0033 
0034 //
0035 // class declaration
0036 //
0037 
0038 //
0039 // constants, enums and typedefs
0040 //
0041 
0042 //
0043 // static data member definitions
0044 //
0045 
0046 //
0047 // constructors and destructor
0048 //
0049 L1CondDBIOVWriter::L1CondDBIOVWriter(const edm::ParameterSet& iConfig)
0050     : m_tscKey(iConfig.getParameter<std::string>("tscKey")),
0051       m_ignoreTriggerKey(iConfig.getParameter<bool>("ignoreTriggerKey")),
0052       m_logKeys(iConfig.getParameter<bool>("logKeys")),
0053       m_logTransactions(iConfig.getParameter<bool>("logTransactions")),
0054       m_forceUpdate(iConfig.getParameter<bool>("forceUpdate")) {
0055   //now do what ever initialization is needed
0056   typedef std::vector<edm::ParameterSet> ToSave;
0057   ToSave toSave = iConfig.getParameter<ToSave>("toPut");
0058   for (ToSave::const_iterator it = toSave.begin(); it != toSave.end(); it++) {
0059     std::string record = it->getParameter<std::string>("record");
0060     std::string type = it->getParameter<std::string>("type");
0061     m_recordTypes.push_back(record + "@" + type);
0062   }
0063   l1TriggerKeyToken_ = esConsumes();
0064 }
0065 
0066 L1CondDBIOVWriter::~L1CondDBIOVWriter() {
0067   // do anything here that needs to be done at desctruction time
0068   // (e.g. close files, deallocate resources etc.)
0069 }
0070 
0071 //
0072 // member functions
0073 //
0074 
0075 // ------------ method called to for each event  ------------
0076 void L1CondDBIOVWriter::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0077   using namespace edm;
0078 
0079   // Get L1TriggerKeyList
0080   L1TriggerKeyList keyList;
0081   l1t::DataWriter dataWriter;
0082   if (!dataWriter.fillLastTriggerKeyList(keyList)) {
0083     edm::LogError("L1-O2O") << "Problem getting last L1TriggerKeyList";
0084   }
0085 
0086   unsigned long long run = iEvent.id().run();
0087 
0088   L1TriggerKey::RecordToKey recordTypeToKeyMap;
0089 
0090   bool triggerKeyIOVUpdated = true;
0091 
0092   // Start log string, convert run number into string
0093   std::stringstream ss;
0094   ss << run;
0095   std::string log = "KEYLOG runNumber=" + ss.str();
0096   bool logRecords = true;
0097 
0098   if (!m_ignoreTriggerKey) {
0099     if (!m_tscKey.empty()) {
0100       edm::LogVerbatim("L1-O2O") << "Object key for L1TriggerKey@L1TriggerKeyRcd: " << m_tscKey;
0101 
0102       // Use TSC key and L1TriggerKeyList to find next run's
0103       // L1TriggerKey token
0104       std::string keyToken = keyList.token(m_tscKey);
0105 
0106       // Update IOV sequence for this token with since-time = new run
0107       triggerKeyIOVUpdated = m_writer.updateIOV("L1TriggerKeyRcd", keyToken, run, m_logTransactions);
0108 
0109       // Read current L1TriggerKey directly from ORCON using token
0110       L1TriggerKey key;
0111       m_writer.readObject(keyToken, key);
0112 
0113       recordTypeToKeyMap = key.recordToKeyMap();
0114 
0115       // Replace spaces in key with ?s.  Do reverse substitution when
0116       // making L1TriggerKey.
0117       std::string tmpKey = m_tscKey;
0118       replace(tmpKey.begin(), tmpKey.end(), ' ', '?');
0119       log += " tscKey=" + tmpKey;
0120       logRecords = false;
0121     } else {
0122       // For use with Run Settings, no corresponding L1TrigerKey in
0123       // ORCON.
0124 
0125       // Get L1TriggerKey from EventSetup
0126       auto esKey = iSetup.getHandle(l1TriggerKeyToken_);
0127       recordTypeToKeyMap = esKey->recordToKeyMap();
0128     }
0129   } else {
0130     std::vector<std::string>::const_iterator recordTypeItr = m_recordTypes.begin();
0131     std::vector<std::string>::const_iterator recordTypeEnd = m_recordTypes.end();
0132 
0133     for (; recordTypeItr != recordTypeEnd; ++recordTypeItr) {
0134       recordTypeToKeyMap.insert(std::make_pair(*recordTypeItr, m_tscKey));
0135     }
0136   }
0137 
0138   // If L1TriggerKey IOV was already up to date, then so are all its
0139   // sub-records.
0140   bool throwException = false;
0141 
0142   if (triggerKeyIOVUpdated || m_forceUpdate) {
0143     // Loop over record@type in L1TriggerKey
0144     L1TriggerKey::RecordToKey::const_iterator itr = recordTypeToKeyMap.begin();
0145     L1TriggerKey::RecordToKey::const_iterator end = recordTypeToKeyMap.end();
0146 
0147     for (; itr != end; ++itr) {
0148       std::string recordType = itr->first;
0149       std::string objectKey = itr->second;
0150 
0151       std::string recordName(recordType, 0, recordType.find_first_of('@'));
0152 
0153       if (logRecords) {
0154         // Replace spaces in key with ?s.  Do reverse substitution when
0155         // making L1TriggerKey.
0156         std::string tmpKey = objectKey;
0157         replace(tmpKey.begin(), tmpKey.end(), ' ', '?');
0158         log += " " + recordName + "Key=" + tmpKey;
0159       }
0160 
0161       // Do nothing if object key is null.
0162       if (objectKey == L1TriggerKey::kNullKey) {
0163         edm::LogVerbatim("L1-O2O") << "L1CondDBIOVWriter: null object key for " << recordType
0164                                    << "; skipping this record.";
0165       } else {
0166         // Find payload token
0167         edm::LogVerbatim("L1-O2O") << "Object key for " << recordType << ": " << objectKey;
0168 
0169         std::string payloadToken = keyList.token(recordType, objectKey);
0170         if (payloadToken.empty()) {
0171           edm::LogVerbatim("L1-O2O") << "L1CondDBIOVWriter: empty payload token for " + recordType + ", key " +
0172                                             objectKey;
0173 
0174           throwException = true;
0175         } else {
0176           m_writer.updateIOV(recordName, payloadToken, run, m_logTransactions);
0177         }
0178       }
0179     }
0180   }
0181 
0182   if (m_logKeys) {
0183     edm::LogVerbatim("L1-O2O") << log;
0184   }
0185 
0186   if (throwException) {
0187     throw cond::Exception("L1CondDBIOVWriter: empty payload tokens");
0188   }
0189 }
0190 
0191 // ------------ method called once each job just before starting event loop  ------------
0192 void L1CondDBIOVWriter::beginJob() {}
0193 
0194 // ------------ method called once each job just after ending the event loop  ------------
0195 void L1CondDBIOVWriter::endJob() {}
0196 
0197 //define this as a plug-in
0198 //DEFINE_FWK_MODULE(L1CondDBIOVWriter);