CMS 3D CMS Logo

AlCaRecoTriggerBitsRcdUpdate.cc
Go to the documentation of this file.
1 
10 #include <string>
11 #include <map>
12 #include <vector>
13 
14 // Framework
22 
23 // Database
25 
26 // What I want to write:
28 // Rcd for reading old one:
30 
32 public:
35 
36  void analyze(const edm::Event &evt, const edm::EventSetup &evtSetup) override;
37 
38 private:
39  typedef std::map<std::string, std::string> TriggerMap;
41  bool removeKeysFromMap(const std::vector<std::string> &keys, TriggerMap &triggerMap) const;
42  bool replaceKeysFromMap(const std::vector<edm::ParameterSet> &alcarecoReplace, TriggerMap &triggerMap) const;
43  bool addTriggerLists(const std::vector<edm::ParameterSet> &triggerListsAdd, AlCaRecoTriggerBits &bits) const;
45  void writeBitsToDB(AlCaRecoTriggerBits *bitsToWrite) const;
46 
47  unsigned int nEventCalls_;
48  const unsigned int firstRunIOV_;
49  const int lastRunIOV_;
50  const bool startEmpty_;
51  const std::vector<std::string> listNamesRemove_;
52  const std::vector<edm::ParameterSet> triggerListsAdd_;
53  const std::vector<edm::ParameterSet> alcarecoReplace_;
54 };
55 
59 
61  : nEventCalls_(0),
62  firstRunIOV_(cfg.getParameter<unsigned int>("firstRunIOV")),
63  lastRunIOV_(cfg.getParameter<int>("lastRunIOV")),
64  startEmpty_(cfg.getParameter<bool>("startEmpty")),
65  listNamesRemove_(cfg.getParameter<std::vector<std::string> >("listNamesRemove")),
66  triggerListsAdd_(cfg.getParameter<std::vector<edm::ParameterSet> >("triggerListsAdd")),
67  alcarecoReplace_(cfg.getParameter<std::vector<edm::ParameterSet> >("alcarecoToReplace")) {}
68 
71  if (nEventCalls_++ > 0) { // postfix increment!
72  edm::LogWarning("BadConfig") << "@SUB=analyze"
73  << "Writing to DB to be done only once, set\n"
74  << "'process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(1))'\n"
75  << " next time. But your writing is fine.)";
76  return;
77  }
78 
79  // create what to write - starting from empty or existing list (auto_ptr?)
80  AlCaRecoTriggerBits *bitsToWrite = this->createStartTriggerBits(startEmpty_, iSetup);
81 
82  // remove some existing entries in map
84 
85  // now add new entries
86  this->addTriggerLists(triggerListsAdd_, *bitsToWrite);
87 
88  // now replace keys
90 
91  // finally write to DB
92  this->writeBitsToDB(bitsToWrite);
93 }
94 
96 AlCaRecoTriggerBits * // auto_ptr?
98  if (startEmpty) {
99  return new AlCaRecoTriggerBits;
100  } else {
102  evtSetup.get<AlCaRecoTriggerBitsRcd>().get(triggerBits);
103  return new AlCaRecoTriggerBits(*triggerBits); // copy old one
104  }
105 }
106 
108 bool AlCaRecoTriggerBitsRcdUpdate::removeKeysFromMap(const std::vector<std::string> &keys,
109  TriggerMap &triggerMap) const {
110  for (std::vector<std::string>::const_iterator iKey = keys.begin(), endKey = keys.end(); iKey != endKey; ++iKey) {
111  if (triggerMap.find(*iKey) != triggerMap.end()) {
112  // remove
113  // edm::LogError("Temp") << "@SUB=removeKeysFromMap" << "Cannot yet remove '" << *iKey
114  // << "' from map.";
115  // FIXME: test next line@
116  triggerMap.erase(*iKey);
117  } else { // not in list ==> misconfiguartion!
118  throw cms::Exception("BadConfig") << "[AlCaRecoTriggerBitsRcdUpdate::removeKeysFromMap] "
119  << "Cannot remove key '" << *iKey << "' since not in "
120  << "list - typo in configuration?\n";
121  return false;
122  }
123  }
124  return true;
125 }
126 
128 bool AlCaRecoTriggerBitsRcdUpdate::replaceKeysFromMap(const std::vector<edm::ParameterSet> &alcarecoReplace,
129  TriggerMap &triggerMap) const {
130  std::vector<std::pair<std::string, std::string> > keyPairs;
131  keyPairs.reserve(alcarecoReplace.size());
132 
133  for (auto &iSet : alcarecoReplace) {
134  const std::string oldKey(iSet.getParameter<std::string>("oldKey"));
135  const std::string newKey(iSet.getParameter<std::string>("newKey"));
136  keyPairs.push_back(std::make_pair(oldKey, newKey));
137  }
138 
139  for (auto &iKey : keyPairs) {
140  if (triggerMap.find(iKey.first) != triggerMap.end()) {
141  std::string bitsToReplace = triggerMap[iKey.first];
142  triggerMap.erase(iKey.first);
143  triggerMap[iKey.second] = bitsToReplace;
144  } else { // not in list ==> misconfiguration!
145  edm::LogWarning("AlCaRecoTriggerBitsRcdUpdate")
146  << "[AlCaRecoTriggerBitsRcdUpdate::replaceKeysFromMap] "
147  << "Cannot replace key '" << iKey.first << "with " << iKey.second << " since not in "
148  << "list - typo in configuration?\n";
149  return false;
150  }
151  }
152  return true;
153 }
154 
156 bool AlCaRecoTriggerBitsRcdUpdate::addTriggerLists(const std::vector<edm::ParameterSet> &triggerListsAdd,
157  AlCaRecoTriggerBits &bits) const {
158  TriggerMap &triggerMap = bits.m_alcarecoToTrig;
159 
160  // loop on PSets, each containing the key (filter name) and a vstring with triggers
161  for (std::vector<edm::ParameterSet>::const_iterator iSet = triggerListsAdd.begin(); iSet != triggerListsAdd.end();
162  ++iSet) {
163  const std::vector<std::string> paths(iSet->getParameter<std::vector<std::string> >("hltPaths"));
164  // We must avoid a map<string,vector<string> > in DB for performance reason,
165  // so we have to merge the paths into one string that will be decoded when needed:
166  const std::string mergedPaths = bits.compose(paths);
167 
168  const std::string filter(iSet->getParameter<std::string>("listName"));
169  if (triggerMap.find(filter) != triggerMap.end()) {
170  throw cms::Exception("BadConfig") << "List name '" << filter << "' already in map, either "
171  << "remove from 'triggerListsAdd' or "
172  << " add to 'listNamesRemove'.\n";
173  }
174  triggerMap[filter] = mergedPaths;
175  }
176 
177  return true;
178 }
179 
182  edm::LogInfo("") << "Uploading to the database...";
183 
185  if (!poolDbService.isAvailable()) {
186  throw cms::Exception("NotAvailable") << "PoolDBOutputService not available.\n";
187  }
188 
189  // ownership of bitsToWrite transferred
190  // FIXME: Have to check that timetype is run number! How?
191  const std::string recordName("AlCaRecoTriggerBitsRcd");
192  if (poolDbService->isNewTagRequest(recordName)) { // tag not yet existing
193  // lastRunIOV_ = -1 means infinity:
194  const cond::Time_t lastRun = (lastRunIOV_ < 0 ? poolDbService->endOfTime() : lastRunIOV_);
195  poolDbService->createNewIOV(bitsToWrite, firstRunIOV_, lastRun, recordName);
196  } else { // tag exists, can only append
197  if (lastRunIOV_ >= 0) {
198  throw cms::Exception("BadConfig") << "Tag already exists, can only append until infinity,"
199  << " but lastRunIOV = " << lastRunIOV_ << ".\n";
200  }
201  poolDbService->appendSinceTime(bitsToWrite, firstRunIOV_, recordName);
202  }
203 
204  edm::LogInfo("") << "...done for runs " << firstRunIOV_ << " to " << lastRunIOV_ << " (< 0 meaning infinity)!";
205 }
206 
207 //define this as a plug-in
electrons_cff.bool
bool
Definition: electrons_cff.py:366
AlCaRecoTriggerBitsRcdUpdate::analyze
void analyze(const edm::Event &evt, const edm::EventSetup &evtSetup) override
Definition: AlCaRecoTriggerBitsRcdUpdate.cc:70
MessageLogger.h
ESHandle.h
AlCaRecoTriggerBitsRcdUpdate::startEmpty_
const bool startEmpty_
Definition: AlCaRecoTriggerBitsRcdUpdate.cc:50
AlCaRecoTriggerBitsRcdUpdate::createStartTriggerBits
AlCaRecoTriggerBits * createStartTriggerBits(bool startEmpty, const edm::EventSetup &evtSetup) const
Definition: AlCaRecoTriggerBitsRcdUpdate.cc:97
edm
HLT enums.
Definition: AlignableModifier.h:19
align_cfg.recordName
recordName
Definition: align_cfg.py:66
cond::service::PoolDBOutputService::appendSinceTime
void appendSinceTime(const T *payloadObj, cond::Time_t sinceTime, const std::string &recordName)
Definition: PoolDBOutputService.h:141
AlCaRecoTriggerBitsRcdUpdate::writeBitsToDB
void writeBitsToDB(AlCaRecoTriggerBits *bitsToWrite) const
Takes over memory uresponsibility for 'bitsToWrite'.
Definition: AlCaRecoTriggerBitsRcdUpdate.cc:181
EDAnalyzer.h
relativeConstraints.keys
keys
Definition: relativeConstraints.py:89
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
AlCaRecoTriggerBits.h
AlCaRecoTriggerBitsRcdUpdate::alcarecoReplace_
const std::vector< edm::ParameterSet > alcarecoReplace_
Definition: AlCaRecoTriggerBitsRcdUpdate.cc:53
edm::Service::isAvailable
bool isAvailable() const
Definition: Service.h:40
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
edm::EDAnalyzer
Definition: EDAnalyzer.h:28
AlCaRecoTriggerBitsRcdUpdate::removeKeysFromMap
bool removeKeysFromMap(const std::vector< std::string > &keys, TriggerMap &triggerMap) const
Definition: AlCaRecoTriggerBitsRcdUpdate.cc:108
AlCaRecoTriggerBitsRcdUpdate::listNamesRemove_
const std::vector< std::string > listNamesRemove_
Definition: AlCaRecoTriggerBitsRcdUpdate.cc:51
MakerMacros.h
PoolDBOutputService.h
edm::EventSetup::get
T get() const
Definition: EventSetup.h:87
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
cond::service::PoolDBOutputService::createNewIOV
void createNewIOV(const T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t, const std::string &recordName)
Definition: PoolDBOutputService.h:116
Service.h
edm::ESHandle
Definition: DTSurvey.h:22
CreateSqliteForCondDB_cfg.startEmpty
startEmpty
Definition: CreateSqliteForCondDB_cfg.py:88
ALCARECOTkAlBeamHalo_cff.filter
filter
Definition: ALCARECOTkAlBeamHalo_cff.py:27
AlCaRecoTriggerBits
Definition: AlCaRecoTriggerBits.h:9
AlCaRecoTriggerBitsRcdUpdate::nEventCalls_
unsigned int nEventCalls_
Definition: AlCaRecoTriggerBitsRcdUpdate.cc:47
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
AlCaRecoTriggerBitsRcdUpdate::AlCaRecoTriggerBitsRcdUpdate
AlCaRecoTriggerBitsRcdUpdate(const edm::ParameterSet &cfg)
Definition: AlCaRecoTriggerBitsRcdUpdate.cc:60
BeamSpotPI::lastRun
Definition: BeamSpotPayloadInspectorHelper.h:40
AlCaRecoTriggerBitsRcdUpdate
Definition: AlCaRecoTriggerBitsRcdUpdate.cc:31
AlCaRecoTriggerBitsRcd
Definition: AlCaRecoTriggerBitsRcd.h:22
edm::ParameterSet
Definition: ParameterSet.h:47
ParameterSet
Definition: Functions.h:16
AlCaRecoTriggerBitsRcdUpdate::TriggerMap
std::map< std::string, std::string > TriggerMap
Definition: AlCaRecoTriggerBitsRcdUpdate.cc:39
cond::Time_t
unsigned long long Time_t
Definition: Time.h:14
edm::Service< cond::service::PoolDBOutputService >
createfilelist.int
int
Definition: createfilelist.py:10
AlCaRecoTriggerBitsRcd.h
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
AlCaRecoTriggerBitsRcdUpdate::addTriggerLists
bool addTriggerLists(const std::vector< edm::ParameterSet > &triggerListsAdd, AlCaRecoTriggerBits &bits) const
Definition: AlCaRecoTriggerBitsRcdUpdate.cc:156
edm::EventSetup
Definition: EventSetup.h:58
get
#define get
looper.cfg
cfg
Definition: looper.py:297
cond::service::PoolDBOutputService::endOfTime
cond::Time_t endOfTime() const
Definition: PoolDBOutputService.cc:213
AlCaRecoTriggerBitsRcdUpdate::firstRunIOV_
const unsigned int firstRunIOV_
Definition: AlCaRecoTriggerBitsRcdUpdate.cc:48
std
Definition: JetResolutionObject.h:76
AlCaRecoTriggerBits::m_alcarecoToTrig
std::map< std::string, std::string > m_alcarecoToTrig
Definition: AlCaRecoTriggerBits.h:21
AlCaRecoTriggerBitsRcdUpdate::replaceKeysFromMap
bool replaceKeysFromMap(const std::vector< edm::ParameterSet > &alcarecoReplace, TriggerMap &triggerMap) const
Definition: AlCaRecoTriggerBitsRcdUpdate.cc:128
Exception
Definition: hltDiff.cc:245
AlCaRecoTriggerBitsRcdUpdate::lastRunIOV_
const int lastRunIOV_
Definition: AlCaRecoTriggerBitsRcdUpdate.cc:49
EventSetup.h
cond::service::PoolDBOutputService::isNewTagRequest
bool isNewTagRequest(const std::string &recordName)
Definition: PoolDBOutputService.cc:128
Skims_PA_cff.paths
paths
Definition: Skims_PA_cff.py:18
AlCaRecoTriggerBitsRcdUpdate::triggerListsAdd_
const std::vector< edm::ParameterSet > triggerListsAdd_
Definition: AlCaRecoTriggerBitsRcdUpdate.cc:52
ParameterSet.h
AlCaRecoTriggerBits::compose
std::string compose(const std::vector< std::string > &paths) const
Compose several paths into one string :
Definition: AlCaRecoTriggerBits.cc:9
edm::Event
Definition: Event.h:73
CreateSqliteForCondDB_cfg.triggerListsAdd
triggerListsAdd
Definition: CreateSqliteForCondDB_cfg.py:91
AlCaRecoTriggerBitsRcdUpdate::~AlCaRecoTriggerBitsRcdUpdate
~AlCaRecoTriggerBitsRcdUpdate() override
Definition: AlCaRecoTriggerBitsRcdUpdate.cc:34