File indexing completed on 2024-04-06 12:03:12
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #include <sstream>
0022
0023
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
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
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
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
0068
0069 }
0070
0071
0072
0073
0074
0075
0076 void L1CondDBIOVWriter::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0077 using namespace edm;
0078
0079
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
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
0103
0104 std::string keyToken = keyList.token(m_tscKey);
0105
0106
0107 triggerKeyIOVUpdated = m_writer.updateIOV("L1TriggerKeyRcd", keyToken, run, m_logTransactions);
0108
0109
0110 L1TriggerKey key;
0111 m_writer.readObject(keyToken, key);
0112
0113 recordTypeToKeyMap = key.recordToKeyMap();
0114
0115
0116
0117 std::string tmpKey = m_tscKey;
0118 replace(tmpKey.begin(), tmpKey.end(), ' ', '?');
0119 log += " tscKey=" + tmpKey;
0120 logRecords = false;
0121 } else {
0122
0123
0124
0125
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
0139
0140 bool throwException = false;
0141
0142 if (triggerKeyIOVUpdated || m_forceUpdate) {
0143
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
0155
0156 std::string tmpKey = objectKey;
0157 replace(tmpKey.begin(), tmpKey.end(), ' ', '?');
0158 log += " " + recordName + "Key=" + tmpKey;
0159 }
0160
0161
0162 if (objectKey == L1TriggerKey::kNullKey) {
0163 edm::LogVerbatim("L1-O2O") << "L1CondDBIOVWriter: null object key for " << recordType
0164 << "; skipping this record.";
0165 } else {
0166
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
0192 void L1CondDBIOVWriter::beginJob() {}
0193
0194
0195 void L1CondDBIOVWriter::endJob() {}
0196
0197
0198