-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathL1CondDBPayloadWriterExt.cc
183 lines (149 loc) · 6.9 KB
/
L1CondDBPayloadWriterExt.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "CondFormats/L1TObjects/interface/L1TriggerKeyExt.h"
#include "CondFormats/DataRecord/interface/L1TriggerKeyExtRcd.h"
#include "CondFormats/L1TObjects/interface/L1TriggerKeyListExt.h"
#include "CondFormats/DataRecord/interface/L1TriggerKeyListExtRcd.h"
#include <memory>
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/ESGetToken.h"
#include "CondTools/L1TriggerExt/interface/DataWriterExt.h"
class L1CondDBPayloadWriterExt : public edm::one::EDAnalyzer<> {
public:
explicit L1CondDBPayloadWriterExt(const edm::ParameterSet&);
~L1CondDBPayloadWriterExt() override;
private:
void beginJob() override;
void analyze(const edm::Event&, const edm::EventSetup&) override;
void endJob() override;
// ----------member data ---------------------------
l1t::DataWriterExt m_writer;
// std::string m_tag ; // tag is known by PoolDBOutputService
// set to false to write config data without valid TSC key
bool m_writeL1TriggerKeyExt;
// set to false to write config data only
bool m_writeConfigData;
// substitute new payload tokens for existing keys in L1TriggerKeyListExt
bool m_overwriteKeys;
bool m_logTransactions;
// if true, do not retrieve L1TriggerKeyListExt from EventSetup
bool m_newL1TriggerKeyListExt;
// Token to access L1TriggerKeyExt data in the event setup
edm::ESGetToken<L1TriggerKeyExt, L1TriggerKeyExtRcd> theL1TriggerKeyExtToken_;
};
L1CondDBPayloadWriterExt::L1CondDBPayloadWriterExt(const edm::ParameterSet& iConfig)
: m_writeL1TriggerKeyExt(iConfig.getParameter<bool>("writeL1TriggerKeyExt")),
m_writeConfigData(iConfig.getParameter<bool>("writeConfigData")),
m_overwriteKeys(iConfig.getParameter<bool>("overwriteKeys")),
m_logTransactions(iConfig.getParameter<bool>("logTransactions")),
m_newL1TriggerKeyListExt(iConfig.getParameter<bool>("newL1TriggerKeyListExt")),
theL1TriggerKeyExtToken_(esConsumes()) {}
L1CondDBPayloadWriterExt::~L1CondDBPayloadWriterExt() {
// do anything here that needs to be done at desctruction time
// (e.g. close files, deallocate resources etc.)
}
// ------------ method called to for each event ------------
void L1CondDBPayloadWriterExt::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
using namespace edm;
// Get L1TriggerKeyListExt and make a copy
L1TriggerKeyListExt oldKeyList;
if (!m_newL1TriggerKeyListExt) {
if (!m_writer.fillLastTriggerKeyList(oldKeyList)) {
edm::LogError("L1-O2O") << "Problem getting last L1TriggerKeyListExt";
}
}
L1TriggerKeyListExt* keyList = nullptr;
// Write L1TriggerKeyExt to ORCON with no IOV
std::string token;
L1TriggerKeyExt key;
// Before calling writePayload(), check if TSC key is already in
// L1TriggerKeyListExt. writePayload() will not catch this situation in
// the case of dummy configurations.
bool triggerKeyOK = true;
try {
// Get L1TriggerKeyExt
key = iSetup.getData(theL1TriggerKeyExtToken_);
if (!m_overwriteKeys) {
triggerKeyOK = oldKeyList.token(key.tscKey()).empty();
}
} catch (l1t::DataAlreadyPresentException& ex) {
triggerKeyOK = false;
edm::LogVerbatim("L1-O2O") << ex.what();
}
if (triggerKeyOK && m_writeL1TriggerKeyExt) {
edm::LogVerbatim("L1-O2O") << "Object key for L1TriggerKeyExtRcd@L1TriggerKeyExt: " << key.tscKey();
token = m_writer.writePayload(iSetup, "L1TriggerKeyExtRcd@L1TriggerKeyExt");
}
// If L1TriggerKeyExt is invalid, then all configuration data is already in DB
bool throwException = false;
if (!token.empty() || !m_writeL1TriggerKeyExt) {
// Record token in L1TriggerKeyListExt
if (m_writeL1TriggerKeyExt) {
keyList = new L1TriggerKeyListExt(oldKeyList);
if (!(keyList->addKey(key.tscKey(), token, m_overwriteKeys))) {
throw cond::Exception("L1CondDBPayloadWriter: TSC key " + key.tscKey() + " already in L1TriggerKeyListExt");
}
}
if (m_writeConfigData) {
// Loop over record@type in L1TriggerKeyExt
L1TriggerKeyExt::RecordToKey::const_iterator it = key.recordToKeyMap().begin();
L1TriggerKeyExt::RecordToKey::const_iterator end = key.recordToKeyMap().end();
for (; it != end; ++it) {
// Do nothing if object key is null.
if (it->second == L1TriggerKeyExt::kNullKey) {
edm::LogVerbatim("L1-O2O") << "L1CondDBPayloadWriter: null object key for " << it->first
<< "; skipping this record.";
} else {
// Check key is new before writing
if (oldKeyList.token(it->first, it->second).empty() || m_overwriteKeys) {
// Write data to ORCON with no IOV
if (!oldKeyList.token(it->first, it->second).empty()) {
edm::LogVerbatim("L1-O2O") << "*** Overwriting payload: object key for " << it->first << ": "
<< it->second;
} else {
edm::LogVerbatim("L1-O2O") << "object key for " << it->first << ": " << it->second;
}
try {
token = m_writer.writePayload(iSetup, it->first);
} catch (l1t::DataInvalidException& ex) {
edm::LogVerbatim("L1-O2O") << ex.what() << " Skipping to next record.";
throwException = true;
continue;
}
if (!token.empty()) {
// Record token in L1TriggerKeyListExt
if (!keyList) {
keyList = new L1TriggerKeyListExt(oldKeyList);
}
if (!(keyList->addKey(it->first, it->second, token, m_overwriteKeys))) {
// This should never happen because of the check
// above, but just in case....
throw cond::Exception("L1CondDBPayloadWriter: subsystem key " + it->second + " for " + it->first +
" already in L1TriggerKeyListExt");
}
}
} else {
edm::LogVerbatim("L1-O2O") << "L1CondDBPayloadWriter: object key " << it->second << " for " << it->first
<< " already in L1TriggerKeyListExt";
}
}
}
}
}
if (keyList) {
// Write L1TriggerKeyListExt to ORCON
m_writer.writeKeyList(keyList, 0, m_logTransactions);
}
if (throwException) {
throw l1t::DataInvalidException("Payload problem found.");
}
}
// ------------ method called once each job just before starting event loop ------------
void L1CondDBPayloadWriterExt::beginJob() {}
// ------------ method called once each job just after ending the event loop ------------
void L1CondDBPayloadWriterExt::endJob() {}
//define this as a plug-in
DEFINE_FWK_MODULE(L1CondDBPayloadWriterExt);