64 desc.setComment(
"Plugin to write payloads of type AlCaRecoTriggerBits");
65 desc.add<
unsigned int>(
"firstRunIOV", 1);
66 desc.add<
int>(
"lastRunIOV", -1);
67 desc.add<
bool>(
"startEmpty",
true);
68 desc.add<std::vector<std::string>>(
"listNamesRemove", {});
72 desc_triggeListsToAdd.add<std::vector<std::string>>(
"hltPaths");
73 std::vector<edm::ParameterSet> default_triggerListsToAdd;
74 desc.addVPSet(
"triggerListsAdd", desc_triggeListsToAdd, default_triggerListsToAdd);
79 std::vector<edm::ParameterSet> default_alcarecoToReplace;
80 desc.addVPSet(
"alcarecoToReplace", desc_alcarecoToReplace, default_alcarecoToReplace);
84 desc_pathsToAdd.
add<std::vector<std::string>>(
"hltPaths");
85 std::vector<edm::ParameterSet> default_pathsToAdd;
86 desc.addVPSet(
"pathsToAdd", desc_pathsToAdd, default_pathsToAdd);
90 desc_pathsToRemove.
add<std::vector<std::string>>(
"hltPaths");
91 std::vector<edm::ParameterSet> default_pathsToRemove;
92 desc.addVPSet(
"pathsToRemove", desc_pathsToRemove, default_pathsToRemove);
101 firstRunIOV_(
cfg.getParameter<unsigned
int>(
"firstRunIOV")),
102 lastRunIOV_(
cfg.getParameter<
int>(
"lastRunIOV")),
103 startEmpty_(
cfg.getParameter<
bool>(
"startEmpty")),
114 <<
"Writing to DB to be done only once, set\n" 115 <<
"'process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(1))'\n" 116 <<
" next time. But your writing is fine.)";
121 std::unique_ptr<AlCaRecoTriggerBits> bitsToWrite;
123 bitsToWrite = std::make_unique<AlCaRecoTriggerBits>();
150 for (std::vector<std::string>::const_iterator iKey =
keys.begin(), endKey =
keys.end(); iKey != endKey; ++iKey) {
151 if (triggerMap.find(*iKey) != triggerMap.end()) {
152 triggerMap.erase(*iKey);
154 throw cms::Exception(
"BadConfig") <<
"[AlCaRecoTriggerBitsRcdUpdate::removeKeysFromMap] " 155 <<
"Cannot remove key '" << *iKey <<
"' since not in " 156 <<
"list - typo in configuration?\n";
166 std::vector<std::pair<std::string, std::string>> keyPairs;
167 keyPairs.reserve(alcarecoReplace.size());
169 for (
auto &iSet : alcarecoReplace) {
172 keyPairs.push_back(std::make_pair(oldKey, newKey));
175 for (
auto &iKey : keyPairs) {
176 if (triggerMap.find(iKey.first) != triggerMap.end()) {
177 std::string bitsToReplace = triggerMap[iKey.first];
178 triggerMap.erase(iKey.first);
179 triggerMap[iKey.second] = bitsToReplace;
182 <<
"[AlCaRecoTriggerBitsRcdUpdate::replaceKeysFromMap] " 183 <<
"Cannot replace key '" << iKey.first <<
"with " << iKey.second <<
" since not in " 184 <<
"list - typo in configuration?\n";
198 const std::vector<std::string>
paths(iSet.getParameter<std::vector<std::string>>(
"hltPaths"));
204 if (triggerMap.find(
filter) != triggerMap.end()) {
206 <<
"remove from 'triggerListsAdd' or " 207 <<
" add to 'listNamesRemove'.\n";
209 triggerMap[
filter] = mergedPaths;
221 for (
const auto &iSet : pathsToAdd) {
225 for (
const auto &imap : triggerMap) {
227 mergedPathsInKey = imap.second;
230 if (mergedPathsInKey.empty()) {
232 <<
"if you want to add new key/paths, please use 'addTriggerLists'.\n";
235 auto const &pathsInKey =
bits.decompose(mergedPathsInKey);
236 auto const &
paths = iSet.getParameter<std::vector<std::string>>(
"hltPaths");
239 throw cms::Exception(
"BadConfig") <<
"Didn't set any path to add!";
242 std::set<std::string> pathsSet{pathsInKey.begin(), pathsInKey.end()};
244 std::vector<std::string>
const newPathsInKey{pathsSet.begin(), pathsSet.end()};
248 triggerMap[
filter] =
bits.compose(newPathsInKey);
260 for (
const auto &iSet : pathsToRemove) {
264 for (
const auto &imap : triggerMap) {
266 mergedPathsInKey = imap.second;
269 if (mergedPathsInKey.empty()) {
273 auto PathsInKey =
bits.decompose(mergedPathsInKey);
275 iSet.getParameter<std::vector<std::string>>(
"hltPaths"));
278 throw cms::Exception(
"BadConfig") <<
"Didn't set any path to remove!";
282 PathsInKey.erase(
std::remove(PathsInKey.begin(), PathsInKey.end(),
path), PathsInKey.end());
287 triggerMap[
filter] =
bits.compose(PathsInKey);
295 edm::LogInfo(
"AlCaRecoTriggerBitsRcdUpdate") <<
"Uploading to the database...";
299 throw cms::Exception(
"NotAvailable") <<
"PoolDBOutputService not available.\n";
311 edm::LogInfo(
"AlCaRecoTriggerBitsRcdUpdate") <<
"## Appending to existing tag...";
315 edm::LogInfo(
"AlCaRecoTriggerBitsRcdUpdate") <<
"## Skipping update since hash is the same...";
319 edm::LogInfo(
"AlCaRecoTriggerBitsRcdUpdate") <<
"## Creating new tag...";
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
const edm::ESGetToken< AlCaRecoTriggerBits, AlCaRecoTriggerBitsRcd > triggerBitsToken_
bool addTriggerLists(const std::vector< edm::ParameterSet > &triggerListsAdd, AlCaRecoTriggerBits &bits) const
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
bool addPathsFromMap(const std::vector< edm::ParameterSet > &pathsToAdd, AlCaRecoTriggerBits &bits) const
bool replaceKeysFromMap(const std::vector< edm::ParameterSet > &alcarecoReplace, TriggerMap &triggerMap) const
unsigned int nEventCalls_
const std::vector< edm::ParameterSet > pathsToRemove_
std::map< std::string, std::string > TriggerMap
const std::vector< edm::ParameterSet > triggerListsAdd_
const std::vector< edm::ParameterSet > pathsToAdd_
bool removePathsFromMap(const std::vector< edm::ParameterSet > &pathsToRemove, AlCaRecoTriggerBits &bits) const
void analyze(const edm::Event &evt, const edm::EventSetup &evtSetup) override
const std::vector< edm::ParameterSet > alcarecoReplace_
bool removeKeysFromMap(const std::vector< std::string > &keys, TriggerMap &triggerMap) const
void writeBitsToDB(const AlCaRecoTriggerBits &bitsToWrite) const
#define DEFINE_FWK_MODULE(type)
const unsigned int firstRunIOV_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
~AlCaRecoTriggerBitsRcdUpdate() override=default
Log< level::Info, false > LogInfo
def remove(d, key, TELL=False)
bool appendSinceTime(const std::string &payloadId, cond::Time_t sinceTime, const std::string &recordName)
void createNewIOV(const std::string &firstPayloadId, cond::Time_t firstSinceTime, const std::string &recordName)
AlCaRecoTriggerBitsRcdUpdate(const edm::ParameterSet &cfg)
cond::Hash storePayload(const T &payload, const boost::posix_time::ptime &creationTime=boost::posix_time::microsec_clock::universal_time())
const std::vector< std::string > listNamesRemove_
Log< level::Warning, false > LogWarning
bool tagInfo(const std::string &recordName, cond::TagInfo_t &result)
cond::persistency::Session session() const